]> source.dussan.org Git - archiva.git/commitdiff
record mailing lists in Cassandra
authorOlivier Lamy <olamy@apache.org>
Tue, 25 Mar 2014 06:28:03 +0000 (06:28 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 25 Mar 2014 06:28:03 +0000 (06:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581252 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java

index d7ba7b1174965faf7a90f88b5f3f4c707280492d..78b7f86117916a5eef5de7051edc6feed241a437 100644 (file)
@@ -42,6 +42,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.CiManagement;
 import org.apache.archiva.metadata.model.FacetedMetadata;
 import org.apache.archiva.metadata.model.IssueManagement;
+import org.apache.archiva.metadata.model.MailingList;
 import org.apache.archiva.metadata.model.MetadataFacet;
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 import org.apache.archiva.metadata.model.Organization;
@@ -74,6 +75,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 
 import static org.apache.archiva.metadata.repository.cassandra.CassandraUtils.*;
 
@@ -101,6 +103,8 @@ public class CassandraMetadataRepository
 
     private final ColumnFamilyTemplate<String, String> metadataFacetTemplate;
 
+    private final ColumnFamilyTemplate<String, String> mailingListTemplate;
+
     public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
                                         ArchivaConfiguration configuration,
                                         CassandraArchivaManager cassandraArchivaManager )
@@ -134,6 +138,13 @@ public class CassandraMetadataRepository
                                                             //
                                                             StringSerializer.get(), //
                                                             StringSerializer.get() );
+
+        this.mailingListTemplate =
+            new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
+                                                            cassandraArchivaManager.getMailingListFamilyName(),
+                                                            //
+                                                            StringSerializer.get(), //
+                                                            StringSerializer.get() );
     }
 
 
@@ -879,6 +890,11 @@ public class CassandraMetadataRepository
                 }
             }
 
+            if ( versionMetadata.getMailingLists() != null )
+            {
+                recordMailingList( key, versionMetadata.getMailingLists() );
+            }
+
             MutationResult mutationResult = mutator.execute();
         }
         else
@@ -936,6 +952,13 @@ public class CassandraMetadataRepository
                 }
             }
 
+            if ( versionMetadata.getMailingLists() != null )
+            {
+                // update is a delete record
+                removeMailingList( key );
+                recordMailingList( key, versionMetadata.getMailingLists() );
+            }
+
             projectVersionMetadataModelTemplate.update( updater );
 
         }
@@ -1008,6 +1031,7 @@ public class CassandraMetadataRepository
                 projectVersionMetadata.setScm( new Scm( conn, devConn, url ) );
             }
         }
+        projectVersionMetadata.setMailingLists( getMailingLists( key ) );
         // FIXME complete collections !!
         // facets
 
@@ -1056,6 +1080,96 @@ public class CassandraMetadataRepository
         return projectVersionMetadata;
     }
 
