use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class Maven2RepositoryMetadataResolverTest method testModelWithJdkProfileActivation.
@Test
public void testModelWithJdkProfileActivation() throws Exception {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(TEST_REPO_ID).namespace("org.apache.maven").projectId("maven-archiver").projectVersion("2.4.1");
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
}
use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class ArchivaMetadataCreationConsumer method processFile.
@Override
public void processFile(String path) throws ConsumerException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
// note that we do minimal processing including checksums and POM information for performance of
// the initial scan. Any request for this information will be intercepted and populated on-demand
// or picked up by subsequent scans
ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath(repoId, path);
ProjectMetadata project = new ProjectMetadata();
project.setNamespace(artifact.getNamespace());
project.setId(artifact.getProject());
String projectVersion = VersionUtil.getBaseVersion(artifact.getVersion());
MetadataRepository metadataRepository = repositorySession.getRepository();
boolean createVersionMetadata = false;
// FIXME: maybe not too efficient since it may have already been read and stored for this artifact
ProjectVersionMetadata versionMetadata = null;
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(artifact.getNamespace()).projectId(artifact.getProject()).projectVersion(projectVersion);
versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
createVersionMetadata = true;
} catch (RepositoryStorageMetadataNotFoundException e) {
log.warn("Missing or invalid POM for artifact:{} (repository:{}); creating empty metadata", path, repoId);
versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId(projectVersion);
versionMetadata.setIncomplete(true);
createVersionMetadata = true;
} catch (RepositoryStorageMetadataInvalidException e) {
log.warn("Error occurred resolving POM for artifact:{} (repository:{}); message: {}", new Object[] { path, repoId, e.getMessage() });
}
// read the metadata and update it if it is newer or doesn't exist
artifact.setWhenGathered(whenGathered);
metadataRepository.updateArtifact(repoId, project.getNamespace(), project.getId(), projectVersion, artifact);
if (createVersionMetadata) {
metadataRepository.updateProjectVersion(repoId, project.getNamespace(), project.getId(), versionMetadata);
}
metadataRepository.updateProject(repoId, project);
repositorySession.save();
} catch (MetadataRepositoryException e) {
log.warn("Error occurred persisting metadata for artifact:{} (repository:{}); message: {}", path, repoId, e.getMessage(), e);
repositorySession.revert();
} catch (RepositoryStorageRuntimeException e) {
log.warn("Error occurred persisting metadata for artifact:{} (repository:{}); message: {}", path, repoId, e.getMessage(), e);
repositorySession.revert();
} finally {
repositorySession.close();
}
}
use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class BrowseServiceTest method getProjectVersionMetadata.
@Test
public void getProjectVersionMetadata() throws Exception {
BrowseService browseService = getBrowseService(authorizationHeader, true);
ProjectVersionMetadata metadata = browseService.getProjectVersionMetadata("org.apache.karaf.features", "org.apache.karaf.features.core", TEST_REPO_ID);
assertThat(metadata).isNotNull();
}
use of org.apache.archiva.metadata.model.ProjectVersionMetadata 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.model.ProjectVersionMetadata 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