Search in sources :

Example 1 with MetadataFacetModel

use of org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel in project archiva by apache.

the class CassandraMetadataRepository method mapArtifactMetadataToArtifact.

/**
 * Attach metadata to each of the  ArtifactMetadata objects
 */
private List<ArtifactMetadata> mapArtifactMetadataToArtifact(QueryResult<OrderedRows<String, String, String>> result, List<ArtifactMetadata> artifactMetadatas) {
    if (result.get() == null || result.get().getCount() < 1) {
        return artifactMetadatas;
    }
    final List<MetadataFacetModel> metadataFacetModels = new ArrayList<>(result.get().getCount());
    for (Row<String, String, String> row : result.get()) {
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        MetadataFacetModel metadataFacetModel = new MetadataFacetModel();
        metadataFacetModel.setFacetId(getStringValue(columnSlice, FACET_ID.toString()));
        metadataFacetModel.setName(getStringValue(columnSlice, NAME.toString()));
        metadataFacetModel.setValue(getStringValue(columnSlice, VALUE.toString()));
        metadataFacetModel.setKey(getStringValue(columnSlice, KEY.toString()));
        metadataFacetModel.setProjectVersion(getStringValue(columnSlice, PROJECT_VERSION.toString()));
        metadataFacetModels.add(metadataFacetModel);
    }
    for (final ArtifactMetadata artifactMetadata : artifactMetadatas) {
        Iterable<MetadataFacetModel> metadataFacetModelIterable = Iterables.filter(metadataFacetModels, new Predicate<MetadataFacetModel>() {

            @Override
            public boolean apply(MetadataFacetModel metadataFacetModel) {
                if (metadataFacetModel != null) {
                    return StringUtils.equals(artifactMetadata.getVersion(), metadataFacetModel.getProjectVersion());
                }
                return false;
            }
        });
        Iterator<MetadataFacetModel> iterator = metadataFacetModelIterable.iterator();
        Map<String, List<MetadataFacetModel>> metadataFacetValuesPerFacetId = new HashMap<>();
        while (iterator.hasNext()) {
            MetadataFacetModel metadataFacetModel = iterator.next();
            List<MetadataFacetModel> values = metadataFacetValuesPerFacetId.get(metadataFacetModel.getName());
            if (values == null) {
                values = new ArrayList<>();
                metadataFacetValuesPerFacetId.put(metadataFacetModel.getFacetId(), values);
            }
            values.add(metadataFacetModel);
        }
        for (Map.Entry<String, List<MetadataFacetModel>> entry : metadataFacetValuesPerFacetId.entrySet()) {
            MetadataFacetFactory metadataFacetFactory = metadataFacetFactories.get(entry.getKey());
            if (metadataFacetFactory != null) {
                List<MetadataFacetModel> facetModels = entry.getValue();
                if (!facetModels.isEmpty()) {
                    MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet();
                    Map<String, String> props = new HashMap<>(facetModels.size());
                    for (MetadataFacetModel metadataFacetModel : facetModels) {
                        props.put(metadataFacetModel.getKey(), metadataFacetModel.getValue());
                    }
                    metadataFacet.fromProperties(props);
                    artifactMetadata.addFacet(metadataFacet);
                }
            }
        }
    }
    return artifactMetadatas;
}
Also used : MetadataFacetModel(org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) MailingList(org.apache.archiva.metadata.model.MailingList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)1 MailingList (org.apache.archiva.metadata.model.MailingList)1 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)1 MetadataFacetFactory (org.apache.archiva.metadata.model.MetadataFacetFactory)1 MetadataFacetModel (org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel)1