+    protected void recordMailingList( String projectVersionMetadataKey, List<MailingList> mailingLists )
+    {
+        if ( mailingLists == null || mailingLists.isEmpty() )
+        {
+            return;
+        }
+        Mutator<String> mailingMutator = this.mailingListTemplate.createMutator();
+        for ( MailingList mailingList : mailingLists )
+        {
+            // we don't care about the key as the real used one with the projectVersionMetadata
+            String keyMailingList = UUID.randomUUID().toString();
+            String cfMailingList = cassandraArchivaManager.getMailingListFamilyName();
+
+            addInsertion( mailingMutator, keyMailingList, cfMailingList, "projectVersionMetadataModel.key",
+                          projectVersionMetadataKey );
+            addInsertion( mailingMutator, keyMailingList, cfMailingList, "name", mailingList.getName() );
+            addInsertion( mailingMutator, keyMailingList, cfMailingList, "mainArchiveUrl",
+                          mailingList.getMainArchiveUrl() );
+            addInsertion( mailingMutator, keyMailingList, cfMailingList, "postAddress", mailingList.getPostAddress() );
+            addInsertion( mailingMutator, keyMailingList, cfMailingList, "subscribeAddress",
+                          mailingList.getSubscribeAddress() );
+            addInsertion( mailingMutator, keyMailingList, cfMailingList, "unsubscribeAddress",
+                          mailingList.getUnsubscribeAddress() );
+            int idx = 0;
+            for ( String otherArchive : mailingList.getOtherArchives() )
+            {
+                addInsertion( mailingMutator, keyMailingList, cfMailingList, "otherArchive." + idx, otherArchive );
+                idx++;
+            }
+
+        }
+        mailingMutator.execute();
+    }
+
+    protected void removeMailingList( String projectVersionMetadataKey )
+    {
+        StringSerializer ss = StringSerializer.get();
+        QueryResult<OrderedRows<String, String, String>> result =
+            HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
+                .setColumnFamily( cassandraArchivaManager.getMailingListFamilyName() ) //
+                .setColumnNames( "name" ) //
+                .setRowCount( Integer.MAX_VALUE ) //
+                .addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
+                .execute();
+        for ( Row<String, String, String> row : result.get() )
+        {
+            this.mailingListTemplate.deleteRow( row.getKey() );
+        }
+    }
+
+    protected List<MailingList> getMailingLists( String projectVersionMetadataKey )
+    {
+        List<MailingList> mailingLists = new ArrayList<MailingList>();
+
+        StringSerializer ss = StringSerializer.get();
+        QueryResult<OrderedRows<String, String, String>> result =
+            HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
+                .setColumnFamily( cassandraArchivaManager.getMailingListFamilyName() ) //
+                .setColumnNames( "name" ) //
+                .setRowCount( Integer.MAX_VALUE ) //
+                .addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
+                .execute();
+        for ( Row<String, String, String> row : result.get() )
+        {
+            ColumnFamilyResult<String, String> columnFamilyResult =
+                this.mailingListTemplate.queryColumns( row.getKey() );
+
+            MailingList mailingList = new MailingList();
+            mailingList.setName( columnFamilyResult.getString( "name" ) );
+            mailingList.setMainArchiveUrl( columnFamilyResult.getString( "mainArchiveUrl" ) );
+            mailingList.setPostAddress( columnFamilyResult.getString( "postAddress" ) );
+            mailingList.setSubscribeAddress( columnFamilyResult.getString( "subscribeAddress" ) );
+            mailingList.setUnsubscribeAddress( columnFamilyResult.getString( "unsubscribeAddress" ) );
+
+            List<String> otherArchives = new ArrayList<String>();
+
+            for ( String columnName : columnFamilyResult.getColumnNames() )
+            {
+                if (StringUtils.startsWith( columnName, "otherArchive." ))
+                {
+                    otherArchives.add( columnFamilyResult.getString( columnName ) );
+                }
+            }
+
+            mailingList.setOtherArchives( otherArchives );
+            mailingLists.add( mailingList );
+        }
+
+        return mailingLists;
+    }
 
     @Override
     public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
index 651507d02ee395edc10a866140987b92cdf0cae1..abf060502902032b13e030b3454441d8a0bdf609 100644 (file)
@@ -81,6 +81,8 @@ public class DefaultCassandraArchivaManager
 
     private String metadataFacetModelFamilyName = "metadatafacetmodel";
 
+    private String mailingListFamilyName = "mailinglist";
+
 
     @PostConstruct
     public void initialize()
@@ -359,6 +361,25 @@ public class DefaultCassandraArchivaManager
 
         }
 
+        // mailinglist table
+        {
+            final ColumnFamilyDefinition mailingListCf =
+                HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
+                                                       getMailingListFamilyName(), //
+                                                       ComparatorType.UTF8TYPE );
+            cfds.add( mailingListCf );
+
+            // creating indexes for cql query
+
+            BasicColumnDefinition projectVersionMetadataIdColumn = new BasicColumnDefinition();
+            projectVersionMetadataIdColumn.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataId" ) );
+            projectVersionMetadataIdColumn.setIndexName( "projectVersionMetadataId" );
+            projectVersionMetadataIdColumn.setIndexType( ColumnIndexType.KEYS );
+            projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+            mailingListCf.addColumnDefinition( projectVersionMetadataIdColumn );
+
+
+        }
 
         // TODO take care of update new table!!
         { // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
@@ -432,4 +453,9 @@ public class DefaultCassandraArchivaManager
     {
         return metadataFacetModelFamilyName;
     }
+
+    public String getMailingListFamilyName()
+    {
+        return mailingListFamilyName;
+    }
 }