String cf = cassandraArchivaManager.getMetadataFacetFamilyName();
for ( final String facetId : metadataFacetFactories.keySet() )
{
MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId );
if ( metadataFacet == null )
{
continue;
}
// clean first
QueryResult<OrderedRows<String, String, String>> result =
HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
.setColumnFamily( cf ) //
.setColumnNames( "repositoryName" ) //
.addEqualsExpression( "repositoryName", artifactMetadataModel.getRepositoryId() ) //
.addEqualsExpression( "namespaceId", artifactMetadataModel.getNamespace() ) //
.addEqualsExpression( "projectId", artifactMetadataModel.getProject() ) //
.addEqualsExpression( "projectVersion", artifactMetadataModel.getProjectVersion() ) //
.addEqualsExpression( "facetId", facetId ) //
.execute();
for ( Row<String, String, String> row : result.get().getList() )
{
this.metadataFacetTemplate.deleteRow( row.getKey() );
}
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();
Mutator<String> mutator = metadataFacetTemplate.createMutator() //
.addInsertion( key, cf, column( "repositoryName", artifactMetadataModel.getRepositoryId() ) ) //
.addInsertion( key, cf, column( "namespaceId", artifactMetadataModel.getNamespace() ) ) //
.addInsertion( key, cf, column( "projectId", artifactMetadataModel.getProject() ) ) //
.addInsertion( key, cf, column( "projectVersion", artifactMetadataModel.getProjectVersion() ) ) //
.addInsertion( key, cf, column( "facetId", facetId ) ) //
.addInsertion( key, cf, column( "key", entry.getKey() ) ) //
.addInsertion( key, cf, column( "value", entry.getValue() ) );
if ( metadataFacet.getName() != null )
{
mutator.addInsertion( key, cf, column( "name", metadataFacet.getName() ) );
}
mutator.execute();
}
}