001 package org.apache.archiva.admin.model.beans; 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 022 import javax.xml.bind.annotation.XmlRootElement; 023 import java.io.Serializable; 024 import java.util.ArrayList; 025 import java.util.HashMap; 026 import java.util.List; 027 import java.util.Map; 028 029 /** 030 * @author Olivier Lamy 031 * @since 1.4-M1 032 */ 033 @XmlRootElement (name = "remoteRepository") 034 public class RemoteRepository 035 extends AbstractRepository 036 implements Serializable 037 { 038 039 private String url; 040 041 private String userName; 042 043 private String password; 044 045 private int timeout = 60; 046 047 /** 048 * Activate download of remote index if remoteIndexUrl is set too. 049 */ 050 private boolean downloadRemoteIndex = false; 051 052 /** 053 * Remote Index Url : if not starting with http will be relative to the remote repository url. 054 */ 055 private String remoteIndexUrl = ".index"; 056 057 private String remoteDownloadNetworkProxyId; 058 059 /** 060 * default model value daily : every sunday at 8H00 061 */ 062 private String cronExpression = "0 0 08 ? * SUN"; 063 064 private int remoteDownloadTimeout = 300; 065 066 /** 067 * @since 1.4-M2 068 */ 069 private boolean downloadRemoteIndexOnStartup = false; 070 071 /** 072 * extraParameters. 073 * 074 * @since 1.4-M4 075 */ 076 private Map<String, String> extraParameters; 077 078 /** 079 * field to ease json mapping wrapper on <code>extraParameters</code> field 080 * 081 * @since 1.4-M4 082 */ 083 private List<PropertyEntry> extraParametersEntries; 084 085 /** 086 * extraHeaders. 087 * 088 * @since 1.4-M4 089 */ 090 private Map<String, String> extraHeaders; 091 092 /** 093 * field to ease json mapping wrapper on <code>extraHeaders</code> field 094 * 095 * @since 1.4-M4 096 */ 097 private List<PropertyEntry> extraHeadersEntries; 098 099 100 public RemoteRepository() 101 { 102 // no op 103 } 104 105 public RemoteRepository( String id, String name, String url, String layout ) 106 { 107 super( id, name, layout ); 108 this.url = url; 109 } 110 111 public RemoteRepository( String id, String name, String url, String layout, String userName, String password, 112 int timeout ) 113 { 114 super( id, name, layout ); 115 this.url = url; 116 this.userName = userName; 117 this.password = password; 118 this.timeout = timeout; 119 } 120 121 /** 122 * @since 1.4-M3 123 */ 124 public RemoteRepository( String id, String name, String url, String layout, String userName, String password, 125 int timeout, String description ) 126 { 127 this( id, name, url, layout, userName, password, timeout ); 128 setDescription( description ); 129 } 130 131 public String getUrl() 132 { 133 return url; 134 } 135 136 public void setUrl( String url ) 137 { 138 this.url = url; 139 } 140 141 public String getUserName() 142 { 143 return userName; 144 } 145 146 public void setUserName( String userName ) 147 { 148 this.userName = userName; 149 } 150 151 public String getPassword() 152 { 153 return password; 154 } 155 156 public void setPassword( String password ) 157 { 158 this.password = password; 159 } 160 161 public int getTimeout() 162 { 163 return timeout; 164 } 165 166 public void setTimeout( int timeout ) 167 { 168 this.timeout = timeout; 169 } 170 171 public boolean isDownloadRemoteIndex() 172 { 173 return downloadRemoteIndex; 174 } 175 176 public void setDownloadRemoteIndex( boolean downloadRemoteIndex ) 177 { 178 this.downloadRemoteIndex = downloadRemoteIndex; 179 } 180 181 public String getRemoteIndexUrl() 182 { 183 return remoteIndexUrl; 184 } 185 186 public void setRemoteIndexUrl( String remoteIndexUrl ) 187 { 188 this.remoteIndexUrl = remoteIndexUrl; 189 } 190 191 public String getRemoteDownloadNetworkProxyId() 192 { 193 return remoteDownloadNetworkProxyId; 194 } 195 196 public void setRemoteDownloadNetworkProxyId( String remoteDownloadNetworkProxyId ) 197 { 198 this.remoteDownloadNetworkProxyId = remoteDownloadNetworkProxyId; 199 } 200 201 public String getCronExpression() 202 { 203 return cronExpression; 204 } 205 206 public void setCronExpression( String cronExpression ) 207 { 208 this.cronExpression = cronExpression; 209 } 210 211 public int getRemoteDownloadTimeout() 212 { 213 return remoteDownloadTimeout; 214 } 215 216 public void setRemoteDownloadTimeout( int remoteDownloadTimeout ) 217 { 218 this.remoteDownloadTimeout = remoteDownloadTimeout; 219 } 220 221 public boolean isDownloadRemoteIndexOnStartup() 222 { 223 return downloadRemoteIndexOnStartup; 224 } 225 226 public void setDownloadRemoteIndexOnStartup( boolean downloadRemoteIndexOnStartup ) 227 { 228 this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup; 229 } 230 231 public Map<String, String> getExtraParameters() 232 { 233 if ( this.extraParameters == null ) 234 { 235 this.extraParameters = new HashMap<String, String>(); 236 } 237 return extraParameters; 238 } 239 240 public void setExtraParameters( Map<String, String> extraParameters ) 241 { 242 this.extraParameters = extraParameters; 243 } 244 245 public void addExtraParameter( String key, String value ) 246 { 247 getExtraParameters().put( key, value ); 248 } 249 250 public List<PropertyEntry> getExtraParametersEntries() 251 { 252 this.extraParametersEntries = new ArrayList<PropertyEntry>(); 253 for ( Map.Entry<String, String> entry : getExtraParameters().entrySet() ) 254 { 255 this.extraParametersEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) ); 256 } 257 return this.extraParametersEntries; 258 } 259 260 public void setExtraParametersEntries( List<PropertyEntry> extraParametersEntries ) 261 { 262 if ( extraParametersEntries == null ) 263 { 264 return; 265 } 266 267 this.extraParametersEntries = extraParametersEntries; 268 for ( PropertyEntry propertyEntry : extraParametersEntries ) 269 { 270 this.addExtraParameter( propertyEntry.getKey(), propertyEntry.getValue() ); 271 } 272 } 273 274 public Map<String, String> getExtraHeaders() 275 { 276 if ( this.extraHeaders == null ) 277 { 278 this.extraHeaders = new HashMap<String, String>(); 279 } 280 return extraHeaders; 281 } 282 283 public void setExtraHeaders( Map<String, String> extraHeaders ) 284 { 285 this.extraHeaders = extraHeaders; 286 } 287 288 public void addExtraHeader( String key, String value ) 289 { 290 getExtraHeaders().put( key, value ); 291 } 292 293 public List<PropertyEntry> getExtraHeadersEntries() 294 { 295 this.extraHeadersEntries = new ArrayList<PropertyEntry>(); 296 for ( Map.Entry<String, String> entry : getExtraHeaders().entrySet() ) 297 { 298 this.extraHeadersEntries.add( new PropertyEntry( entry.getKey(), entry.getValue() ) ); 299 } 300 return this.extraHeadersEntries; 301 } 302 303 public void setExtraHeadersEntries( List<PropertyEntry> extraHeadersEntries ) 304 { 305 if ( extraHeadersEntries == null ) 306 { 307 return; 308 } 309 310 this.extraHeadersEntries = extraHeadersEntries; 311 for ( PropertyEntry propertyEntry : extraHeadersEntries ) 312 { 313 this.addExtraHeader( propertyEntry.getKey(), propertyEntry.getValue() ); 314 } 315 } 316 317 318 @Override 319 public String toString() 320 { 321 final StringBuilder sb = new StringBuilder(); 322 sb.append( super.toString() ); 323 sb.append( "RemoteRepository" ); 324 sb.append( "{url='" ).append( url ).append( '\'' ); 325 sb.append( ", userName='" ).append( userName ).append( '\'' ); 326 sb.append( ", password='" ).append( password ).append( '\'' ); 327 sb.append( ", timeout=" ).append( timeout ); 328 sb.append( ", downloadRemoteIndex=" ).append( downloadRemoteIndex ); 329 sb.append( ", remoteIndexUrl='" ).append( remoteIndexUrl ).append( '\'' ); 330 sb.append( ", remoteDownloadNetworkProxyId='" ).append( remoteDownloadNetworkProxyId ).append( '\'' ); 331 sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' ); 332 sb.append( ", remoteDownloadTimeout=" ).append( remoteDownloadTimeout ); 333 sb.append( ", downloadRemoteIndexOnStartup=" ).append( downloadRemoteIndexOnStartup ); 334 sb.append( ", extraParameters=" ).append( extraParameters ); 335 sb.append( ", extraHeaders=" ).append( extraHeaders ); 336 sb.append( '}' ); 337 return sb.toString(); 338 } 339 340 341 }