use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved.
@Test
public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved() throws Exception {
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
metadata.setId(TEST_PROJECT_VERSION);
Map<String, String> additionalProps = new HashMap<>();
additionalProps.put("deleteKey", "deleteValue");
MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz", additionalProps);
metadata.addFacet(facet);
repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
assertThat(metadata.getFacetIds()).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
Map<String, String> facetProperties = testFacet.toProperties();
assertEquals("deleteValue", facetProperties.get("deleteKey"));
facetProperties.remove("deleteKey");
TestMetadataFacet newTestFacet = new TestMetadataFacet(TEST_FACET_ID, testFacet.getValue(), facetProperties);
metadata.addFacet(newTestFacet);
repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
assertThat(metadata.getFacetIds()).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
assertFalse(testFacet.toProperties().containsKey("deleteKey"));
}
use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class AbstractMetadataRepositoryTest method testUpdateProjectVersionMetadataWithAllElements.
@Test
public void testUpdateProjectVersionMetadataWithAllElements() throws Exception {
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
metadata.setId(TEST_PROJECT_VERSION);
metadata.setName("project name");
metadata.setDescription("project description");
metadata.setUrl("the url");
MailingList mailingList = new MailingList();
mailingList.setName("Foo List");
mailingList.setUnsubscribeAddress("UnsubscribeAddress");
mailingList.setSubscribeAddress("SubscribeAddress");
mailingList.setPostAddress("PostAddress");
mailingList.setMainArchiveUrl("MainArchiveUrl");
mailingList.setOtherArchives(Arrays.asList("other archive"));
metadata.setMailingLists(Arrays.asList(mailingList));
Scm scm = new Scm();
scm.setConnection("connection");
scm.setDeveloperConnection("dev conn");
scm.setUrl("url");
metadata.setScm(scm);
CiManagement ci = new CiManagement();
ci.setSystem("system");
ci.setUrl("ci url");
metadata.setCiManagement(ci);
IssueManagement tracker = new IssueManagement();
tracker.setSystem("system");
tracker.setUrl("issue tracker url");
metadata.setIssueManagement(tracker);
metadata.setOrganization(TEST_ORGANIZATION);
License l = new License();
l.setName("license name");
l.setUrl("license url");
metadata.addLicense(l);
Dependency d = new Dependency();
d.setArtifactId("artifactId");
d.setClassifier("classifier");
d.setGroupId("groupId");
d.setScope("scope");
d.setSystemPath("system path");
d.setType("type");
d.setVersion("version");
d.setOptional(true);
metadata.addDependency(d);
repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
assertEquals(TEST_PROJECT_VERSION, metadata.getId());
assertEquals(TEST_PROJECT_VERSION, metadata.getVersion());
assertEquals("project name", metadata.getName());
assertEquals("project description", metadata.getDescription());
assertEquals("the url", metadata.getUrl());
assertEquals("connection", metadata.getScm().getConnection());
assertEquals("dev conn", metadata.getScm().getDeveloperConnection());
assertEquals("url", metadata.getScm().getUrl());
assertEquals("system", metadata.getCiManagement().getSystem());
assertEquals("ci url", metadata.getCiManagement().getUrl());
assertEquals("system", metadata.getIssueManagement().getSystem());
assertEquals("issue tracker url", metadata.getIssueManagement().getUrl());
assertEquals(TEST_ORGANIZATION.getName(), metadata.getOrganization().getName());
assertEquals(TEST_ORGANIZATION.getUrl(), metadata.getOrganization().getUrl());
assertEquals(1, metadata.getMailingLists().size());
MailingList retrievedMailingList = metadata.getMailingLists().get(0);
assertEquals(mailingList.getName(), retrievedMailingList.getName());
assertEquals(mailingList.getMainArchiveUrl(), retrievedMailingList.getMainArchiveUrl());
assertEquals(mailingList.getPostAddress(), retrievedMailingList.getPostAddress());
assertEquals(mailingList.getSubscribeAddress(), retrievedMailingList.getSubscribeAddress());
assertEquals(mailingList.getUnsubscribeAddress(), retrievedMailingList.getUnsubscribeAddress());
//
assertThat(retrievedMailingList.getOtherArchives()).isNotNull().isNotEmpty().hasSize(//
1).contains("other archive");
assertEquals(1, metadata.getLicenses().size());
l = metadata.getLicenses().get(0);
assertEquals("license name", l.getName());
assertEquals("license url", l.getUrl());
assertEquals(1, metadata.getDependencies().size());
d = metadata.getDependencies().get(0);
assertEquals("artifactId", d.getArtifactId());
assertEquals("classifier", d.getClassifier());
assertEquals("groupId", d.getGroupId());
assertEquals("scope", d.getScope());
assertEquals("system path", d.getSystemPath());
assertEquals("type", d.getType());
assertEquals("version", d.getVersion());
assertTrue(d.isOptional());
}
use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class DefaultMetadataResolver method resolveProjectVersion.
@Override
public ProjectVersionMetadata resolveProjectVersion(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
MetadataRepository metadataRepository = session.getRepository();
ProjectVersionMetadata metadata = metadataRepository.getProjectVersion(repoId, namespace, projectId, projectVersion);
// may then work here and be more efficient than always trying again)
if (metadata == null || metadata.isIncomplete()) {
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion).browsingRequest(true);
metadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
log.debug("Resolved project version metadata from storage: {}", metadata);
// eg. maven projects should be able to process parent here
if (!metadata.getDependencies().isEmpty()) {
ProjectVersionReference ref = new ProjectVersionReference();
ref.setNamespace(namespace);
ref.setProjectId(projectId);
ref.setProjectVersion(projectVersion);
ref.setReferenceType(ProjectVersionReference.ReferenceType.DEPENDENCY);
}
try {
for (RepositoryListener listener : listeners) {
listener.addArtifact(session, repoId, namespace, projectId, metadata);
}
metadataRepository.updateProjectVersion(repoId, namespace, projectId, metadata);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
}
session.markDirty();
} catch (RepositoryStorageMetadataInvalidException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
} catch (RepositoryStorageMetadataNotFoundException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
// no need to rethrow - return null
} catch (RepositoryStorageRuntimeException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
throw new MetadataResolutionException(e.getMessage(), e);
}
}
return metadata;
}
use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class DefaultMetadataResolver method resolveProjectVersions.
@Override
public Collection<String> resolveProjectVersions(RepositorySession session, String repoId, String namespace, String projectId) throws MetadataResolutionException {
try {
MetadataRepository metadataRepository = session.getRepository();
Collection<String> projectVersions = metadataRepository.getProjectVersions(repoId, namespace, projectId);
Collection<String> storageProjectVersions = repositoryStorage.listProjectVersions(repoId, namespace, projectId, new ExcludesFilter<String>(projectVersions));
if (storageProjectVersions != null && !storageProjectVersions.isEmpty()) {
log.debug("Resolved project versions from storage: {}", storageProjectVersions);
for (String projectVersion : storageProjectVersions) {
try {
ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(repoId).namespace(namespace).projectId(projectId).projectVersion(projectVersion);
ProjectVersionMetadata versionMetadata = repositoryStorage.readProjectVersionMetadata(readMetadataRequest);
for (RepositoryListener listener : listeners) {
listener.addArtifact(session, repoId, namespace, projectId, versionMetadata);
}
metadataRepository.updateProjectVersion(repoId, namespace, projectId, versionMetadata);
} catch (MetadataRepositoryException e) {
log.warn("Unable to persist resolved information: {}", e.getMessage(), e);
} catch (RepositoryStorageMetadataInvalidException e) {
log.warn("Not update project in metadata repository due to an error resolving it from storage: {}", e.getMessage());
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
} catch (RepositoryStorageMetadataNotFoundException e) {
for (RepositoryListener listener : listeners) {
listener.addArtifactProblem(session, repoId, namespace, projectId, projectVersion, e);
}
}
}
session.markDirty();
projectVersions = new ArrayList<>(projectVersions);
projectVersions.addAll(storageProjectVersions);
}
return projectVersions;
} catch (RepositoryStorageRuntimeException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.model.ProjectVersionMetadata in project archiva by apache.
the class CassandraMetadataRepository method getProjectVersion.
@Override
public ProjectVersionMetadata getProjectVersion(final String repoId, final String namespace, final String projectId, final String projectVersion) throws MetadataResolutionException {
QueryResult<OrderedRows<String, String, String>> result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(//
PROJECT_VERSION.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repoId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespace).addEqualsExpression(PROJECT_ID.toString(), //
projectId).addEqualsExpression(PROJECT_VERSION.toString(), //
projectVersion).execute();
if (result.get().getCount() < 1) {
return null;
}
String key = result.get().iterator().next().getKey();
ColumnFamilyResult<String, String> columnFamilyResult = this.projectVersionMetadataTemplate.queryColumns(key);
if (!columnFamilyResult.hasResults()) {
return null;
}
ProjectVersionMetadata projectVersionMetadata = new ProjectVersionMetadata();
projectVersionMetadata.setId(columnFamilyResult.getString(PROJECT_VERSION.toString()));
projectVersionMetadata.setDescription(columnFamilyResult.getString(DESCRIPTION.toString()));
projectVersionMetadata.setName(columnFamilyResult.getString(NAME.toString()));
projectVersionMetadata.setIncomplete(Boolean.parseBoolean(columnFamilyResult.getString("incomplete")));
projectVersionMetadata.setUrl(columnFamilyResult.getString(URL.toString()));
{
String ciUrl = columnFamilyResult.getString("ciManagement.url");
String ciSystem = columnFamilyResult.getString("ciManagement.system");
if (StringUtils.isNotEmpty(ciSystem) || StringUtils.isNotEmpty(ciUrl)) {
projectVersionMetadata.setCiManagement(new CiManagement(ciSystem, ciUrl));
}
}
{
String issueUrl = columnFamilyResult.getString("issueManagement.url");
String issueSystem = columnFamilyResult.getString("issueManagement.system");
if (StringUtils.isNotEmpty(issueSystem) || StringUtils.isNotEmpty(issueUrl)) {
projectVersionMetadata.setIssueManagement(new IssueManagement(issueSystem, issueUrl));
}
}
{
String organizationUrl = columnFamilyResult.getString("organization.url");
String organizationName = columnFamilyResult.getString("organization.name");
if (StringUtils.isNotEmpty(organizationUrl) || StringUtils.isNotEmpty(organizationName)) {
projectVersionMetadata.setOrganization(new Organization(organizationName, organizationUrl));
}
}
{
String devConn = columnFamilyResult.getString("scm.developerConnection");
String conn = columnFamilyResult.getString("scm.connection");
String url = columnFamilyResult.getString("scm.url");
if (StringUtils.isNotEmpty(devConn) || StringUtils.isNotEmpty(conn) || StringUtils.isNotEmpty(url)) {
projectVersionMetadata.setScm(new Scm(conn, devConn, url));
}
}
projectVersionMetadata.setMailingLists(getMailingLists(key));
projectVersionMetadata.setLicenses(getLicenses(key));
projectVersionMetadata.setDependencies(getDependencies(key));
// facets
result = //
HFactory.createRangeSlicesQuery(keyspace, ss, ss, //
ss).setColumnFamily(//
cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(FACET_ID.toString(), KEY.toString(), VALUE.toString(), //
NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), //
repoId).addEqualsExpression(NAMESPACE_ID.toString(), //
namespace).addEqualsExpression(PROJECT_ID.toString(), //
projectId).addEqualsExpression(PROJECT_VERSION.toString(), //
projectVersion).execute();
Map<String, Map<String, String>> metadataFacetsPerFacetIds = new HashMap<>();
for (Row<String, String, String> row : result.get()) {
ColumnSlice<String, String> columnSlice = row.getColumnSlice();
String facetId = getStringValue(columnSlice, FACET_ID.toString());
Map<String, String> metaValues = metadataFacetsPerFacetIds.get(facetId);
if (metaValues == null) {
metaValues = new HashMap<>();
metadataFacetsPerFacetIds.put(facetId, metaValues);
}
metaValues.put(getStringValue(columnSlice, KEY.toString()), getStringValue(columnSlice, VALUE.toString()));
}
if (!metadataFacetsPerFacetIds.isEmpty()) {
for (Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet()) {
MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(entry.getKey());
if (metadataFacetFactory != null) {
MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet();
metadataFacet.fromProperties(entry.getValue());
projectVersionMetadata.addFacet(metadataFacet);
}
}
}
return projectVersionMetadata;
}
Aggregations