From 01b3328e2b8ce6de4ec017049143f6882372dec4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 21 Mar 2014 04:57:24 +0000 Subject: [PATCH] fix retrieving ArtifactMetadata with null date git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1579884 13f79535-47bb-0310-9956-ffa450edef68 --- .../CassandraMetadataRepository.java | 92 ++++++++----------- .../src/test/resources/log4j2-test.xml | 2 +- 2 files changed, 38 insertions(+), 56 deletions(-) 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 a2447893f..298030fdb 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 @@ -21,6 +21,7 @@ package org.apache.archiva.metadata.repository.cassandra; import me.prettyprint.cassandra.model.CqlQuery; import me.prettyprint.cassandra.model.CqlRows; +import me.prettyprint.cassandra.serializers.LongSerializer; import me.prettyprint.cassandra.serializers.StringSerializer; import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate; import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater; @@ -643,9 +644,7 @@ public class CassandraMetadataRepository .addEqualsExpression( "projectId", projectId ) // .execute(); - - - for (Row row : result.get()) + for ( Row row : result.get() ) { this.projectVersionMetadataModelTemplate.deleteRow( row.getKey() ); } @@ -1534,64 +1533,47 @@ public class CassandraMetadataRepository .execute(); */ StringSerializer ss = StringSerializer.get(); - CqlQuery cqlQuery = new CqlQuery( keyspace, ss, ss, ss ); - cqlQuery.setQuery( "select * from " + cassandraArchivaManager.getArtifactMetadataModelFamilyName() // - + " where 'whenGathered' >= " + startTime.getTime() // - + " and 'whenGathered' <= " + endTime.getTime() // - + " and respositoryName = '" + repositoryId + "'" ); - QueryResult> result = cqlQuery.execute(); - List keys = new ArrayList( result.get().getCount() ); + StringBuilder cqlQuery = + new StringBuilder( "select * from " + cassandraArchivaManager.getArtifactMetadataModelFamilyName() ); + cqlQuery.append( " where repositoryName = '" + repositoryId + "'" ); + if ( startTime != null ) + { + cqlQuery.append( " and 'whenGathered' >= " + startTime.getTime() ); + } + + if ( endTime != null ) + { + cqlQuery.append( " and 'whenGathered' <= " + endTime.getTime() ); + } + + QueryResult> result = + new CqlQuery( keyspace, ss, ss, ss ).setQuery( cqlQuery.toString() ).execute(); + + List artifactMetadatas = new ArrayList( result.get().getCount() ); + + LongSerializer ls = LongSerializer.get(); for ( Row row : result.get() ) { - keys.add( row.getKey() ); - } - - - -/* final List artifactMetadataModels = new ArrayList(); - - // FIXME cql query - getArtifactMetadataModelEntityManager().visitAll( new Function() - { - @Override - public Boolean apply( ArtifactMetadataModel artifactMetadataModel ) - { - if ( artifactMetadataModel != null ) - { - if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId ) - && artifactMetadataModel.getNamespace() != null && - artifactMetadataModel.getProject() != null && artifactMetadataModel.getId() != null ) - { - - Date when = artifactMetadataModel.getWhenGathered(); - if ( ( startTime != null ? when.getTime() >= startTime.getTime() : true ) && ( endTime != null ? - when.getTime() <= endTime.getTime() : true ) ) - { - logger.debug( "getArtifactsByDateRange visitAll found: {}", artifactMetadataModel ); - artifactMetadataModels.add( artifactMetadataModel ); - } - } - } - return Boolean.TRUE; - } - } ); - List artifactMetadatas = new ArrayList( artifactMetadataModels.size() ); - - for ( ArtifactMetadataModel model : artifactMetadataModels ) - { - ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class ); - populateFacets( artifactMetadata ); + ColumnSlice columnSlice = row.getColumnSlice(); + ArtifactMetadata artifactMetadata = new ArtifactMetadata(); + artifactMetadata.setNamespace( columnSlice.getColumnByName( "namespaceId" ).getValue() ); + artifactMetadata.setSize( ls.fromByteBuffer( columnSlice.getColumnByName( "size" ).getValueBytes() ) ); + artifactMetadata.setId( columnSlice.getColumnByName( "id" ).getValue() ); + artifactMetadata.setFileLastModified( + ls.fromByteBuffer( columnSlice.getColumnByName( "fileLastModified" ).getValueBytes() ) ); + artifactMetadata.setMd5( columnSlice.getColumnByName( "md5" ).getValue() ); + artifactMetadata.setProject( columnSlice.getColumnByName( "project" ).getValue() ); + artifactMetadata.setProjectVersion( columnSlice.getColumnByName( "projectVersion" ).getValue() ); + artifactMetadata.setRepositoryId( columnSlice.getColumnByName( "repositoryName" ).getValue() ); + artifactMetadata.setSha1( columnSlice.getColumnByName( "sha1" ).getValue() ); + artifactMetadata.setVersion( columnSlice.getColumnByName( "version" ).getValue() ); + artifactMetadata.setWhenGathered( + new Date( ls.fromByteBuffer( columnSlice.getColumnByName( "whenGathered" ).getValueBytes() ) ) ); artifactMetadatas.add( artifactMetadata ); } - // FIXME facets ? - - logger.debug( "getArtifactsByDateRange repositoryId: {}, startTime: {}, endTime: {}, artifactMetadatas: {}", - repositoryId, startTime, endTime, artifactMetadatas ); - - return artifactMetadatas;*/ - return Collections.emptyList(); + return artifactMetadatas; } protected void populateFacets( final ArtifactMetadata artifactMetadata ) diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml b/archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml index eda946883..a2aad3034 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml @@ -33,7 +33,7 @@ - +