1package org.apache.archiva.reports;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import org.apache.archiva.metadata.model.ProjectVersionMetadata;
23import org.apache.archiva.metadata.model.facets.RepositoryProblemFacet;
24import org.apache.archiva.metadata.repository.MetadataRepository;
25import org.apache.archiva.metadata.repository.MetadataRepositoryException;
26import org.apache.archiva.metadata.repository.RepositorySession;
27import org.apache.archiva.metadata.repository.RepositorySessionFactory;
28import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataException;
29import org.apache.archiva.metadata.audit.RepositoryListener;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32import org.springframework.stereotype.Service;
3334import javax.inject.Inject;
3536/**37 * Process repository management events and respond appropriately.38 *39 */40 @Service( "repositoryListener#problem-reports" )
41publicclassRepositoryProblemEventListener42implementsRepositoryListener43 {
44private Logger log = LoggerFactory.getLogger( RepositoryProblemEventListener.class );
4546 @Inject
47privateRepositorySessionFactory repositorySessionFactory;
4849// FIXME: move to session50 @Override
51publicvoid deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace,
52 String project, String version, String id )
53 {
54 String name = RepositoryProblemFacet.createName( namespace, project, version, id );
5556try(RepositorySession session = repositorySessionFactory.createSession())
57 {
58 metadataRepository.removeMetadataFacet(session , repositoryId, RepositoryProblemFacet.FACET_ID, name );
59 }
60catch ( MetadataRepositoryException e )
61 {
62 log.warn( "Unable to remove metadata facet as part of delete event: {}", e.getMessage(), e );
63 }
64 }
6566 @Override
67publicvoid addArtifact( RepositorySession session, String repoId, String namespace, String projectId,
68ProjectVersionMetadata metadata )
69 {
70// Remove problems associated with this version on successful addition71// 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 );
73try74 {
75MetadataRepository metadataRepository = session.getRepository();
76 metadataRepository.removeMetadataFacet(session , repoId, RepositoryProblemFacet.FACET_ID, name );
77 session.markDirty();
78 }
79catch ( MetadataRepositoryException e )
80 {
81 log.warn( "Unable to remove repository problem facets for the version being corrected in the repository: {}",
82 e.getMessage(), e );
83 }
84 }
8586 @Override
87publicvoid addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId,
88 String projectVersion, RepositoryStorageMetadataException exception )
89 {
90RepositoryProblemFacetsitoryProblemFacet.html#RepositoryProblemFacet">RepositoryProblemFacet problem = newRepositoryProblemFacet();
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() );
9798try99 {
100 session.getRepository().addMetadataFacet(session , repoId, problem );
101 session.markDirty();
102 }
103catch ( MetadataRepositoryException e )
104 {
105 log.warn( "Unable to add repository problem facets for the version being removed: {}", e.getMessage(), e );
106 }
107 }
108109 }