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.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
24 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
25 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
26 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
27 import org.apache.commons.lang.StringUtils;
28 import org.springframework.stereotype.Service;
30 import javax.inject.Inject;
31 import java.util.Collections;
32 import java.util.List;
35 * @author Olivier Lamy
38 @Service( "managedRepositoriesService#rest" )
39 public class DefaultManagedRepositoriesService
40 extends AbstractRestService
41 implements ManagedRepositoriesService
45 private ManagedRepositoryAdmin managedRepositoryAdmin;
48 private PlexusSisuBridge plexusSisuBridge;
51 public List<ManagedRepository> getManagedRepositories()
52 throws ArchivaRestServiceException
56 List<org.apache.archiva.admin.model.beans.ManagedRepository> repos =
57 managedRepositoryAdmin.getManagedRepositories();
58 return repos == null ? Collections.<ManagedRepository>emptyList() : repos;
60 catch ( RepositoryAdminException e )
62 throw new ArchivaRestServiceException( e.getMessage() );
66 public ManagedRepository getManagedRepository( String repositoryId )
67 throws ArchivaRestServiceException
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 )
82 throws ArchivaRestServiceException
87 return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent );
89 catch ( RepositoryAdminException e )
91 log.error( e.getMessage(), e );
92 throw new ArchivaRestServiceException( e.getMessage() );
96 public Boolean addManagedRepository( ManagedRepository managedRepository )
97 throws ArchivaRestServiceException
102 return managedRepositoryAdmin.addManagedRepository( managedRepository,
103 managedRepository.isStageRepoNeeded(),
104 getAuditInformation() );
106 catch ( RepositoryAdminException e )
108 throw new ArchivaRestServiceException( e.getMessage() );
113 public Boolean updateManagedRepository( ManagedRepository managedRepository )
114 throws ArchivaRestServiceException
119 return managedRepositoryAdmin.updateManagedRepository( managedRepository,
120 managedRepository.isStageRepoNeeded(),
121 getAuditInformation(),
122 managedRepository.isResetStats() );
124 catch ( RepositoryAdminException e )
126 throw new ArchivaRestServiceException( e.getMessage() );