]> source.dussan.org Git - archiva.git/blob
24087aa067606831f124e05b62c8cfa4d4762145
[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.ArchivaRestServiceException;
26 import org.apache.archiva.rest.api.services.ProxyConnectorService;
27 import org.springframework.stereotype.Service;
28
29 import javax.inject.Inject;
30 import java.util.ArrayList;
31 import java.util.List;
32
33 /**
34  * @author Olivier Lamy
35  */
36 @Service( "proxyConnectorService#rest" )
37 public class DefaultProxyConnectorService
38     extends AbstractRestService
39     implements ProxyConnectorService
40 {
41     @Inject
42     private ProxyConnectorAdmin proxyConnectorAdmin;
43
44     public List<ProxyConnector> getProxyConnectors()
45         throws ArchivaRestServiceException
46     {
47         try
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         catch ( RepositoryAdminException e )
57         {
58             throw new ArchivaRestServiceException( e.getMessage() );
59         }
60     }
61
62     public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
63         throws ArchivaRestServiceException
64     {
65         try
66         {
67             org.apache.archiva.admin.repository.proxyconnector.ProxyConnector proxyConnector =
68                 proxyConnectorAdmin.getProxyConnector( sourceRepoId, targetRepoId );
69             return proxyConnector == null
70                 ? null
71                 : new BeanReplicator().replicateBean( proxyConnector, ProxyConnector.class );
72         }
73         catch ( RepositoryAdminException e )
74         {
75             throw new ArchivaRestServiceException( e.getMessage() );
76         }
77     }
78
79     public Boolean addProxyConnector( ProxyConnector proxyConnector )
80         throws ArchivaRestServiceException
81     {
82         if ( proxyConnector == null )
83         {
84             return Boolean.FALSE;
85         }
86         try
87         {
88             return proxyConnectorAdmin.addProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
89                                                                                               org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
90                                                           getAuditInformation() );
91         }
92         catch ( RepositoryAdminException e )
93         {
94             throw new ArchivaRestServiceException( e.getMessage() );
95         }
96     }
97
98     public Boolean deleteProxyConnector( ProxyConnector proxyConnector )
99         throws ArchivaRestServiceException
100     {
101         if ( proxyConnector == null )
102         {
103             return Boolean.FALSE;
104         }
105         try
106         {
107             return proxyConnectorAdmin.deleteProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
108                                                                                                  org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
109                                                              getAuditInformation() );
110         }
111         catch ( RepositoryAdminException e )
112         {
113             throw new ArchivaRestServiceException( e.getMessage() );
114         }
115     }
116
117     public Boolean updateProxyConnector( ProxyConnector proxyConnector )
118         throws ArchivaRestServiceException
119     {
120         if ( proxyConnector == null )
121         {
122             return Boolean.FALSE;
123         }
124         try
125         {
126             return proxyConnectorAdmin.updateProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
127                                                                                                  org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
128                                                              getAuditInformation() );
129         }
130         catch ( RepositoryAdminException e )
131         {
132             throw new ArchivaRestServiceException( e.getMessage() );
133         }
134     }
135
136     public ProxyConnectorAdmin getProxyConnectorAdmin()
137     {
138         return proxyConnectorAdmin;
139     }
140
141     public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
142     {
143         this.proxyConnectorAdmin = proxyConnectorAdmin;
144     }
145 }
146
147