1package org.apache.archiva.web.api;
2/*3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements. See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership. The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License. You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied. See the License for the17 * specific language governing permissions and limitations18 * under the License.19 */2021import org.apache.archiva.admin.model.RepositoryAdminException;
22import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
23import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
24import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
25import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
26import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
27import org.springframework.stereotype.Service;
2829import javax.inject.Inject;
3031/**32 * @author Olivier Lamy33 * @since 1.4-M334 */35 @Service( "dataValidatorService#rest" )
36publicclassDefaultDataValidatorService37implementsDataValidatorService38 {
3940 @Inject
41private ManagedRepositoryAdmin managedRepositoryAdmin;
4243 @Inject
44private RemoteRepositoryAdmin remoteRepositoryAdmin;
4546 @Inject
47private NetworkProxyAdmin networkProxyAdmin;
4849 @Inject
50private RepositoryGroupAdmin repositoryGroupAdmin;
515253 @Override
54public Boolean managedRepositoryIdNotExists( String id )
55throws ArchivaRestServiceException
56 {
57try58 {
59return !idExist( id );
60 }
61catch ( RepositoryAdminException e )
62 {
63thrownew ArchivaRestServiceException( e.getMessage(), e );
64 }
65 }
6667 @Override
68public Boolean remoteRepositoryIdNotExists( String id )
69throws ArchivaRestServiceException
70 {
71try72 {
73return !idExist( id );
74 }
75catch ( RepositoryAdminException e )
76 {
77thrownew ArchivaRestServiceException( e.getMessage(), e );
78 }
79 }
8081 @Override
82public Boolean networkProxyIdNotExists( String id )
83throws ArchivaRestServiceException
84 {
85try86 {
87return networkProxyAdmin.getNetworkProxy( id ) == null;
88 }
89catch ( RepositoryAdminException e )
90 {
91thrownew ArchivaRestServiceException( e.getMessage(), e );
92 }
93 }
9495/**96 * check if managedRepo, remoteRepo ou group exists with this id97 *98 * @param id99 * @return true if something exists with this id.100 */101private Boolean idExist( String id )
102throws RepositoryAdminException
103 {
104return ( managedRepositoryAdmin.getManagedRepository( id ) != null ) || (
105 remoteRepositoryAdmin.getRemoteRepository( id ) != null ) || ( repositoryGroupAdmin.getRepositoryGroup( id )
106 != null );
107 }
108 }