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.NetworkProxy; 023import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin; 024import org.apache.archiva.rest.api.services.ArchivaRestServiceException; 025import org.apache.archiva.rest.api.services.NetworkProxyService; 026import org.springframework.stereotype.Service; 027 028import javax.inject.Inject; 029import java.util.Collections; 030import java.util.List; 031 032/** 033 * @author Olivier Lamy 034 */ 035@Service( "networkProxyService#rest" ) 036public class DefaultNetworkProxyService 037 extends AbstractRestService 038 implements NetworkProxyService 039{ 040 @Inject 041 private NetworkProxyAdmin networkProxyAdmin; 042 043 @Override 044 public List<NetworkProxy> getNetworkProxies() 045 throws ArchivaRestServiceException 046 { 047 try 048 { 049 List<NetworkProxy> networkProxies = networkProxyAdmin.getNetworkProxies(); 050 return networkProxies == null ? Collections.<NetworkProxy>emptyList() : networkProxies; 051 } 052 catch ( RepositoryAdminException e ) 053 { 054 throw new ArchivaRestServiceException( e.getMessage(), e ); 055 } 056 } 057 058 @Override 059 public NetworkProxy getNetworkProxy( String networkProxyId ) 060 throws ArchivaRestServiceException 061 { 062 try 063 { 064 return networkProxyAdmin.getNetworkProxy( networkProxyId ); 065 } 066 catch ( RepositoryAdminException e ) 067 { 068 throw new ArchivaRestServiceException( e.getMessage(), e ); 069 } 070 } 071 072 @Override 073 public void addNetworkProxy( NetworkProxy networkProxy ) 074 throws ArchivaRestServiceException 075 { 076 try 077 { 078 if ( networkProxy == null ) 079 { 080 return; 081 } 082 getNetworkProxyAdmin().addNetworkProxy( networkProxy, getAuditInformation() ); 083 } 084 catch ( RepositoryAdminException e ) 085 { 086 throw new ArchivaRestServiceException( e.getMessage(), e ); 087 } 088 } 089 090 @Override 091 public void updateNetworkProxy( NetworkProxy networkProxy ) 092 throws ArchivaRestServiceException 093 { 094 if ( networkProxy == null ) 095 { 096 return; 097 } 098 try 099 { 100 getNetworkProxyAdmin().updateNetworkProxy( networkProxy, getAuditInformation() ); 101 } 102 catch ( RepositoryAdminException e ) 103 { 104 throw new ArchivaRestServiceException( e.getMessage(), e ); 105 } 106 } 107 108 @Override 109 public Boolean deleteNetworkProxy( String networkProxyId ) 110 throws ArchivaRestServiceException 111 { 112 try 113 { 114 getNetworkProxyAdmin().deleteNetworkProxy( networkProxyId, getAuditInformation() ); 115 return Boolean.TRUE; 116 } 117 catch ( RepositoryAdminException e ) 118 { 119 throw new ArchivaRestServiceException( e.getMessage(), e ); 120 } 121 } 122 123 public NetworkProxyAdmin getNetworkProxyAdmin() 124 { 125 return networkProxyAdmin; 126 } 127 128 public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin ) 129 { 130 this.networkProxyAdmin = networkProxyAdmin; 131 } 132}