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 java.io.IOException;
23 import java.util.List;
26 import com.opensymphony.xwork2.Preparable;
27 import org.apache.archiva.metadata.repository.MetadataRepository;
28 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
29 import org.apache.commons.lang.StringUtils;
30 import org.apache.maven.archiva.configuration.Configuration;
31 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
32 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
33 import org.apache.maven.archiva.repository.audit.AuditEvent;
34 import org.codehaus.plexus.redback.role.RoleManagerException;
37 * DeleteManagedRepositoryAction
40 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteManagedRepositoryAction" instantiation-strategy="per-lookup"
42 public class DeleteManagedRepositoryAction
43 extends AbstractManagedRepositoriesAction
46 private ManagedRepositoryConfiguration repository;
48 private String repoid;
53 private RepositoryStatisticsManager repositoryStatisticsManager;
58 private MetadataRepository metadataRepository;
62 if ( StringUtils.isNotBlank( repoid ) )
64 this.repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
68 public String confirmDelete()
70 if ( StringUtils.isBlank( repoid ) )
72 addActionError( "Unable to delete managed repository: repository id was blank." );
79 public String deleteEntry()
81 return deleteRepository( false );
84 public String deleteContents()
86 return deleteRepository( true );
89 private String deleteRepository( boolean deleteContents )
91 ManagedRepositoryConfiguration existingRepository = repository;
92 if ( existingRepository == null )
94 addActionError( "A repository with that id does not exist" );
102 Configuration configuration = archivaConfiguration.getConfiguration();
103 cleanupRepositoryData( existingRepository );
104 removeRepository( repoid, configuration );
105 triggerAuditEvent( repoid, null, AuditEvent.DELETE_MANAGED_REPO );
106 result = saveConfiguration( configuration );
108 if ( result.equals( SUCCESS ) )
110 if ( deleteContents )
112 removeContents( existingRepository );
116 catch ( IOException e )
118 addActionError( "Unable to delete repository: " + e.getMessage() );
121 catch ( RoleManagerException e )
123 addActionError( "Unable to delete repository: " + e.getMessage() );
130 private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository )
131 throws RoleManagerException
133 removeRepositoryRoles( cleanupRepository );
134 cleanupDatabase( cleanupRepository.getId() );
135 repositoryStatisticsManager.deleteStatistics( cleanupRepository.getId() );
136 // TODO: delete all content for a repository from the content API?
138 List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
139 for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
141 if ( StringUtils.equals( proxyConnector.getSourceRepoId(), cleanupRepository.getId() ) )
143 archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
147 Map<String, List<String>> repoToGroupMap = archivaConfiguration.getConfiguration().getRepositoryToGroupMap();
148 if( repoToGroupMap != null )
150 if( repoToGroupMap.containsKey( cleanupRepository.getId() ) )
152 List<String> repoGroups = repoToGroupMap.get( cleanupRepository.getId() );
153 for( String repoGroup : repoGroups )
155 archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository( cleanupRepository.getId() );
161 private void cleanupDatabase( String repoId )
163 metadataRepository.deleteRepository( repoId );
166 public ManagedRepositoryConfiguration getRepository()
171 public void setRepository( ManagedRepositoryConfiguration repository )
173 this.repository = repository;
176 public String getRepoid()
181 public void setRepoid( String repoid )
183 this.repoid = repoid;
186 public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
188 this.repositoryStatisticsManager = repositoryStatisticsManager;
191 public void setMetadataRepository( MetadataRepository metadataRepository )
193 this.metadataRepository = metadataRepository;