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.lang3.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;
46 public List<RepositoryGroup> getRepositoriesGroups()
47 throws ArchivaRestServiceException
51 List<RepositoryGroup> repositoriesGroups =
52 new ArrayList<>( repositoryGroupAdmin.getRepositoriesGroups().size() );
53 for ( org.apache.archiva.admin.model.beans.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() )
55 repositoriesGroups.add( new RepositoryGroup( repoGroup.getId(), new ArrayList<>(
56 repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ).mergedIndexTtl(
57 repoGroup.getMergedIndexTtl() ).cronExpression( repoGroup.getCronExpression() ) );
59 return repositoriesGroups;
61 catch ( RepositoryAdminException e )
63 throw new ArchivaRestServiceException( e.getMessage(), e );
68 public RepositoryGroup getRepositoryGroup( String repositoryGroupId )
69 throws ArchivaRestServiceException
71 for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() )
73 if ( StringUtils.equals( repositoryGroupId, repositoryGroup.getId() ) )
75 return repositoryGroup;
82 public Boolean addRepositoryGroup( RepositoryGroup repoGroup )
83 throws ArchivaRestServiceException
87 return repositoryGroupAdmin.addRepositoryGroup(
88 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<>(
89 repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ).mergedIndexTtl(
90 repoGroup.getMergedIndexTtl() ).cronExpression( repoGroup.getCronExpression() ),
91 getAuditInformation() );
93 catch ( RepositoryAdminException e )
95 throw new ArchivaRestServiceException( e.getMessage(), e );
100 public Boolean updateRepositoryGroup( RepositoryGroup repoGroup )
101 throws ArchivaRestServiceException
105 return repositoryGroupAdmin.updateRepositoryGroup(
106 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<>(
107 repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ).mergedIndexTtl(
108 repoGroup.getMergedIndexTtl() ).cronExpression( repoGroup.getCronExpression() ),
109 getAuditInformation() );
111 catch ( RepositoryAdminException e )
113 throw new ArchivaRestServiceException( e.getMessage(), e );
118 public Boolean deleteRepositoryGroup( String repositoryGroupId )
119 throws ArchivaRestServiceException
123 return repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation() );
125 catch ( RepositoryAdminException e )
127 throw new ArchivaRestServiceException( e.getMessage(), e );
132 public Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId )
133 throws ArchivaRestServiceException
137 return repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation() );
139 catch ( RepositoryAdminException e )
141 throw new ArchivaRestServiceException( e.getMessage(), e );
146 public Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId )
147 throws ArchivaRestServiceException
151 return repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId,
152 getAuditInformation() );
154 catch ( RepositoryAdminException e )
156 throw new ArchivaRestServiceException( e.getMessage(), e );