This project has retired. For details please refer to its Attic page.
DefaultProxyConnectorService xref
View Javadoc
1   package org.apache.archiva.rest.services;
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.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;
30  
31  import javax.inject.Inject;
32  import java.util.ArrayList;
33  import java.util.Collections;
34  import java.util.List;
35  
36  /**
37   * @author Olivier Lamy
38   */
39  @Service( "proxyConnectorService#rest" )
40  public class DefaultProxyConnectorService
41      extends AbstractRestService
42      implements ProxyConnectorService
43  {
44  
45      private List<Policy> allPolicies;
46  
47      @Inject
48      public DefaultProxyConnectorService( ApplicationContext applicationContext )
49      {
50          allPolicies = new ArrayList<>( getBeansOfType( applicationContext, Policy.class ).values() );
51      }
52  
53      @Override
54      public List<ProxyConnector> getProxyConnectors()
55          throws ArchivaRestServiceException
56      {
57          try
58          {
59              List<ProxyConnector> proxyConnectors = proxyConnectorAdmin.getProxyConnectors();
60              return proxyConnectors == null ? Collections.<ProxyConnector>emptyList() : proxyConnectors;
61          }
62          catch ( RepositoryAdminException e )
63          {
64              throw new ArchivaRestServiceException( e.getMessage(), e );
65          }
66      }
67  
68      @Override
69      public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
70          throws ArchivaRestServiceException
71      {
72          try
73          {
74              return proxyConnectorAdmin.getProxyConnector( sourceRepoId, targetRepoId );
75          }
76          catch ( RepositoryAdminException e )
77          {
78              throw new ArchivaRestServiceException( e.getMessage(), e );
79          }
80      }
81  
82      @Override
83      public Boolean addProxyConnector( ProxyConnector proxyConnector )
84          throws ArchivaRestServiceException
85      {
86          if ( proxyConnector == null )
87          {
88              return Boolean.FALSE;
89          }
90          try
91          {
92              return proxyConnectorAdmin.addProxyConnector( proxyConnector, getAuditInformation() );
93          }
94          catch ( RepositoryAdminException e )
95          {
96              throw new ArchivaRestServiceException( e.getMessage(), e );
97          }
98      }
99  
100     @Override
101     public Boolean deleteProxyConnector( ProxyConnector proxyConnector )
102         throws ArchivaRestServiceException
103     {
104         if ( proxyConnector == null )
105         {
106             return Boolean.FALSE;
107         }
108         try
109         {
110             return proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getAuditInformation() );
111         }
112         catch ( RepositoryAdminException e )
113         {
114             throw new ArchivaRestServiceException( e.getMessage(), e );
115         }
116     }
117 
118     @Override
119     public Boolean removeProxyConnector( String sourceRepoId, String targetRepoId )
120         throws ArchivaRestServiceException
121     {
122         ProxyConnector proxyConnector = getProxyConnector( sourceRepoId, targetRepoId );
123         if ( proxyConnector == null )
124         {
125             throw new ArchivaRestServiceException(
126                 "proxyConnector with sourceRepoId:" + sourceRepoId + " and targetRepoId:" + targetRepoId
127                     + " not exists", null );
128         }
129         return deleteProxyConnector( proxyConnector );
130     }
131 
132     @Override
133     public Boolean updateProxyConnector( ProxyConnector proxyConnector )
134         throws ArchivaRestServiceException
135     {
136         if ( proxyConnector == null )
137         {
138             return Boolean.FALSE;
139         }
140         try
141         {
142             return proxyConnectorAdmin.updateProxyConnector( proxyConnector, getAuditInformation() );
143         }
144         catch ( RepositoryAdminException e )
145         {
146             throw new ArchivaRestServiceException( e.getMessage(), e );
147         }
148     }
149 
150     @Override
151     public List<PolicyInformation> getAllPolicyInformations()
152         throws ArchivaRestServiceException
153     {
154         List<PolicyInformation> policyInformations = new ArrayList<>( allPolicies.size() );
155 
156         for ( Policy policy : allPolicies )
157         {
158             policyInformations.add(
159                 new PolicyInformation( policy.getOptions(), policy.getDefaultOption(), policy.getId(),
160                                        policy.getName() ) );
161         }
162 
163         return policyInformations;
164     }
165 
166     public ProxyConnectorAdmin getProxyConnectorAdmin()
167     {
168         return proxyConnectorAdmin;
169     }
170 
171     public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
172     {
173         this.proxyConnectorAdmin = proxyConnectorAdmin;
174     }
175 }
176 
177