]> source.dussan.org Git - archiva.git/blob
cf046febbe50d2940530885d47f2bb9da2254a8c
[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.networkproxy.NetworkProxyAdmin;
24 import org.apache.archiva.rest.api.model.NetworkProxy;
25 import org.apache.archiva.rest.api.services.NetworkProxyService;
26 import org.springframework.stereotype.Service;
27
28 import javax.inject.Inject;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 /**
33  * @author Olivier Lamy
34  */
35 @Service( "networkProxyService#rest" )
36 public class DefaultNetworkProxyService
37     extends AbstractRestService
38     implements NetworkProxyService
39 {
40     @Inject
41     private NetworkProxyAdmin networkProxyAdmin;
42
43     public List<NetworkProxy> getNetworkProxies()
44         throws RepositoryAdminException
45     {
46         List<NetworkProxy> networkProxies = new ArrayList<NetworkProxy>();
47         for ( org.apache.archiva.admin.repository.networkproxy.NetworkProxy networkProxy : networkProxyAdmin.getNetworkProxies() )
48         {
49             networkProxies.add( new BeanReplicator().replicateBean( networkProxy, NetworkProxy.class ) );
50         }
51         return networkProxies;
52     }
53
54     public NetworkProxy getNetworkProxy( String networkProxyId )
55         throws RepositoryAdminException
56     {
57         org.apache.archiva.admin.repository.networkproxy.NetworkProxy networkProxy =
58             networkProxyAdmin.getNetworkProxy( networkProxyId );
59         return networkProxy == null ? null : new BeanReplicator().replicateBean( networkProxy, NetworkProxy.class );
60     }
61
62     public void addNetworkProxy( NetworkProxy networkProxy )
63         throws RepositoryAdminException
64     {
65         if ( networkProxy == null )
66         {
67             return;
68         }
69         getNetworkProxyAdmin().addNetworkProxy( new BeanReplicator().replicateBean( networkProxy,
70                                                                                     org.apache.archiva.admin.repository.networkproxy.NetworkProxy.class ),
71                                                 getAuditInformation() );
72     }
73
74     public void updateNetworkProxy( NetworkProxy networkProxy )
75         throws RepositoryAdminException
76     {
77         if ( networkProxy == null )
78         {
79             return;
80         }
81         getNetworkProxyAdmin().updateNetworkProxy( new BeanReplicator().replicateBean( networkProxy,
82                                                                                        org.apache.archiva.admin.repository.networkproxy.NetworkProxy.class ),
83                                                    getAuditInformation() );
84     }
85
86     public Boolean deleteNetworkProxy( String networkProxyId )
87         throws RepositoryAdminException
88     {
89         getNetworkProxyAdmin().deleteNetworkProxy( networkProxyId, getAuditInformation() );
90         return Boolean.TRUE;
91     }
92
93     public NetworkProxyAdmin getNetworkProxyAdmin()
94     {
95         return networkProxyAdmin;
96     }
97
98     public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin )
99     {
100         this.networkProxyAdmin = networkProxyAdmin;
101     }
102 }