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.

RemoteRepository.java 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. package org.apache.archiva.admin.model.beans;
  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 javax.xml.bind.annotation.XmlRootElement;
  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. @XmlRootElement (name = "remoteRepository")
  31. public class RemoteRepository
  32. extends AbstractRepository
  33. implements Serializable
  34. {
  35. private String url;
  36. private String userName;
  37. private String password;
  38. private int timeout = 60;
  39. /**
  40. * Activate download of remote index if remoteIndexUrl is set too.
  41. */
  42. private boolean downloadRemoteIndex = false;
  43. /**
  44. * Remote Index Url : if not starting with http will be relative to the remote repository url.
  45. */
  46. private String remoteIndexUrl = ".index";
  47. private String remoteDownloadNetworkProxyId;
  48. /**
  49. * default model value daily : every sunday at 8H00
  50. */
  51. private String cronExpression = "0 0 08 ? * SUN";
  52. private int remoteDownloadTimeout = 300;
  53. /**
  54. * @since 1.4-M2
  55. */
  56. private boolean downloadRemoteIndexOnStartup = false;
  57. /**
  58. * extraParameters.
  59. *
  60. * @since 1.4-M4
  61. */
  62. private Map<String, String> extraParameters;
  63. /**
  64. * field to ease json mapping wrapper on <code>extraParameters</code> field
  65. *
  66. * @since 1.4-M4
  67. */
  68. private List<PropertyEntry> extraParametersEntries;
  69. /**
  70. * extraHeaders.
  71. *
  72. * @since 1.4-M4
  73. */
  74. private Map<String, String> extraHeaders;
  75. /**
  76. * field to ease json mapping wrapper on <code>extraHeaders</code> field
  77. *
  78. * @since 1.4-M4
  79. */
  80. private List<PropertyEntry> extraHeadersEntries;
  81. public RemoteRepository()
  82. {
  83. // no op
  84. }
  85. public RemoteRepository( String id, String name, String url, String layout )
  86. {
  87. super( id, name, layout );
  88. this.url = url;
  89. }
  90. public RemoteRepository( String id, String name, String url, String layout, String userName, String password,
  91. int timeout )
  92. {
  93. super( id, name, layout );
  94. this.url = url;
  95. this.userName = userName;
  96. this.password = password;
  97. this.timeout = timeout;
  98. }
  99. /**
  100. * @since 1.4-M3
  101. */
  102. public RemoteRepository( String id, String name, String url, String layout, String userName, String password,
  103. int timeout, String description )
  104. {
  105. this( id, name, url, layout, userName, password, timeout );
  106. setDescription( description );
  107. }
  108. public String getUrl()
  109. {
  110. return url;
  111. }
  112. public void setUrl( String url )
  113. {
  114. this.url = url;
  115. }
  116. public String getUserName()
  117. {
  118. return userName;
  119. }
  120. public void setUserName( String userName )
  121. {
  122. this.userName = userName;
  123. }
  124. public String getPassword()
  125. {
  126. return password;
  127. }
  128. public void setPassword( String password )
  129. {
  130. this.password = password;
  131. }
  132. public int getTimeout()
  133. {
  134. return timeout;
  135. }
  136. public void setTimeout( int timeout )
  137. {
  138. this.timeout = timeout;
  139. }
  140. public boolean isDownloadRemoteIndex()
  141. {
  142. return downloadRemoteIndex;
  143. }
  144. public void setDownloadRemoteIndex( boolean downloadRemoteIndex )
  145. {
  146. this.downloadRemoteIndex = downloadRemoteIndex;
  147. }
  148. public String getRemoteIndexUrl()
  149. {
  150. return remoteIndexUrl;
  151. }
  152. public void setRemoteIndexUrl( String remoteIndexUrl )
  153. {
  154. this.remoteIndexUrl = remoteIndexUrl;
  155. }
  156. public String getRemoteDownloadNetworkProxyId()
  157. {
  158. return remoteDownloadNetworkProxyId;
  159. }
  160. public void setRemoteDownloadNetworkProxyId( String remoteDownloadNetworkProxyId )
  161. {
  162. this.remoteDownloadNetworkProxyId = remoteDownloadNetworkProxyId;
  163. }
  164. public String getCronExpression()
  165. {
  166. return cronExpression;
  167. }
  168. public void setCronExpression( String cronExpression )
  169. {
  170. this.cronExpression = cronExpression;
  171. }
  172. public int getRemoteDownloadTimeout()
  173. {
  174. return remoteDownloadTimeout;
  175. }
  176. public void setRemoteDownloadTimeout( int remoteDownloadTimeout )
  177. {
  178. this.remoteDownloadTimeout = remoteDownloadTimeout;
  179. }
  180. public boolean isDownloadRemoteIndexOnStartup()
  181. {
  182. return downloadRemoteIndexOnStartup;
  183. }
  184. public void setDownloadRemoteIndexOnStartup( boolean downloadRemoteIndexOnStartup )
  185. {
  186. this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup;
  187. }
  188. public Map<String, String> getExtraParameters()
  189. {
  190. if ( this.extraParameters == null )
  191. {
  192. this.extraParameters = new HashMap<String, String>();
  193. }
  194. return extraParameters;
  195. }
  196. public void setExtraParameters( Map<String, String> extraParameters )
  197. {
  198. this.extraParameters = extraParameters;
  199. }
  200. public void addExtraParameter( String key, String value )
  201. {
  202. getExtraParameters().put( key, value );
  203. }
  204. public List<PropertyEntry> getExtraParametersEntries()
  205. {
  206. this.extraParametersEntries = new ArrayList<>();
  207. for ( Map.Entry<String, String> entry : getExtraParameters().entrySet() )
  208. {
  209. this.extraParametersEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
  210. }
  211. return this.extraParametersEntries;
  212. }
  213. public void setExtraParametersEntries( List<PropertyEntry> extraParametersEntries )
  214. {
  215. if ( extraParametersEntries == null )
  216. {
  217. return;
  218. }
  219. this.extraParametersEntries = extraParametersEntries;
  220. for ( PropertyEntry propertyEntry : extraParametersEntries )
  221. {
  222. this.addExtraParameter( propertyEntry.getKey(), propertyEntry.getValue() );
  223. }
  224. }
  225. public Map<String, String> getExtraHeaders()
  226. {
  227. if ( this.extraHeaders == null )
  228. {
  229. this.extraHeaders = new HashMap<String, String>();
  230. }
  231. return extraHeaders;
  232. }
  233. public void setExtraHeaders( Map<String, String> extraHeaders )
  234. {
  235. this.extraHeaders = extraHeaders;
  236. }
  237. public void addExtraHeader( String key, String value )
  238. {
  239. getExtraHeaders().put( key, value );
  240. }
  241. public List<PropertyEntry> getExtraHeadersEntries()
  242. {
  243. this.extraHeadersEntries = new ArrayList<>();
  244. for ( Map.Entry<String, String> entry : getExtraHeaders().entrySet() )
  245. {
  246. this.extraHeadersEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) );
  247. }
  248. return this.extraHeadersEntries;
  249. }
  250. public void setExtraHeadersEntries( List<PropertyEntry> extraHeadersEntries )
  251. {
  252. if ( extraHeadersEntries == null )
  253. {
  254. return;
  255. }
  256. this.extraHeadersEntries = extraHeadersEntries;
  257. for ( PropertyEntry propertyEntry : extraHeadersEntries )
  258. {
  259. this.addExtraHeader( propertyEntry.getKey(), propertyEntry.getValue() );
  260. }
  261. }
  262. @Override
  263. public String toString()
  264. {
  265. final StringBuilder sb = new StringBuilder();
  266. sb.append( super.toString() );
  267. sb.append( "RemoteRepository" );
  268. sb.append( "{url='" ).append( url ).append( '\'' );
  269. sb.append( ", userName='" ).append( userName ).append( '\'' );
  270. sb.append( ", password='" ).append( password ).append( '\'' );
  271. sb.append( ", timeout=" ).append( timeout );
  272. sb.append( ", downloadRemoteIndex=" ).append( downloadRemoteIndex );
  273. sb.append( ", remoteIndexUrl='" ).append( remoteIndexUrl ).append( '\'' );
  274. sb.append( ", remoteDownloadNetworkProxyId='" ).append( remoteDownloadNetworkProxyId ).append( '\'' );
  275. sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' );
  276. sb.append( ", remoteDownloadTimeout=" ).append( remoteDownloadTimeout );
  277. sb.append( ", downloadRemoteIndexOnStartup=" ).append( downloadRemoteIndexOnStartup );
  278. sb.append( ", extraParameters=" ).append( extraParameters );
  279. sb.append( ", extraHeaders=" ).append( extraHeaders );
  280. sb.append( '}' );
  281. return sb.toString();
  282. }
  283. }