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.lang3.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.Locale;
30  import java.util.Map;
31  
32  /**
33   * @author Olivier Lamy
34   * @since 1.4-M1
35   */
36  @XmlRootElement (name = "remoteRepository")
37  public class RemoteRepository
38      extends AbstractRepository
39      implements Serializable
40  {
41  
42      private String url;
43  
44      private String userName;
45  
46      private String password;
47  
48      private int timeout = 60;
49  
50      /**
51       * @since 2.2.3
52       * The path to use for checking availability of the remote repository
53       */
54      private String checkPath;
55  
56      /**
57       * Activate download of remote index if remoteIndexUrl is set too.
58       */
59      private boolean downloadRemoteIndex = false;
60  
61      /**
62       * Remote Index Url : if not starting with http will be relative to the remote repository url.
63       */
64      private String remoteIndexUrl = ".index";
65  
66      private String remoteDownloadNetworkProxyId;
67  
68      /**
69       * default model value daily : every sunday at 8H00
70       */
71      private String cronExpression = "0 0 08 ? * SUN";
72  
73      private int remoteDownloadTimeout = 300;
74  
75      /**
76       * @since 1.4-M2
77       */
78      private boolean downloadRemoteIndexOnStartup = false;
79  
80      /**
81       * extraParameters.
82       *
83       * @since 1.4-M4
84       */
85      private Map<String, String> extraParameters;
86  
87      /**
88       * field to ease json mapping wrapper on <code>extraParameters</code> field
89       *
90       * @since 1.4-M4
91       */
92      private List<PropertyEntry> extraParametersEntries;
93  
94      /**
95       * extraHeaders.
96       *
97       * @since 1.4-M4
98       */
99      private Map<String, String> extraHeaders;
100 
101     /**
102      * field to ease json mapping wrapper on <code>extraHeaders</code> field
103      *
104      * @since 1.4-M4
105      */
106     private List<PropertyEntry> extraHeadersEntries;
107 
108     public RemoteRepository() {
109         super(Locale.getDefault());
110     }
111 
112     public RemoteRepository(Locale locale)
113     {
114         super(locale);
115     }
116 
117     public RemoteRepository( Locale locale, String id, String name, String url, String layout )
118     {
119         super( locale, id, name, layout );
120         this.url = url;
121     }
122 
123     public RemoteRepository( Locale locale, String id, String name, String url, String layout, String userName, String password,
124                              int timeout )
125     {
126         super( locale, id, name, layout );
127         this.url = StringUtils.stripEnd(url,"/");
128         this.userName = userName;
129         this.password = password;
130         this.timeout = timeout;
131     }
132 
133     /**
134      * @since 1.4-M3
135      */
136     public RemoteRepository( Locale locale, String id, String name, String url, String layout, String userName, String password,
137                              int timeout, String description )
138     {
139         this( locale, id, name, url, layout, userName, password, timeout );
140         setDescription( description );
141     }
142 
143     public String getUrl()
144     {
145         return url;
146     }
147 
148     public void setUrl( String url )
149     {
150         this.url = StringUtils.stripEnd(url,"/");
151     }
152 
153     public String getUserName()
154     {
155         return userName;
156     }
157 
158     public void setUserName( String userName )
159     {
160         this.userName = userName;
161     }
162 
163     public String getPassword()
164     {
165         return password;
166     }
167 
168     public void setPassword( String password )
169     {
170         this.password = password;
171     }
172 
173     public int getTimeout()
174     {
175         return timeout;
176     }
177 
178     public void setTimeout( int timeout )
179     {
180         this.timeout = timeout;
181     }
182 
183     public boolean isDownloadRemoteIndex()
184     {
185         return downloadRemoteIndex;
186     }
187 
188     public void setDownloadRemoteIndex( boolean downloadRemoteIndex )
189     {
190         this.downloadRemoteIndex = downloadRemoteIndex;
191     }
192 
193     public String getRemoteIndexUrl()
194     {
195         return remoteIndexUrl;
196     }
197 
198     public void setRemoteIndexUrl( String remoteIndexUrl )
199     {
200         this.remoteIndexUrl = remoteIndexUrl;
201     }
202 
203     public String getRemoteDownloadNetworkProxyId()
204     {
205         return remoteDownloadNetworkProxyId;
206     }
207 
208     public void setRemoteDownloadNetworkProxyId( String remoteDownloadNetworkProxyId )
209     {
210         this.remoteDownloadNetworkProxyId = remoteDownloadNetworkProxyId;
211     }
212 
213     public String getCronExpression()
214     {
215         return cronExpression;
216     }
217 
218     public void setCronExpression( String cronExpression )
219     {
220         this.cronExpression = cronExpression;
221     }
222 
223     public int getRemoteDownloadTimeout()
224     {
225         return remoteDownloadTimeout;
226     }
227 
228     public void setRemoteDownloadTimeout( int remoteDownloadTimeout )
229     {
230         this.remoteDownloadTimeout = remoteDownloadTimeout;
231     }
232 
233     public boolean isDownloadRemoteIndexOnStartup()
234     {
235         return downloadRemoteIndexOnStartup;
236     }
237 
238     public void setDownloadRemoteIndexOnStartup( boolean downloadRemoteIndexOnStartup )
239     {
240         this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup;
241     }
242 
243     public Map<String, String> getExtraParameters()
244     {
245         if ( this.extraParameters == null )
246         {
247             this.extraParameters = new HashMap<>();
248         }
249         return extraParameters;
250     }
251 
252     public void setExtraParameters( Map<String, String> extraParameters )
253     {
254         this.extraParameters = extraParameters;
255     }
256 
257     public void addExtraParameter( String key, String value )
258     {
259         getExtraParameters().put( key, value );
260     }
261 
262     public List<PropertyEntry> getExtraParametersEntries()
263     {
264         this.extraParametersEntries = new ArrayList<>();
265         for ( Map.Entry<String, String> entry : getExtraParameters().entrySet() )
266         {
267             this.extraParametersEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
268         }
269         return this.extraParametersEntries;
270     }
271 
272     public void setExtraParametersEntries( List<PropertyEntry> extraParametersEntries )
273     {
274         if ( extraParametersEntries == null )
275         {
276             return;
277         }
278 
279         this.extraParametersEntries = extraParametersEntries;
280         for ( PropertyEntry propertyEntry : extraParametersEntries )
281         {
282             this.addExtraParameter( propertyEntry.getKey(), propertyEntry.getValue() );
283         }
284     }
285 
286     public Map<String, String> getExtraHeaders()
287     {
288         if ( this.extraHeaders == null )
289         {
290             this.extraHeaders = new HashMap<>();
291         }
292         return extraHeaders;
293     }
294 
295     public void setExtraHeaders( Map<String, String> extraHeaders )
296     {
297         this.extraHeaders = extraHeaders;
298     }
299 
300     public void addExtraHeader( String key, String value )
301     {
302         getExtraHeaders().put( key, value );
303     }
304 
305     public List<PropertyEntry> getExtraHeadersEntries()
306     {
307         this.extraHeadersEntries = new ArrayList<>();
308         for ( Map.Entry<String, String> entry : getExtraHeaders().entrySet() )
309         {
310             this.extraHeadersEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
311         }
312         return this.extraHeadersEntries;
313     }
314 
315     public void setExtraHeadersEntries( List<PropertyEntry> extraHeadersEntries )
316     {
317         if ( extraHeadersEntries == null )
318         {
319             return;
320         }
321 
322         this.extraHeadersEntries = extraHeadersEntries;
323         for ( PropertyEntry propertyEntry : extraHeadersEntries )
324         {
325             this.addExtraHeader( propertyEntry.getKey(), propertyEntry.getValue() );
326         }
327     }
328 
329     public void setCheckPath(String checkPath) {
330         if (checkPath==null) {
331             this.checkPath="";
332         } else if (checkPath.startsWith("/")) {
333             this.checkPath = StringUtils.removeStart(checkPath, "/");
334             while(this.checkPath.startsWith("/")) {
335                 this.checkPath = StringUtils.removeStart(checkPath, "/");
336             }
337         } else {
338             this.checkPath = checkPath;
339         }
340     }
341 
342     public String getCheckPath() {
343         return checkPath;
344     }
345 
346     @Override
347     public String toString()
348     {
349         final StringBuilder sb = new StringBuilder();
350         sb.append( super.toString() );
351         sb.append( "RemoteRepository" );
352         sb.append( "{url='" ).append( url ).append( '\'' );
353         sb.append( ", userName='" ).append( userName ).append( '\'' );
354         sb.append( ", password='" ).append( password ).append( '\'' );
355         sb.append( ", timeout=" ).append( timeout );
356         sb.append( ", downloadRemoteIndex=" ).append( downloadRemoteIndex );
357         sb.append( ", remoteIndexUrl='" ).append( remoteIndexUrl ).append( '\'' );
358         sb.append( ", remoteDownloadNetworkProxyId='" ).append( remoteDownloadNetworkProxyId ).append( '\'' );
359         sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' );
360         sb.append( ", remoteDownloadTimeout=" ).append( remoteDownloadTimeout );
361         sb.append( ", downloadRemoteIndexOnStartup=" ).append( downloadRemoteIndexOnStartup );
362         sb.append( ", extraParameters=" ).append( extraParameters );
363         sb.append( ", extraHeaders=" ).append( extraHeaders );
364         sb.append( ", checkPath=").append(checkPath);
365         sb.append( '}' );
366         return sb.toString();
367     }
368 
369 
370 }