diff options
Diffstat (limited to 'archiva-modules/archiva-web')
13 files changed, 138 insertions, 328 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp/pom.xml b/archiva-modules/archiva-web/archiva-webapp/pom.xml index 6695cd840..b39989c85 100644 --- a/archiva-modules/archiva-web/archiva-webapp/pom.xml +++ b/archiva-modules/archiva-web/archiva-webapp/pom.xml @@ -51,10 +51,6 @@ </dependency> <dependency> <groupId>org.apache.archiva</groupId> - <artifactId>archiva-database</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> <artifactId>archiva-repository-layer</artifactId> </dependency> <dependency> @@ -67,10 +63,6 @@ </dependency> <dependency> <groupId>org.apache.archiva</groupId> - <artifactId>archiva-database-consumers</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> <artifactId>archiva-metadata-consumer</artifactId> <version>1.3-SNAPSHOT</version> <scope>runtime</scope> diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java index 79ca76474..6994e9655 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java @@ -24,6 +24,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; @@ -33,14 +34,12 @@ import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Validateable; import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksummedFile; +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.maven.archiva.common.utils.VersionComparator; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.maven.archiva.database.ArchivaDatabaseException; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.constraints.ArtifactVersionsConstraint; -import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaRepositoryMetadata; import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.ContentNotFoundException; @@ -62,7 +61,7 @@ import org.apache.maven.archiva.security.UserRepositories; /** * Delete an artifact. Metadata will be updated if one exists, otherwise it would be created. - * + * * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteArtifactAction" instantiation-strategy="per-lookup" */ public class DeleteArtifactAction @@ -110,14 +109,16 @@ public class DeleteArtifactAction private RepositoryContentFactory repositoryFactory; /** - * @plexus.requirement role-hint="jdo" + * @plexus.requirement role="org.apache.maven.archiva.repository.events.RepositoryListener" */ - private ArtifactDAO artifactDAO; - - /** @plexus.requirement role="org.apache.maven.archiva.repository.events.RepositoryListener" */ private List<RepositoryListener> listeners; - private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; + private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5}; + + /** + * @plexus.requirement + */ + private MetadataRepository metadataRepository; public String getGroupId() { @@ -217,6 +218,7 @@ public class DeleteArtifactAction throw new ContentNotFoundException( groupId + ":" + artifactId + ":" + version ); } + // TODO: this should be in the storage mechanism so that it is all tied together // delete from file system repository.deleteVersion( ref ); @@ -225,40 +227,31 @@ public class DeleteArtifactAction updateMetadata( metadata, metadataFile, lastUpdatedTimestamp ); - ArtifactVersionsConstraint constraint = - new ArtifactVersionsConstraint( repositoryId, groupId, artifactId, false ); - List<ArchivaArtifact> artifacts = null; + Collection<ArtifactMetadata> artifacts = + metadataRepository.getArtifacts( repositoryId, groupId, artifactId, version ); - try + for ( ArtifactMetadata artifact : artifacts ) { - artifacts = artifactDAO.queryArtifacts( constraint ); - - if ( artifacts != null ) + if ( artifact.getVersion().equals( version ) ) { - for ( ArchivaArtifact artifact : artifacts ) + metadataRepository.deleteArtifact( artifact.getRepositoryId(), artifact.getNamespace(), + artifact.getProject(), artifact.getVersion(), + artifact.getId() ); + + // TODO: move into the metadata repository proper - need to differentiate attachment of + // repository metadata to an artifact + for ( RepositoryListener listener : listeners ) { - if ( artifact.getVersion().equals( version ) ) - { - for ( RepositoryListener listener : listeners ) - { - listener.deleteArtifact( repository, artifact ); - } - } + listener.deleteArtifact( repository.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion(), artifact.getId() ); } } } - catch ( ArchivaDatabaseException e ) - { - addActionError( "Error occurred while cleaning up database: " + e.getMessage() ); - return ERROR; - } - String msg = - "Artifact \'" + groupId + ":" + artifactId + ":" + version + - "\' was successfully deleted from repository \'" + repositoryId + "\'"; + String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version + + "\' was successfully deleted from repository \'" + repositoryId + "\'"; - triggerAuditEvent( repositoryId, groupId + ":" + artifactId + ":" + version, - AuditEvent.REMOVE_FILE ); + triggerAuditEvent( repositoryId, groupId + ":" + artifactId + ":" + version, AuditEvent.REMOVE_FILE ); addActionMessage( msg ); @@ -302,7 +295,7 @@ public class DeleteArtifactAction /** * Update artifact level metadata. Creates one if metadata does not exist after artifact deletion. - * + * * @param metadata */ private void updateMetadata( ArchivaRepositoryMetadata metadata, File metadataFile, Date lastUpdatedTimestamp ) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java index 73738a6b5..237a1936b 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -24,17 +24,12 @@ import java.util.List; import java.util.Map; import com.opensymphony.xwork2.Preparable; +import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.maven.archiva.database.ArchivaDatabaseException; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.Constraint; -import org.apache.maven.archiva.database.ObjectNotFoundException; -import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint; -import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.repository.audit.AuditEvent; import org.codehaus.plexus.redback.role.RoleManagerException; @@ -53,14 +48,14 @@ public class DeleteManagedRepositoryAction private String repoid; /** - * @plexus.requirement role-hint="jdo" + * @plexus.requirement */ - private ArtifactDAO artifactDao; + private RepositoryStatisticsManager repositoryStatisticsManager; /** * @plexus.requirement */ - private RepositoryStatisticsManager repositoryStatisticsManager; + private MetadataRepository metadataRepository; public void prepare() { @@ -128,17 +123,12 @@ public class DeleteManagedRepositoryAction addActionError( "Unable to delete repository: " + e.getMessage() ); result = ERROR; } - catch ( ArchivaDatabaseException e ) - { - addActionError( "Unable to delete repositoy: " + e.getMessage() ); - result = ERROR; - } return result; } private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository ) - throws RoleManagerException, ArchivaDatabaseException + throws RoleManagerException { removeRepositoryRoles( cleanupRepository ); cleanupDatabase( cleanupRepository.getId() ); @@ -169,31 +159,8 @@ public class DeleteManagedRepositoryAction } private void cleanupDatabase( String repoId ) - throws ArchivaDatabaseException { - Constraint constraint = new ArtifactsByRepositoryConstraint( repoId ); - - List<ArchivaArtifact> artifacts = artifactDao.queryArtifacts( constraint ); - - for ( ArchivaArtifact artifact : artifacts ) - { - log.info( "Removing artifact " + artifact + " from the database." ); - try - { - artifactDao.deleteArtifact( artifact ); - - } - catch ( ObjectNotFoundException oe ) - { - log.info( "Project model of artifact " + artifact + " does not exist in the database. " + - "Moving on to the next artifact." ); - } - catch ( ArchivaDatabaseException ae ) - { - log.info( "Unable to delete artifact " + artifact + " from the database. " + - "Moving on to the next artifact." ); - } - } + metadataRepository.deleteRepository( repoId ); } public ManagedRepositoryConfiguration getRepository() @@ -221,8 +188,8 @@ public class DeleteManagedRepositoryAction this.repositoryStatisticsManager = repositoryStatisticsManager; } - public void setArtifactDao( ArtifactDAO artifactDao ) + public void setMetadataRepository( MetadataRepository metadataRepository ) { - this.artifactDao = artifactDao; + this.metadataRepository = metadataRepository; } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java index b883a4338..7f030a06c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java @@ -183,6 +183,16 @@ public class TestMetadataRepository return null; //To change body of implemented methods use File | Settings | File Templates. } + public void deleteArtifact( String repositoryId, String namespace, String project, String version, String id ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void deleteRepository( String repoId ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, String projectVersion ) { diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java deleted file mode 100644 index ab419cbd8..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.maven.archiva.web.action.admin.repositories; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.List; - -import org.apache.maven.archiva.database.ArchivaDAO; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.SimpleConstraint; - -/** - * Stub class for Archiva DAO to avoid having to set up a database for tests. - * - * @todo a mock would be better, but that won't play nicely with Plexus injection. - */ -public class ArchivaDAOStub - implements ArchivaDAO -{ - - private ArtifactDAO artifactDao; - - public List<?> query( SimpleConstraint constraint ) - { - throw new UnsupportedOperationException(); - } - - public ArtifactDAO getArtifactDAO() - { - return artifactDao; - } - - public void setArtifactDao( ArtifactDAO artifactDao ) - { - this.artifactDao = artifactDao; - } - -} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java deleted file mode 100644 index 3efb1ec6b..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.apache.maven.archiva.web.action.admin.repositories; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.archiva.database.ArchivaDatabaseException; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.Constraint; -import org.apache.maven.archiva.database.ObjectNotFoundException; -import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.model.ArchivaArtifactModel; - -/** - * ArtifactDAOStub - * - * @version - */ -public class ArtifactDAOStub - implements ArtifactDAO -{ - - public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier, - String type, String repositoryId ) - { - // TODO Auto-generated method stub - return null; - } - - public void deleteArtifact( ArchivaArtifact artifact ) - throws ArchivaDatabaseException - { - // TODO Auto-generated method stub - - } - - public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier, - String type, String repositoryId ) - throws ObjectNotFoundException, ArchivaDatabaseException - { - // TODO Auto-generated method stub - return null; - } - - public List<ArchivaArtifact> queryArtifacts( Constraint constraint ) - throws ObjectNotFoundException, ArchivaDatabaseException - { - - List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>(); - - ArchivaArtifactModel model = new ArchivaArtifactModel(); - model.setGroupId( "org.apache.maven.archiva" ); - model.setArtifactId( "test-artifact" ); - model.setVersion( "1.0" ); - model.setType( "jar" ); - model.setRepositoryId( "repo-ident" ); - - ArchivaArtifact artifact = new ArchivaArtifact( model ); - artifacts.add( artifact ); - - return artifacts; - } - - public ArchivaArtifact saveArtifact( ArchivaArtifact artifact ) - throws ArchivaDatabaseException - { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index 486fd0e53..d4f631679 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.List; import com.opensymphony.xwork2.Action; +import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; @@ -88,7 +89,12 @@ public class DeleteManagedRepositoryActionTest repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock(); action.setRepositoryStatisticsManager( repositoryStatisticsManager ); - action.setArtifactDao( new ArtifactDAOStub() ); + MockControl metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); + MetadataRepository metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); + metadataRepository.deleteRepository( REPO_ID ); + action.setMetadataRepository( metadataRepository ); + + metadataRepositoryControl.replay(); } public void testSecureActionBundle() diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java index be7a07c4a..01c8a11e5 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/reports/GenerateReportActionTest.java @@ -33,7 +33,6 @@ import org.apache.archiva.metadata.repository.stats.RepositoryStatistics; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.reports.RepositoryProblemFacet; import org.apache.commons.io.IOUtils; -import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; @@ -247,7 +246,7 @@ public class GenerateReportActionTest } public void testDownloadStatisticsSingleRepo() - throws IOException, ArchivaDatabaseException + throws IOException { Date date = new Date(); repositoryStatisticsManagerControl.expectAndReturn( @@ -269,7 +268,7 @@ public class GenerateReportActionTest } public void testDownloadStatisticsMultipleRepos() - throws IOException, ArchivaDatabaseException + throws IOException { repositoryStatisticsManagerControl.expectAndReturn( repositoryStatisticsManager.getStatisticsInRange( SNAPSHOTS, null, null ), diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.xml index 1d3db6882..a38222d17 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.xml @@ -20,22 +20,6 @@ <plexus> <components> <component> - <role>org.apache.maven.archiva.database.ArchivaDAO</role> - <role-hint>jdo</role-hint> - <implementation>org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub</implementation> - <requirements> - <requirement> - <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> - <field-name>configuration</field-name> - </requirement> - </requirements> - </component> - <component> - <role>org.apache.maven.archiva.database.ArtifactDAO</role> - <role-hint>jdo</role-hint> - <implementation>org.apache.maven.archiva.web.action.admin.repositories.ArtifactDAOStub</implementation> - </component> - <component> <role>org.apache.maven.archiva.security.UserRepositories</role> <role-hint>default</role-hint> <implementation>org.apache.maven.archiva.security.UserRepositoriesStub</implementation> diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index 021a6a030..26393052b 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -144,6 +144,16 @@ public class TestMetadataRepository return null; //To change body of implemented methods use File | Settings | File Templates. } + public void deleteArtifact( String repositoryId, String namespace, String project, String version, String id ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + + public void deleteRepository( String repoId ) + { + //To change body of implemented methods use File | Settings | File Templates. + } + public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, String projectVersion ) { diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml index 56108f745..665095d74 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml @@ -44,10 +44,6 @@ </dependency> <dependency> <groupId>org.apache.archiva</groupId> - <artifactId>archiva-database</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> <artifactId>archiva-xmlrpc-api</artifactId> </dependency> <dependency> diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java index d1a2357d7..2149d7cb4 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java @@ -23,6 +23,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.repository.scanner.RepositoryContentConsumers; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryTask; @@ -37,10 +39,6 @@ import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration; import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.database.ArchivaDatabaseException; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.database.constraints.ArtifactVersionsConstraint; -import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.VersionedReference; import org.apache.maven.archiva.repository.ContentNotFoundException; import org.apache.maven.archiva.repository.ManagedRepositoryContent; @@ -68,23 +66,23 @@ public class AdministrationServiceImpl private RepositoryContentFactory repoFactory; - private ArtifactDAO artifactDAO; - private RepositoryArchivaTaskScheduler repositoryTaskScheduler; private Collection<RepositoryListener> listeners; + private MetadataRepository metadataRepository; + public AdministrationServiceImpl( ArchivaConfiguration archivaConfig, RepositoryContentConsumers repoConsumersUtil, - RepositoryContentFactory repoFactory, ArtifactDAO artifactDAO, + RepositoryContentFactory repoFactory, MetadataRepository metadataRepository, RepositoryArchivaTaskScheduler repositoryTaskScheduler, Collection<RepositoryListener> listeners ) { this.archivaConfiguration = archivaConfig; this.repoConsumersUtil = repoConsumersUtil; this.repoFactory = repoFactory; - this.artifactDAO = artifactDAO; this.repositoryTaskScheduler = repositoryTaskScheduler; this.listeners = listeners; + this.metadataRepository = metadataRepository; } /** @@ -142,7 +140,7 @@ public class AdministrationServiceImpl config.setRepositoryScanning( repoScanningConfig ); saveConfiguration( config ); - return new Boolean( true ); + return true; } /** @@ -151,6 +149,8 @@ public class AdministrationServiceImpl public Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception { + // TODO: remove duplication with web + Configuration config = archivaConfiguration.getConfiguration(); ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( repoId ); @@ -170,28 +170,23 @@ public class AdministrationServiceImpl // delete from file system repoContent.deleteVersion( ref ); - ArtifactVersionsConstraint constraint = new ArtifactVersionsConstraint( repoId, groupId, artifactId, false ); - List<ArchivaArtifact> artifacts = null; + Collection<ArtifactMetadata> artifacts = + metadataRepository.getArtifacts( repoId, groupId, artifactId, version ); - try - { - artifacts = artifactDAO.queryArtifacts( constraint ); - } - catch ( ArchivaDatabaseException e ) + for ( ArtifactMetadata artifact : artifacts ) { - throw new Exception( "Error occurred while cleaning up database." ); - } - - if ( artifacts != null ) - { - for ( ArchivaArtifact artifact : artifacts ) + if ( artifact.getVersion().equals( version ) ) { - if ( artifact.getVersion().equals( version ) ) + metadataRepository.deleteArtifact( artifact.getRepositoryId(), artifact.getNamespace(), + artifact.getProject(), artifact.getVersion(), + artifact.getId() ); + + // TODO: move into the metadata repository proper - need to differentiate attachment of + // repository metadata to an artifact + for ( RepositoryListener listener : listeners ) { - for ( RepositoryListener listener : listeners ) - { - listener.deleteArtifact( repoContent, artifact ); - } + listener.deleteArtifact( repoId, artifact.getNamespace(), artifact.getProject(), + artifact.getVersion(), artifact.getId() ); } } } @@ -209,7 +204,7 @@ public class AdministrationServiceImpl throw new Exception( "Repository exception occurred." ); } - return new Boolean( true ); + return true; } /** @@ -233,7 +228,7 @@ public class AdministrationServiceImpl repositoryTaskScheduler.queueTask( task ); - return new Boolean( true ); + return true; } /** diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java index 642e1be4b..310225772 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.repository.scanner.RepositoryContentConsumers; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryTask; @@ -40,9 +42,6 @@ import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration; import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.model.ArchivaArtifactModel; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent; @@ -74,8 +73,6 @@ public class AdministrationServiceImplTest private MockControl repositoryTaskSchedulerControl; - private MockControl databaseTaskSchedulerControl; - private RepositoryArchivaTaskScheduler repositoryTaskScheduler; // repository consumers @@ -100,16 +97,14 @@ public class AdministrationServiceImplTest private RepositoryContentFactory repositoryFactory; - private MockControl artifactDaoControl; - - private ArtifactDAO artifactDao; - private MockControl listenerControl; private RepositoryListener listener; - private MockControl cleanupConsumersControl; - + private MockControl metadataRepositoryControl; + + private MetadataRepository metadataRepository; + protected void setUp() throws Exception { @@ -140,15 +135,15 @@ public class AdministrationServiceImplTest repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class ); repositoryFactory = ( RepositoryContentFactory ) repoFactoryControl.getMock(); - artifactDaoControl = MockControl.createControl( ArtifactDAO.class ); - artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock(); + metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); + metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); listenerControl = MockControl.createControl( RepositoryListener.class ); listener = (RepositoryListener) listenerControl.getMock(); service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory, - artifactDao, repositoryTaskScheduler, + metadataRepository, repositoryTaskScheduler, Collections.singletonList( listener ) ); } @@ -305,19 +300,23 @@ public class AdministrationServiceImplTest repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent ); - List<ArchivaArtifact> artifacts = getArtifacts(); - - artifactDao.queryArtifacts( null ); - artifactDaoControl.setMatcher( MockControl.ALWAYS_MATCHER ); - artifactDaoControl.setReturnValue( artifacts ); - - listener.deleteArtifact( repoContent, artifacts.get( 0 ) ); + List<ArtifactMetadata> artifacts = getArtifacts(); + ArtifactMetadata artifact = artifacts.get( 0 ); + + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion() ), artifacts ); + metadataRepository.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion(), artifact.getId() ); + + listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion(), artifact.getId() ); listenerControl.setVoidCallable( 1 ); archivaConfigControl.replay(); configControl.replay(); repoFactoryControl.replay(); - artifactDaoControl.replay(); + metadataRepositoryControl.replay(); listenerControl.replay(); boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" ); @@ -326,7 +325,7 @@ public class AdministrationServiceImplTest archivaConfigControl.verify(); configControl.verify(); repoFactoryControl.verify(); - artifactDaoControl.verify(); + metadataRepositoryControl.verify(); listenerControl.verify(); assertFalse( new File( managedRepo.getLocation(), "org/apache/archiva/archiva-test/1.0" ).exists() ); @@ -356,19 +355,23 @@ public class AdministrationServiceImplTest recordInManagedLegacyRepoContent( fileTypesControl, fileTypes, pathParserControl, parser ); - List<ArchivaArtifact> artifacts = getArtifacts(); - - artifactDao.queryArtifacts( null ); - artifactDaoControl.setMatcher( MockControl.ALWAYS_MATCHER ); - artifactDaoControl.setReturnValue( artifacts ); - - listener.deleteArtifact( repoContent, artifacts.get( 0 ) ); + List<ArtifactMetadata> artifacts = getArtifacts(); + ArtifactMetadata artifact = artifacts.get( 0 ); + + metadataRepositoryControl.expectAndReturn( + metadataRepository.getArtifacts( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion() ), artifacts ); + metadataRepository.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion(), artifact.getId() ); + + listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(), + artifact.getVersion(), artifact.getId() ); listenerControl.setVoidCallable( 1 ); archivaConfigControl.replay(); configControl.replay(); repoFactoryControl.replay(); - artifactDaoControl.replay(); + metadataRepositoryControl.replay(); listenerControl.replay(); fileTypesControl.replay(); pathParserControl.replay(); @@ -379,7 +382,7 @@ public class AdministrationServiceImplTest archivaConfigControl.verify(); configControl.verify(); repoFactoryControl.verify(); - artifactDaoControl.verify(); + metadataRepositoryControl.verify(); listenerControl.verify(); fileTypesControl.verify(); pathParserControl.verify(); @@ -576,8 +579,8 @@ public class AdministrationServiceImplTest assertNotNull( repos ); assertEquals( 2, repos.size() ); - assertManagedRepo( ( ManagedRepository ) repos.get( 0 ), managedRepos.get( 0 ) ); - assertManagedRepo( ( ManagedRepository ) repos.get( 1 ), managedRepos.get( 1 ) ); + assertManagedRepo( repos.get( 0 ), managedRepos.get( 0 ) ); + assertManagedRepo( repos.get( 1 ), managedRepos.get( 1 ) ); } public void testGetAllRemoteRepositories() @@ -601,8 +604,8 @@ public class AdministrationServiceImplTest assertNotNull( repos ); assertEquals( 2, repos.size() ); - assertRemoteRepo( (RemoteRepository) repos.get( 0 ), remoteRepos.get( 0 ) ); - assertRemoteRepo( (RemoteRepository) repos.get( 1 ), remoteRepos.get( 1 ) ); + assertRemoteRepo( repos.get( 0 ), remoteRepos.get( 0 ) ); + assertRemoteRepo( repos.get( 1 ), remoteRepos.get( 1 ) ); } /* private methods */ @@ -708,18 +711,16 @@ public class AdministrationServiceImplTest pathParserControl.expectAndReturn( parser.toArtifactReference( at11j ), aRef ); } - private List<ArchivaArtifact> getArtifacts() + private List<ArtifactMetadata> getArtifacts() { - List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>(); - - ArchivaArtifactModel model = new ArchivaArtifactModel(); - model.setRepositoryId( "internal" ); - model.setGroupId( "org.apache.archiva" ); - model.setArtifactId( "archiva-test" ); - model.setVersion( "1.0" ); - model.setType( "jar" ); - - ArchivaArtifact artifact = new ArchivaArtifact( model ); + List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>(); + + ArtifactMetadata artifact = new ArtifactMetadata(); + artifact.setId( "archiva-test-1.0.jar" ); + artifact.setProject( "archiva-test" ); + artifact.setVersion( "1.0" ); + artifact.setNamespace( "org.apache.archiva" ); + artifact.setRepositoryId( "internal" ); artifacts.add( artifact ); return artifacts; } |