From d4d13dd56eccd51d2203434bed5c0f91f5bc8677 Mon Sep 17 00:00:00 2001 From: SteveScorfield <47788084+SteveScorfield@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:05:46 +0000 Subject: [PATCH] RAS-940: Questionnaire Completion Rate Information (#288) * Initial commit of code changes * auto patch increment * Have updated the naming * Updated changelog * Have added an additional test to ensure that datetime is added * Have ran mvn format * I have removed the test and just added the check within the first test * Have made changes based on recommendations and have updated name of audit test * Forgot to format --------- Co-authored-by: ras-rm-pr-bot --- _infra/helm/case/Chart.yaml | 4 ++-- .../ctp/response/casesvc/domain/model/CaseGroup.java | 4 ++++ .../casesvc/service/CaseGroupAuditService.java | 3 +-- .../response/casesvc/service/CaseGroupService.java | 2 ++ src/main/resources/database/changelog-master.yml | 5 ++++- .../release-36/add_timestamp_for_status_change.sql | 2 ++ .../database/changes/release-36/changelog.yml | 11 +++++++++++ .../casesvc/service/CaseGroupServiceTest.java | 8 ++++---- 8 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/database/changes/release-36/add_timestamp_for_status_change.sql create mode 100644 src/main/resources/database/changes/release-36/changelog.yml diff --git a/_infra/helm/case/Chart.yaml b/_infra/helm/case/Chart.yaml index d3f113b7b..891cc2500 100644 --- a/_infra/helm/case/Chart.yaml +++ b/_infra/helm/case/Chart.yaml @@ -14,8 +14,8 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. -version: 12.0.18 +version: 12.0.19 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. -appVersion: 12.0.18 +appVersion: 12.0.19 diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java index a5ce220fe..b5c840ee7 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java @@ -1,6 +1,7 @@ package uk.gov.ons.ctp.response.casesvc.domain.model; import java.io.Serializable; +import java.sql.Timestamp; import java.util.UUID; import javax.persistence.Column; import javax.persistence.Entity; @@ -61,4 +62,7 @@ public class CaseGroup implements Serializable { @Enumerated(EnumType.STRING) @Column(name = "status") private CaseGroupStatus status; + + @Column(name = "status_change_timestamp") + private Timestamp statusChangeTimestamp; } diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupAuditService.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupAuditService.java index eaf4ed876..7da1819d8 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupAuditService.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupAuditService.java @@ -8,7 +8,6 @@ import uk.gov.ons.ctp.response.casesvc.domain.model.CaseGroup; import uk.gov.ons.ctp.response.casesvc.domain.model.CaseGroupStatusAudit; import uk.gov.ons.ctp.response.casesvc.domain.repository.CaseGroupStatusAuditRepository; -import uk.gov.ons.ctp.response.lib.common.time.DateTimeUtil; @Service public class CaseGroupAuditService { @@ -23,7 +22,7 @@ public void updateAuditTable(final CaseGroup caseGroup, final UUID partyId) { auditEntity.setCaseGroupFK(caseGroup.getCaseGroupPK()); auditEntity.setStatus(caseGroup.getStatus()); auditEntity.setPartyId(partyId); - auditEntity.setCreatedDateTime(DateTimeUtil.nowUTC()); + auditEntity.setCreatedDateTime(caseGroup.getStatusChangeTimestamp()); log.with("audit_entity", auditEntity).debug("Updating the caseGroupStatus"); caseGroupStatusAuditRepository.saveAndFlush(auditEntity); } diff --git a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupService.java b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupService.java index 91398b4c2..f7931eb6e 100644 --- a/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupService.java +++ b/src/main/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupService.java @@ -18,6 +18,7 @@ import uk.gov.ons.ctp.response.lib.collection.exercise.CollectionExerciseDTO; import uk.gov.ons.ctp.response.lib.common.error.CTPException; import uk.gov.ons.ctp.response.lib.common.state.StateTransitionManager; +import uk.gov.ons.ctp.response.lib.common.time.DateTimeUtil; /** * A CaseGroupService implementation which encapsulates all business logic operating on the @@ -106,6 +107,7 @@ public void transitionCaseGroupStatus( if (newCaseGroupStatus != null && !oldCaseGroupStatus.equals(newCaseGroupStatus)) { caseGroup.setStatus(newCaseGroupStatus); + caseGroup.setStatusChangeTimestamp(DateTimeUtil.nowUTC()); caseGroupRepo.saveAndFlush(caseGroup); caseGroupAuditService.updateAuditTable(caseGroup, partyId); } diff --git a/src/main/resources/database/changelog-master.yml b/src/main/resources/database/changelog-master.yml index b80fa80e2..4bbd15c84 100644 --- a/src/main/resources/database/changelog-master.yml +++ b/src/main/resources/database/changelog-master.yml @@ -141,4 +141,7 @@ databaseChangeLog: file: database/changes/release-34/changelog.yml - include: - file: database/changes/release-35/changelog.yml \ No newline at end of file + file: database/changes/release-35/changelog.yml + + - include: + file: database/changes/release-36/changelog.yml \ No newline at end of file diff --git a/src/main/resources/database/changes/release-36/add_timestamp_for_status_change.sql b/src/main/resources/database/changes/release-36/add_timestamp_for_status_change.sql new file mode 100644 index 000000000..109b7d875 --- /dev/null +++ b/src/main/resources/database/changes/release-36/add_timestamp_for_status_change.sql @@ -0,0 +1,2 @@ +ALTER TABLE ONLY casesvc.casegroup + ADD status_change_timestamp timestamp with time zone; \ No newline at end of file diff --git a/src/main/resources/database/changes/release-36/changelog.yml b/src/main/resources/database/changes/release-36/changelog.yml new file mode 100644 index 000000000..42dd47766 --- /dev/null +++ b/src/main/resources/database/changes/release-36/changelog.yml @@ -0,0 +1,11 @@ +databaseChangeLog: + + - changeSet: + id: 36-1 + author: Steve Scorfield + changes: + - sqlFile: + comment: Add a timestamp column for when a status change is made to the survey for a respondent + path: add_timestamp_for_status_change.sql + relativeToChangelogFile: true + splitStatements: false \ No newline at end of file diff --git a/src/test/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupServiceTest.java b/src/test/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupServiceTest.java index e7b152458..d097a61de 100644 --- a/src/test/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupServiceTest.java +++ b/src/test/java/uk/gov/ons/ctp/response/casesvc/service/CaseGroupServiceTest.java @@ -42,8 +42,7 @@ public class CaseGroupServiceTest { private static final UUID SURVEY_ID = UUID.fromString("cb8accda-6118-4d3b-85a3-149e28960c54"); @Test - public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsSaved() - throws Exception { + public void testCaseGroupCorrectlyTransitionsToNewStatus() throws Exception { // Given CaseGroup caseGroup = CaseGroup.builder() @@ -64,12 +63,13 @@ public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsS caseGroupService.transitionCaseGroupStatus(caseGroup, categoryName, caseGroup.getPartyId()); // Then + assertNotNull(caseGroup.getStatusChangeTimestamp()); + assertEquals(caseGroup.getStatus(), CaseGroupStatus.COMPLETE); verify(caseGroupRepo).saveAndFlush(caseGroup); } @Test - public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsAudited() - throws Exception { + public void testCaseGroupStatusChangeIsCorrectlyAudited() throws Exception { // Given CaseGroup caseGroup = CaseGroup.builder()