1 package org.apache.archiva.maven.repository.mock.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
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import org.apache.archiva.admin.model.AuditInformation;
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.admin.model.beans.NetworkProxy;
24 import org.apache.archiva.admin.model.beans.ProxyConnector;
25 import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
26 import org.apache.archiva.admin.model.beans.RemoteRepository;
27 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
28 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
29 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
30 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorOrderComparator;
31 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
32 import org.apache.archiva.configuration.ArchivaConfiguration;
33 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
34 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
35 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
36 import org.apache.commons.lang3.StringUtils;
37 import org.modelmapper.ModelMapper;
38 import org.springframework.stereotype.Service;
40 import javax.inject.Inject;
41 import javax.inject.Named;
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.HashMap;
45 import java.util.Iterator;
46 import java.util.List;
47 import java.util.Locale;
51 * @author Olivier Lamy
54 public class MockRepoAdmin
55 implements RemoteRepositoryAdmin, ManagedRepositoryAdmin, ProxyConnectorAdmin, NetworkProxyAdmin
58 @Named ( "archivaConfiguration#test" )
59 private ArchivaConfiguration archivaConfiguration;
62 public List<RemoteRepository> getRemoteRepositories()
63 throws RepositoryAdminException
65 List<RemoteRepository> remoteRepositories =
66 new ArrayList<>( archivaConfiguration.getConfiguration().getRemoteRepositories().size() );
67 for ( RemoteRepositoryConfiguration repositoryConfiguration : archivaConfiguration.getConfiguration().getRemoteRepositories() )
69 RemoteRepository remoteRepository =
70 new RemoteRepository( Locale.getDefault(), repositoryConfiguration.getId(), repositoryConfiguration.getName(),
71 repositoryConfiguration.getUrl(), repositoryConfiguration.getLayout(),
72 repositoryConfiguration.getUsername(), repositoryConfiguration.getPassword(),
73 repositoryConfiguration.getTimeout() );
74 remoteRepository.setDownloadRemoteIndex( repositoryConfiguration.isDownloadRemoteIndex() );
75 remoteRepository.setRemoteIndexUrl( repositoryConfiguration.getRemoteIndexUrl() );
76 remoteRepository.setCronExpression( repositoryConfiguration.getRefreshCronExpression() );
77 remoteRepository.setIndexDirectory( repositoryConfiguration.getIndexDir() );
78 remoteRepository.setRemoteDownloadNetworkProxyId(
79 repositoryConfiguration.getRemoteDownloadNetworkProxyId() );
80 remoteRepository.setRemoteDownloadTimeout( repositoryConfiguration.getRemoteDownloadTimeout() );
81 remoteRepository.setDownloadRemoteIndexOnStartup(
82 repositoryConfiguration.isDownloadRemoteIndexOnStartup() );
83 remoteRepositories.add( remoteRepository );
85 return remoteRepositories;
89 public RemoteRepository getRemoteRepository( String repositoryId )
90 throws RepositoryAdminException
92 for ( RemoteRepository remoteRepository : getRemoteRepositories() )
94 if ( StringUtils.equals( repositoryId, remoteRepository.getId() ) )
96 return remoteRepository;
103 public Boolean deleteRemoteRepository( String repositoryId, AuditInformation auditInformation )
104 throws RepositoryAdminException
106 return null; //To change body of implemented methods use File | Settings | File Templates.
110 public Boolean addRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
111 throws RepositoryAdminException
113 return null; //To change body of implemented methods use File | Settings | File Templates.
117 public Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
118 throws RepositoryAdminException
120 return null; //To change body of implemented methods use File | Settings | File Templates.
124 public Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
125 throws RepositoryAdminException
127 return null; //To change body of implemented methods use File | Settings | File Templates.
131 public List<ManagedRepository> getManagedRepositories()
132 throws RepositoryAdminException
134 return null; //To change body of implemented methods use File | Settings | File Templates.
138 public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
139 throws RepositoryAdminException
141 return null; //To change body of implemented methods use File | Settings | File Templates.
145 public ManagedRepository getManagedRepository( String repositoryId )
146 throws RepositoryAdminException
148 for ( ManagedRepositoryConfiguration repoConfig : archivaConfiguration.getConfiguration().getManagedRepositories() )
150 if ( StringUtils.equals( repositoryId, repoConfig.getId() ) )
152 return new ManagedRepository( Locale.getDefault(), repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
153 repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
154 repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
155 repoConfig.getIndexDir(), repoConfig.isScanned(),
156 repoConfig.getRetentionPeriod(), repoConfig.getRetentionCount(),
157 repoConfig.isDeleteReleasedSnapshots(), false );
164 public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
165 boolean deleteContent )
166 throws RepositoryAdminException
168 return null; //To change body of implemented methods use File | Settings | File Templates.
172 public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
173 AuditInformation auditInformation )
174 throws RepositoryAdminException
176 return null; //To change body of implemented methods use File | Settings | File Templates.
180 public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
181 AuditInformation auditInformation, boolean resetStats )
182 throws RepositoryAdminException
184 return null; //To change body of implemented methods use File | Settings | File Templates.
189 public List<ProxyConnector> getProxyConnectors()
190 throws RepositoryAdminException
192 List<ProxyConnectorConfiguration> proxyConnectorConfigurations =
193 archivaConfiguration.getConfiguration().getProxyConnectors();
194 List<ProxyConnector> proxyConnectors = new ArrayList<>( proxyConnectorConfigurations.size() );
195 for ( ProxyConnectorConfiguration configuration : proxyConnectorConfigurations )
197 proxyConnectors.add( getProxyConnector( configuration ) );
199 Collections.sort( proxyConnectors, ProxyConnectorOrderComparator.getInstance() );
200 return proxyConnectors;
204 public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
205 throws RepositoryAdminException
207 return null; //To change body of implemented methods use File | Settings | File Templates.
211 public Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
212 throws RepositoryAdminException
214 return null; //To change body of implemented methods use File | Settings | File Templates.
218 public Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
219 throws RepositoryAdminException
221 return null; //To change body of implemented methods use File | Settings | File Templates.
225 public Boolean updateProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
226 throws RepositoryAdminException
232 public Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
233 throws RepositoryAdminException
235 Map<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<>();
237 Iterator<ProxyConnector> it = getProxyConnectors().iterator();
238 while ( it.hasNext() )
240 ProxyConnector proxyConfig = it.next();
241 String key = proxyConfig.getSourceRepoId();
243 List<ProxyConnector> connectors = proxyConnectorMap.get( key );
244 if ( connectors == null )
246 connectors = new ArrayList<>( 1 );
247 proxyConnectorMap.put( key, connectors );
250 connectors.add( proxyConfig );
252 Collections.sort( connectors, ProxyConnectorOrderComparator.getInstance() );
255 return proxyConnectorMap;
259 public List<NetworkProxy> getNetworkProxies()
260 throws RepositoryAdminException
262 return null; //To change body of implemented methods use File | Settings | File Templates.
266 public NetworkProxy getNetworkProxy( String networkProxyId )
267 throws RepositoryAdminException
269 return null; //To change body of implemented methods use File | Settings | File Templates.
273 public void addNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
274 throws RepositoryAdminException
276 //To change body of implemented methods use File | Settings | File Templates.
280 public void updateNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
281 throws RepositoryAdminException
283 //To change body of implemented methods use File | Settings | File Templates.
287 public void deleteNetworkProxy( String networkProxyId, AuditInformation auditInformation )
288 throws RepositoryAdminException
290 //To change body of implemented methods use File | Settings | File Templates.
293 protected ProxyConnector getProxyConnector( ProxyConnectorConfiguration proxyConnectorConfiguration )
295 return proxyConnectorConfiguration == null
297 : new ModelMapper().map( proxyConnectorConfiguration, ProxyConnector.class );
300 public List<ProxyConnectorRule> getProxyConnectorRules()
301 throws RepositoryAdminException
306 public void addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
307 throws RepositoryAdminException
312 public void deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
313 throws RepositoryAdminException
318 public void updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
319 throws RepositoryAdminException