1 package org.apache.archiva.admin.repository.remote;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
21 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
22 import org.apache.archiva.admin.repository.RepositoryAdminException;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.maven.archiva.configuration.Configuration;
25 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
26 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
27 import org.springframework.stereotype.Service;
29 import java.util.ArrayList;
30 import java.util.List;
33 * @author Olivier Lamy
36 @Service( "remoteRepositoryAdmin#default" )
37 public class DefaultRemoteRepositoryAdmin
38 extends AbstractRepositoryAdmin
39 implements RemoteRepositoryAdmin
43 public List<RemoteRepository> getRemoteRepositories()
44 throws RepositoryAdminException
46 List<RemoteRepository> remoteRepositories = new ArrayList<RemoteRepository>();
47 for ( RemoteRepositoryConfiguration repositoryConfiguration : getArchivaConfiguration().getConfiguration().getRemoteRepositories() )
49 remoteRepositories.add(
50 new RemoteRepository( repositoryConfiguration.getId(), repositoryConfiguration.getName(),
51 repositoryConfiguration.getUrl(), repositoryConfiguration.getLayout(),
52 repositoryConfiguration.getUsername(), repositoryConfiguration.getPassword(),
53 repositoryConfiguration.getTimeout() ) );
55 return remoteRepositories;
58 public RemoteRepository getRemoteRepository( String repositoryId )
59 throws RepositoryAdminException
61 for ( RemoteRepository remoteRepository : getRemoteRepositories() )
63 if ( StringUtils.equals( repositoryId, remoteRepository.getId() ) )
65 return remoteRepository;
71 public Boolean addRemoteRepository( RemoteRepository remoteRepository )
72 throws RepositoryAdminException
74 getRepositoryCommonValidator().basicValidation( remoteRepository, false );
76 //TODO we can validate it's a good uri/url
77 if ( StringUtils.isEmpty( remoteRepository.getUrl() ) )
79 throw new RepositoryAdminException( "url cannot be null" );
82 //MRM-752 - url needs trimming
83 remoteRepository.setUrl( StringUtils.trim( remoteRepository.getUrl() ) );
85 RemoteRepositoryConfiguration remoteRepositoryConfiguration = new RemoteRepositoryConfiguration();
86 remoteRepositoryConfiguration.setId( remoteRepository.getId() );
87 remoteRepositoryConfiguration.setPassword( remoteRepository.getPassword() );
88 remoteRepositoryConfiguration.setTimeout( remoteRepository.getTimeout() );
89 remoteRepositoryConfiguration.setUrl( remoteRepository.getUrl() );
90 remoteRepositoryConfiguration.setUsername( remoteRepository.getUserName() );
91 remoteRepositoryConfiguration.setLayout( remoteRepository.getLayout() );
92 remoteRepositoryConfiguration.setName( remoteRepository.getName() );
94 Configuration configuration = getArchivaConfiguration().getConfiguration();
95 configuration.addRemoteRepository( remoteRepositoryConfiguration );
96 saveConfiguration( configuration );
100 public Boolean deleteRemoteRepository( String repositoryId )
101 throws RepositoryAdminException
103 Configuration configuration = getArchivaConfiguration().getConfiguration();
105 RemoteRepositoryConfiguration remoteRepositoryConfiguration =
106 configuration.getRemoteRepositoriesAsMap().get( repositoryId );
107 if ( remoteRepositoryConfiguration == null )
109 throw new RepositoryAdminException(
110 "remoteRepository with id " + repositoryId + " not exist cannot remove it" );
113 configuration.removeRemoteRepository( remoteRepositoryConfiguration );
115 // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
116 List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
117 for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
119 if ( StringUtils.equals( proxyConnector.getTargetRepoId(), repositoryId ) )
121 configuration.removeProxyConnector( proxyConnector );
125 saveConfiguration( configuration );
130 public Boolean updateRemoteRepository( RemoteRepository remoteRepository )
131 throws RepositoryAdminException
133 return null; //To change body of implemented methods use File | Settings | File Templates.