aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2014-03-21 04:57:24 +0000
committerOlivier Lamy <olamy@apache.org>2014-03-21 04:57:24 +0000
commit01b3328e2b8ce6de4ec017049143f6882372dec4 (patch)
tree0cfbf5c3e43dc194625f5c3a4c708e8512c9a5cc /archiva-modules
parent8c88e1f44625e482df2b0c3202dd5b9b383aa749 (diff)
downloadarchiva-01b3328e2b8ce6de4ec017049143f6882372dec4.tar.gz
archiva-01b3328e2b8ce6de4ec017049143f6882372dec4.zip
fix retrieving ArtifactMetadata with null date
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1579884 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java82
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml2
2 files changed, 33 insertions, 51 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<String,String,String> row : result.get())
+ for ( Row<String, String, String> row : result.get() )
{
this.projectVersionMetadataModelTemplate.deleteRow( row.getKey() );
}
@@ -1534,64 +1533,47 @@ public class CassandraMetadataRepository
.execute();
*/
StringSerializer ss = StringSerializer.get();
- CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>( keyspace, ss, ss, ss );
- cqlQuery.setQuery( "select * from " + cassandraArchivaManager.getArtifactMetadataModelFamilyName() //
- + " where 'whenGathered' >= " + startTime.getTime() //
- + " and 'whenGathered' <= " + endTime.getTime() //
- + " and respositoryName = '" + repositoryId + "'" );
- QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute();
- List<String> keys = new ArrayList<String>( result.get().getCount() );
-
- for ( Row<String, String, String> row : result.get() )
+ StringBuilder cqlQuery =
+ new StringBuilder( "select * from " + cassandraArchivaManager.getArtifactMetadataModelFamilyName() );
+ cqlQuery.append( " where repositoryName = '" + repositoryId + "'" );
+ if ( startTime != null )
{
- keys.add( row.getKey() );
+ cqlQuery.append( " and 'whenGathered' >= " + startTime.getTime() );
}
+ if ( endTime != null )
+ {
+ cqlQuery.append( " and 'whenGathered' <= " + endTime.getTime() );
+ }
+ QueryResult<CqlRows<String, String, String>> result =
+ new CqlQuery<String, String, String>( keyspace, ss, ss, ss ).setQuery( cqlQuery.toString() ).execute();
-/* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
-
- // FIXME cql query
- getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
- {
- @Override
- public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
- {
- if ( artifactMetadataModel != null )
- {
- if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId )
- && artifactMetadataModel.getNamespace() != null &&
- artifactMetadataModel.getProject() != null && artifactMetadataModel.getId() != null )
- {
+ List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( result.get().getCount() );
- 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<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
+ LongSerializer ls = LongSerializer.get();
- for ( ArtifactMetadataModel model : artifactMetadataModels )
+ for ( Row<String, String, String> row : result.get() )
{
- ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
- populateFacets( artifactMetadata );
+ ColumnSlice<String, String> 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 @@
<loggers>
- <logger name="org.apache.archiva.metadata.repository.cassandra.CassandraMetadataRepository" level="debug"/>
+ <logger name="org.apache.archiva.metadata.repository.cassandra" level="debug"/>
<root level="info" includeLocation="true">
<appender-ref ref="console"/>