Search in sources :

Example 11 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet 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;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) HashMap(java.util.HashMap) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession)

Example 12 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class DefaultBrowseService method getMetadatas.

@Override
public List<Entry> getMetadatas(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
    ProjectVersionMetadata projectVersionMetadata = getProjectMetadata(groupId, artifactId, version, repositoryId);
    if (projectVersionMetadata == null) {
        return Collections.emptyList();
    }
    MetadataFacet metadataFacet = projectVersionMetadata.getFacet(GenericMetadataFacet.FACET_ID);
    if (metadataFacet == null) {
        return Collections.emptyList();
    }
    Map<String, String> map = metadataFacet.toProperties();
    List<Entry> entries = new ArrayList<>(map.size());
    for (Map.Entry<String, String> entry : map.entrySet()) {
        entries.add(new Entry(entry.getKey(), entry.getValue()));
    }
    return entries;
}
Also used : BrowseResultEntry(org.apache.archiva.rest.api.model.BrowseResultEntry) ZipEntry(java.util.zip.ZipEntry) TreeEntry(org.apache.archiva.maven2.model.TreeEntry) JarEntry(java.util.jar.JarEntry) Entry(org.apache.archiva.rest.api.model.Entry) ArtifactContentEntry(org.apache.archiva.rest.api.model.ArtifactContentEntry) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArrayList(java.util.ArrayList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class AbstractMetadataRepositoryTest method testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved.

@Test
public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved() throws Exception {
    ArtifactMetadata metadata = createArtifact();
    Map<String, String> additionalProps = new HashMap<>();
    additionalProps.put("deleteKey", "deleteValue");
    MetadataFacet facet = new TestMetadataFacet(TEST_FACET_ID, "baz", additionalProps);
    metadata.addFacet(facet);
    repository.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
    Collection<ArtifactMetadata> artifacts = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
    metadata = artifacts.iterator().next();
    Collection<String> ids = metadata.getFacetIds();
    assertThat(ids).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.updateArtifact(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata);
    artifacts = repository.getArtifacts(TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
    metadata = artifacts.iterator().next();
    ids = metadata.getFacetIds();
    assertThat(ids).isNotNull().isNotEmpty().hasSize(1).contains(TEST_FACET_ID);
    testFacet = (TestMetadataFacet) metadata.getFacet(TEST_FACET_ID);
    Map<String, String> props = testFacet.toProperties();
    assertThat(props).isNotNull().doesNotContainKey("deleteKey");
}
Also used : HashMap(java.util.HashMap) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Example 14 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetMetadataFacetWhenDefaultValue.

@Test
public void testGetMetadataFacetWhenDefaultValue() throws Exception {
    repository.addMetadataFacet(TEST_REPO_ID, new TestMetadataFacet(null));
    MetadataFacet metadataFacet = repository.getMetadataFacet(TEST_REPO_ID, TEST_FACET_ID, TEST_NAME);
    assertEquals(new TestMetadataFacet(TEST_METADATA_VALUE), metadataFacet);
}
Also used : MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) Test(org.junit.Test)

Example 15 with MetadataFacet

use of org.apache.archiva.metadata.model.MetadataFacet in project archiva by apache.

the class AbstractMetadataRepositoryTest method testGetArtifactsByMetadataAllRepositories.

@Test
public void testGetArtifactsByMetadataAllRepositories() throws Exception {
    createArtifactWithMavenArtifactFacet();
    tryAssert(() -> {
        Collection<ArtifactMetadata> artifactsByMetadata = repository.getArtifactsByMetadata("foo", TEST_METADATA_VALUE, null);
        assertThat(artifactsByMetadata).hasSize(1);
        ArtifactMetadata artifactMetadata = artifactsByMetadata.iterator().next();
        assertThat(artifactMetadata.getId()).isEqualTo("projectId-1.0.jar");
        assertThat(artifactMetadata.getSha1()).isEqualTo(TEST_SHA1);
        assertThat(artifactMetadata.getRepositoryId()).isEqualTo(TEST_REPO_ID);
        MetadataFacet facet = artifactMetadata.getFacet(TEST_FACET_ID);
        assertThat(facet).isNotNull();
        assertThat(facet.toProperties()).isEqualTo(Collections.singletonMap("foo", TEST_METADATA_VALUE));
    });
}
Also used : MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Test(org.junit.Test)

Aggregations

MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)25 HashMap (java.util.HashMap)19 GenericMetadataFacet (org.apache.archiva.metadata.generic.GenericMetadataFacet)11 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)10 Map (java.util.Map)8 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)8 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)8 Test (org.junit.Test)7 Node (javax.jcr.Node)6 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)6 ArrayList (java.util.ArrayList)5 RepositoryException (javax.jcr.RepositoryException)5 MailingList (org.apache.archiva.metadata.model.MailingList)4 IOException (java.io.IOException)3 Properties (java.util.Properties)3 Property (javax.jcr.Property)3 OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)3 CiManagement (org.apache.archiva.metadata.model.CiManagement)3 Dependency (org.apache.archiva.metadata.model.Dependency)3 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)3