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.group.RepositoryGroupAdmin;
23 import org.apache.archiva.rest.api.model.RepositoryGroup;
24 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
25 import org.apache.archiva.rest.api.services.RepositoryGroupService;
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
36 @Service( "repositoryGroupService#rest" )
37 public class DefaultRepositoryGroupService
38 extends AbstractRestService
39 implements RepositoryGroupService
43 private RepositoryGroupAdmin repositoryGroupAdmin;
45 public List<RepositoryGroup> getRepositoriesGroups()
46 throws ArchivaRestServiceException
50 List<RepositoryGroup> repositoriesGroups = new ArrayList<RepositoryGroup>();
51 for ( org.apache.archiva.admin.repository.group.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() )
53 repositoriesGroups.add(
54 new RepositoryGroup( repoGroup.getId(), new ArrayList<String>( repoGroup.getRepositories() ) ) );
56 return repositoriesGroups;
58 catch ( RepositoryAdminException e )
60 throw new ArchivaRestServiceException( e.getMessage() );
64 public RepositoryGroup getRepositoryGroup( String repositoryGroupId )
65 throws ArchivaRestServiceException
67 for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() )
69 if ( StringUtils.equals( repositoryGroupId, repositoryGroup.getId() ) )
71 return repositoryGroup;
77 public Boolean addRepositoryGroup( RepositoryGroup repoGroup )
78 throws ArchivaRestServiceException
82 return repositoryGroupAdmin.addRepositoryGroup(
83 new org.apache.archiva.admin.repository.group.RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
84 repoGroup.getRepositories() ) ), getAuditInformation() );
86 catch ( RepositoryAdminException e )
88 throw new ArchivaRestServiceException( e.getMessage() );
92 public Boolean updateRepositoryGroup( RepositoryGroup repoGroup )
93 throws ArchivaRestServiceException
97 return repositoryGroupAdmin.updateRepositoryGroup(
98 new org.apache.archiva.admin.repository.group.RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
99 repoGroup.getRepositories() ) ), getAuditInformation() );
101 catch ( RepositoryAdminException e )
103 throw new ArchivaRestServiceException( e.getMessage() );
107 public Boolean deleteRepositoryGroup( String repositoryGroupId )
108 throws ArchivaRestServiceException
112 return repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation() );
114 catch ( RepositoryAdminException e )
116 throw new ArchivaRestServiceException( e.getMessage() );
120 public Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId )
121 throws ArchivaRestServiceException
125 return repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation() );
127 catch ( RepositoryAdminException e )
129 throw new ArchivaRestServiceException( e.getMessage() );
133 public Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId )
134 throws ArchivaRestServiceException
138 return repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId,
139 getAuditInformation() );
141 catch ( RepositoryAdminException e )
143 throw new ArchivaRestServiceException( e.getMessage() );