diff options
author | Brett Porter <brett@apache.org> | 2010-12-29 06:14:04 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2010-12-29 06:14:04 +0000 |
commit | f56609efad6393b10c861446ec11ddda00f9a218 (patch) | |
tree | 05aad2cd341eff4c2c1e3397e8a93570ef27bcfc /archiva-modules/plugins/problem-reports/src | |
parent | a44b2ac9dd664f3a93e2a7001afd507abb218110 (diff) | |
download | archiva-f56609efad6393b10c861446ec11ddda00f9a218.tar.gz archiva-f56609efad6393b10c861446ec11ddda00f9a218.zip |
[MRM-1330] refactor access around the concept of a "repository session". See Javadoc for some notes. This should be a single entry point for application users of either the metadata repository, resolution, or storage access. The session needs to be explicitly closed (and modifications saved) to facilitate some storage mechanisms.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053542 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/problem-reports/src')
-rw-r--r-- | archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java index fe4201056..575af1e82 100644 --- a/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java +++ b/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/RepositoryProblemEventListener.java @@ -19,8 +19,11 @@ package org.apache.archiva.reports; * under the License. */ +import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepositoryException; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataException; import org.apache.archiva.repository.events.RepositoryListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,12 +38,9 @@ public class RepositoryProblemEventListener { private Logger log = LoggerFactory.getLogger( RepositoryProblemEventListener.class ); - /** - * @plexus.requirement - */ - private MetadataRepository metadataRepository; - - public void deleteArtifact( String repositoryId, String namespace, String project, String version, String id ) + // FIXME: move to session + public void deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace, + String project, String version, String id ) { String name = RepositoryProblemFacet.createName( namespace, project, version, id ); @@ -53,4 +53,46 @@ public class RepositoryProblemEventListener log.warn( "Unable to remove metadata facet as part of delete event: " + e.getMessage(), e ); } } + + public void addArtifact( RepositorySession session, String repoId, String namespace, String projectId, + ProjectVersionMetadata metadata ) + { + // Remove problems associated with this version on successful addition + // TODO: this removes all problems - do we need something that just remove the problems we know are corrected? + String name = RepositoryProblemFacet.createName( namespace, projectId, metadata.getId(), null ); + try + { + MetadataRepository metadataRepository = session.getRepository(); + metadataRepository.removeMetadataFacet( repoId, RepositoryProblemFacet.FACET_ID, name ); + session.markDirty(); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to remove repository problem facets for the version being corrected in the repository: " + + e.getMessage(), e ); + } + } + + public void addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion, RepositoryStorageMetadataException exception ) + { + RepositoryProblemFacet problem = new RepositoryProblemFacet(); + problem.setMessage( exception.getMessage() ); + problem.setProject( projectId ); + problem.setNamespace( namespace ); + problem.setRepositoryId( repoId ); + problem.setVersion( projectVersion ); + problem.setProblem( exception.getId() ); + + try + { + session.getRepository().addMetadataFacet( repoId, problem ); + session.markDirty(); + } + catch ( MetadataRepositoryException e ) + { + log.warn( "Unable to add repository problem facets for the version being removed: " + e.getMessage(), e ); + } + } + }
\ No newline at end of file |