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 org.apache.archiva.admin.model.AuditInformation;
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.NetworkProxy;
24 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
25 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
26 import org.apache.archiva.audit.AuditEvent;
27 import org.apache.archiva.configuration.Configuration;
28 import org.apache.archiva.configuration.NetworkProxyConfiguration;
29 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
30 import org.apache.commons.lang.StringUtils;
31 import org.springframework.stereotype.Service;
33 import java.util.ArrayList;
34 import java.util.List;
37 * @author Olivier Lamy
40 @Service( "networkProxyAdmin#default" )
41 public class DefaultNetworkProxyAdmin
42 extends AbstractRepositoryAdmin
43 implements NetworkProxyAdmin
47 public List<NetworkProxy> getNetworkProxies()
48 throws RepositoryAdminException
50 List<NetworkProxy> networkProxies =
51 new ArrayList<>( getArchivaConfiguration().getConfiguration().getNetworkProxies().size() );
52 for ( NetworkProxyConfiguration networkProxyConfiguration : getArchivaConfiguration().getConfiguration().getNetworkProxies() )
54 networkProxies.add( getNetworkProxy( networkProxyConfiguration ) );
56 return networkProxies;
60 public NetworkProxy getNetworkProxy( String networkProxyId )
61 throws RepositoryAdminException
63 for ( NetworkProxy networkProxy : getNetworkProxies() )
65 if ( StringUtils.equals( networkProxyId, networkProxy.getId() ) )
75 public void addNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
76 throws RepositoryAdminException
78 if ( networkProxy == null )
82 if ( getNetworkProxy( networkProxy.getId() ) != null )
84 throw new RepositoryAdminException(
85 "cannot add NetworkProxy with id " + networkProxy.getId() + " already exist" );
87 Configuration configuration = getArchivaConfiguration().getConfiguration();
88 configuration.addNetworkProxy( getNetworkProxyConfiguration( networkProxy ) );
90 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.ADD_NETWORK_PROXY, auditInformation );
92 saveConfiguration( configuration );
96 public void updateNetworkProxy( NetworkProxy networkProxy, AuditInformation auditInformation )
97 throws RepositoryAdminException
99 if ( networkProxy == null )
103 if ( getNetworkProxy( networkProxy.getId() ) == null )
105 throw new RepositoryAdminException(
106 "cannot update NetworkProxy with id " + networkProxy.getId() + " as not exist" );
108 Configuration configuration = getArchivaConfiguration().getConfiguration();
109 NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
110 configuration.removeNetworkProxy( networkProxyConfiguration );
111 configuration.addNetworkProxy( networkProxyConfiguration );
113 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.MODIFY_NETWORK_PROXY, auditInformation );
115 saveConfiguration( configuration );
119 public void deleteNetworkProxy( String networkProxyId, AuditInformation auditInformation )
120 throws RepositoryAdminException
123 NetworkProxy networkProxy = getNetworkProxy( networkProxyId );
124 if ( networkProxy == null )
126 throw new RepositoryAdminException(
127 "cannot delete NetworkProxy with id " + networkProxyId + " as not exist" );
129 Configuration configuration = getArchivaConfiguration().getConfiguration();
130 NetworkProxyConfiguration networkProxyConfiguration = getNetworkProxyConfiguration( networkProxy );
131 configuration.removeNetworkProxy( networkProxyConfiguration );
133 for ( RemoteRepositoryConfiguration rrc : configuration.getRemoteRepositories() )
135 if ( StringUtils.equals( rrc.getRemoteDownloadNetworkProxyId(), networkProxyId ) )
137 rrc.setRemoteDownloadNetworkProxyId( null );
141 triggerAuditEvent( networkProxy.getId(), null, AuditEvent.DELETE_NETWORK_PROXY, auditInformation );
143 saveConfiguration( configuration );
146 protected NetworkProxy getNetworkProxy( NetworkProxyConfiguration networkProxyConfiguration )
148 return networkProxyConfiguration == null
150 : getModelMapper().map( networkProxyConfiguration, NetworkProxy.class );
153 protected NetworkProxyConfiguration getNetworkProxyConfiguration( NetworkProxy networkProxy )
155 return networkProxy == null
157 : getModelMapper().map( networkProxy, NetworkProxyConfiguration.class );