Search in sources :

Example 1 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class MetadataAuditListener method auditEvent.

@Override
public void auditEvent(AuditEvent event) {
    // for now we only log upload events, some of the others are quite noisy
    if (event.getAction().equals(AuditEvent.CREATE_FILE) || event.getAction().equals(AuditEvent.UPLOAD_FILE) || event.getAction().equals(AuditEvent.MERGING_REPOSITORIES)) {
        RepositorySession repositorySession = repositorySessionFactory.createSession();
        try {
            auditManager.addAuditEvent(repositorySession.getRepository(), event);
            repositorySession.save();
        } catch (MetadataRepositoryException e) {
            log.warn("Unable to write audit event to repository: {}", e.getMessage(), e);
        } finally {
            repositorySession.close();
        }
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession)

Example 2 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class FileMetadataRepository method removeArtifact.

@Override
public void removeArtifact(ArtifactMetadata artifactMetadata, String baseVersion) throws MetadataRepositoryException {
    try {
        Path directory = getDirectory(artifactMetadata.getRepositoryId()).resolve(artifactMetadata.getNamespace() + "/" + artifactMetadata.getProject() + "/" + baseVersion);
        Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
        String id = artifactMetadata.getId();
        properties.remove("artifact:updated:" + id);
        properties.remove("artifact:whenGathered:" + id);
        properties.remove("artifact:size:" + id);
        properties.remove("artifact:md5:" + id);
        properties.remove("artifact:sha1:" + id);
        properties.remove("artifact:version:" + id);
        properties.remove("artifact:facetIds:" + id);
        String prefix = "artifact:facet:" + id + ":";
        for (Object key : new ArrayList<>(properties.keySet())) {
            String property = (String) key;
            if (property.startsWith(prefix)) {
                properties.remove(property);
            }
        }
        writeProperties(properties, directory, PROJECT_VERSION_METADATA_KEY);
    } catch (IOException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties)

Example 3 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class FileMetadataRepository method removeRepository.

@Override
public void removeRepository(String repoId) throws MetadataRepositoryException {
    try {
        Path dir = getDirectory(repoId);
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(dir);
    } catch (IOException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException)

Example 4 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class FileMetadataRepository method removeNamespace.

@Override
public void removeNamespace(String repositoryId, String project) throws MetadataRepositoryException {
    try {
        Path namespaceDirectory = getDirectory(repositoryId).resolve(project);
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(namespaceDirectory);
    // Properties properties = new Properties();
    // properties.setProperty( "namespace", namespace );
    // writeProperties( properties, namespaceDirectory, NAMESPACE_METADATA_KEY );
    } catch (IOException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException)

Example 5 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class FileMetadataRepository method removeMetadataFacet.

@Override
public void removeMetadataFacet(String repoId, String facetId, String name) throws MetadataRepositoryException {
    try {
        Path dir = getMetadataDirectory(repoId, facetId).resolve(name);
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(dir);
    } catch (IOException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException)

Aggregations

MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)65 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)24 RepositoryException (javax.jcr.RepositoryException)22 Node (javax.jcr.Node)21 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)19 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)18 Path (java.nio.file.Path)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)10 HashMap (java.util.HashMap)8 RepositoryException (org.apache.archiva.repository.RepositoryException)8 Map (java.util.Map)6 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)6 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)6 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)6 Date (java.util.Date)5 Query (javax.jcr.query.Query)5 QueryResult (javax.jcr.query.QueryResult)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5