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.NetworkProxy;
23 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
24 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
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.Collections;
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 @Override
44 public List<NetworkProxy> getNetworkProxies()
45 throws ArchivaRestServiceException
46 {
47 try
48 {
49 List<NetworkProxy> networkProxies = networkProxyAdmin.getNetworkProxies();
50 return networkProxies == null ? Collections.<NetworkProxy>emptyList() : networkProxies;
51 }
52 catch ( RepositoryAdminException e )
53 {
54 throw new ArchivaRestServiceException( e.getMessage(), e );
55 }
56 }
57
58 @Override
59 public NetworkProxy getNetworkProxy( String networkProxyId )
60 throws ArchivaRestServiceException
61 {
62 try
63 {
64 return networkProxyAdmin.getNetworkProxy( networkProxyId );
65 }
66 catch ( RepositoryAdminException e )
67 {
68 throw new ArchivaRestServiceException( e.getMessage(), e );
69 }
70 }
71
72 @Override
73 public void addNetworkProxy( NetworkProxy networkProxy )
74 throws ArchivaRestServiceException
75 {
76 try
77 {
78 if ( networkProxy == null )
79 {
80 return;
81 }
82 getNetworkProxyAdmin().addNetworkProxy( networkProxy, getAuditInformation() );
83 }
84 catch ( RepositoryAdminException e )
85 {
86 throw new ArchivaRestServiceException( e.getMessage(), e );
87 }
88 }
89
90 @Override
91 public void updateNetworkProxy( NetworkProxy networkProxy )
92 throws ArchivaRestServiceException
93 {
94 if ( networkProxy == null )
95 {
96 return;
97 }
98 try
99 {
100 getNetworkProxyAdmin().updateNetworkProxy( networkProxy, getAuditInformation() );
101 }
102 catch ( RepositoryAdminException e )
103 {
104 throw new ArchivaRestServiceException( e.getMessage(), e );
105 }
106 }
107
108 @Override
109 public Boolean deleteNetworkProxy( String networkProxyId )
110 throws ArchivaRestServiceException
111 {
112 try
113 {
114 getNetworkProxyAdmin().deleteNetworkProxy( networkProxyId, getAuditInformation() );
115 return Boolean.TRUE;
116 }
117 catch ( RepositoryAdminException e )
118 {
119 throw new ArchivaRestServiceException( e.getMessage(), e );
120 }
121 }
122
123 public NetworkProxyAdmin getNetworkProxyAdmin()
124 {
125 return networkProxyAdmin;
126 }
127
128 public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin )
129 {
130 this.networkProxyAdmin = networkProxyAdmin;
131 }
132 }