Search in sources :

Example 1 with GenericMetadataFacet

use of org.apache.archiva.metadata.generic.GenericMetadataFacet in project archiva by apache.

the class AbstractMetadataRepositoryTest method createArtifactWithGenericMetadataFacet.

private void createArtifactWithGenericMetadataFacet(int artifacts) throws MetadataRepositoryException, MetadataResolutionException {
    MetadataFacet metadataFacet = new GenericMetadataFacet();
    Map<String, String> properties = new HashMap<>();
    properties.put(TEST_METADATA_KEY, TEST_METADATA_VALUE);
    metadataFacet.fromProperties(properties);
    createArtifactWithFacet(artifacts, null, metadataFacet);
}
Also used : HashMap(java.util.HashMap) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet)

Example 2 with GenericMetadataFacet

use of org.apache.archiva.metadata.generic.GenericMetadataFacet 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 3 with GenericMetadataFacet

use of org.apache.archiva.metadata.generic.GenericMetadataFacet 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)

Aggregations

GenericMetadataFacet (org.apache.archiva.metadata.generic.GenericMetadataFacet)3 HashMap (java.util.HashMap)2 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)2 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)2 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)2 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)2 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)2 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)2