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