List<ArtifactMetadata> artifactMetadatas = new ArrayList<>( result.get().getCount() );
for ( Row<String, String, String> row : result.get() )
{
ColumnSlice<String, String> columnSlice = row.getColumnSlice();
ArtifactMetadata artifactMetadata = new ArtifactMetadata();
artifactMetadata.setNamespace( getStringValue( columnSlice, "namespaceId" ) );
artifactMetadata.setSize( getAsLongValue( columnSlice, "size" ) );
artifactMetadata.setId( getStringValue( columnSlice, "id" ) );
artifactMetadata.setFileLastModified( getAsLongValue( columnSlice, "fileLastModified" ) );
artifactMetadata.setMd5( getStringValue( columnSlice, "md5" ) );
artifactMetadata.setProject( getStringValue( columnSlice, "project" ) );
artifactMetadata.setProjectVersion( getStringValue( columnSlice, "projectVersion" ) );
artifactMetadata.setRepositoryId( repoId );
artifactMetadata.setSha1( getStringValue( columnSlice, "sha1" ) );
artifactMetadata.setVersion( getStringValue( columnSlice, "version" ) );
Long whenGathered = getAsLongValue( columnSlice, "whenGathered" );
if ( whenGathered != null )
{
artifactMetadata.setWhenGathered( new Date( whenGathered ) );
}
artifactMetadatas.add( artifactMetadata );
}
result = HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) //
.setColumnNames( "facetId", "name", "value", "key", "projectVersion" ) //
.setRowCount( Integer.MAX_VALUE ) //
.addEqualsExpression( "repositoryName", repoId ) //
.addEqualsExpression( "namespaceId", namespace ) //
.addEqualsExpression( "projectId", projectId ) //
.addEqualsExpression( "projectVersion", projectVersion ) //
.execute();
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, "facetId" ) );
metadataFacetModel.setName( getStringValue( columnSlice, "name" ) );
metadataFacetModel.setValue( getStringValue( columnSlice, "value" ) );
metadataFacetModel.setKey( getStringValue( columnSlice, "key" ) );
metadataFacetModel.setProjectVersion( getStringValue( columnSlice, "projectVersion" ) );
metadataFacetModels.add( metadataFacetModel );
}
// rebuild MetadataFacet for artifacts
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 );
}
}
}