use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class JcrMetadataRepository method removeArtifact.
@Override
public void removeArtifact(String repositoryId, String namespace, String project, String projectVersion, MetadataFacet metadataFacet) throws MetadataRepositoryException {
try {
Node root = getJcrSession().getRootNode();
String path = getProjectVersionPath(repositoryId, namespace, project, projectVersion);
if (root.hasNode(path)) {
Node node = root.getNode(path);
for (Node n : JcrUtils.getChildNodes(node)) {
if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
ArtifactMetadata artifactMetadata = getArtifactFromNode(repositoryId, n);
log.debug("artifactMetadata: {}", artifactMetadata);
MetadataFacet metadataFacetToRemove = artifactMetadata.getFacet(metadataFacet.getFacetId());
if (metadataFacetToRemove != null && metadataFacet.equals(metadataFacetToRemove)) {
n.remove();
}
}
}
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class JcrMetadataRepository method getArtifactFromNode.
private ArtifactMetadata getArtifactFromNode(String repositoryId, Node artifactNode) throws RepositoryException {
String id = artifactNode.getName();
ArtifactMetadata artifact = new ArtifactMetadata();
artifact.setId(id);
artifact.setRepositoryId(repositoryId == null ? artifactNode.getAncestor(2).getName() : repositoryId);
Node projectVersionNode = artifactNode.getParent();
Node projectNode = projectVersionNode.getParent();
Node namespaceNode = projectNode.getParent();
artifact.setNamespace(namespaceNode.getProperty("namespace").getString());
artifact.setProject(projectNode.getName());
artifact.setProjectVersion(projectVersionNode.getName());
artifact.setVersion(artifactNode.hasProperty("version") ? artifactNode.getProperty("version").getString() : projectVersionNode.getName());
if (artifactNode.hasProperty(JCR_LAST_MODIFIED)) {
artifact.setFileLastModified(artifactNode.getProperty(JCR_LAST_MODIFIED).getDate().getTimeInMillis());
}
if (artifactNode.hasProperty("whenGathered")) {
artifact.setWhenGathered(artifactNode.getProperty("whenGathered").getDate().getTime());
}
if (artifactNode.hasProperty("size")) {
artifact.setSize(artifactNode.getProperty("size").getLong());
}
if (artifactNode.hasProperty("md5")) {
artifact.setMd5(artifactNode.getProperty("md5").getString());
}
if (artifactNode.hasProperty("sha1")) {
artifact.setSha1(artifactNode.getProperty("sha1").getString());
}
for (Node n : JcrUtils.getChildNodes(artifactNode)) {
if (n.isNodeType(FACET_NODE_TYPE)) {
String name = n.getName();
MetadataFacetFactory factory = metadataFacetFactories.get(name);
if (factory == null) {
log.error("Attempted to load unknown project version metadata facet: {}", name);
} else {
MetadataFacet facet = factory.createMetadataFacet();
Map<String, String> map = new HashMap<>();
for (Property p : JcrUtils.getProperties(n)) {
String property = p.getName();
if (!property.startsWith("jcr:")) {
map.put(property, p.getString());
}
}
facet.fromProperties(map);
artifact.addFacet(facet);
}
}
}
return artifact;
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class JcrMetadataRepository method getArtifactsByChecksum.
@Override
public List<ArtifactMetadata> getArtifactsByChecksum(String repositoryId, String checksum) throws MetadataRepositoryException {
List<ArtifactMetadata> artifacts;
String q = getArtifactQuery(repositoryId) + " AND ([sha1] = $checksum OR [md5] = $checksum)";
try {
Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
ValueFactory valueFactory = getJcrSession().getValueFactory();
query.bindValue("checksum", valueFactory.createValue(checksum));
QueryResult result = query.execute();
artifacts = new ArrayList<>();
for (Node n : JcrUtils.getNodes(result)) {
artifacts.add(getArtifactFromNode(repositoryId, n));
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException(e.getMessage(), e);
}
return artifacts;
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class ArtifactExtensionMappingTest method getTypeFromArtifactId.
private String getTypeFromArtifactId(String artifactId) {
ArtifactMetadata artifact = pathTranslator.getArtifactFromId(null, "groupId", artifactId, "1.0", artifactId + "-1.0.jar");
MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet(MavenArtifactFacet.FACET_ID);
return facet.getType();
}
use of org.apache.archiva.metadata.model.ArtifactMetadata in project archiva by apache.
the class Maven2RepositoryMetadataResolverTest method testGetArtifactMetadataSnapshots.
@Test
public void testGetArtifactMetadataSnapshots() throws Exception {
Collection<ArtifactMetadata> testArtifacts = storage.readArtifactsMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact", "1.0-SNAPSHOT", ALL));
List<ArtifactMetadata> artifacts = new ArrayList<>(testArtifacts);
Collections.sort(artifacts, new Comparator<ArtifactMetadata>() {
@Override
public int compare(ArtifactMetadata o1, ArtifactMetadata o2) {
return o1.getId().compareTo(o2.getId());
}
});
assertEquals(6, artifacts.size());
ArtifactMetadata artifactMetadata = artifacts.get(0);
assertEquals("test-artifact-1.0-20100308.230825-1.jar", artifactMetadata.getId());
MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(1, facet.getBuildNumber());
assertEquals("20100308.230825", facet.getTimestamp());
assertNull(facet.getClassifier());
assertEquals("jar", facet.getType());
artifactMetadata = artifacts.get(1);
assertEquals("test-artifact-1.0-20100308.230825-1.pom", artifactMetadata.getId());
facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(1, facet.getBuildNumber());
assertEquals("20100308.230825", facet.getTimestamp());
assertNull(facet.getClassifier());
assertEquals("pom", facet.getType());
artifactMetadata = artifacts.get(2);
assertEquals("test-artifact-1.0-20100310.014828-2-javadoc.jar", artifactMetadata.getId());
facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(2, facet.getBuildNumber());
assertEquals("20100310.014828", facet.getTimestamp());
assertEquals("javadoc", facet.getClassifier());
assertEquals("javadoc", facet.getType());
artifactMetadata = artifacts.get(3);
assertEquals("test-artifact-1.0-20100310.014828-2-sources.jar", artifactMetadata.getId());
facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(2, facet.getBuildNumber());
assertEquals("20100310.014828", facet.getTimestamp());
assertEquals("sources", facet.getClassifier());
assertEquals("java-source", facet.getType());
artifactMetadata = artifacts.get(4);
assertEquals("test-artifact-1.0-20100310.014828-2.jar", artifactMetadata.getId());
facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(2, facet.getBuildNumber());
assertEquals("20100310.014828", facet.getTimestamp());
assertNull(facet.getClassifier());
assertEquals("jar", facet.getType());
artifactMetadata = artifacts.get(5);
assertEquals("test-artifact-1.0-20100310.014828-2.pom", artifactMetadata.getId());
facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
assertEquals(2, facet.getBuildNumber());
assertEquals("20100310.014828", facet.getTimestamp());
assertNull(facet.getClassifier());
assertEquals("pom", facet.getType());
}
Aggregations