You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractRepositoryConnector.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. import org.apache.archiva.admin.model.beans.PropertyEntry;
  21. import java.io.Serializable;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * @author Olivier Lamy
  28. * @since 1.4-M1
  29. */
  30. public abstract class AbstractRepositoryConnector
  31. implements Serializable
  32. {
  33. /**
  34. * The Repository Source for this connector.
  35. */
  36. private String sourceRepoId;
  37. /**
  38. * The Repository Target for this connector.
  39. */
  40. private String targetRepoId;
  41. /**
  42. * The network proxy ID to use for this connector.
  43. */
  44. private String proxyId;
  45. /**
  46. * Field blackListPatterns.
  47. */
  48. private List<String> blackListPatterns;
  49. /**
  50. * Field whiteListPatterns.
  51. */
  52. private List<String> whiteListPatterns;
  53. /**
  54. * Field policies.
  55. */
  56. private Map<String, String> policies;
  57. /**
  58. * field to ease json mapping wrapper on <code>policies</code> field
  59. *
  60. * @since 1.4-M3
  61. */
  62. private List<PropertyEntry> policiesEntries;
  63. /**
  64. * Field properties.
  65. */
  66. private Map<String, String> properties;
  67. /**
  68. * field to ease json mapping wrapper on <code>properties</code> field
  69. *
  70. * @since 1.4-M3
  71. */
  72. private List<PropertyEntry> propertiesEntries;
  73. /**
  74. * If the the repository proxy connector is disabled or not
  75. */
  76. private boolean disabled = false;
  77. //-----------/
  78. //- Methods -/
  79. //-----------/
  80. /**
  81. * Method addBlackListPattern.
  82. *
  83. * @param string
  84. */
  85. public void addBlackListPattern( String string )
  86. {
  87. getBlackListPatterns().add( string );
  88. }
  89. /**
  90. * Method addPolicy.
  91. *
  92. * @param key
  93. * @param value
  94. */
  95. public void addPolicy( String key, String value )
  96. {
  97. getPolicies().put( key, value );
  98. }
  99. /**
  100. * Method addProperty.
  101. *
  102. * @param key
  103. * @param value
  104. */
  105. public void addProperty( String key, String value )
  106. {
  107. getProperties().put( key, value );
  108. }
  109. /**
  110. * Method addWhiteListPattern.
  111. *
  112. * @param string
  113. */
  114. public void addWhiteListPattern( String string )
  115. {
  116. getWhiteListPatterns().add( string );
  117. }
  118. /**
  119. * Method getBlackListPatterns.
  120. *
  121. * @return List
  122. */
  123. public List<String> getBlackListPatterns()
  124. {
  125. if ( this.blackListPatterns == null )
  126. {
  127. this.blackListPatterns = new ArrayList<>( 0 );
  128. }
  129. return this.blackListPatterns;
  130. }
  131. /**
  132. * Method getPolicies.
  133. *
  134. * @return Map
  135. */
  136. public Map<String, String> getPolicies()
  137. {
  138. if ( this.policies == null )
  139. {
  140. this.policies = new HashMap<String, String>();
  141. }
  142. return this.policies;
  143. }
  144. /**
  145. * Method getProperties.
  146. *
  147. * @return Map
  148. */
  149. public Map<String, String> getProperties()
  150. {
  151. if ( this.properties == null )
  152. {
  153. this.properties = new HashMap<String, String>();
  154. }
  155. return this.properties;
  156. }
  157. /**
  158. * Get the network proxy ID to use for this connector.
  159. *
  160. * @return String
  161. */
  162. public String getProxyId()
  163. {
  164. return this.proxyId;
  165. }
  166. /**
  167. * Get the Repository Source for this connector.
  168. *
  169. * @return String
  170. */
  171. public String getSourceRepoId()
  172. {
  173. return this.sourceRepoId;
  174. }
  175. /**
  176. * Get the Repository Target for this connector.
  177. *
  178. * @return String
  179. */
  180. public String getTargetRepoId()
  181. {
  182. return this.targetRepoId;
  183. }
  184. /**
  185. * Method getWhiteListPatterns.
  186. *
  187. * @return List
  188. */
  189. public List<String> getWhiteListPatterns()
  190. {
  191. if ( this.whiteListPatterns == null )
  192. {
  193. this.whiteListPatterns = new ArrayList<>( 0 );
  194. }
  195. return this.whiteListPatterns;
  196. }
  197. /**
  198. * Get if the the repository proxy connector is disabled or not
  199. * .
  200. *
  201. * @return boolean
  202. */
  203. public boolean isDisabled()
  204. {
  205. return this.disabled;
  206. }
  207. /**
  208. * Method removeBlackListPattern.
  209. *
  210. * @param string
  211. */
  212. public void removeBlackListPattern( String string )
  213. {
  214. getBlackListPatterns().remove( string );
  215. }
  216. /**
  217. * Method removeWhiteListPattern.
  218. *
  219. * @param string
  220. */
  221. public void removeWhiteListPattern( String string )
  222. {
  223. getWhiteListPatterns().remove( string );
  224. }
  225. /**
  226. * Set the list of blacklisted patterns for this connector.
  227. *
  228. * @param blackListPatterns
  229. */
  230. public void setBlackListPatterns( List<String> blackListPatterns )
  231. {
  232. this.blackListPatterns = blackListPatterns;
  233. }
  234. /**
  235. * Set if the the repository proxy connector is
  236. * disabled or not
  237. * .
  238. *
  239. * @param disabled
  240. */
  241. public void setDisabled( boolean disabled )
  242. {
  243. this.disabled = disabled;
  244. }
  245. /**
  246. * Set policy configuration for the connector.
  247. *
  248. * @param policies
  249. */
  250. public void setPolicies( Map<String, String> policies )
  251. {
  252. this.policies = policies;
  253. }
  254. /**
  255. * Set configuration for the connector.
  256. *
  257. * @param properties
  258. */
  259. public void setProperties( Map<String, String> properties )
  260. {
  261. this.properties = properties;
  262. }
  263. /**
  264. * Set the network proxy ID to use for this connector.
  265. *
  266. * @param proxyId
  267. */
  268. public void setProxyId( String proxyId )
  269. {
  270. this.proxyId = proxyId;
  271. }
  272. /**
  273. * Set the Repository Source for this connector.
  274. *
  275. * @param sourceRepoId
  276. */
  277. public void setSourceRepoId( String sourceRepoId )
  278. {
  279. this.sourceRepoId = sourceRepoId;
  280. }
  281. /**
  282. * Set the Repository Target for this connector.
  283. *
  284. * @param targetRepoId
  285. */
  286. public void setTargetRepoId( String targetRepoId )
  287. {
  288. this.targetRepoId = targetRepoId;
  289. }
  290. /**
  291. * Set
  292. * The list of whitelisted patterns for this
  293. * connector.
  294. *
  295. * @param whiteListPatterns
  296. */
  297. public void setWhiteListPatterns( List<String> whiteListPatterns )
  298. {
  299. this.whiteListPatterns = whiteListPatterns;
  300. }
  301. /**
  302. * Obtain a specific policy from the underlying connector.
  303. *
  304. * @param policyId the policy id to fetch.
  305. * @param defaultValue the default value for the policy id.
  306. * @return the configured policy value (or default value if not found).
  307. */
  308. public String getPolicy( String policyId, String defaultValue )
  309. {
  310. if ( this.getPolicies() == null )
  311. {
  312. return null;
  313. }
  314. String value = this.getPolicies().get( policyId );
  315. if ( value == null )
  316. {
  317. return defaultValue;
  318. }
  319. return value;
  320. }
  321. public List<PropertyEntry> getPoliciesEntries()
  322. {
  323. policiesEntries = new ArrayList<>( getPolicies().size() );
  324. for ( Map.Entry<String, String> entry : getPolicies().entrySet() )
  325. {
  326. policiesEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
  327. }
  328. return policiesEntries;
  329. }
  330. public void setPoliciesEntries( List<PropertyEntry> policiesEntries )
  331. {
  332. for ( PropertyEntry propertyEntry : policiesEntries )
  333. {
  334. addPolicy( propertyEntry.getKey(), propertyEntry.getValue() );
  335. }
  336. }
  337. public List<PropertyEntry> getPropertiesEntries()
  338. {
  339. propertiesEntries = new ArrayList<>( getProperties().size() );
  340. for ( Map.Entry<String, String> entry : getProperties().entrySet() )
  341. {
  342. propertiesEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
  343. }
  344. return propertiesEntries;
  345. }
  346. public void setPropertiesEntries( List<PropertyEntry> propertiesEntries )
  347. {
  348. for ( PropertyEntry propertyEntry : propertiesEntries )
  349. {
  350. addProperty( propertyEntry.getKey(), propertyEntry.getValue() );
  351. }
  352. }
  353. @Override
  354. public boolean equals( Object o )
  355. {
  356. if ( this == o )
  357. {
  358. return true;
  359. }
  360. if ( o == null || getClass() != o.getClass() )
  361. {
  362. return false;
  363. }
  364. AbstractRepositoryConnector that = (AbstractRepositoryConnector) o;
  365. if ( sourceRepoId != null ? !sourceRepoId.equals( that.sourceRepoId ) : that.sourceRepoId != null )
  366. {
  367. return false;
  368. }
  369. if ( targetRepoId != null ? !targetRepoId.equals( that.targetRepoId ) : that.targetRepoId != null )
  370. {
  371. return false;
  372. }
  373. return true;
  374. }
  375. @Override
  376. public int hashCode()
  377. {
  378. int result = sourceRepoId != null ? sourceRepoId.hashCode() : 0;
  379. result = 31 * result + ( targetRepoId != null ? targetRepoId.hashCode() : 0 );
  380. return result;
  381. }
  382. @Override
  383. public String toString()
  384. {
  385. final StringBuilder sb = new StringBuilder();
  386. sb.append( "AbstractRepositoryConnector" );
  387. sb.append( "{sourceRepoId='" ).append( sourceRepoId ).append( '\'' );
  388. sb.append( ", targetRepoId='" ).append( targetRepoId ).append( '\'' );
  389. sb.append( ", proxyId='" ).append( proxyId ).append( '\'' );
  390. sb.append( ", blackListPatterns=" ).append( blackListPatterns );
  391. sb.append( ", whiteListPatterns=" ).append( whiteListPatterns );
  392. sb.append( ", policies=" ).append( policies );
  393. sb.append( ", properties=" ).append( properties );
  394. sb.append( ", disabled=" ).append( disabled );
  395. sb.append( '}' );
  396. return sb.toString();
  397. }
  398. }