001 package org.apache.archiva.rest.services; 002 /* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 021 import org.apache.archiva.admin.model.RepositoryAdminException; 022 import org.apache.archiva.admin.model.beans.RepositoryGroup; 023 import org.apache.archiva.admin.model.group.RepositoryGroupAdmin; 024 import org.apache.archiva.rest.api.services.ArchivaRestServiceException; 025 import org.apache.archiva.rest.api.services.RepositoryGroupService; 026 import org.apache.commons.lang.StringUtils; 027 import org.springframework.stereotype.Service; 028 029 import javax.inject.Inject; 030 import java.util.ArrayList; 031 import java.util.List; 032 033 /** 034 * @author Olivier Lamy 035 */ 036 @Service( "repositoryGroupService#rest" ) 037 public class DefaultRepositoryGroupService 038 extends AbstractRestService 039 implements RepositoryGroupService 040 { 041 042 @Inject 043 private RepositoryGroupAdmin repositoryGroupAdmin; 044 045 public List<RepositoryGroup> getRepositoriesGroups() 046 throws ArchivaRestServiceException 047 { 048 try 049 { 050 List<RepositoryGroup> repositoriesGroups = 051 new ArrayList<RepositoryGroup>( repositoryGroupAdmin.getRepositoriesGroups().size() ); 052 for ( org.apache.archiva.admin.model.beans.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() ) 053 { 054 repositoriesGroups.add( new RepositoryGroup( repoGroup.getId(), new ArrayList<String>( 055 repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ) 056 .mergedIndexTtl( repoGroup.getMergedIndexTtl() ) ); 057 } 058 return repositoriesGroups; 059 } 060 catch ( RepositoryAdminException e ) 061 { 062 throw new ArchivaRestServiceException( e.getMessage(), e ); 063 } 064 } 065 066 public RepositoryGroup getRepositoryGroup( String repositoryGroupId ) 067 throws ArchivaRestServiceException 068 { 069 for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() ) 070 { 071 if ( StringUtils.equals( repositoryGroupId, repositoryGroup.getId() ) ) 072 { 073 return repositoryGroup; 074 } 075 } 076 return null; 077 } 078 079 public Boolean addRepositoryGroup( RepositoryGroup repoGroup ) 080 throws ArchivaRestServiceException 081 { 082 try 083 { 084 return repositoryGroupAdmin.addRepositoryGroup( 085 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<String>( 086 repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ) 087 .mergedIndexTtl( repoGroup.getMergedIndexTtl() ), getAuditInformation() ); 088 } 089 catch ( RepositoryAdminException e ) 090 { 091 throw new ArchivaRestServiceException( e.getMessage(), e ); 092 } 093 } 094 095 public Boolean updateRepositoryGroup( RepositoryGroup repoGroup ) 096 throws ArchivaRestServiceException 097 { 098 try 099 { 100 return repositoryGroupAdmin.updateRepositoryGroup( 101 new org.apache.archiva.admin.model.beans.RepositoryGroup( repoGroup.getId(), new ArrayList<String>( 102 repoGroup.getRepositories() ) ).mergedIndexPath( repoGroup.getMergedIndexPath() ) 103 .mergedIndexTtl( repoGroup.getMergedIndexTtl() ), getAuditInformation() ); 104 } 105 catch ( RepositoryAdminException e ) 106 { 107 throw new ArchivaRestServiceException( e.getMessage(), e ); 108 } 109 } 110 111 public Boolean deleteRepositoryGroup( String repositoryGroupId ) 112 throws ArchivaRestServiceException 113 { 114 try 115 { 116 return repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation() ); 117 } 118 catch ( RepositoryAdminException e ) 119 { 120 throw new ArchivaRestServiceException( e.getMessage(), e ); 121 } 122 } 123 124 public Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId ) 125 throws ArchivaRestServiceException 126 { 127 try 128 { 129 return repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation() ); 130 } 131 catch ( RepositoryAdminException e ) 132 { 133 throw new ArchivaRestServiceException( e.getMessage(), e ); 134 } 135 } 136 137 public Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId ) 138 throws ArchivaRestServiceException 139 { 140 try 141 { 142 return repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId, 143 getAuditInformation() ); 144 } 145 catch ( RepositoryAdminException e ) 146 { 147 throw new ArchivaRestServiceException( e.getMessage(), e ); 148 } 149 } 150 }