1 package org.apache.archiva.admin.repository.networkproxy;
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.AuditInformation;
23 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
24 import org.apache.archiva.admin.repository.RepositoryAdminException;
25 import org.apache.archiva.audit.AuditEvent;
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
29 import org.springframework.stereotype.Service;
31 import java.util.ArrayList;
32 import java.util.List;
35 * @author Olivier Lamy
38 @Service( "networkProxyAdmin#default" )
39 public class DefaultNetworkProxyAdmin
40 extends AbstractRepositoryAdmin
41 implements NetworkProxyAdmin
44 public List<NetworkProxy> getNetworkProxies()
45 throws RepositoryAdminException
47 List<NetworkProxy> networkProxies = new ArrayList<NetworkProxy>();
48 for ( NetworkProxyConfiguration networkProxyConfiguration : getArchivaConfiguration().getConfiguration().getNetworkProxies() )
50 networkProxies.add( getNetworkProxy( networkProxyConfiguration ) );
52 return networkProxies;
55 public NetworkProxy getNetworkProxy( String networkProxyId )
56 throws RepositoryAdminException
58 for ( NetworkProxy networkProxy : getNetworkProxies() )
60 if ( StringUtils.equals( networkProxyId, networkProxy.getId() ) )
69 public void addNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
70 throws RepositoryAdminException
72 if ( networkProxy == null )
76 if ( getNetworkProxy( networkProxy.getId() ) != null )
78 throw new RepositoryAdminException(
79 "cannot add NetworkProxy with id " + networkProxy.getId() + " already exist" );
81 Configuration configuration = getArchivaConfiguration().getConfiguration();
82 configuration.addNetworkProxy( getNetworkProxyConfiguration( networkProxy ) );
84 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.ADD_NETWORK_PROXY, auditInformation );
86 saveConfiguration( configuration );
89 public void updateNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
90 throws RepositoryAdminException
92 if ( networkProxy == null )
96 if ( getNetworkProxy( networkProxy.getId() ) == null )
98 throw new RepositoryAdminException(
99 "cannot update NetworkProxy with id " + networkProxy.getId() + " as not exist" );
101 Configuration configuration = getArchivaConfiguration().getConfiguration();
102 NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
103 configuration.removeNetworkProxy( networkProxyConfiguration );
104 configuration.addNetworkProxy( networkProxyConfiguration );
106 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.MODIFY_NETWORK_PROXY, auditInformation );
108 saveConfiguration( configuration );
111 public void deleteNetworkProxy( String networkProxyId, AuditInformation auditInformation )
112 throws RepositoryAdminException
115 NetworkProxy networkProxy = getNetworkProxy( networkProxyId );
116 if ( networkProxy == null )
118 throw new RepositoryAdminException(
119 "cannot delete NetworkProxy with id " + networkProxyId + " as not exist" );
121 Configuration configuration = getArchivaConfiguration().getConfiguration();
122 NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
123 configuration.removeNetworkProxy( networkProxyConfiguration );
125 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation );
127 saveConfiguration( configuration );
130 protected NetworkProxy getNetworkProxy( NetworkProxyConfiguration networkProxyConfiguration )
132 return networkProxyConfiguration == null
134 : new BeanReplicator().replicateBean( networkProxyConfiguration, NetworkProxy.class );
137 protected NetworkProxyConfiguration getNetworkProxyConfiguration( NetworkProxy networkProxy )
139 return networkProxy == null
141 : new BeanReplicator().replicateBean( networkProxy, NetworkProxyConfiguration.class );