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.RepositoryGroup;
23 import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
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 =
51 new ArrayList<RepositoryGroup>( repositoryGroupAdmin.getRepositoriesGroups().size() );
52 for ( org.apache.archiva.admin.model.beans.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() )
54 repositoriesGroups.add(
55 new RepositoryGroup( repoGroup.getId(), new ArrayList<String>( repoGroup.getRepositories() ) ) );
57 return repositoriesGroups;
59 catch ( RepositoryAdminException e )
61 throw new ArchivaRestServiceException( e.getMessage(), e );
65 public RepositoryGroup getRepositoryGroup( String repositoryGroupId )
66 throws ArchivaRestServiceException
68 for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() )
70 if ( StringUtils.equals( repositoryGroupId, repositoryGroup.getId() ) )
72 return repositoryGroup;
78 public Boolean addRepositoryGroup( RepositoryGroup repoGroup )
79 throws ArchivaRestServiceException
83 return repositoryGroupAdmin.addRepositoryGroup(
84 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
85 repoGroup.getRepositories() ) ), getAuditInformation() );
87 catch ( RepositoryAdminException e )
89 throw new ArchivaRestServiceException( e.getMessage(), e );
93 public Boolean updateRepositoryGroup( RepositoryGroup repoGroup )
94 throws ArchivaRestServiceException
98 return repositoryGroupAdmin.updateRepositoryGroup(
99 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
100 repoGroup.getRepositories() ) ), getAuditInformation() );
102 catch ( RepositoryAdminException e )
104 throw new ArchivaRestServiceException( e.getMessage(), e );
108 public Boolean deleteRepositoryGroup( String repositoryGroupId )
109 throws ArchivaRestServiceException
113 return repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation() );
115 catch ( RepositoryAdminException e )
117 throw new ArchivaRestServiceException( e.getMessage(), e );
121 public Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId )
122 throws ArchivaRestServiceException
126 return repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation() );
128 catch ( RepositoryAdminException e )
130 throw new ArchivaRestServiceException( e.getMessage(), e );
134 public Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId )
135 throws ArchivaRestServiceException
139 return repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId,
140 getAuditInformation() );
142 catch ( RepositoryAdminException e )
144 throw new ArchivaRestServiceException( e.getMessage(), e );