From 4138da0f580c57d0d370735fbe408c6ce1038b0e Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Wed, 3 Oct 2018 09:44:09 +0100 Subject: [PATCH 1/2] Allow multiple verifications on a record This may be an edge-case, but the existing primary key setup means that if a user raises more than one issue against a record, then only one verification of these can be saved: the rowkey, userId and code (50005 unconfirmed) would all be the same. Verifying another one of the user's issues against the same record overwrites the first one. Including the relatedUuid field in the primary key fixes this, BUT it means non-verification qa entries must have an empty string ("") relatedUuid, instead of null, since part of a composite key cannot be null. This is fixed in the next pull request. --- conf/cassandra3_case_sensitive_schema.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/cassandra3_case_sensitive_schema.txt b/conf/cassandra3_case_sensitive_schema.txt index e2db99638..c3083f023 100644 --- a/conf/cassandra3_case_sensitive_schema.txt +++ b/conf/cassandra3_case_sensitive_schema.txt @@ -114,7 +114,7 @@ CREATE TABLE occ.qa ( "userDisplayName" text, "userEmail" text, uuid text, - PRIMARY KEY (rowkey, "userId", code) + PRIMARY KEY (rowkey, "userId", code, relatedUuid) ) WITH CLUSTERING ORDER BY ("userId" ASC, code ASC) AND bloom_filter_fp_chance = 0.01 AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} @@ -721,4 +721,4 @@ CREATE TABLE occ.loc_new ( AND memtable_flush_period_in_ms = 0 AND min_index_interval = 128 AND read_repair_chance = 0.0 - AND speculative_retry = '99PERCENTILE'; \ No newline at end of file + AND speculative_retry = '99PERCENTILE'; From 134bb7d7470378250d7ebfd2c5cd53b0b90f7a94 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Wed, 3 Oct 2018 09:49:18 +0100 Subject: [PATCH 2/2] Fixes for new cassandra occ.qa primary key Allow single verification deletion, instead of all with particular code by particular user on single record. --- .../scala/au/org/ala/biocache/dao/OccurrenceDAOImpl.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/scala/au/org/ala/biocache/dao/OccurrenceDAOImpl.scala b/src/main/scala/au/org/ala/biocache/dao/OccurrenceDAOImpl.scala index 650441902..d82801671 100644 --- a/src/main/scala/au/org/ala/biocache/dao/OccurrenceDAOImpl.scala +++ b/src/main/scala/au/org/ala/biocache/dao/OccurrenceDAOImpl.scala @@ -902,7 +902,7 @@ class OccurrenceDAOImpl extends OccurrenceDAO { if (!record.isEmpty) { //preserve the raw record - val qaMap = qualityAssertionProperties ++ Map("snapshot" -> Json.toJSON(record.get)) + val qaMap = qualityAssertionProperties ++ (if (qualityAssertion.relatedUuid == null || qualityAssertion.relatedUuid.isEmpty()) Map("relatedUuid" -> "") else Map()) ++ Map("snapshot" -> Json.toJSON(record.get)) persistenceManager.put(rowKey, qaEntityName, qaMap, true, false) val systemAssertions = getSystemAssertions(rowKey) val userAssertions = getUserAssertions(rowKey) @@ -969,7 +969,8 @@ class OccurrenceDAOImpl extends OccurrenceDAO { Map( "rowkey" -> toBeDeleted.referenceRowKey, "userId" -> toBeDeleted.getUserId, - "code" -> toBeDeleted.code.toString + "code" -> toBeDeleted.code.toString, + (if (Config.caseSensitiveCassandra) "relatedUuid" else "relateduuid") -> toBeDeleted.getRelatedUuid ), qaEntityName )