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;
}
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;
}
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());
}
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);
}
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;
}
Aggregations