1 package org.apache.archiva.reports;
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 org.apache.archiva.metadata.model.ProjectVersionMetadata;
23 import org.apache.archiva.metadata.repository.MetadataRepository;
24 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
25 import org.apache.archiva.metadata.repository.RepositorySession;
26 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataException;
27 import org.apache.archiva.repository.events.RepositoryListener;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.stereotype.Service;
33 * Process repository management events and respond appropriately.
35 * plexus.component role="org.apache.archiva.repository.events.RepositoryListener" role-hint="problem-reports"
37 @Service( "repositoryListener#problem-reports" )
38 public class RepositoryProblemEventListener
39 implements RepositoryListener
41 private Logger log = LoggerFactory.getLogger( RepositoryProblemEventListener.class );
43 // FIXME: move to session
44 public void deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace,
45 String project, String version, String id )
47 String name = RepositoryProblemFacet.createName( namespace, project, version, id );
51 metadataRepository.removeMetadataFacet( repositoryId, RepositoryProblemFacet.FACET_ID, name );
53 catch ( MetadataRepositoryException e )
55 log.warn( "Unable to remove metadata facet as part of delete event: " + e.getMessage(), e );
59 public void addArtifact( RepositorySession session, String repoId, String namespace, String projectId,
60 ProjectVersionMetadata metadata )
62 // Remove problems associated with this version on successful addition
63 // TODO: this removes all problems - do we need something that just remove the problems we know are corrected?
64 String name = RepositoryProblemFacet.createName( namespace, projectId, metadata.getId(), null );
67 MetadataRepository metadataRepository = session.getRepository();
68 metadataRepository.removeMetadataFacet( repoId, RepositoryProblemFacet.FACET_ID, name );
71 catch ( MetadataRepositoryException e )
73 log.warn( "Unable to remove repository problem facets for the version being corrected in the repository: "
74 + e.getMessage(), e );
78 public void addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId,
79 String projectVersion, RepositoryStorageMetadataException exception )
81 RepositoryProblemFacet problem = new RepositoryProblemFacet();
82 problem.setMessage( exception.getMessage() );
83 problem.setProject( projectId );
84 problem.setNamespace( namespace );
85 problem.setRepositoryId( repoId );
86 problem.setVersion( projectVersion );
87 problem.setProblem( exception.getId() );
91 session.getRepository().addMetadataFacet( repoId, problem );
94 catch ( MetadataRepositoryException e )
96 log.warn( "Unable to add repository problem facets for the version being removed: " + e.getMessage(), e );