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.proxyconnector.ProxyConnectorAdmin;
24 import org.apache.archiva.rest.api.model.ProxyConnector;
25 import org.apache.archiva.rest.api.services.ProxyConnectorService;
26 import org.springframework.stereotype.Service;
28 import javax.inject.Inject;
29 import java.util.ArrayList;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.List;
36 * @author Olivier Lamy
38 @Service( "proxyConnectorService#rest" )
39 public class DefaultProxyConnectorService
40 extends AbstractRestService
41 implements ProxyConnectorService
44 private ProxyConnectorAdmin proxyConnectorAdmin;
46 public List<ProxyConnector> getProxyConnectors()
47 throws RepositoryAdminException
49 List<ProxyConnector> proxyConnectors = new ArrayList<ProxyConnector>();
50 for ( org.apache.archiva.admin.repository.proxyconnector.ProxyConnector proxyConnector : proxyConnectorAdmin.getProxyConnectors() )
52 proxyConnectors.add( new BeanReplicator().replicateBean( proxyConnector, ProxyConnector.class ) );
54 return proxyConnectors;
57 public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
58 throws RepositoryAdminException
60 org.apache.archiva.admin.repository.proxyconnector.ProxyConnector proxyConnector =
61 proxyConnectorAdmin.getProxyConnector( sourceRepoId, targetRepoId );
62 return proxyConnector == null
64 : new BeanReplicator().replicateBean( proxyConnector, ProxyConnector.class );
67 public Boolean addProxyConnector( ProxyConnector proxyConnector )
68 throws RepositoryAdminException
70 if ( proxyConnector == null )
74 return proxyConnectorAdmin.addProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
75 org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
76 getAuditInformation() );
79 public Boolean deleteProxyConnector( ProxyConnector proxyConnector )
80 throws RepositoryAdminException
82 if ( proxyConnector == null )
86 return proxyConnectorAdmin.deleteProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
87 org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
88 getAuditInformation() );
91 public Boolean updateProxyConnector( ProxyConnector proxyConnector )
92 throws RepositoryAdminException
94 if ( proxyConnector == null )
98 return proxyConnectorAdmin.updateProxyConnector( new BeanReplicator().replicateBean( proxyConnector,
99 org.apache.archiva.admin.repository.proxyconnector.ProxyConnector.class ),
100 getAuditInformation() );
103 public Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
104 throws RepositoryAdminException
106 Map<String, List<org.apache.archiva.admin.repository.proxyconnector.ProxyConnector>> modelMap =
107 proxyConnectorAdmin.getProxyConnectorAsMap();
108 if ( modelMap == null || modelMap.isEmpty() )
110 return Collections.emptyMap();
112 Map<String, List<ProxyConnector>> map = new HashMap<String, List<ProxyConnector>>( modelMap.size() );
113 for ( Map.Entry<String, List<org.apache.archiva.admin.repository.proxyconnector.ProxyConnector>> entry : modelMap.entrySet() )
115 List<ProxyConnector> proxyConnectors = new ArrayList<ProxyConnector>( entry.getValue().size() );
116 for ( org.apache.archiva.admin.repository.proxyconnector.ProxyConnector proxyConnector : entry.getValue() )
118 proxyConnectors.add( new BeanReplicator().replicateBean( proxyConnector, ProxyConnector.class ) );
120 map.put( entry.getKey(), proxyConnectors );
126 public ProxyConnectorAdmin getProxyConnectorAdmin()
128 return proxyConnectorAdmin;
131 public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
133 this.proxyConnectorAdmin = proxyConnectorAdmin;