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.RemoteRepository; 023 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; 024 import org.apache.archiva.rest.api.services.ArchivaRestServiceException; 025 import org.apache.archiva.rest.api.services.RemoteRepositoriesService; 026 import org.apache.commons.lang.StringUtils; 027 import org.springframework.stereotype.Service; 028 029 import javax.inject.Inject; 030 import java.util.Collections; 031 import java.util.List; 032 033 /** 034 * @author Olivier Lamy 035 * @since 1.4-M1 036 */ 037 @Service ("remoteRepositoriesService#rest") 038 public class DefaultRemoteRepositoriesService 039 extends AbstractRestService 040 implements RemoteRepositoriesService 041 { 042 043 @Inject 044 private RemoteRepositoryAdmin remoteRepositoryAdmin; 045 046 public List<RemoteRepository> getRemoteRepositories() 047 throws ArchivaRestServiceException 048 { 049 try 050 { 051 List<RemoteRepository> remoteRepositories = remoteRepositoryAdmin.getRemoteRepositories(); 052 return remoteRepositories == null ? Collections.<RemoteRepository>emptyList() : remoteRepositories; 053 } 054 catch ( RepositoryAdminException e ) 055 { 056 log.error( e.getMessage(), e ); 057 throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName(), e ); 058 } 059 } 060 061 public RemoteRepository getRemoteRepository( String repositoryId ) 062 throws ArchivaRestServiceException 063 { 064 065 List<RemoteRepository> remoteRepositories = getRemoteRepositories(); 066 for ( RemoteRepository repository : remoteRepositories ) 067 { 068 if ( StringUtils.equals( repositoryId, repository.getId() ) ) 069 { 070 return repository; 071 } 072 } 073 return null; 074 } 075 076 public Boolean deleteRemoteRepository( String repositoryId ) 077 throws Exception 078 { 079 try 080 { 081 return remoteRepositoryAdmin.deleteRemoteRepository( repositoryId, getAuditInformation() ); 082 } 083 catch ( RepositoryAdminException e ) 084 { 085 log.error( e.getMessage(), e ); 086 throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName(), e ); 087 } 088 } 089 090 public Boolean addRemoteRepository( RemoteRepository remoteRepository ) 091 throws Exception 092 { 093 try 094 { 095 return remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getAuditInformation() ); 096 } 097 catch ( RepositoryAdminException e ) 098 { 099 log.error( e.getMessage(), e ); 100 throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName(), e ); 101 } 102 } 103 104 public Boolean updateRemoteRepository( RemoteRepository remoteRepository ) 105 throws Exception 106 { 107 try 108 { 109 return remoteRepositoryAdmin.updateRemoteRepository( remoteRepository, getAuditInformation() ); 110 } 111 catch ( RepositoryAdminException e ) 112 { 113 log.error( e.getMessage(), e ); 114 throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName(), e ); 115 } 116 } 117 118 119 }