]> source.dussan.org Git - archiva.git/commitdiff
fix retrieving ArtifactMetadata with null date
authorOlivier Lamy <olamy@apache.org>
Fri, 21 Mar 2014 04:57:24 +0000 (04:57 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 21 Mar 2014 04:57:24 +0000 (04:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1579884 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml

index a2447893f8b6732c9e84d109b9039ba54ed52d46..298030fdb814e92de63769401ea44d39bd62935d 100644 (file)
@@ -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 )
index eda9468838ae4cdf2ac11981f8398a428d8deb07..a2aad30342754c66c683c2c5182bf74a9adc6cde 100644 (file)
@@ -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"/>