You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultProxyConnectorService.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package org.apache.archiva.rest.services;
  2. /*
  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
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  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
  18. * under the License.
  19. */
  20. import org.apache.archiva.admin.model.RepositoryAdminException;
  21. import org.apache.archiva.admin.model.beans.ProxyConnector;
  22. import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
  23. import org.apache.archiva.policies.Policy;
  24. import org.apache.archiva.rest.api.model.PolicyInformation;
  25. import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
  26. import org.apache.archiva.rest.api.services.ProxyConnectorService;
  27. import org.springframework.context.ApplicationContext;
  28. import org.springframework.stereotype.Service;
  29. import javax.inject.Inject;
  30. import java.util.ArrayList;
  31. import java.util.Collections;
  32. import java.util.List;
  33. /**
  34. * @author Olivier Lamy
  35. */
  36. @Service( "proxyConnectorService#rest" )
  37. public class DefaultProxyConnectorService
  38. extends AbstractRestService
  39. implements ProxyConnectorService
  40. {
  41. private List<Policy> allPolicies;
  42. @Inject
  43. public DefaultProxyConnectorService( ApplicationContext applicationContext )
  44. {
  45. allPolicies = new ArrayList<>( getBeansOfType( applicationContext, Policy.class ).values() );
  46. }
  47. @Override
  48. public List<ProxyConnector> getProxyConnectors()
  49. throws ArchivaRestServiceException
  50. {
  51. try
  52. {
  53. List<ProxyConnector> proxyConnectors = proxyConnectorAdmin.getProxyConnectors();
  54. return proxyConnectors == null ? Collections.<ProxyConnector>emptyList() : proxyConnectors;
  55. }
  56. catch ( RepositoryAdminException e )
  57. {
  58. throw new ArchivaRestServiceException( e.getMessage(), e );
  59. }
  60. }
  61. @Override
  62. public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
  63. throws ArchivaRestServiceException
  64. {
  65. try
  66. {
  67. return proxyConnectorAdmin.getProxyConnector( sourceRepoId, targetRepoId );
  68. }
  69. catch ( RepositoryAdminException e )
  70. {
  71. throw new ArchivaRestServiceException( e.getMessage(), e );
  72. }
  73. }
  74. @Override
  75. public Boolean addProxyConnector( ProxyConnector proxyConnector )
  76. throws ArchivaRestServiceException
  77. {
  78. if ( proxyConnector == null )
  79. {
  80. return Boolean.FALSE;
  81. }
  82. try
  83. {
  84. return proxyConnectorAdmin.addProxyConnector( proxyConnector, getAuditInformation() );
  85. }
  86. catch ( RepositoryAdminException e )
  87. {
  88. throw new ArchivaRestServiceException( e.getMessage(), e );
  89. }
  90. }
  91. @Override
  92. public Boolean deleteProxyConnector( ProxyConnector proxyConnector )
  93. throws ArchivaRestServiceException
  94. {
  95. if ( proxyConnector == null )
  96. {
  97. return Boolean.FALSE;
  98. }
  99. try
  100. {
  101. return proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getAuditInformation() );
  102. }
  103. catch ( RepositoryAdminException e )
  104. {
  105. throw new ArchivaRestServiceException( e.getMessage(), e );
  106. }
  107. }
  108. @Override
  109. public Boolean removeProxyConnector( String sourceRepoId, String targetRepoId )
  110. throws ArchivaRestServiceException
  111. {
  112. ProxyConnector proxyConnector = getProxyConnector( sourceRepoId, targetRepoId );
  113. if ( proxyConnector == null )
  114. {
  115. throw new ArchivaRestServiceException(
  116. "proxyConnector with sourceRepoId:" + sourceRepoId + " and targetRepoId:" + targetRepoId
  117. + " not exists", null );
  118. }
  119. return deleteProxyConnector( proxyConnector );
  120. }
  121. @Override
  122. public Boolean updateProxyConnector( ProxyConnector proxyConnector )
  123. throws ArchivaRestServiceException
  124. {
  125. if ( proxyConnector == null )
  126. {
  127. return Boolean.FALSE;
  128. }
  129. try
  130. {
  131. return proxyConnectorAdmin.updateProxyConnector( proxyConnector, getAuditInformation() );
  132. }
  133. catch ( RepositoryAdminException e )
  134. {
  135. throw new ArchivaRestServiceException( e.getMessage(), e );
  136. }
  137. }
  138. @Override
  139. public List<PolicyInformation> getAllPolicyInformations()
  140. throws ArchivaRestServiceException
  141. {
  142. List<PolicyInformation> policyInformations = new ArrayList<>( allPolicies.size() );
  143. for ( Policy policy : allPolicies )
  144. {
  145. policyInformations.add(
  146. new PolicyInformation( policy.getOptions(), policy.getDefaultOption(), policy.getId(),
  147. policy.getName() ) );
  148. }
  149. return policyInformations;
  150. }
  151. public ProxyConnectorAdmin getProxyConnectorAdmin()
  152. {
  153. return proxyConnectorAdmin;
  154. }
  155. public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
  156. {
  157. this.proxyConnectorAdmin = proxyConnectorAdmin;
  158. }
  159. }