]> source.dussan.org Git - archiva.git/blob
5e23c9ff0ea6b8df1e600404154b0d020141c4b6
[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.ArchivaRestServiceException;
26 import org.apache.archiva.rest.api.services.NetworkProxyService;
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( "networkProxyService#rest" )
37 public class DefaultNetworkProxyService
38     extends AbstractRestService
39     implements NetworkProxyService
40 {
41     @Inject
42     private NetworkProxyAdmin networkProxyAdmin;
43
44     public List<NetworkProxy> getNetworkProxies()
45         throws ArchivaRestServiceException
46     {
47         try
48         {
49             List<NetworkProxy> networkProxies = new ArrayList<NetworkProxy>();
50             for ( org.apache.archiva.admin.repository.networkproxy.NetworkProxy networkProxy : networkProxyAdmin.getNetworkProxies() )
51             {
52                 networkProxies.add( new BeanReplicator().replicateBean( networkProxy, NetworkProxy.class ) );
53             }
54             return networkProxies;
55         }
56         catch ( RepositoryAdminException e )
57         {
58             throw new ArchivaRestServiceException( e.getMessage() );
59         }
60     }
61
62     public NetworkProxy getNetworkProxy( String networkProxyId )
63         throws ArchivaRestServiceException
64     {
65         try
66         {
67             org.apache.archiva.admin.repository.networkproxy.NetworkProxy networkProxy =
68                 networkProxyAdmin.getNetworkProxy( networkProxyId );
69             return networkProxy == null ? null : new BeanReplicator().replicateBean( networkProxy, NetworkProxy.class );
70         }
71         catch ( RepositoryAdminException e )
72         {
73             throw new ArchivaRestServiceException( e.getMessage() );
74         }
75     }
76
77     public void addNetworkProxy( NetworkProxy networkProxy )
78         throws ArchivaRestServiceException
79     {
80         try
81         {
82             if ( networkProxy == null )
83             {
84                 return;
85             }
86             getNetworkProxyAdmin().addNetworkProxy( new BeanReplicator().replicateBean( networkProxy,
87                                                                                         org.apache.archiva.admin.repository.networkproxy.NetworkProxy.class ),
88                                                     getAuditInformation() );
89         }
90         catch ( RepositoryAdminException e )
91         {
92             throw new ArchivaRestServiceException( e.getMessage() );
93         }
94     }
95
96     public void updateNetworkProxy( NetworkProxy networkProxy )
97         throws ArchivaRestServiceException
98     {
99         if ( networkProxy == null )
100         {
101             return;
102         }
103         try
104         {
105             getNetworkProxyAdmin().updateNetworkProxy( new BeanReplicator().replicateBean( networkProxy,
106                                                                                            org.apache.archiva.admin.repository.networkproxy.NetworkProxy.class ),
107                                                        getAuditInformation() );
108         }
109         catch ( RepositoryAdminException e )
110         {
111             throw new ArchivaRestServiceException( e.getMessage() );
112         }
113     }
114
115     public Boolean deleteNetworkProxy( String networkProxyId )
116         throws ArchivaRestServiceException
117     {
118         try
119         {
120             getNetworkProxyAdmin().deleteNetworkProxy( networkProxyId, getAuditInformation() );
121             return Boolean.TRUE;
122         }
123         catch ( RepositoryAdminException e )
124         {
125             throw new ArchivaRestServiceException( e.getMessage() );
126         }
127     }
128
129     public NetworkProxyAdmin getNetworkProxyAdmin()
130     {
131         return networkProxyAdmin;
132     }
133
134     public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin )
135     {
136         this.networkProxyAdmin = networkProxyAdmin;
137     }
138 }