This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.proxy.model;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.archiva.policies.Policy;
023import org.apache.archiva.policies.PolicyOption;
024import org.apache.archiva.repository.ManagedRepository;
025import org.apache.archiva.repository.RemoteRepository;
026import org.apache.archiva.repository.connector.RepositoryConnector;
027
028import java.util.Iterator;
029import java.util.List;
030import java.util.Map;
031
032/**
033 * This represents a connector for a repository to a remote repository that is proxied.
034 */
035public class ProxyConnector
036    implements RepositoryConnector
037{
038    private ManagedRepository sourceRepository;
039
040    private RemoteRepository targetRepository;
041
042    private List<String> blacklist;
043
044    private List<String> whitelist;
045
046    private String proxyId;
047
048    private int order;
049
050    private Map<Policy, PolicyOption> policies;
051
052    private boolean enabled;
053
054    private Map<String, String> properties;
055
056    public ProxyConnector()
057    {
058        // no op
059    }
060
061    /**
062     * @see RepositoryConnector#isEnabled()
063     */
064    @Override
065    public boolean isEnabled()
066    {
067        return enabled;
068    }
069
070
071    /**
072     * @see RepositoryConnector#enable()
073     */
074    @Override
075    public void enable()
076    {
077        this.enabled = true;
078    }
079
080    /**
081     * @see RepositoryConnector#disable()
082     */
083    @Override
084    public void disable( )
085    {
086        this.enabled = false;
087    }
088
089    /**
090     * @see RepositoryConnector#getBlacklist()
091     */
092    @Override
093    public List<String> getBlacklist()
094    {
095        return blacklist;
096    }
097
098    /**
099     * Sets the blacklist. The list is a string of paths.
100     *
101     * @param blacklist List of paths.
102     */
103    public void setBlacklist( List<String> blacklist )
104    {
105        this.blacklist = blacklist;
106    }
107
108    /**
109     * @see RepositoryConnector#getSourceRepository()
110     */
111    @Override
112    public ManagedRepository getSourceRepository()
113    {
114        return sourceRepository;
115    }
116
117    /**
118     * Sets the source repository.
119     * @param sourceRepository The managed repository which is the local representation of the proxy.
120     */
121    public void setSourceRepository( ManagedRepository sourceRepository )
122    {
123        this.sourceRepository = sourceRepository;
124    }
125
126    /**
127     * @see ProxyConnector#getTargetRepository()
128     */
129    @Override
130    public RemoteRepository getTargetRepository()
131    {
132        return targetRepository;
133    }
134
135    /**
136     * Sets the target repository.
137     * @param targetRepository The remote repository, where the artifacts are downloaded from.
138     */
139    public void setTargetRepository( RemoteRepository targetRepository )
140    {
141        this.targetRepository = targetRepository;
142    }
143
144    /**
145     * @see ProxyConnector#getWhitelist()
146     */
147    @Override
148    public List<String> getWhitelist()
149    {
150        return whitelist;
151    }
152
153    /**
154     * Sets the list of paths that are proxied.
155     * @param whitelist List of paths.
156     */
157    public void setWhitelist( List<String> whitelist )
158    {
159        this.whitelist = whitelist;
160    }
161
162    /**
163     * Returns the policies that are defined
164     * @return
165     */
166    public Map<Policy, PolicyOption> getPolicies()
167    {
168        return policies;
169    }
170
171    /**
172     * Sets policies that set the behaviour of this proxy connector.
173     * @param policies A map of policies with each option.
174     */
175    public void setPolicies( Map<Policy, PolicyOption> policies )
176    {
177        this.policies = policies;
178    }
179
180    /**
181     * Adds a new policy.
182     * @param policy The policy to add.
183     * @param option  The option for the policy.
184     */
185    public void addPolicy( Policy policy, PolicyOption option )
186    {
187        this.policies.put( policy, option );
188    }
189
190    /**
191     * Returns the id of this proxy connector.
192     * @return The id string.
193     */
194    public String getProxyId()
195    {
196        return proxyId;
197    }
198
199    /**
200     * Sets the id of this proxy connector.
201     * @param proxyId A id string.
202     */
203    public void setProxyId( String proxyId )
204    {
205        this.proxyId = proxyId;
206    }
207
208    @Override
209    public String toString()
210    {
211        StringBuilder sb = new StringBuilder();
212
213        sb.append( "ProxyConnector[\n" );
214        sb.append( "  source: [managed] " ).append( this.sourceRepository.getId() ).append( "\n" );
215        sb.append( "  target: [remote] " ).append( this.targetRepository.getId() ).append( "\n" );
216        sb.append( "  proxyId:" ).append( this.proxyId ).append( "\n" );
217
218        Iterator<Policy> keys = this.policies.keySet().iterator();
219        while ( keys.hasNext() )
220        {
221            String name = keys.next().getId();
222            sb.append( "  policy[" ).append( name ).append( "]:" );
223            sb.append( this.policies.get( name ) ).append( "\n" );
224        }
225
226        sb.append( "]" );
227
228        return sb.toString();
229    }
230
231    /**
232     * Returns a number that orders the proxy connectors numerically.
233     * @return The order number of this connector.
234     */
235    public int getOrder()
236    {
237        return order;
238    }
239
240    /**
241     * Set the order number of this proxy connector.
242     *
243     * @param order The order number.
244     */
245    public void setOrder( int order )
246    {
247        this.order = order;
248    }
249
250    /**
251     * Returns additional properties defined for this connector.
252     * @return Map of key, value pairs.
253     */
254    public Map<String, String> getProperties() {
255        return properties;
256    }
257
258    /**
259     * Sets additional properties for this connector.
260     * @param properties Map of key, value pairs.
261     */
262    public void setProperties(Map<String, String> properties) {
263        this.properties = properties;
264    }
265}