use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.
the class AbstractMetadataRepositoryTest method testUpdateProjectVersionMetadataWithExistingFacets.
@Test
public void testUpdateProjectVersionMetadataWithExistingFacets() throws Exception {
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
metadata.setId(TEST_PROJECT_VERSION);
MetadataFacet facet = new TestMetadataFacet("baz");
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);
assertEquals(Collections.singleton(TEST_FACET_ID), metadata.getFacetIds());
metadata = new ProjectVersionMetadata();
metadata.setId(TEST_PROJECT_VERSION);
repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata);
metadata = repository.getProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
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 AbstractMetadataRepositoryTest method testGetArtifactsDoesntReturnProjectVersionMetadataFacets.
@Test
public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets() throws Exception {
ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
versionMetadata.setId(TEST_PROJECT_VERSION);
MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz");
versionMetadata.addFacet(facet);
repository.updateProjectVersion(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata);
ArtifactMetadata artifactMetadata = createArtifact();
repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata);
repository.save();
Collection<ArtifactMetadata> artifacts = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
artifacts = repository.getArtifacts(TEST_REPO_ID);
assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
artifacts = repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_SHA1);
assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
artifacts = repository.getArtifactsByChecksum(TEST_REPO_ID, TEST_MD5);
assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
artifacts = repository.getArtifactsByDateRange(TEST_REPO_ID, null, null);
assertEquals(Collections.singletonList(artifactMetadata), new ArrayList<>(artifacts));
}
use of org.apache.archiva.metadata.model.MetadataFacet 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.model.MetadataFacet in project archiva by apache.
the class FileMetadataRepository method getArtifacts.
@Override
public Collection<ArtifactMetadata> getArtifacts(String repoId, String namespace, String projectId, String projectVersion) throws MetadataResolutionException {
try {
Map<String, ArtifactMetadata> artifacts = new HashMap<>();
Path directory = getDirectory(repoId).resolve(namespace + "/" + projectId + "/" + projectVersion);
Properties properties = readOrCreateProperties(directory, PROJECT_VERSION_METADATA_KEY);
for (Map.Entry entry : properties.entrySet()) {
String name = (String) entry.getKey();
StringTokenizer tok = new StringTokenizer(name, ":");
if (tok.hasMoreTokens() && "artifact".equals(tok.nextToken())) {
String field = tok.nextToken();
String id = tok.nextToken();
ArtifactMetadata artifact = artifacts.get(id);
if (artifact == null) {
artifact = new ArtifactMetadata();
artifact.setRepositoryId(repoId);
artifact.setNamespace(namespace);
artifact.setProject(projectId);
artifact.setProjectVersion(projectVersion);
artifact.setVersion(projectVersion);
artifact.setId(id);
artifacts.put(id, artifact);
}
String value = (String) entry.getValue();
if ("updated".equals(field)) {
artifact.setFileLastModified(Long.parseLong(value));
} else if ("size".equals(field)) {
artifact.setSize(Long.valueOf(value));
} else if ("whenGathered".equals(field)) {
artifact.setWhenGathered(new Date(Long.parseLong(value)));
} else if ("version".equals(field)) {
artifact.setVersion(value);
} else if ("md5".equals(field)) {
artifact.setMd5(value);
} else if ("sha1".equals(field)) {
artifact.setSha1(value);
} else if ("facetIds".equals(field)) {
if (value.length() > 0) {
String propertyPrefix = "artifact:facet:" + id + ":";
for (String facetId : value.split(",")) {
MetadataFacetFactory factory = metadataFacetFactories.get(facetId);
if (factory == null) {
log.error("Attempted to load unknown artifact metadata facet: {}", facetId);
} else {
MetadataFacet facet = factory.createMetadataFacet();
String prefix = propertyPrefix + facet.getFacetId();
Map<String, String> map = new HashMap<>();
for (Object key : new ArrayList<>(properties.keySet())) {
String property = (String) key;
if (property.startsWith(prefix)) {
map.put(property.substring(prefix.length() + 1), properties.getProperty(property));
}
}
facet.fromProperties(map);
artifact.addFacet(facet);
}
}
}
updateArtifactFacets(artifact, properties);
}
}
}
return artifacts.values();
} catch (IOException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.
the class FileMetadataRepository method getMetadataFacet.
@Override
public MetadataFacet getMetadataFacet(String repositoryId, String facetId, String name) {
Properties properties;
try {
properties = readProperties(getMetadataDirectory(repositoryId, facetId).resolve(name), METADATA_KEY);
} catch (NoSuchFileException | FileNotFoundException e) {
return null;
} catch (IOException e) {
log.error("Could not read properties from {}, {}: {}", repositoryId, facetId, e.getMessage(), e);
return null;
}
MetadataFacet metadataFacet = null;
MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(facetId);
if (metadataFacetFactory != null) {
metadataFacet = metadataFacetFactory.createMetadataFacet(repositoryId, name);
Map<String, String> map = new HashMap<>();
for (Object key : new ArrayList<>(properties.keySet())) {
String property = (String) key;
map.put(property, properties.getProperty(property));
}
metadataFacet.fromProperties(map);
}
return metadataFacet;
}
Aggregations