1 package org.apache.archiva.web.api;
2 /*
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 */
20
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
23 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
24 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
25 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
26 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
27 import org.springframework.stereotype.Service;
28
29 import javax.inject.Inject;
30
31 /**
32 * @author Olivier Lamy
33 * @since 1.4-M3
34 */
35 @Service( "dataValidatorService#rest" )
36 public class DefaultDataValidatorService
37 implements DataValidatorService
38 {
39
40 @Inject
41 private ManagedRepositoryAdmin managedRepositoryAdmin;
42
43 @Inject
44 private RemoteRepositoryAdmin remoteRepositoryAdmin;
45
46 @Inject
47 private NetworkProxyAdmin networkProxyAdmin;
48
49 @Inject
50 private RepositoryGroupAdmin repositoryGroupAdmin;
51
52
53 @Override
54 public Boolean managedRepositoryIdNotExists( String id )
55 throws ArchivaRestServiceException
56 {
57 try
58 {
59 return !idExist( id );
60 }
61 catch ( RepositoryAdminException e )
62 {
63 throw new ArchivaRestServiceException( e.getMessage(), e );
64 }
65 }
66
67 @Override
68 public Boolean remoteRepositoryIdNotExists( String id )
69 throws ArchivaRestServiceException
70 {
71 try
72 {
73 return !idExist( id );
74 }
75 catch ( RepositoryAdminException e )
76 {
77 throw new ArchivaRestServiceException( e.getMessage(), e );
78 }
79 }
80
81 @Override
82 public Boolean networkProxyIdNotExists( String id )
83 throws ArchivaRestServiceException
84 {
85 try
86 {
87 return networkProxyAdmin.getNetworkProxy( id ) == null;
88 }
89 catch ( RepositoryAdminException e )
90 {
91 throw new ArchivaRestServiceException( e.getMessage(), e );
92 }
93 }
94
95 /**
96 * check if managedRepo, remoteRepo ou group exists with this id
97 *
98 * @param id
99 * @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 }