1 package org.apache.archiva.rest.services;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
29 import javax.inject.Inject;
30 import java.util.ArrayList;
31 import java.util.List;
34 * @author Olivier Lamy
36 @Service( "networkProxyService#rest" )
37 public class DefaultNetworkProxyService
38 extends AbstractRestService
39 implements NetworkProxyService
42 private NetworkProxyAdmin networkProxyAdmin;
44 public List<NetworkProxy> getNetworkProxies()
45 throws ArchivaRestServiceException
49 List<NetworkProxy> networkProxies = new ArrayList<NetworkProxy>();
50 for ( org.apache.archiva.admin.repository.networkproxy.NetworkProxy networkProxy : networkProxyAdmin.getNetworkProxies() )
52 networkProxies.add( new BeanReplicator().replicateBean( networkProxy, NetworkProxy.class ) );
54 return networkProxies;
56 catch ( RepositoryAdminException e )
58 throw new ArchivaRestServiceException( e.getMessage() );
62 public NetworkProxy getNetworkProxy( String networkProxyId )
63 throws ArchivaRestServiceException
67 org.apache.archiva.admin.repository.networkproxy.NetworkProxy networkProxy =
68 networkProxyAdmin.getNetworkProxy( networkProxyId );
69 return networkProxy == null ? null : new BeanReplicator().replicateBean( networkProxy, NetworkProxy.class );
71 catch ( RepositoryAdminException e )
73 throw new ArchivaRestServiceException( e.getMessage() );
77 public void addNetworkProxy( NetworkProxy networkProxy )
78 throws ArchivaRestServiceException
82 if ( networkProxy == null )
86 getNetworkProxyAdmin().addNetworkProxy( new BeanReplicator().replicateBean( networkProxy,
87 org.apache.archiva.admin.repository.networkproxy.NetworkProxy.class ),
88 getAuditInformation() );
90 catch ( RepositoryAdminException e )
92 throw new ArchivaRestServiceException( e.getMessage() );
96 public void updateNetworkProxy( NetworkProxy networkProxy )
97 throws ArchivaRestServiceException
99 if ( networkProxy == null )
105 getNetworkProxyAdmin().updateNetworkProxy( new BeanReplicator().replicateBean( networkProxy,
106 org.apache.archiva.admin.repository.networkproxy.NetworkProxy.class ),
107 getAuditInformation() );
109 catch ( RepositoryAdminException e )
111 throw new ArchivaRestServiceException( e.getMessage() );
115 public Boolean deleteNetworkProxy( String networkProxyId )
116 throws ArchivaRestServiceException
120 getNetworkProxyAdmin().deleteNetworkProxy( networkProxyId, getAuditInformation() );
123 catch ( RepositoryAdminException e )
125 throw new ArchivaRestServiceException( e.getMessage() );
129 public NetworkProxyAdmin getNetworkProxyAdmin()
131 return networkProxyAdmin;
134 public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin )
136 this.networkProxyAdmin = networkProxyAdmin;