From 869291b35110fbe85810c9fe591228b96b19b40a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 24 Mar 2014 04:55:24 +0000 Subject: fix retrieving facets git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1580743 13f79535-47bb-0310-9956-ffa450edef68 --- .../cassandra/CassandraMetadataRepository.java | 73 +++++++--------------- 1 file changed, 21 insertions(+), 52 deletions(-) (limited to 'archiva-modules') diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java index 3a689fa45..1714f25fd 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java @@ -969,66 +969,35 @@ public class CassandraMetadataRepository projectVersionMetadata.setUrl( columnFamilyResult.getString( "url" ) ); - /* - - ProjectVersionMetadataModel projectVersionMetadataModel = - getProjectVersionMetadataModelEntityManager().get( key ); - - if ( projectVersionMetadataModel == null ) - { - logger.debug( - "getProjectVersion repoId: '{}', namespace: '{}', projectId: '{}', projectVersion: {} -> not found", - repoId, namespace, projectId, projectVersion ); - return null; - } - - ProjectVersionMetadata projectVersionMetadata = - getModelMapper().map( projectVersionMetadataModel, ProjectVersionMetadata.class ); - - logger.debug( "getProjectVersion repoId: '{}', namespace: '{}', projectId: '{}', projectVersion: {} -> {}", - repoId, namespace, projectId, projectVersion, projectVersionMetadata ); + // FIXME complete collections !! + // facets - projectVersionMetadata.setCiManagement( projectVersionMetadataModel.getCiManagement() ); - projectVersionMetadata.setIssueManagement( projectVersionMetadataModel.getIssueManagement() ); - projectVersionMetadata.setOrganization( projectVersionMetadataModel.getOrganization() ); - projectVersionMetadata.setScm( projectVersionMetadataModel.getScm() ); + StringSerializer ss = StringSerializer.get(); - // FIXME complete collections !! + Keyspace keyspace = cassandraArchivaManager.getKeyspace(); + QueryResult> result = HFactory // + .createRangeSlicesQuery( keyspace, ss, ss, ss ) // + .setColumnFamily( cassandraArchivaManager.getMetadataFacetModelFamilyName() ) // + .setColumnNames( "facetId", "key", "value", "name" ) // + .addEqualsExpression( "repositoryName", repoId ) // + .addEqualsExpression( "namespaceId", namespace ) // + .addEqualsExpression( "projectId", projectId ) // + .addEqualsExpression( "projectVersion", projectVersion ) // + .execute(); - // facets - final List metadataFacetModels = new ArrayList(); - // FIXME use cql query - getMetadataFacetModelEntityManager().visitAll( new Function() - { - @Override - public Boolean apply( MetadataFacetModel metadataFacetModel ) - { - if ( metadataFacetModel != null ) - { - if ( StringUtils.equals( repoId, metadataFacetModel.getArtifactMetadataModel().getRepositoryId() ) - && StringUtils.equals( namespace, metadataFacetModel.getArtifactMetadataModel().getNamespace() ) - && StringUtils.equals( projectId, metadataFacetModel.getArtifactMetadataModel().getProject() ) - && StringUtils.equals( projectVersion, - metadataFacetModel.getArtifactMetadataModel().getProjectVersion() ) ) - { - metadataFacetModels.add( metadataFacetModel ); - } - } - return Boolean.TRUE; - } - } ); Map> metadataFacetsPerFacetIds = new HashMap>(); - for ( MetadataFacetModel metadataFacetModel : metadataFacetModels ) - { - Map metaValues = metadataFacetsPerFacetIds.get( metadataFacetModel.getFacetId() ); + for ( Row row : result.get() ) + { + ColumnSlice columnSlice = row.getColumnSlice(); + String facetId = getStringValue( columnSlice, "facetId" ); + Map metaValues = metadataFacetsPerFacetIds.get( facetId ); if ( metaValues == null ) { metaValues = new HashMap(); - metadataFacetsPerFacetIds.put( metadataFacetModel.getFacetId(), metaValues ); + metadataFacetsPerFacetIds.put( facetId, metaValues ); } - metaValues.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() ); - + metaValues.put( getStringValue( columnSlice, "key" ), getStringValue( columnSlice, "value" ) ); } if ( !metadataFacetsPerFacetIds.isEmpty() ) @@ -1044,7 +1013,7 @@ public class CassandraMetadataRepository } } } - */ + return projectVersionMetadata; } -- cgit v1.2.3