1 package org.apache.archiva.configuration;
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.model.AuditInformation;
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ManagedRepository;
24 import org.apache.archiva.admin.model.beans.NetworkProxy;
25 import org.apache.archiva.admin.model.beans.ProxyConnector;
26 import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
27 import org.apache.archiva.admin.model.beans.RemoteRepository;
28 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
29 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
30 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
31 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorOrderComparator;
32 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
33 import org.apache.archiva.indexer.ArchivaIndexingContext;
34 import org.apache.commons.lang3.StringUtils;
35 import org.modelmapper.ModelMapper;
36 import org.springframework.stereotype.Service;
38 import javax.inject.Inject;
39 import javax.inject.Named;
40 import java.util.ArrayList;
41 import java.util.Collections;
42 import java.util.HashMap;
43 import java.util.Iterator;
44 import java.util.List;
45 import java.util.Locale;
49 * @author Olivier Lamy
52 public class MockRepoAdmin
53 implements RemoteRepositoryAdmin, ManagedRepositoryAdmin, ProxyConnectorAdmin, NetworkProxyAdmin
56 @Named ( "archivaConfiguration#test" )
57 private ArchivaConfiguration archivaConfiguration;
60 public List<RemoteRepository> getRemoteRepositories()
61 throws RepositoryAdminException
63 List<RemoteRepository> remoteRepositories =
64 new ArrayList<>( archivaConfiguration.getConfiguration().getRemoteRepositories().size() );
65 for ( RemoteRepositoryConfiguration repositoryConfiguration : archivaConfiguration.getConfiguration().getRemoteRepositories() )
67 RemoteRepository remoteRepository =
68 new RemoteRepository( Locale.getDefault(), repositoryConfiguration.getId(), repositoryConfiguration.getName(),
69 repositoryConfiguration.getUrl(), repositoryConfiguration.getLayout(),
70 repositoryConfiguration.getUsername(), repositoryConfiguration.getPassword(),
71 repositoryConfiguration.getTimeout() );
72 remoteRepository.setDownloadRemoteIndex( repositoryConfiguration.isDownloadRemoteIndex() );
73 remoteRepository.setRemoteIndexUrl( repositoryConfiguration.getRemoteIndexUrl() );
74 remoteRepository.setCronExpression( repositoryConfiguration.getRefreshCronExpression() );
75 remoteRepository.setIndexDirectory( repositoryConfiguration.getIndexDir() );
76 remoteRepository.setRemoteDownloadNetworkProxyId(
77 repositoryConfiguration.getRemoteDownloadNetworkProxyId() );
78 remoteRepository.setRemoteDownloadTimeout( repositoryConfiguration.getRemoteDownloadTimeout() );
79 remoteRepository.setDownloadRemoteIndexOnStartup(
80 repositoryConfiguration.isDownloadRemoteIndexOnStartup() );
81 remoteRepositories.add( remoteRepository );
83 return remoteRepositories;
87 public RemoteRepository getRemoteRepository( String repositoryId )
88 throws RepositoryAdminException
90 for ( RemoteRepository remoteRepository : getRemoteRepositories() )
92 if ( StringUtils.equals( repositoryId, remoteRepository.getId() ) )
94 return remoteRepository;
101 public Boolean deleteRemoteRepository( String repositoryId, AuditInformation auditInformation )
102 throws RepositoryAdminException
104 return null; //To change body of implemented methods use File | Settings | File Templates.
108 public Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
109 throws RepositoryAdminException
111 return null; //To change body of implemented methods use File | Settings | File Templates.
115 public Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
116 throws RepositoryAdminException
118 return null; //To change body of implemented methods use File | Settings | File Templates.
122 public Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
123 throws RepositoryAdminException
125 return null; //To change body of implemented methods use File | Settings | File Templates.
129 public ArchivaIndexingContext createIndexContext( RemoteRepository repository )
130 throws RepositoryAdminException
132 return null; //To change body of implemented methods use File | Settings | File Templates.
136 public List<ManagedRepository> getManagedRepositories()
137 throws RepositoryAdminException
139 return null; //To change body of implemented methods use File | Settings | File Templates.
143 public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
144 throws RepositoryAdminException
146 return null; //To change body of implemented methods use File | Settings | File Templates.
150 public ManagedRepository getManagedRepository( String repositoryId )
151 throws RepositoryAdminException
153 for ( ManagedRepositoryConfiguration repoConfig : archivaConfiguration.getConfiguration().getManagedRepositories() )
155 if ( StringUtils.equals( repositoryId, repoConfig.getId() ) )
157 return new ManagedRepository( Locale.getDefault(), repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
158 repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
159 repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
160 repoConfig.getIndexDir(), repoConfig.isScanned(),
161 repoConfig.getRetentionPeriod(), repoConfig.getRetentionCount(),
162 repoConfig.isDeleteReleasedSnapshots(), false );
169 public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
170 boolean deleteContent )
171 throws RepositoryAdminException
173 return null; //To change body of implemented methods use File | Settings | File Templates.
177 public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
178 AuditInformation auditInformation )
179 throws RepositoryAdminException
181 return null; //To change body of implemented methods use File | Settings | File Templates.
185 public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
186 AuditInformation auditInformation, boolean resetStats )
187 throws RepositoryAdminException
189 return null; //To change body of implemented methods use File | Settings | File Templates.
194 public List<ProxyConnector> getProxyConnectors()
195 throws RepositoryAdminException
197 List<ProxyConnectorConfiguration> proxyConnectorConfigurations =
198 archivaConfiguration.getConfiguration().getProxyConnectors();
199 List<ProxyConnector> proxyConnectors = new ArrayList<>( proxyConnectorConfigurations.size() );
200 for ( ProxyConnectorConfiguration configuration : proxyConnectorConfigurations )
202 proxyConnectors.add( getProxyConnector( configuration ) );
204 Collections.sort( proxyConnectors, ProxyConnectorOrderComparator.getInstance() );
205 return proxyConnectors;
209 public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
210 throws RepositoryAdminException
212 return null; //To change body of implemented methods use File | Settings | File Templates.
216 public Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
217 throws RepositoryAdminException
219 return null; //To change body of implemented methods use File | Settings | File Templates.
223 public Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
224 throws RepositoryAdminException
226 return null; //To change body of implemented methods use File | Settings | File Templates.
230 public Boolean updateProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
231 throws RepositoryAdminException
237 public Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
238 throws RepositoryAdminException
240 Map<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<>();
242 Iterator<ProxyConnector> it = getProxyConnectors().iterator();
243 while ( it.hasNext() )
245 ProxyConnector proxyConfig = it.next();
246 String key = proxyConfig.getSourceRepoId();
248 List<ProxyConnector> connectors = proxyConnectorMap.get( key );
249 if ( connectors == null )
251 connectors = new ArrayList<>( 1 );
252 proxyConnectorMap.put( key, connectors );
255 connectors.add( proxyConfig );
257 Collections.sort( connectors, ProxyConnectorOrderComparator.getInstance() );
260 return proxyConnectorMap;
264 public List<NetworkProxy> getNetworkProxies()
265 throws RepositoryAdminException
267 return null; //To change body of implemented methods use File | Settings | File Templates.
271 public NetworkProxy getNetworkProxy( String networkProxyId )
272 throws RepositoryAdminException
274 return null; //To change body of implemented methods use File | Settings | File Templates.
278 public void addNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
279 throws RepositoryAdminException
281 //To change body of implemented methods use File | Settings | File Templates.
285 public void updateNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
286 throws RepositoryAdminException
288 //To change body of implemented methods use File | Settings | File Templates.
292 public void deleteNetworkProxy( String networkProxyId, AuditInformation auditInformation )
293 throws RepositoryAdminException
295 //To change body of implemented methods use File | Settings | File Templates.
298 protected ProxyConnector getProxyConnector( ProxyConnectorConfiguration proxyConnectorConfiguration )
300 return proxyConnectorConfiguration == null
302 : new ModelMapper().map( proxyConnectorConfiguration, ProxyConnector.class );
305 public List<ProxyConnectorRule> getProxyConnectorRules()
306 throws RepositoryAdminException
311 public void addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
312 throws RepositoryAdminException
317 public void deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
318 throws RepositoryAdminException
323 public void updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
324 throws RepositoryAdminException