1 package org.apache.archiva.rest.services;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.ProxyConnector;
23 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
24 import org.apache.archiva.policies.Policy;
25 import org.apache.archiva.rest.api.model.PolicyInformation;
26 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
27 import org.apache.archiva.rest.api.services.ProxyConnectorService;
28 import org.springframework.context.ApplicationContext;
29 import org.springframework.stereotype.Service;
31 import javax.inject.Inject;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.List;
37 * @author Olivier Lamy
39 @Service( "proxyConnectorService#rest" )
40 public class DefaultProxyConnectorService
41 extends AbstractRestService
42 implements ProxyConnectorService
45 private ProxyConnectorAdmin proxyConnectorAdmin;
47 private List<Policy> allPolicies;
50 public DefaultProxyConnectorService( ApplicationContext applicationContext )
52 allPolicies = new ArrayList<>( getBeansOfType( applicationContext, Policy.class ).values() );
56 public List<ProxyConnector> getProxyConnectors()
57 throws ArchivaRestServiceException
61 List<ProxyConnector> proxyConnectors = proxyConnectorAdmin.getProxyConnectors();
62 return proxyConnectors == null ? Collections.<ProxyConnector>emptyList() : proxyConnectors;
64 catch ( RepositoryAdminException e )
66 throw new ArchivaRestServiceException( e.getMessage(), e );
71 public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
72 throws ArchivaRestServiceException
76 return proxyConnectorAdmin.getProxyConnector( sourceRepoId, targetRepoId );
78 catch ( RepositoryAdminException e )
80 throw new ArchivaRestServiceException( e.getMessage(), e );
85 public Boolean addProxyConnector( ProxyConnector proxyConnector )
86 throws ArchivaRestServiceException
88 if ( proxyConnector == null )
94 return proxyConnectorAdmin.addProxyConnector( proxyConnector, getAuditInformation() );
96 catch ( RepositoryAdminException e )
98 throw new ArchivaRestServiceException( e.getMessage(), e );
103 public Boolean deleteProxyConnector( ProxyConnector proxyConnector )
104 throws ArchivaRestServiceException
106 if ( proxyConnector == null )
108 return Boolean.FALSE;
112 return proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getAuditInformation() );
114 catch ( RepositoryAdminException e )
116 throw new ArchivaRestServiceException( e.getMessage(), e );
121 public Boolean removeProxyConnector( String sourceRepoId, String targetRepoId )
122 throws ArchivaRestServiceException
124 ProxyConnector proxyConnector = getProxyConnector( sourceRepoId, targetRepoId );
125 if ( proxyConnector == null )
127 throw new ArchivaRestServiceException(
128 "proxyConnector with sourceRepoId:" + sourceRepoId + " and targetRepoId:" + targetRepoId
129 + " not exists", null );
131 return deleteProxyConnector( proxyConnector );
135 public Boolean updateProxyConnector( ProxyConnector proxyConnector )
136 throws ArchivaRestServiceException
138 if ( proxyConnector == null )
140 return Boolean.FALSE;
144 return proxyConnectorAdmin.updateProxyConnector( proxyConnector, getAuditInformation() );
146 catch ( RepositoryAdminException e )
148 throw new ArchivaRestServiceException( e.getMessage(), e );
153 public List<PolicyInformation> getAllPolicyInformations()
154 throws ArchivaRestServiceException
156 List<PolicyInformation> policyInformations = new ArrayList<>( allPolicies.size() );
158 for ( Policy policy : allPolicies )
160 policyInformations.add(
161 new PolicyInformation( policy.getOptions(), policy.getDefaultOption(), policy.getId(),
162 policy.getName() ) );
165 return policyInformations;
168 public ProxyConnectorAdmin getProxyConnectorAdmin()
170 return proxyConnectorAdmin;
173 public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
175 this.proxyConnectorAdmin = proxyConnectorAdmin;