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( new RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
55 repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ) );
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() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ),
86 getAuditInformation() );
88 catch ( RepositoryAdminException e )
90 throw new ArchivaRestServiceException( e.getMessage(), e );
94 public Boolean updateRepositoryGroup( RepositoryGroup repoGroup )
95 throws ArchivaRestServiceException
99 return repositoryGroupAdmin.updateRepositoryGroup(
100 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<String>(
101 repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ),
102 getAuditInformation() );
104 catch ( RepositoryAdminException e )
106 throw new ArchivaRestServiceException( e.getMessage(), e );
110 public Boolean deleteRepositoryGroup( String repositoryGroupId )
111 throws ArchivaRestServiceException
115 return repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation() );
117 catch ( RepositoryAdminException e )
119 throw new ArchivaRestServiceException( e.getMessage(), e );
123 public Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId )
124 throws ArchivaRestServiceException
128 return repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation() );
130 catch ( RepositoryAdminException e )
132 throw new ArchivaRestServiceException( e.getMessage(), e );
136 public Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId )
137 throws ArchivaRestServiceException
141 return repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId,
142 getAuditInformation() );
144 catch ( RepositoryAdminException e )
146 throw new ArchivaRestServiceException( e.getMessage(), e );