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