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);
}
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;
}
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;
}
Aggregations