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.

DeleteRemoteRepositoryAction.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package org.apache.maven.archiva.web.action.admin.repositories;
  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 com.opensymphony.xwork2.Preparable;
  21. import org.apache.commons.lang.StringUtils;
  22. import org.apache.maven.archiva.configuration.Configuration;
  23. import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
  24. import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
  25. import java.util.List;
  26. /**
  27. * DeleteRemoteRepositoryAction
  28. *
  29. * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  30. * @version $Id$
  31. *
  32. * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteRemoteRepositoryAction"
  33. */
  34. public class DeleteRemoteRepositoryAction
  35. extends AbstractRemoteRepositoriesAction
  36. implements Preparable
  37. {
  38. private RemoteRepositoryConfiguration repository;
  39. private String repoid;
  40. public void prepare()
  41. {
  42. if ( StringUtils.isNotBlank( repoid ) )
  43. {
  44. this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoid );
  45. }
  46. }
  47. public String confirmDelete()
  48. {
  49. if ( StringUtils.isBlank( repoid ) )
  50. {
  51. addActionError( "Unable to delete remote repository: repository id was blank." );
  52. return ERROR;
  53. }
  54. return INPUT;
  55. }
  56. public String delete()
  57. {
  58. String result = SUCCESS;
  59. RemoteRepositoryConfiguration existingRepository = repository;
  60. if ( existingRepository == null )
  61. {
  62. addActionError( "A repository with that id does not exist" );
  63. return ERROR;
  64. }
  65. Configuration configuration = archivaConfiguration.getConfiguration();
  66. removeRepository( repoid, configuration );
  67. result = saveConfiguration( configuration );
  68. cleanupRepositoryData( existingRepository );
  69. return result;
  70. }
  71. private void cleanupRepositoryData( RemoteRepositoryConfiguration existingRepository )
  72. {
  73. // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
  74. List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
  75. for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
  76. {
  77. if ( StringUtils.equals( proxyConnector.getTargetRepoId(), existingRepository.getId() ) )
  78. {
  79. archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
  80. }
  81. }
  82. }
  83. public RemoteRepositoryConfiguration getRepository()
  84. {
  85. return repository;
  86. }
  87. public void setRepository( RemoteRepositoryConfiguration repository )
  88. {
  89. this.repository = repository;
  90. }
  91. public String getRepoid()
  92. {
  93. return repoid;
  94. }
  95. public void setRepoid( String repoid )
  96. {
  97. this.repoid = repoid;
  98. }
  99. }