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