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.model.facets.RepositoryProblemFacet;
24 import org.apache.archiva.metadata.repository.MetadataRepository;
25 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
26 import org.apache.archiva.metadata.repository.RepositorySession;
27 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
28 import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataException;
29 import org.apache.archiva.repository.events.RepositoryListener;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.stereotype.Service;
34 import javax.inject.Inject;
37 * Process repository management events and respond appropriately.
40 @Service( "repositoryListener#problem-reports" )
41 public class RepositoryProblemEventListener
42 implements RepositoryListener
44 private Logger log = LoggerFactory.getLogger( RepositoryProblemEventListener.class );
47 private RepositorySessionFactory repositorySessionFactory;
49 // FIXME: move to session
51 public void deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace,
52 String project, String version, String id )
54 String name = RepositoryProblemFacet.createName( namespace, project, version, id );
56 try(RepositorySession session = repositorySessionFactory.createSession())
58 metadataRepository.removeMetadataFacet(session , repositoryId, RepositoryProblemFacet.FACET_ID, name );
60 catch ( MetadataRepositoryException e )
62 log.warn( "Unable to remove metadata facet as part of delete event: {}", e.getMessage(), e );
67 public void addArtifact( RepositorySession session, String repoId, String namespace, String projectId,
68 ProjectVersionMetadata metadata )
70 // Remove problems associated with this version on successful addition
71 // TODO: this removes all problems - do we need something that just remove the problems we know are corrected?
72 String name = RepositoryProblemFacet.createName( namespace, projectId, metadata.getId(), null );
75 MetadataRepository metadataRepository = session.getRepository();
76 metadataRepository.removeMetadataFacet(session , repoId, RepositoryProblemFacet.FACET_ID, name );
79 catch ( MetadataRepositoryException e )
81 log.warn( "Unable to remove repository problem facets for the version being corrected in the repository: {}",
87 public void addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId,
88 String projectVersion, RepositoryStorageMetadataException exception )
90 RepositoryProblemFacet problem = new RepositoryProblemFacet();
91 problem.setMessage( exception.getMessage() );
92 problem.setProject( projectId );
93 problem.setNamespace( namespace );
94 problem.setRepositoryId( repoId );
95 problem.setVersion( projectVersion );
96 problem.setProblem( exception.getId() );
100 session.getRepository().addMetadataFacet(session , repoId, problem );
103 catch ( MetadataRepositoryException e )
105 log.warn( "Unable to add repository problem facets for the version being removed: {}", e.getMessage(), e );