Search in sources :

Example 1 with MetadataFacet

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());
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) Test(org.junit.Test)

Example 2 with MetadataFacet

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));
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) 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 3 with MetadataFacet

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);
}
Also used : HashMap(java.util.HashMap) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet)

Example 4 with 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);
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) StringTokenizer(java.util.StringTokenizer) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with MetadataFacet

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;
}
Also used : HashMap(java.util.HashMap) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) IOException(java.io.IOException) Properties(java.util.Properties) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory)

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