This project has retired. For details please refer to its Attic page.
RemoteRepository xref
View Javadoc
1   package org.apache.archiva.admin.model.beans;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.lang.StringUtils;
23  
24  import javax.xml.bind.annotation.XmlRootElement;
25  import java.io.Serializable;
26  import java.util.ArrayList;
27  import java.util.HashMap;
28  import java.util.List;
29  import java.util.Map;
30  
31  /**
32   * @author Olivier Lamy
33   * @since 1.4-M1
34   */
35  @XmlRootElement (name = "remoteRepository")
36  public class RemoteRepository
37      extends AbstractRepository
38      implements Serializable
39  {
40  
41      private String url;
42  
43      private String userName;
44  
45      private String password;
46  
47      private int timeout = 60;
48  
49      /**
50       * @since 2.2.3
51       * The path to use for checking availability of the remote repository
52       */
53      private String checkPath;
54  
55      /**
56       * Activate download of remote index if remoteIndexUrl is set too.
57       */
58      private boolean downloadRemoteIndex = false;
59  
60      /**
61       * Remote Index Url : if not starting with http will be relative to the remote repository url.
62       */
63      private String remoteIndexUrl = ".index";
64  
65      private String remoteDownloadNetworkProxyId;
66  
67      /**
68       * default model value daily : every sunday at 8H00
69       */
70      private String cronExpression = "0 0 08 ? * SUN";
71  
72      private int remoteDownloadTimeout = 300;
73  
74      /**
75       * @since 1.4-M2
76       */
77      private boolean downloadRemoteIndexOnStartup = false;
78  
79      /**
80       * extraParameters.
81       *
82       * @since 1.4-M4
83       */
84      private Map<String, String> extraParameters;
85  
86      /**
87       * field to ease json mapping wrapper on <code>extraParameters</code> field
88       *
89       * @since 1.4-M4
90       */
91      private List<PropertyEntry> extraParametersEntries;
92  
93      /**
94       * extraHeaders.
95       *
96       * @since 1.4-M4
97       */
98      private Map<String, String> extraHeaders;
99  
100     /**
101      * field to ease json mapping wrapper on <code>extraHeaders</code> field
102      *
103      * @since 1.4-M4
104      */
105     private List<PropertyEntry> extraHeadersEntries;
106 
107 
108     public RemoteRepository()
109     {
110         // no op
111     }
112 
113     public RemoteRepository( String id, String name, String url, String layout )
114     {
115         super( id, name, layout );
116         this.url = url;
117     }
118 
119     public RemoteRepository( String id, String name, String url, String layout, String userName, String password,
120                              int timeout )
121     {
122         super( id, name, layout );
123         this.url = StringUtils.stripEnd(url,"/");
124         this.userName = userName;
125         this.password = password;
126         this.timeout = timeout;
127     }
128 
129     /**
130      * @since 1.4-M3
131      */
132     public RemoteRepository( String id, String name, String url, String layout, String userName, String password,
133                              int timeout, String description )
134     {
135         this( id, name, url, layout, userName, password, timeout );
136         setDescription( description );
137     }
138 
139     public String getUrl()
140     {
141         return url;
142     }
143 
144     public void setUrl( String url )
145     {
146         this.url = StringUtils.stripEnd(url,"/");
147     }
148 
149     public String getUserName()
150     {
151         return userName;
152     }
153 
154     public void setUserName( String userName )
155     {
156         this.userName = userName;
157     }
158 
159     public String getPassword()
160     {
161         return password;
162     }
163 
164     public void setPassword( String password )
165     {
166         this.password = password;
167     }
168 
169     public int getTimeout()
170     {
171         return timeout;
172     }
173 
174     public void setTimeout( int timeout )
175     {
176         this.timeout = timeout;
177     }
178 
179     public boolean isDownloadRemoteIndex()
180     {
181         return downloadRemoteIndex;
182     }
183 
184     public void setDownloadRemoteIndex( boolean downloadRemoteIndex )
185     {
186         this.downloadRemoteIndex = downloadRemoteIndex;
187     }
188 
189     public String getRemoteIndexUrl()
190     {
191         return remoteIndexUrl;
192     }
193 
194     public void setRemoteIndexUrl( String remoteIndexUrl )
195     {
196         this.remoteIndexUrl = remoteIndexUrl;
197     }
198 
199     public String getRemoteDownloadNetworkProxyId()
200     {
201         return remoteDownloadNetworkProxyId;
202     }
203 
204     public void setRemoteDownloadNetworkProxyId( String remoteDownloadNetworkProxyId )
205     {
206         this.remoteDownloadNetworkProxyId = remoteDownloadNetworkProxyId;
207     }
208 
209     public String getCronExpression()
210     {
211         return cronExpression;
212     }
213 
214     public void setCronExpression( String cronExpression )
215     {
216         this.cronExpression = cronExpression;
217     }
218 
219     public int getRemoteDownloadTimeout()
220     {
221         return remoteDownloadTimeout;
222     }
223 
224     public void setRemoteDownloadTimeout( int remoteDownloadTimeout )
225     {
226         this.remoteDownloadTimeout = remoteDownloadTimeout;
227     }
228 
229     public boolean isDownloadRemoteIndexOnStartup()
230     {
231         return downloadRemoteIndexOnStartup;
232     }
233 
234     public void setDownloadRemoteIndexOnStartup( boolean downloadRemoteIndexOnStartup )
235     {
236         this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup;
237     }
238 
239     public Map<String, String> getExtraParameters()
240     {
241         if ( this.extraParameters == null )
242         {
243             this.extraParameters = new HashMap<>();
244         }
245         return extraParameters;
246     }
247 
248     public void setExtraParameters( Map<String, String> extraParameters )
249     {
250         this.extraParameters = extraParameters;
251     }
252 
253     public void addExtraParameter( String key, String value )
254     {
255         getExtraParameters().put( key, value );
256     }
257 
258     public List<PropertyEntry> getExtraParametersEntries()
259     {
260         this.extraParametersEntries = new ArrayList<>();
261         for ( Map.Entry<String, String> entry : getExtraParameters().entrySet() )
262         {
263             this.extraParametersEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
264         }
265         return this.extraParametersEntries;
266     }
267 
268     public void setExtraParametersEntries( List<PropertyEntry> extraParametersEntries )
269     {
270         if ( extraParametersEntries == null )
271         {
272             return;
273         }
274 
275         this.extraParametersEntries = extraParametersEntries;
276         for ( PropertyEntry propertyEntry : extraParametersEntries )
277         {
278             this.addExtraParameter( propertyEntry.getKey(), propertyEntry.getValue() );
279         }
280     }
281 
282     public Map<String, String> getExtraHeaders()
283     {
284         if ( this.extraHeaders == null )
285         {
286             this.extraHeaders = new HashMap<>();
287         }
288         return extraHeaders;
289     }
290 
291     public void setExtraHeaders( Map<String, String> extraHeaders )
292     {
293         this.extraHeaders = extraHeaders;
294     }
295 
296     public void addExtraHeader( String key, String value )
297     {
298         getExtraHeaders().put( key, value );
299     }
300 
301     public List<PropertyEntry> getExtraHeadersEntries()
302     {
303         this.extraHeadersEntries = new ArrayList<>();
304         for ( Map.Entry<String, String> entry : getExtraHeaders().entrySet() )
305         {
306             this.extraHeadersEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
307         }
308         return this.extraHeadersEntries;
309     }
310 
311     public void setExtraHeadersEntries( List<PropertyEntry> extraHeadersEntries )
312     {
313         if ( extraHeadersEntries == null )
314         {
315             return;
316         }
317 
318         this.extraHeadersEntries = extraHeadersEntries;
319         for ( PropertyEntry propertyEntry : extraHeadersEntries )
320         {
321             this.addExtraHeader( propertyEntry.getKey(), propertyEntry.getValue() );
322         }
323     }
324 
325     public void setCheckPath(String checkPath) {
326         if (checkPath==null) {
327             this.checkPath="";
328         } else if (checkPath.startsWith("/")) {
329             this.checkPath = StringUtils.removeStart(checkPath, "/");
330             while(this.checkPath.startsWith("/")) {
331                 this.checkPath = StringUtils.removeStart(checkPath, "/");
332             }
333         } else {
334             this.checkPath = checkPath;
335         }
336     }
337 
338     public String getCheckPath() {
339         return checkPath;
340     }
341 
342     @Override
343     public String toString()
344     {
345         final StringBuilder sb = new StringBuilder();
346         sb.append( super.toString() );
347         sb.append( "RemoteRepository" );
348         sb.append( "{url='" ).append( url ).append( '\'' );
349         sb.append( ", userName='" ).append( userName ).append( '\'' );
350         sb.append( ", password='" ).append( password ).append( '\'' );
351         sb.append( ", timeout=" ).append( timeout );
352         sb.append( ", downloadRemoteIndex=" ).append( downloadRemoteIndex );
353         sb.append( ", remoteIndexUrl='" ).append( remoteIndexUrl ).append( '\'' );
354         sb.append( ", remoteDownloadNetworkProxyId='" ).append( remoteDownloadNetworkProxyId ).append( '\'' );
355         sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' );
356         sb.append( ", remoteDownloadTimeout=" ).append( remoteDownloadTimeout );
357         sb.append( ", downloadRemoteIndexOnStartup=" ).append( downloadRemoteIndexOnStartup );
358         sb.append( ", extraParameters=" ).append( extraParameters );
359         sb.append( ", extraHeaders=" ).append( extraHeaders );
360         sb.append( ", checkPath=").append(checkPath);
361         sb.append( '}' );
362         return sb.toString();
363     }
364 
365 
366 }