1 package org.apache.archiva.rest.services;
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.RepositoryAdminException;
22 import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
23 import org.apache.archiva.rest.api.model.ManagedRepository;
24 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
25 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
26 import org.apache.commons.lang.StringUtils;
27 import org.springframework.stereotype.Service;
29 import javax.inject.Inject;
30 import java.util.ArrayList;
31 import java.util.List;
34 * @author Olivier Lamy
37 @Service( "managedRepositoriesService#rest" )
38 public class DefaultManagedRepositoriesService
39 extends AbstractRestService
40 implements ManagedRepositoriesService
44 private ManagedRepositoryAdmin managedRepositoryAdmin;
46 public List<ManagedRepository> getManagedRepositories()
47 throws ArchivaRestServiceException
51 List<org.apache.archiva.admin.repository.managed.ManagedRepository> repos =
52 managedRepositoryAdmin.getManagedRepositories();
54 List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>( repos.size() );
56 for ( org.apache.archiva.admin.repository.managed.ManagedRepository repoConfig : repos )
58 // TODO staging repo too
59 ManagedRepository repo =
60 new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
61 repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
62 repoConfig.isBlockRedeployments(), false, repoConfig.getCronExpression() );
63 managedRepos.add( repo );
68 catch ( RepositoryAdminException e )
70 throw new ArchivaRestServiceException( e.getMessage() );
74 public ManagedRepository getManagedRepository( String repositoryId )
75 throws ArchivaRestServiceException
77 List<ManagedRepository> repos = getManagedRepositories();
78 for ( ManagedRepository repo : repos )
80 if ( StringUtils.equals( repo.getId(), repositoryId ) )
89 public Boolean deleteManagedRepository( String repoId, boolean deleteContent )
93 return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent );
96 public Boolean addManagedRepository( ManagedRepository managedRepository )
99 org.apache.archiva.admin.repository.managed.ManagedRepository repo =
100 new org.apache.archiva.admin.repository.managed.ManagedRepository();
101 repo.setLocation( managedRepository.getLocation() );
102 repo.setBlockRedeployments( managedRepository.isBlockRedeployments() );
103 repo.setCronExpression( managedRepository.getCronExpression() );
104 repo.setId( managedRepository.getId() );
105 repo.setLayout( managedRepository.getLayout() );
106 repo.setName( managedRepository.getName() );
107 repo.setReleases( managedRepository.isReleases() );
108 repo.setSnapshots( managedRepository.isSnapshots() );
109 return managedRepositoryAdmin.addManagedRepository( repo, managedRepository.isStageRepoNeeded(),
110 getAuditInformation() );
114 public Boolean updateManagedRepository( ManagedRepository managedRepository )
117 org.apache.archiva.admin.repository.managed.ManagedRepository repo =
118 new org.apache.archiva.admin.repository.managed.ManagedRepository();
119 repo.setLocation( managedRepository.getLocation() );
120 repo.setBlockRedeployments( managedRepository.isBlockRedeployments() );
121 repo.setCronExpression( managedRepository.getCronExpression() );
122 repo.setId( managedRepository.getId() );
123 repo.setLayout( managedRepository.getLayout() );
124 repo.setName( managedRepository.getName() );
125 repo.setReleases( managedRepository.isReleases() );
126 repo.setSnapshots( managedRepository.isSnapshots() );
127 return managedRepositoryAdmin.updateManagedRepository( repo, managedRepository.isStageRepoNeeded(),
128 getAuditInformation(),
129 managedRepository.isResetStats() );