Search in sources :

Example 11 with MetadataRepository

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

the class DefaultBrowseService method addMetadata.

@Override
public Boolean addMetadata(String groupId, String artifactId, String version, String key, String value, String repositoryId) throws ArchivaRestServiceException {
    ProjectVersionMetadata projectVersionMetadata = getProjectMetadata(groupId, artifactId, version, repositoryId);
    if (projectVersionMetadata == null) {
        return Boolean.FALSE;
    }
    Map<String, String> properties = new HashMap<>();
    MetadataFacet metadataFacet = projectVersionMetadata.getFacet(GenericMetadataFacet.FACET_ID);
    if (metadataFacet != null && metadataFacet.toProperties() != null) {
        properties.putAll(metadataFacet.toProperties());
    } else {
        metadataFacet = new GenericMetadataFacet();
    }
    properties.put(key, value);
    metadataFacet.fromProperties(properties);
    projectVersionMetadata.addFacet(metadataFacet);
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        metadataRepository.updateProjectVersion(repositoryId, groupId, artifactId, projectVersionMetadata);
        repositorySession.save();
    } catch (MetadataRepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        repositorySession.close();
    }
    return Boolean.TRUE;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) HashMap(java.util.HashMap) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession)

Example 12 with MetadataRepository

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

the class DefaultBrowseService method deleteMetadata.

@Override
public Boolean deleteMetadata(String groupId, String artifactId, String version, String key, String repositoryId) throws ArchivaRestServiceException {
    ProjectVersionMetadata projectVersionMetadata = getProjectMetadata(groupId, artifactId, version, repositoryId);
    if (projectVersionMetadata == null) {
        return Boolean.FALSE;
    }
    GenericMetadataFacet metadataFacet = (GenericMetadataFacet) projectVersionMetadata.getFacet(GenericMetadataFacet.FACET_ID);
    if (metadataFacet != null && metadataFacet.toProperties() != null) {
        Map<String, String> properties = metadataFacet.toProperties();
        properties.remove(key);
        metadataFacet.setAdditionalProperties(properties);
    } else {
        return Boolean.TRUE;
    }
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        metadataRepository.updateProjectVersion(repositoryId, groupId, artifactId, projectVersionMetadata);
        repositorySession.save();
    } catch (MetadataRepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        repositorySession.close();
    }
    return Boolean.TRUE;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession)

Example 13 with MetadataRepository

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

the class DefaultManagedRepositoriesService method getManagedRepositoryStatistics.

@Override
public ArchivaRepositoryStatistics getManagedRepositoryStatistics(String repositoryId, String lang) throws ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", new Locale(lang));
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        RepositoryStatistics stats = null;
        try {
            stats = repositoryStatisticsManager.getLastStatistics(metadataRepository, repositoryId);
        } catch (MetadataRepositoryException e) {
            log.warn("Error retrieving repository statistics: {}", e.getMessage(), e);
        }
        if (stats != null) {
            ArchivaRepositoryStatistics archivaRepositoryStatistics = getModelMapper().map(stats, ArchivaRepositoryStatistics.class);
            archivaRepositoryStatistics.setDuration(archivaRepositoryStatistics.getScanEndTime().getTime() - archivaRepositoryStatistics.getScanStartTime().getTime());
            archivaRepositoryStatistics.setLastScanDate(sdf.format(archivaRepositoryStatistics.getScanEndTime()));
            return archivaRepositoryStatistics;
        }
    } finally {
        if (repositorySession != null) {
            repositorySession.close();
        }
    }
    return null;
}
Also used : Locale(java.util.Locale) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) SimpleDateFormat(java.text.SimpleDateFormat) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)

Example 14 with MetadataRepository

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

the class DefaultMergeRepositoriesService method doMerge.

protected void doMerge(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
        if (repository.isReleases() && !repository.isSnapshots()) {
            mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
        } else {
            repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId);
            for (ArtifactMetadata metadata : sourceArtifacts) {
                triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
            }
        }
        doScanRepository(targetRepositoryId, false);
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 15 with MetadataRepository

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

the class DefaultMergeRepositoriesService method mergeBySkippingConflicts.

public void mergeBySkippingConflicts(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        List<ArtifactMetadata> conflictSourceArtifacts = repositoryMerger.getConflictingArtifacts(repositorySession.getRepository(), sourceRepositoryId, targetRepositoryId);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
        sourceArtifacts.removeAll(conflictSourceArtifacts);
        ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
        if (repository.isReleases() && !repository.isSnapshots()) {
            mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
        } else {
            Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(sourceArtifacts);
            repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId, artifactsWithOutConflicts);
            for (ArtifactMetadata metadata : sourceArtifacts) {
                triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
            }
        }
        doScanRepository(targetRepositoryId, false);
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) IncludesFilter(org.apache.archiva.metadata.repository.filter.IncludesFilter) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Aggregations

MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)25 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)20 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)18 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)10 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)8 Path (java.nio.file.Path)6 RepositoryException (org.apache.archiva.repository.RepositoryException)6 ArrayList (java.util.ArrayList)5 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)4 ArtifactReference (org.apache.archiva.model.ArtifactReference)4 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)4 IOException (java.io.IOException)3 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)3 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)3 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)3 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)3 VersionedReference (org.apache.archiva.model.VersionedReference)3 RepositoryListener (org.apache.archiva.repository.events.RepositoryListener)3