use of org.apache.archiva.metadata.model.FacetedMetadata in project archiva by apache.
the class CassandraMetadataRepository method updateFacets.
/*
* iterate over available facets to remove/add from the artifactMetadata
*
* @param facetedMetadata
* @param artifactMetadataModel only use for the key
*/
private void updateFacets(final FacetedMetadata facetedMetadata, final ArtifactMetadataModel artifactMetadataModel) {
String table = cassandraArchivaManager.getMetadataFacetFamilyName();
CqlSession session = cassandraArchivaManager.getSession();
{
for (final String facetId : getSupportedFacets()) {
MetadataFacet metadataFacet = facetedMetadata.getFacet(facetId);
if (metadataFacet != null) {
Select deleteRows = selectFrom(table).column(DEFAULT_PRIMARY_KEY).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(artifactMetadataModel.getRepositoryId())).whereColumn(NAMESPACE_ID.toString()).isEqualTo(literal(artifactMetadataModel.getNamespace())).whereColumn(PROJECT_ID.toString()).isEqualTo(literal(artifactMetadataModel.getProject())).whereColumn(PROJECT_VERSION.toString()).isEqualTo(literal(artifactMetadataModel.getProjectVersion())).whereColumn(FACET_ID.toString()).isEqualTo(literal(facetId)).allowFiltering();
ResultSet resultSet = session.execute(deleteRows.build());
StreamSupport.stream(resultSet.spliterator(), false).map(row -> row.getString(DEFAULT_PRIMARY_KEY)).distinct().forEach(key -> {
Delete delete = deleteFrom(table).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
session.execute(delete.build());
});
Map<String, String> properties = metadataFacet.toProperties();
for (Map.Entry<String, String> entry : properties.entrySet()) {
String key = new MetadataFacetModel.KeyBuilder().withKey(entry.getKey()).withArtifactMetadataModel(artifactMetadataModel).withFacetId(facetId).withName(metadataFacet.getName()).build();
Update update = update(table).setColumn(REPOSITORY_NAME.toString(), literal(artifactMetadataModel.getRepositoryId())).setColumn(NAMESPACE_ID.toString(), literal(artifactMetadataModel.getNamespace())).setColumn(PROJECT_ID.toString(), literal(artifactMetadataModel.getProject())).setColumn(PROJECT_VERSION.toString(), literal(artifactMetadataModel.getProjectVersion())).setColumn(FACET_ID.toString(), literal(facetId)).setColumn(KEY.toString(), literal(entry.getKey())).setColumn(VALUE.toString(), literal(entry.getValue())).whereColumn(DEFAULT_PRIMARY_KEY).isEqualTo(literal(key));
session.execute(update.build());
}
}
}
}
}
Aggregations