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.

DefaultNetworkProxyService.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.NetworkProxy;
  22. import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
  23. import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
  24. import org.apache.archiva.rest.api.services.NetworkProxyService;
  25. import org.springframework.stereotype.Service;
  26. import javax.inject.Inject;
  27. import java.util.Collections;
  28. import java.util.List;
  29. /**
  30. * @author Olivier Lamy
  31. */
  32. @Service( "networkProxyService#rest" )
  33. public class DefaultNetworkProxyService
  34. extends AbstractRestService
  35. implements NetworkProxyService
  36. {
  37. @Inject
  38. private NetworkProxyAdmin networkProxyAdmin;
  39. @Override
  40. public List<NetworkProxy> getNetworkProxies()
  41. throws ArchivaRestServiceException
  42. {
  43. try
  44. {
  45. List<NetworkProxy> networkProxies = networkProxyAdmin.getNetworkProxies();
  46. return networkProxies == null ? Collections.<NetworkProxy>emptyList() : networkProxies;
  47. }
  48. catch ( RepositoryAdminException e )
  49. {
  50. throw new ArchivaRestServiceException( e.getMessage(), e );
  51. }
  52. }
  53. @Override
  54. public NetworkProxy getNetworkProxy( String networkProxyId )
  55. throws ArchivaRestServiceException
  56. {
  57. try
  58. {
  59. return networkProxyAdmin.getNetworkProxy( networkProxyId );
  60. }
  61. catch ( RepositoryAdminException e )
  62. {
  63. throw new ArchivaRestServiceException( e.getMessage(), e );
  64. }
  65. }
  66. @Override
  67. public void addNetworkProxy( NetworkProxy networkProxy )
  68. throws ArchivaRestServiceException
  69. {
  70. try
  71. {
  72. if ( networkProxy == null )
  73. {
  74. return;
  75. }
  76. getNetworkProxyAdmin().addNetworkProxy( networkProxy, getAuditInformation() );
  77. }
  78. catch ( RepositoryAdminException e )
  79. {
  80. throw new ArchivaRestServiceException( e.getMessage(), e );
  81. }
  82. }
  83. @Override
  84. public void updateNetworkProxy( NetworkProxy networkProxy )
  85. throws ArchivaRestServiceException
  86. {
  87. if ( networkProxy == null )
  88. {
  89. return;
  90. }
  91. try
  92. {
  93. getNetworkProxyAdmin().updateNetworkProxy( networkProxy, getAuditInformation() );
  94. }
  95. catch ( RepositoryAdminException e )
  96. {
  97. throw new ArchivaRestServiceException( e.getMessage(), e );
  98. }
  99. }
  100. @Override
  101. public Boolean deleteNetworkProxy( String networkProxyId )
  102. throws ArchivaRestServiceException
  103. {
  104. try
  105. {
  106. getNetworkProxyAdmin().deleteNetworkProxy( networkProxyId, getAuditInformation() );
  107. return Boolean.TRUE;
  108. }
  109. catch ( RepositoryAdminException e )
  110. {
  111. throw new ArchivaRestServiceException( e.getMessage(), e );
  112. }
  113. }
  114. public NetworkProxyAdmin getNetworkProxyAdmin()
  115. {
  116. return networkProxyAdmin;
  117. }
  118. public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin )
  119. {
  120. this.networkProxyAdmin = networkProxyAdmin;
  121. }
  122. }