This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.admin.model;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020
021import org.apache.archiva.admin.model.beans.PropertyEntry;
022
023import java.io.Serializable;
024import java.util.ArrayList;
025import java.util.HashMap;
026import java.util.List;
027import java.util.Map;
028
029/**
030 * @author Olivier Lamy
031 * @since 1.4-M1
032 */
033public abstract class AbstractRepositoryConnector
034    implements Serializable
035{
036    /**
037     * The Repository Source for this connector.
038     */
039    private String sourceRepoId;
040
041    /**
042     * The Repository Target for this connector.
043     */
044    private String targetRepoId;
045
046    /**
047     * The network proxy ID to use for this connector.
048     */
049    private String proxyId;
050
051    /**
052     * Field blackListPatterns.
053     */
054    private List<String> blackListPatterns;
055
056    /**
057     * Field whiteListPatterns.
058     */
059    private List<String> whiteListPatterns;
060
061    /**
062     * Field policies.
063     */
064    private Map<String, String> policies;
065
066    /**
067     * field to ease json mapping wrapper on <code>policies</code> field
068     *
069     * @since 1.4-M3
070     */
071    private List<PropertyEntry> policiesEntries;
072
073    /**
074     * Field properties.
075     */
076    private Map<String, String> properties;
077
078    /**
079     * field to ease json mapping wrapper on <code>properties</code> field
080     *
081     * @since 1.4-M3
082     */
083    private List<PropertyEntry> propertiesEntries;
084
085    /**
086     * If the the repository proxy connector is disabled or not
087     */
088    private boolean disabled = false;
089
090    //-----------/
091    //- Methods -/
092    //-----------/
093
094    /**
095     * Method addBlackListPattern.
096     *
097     * @param string
098     */
099    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        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