This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.rest.services;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020
021import org.apache.archiva.admin.model.RepositoryAdminException;
022import org.apache.archiva.admin.model.beans.ProxyConnector;
023import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
024import org.apache.archiva.policies.Policy;
025import org.apache.archiva.rest.api.model.PolicyInformation;
026import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
027import org.apache.archiva.rest.api.services.ProxyConnectorService;
028import org.springframework.context.ApplicationContext;
029import org.springframework.stereotype.Service;
030
031import javax.inject.Inject;
032import java.util.ArrayList;
033import java.util.Collections;
034import java.util.List;
035
036/**
037 * @author Olivier Lamy
038 */
039@Service( "proxyConnectorService#rest" )
040public class DefaultProxyConnectorService
041    extends AbstractRestService
042    implements ProxyConnectorService
043{
044
045    private List<Policy> allPolicies;
046
047    @Inject
048    public DefaultProxyConnectorService( ApplicationContext applicationContext )
049    {
050        allPolicies = new ArrayList<>( getBeansOfType( applicationContext, Policy.class ).values() );
051    }
052
053    @Override
054    public List<ProxyConnector> getProxyConnectors()
055        throws ArchivaRestServiceException
056    {
057        try
058        {
059            List<ProxyConnector> proxyConnectors = proxyConnectorAdmin.getProxyConnectors();
060            return proxyConnectors == null ? Collections.<ProxyConnector>emptyList() : proxyConnectors;
061        }
062        catch ( RepositoryAdminException e )
063        {
064            throw new ArchivaRestServiceException( e.getMessage(), e );
065        }
066    }
067
068    @Override
069    public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
070        throws ArchivaRestServiceException
071    {
072        try
073        {
074            return proxyConnectorAdmin.getProxyConnector( sourceRepoId, targetRepoId );
075        }
076        catch ( RepositoryAdminException e )
077        {
078            throw new ArchivaRestServiceException( e.getMessage(), e );
079        }
080    }
081
082    @Override
083    public Boolean addProxyConnector( ProxyConnector proxyConnector )
084        throws ArchivaRestServiceException
085    {
086        if ( proxyConnector == null )
087        {
088            return Boolean.FALSE;
089        }
090        try
091        {
092            return proxyConnectorAdmin.addProxyConnector( proxyConnector, getAuditInformation() );
093        }
094        catch ( RepositoryAdminException e )
095        {
096            throw new ArchivaRestServiceException( e.getMessage(), e );
097        }
098    }
099
100    @Override
101    public Boolean deleteProxyConnector( ProxyConnector proxyConnector )
102        throws ArchivaRestServiceException
103    {
104        if ( proxyConnector == null )
105        {
106            return Boolean.FALSE;
107        }
108        try
109        {
110            return proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getAuditInformation() );
111        }
112        catch ( RepositoryAdminException e )
113        {
114            throw new ArchivaRestServiceException( e.getMessage(), e );
115        }
116    }
117
118    @Override
119    public Boolean removeProxyConnector( String sourceRepoId, String targetRepoId )
120        throws ArchivaRestServiceException
121    {
122        ProxyConnector proxyConnector = getProxyConnector( sourceRepoId, targetRepoId );
123        if ( proxyConnector == null )
124        {
125            throw new ArchivaRestServiceException(
126                "proxyConnector with sourceRepoId:" + sourceRepoId + " and targetRepoId:" + targetRepoId
127                    + " not exists", null );
128        }
129        return deleteProxyConnector( proxyConnector );
130    }
131
132    @Override
133    public Boolean updateProxyConnector( ProxyConnector proxyConnector )
134        throws ArchivaRestServiceException
135    {
136        if ( proxyConnector == null )
137        {
138            return Boolean.FALSE;
139        }
140        try
141        {
142            return proxyConnectorAdmin.updateProxyConnector( proxyConnector, getAuditInformation() );
143        }
144        catch ( RepositoryAdminException e )
145        {
146            throw new ArchivaRestServiceException( e.getMessage(), e );
147        }
148    }
149
150    @Override
151    public List<PolicyInformation> getAllPolicyInformations()
152        throws ArchivaRestServiceException
153    {
154        List<PolicyInformation> policyInformations = new ArrayList<>( allPolicies.size() );
155
156        for ( Policy policy : allPolicies )
157        {
158            policyInformations.add(
159                new PolicyInformation( policy.getOptions(), policy.getDefaultOption(), policy.getId(),
160                                       policy.getName() ) );
161        }
162
163        return policyInformations;
164    }
165
166    public ProxyConnectorAdmin getProxyConnectorAdmin()
167    {
168        return proxyConnectorAdmin;
169    }
170
171    public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
172    {
173        this.proxyConnectorAdmin = proxyConnectorAdmin;
174    }
175}
176
177