This project has retired. For details please refer to its Attic page.
AbstractRepositoryConnector xref
View Javadoc
1   package org.apache.archiva.admin.model;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.archiva.admin.model.beans.PropertyEntry;
22  
23  import java.io.Serializable;
24  import java.util.ArrayList;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  
29  /**
30   * @author Olivier Lamy
31   * @since 1.4-M1
32   */
33  public abstract class AbstractRepositoryConnector
34      implements Serializable
35  {
36      /**
37       * The Repository Source for this connector.
38       */
39      private String sourceRepoId;
40  
41      /**
42       * The Repository Target for this connector.
43       */
44      private String targetRepoId;
45  
46      /**
47       * The network proxy ID to use for this connector.
48       */
49      private String proxyId;
50  
51      /**
52       * Field blackListPatterns.
53       */
54      private List<String> blackListPatterns;
55  
56      /**
57       * Field whiteListPatterns.
58       */
59      private List<String> whiteListPatterns;
60  
61      /**
62       * Field policies.
63       */
64      private Map<String, String> policies;
65  
66      /**
67       * field to ease json mapping wrapper on <code>policies</code> field
68       *
69       * @since 1.4-M3
70       */
71      private List<PropertyEntry> policiesEntries;
72  
73      /**
74       * Field properties.
75       */
76      private Map<String, String> properties;
77  
78      /**
79       * field to ease json mapping wrapper on <code>properties</code> field
80       *
81       * @since 1.4-M3
82       */
83      private List<PropertyEntry> propertiesEntries;
84  
85      /**
86       * If the the repository proxy connector is disabled or not
87       */
88      private boolean disabled = false;
89  
90      //-----------/
91      //- Methods -/
92      //-----------/
93  
94      /**
95       * Method addBlackListPattern.
96       *
97       * @param string
98       */
99      public void addBlackListPattern( String string )
100     {
101         getBlackListPatterns().add( string );
102     }
103 
104     /**
105      * Method addPolicy.
106      *
107      * @param key
108      * @param value
109      */
110     public void addPolicy( String key, String value )
111     {
112         getPolicies().put( key, value );
113     }
114 
115     /**
116      * Method addProperty.
117      *
118      * @param key
119      * @param value
120      */
121     public void addProperty( String key, String value )
122     {
123         getProperties().put( key, value );
124     }
125 
126     /**
127      * Method addWhiteListPattern.
128      *
129      * @param string
130      */
131     public void addWhiteListPattern( String string )
132     {
133         getWhiteListPatterns().add( string );
134     }
135 
136     /**
137      * Method getBlackListPatterns.
138      *
139      * @return List
140      */
141     public List<String> getBlackListPatterns()
142     {
143         if ( this.blackListPatterns == null )
144         {
145             this.blackListPatterns = new ArrayList<>( 0 );
146         }
147 
148         return this.blackListPatterns;
149     }
150 
151     /**
152      * Method getPolicies.
153      *
154      * @return Map
155      */
156     public Map<String, String> getPolicies()
157     {
158         if ( this.policies == null )
159         {
160             this.policies = new HashMap<>();
161         }
162 
163         return this.policies;
164     }
165 
166     /**
167      * Method getProperties.
168      *
169      * @return Map
170      */
171     public Map<String, String> getProperties()
172     {
173         if ( this.properties == null )
174         {
175             this.properties = new HashMap<>();
176         }
177 
178         return this.properties;
179     }
180 
181     /**
182      * Get the network proxy ID to use for this connector.
183      *
184      * @return String
185      */
186     public String getProxyId()
187     {
188         return this.proxyId;
189     }
190 
191     /**
192      * Get the Repository Source for this connector.
193      *
194      * @return String
195      */
196     public String getSourceRepoId()
197     {
198         return this.sourceRepoId;
199     }
200 
201     /**
202      * Get the Repository Target for this connector.
203      *
204      * @return String
205      */
206     public String getTargetRepoId()
207     {
208         return this.targetRepoId;
209     }
210 
211     /**
212      * Method getWhiteListPatterns.
213      *
214      * @return List
215      */
216     public List<String> getWhiteListPatterns()
217     {
218         if ( this.whiteListPatterns == null )
219         {
220             this.whiteListPatterns = new ArrayList<>( 0 );
221         }
222 
223         return this.whiteListPatterns;
224     }
225 
226     /**
227      * Get if the the repository proxy connector is disabled or not
228      * .
229      *
230      * @return boolean
231      */
232     public boolean isDisabled()
233     {
234         return this.disabled;
235     }
236 
237     /**
238      * Method removeBlackListPattern.
239      *
240      * @param string
241      */
242     public void removeBlackListPattern( String string )
243     {
244         getBlackListPatterns().remove( string );
245     }
246 
247     /**
248      * Method removeWhiteListPattern.
249      *
250      * @param string
251      */
252     public void removeWhiteListPattern( String string )
253     {
254         getWhiteListPatterns().remove( string );
255     }
256 
257     /**
258      * Set the list of blacklisted patterns for this connector.
259      *
260      * @param blackListPatterns
261      */
262     public void setBlackListPatterns( List<String> blackListPatterns )
263     {
264         this.blackListPatterns = blackListPatterns;
265     }
266 
267     /**
268      * Set if the the repository proxy connector is
269      * disabled or not
270      * .
271      *
272      * @param disabled
273      */
274     public void setDisabled( boolean disabled )
275     {
276         this.disabled = disabled;
277     }
278 
279     /**
280      * Set policy configuration for the connector.
281      *
282      * @param policies
283      */
284     public void setPolicies( Map<String, String> policies )
285     {
286         this.policies = policies;
287     }
288 
289     /**
290      * Set configuration for the connector.
291      *
292      * @param properties
293      */
294     public void setProperties( Map<String, String> properties )
295     {
296         this.properties = properties;
297     }
298 
299     /**
300      * Set the network proxy ID to use for this connector.
301      *
302      * @param proxyId
303      */
304     public void setProxyId( String proxyId )
305     {
306         this.proxyId = proxyId;
307     }
308 
309     /**
310      * Set the Repository Source for this connector.
311      *
312      * @param sourceRepoId
313      */
314     public void setSourceRepoId( String sourceRepoId )
315     {
316         this.sourceRepoId = sourceRepoId;
317     }
318 
319     /**
320      * Set the Repository Target for this connector.
321      *
322      * @param targetRepoId
323      */
324     public void setTargetRepoId( String targetRepoId )
325     {
326         this.targetRepoId = targetRepoId;
327     }
328 
329     /**
330      * Set
331      * The list of whitelisted patterns for this
332      * connector.
333      *
334      * @param whiteListPatterns
335      */
336     public void setWhiteListPatterns( List<String> whiteListPatterns )
337     {
338         this.whiteListPatterns = whiteListPatterns;
339     }
340 
341 
342     /**
343      * Obtain a specific policy from the underlying connector.
344      *
345      * @param policyId     the policy id to fetch.
346      * @param defaultValue the default value for the policy id.
347      * @return the configured policy value (or default value if not found).
348      */
349     public String getPolicy( String policyId, String defaultValue )
350     {
351         if ( this.getPolicies() == null )
352         {
353             return null;
354         }
355 
356         String value = this.getPolicies().get( policyId );
357 
358         if ( value == null )
359         {
360             return defaultValue;
361         }
362 
363         return value;
364     }
365 
366     public List<PropertyEntry> getPoliciesEntries()
367     {
368         policiesEntries = new ArrayList<>( getPolicies().size() );
369         for ( Map.Entry<String, String> entry : getPolicies().entrySet() )
370         {
371             policiesEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
372         }
373         return policiesEntries;
374     }
375 
376     public void setPoliciesEntries( List<PropertyEntry> policiesEntries )
377     {
378         for ( PropertyEntry propertyEntry : policiesEntries )
379         {
380             addPolicy( propertyEntry.getKey(), propertyEntry.getValue() );
381         }
382     }
383 
384     public List<PropertyEntry> getPropertiesEntries()
385     {
386         propertiesEntries = new ArrayList<>( getProperties().size() );
387         for ( Map.Entry<String, String> entry : getProperties().entrySet() )
388         {
389             propertiesEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
390         }
391         return propertiesEntries;
392     }
393 
394     public void setPropertiesEntries( List<PropertyEntry> propertiesEntries )
395     {
396         for ( PropertyEntry propertyEntry : propertiesEntries )
397         {
398             addProperty( propertyEntry.getKey(), propertyEntry.getValue() );
399         }
400     }
401 
402     @Override
403     public boolean equals( Object o )
404     {
405         if ( this == o )
406         {
407             return true;
408         }
409         if ( o == null || getClass() != o.getClass() )
410         {
411             return false;
412         }
413 
414         AbstractRepositoryConnectorapache/archiva/admin/model/AbstractRepositoryConnector.html#AbstractRepositoryConnector">AbstractRepositoryConnector that = (AbstractRepositoryConnector) o;
415 
416         if ( sourceRepoId != null ? !sourceRepoId.equals( that.sourceRepoId ) : that.sourceRepoId != null )
417         {
418             return false;
419         }
420         if ( targetRepoId != null ? !targetRepoId.equals( that.targetRepoId ) : that.targetRepoId != null )
421         {
422             return false;
423         }
424 
425         return true;
426     }
427 
428     @Override
429     public int hashCode()
430     {
431         int result = sourceRepoId != null ? sourceRepoId.hashCode() : 0;
432         result = 31 * result + ( targetRepoId != null ? targetRepoId.hashCode() : 0 );
433         return result;
434     }
435 
436     @Override
437     public String toString()
438     {
439         final StringBuilder sb = new StringBuilder();
440         sb.append( "AbstractRepositoryConnector" );
441         sb.append( "{sourceRepoId='" ).append( sourceRepoId ).append( '\'' );
442         sb.append( ", targetRepoId='" ).append( targetRepoId ).append( '\'' );
443         sb.append( ", proxyId='" ).append( proxyId ).append( '\'' );
444         sb.append( ", blackListPatterns=" ).append( blackListPatterns );
445         sb.append( ", whiteListPatterns=" ).append( whiteListPatterns );
446         sb.append( ", policies=" ).append( policies );
447         sb.append( ", properties=" ).append( properties );
448         sb.append( ", disabled=" ).append( disabled );
449         sb.append( '}' );
450         return sb.toString();
451     }
452 }
453