]> source.dussan.org Git - archiva.git/blob
50cd6b6471f06b8fb618d37553786c20fda1b2ab
[archiva.git] /
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 net.sf.beanlib.provider.replicator.BeanReplicator;
22 import org.apache.archiva.admin.repository.RepositoryAdminException;
23 import org.apache.archiva.admin.repository.proxyconnector.ProxyConnectorAdmin;
24 import org.apache.archiva.rest.api.model.ProxyConnector;
25 import org.apache.archiva.rest.api.services.ProxyConnectorService;
26 import org.springframework.stereotype.Service;
27
28 import javax.inject.Inject;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35 /**
36  * @author Olivier Lamy
37  */
38 @Service( "proxyConnectorService#rest" )
39 public class DefaultProxyConnectorService
40     extends AbstractRestService
41     implements ProxyConnectorService
42 {
43     @Inject
44     private ProxyConnectorAdmin proxyConnectorAdmin;
45
46     public List<ProxyConnector> getProxyConnectors()
47         throws RepositoryAdminException
48     {
49         List<ProxyConnector> proxyConnectors = new ArrayList<ProxyConnector>();
50         for ( org.apache.archiva.admin.repository.proxyconnector.ProxyConnector proxyConnector : proxyConnectorAdmin.getProxyConnectors() )
51         {
52             proxyConnectors.add( new BeanReplicator().replicateBean( proxyConnector, ProxyConnector.class ) );
53         }
54         return proxyConnectors;
55     }
56
57     public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
58         throws RepositoryAdminException
59     {
60         org.apache.archiva.admin.repository.proxyconnector.ProxyConnector proxyConnector =
61             proxyConnectorAdmin.getProxyConnector( sourceRepoId, targetRepoId );
62         return proxyConnector == null
63             ? null
64             : new BeanReplicator().replicateBean( proxyConnector, ProxyConnector.class );
65     }
66
67     public Boolean addProxyConnector( ProxyConnector proxyConnector )
68         throws RepositoryAdminException
69     {
70         if ( proxyConnector == null )
71         {
72             return Boolean.FALSE;
73         }
74         return proxyConnectorAdmin.addProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
75                                                                                           org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
76                                                       getAuditInformation() );
77     }
78
79     public Boolean deleteProxyConnector( ProxyConnector proxyConnector )
80         throws RepositoryAdminException
81     {
82         if ( proxyConnector == null )
83         {
84             return Boolean.FALSE;
85         }
86         return proxyConnectorAdmin.deleteProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
87                                                                                              org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
88                                                          getAuditInformation() );
89     }
90
91     public Boolean updateProxyConnector( ProxyConnector proxyConnector )
92         throws RepositoryAdminException
93     {
94         if ( proxyConnector == null )
95         {
96             return Boolean.FALSE;
97         }
98         return proxyConnectorAdmin.updateProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
99                                                                                              org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
100                                                          getAuditInformation() );
101     }
102
103     public ProxyConnectorAdmin getProxyConnectorAdmin()
104     {
105         return proxyConnectorAdmin;
106     }
107
108     public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
109     {
110         this.proxyConnectorAdmin = proxyConnectorAdmin;
111     }
112 }
113
114