From 27efbb7fb1aba9f00d236233b5b89e06c43aa4a1 Mon Sep 17 00:00:00 2001 From: QBai <31238531+qifeng-bai@users.noreply.github.com> Date: Thu, 9 Jan 2025 12:50:36 +1100 Subject: [PATCH] #346 sort verified assertions with created date Thus, my annotation email always displays the latest assertions --- .../org/ala/alerts/MyAnnotationService.groovy | 17 +- .../org/ala/alerts/NotificationService.groovy | 2 - .../ala/alerts/MyAnnotationServiceSpec.groovy | 1474 ++++++++++------- 3 files changed, 911 insertions(+), 582 deletions(-) diff --git a/grails-app/services/au/org/ala/alerts/MyAnnotationService.groovy b/grails-app/services/au/org/ala/alerts/MyAnnotationService.groovy index c34d3598..628e1360 100644 --- a/grails-app/services/au/org/ala/alerts/MyAnnotationService.groovy +++ b/grails-app/services/au/org/ala/alerts/MyAnnotationService.groovy @@ -126,17 +126,24 @@ class MyAnnotationService{ * @return */ private static def findVerifiedAssertions(JSONArray assertions, String userId) { - def verifiedAssertions = [] + def sortedAssertions = [] if (assertions) { // all the original user assertions (issues users flagged) def origUserAssertions = assertions.findAll { it.uuid && !it.relatedUuid && it.userId == userId } // Find assertions which commented on the original user assertions def myOriginalUuids = origUserAssertions*.uuid - // todo - need to check if 50003 or 50001 is the correct status for Verified assertions - verifiedAssertions = myOriginalUuids.collectMany { uuid -> - assertions.findAll { it.relatedUuid == uuid && ( it.qaStatus == 50003 || it.qaStatus == 50001)} + def verifiedAssertions = myOriginalUuids.collectMany { uuid -> + assertions.findAll { it.relatedUuid == uuid && ( it.qaStatus == 50001 || it.qaStatus == 50002 || it.qaStatus == 50003) } + } + + try { + sortedAssertions = verifiedAssertions.sort { a, b -> + Date.parse("yyyy-MM-dd'T'HH:mm:ssX", b.created) <=> Date.parse("yyyy-MM-dd'T'HH:mm:ssX", a.created) + } + } catch (Exception e) { + sortedAssertions = verifiedAssertions } } - return verifiedAssertions + return sortedAssertions } } diff --git a/grails-app/services/au/org/ala/alerts/NotificationService.groovy b/grails-app/services/au/org/ala/alerts/NotificationService.groovy index 1dfb3a02..23b3e9c0 100644 --- a/grails-app/services/au/org/ala/alerts/NotificationService.groovy +++ b/grails-app/services/au/org/ala/alerts/NotificationService.groovy @@ -3,10 +3,8 @@ package au.org.ala.alerts import com.jayway.jsonpath.JsonPath import grails.gorm.transactions.NotTransactional import grails.converters.JSON -import org.apache.commons.io.IOUtils import org.apache.commons.lang.time.DateUtils import org.grails.web.json.JSONArray -import org.grails.web.json.JSONElement import org.grails.web.json.JSONObject import javax.transaction.Transactional diff --git a/src/test/groovy/au/org/ala/alerts/MyAnnotationServiceSpec.groovy b/src/test/groovy/au/org/ala/alerts/MyAnnotationServiceSpec.groovy index ea0b8173..a89467d5 100644 --- a/src/test/groovy/au/org/ala/alerts/MyAnnotationServiceSpec.groovy +++ b/src/test/groovy/au/org/ala/alerts/MyAnnotationServiceSpec.groovy @@ -3,7 +3,7 @@ package au.org.ala.alerts import grails.testing.services.ServiceUnitTest import spock.lang.Specification -class MyAnnotationServiceSpec extends Specification implements ServiceUnitTest{ +class MyAnnotationServiceSpec extends Specification implements ServiceUnitTest { def assertionService @@ -22,7 +22,7 @@ class MyAnnotationServiceSpec extends Specification implements ServiceUnitTest