Search in sources :

Example 6 with MetadataFacetFactory

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

the class CassandraMetadataRepository method getMetadataFacet.

@Override
public MetadataFacet getMetadataFacet(final String repositoryId, final String facetId, final String name) throws MetadataRepositoryException {
    MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(facetId);
    if (metadataFacetFactory == null) {
        return null;
    }
    QueryResult<OrderedRows<String, String, String>> result = // 
    HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
    ss).setColumnFamily(// 
    cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(KEY.toString(), // 
    VALUE.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
    repositoryId).addEqualsExpression(FACET_ID.toString(), // 
    facetId).addEqualsExpression(NAME.toString(), // 
    name).execute();
    MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet(repositoryId, name);
    int size = result.get().getCount();
    if (size < 1) {
        return null;
    }
    Map<String, String> map = new HashMap<>(size);
    for (Row<String, String, String> row : result.get()) {
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        map.put(getStringValue(columnSlice, KEY.toString()), getStringValue(columnSlice, VALUE.toString()));
    }
    metadataFacet.fromProperties(map);
    return metadataFacet;
}
Also used : HashMap(java.util.HashMap) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory)

Example 7 with MetadataFacetFactory

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

the class JcrMetadataRepository method getMetadataFacet.

@Override
public MetadataFacet getMetadataFacet(String repositoryId, String facetId, String name) throws MetadataRepositoryException {
    MetadataFacet metadataFacet = null;
    try {
        Node root = getJcrSession().getRootNode();
        Node node = root.getNode(getFacetPath(repositoryId, facetId, name));
        if (metadataFacetFactories == null) {
            return metadataFacet;
        }
        MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(facetId);
        if (metadataFacetFactory != null) {
            metadataFacet = metadataFacetFactory.createMetadataFacet(repositoryId, name);
            Map<String, String> map = new HashMap<>();
            for (Property property : JcrUtils.getProperties(node)) {
                String p = property.getName();
                if (!p.startsWith("jcr:")) {
                    map.put(p, property.getString());
                }
            }
            metadataFacet.fromProperties(map);
        }
    } catch (PathNotFoundException e) {
    // ignored - the facet doesn't exist, so return null
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
    return metadataFacet;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) HashMap(java.util.HashMap) Node(javax.jcr.Node) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory)

Example 8 with MetadataFacetFactory

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

the class JcrRepositorySessionFactory method initialize.

public void initialize() {
    // skip initialisation if not jcr
    if (repositorySessionFactoryBean != null && !StringUtils.equals(repositorySessionFactoryBean.getId(), "jcr")) {
        return;
    }
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    metadataFacetFactories = applicationContext.getBeansOfType(MetadataFacetFactory.class);
    // olamy with spring the "id" is now "metadataFacetFactory#hint"
    // whereas was only hint with plexus so let remove  metadataFacetFactory#
    Map<String, MetadataFacetFactory> cleanedMetadataFacetFactories = new HashMap<>(metadataFacetFactories.size());
    for (Map.Entry<String, MetadataFacetFactory> entry : metadataFacetFactories.entrySet()) {
        cleanedMetadataFacetFactories.put(StringUtils.substringAfterLast(entry.getKey(), "#"), entry.getValue());
    }
    metadataFacetFactories = cleanedMetadataFacetFactories;
    JcrMetadataRepository metadataRepository = null;
    try {
        repositoryFactory = new RepositoryFactory();
        // FIXME this need to be configurable
        Path directoryPath = Paths.get(System.getProperty("appserver.base"), "data/jcr");
        repositoryFactory.setRepositoryPath(directoryPath);
        try {
            repository = repositoryFactory.createRepository();
        } catch (InvalidFileStoreVersionException | IOException e) {
            logger.error("Repository creation failed {}", e.getMessage());
            throw new RuntimeException("Fatal error. Could not create metadata repository.");
        }
        metadataRepository = new JcrMetadataRepository(metadataFacetFactories, repository);
        JcrMetadataRepository.initialize(metadataRepository.getJcrSession());
    } catch (RepositoryException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        if (metadataRepository != null) {
            try {
                metadataRepository.close();
            } catch (MetadataRepositoryException e) {
                logger.error("Close of metadata repository failed {}", e.getMessage());
            }
        }
    }
    stopWatch.stop();
    logger.info("time to initialize JcrRepositorySessionFactory: {}", stopWatch.getTime());
}
Also used : Path(java.nio.file.Path) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) HashMap(java.util.HashMap) RepositoryException(javax.jcr.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException) StopWatch(org.apache.commons.lang.time.StopWatch) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) InvalidFileStoreVersionException(org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with MetadataFacetFactory

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

the class CassandraMetadataRepositoryTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    Path directory = Paths.get("target/test-repositories");
    if (Files.exists(directory)) {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(directory);
    }
    Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
    this.cmr = new CassandraMetadataRepository(factories, null, cassandraArchivaManager);
    this.repository = this.cmr;
    clearReposAndNamespace(cassandraArchivaManager);
}
Also used : Path(java.nio.file.Path) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) Before(org.junit.Before)

Example 10 with MetadataFacetFactory

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

Aggregations

MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)15 HashMap (java.util.HashMap)11 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)10 Path (java.nio.file.Path)5 RepositoryException (javax.jcr.RepositoryException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Before (org.junit.Before)4 Properties (java.util.Properties)3 Node (javax.jcr.Node)3 Property (javax.jcr.Property)3 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)3 CiManagement (org.apache.archiva.metadata.model.CiManagement)3 IssueManagement (org.apache.archiva.metadata.model.IssueManagement)3 MailingList (org.apache.archiva.metadata.model.MailingList)3 Organization (org.apache.archiva.metadata.model.Organization)3 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)3 Scm (org.apache.archiva.metadata.model.Scm)3 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)3