1 package org.apache.maven.archiva.web.action.admin.repositories;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.opensymphony.xwork.Preparable;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
28 import org.codehaus.plexus.redback.role.RoleManagerException;
30 import java.io.IOException;
31 import java.util.List;
34 * DeleteManagedRepositoryAction
36 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteManagedRepositoryAction"
41 public class DeleteManagedRepositoryAction
42 extends AbstractManagedRepositoriesAction
45 private ManagedRepositoryConfiguration repository;
47 private String repoid;
51 if ( StringUtils.isNotBlank( repoid ) )
53 this.repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
57 public String confirmDelete()
59 if ( StringUtils.isBlank( repoid ) )
61 addActionError( "Unable to delete managed repository: repository id was blank." );
68 public String deleteEntry()
70 return deleteRepository( false );
73 public String deleteContents()
75 return deleteRepository( true );
78 private String deleteRepository( boolean deleteContents )
80 ManagedRepositoryConfiguration existingRepository = repository;
81 if ( existingRepository == null )
83 addActionError( "A repository with that id does not exist" );
87 String result = SUCCESS;
91 Configuration configuration = archivaConfiguration.getConfiguration();
92 removeRepository( repoid, configuration );
93 result = saveConfiguration( configuration );
95 if ( result.equals( SUCCESS ) )
97 cleanupRepositoryData( existingRepository );
101 removeContents( existingRepository );
105 catch ( IOException e )
107 addActionError( "Unable to delete repository: " + e.getMessage() );
110 catch ( RoleManagerException e )
112 addActionError( "Unable to delete repository: " + e.getMessage() );
119 private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository )
120 throws RoleManagerException
122 removeRepositoryRoles( cleanupRepository );
124 // TODO: [MRM-382] Remove index from artifacts of deleted managed repositories.
126 // TODO: [MRM-265] After removing a managed repository - Browse/Search still see it
128 // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
129 List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
130 for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
132 if ( StringUtils.equals( proxyConnector.getSourceRepoId(), cleanupRepository.getId() ) )
134 archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
139 public ManagedRepositoryConfiguration getRepository()
144 public void setRepository( ManagedRepositoryConfiguration repository )
146 this.repository = repository;
149 public String getRepoid()
154 public void setRepoid( String repoid )
156 this.repoid = repoid;