001 package org.apache.archiva.web.api; 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.group.RepositoryGroupAdmin; 023 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; 024 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; 025 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; 026 import org.apache.archiva.rest.api.services.ArchivaRestServiceException; 027 import org.springframework.stereotype.Service; 028 029 import javax.inject.Inject; 030 031 /** 032 * @author Olivier Lamy 033 * @since 1.4-M3 034 */ 035 @Service( "dataValidatorService#rest" ) 036 public class DefaultDataValidatorService 037 implements DataValidatorService 038 { 039 040 @Inject 041 private ManagedRepositoryAdmin managedRepositoryAdmin; 042 043 @Inject 044 private RemoteRepositoryAdmin remoteRepositoryAdmin; 045 046 @Inject 047 private NetworkProxyAdmin networkProxyAdmin; 048 049 @Inject 050 private RepositoryGroupAdmin repositoryGroupAdmin; 051 052 053 public Boolean managedRepositoryIdNotExists( String id ) 054 throws ArchivaRestServiceException 055 { 056 try 057 { 058 return !idExist( id ); 059 } 060 catch ( RepositoryAdminException e ) 061 { 062 throw new ArchivaRestServiceException( e.getMessage(), e ); 063 } 064 } 065 066 public Boolean remoteRepositoryIdNotExists( String id ) 067 throws ArchivaRestServiceException 068 { 069 try 070 { 071 return !idExist( id ); 072 } 073 catch ( RepositoryAdminException e ) 074 { 075 throw new ArchivaRestServiceException( e.getMessage(), e ); 076 } 077 } 078 079 public Boolean networkProxyIdNotExists( String id ) 080 throws ArchivaRestServiceException 081 { 082 try 083 { 084 return networkProxyAdmin.getNetworkProxy( id ) == null; 085 } 086 catch ( RepositoryAdminException e ) 087 { 088 throw new ArchivaRestServiceException( e.getMessage(), e ); 089 } 090 } 091 092 /** 093 * check if managedRepo, remoteRepo ou group exists with this id 094 * 095 * @param id 096 * @return true if something exists with this id. 097 */ 098 private Boolean idExist( String id ) 099 throws RepositoryAdminException 100 { 101 return ( managedRepositoryAdmin.getManagedRepository( id ) != null ) || ( 102 remoteRepositoryAdmin.getRemoteRepository( id ) != null ) || ( repositoryGroupAdmin.getRepositoryGroup( id ) 103 != null ); 104 } 105 }