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.model.AuditInformation;
23 import org.apache.archiva.admin.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.beans.NetworkProxy;
25 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
26 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
27 import org.apache.archiva.audit.AuditEvent;
28 import org.apache.archiva.configuration.Configuration;
29 import org.apache.archiva.configuration.NetworkProxyConfiguration;
30 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
31 import org.apache.commons.lang.StringUtils;
32 import org.springframework.stereotype.Service;
34 import java.util.ArrayList;
35 import java.util.List;
38 * @author Olivier Lamy
41 @Service( "networkProxyAdmin#default" )
42 public class DefaultNetworkProxyAdmin
43 extends AbstractRepositoryAdmin
44 implements NetworkProxyAdmin
47 public List<NetworkProxy> getNetworkProxies()
48 throws RepositoryAdminException
50 List<NetworkProxy> networkProxies =
51 new ArrayList<NetworkProxy>( getArchivaConfiguration().getConfiguration().getNetworkProxies().size() );
52 for ( NetworkProxyConfiguration networkProxyConfiguration : getArchivaConfiguration().getConfiguration().getNetworkProxies() )
54 networkProxies.add( getNetworkProxy( networkProxyConfiguration ) );
56 return networkProxies;
59 public NetworkProxy getNetworkProxy( String networkProxyId )
60 throws RepositoryAdminException
62 for ( NetworkProxy networkProxy : getNetworkProxies() )
64 if ( StringUtils.equals( networkProxyId, networkProxy.getId() ) )
73 public void addNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
74 throws RepositoryAdminException
76 if ( networkProxy == null )
80 if ( getNetworkProxy( networkProxy.getId() ) != null )
82 throw new RepositoryAdminException(
83 "cannot add NetworkProxy with id " + networkProxy.getId() + " already exist" );
85 Configuration configuration = getArchivaConfiguration().getConfiguration();
86 configuration.addNetworkProxy( getNetworkProxyConfiguration( networkProxy ) );
88 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.ADD_NETWORK_PROXY, auditInformation );
90 saveConfiguration( configuration );
93 public void updateNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
94 throws RepositoryAdminException
96 if ( networkProxy == null )
100 if ( getNetworkProxy( networkProxy.getId() ) == null )
102 throw new RepositoryAdminException(
103 "cannot update NetworkProxy with id " + networkProxy.getId() + " as not exist" );
105 Configuration configuration = getArchivaConfiguration().getConfiguration();
106 NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
107 configuration.removeNetworkProxy( networkProxyConfiguration );
108 configuration.addNetworkProxy( networkProxyConfiguration );
110 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.MODIFY_NETWORK_PROXY, auditInformation );
112 saveConfiguration( configuration );
115 public void deleteNetworkProxy( String networkProxyId, AuditInformation auditInformation )
116 throws RepositoryAdminException
119 NetworkProxy networkProxy = getNetworkProxy( networkProxyId );
120 if ( networkProxy == null )
122 throw new RepositoryAdminException(
123 "cannot delete NetworkProxy with id " + networkProxyId + " as not exist" );
125 Configuration configuration = getArchivaConfiguration().getConfiguration();
126 NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
127 configuration.removeNetworkProxy( networkProxyConfiguration );
129 for ( RemoteRepositoryConfiguration rrc : configuration.getRemoteRepositories() )
131 if ( StringUtils.equals( rrc.getRemoteDownloadNetworkProxyId(), networkProxyId ) )
133 rrc.setRemoteDownloadNetworkProxyId( null );
137 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation );
139 saveConfiguration( configuration );
142 protected NetworkProxy getNetworkProxy( NetworkProxyConfiguration networkProxyConfiguration )
144 return networkProxyConfiguration == null
146 : new BeanReplicator().replicateBean( networkProxyConfiguration, NetworkProxy.class );
149 protected NetworkProxyConfiguration getNetworkProxyConfiguration( NetworkProxy networkProxy )
151 return networkProxy == null
153 : new BeanReplicator().replicateBean( networkProxy, NetworkProxyConfiguration.class );