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
37 @Service( "networkProxyAdmin#default" )
38 public class DefaultNetworkProxyAdmin
39 extends AbstractRepositoryAdmin
40 implements NetworkProxyAdmin
43 public List<NetworkProxy> getNetworkProxies()
44 throws RepositoryAdminException
46 List<NetworkProxy> networkProxies = new ArrayList<NetworkProxy>();
47 for ( NetworkProxyConfiguration networkProxyConfiguration : getArchivaConfiguration().getConfiguration().getNetworkProxies() )
49 networkProxies.add( getNetworkProxy( networkProxyConfiguration ) );
51 return networkProxies;
54 public NetworkProxy getNetworkProxy( String networkProxyId )
55 throws RepositoryAdminException
57 for ( NetworkProxy networkProxy : getNetworkProxies() )
59 if ( StringUtils.equals( networkProxyId, networkProxy.getId() ) )
68 public void addNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
69 throws RepositoryAdminException
71 if ( networkProxy == null )
75 if ( getNetworkProxy( networkProxy.getId() ) != null )
77 throw new RepositoryAdminException(
78 "cannot add NetworkProxy with id " + networkProxy.getId() + " already exist" );
80 Configuration configuration = getArchivaConfiguration().getConfiguration();
81 configuration.addNetworkProxy( getNetworkProxyConfiguration( networkProxy ) );
83 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.ADD_NETWORK_PROXY, auditInformation );
85 saveConfiguration( configuration );
88 public void updateNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
89 throws RepositoryAdminException
91 if ( networkProxy == null )
95 if ( getNetworkProxy( networkProxy.getId() ) == null )
97 throw new RepositoryAdminException(
98 "cannot update NetworkProxy with id " + networkProxy.getId() + " as not exist" );
100 Configuration configuration = getArchivaConfiguration().getConfiguration();
101 NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
102 configuration.removeNetworkProxy( networkProxyConfiguration );
103 configuration.addNetworkProxy( networkProxyConfiguration );
105 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.MODIFY_NETWORK_PROXY, auditInformation );
107 saveConfiguration( configuration );
110 public void deleteNetworkProxy( String networkProxyId, AuditInformation auditInformation )
111 throws RepositoryAdminException
114 NetworkProxy networkProxy = getNetworkProxy( networkProxyId );
115 if ( networkProxy == null )
117 throw new RepositoryAdminException(
118 "cannot delete NetworkProxy with id " + networkProxyId + " as not exist" );
120 Configuration configuration = getArchivaConfiguration().getConfiguration();
121 NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
122 configuration.removeNetworkProxy( networkProxyConfiguration );
124 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation );
126 saveConfiguration( configuration );
129 protected NetworkProxy getNetworkProxy( NetworkProxyConfiguration networkProxyConfiguration )
131 return networkProxyConfiguration == null
133 : new BeanReplicator().replicateBean( networkProxyConfiguration, NetworkProxy.class );
136 protected NetworkProxyConfiguration getNetworkProxyConfiguration( NetworkProxy networkProxy )
138 return networkProxy == null
140 : new BeanReplicator().replicateBean( networkProxy, NetworkProxyConfiguration.class );