use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.
the class AbstractMetadataRepositoryTest method createTestMetadataFacetFactories.
public static Map<String, MetadataFacetFactory> createTestMetadataFacetFactories() {
Map<String, MetadataFacetFactory> factories = new HashMap<>();
factories.put(TEST_FACET_ID, new MetadataFacetFactory() {
@Override
public MetadataFacet createMetadataFacet() {
return new TestMetadataFacet(TEST_METADATA_VALUE);
}
@Override
public MetadataFacet createMetadataFacet(String repositoryId, String name) {
return new TestMetadataFacet(TEST_METADATA_VALUE);
}
});
// add to ensure we don't accidentally create an empty facet ID.
factories.put("", new MetadataFacetFactory() {
@Override
public MetadataFacet createMetadataFacet() {
return new TestMetadataFacet("", TEST_VALUE);
}
@Override
public MetadataFacet createMetadataFacet(String repositoryId, String name) {
return new TestMetadataFacet("", TEST_VALUE);
}
});
// for the getArtifactsByProjectVersionMetadata tests
factories.put(GenericMetadataFacet.FACET_ID, new GenericMetadataFacetFactory());
return factories;
}
use of org.apache.archiva.metadata.model.MetadataFacet 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.MetadataFacet in project archiva by apache.
the class AbstractMetadataRepositoryTest method testUpdateArtifactMetadataWithExistingFacets.
@Test
public void testUpdateArtifactMetadataWithExistingFacets() throws Exception {
ArtifactMetadata metadata = createArtifact();
MetadataFacet facet = new TestMetadataFacet("baz");
metadata.addFacet(facet);
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
metadata = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION).iterator().next();
assertEquals(Collections.singleton(TEST_FACET_ID), metadata.getFacetIds());
metadata = createArtifact();
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
metadata = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION).iterator().next();
assertEquals(Collections.singleton(TEST_FACET_ID), metadata.getFacetIds());
TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
assertEquals("baz", testFacet.getValue());
}
use of org.apache.archiva.metadata.model.MetadataFacet 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;
}
use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.
the class FileMetadataRepository method getProjectVersion.
@Override
public ProjectVersionMetadata getProjectVersion(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
try {
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
String id = properties.getProperty("id");
ProjectVersionMetadata versionMetadata = null;
if (id != null) {
versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId(id);
versionMetadata.setName(properties.getProperty("name"));
versionMetadata.setDescription(properties.getProperty("description"));
versionMetadata.setUrl(properties.getProperty("url"));
versionMetadata.setIncomplete(Boolean.valueOf(properties.getProperty("incomplete", "false")));
String scmConnection = properties.getProperty("scm.connection");
String scmDeveloperConnection = properties.getProperty("scm.developerConnection");
String scmUrl = properties.getProperty("scm.url");
if (scmConnection != null || scmDeveloperConnection != null || scmUrl != null) {
Scm scm = new Scm();
scm.setConnection(scmConnection);
scm.setDeveloperConnection(scmDeveloperConnection);
scm.setUrl(scmUrl);
versionMetadata.setScm(scm);
}
String ciSystem = properties.getProperty("ci.system");
String ciUrl = properties.getProperty("ci.url");
if (ciSystem != null || ciUrl != null) {
CiManagement ci = new CiManagement();
ci.setSystem(ciSystem);
ci.setUrl(ciUrl);
versionMetadata.setCiManagement(ci);
}
String issueSystem = properties.getProperty("issue.system");
String issueUrl = properties.getProperty("issue.url");
if (issueSystem != null || issueUrl != null) {
IssueManagement issueManagement = new IssueManagement();
issueManagement.setSystem(issueSystem);
issueManagement.setUrl(issueUrl);
versionMetadata.setIssueManagement(issueManagement);
}
String orgName = properties.getProperty("org.name");
String orgUrl = properties.getProperty("org.url");
if (orgName != null || orgUrl != null) {
Organization org = new Organization();
org.setName(orgName);
org.setUrl(orgUrl);
versionMetadata.setOrganization(org);
}
boolean done = false;
int i = 0;
while (!done) {
String licenseName = properties.getProperty("license." + i + ".name");
String licenseUrl = properties.getProperty("license." + i + ".url");
if (licenseName != null || licenseUrl != null) {
License license = new License();
license.setName(licenseName);
license.setUrl(licenseUrl);
versionMetadata.addLicense(license);
} else {
done = true;
}
i++;
}
done = false;
i = 0;
while (!done) {
String mailingListName = properties.getProperty("mailingList." + i + ".name");
if (mailingListName != null) {
MailingList mailingList = new MailingList();
mailingList.setName(mailingListName);
mailingList.setMainArchiveUrl(properties.getProperty("mailingList." + i + ".archive"));
String p = properties.getProperty("mailingList." + i + ".otherArchives");
if (p != null && p.length() > 0) {
mailingList.setOtherArchives(Arrays.asList(p.split(",")));
} else {
mailingList.setOtherArchives(Collections.emptyList());
}
mailingList.setPostAddress(properties.getProperty("mailingList." + i + ".post"));
mailingList.setSubscribeAddress(properties.getProperty("mailingList." + i + ".subscribe"));
mailingList.setUnsubscribeAddress(properties.getProperty("mailingList." + i + ".unsubscribe"));
versionMetadata.addMailingList(mailingList);
} else {
done = true;
}
i++;
}
done = false;
i = 0;
while (!done) {
String dependencyArtifactId = properties.getProperty("dependency." + i + ".artifactId");
if (dependencyArtifactId != null) {
Dependency dependency = new Dependency();
dependency.setArtifactId(dependencyArtifactId);
dependency.setGroupId(properties.getProperty("dependency." + i + ".groupId"));
dependency.setClassifier(properties.getProperty("dependency." + i + ".classifier"));
dependency.setOptional(Boolean.valueOf(properties.getProperty("dependency." + i + ".optional")));
dependency.setScope(properties.getProperty("dependency." + i + ".scope"));
dependency.setSystemPath(properties.getProperty("dependency." + i + ".systemPath"));
dependency.setType(properties.getProperty("dependency." + i + ".type"));
dependency.setVersion(properties.getProperty("dependency." + i + ".version"));
dependency.setOptional(Boolean.valueOf(properties.getProperty("dependency." + i + ".optional")));
versionMetadata.addDependency(dependency);
} else {
done = true;
}
i++;
}
String facetIds = properties.getProperty("facetIds", "");
if (facetIds.length() > 0) {
for (String facetId : facetIds.split(",")) {
MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
if (factory == null) {
log.error("Attempted to load unknown project version metadata facet: {}", facetId);
} else {
MetadataFacet facet = factory.createMetadataFacet();
Map<String, String> map = new HashMap<>();
for (Object key : new ArrayList<>(properties.keySet())) {
String property = (String) key;
if (property.startsWith(facet.getFacetId())) {
map.put(property.substring(facet.getFacetId().length() + 1), properties.getProperty(property));
}
}
facet.fromProperties(map);
versionMetadata.addFacet(facet);
}
}
}
updateProjectVersionFacets(versionMetadata, properties);
}
return versionMetadata;
} catch (IOException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
Aggregations