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.

DefaultProxyConnectorRuleService.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.ProxyConnectorRule;
  22. import org.apache.archiva.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin;
  23. import org.apache.archiva.rest.api.model.ActionStatus;
  24. import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
  25. import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.springframework.stereotype.Service;
  28. import javax.inject.Inject;
  29. import java.util.List;
  30. /**
  31. * @author Olivier Lamy
  32. */
  33. @Service ("proxyConnectorRuleService#rest")
  34. public class DefaultProxyConnectorRuleService
  35. extends AbstractRestService
  36. implements ProxyConnectorRuleService
  37. {
  38. @Inject
  39. private ProxyConnectorRuleAdmin proxyConnectorRuleAdmin;
  40. @Override
  41. public List<ProxyConnectorRule> getProxyConnectorRules()
  42. throws ArchivaRestServiceException
  43. {
  44. try
  45. {
  46. return proxyConnectorRuleAdmin.getProxyConnectorRules();
  47. }
  48. catch ( RepositoryAdminException e )
  49. {
  50. throw new ArchivaRestServiceException( e.getMessage(), e );
  51. }
  52. }
  53. private void validateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
  54. throws ArchivaRestServiceException
  55. {
  56. if ( StringUtils.isEmpty( proxyConnectorRule.getPattern() ) )
  57. {
  58. ArchivaRestServiceException e = new ArchivaRestServiceException( "pattern cannot be empty", null );
  59. e.setErrorKey( "proxy-connector-rule.pattern.empty" );
  60. throw e;
  61. }
  62. if ( proxyConnectorRule.getProxyConnectors() == null || proxyConnectorRule.getProxyConnectors().isEmpty() )
  63. {
  64. ArchivaRestServiceException e =
  65. new ArchivaRestServiceException( "proxyConnector rule must have proxyConnectors.", null );
  66. e.setErrorKey( "proxy-connector-rule.pattern.connectors.empty" );
  67. throw e;
  68. }
  69. for ( ProxyConnectorRule proxyConnectorRule1 : getProxyConnectorRules() )
  70. {
  71. if ( StringUtils.equals( proxyConnectorRule.getPattern(), proxyConnectorRule1.getPattern() )
  72. && proxyConnectorRule.getProxyConnectorRuleType() == proxyConnectorRule1.getProxyConnectorRuleType() )
  73. {
  74. ArchivaRestServiceException e =
  75. new ArchivaRestServiceException( "same ProxyConnector rule already exists.", null );
  76. e.setErrorKey( "proxy-connector-rule.pattern.already.exists" );
  77. throw e;
  78. }
  79. }
  80. }
  81. @Override
  82. public ActionStatus addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
  83. throws ArchivaRestServiceException
  84. {
  85. validateProxyConnectorRule( proxyConnectorRule );
  86. try
  87. {
  88. proxyConnectorRuleAdmin.addProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
  89. return ActionStatus.SUCCESS;
  90. }
  91. catch ( RepositoryAdminException e )
  92. {
  93. throw new ArchivaRestServiceException( e.getMessage(), e );
  94. }
  95. }
  96. @Override
  97. public ActionStatus deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
  98. throws ArchivaRestServiceException
  99. {
  100. try
  101. {
  102. proxyConnectorRuleAdmin.deleteProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
  103. return ActionStatus.SUCCESS;
  104. }
  105. catch ( RepositoryAdminException e )
  106. {
  107. throw new ArchivaRestServiceException( e.getMessage(), e );
  108. }
  109. }
  110. @Override
  111. public ActionStatus updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
  112. throws ArchivaRestServiceException
  113. {
  114. try
  115. {
  116. proxyConnectorRuleAdmin.updateProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
  117. return ActionStatus.SUCCESS;
  118. }
  119. catch ( RepositoryAdminException e )
  120. {
  121. throw new ArchivaRestServiceException( e.getMessage(), e );
  122. }
  123. }
  124. }