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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. @Inject
  42. private ProxyConnectorAdmin proxyConnectorAdmin;
  43. private List<Policy> allPolicies;
  44. @Inject
  45. public DefaultProxyConnectorService( ApplicationContext applicationContext )
  46. {
  47. allPolicies = new ArrayList<>( getBeansOfType( applicationContext, Policy.class ).values() );
  48. }
  49. public List<ProxyConnector> getProxyConnectors()
  50. throws ArchivaRestServiceException
  51. {
  52. try
  53. {
  54. List<ProxyConnector> proxyConnectors = proxyConnectorAdmin.getProxyConnectors();
  55. return proxyConnectors == null ? Collections.<ProxyConnector>emptyList() : proxyConnectors;
  56. }
  57. catch ( RepositoryAdminException e )
  58. {
  59. throw new ArchivaRestServiceException( e.getMessage(), e );
  60. }
  61. }
  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. public Boolean addProxyConnector( ProxyConnector proxyConnector )
  75. throws ArchivaRestServiceException
  76. {
  77. if ( proxyConnector == null )
  78. {
  79. return Boolean.FALSE;
  80. }
  81. try
  82. {
  83. return proxyConnectorAdmin.addProxyConnector( proxyConnector, getAuditInformation() );
  84. }
  85. catch ( RepositoryAdminException e )
  86. {
  87. throw new ArchivaRestServiceException( e.getMessage(), e );
  88. }
  89. }
  90. public Boolean deleteProxyConnector( ProxyConnector proxyConnector )
  91. throws ArchivaRestServiceException
  92. {
  93. if ( proxyConnector == null )
  94. {
  95. return Boolean.FALSE;
  96. }
  97. try
  98. {
  99. return proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getAuditInformation() );
  100. }
  101. catch ( RepositoryAdminException e )
  102. {
  103. throw new ArchivaRestServiceException( e.getMessage(), e );
  104. }
  105. }
  106. public Boolean removeProxyConnector( String sourceRepoId, String targetRepoId )
  107. throws ArchivaRestServiceException
  108. {
  109. ProxyConnector proxyConnector = getProxyConnector( sourceRepoId, targetRepoId );
  110. if ( proxyConnector == null )
  111. {
  112. throw new ArchivaRestServiceException(
  113. "proxyConnector with sourceRepoId:" + sourceRepoId + " and targetRepoId:" + targetRepoId
  114. + " not exists", null );
  115. }
  116. return deleteProxyConnector( proxyConnector );
  117. }
  118. public Boolean updateProxyConnector( ProxyConnector proxyConnector )
  119. throws ArchivaRestServiceException
  120. {
  121. if ( proxyConnector == null )
  122. {
  123. return Boolean.FALSE;
  124. }
  125. try
  126. {
  127. return proxyConnectorAdmin.updateProxyConnector( proxyConnector, getAuditInformation() );
  128. }
  129. catch ( RepositoryAdminException e )
  130. {
  131. throw new ArchivaRestServiceException( e.getMessage(), e );
  132. }
  133. }
  134. public List<PolicyInformation> getAllPolicyInformations()
  135. throws ArchivaRestServiceException
  136. {
  137. List<PolicyInformation> policyInformations = new ArrayList<>( allPolicies.size() );
  138. for ( Policy policy : allPolicies )
  139. {
  140. policyInformations.add(
  141. new PolicyInformation( policy.getOptions(), policy.getDefaultOption(), policy.getId(),
  142. policy.getName() ) );
  143. }
  144. return policyInformations;
  145. }
  146. public ProxyConnectorAdmin getProxyConnectorAdmin()
  147. {
  148. return proxyConnectorAdmin;
  149. }
  150. public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
  151. {
  152. this.proxyConnectorAdmin = proxyConnectorAdmin;
  153. }
  154. }