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