1 package org.apache.archiva.proxy.model;
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.archiva.policies.Policy;
23 import org.apache.archiva.policies.PolicyOption;
24 import org.apache.archiva.repository.ManagedRepository;
25 import org.apache.archiva.repository.RemoteRepository;
26 import org.apache.archiva.repository.connector.RepositoryConnector;
27
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31
32 /**
33 * This represents a connector for a repository to a remote repository that is proxied.
34 */
35 public class ProxyConnector
36 implements RepositoryConnector
37 {
38 private ManagedRepository sourceRepository;
39
40 private RemoteRepository targetRepository;
41
42 private List<String> blacklist;
43
44 private List<String> whitelist;
45
46 private String proxyId;
47
48 private int order;
49
50 private Map<Policy, PolicyOption> policies;
51
52 private boolean enabled;
53
54 private Map<String, String> properties;
55
56 public ProxyConnector()
57 {
58 // no op
59 }
60
61 /**
62 * @see RepositoryConnector#isEnabled()
63 */
64 @Override
65 public boolean isEnabled()
66 {
67 return enabled;
68 }
69
70
71 /**
72 * @see RepositoryConnector#enable()
73 */
74 @Override
75 public void enable()
76 {
77 this.enabled = true;
78 }
79
80 /**
81 * @see RepositoryConnector#disable()
82 */
83 @Override
84 public void disable( )
85 {
86 this.enabled = false;
87 }
88
89 /**
90 * @see RepositoryConnector#getBlacklist()
91 */
92 @Override
93 public List<String> getBlacklist()
94 {
95 return blacklist;
96 }
97
98 /**
99 * 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 }