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.ManagedRepositoriesService;
25 import org.apache.commons.lang.StringUtils;
26 import org.springframework.stereotype.Service;
28 import javax.inject.Inject;
29 import java.util.ArrayList;
30 import java.util.List;
33 * @author Olivier Lamy
36 @Service( "managedRepositoriesService#rest" )
37 public class DefaultManagedRepositoriesService
38 extends AbstractRestService
39 implements ManagedRepositoriesService
43 private ManagedRepositoryAdmin managedRepositoryAdmin;
45 public List<ManagedRepository> getManagedRepositories()
46 throws RepositoryAdminException
48 List<org.apache.archiva.admin.repository.managed.ManagedRepository> repos =
49 managedRepositoryAdmin.getManagedRepositories();
51 List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>( repos.size() );
53 for ( org.apache.archiva.admin.repository.managed.ManagedRepository repoConfig : repos )
55 // TODO staging repo too
56 ManagedRepository repo =
57 new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
58 repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
59 repoConfig.isBlockRedeployments(), false, repoConfig.getCronExpression() );
60 managedRepos.add( repo );
66 public ManagedRepository getManagedRepository( String repositoryId )
67 throws RepositoryAdminException
69 List<ManagedRepository> repos = getManagedRepositories();
70 for ( ManagedRepository repo : repos )
72 if ( StringUtils.equals( repo.getId(), repositoryId ) )
81 public Boolean deleteManagedRepository( String repoId, boolean deleteContent )
85 return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent );
88 public Boolean addManagedRepository( ManagedRepository managedRepository )
91 org.apache.archiva.admin.repository.managed.ManagedRepository repo =
92 new org.apache.archiva.admin.repository.managed.ManagedRepository();
93 repo.setLocation( managedRepository.getLocation() );
94 repo.setBlockRedeployments( managedRepository.isBlockRedeployments() );
95 repo.setCronExpression( managedRepository.getCronExpression() );
96 repo.setId( managedRepository.getId() );
97 repo.setLayout( managedRepository.getLayout() );
98 repo.setName( managedRepository.getName() );
99 repo.setReleases( managedRepository.isReleases() );
100 repo.setSnapshots( managedRepository.isSnapshots() );
101 return managedRepositoryAdmin.addManagedRepository( repo, managedRepository.isStageRepoNeeded(),
102 getAuditInformation() );
106 public Boolean updateManagedRepository( ManagedRepository managedRepository )
109 org.apache.archiva.admin.repository.managed.ManagedRepository repo =
110 new org.apache.archiva.admin.repository.managed.ManagedRepository();
111 repo.setLocation( managedRepository.getLocation() );
112 repo.setBlockRedeployments( managedRepository.isBlockRedeployments() );
113 repo.setCronExpression( managedRepository.getCronExpression() );
114 repo.setId( managedRepository.getId() );
115 repo.setLayout( managedRepository.getLayout() );
116 repo.setName( managedRepository.getName() );
117 repo.setReleases( managedRepository.isReleases() );
118 repo.setSnapshots( managedRepository.isSnapshots() );
119 return managedRepositoryAdmin.updateManagedRepository( repo, managedRepository.isStageRepoNeeded(),
120 getAuditInformation(),
121 managedRepository.isResetStats() );