From 57835edda8fbf7db7dff2faa2989aa5519d9ce11 Mon Sep 17 00:00:00 2001 From: SteveScorfield Date: Mon, 29 Jan 2024 13:56:02 +0000 Subject: [PATCH 1/9] Initial commit of code changes --- .../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 +++++++++++ 6 files changed, 24 insertions(+), 3 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/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..bbf6e98c8 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 = "change_state_timestamp") + private Timestamp changeStateTimestamp; } 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..a07220424 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.getChangeStateTimestamp()); 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..6e7087f31 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.setChangeStateTimestamp(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..34fea3aeb --- /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 change_state_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 From f449b330e76d032d21107a3c52856ebca7fa4ee4 Mon Sep 17 00:00:00 2001 From: ras-rm-pr-bot Date: Mon, 29 Jan 2024 14:03:19 +0000 Subject: [PATCH 2/9] auto patch increment --- _infra/helm/case/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 9e2c83eaedd614e39d80f11aba26446c2d4e2997 Mon Sep 17 00:00:00 2001 From: SteveScorfield Date: Fri, 2 Feb 2024 10:01:00 +0000 Subject: [PATCH 3/9] Have updated the naming --- .../gov/ons/ctp/response/casesvc/domain/model/CaseGroup.java | 4 ++-- .../ctp/response/casesvc/service/CaseGroupAuditService.java | 2 +- .../ons/ctp/response/casesvc/service/CaseGroupService.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 bbf6e98c8..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 @@ -63,6 +63,6 @@ public class CaseGroup implements Serializable { @Column(name = "status") private CaseGroupStatus status; - @Column(name = "change_state_timestamp") - private Timestamp changeStateTimestamp; + @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 a07220424..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 @@ -22,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(caseGroup.getChangeStateTimestamp()); + 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 6e7087f31..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 @@ -107,7 +107,7 @@ public void transitionCaseGroupStatus( if (newCaseGroupStatus != null && !oldCaseGroupStatus.equals(newCaseGroupStatus)) { caseGroup.setStatus(newCaseGroupStatus); - caseGroup.setChangeStateTimestamp(DateTimeUtil.nowUTC()); + caseGroup.setStatusChangeTimestamp(DateTimeUtil.nowUTC()); caseGroupRepo.saveAndFlush(caseGroup); caseGroupAuditService.updateAuditTable(caseGroup, partyId); } From 6f17a0ca4c4f8c784eb49600b38a1ce31af2f882 Mon Sep 17 00:00:00 2001 From: SteveScorfield Date: Fri, 2 Feb 2024 10:32:21 +0000 Subject: [PATCH 4/9] Updated changelog --- .../changes/release-36/add_timestamp_for_status_change.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 34fea3aeb..109b7d875 100644 --- 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 @@ -1,2 +1,2 @@ ALTER TABLE ONLY casesvc.casegroup - ADD change_state_timestamp timestamp with time zone; \ No newline at end of file + ADD status_change_timestamp timestamp with time zone; \ No newline at end of file From 4ec8d926005655bd0bb2fc27b7c5a06434e8177d Mon Sep 17 00:00:00 2001 From: SteveScorfield Date: Mon, 5 Feb 2024 08:37:25 +0000 Subject: [PATCH 5/9] Have added an additional test to ensure that datetime is added --- .../casesvc/service/CaseGroupServiceTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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..270b35b10 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 @@ -6,6 +6,8 @@ import static org.mockito.Mockito.verify; import java.util.*; + +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -295,4 +297,30 @@ public void CaseGroupFindForExecutedCaseIsNullThrowsException() throws CTPExcept // Then throws CTPException } + + @Test + public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenStatusChangeTimestampIsUpdated() + throws Exception { + // Given + CaseGroup caseGroup = + CaseGroup.builder() + .id(UUID.randomUUID()) + .collectionExerciseId(UUID.randomUUID()) + .partyId(UUID.randomUUID()) + .sampleUnitRef("12345") + .sampleUnitType("B") + .status(CaseGroupStatus.NOTSTARTED) + .build(); + + CategoryDTO.CategoryName categoryName = + CategoryDTO.CategoryName.COLLECTION_INSTRUMENT_DOWNLOADED; + given(caseGroupStatusTransitionManager.transition(caseGroup.getStatus(), categoryName)) + .willReturn(CaseGroupStatus.COMPLETE); + + // When + caseGroupService.transitionCaseGroupStatus(caseGroup, categoryName, caseGroup.getPartyId()); + + // Then + Assert.assertNotNull(caseGroup.getStatusChangeTimestamp()); + } } From 7a0b9c6857dcb339e157ab9f9155ff03b6466ba6 Mon Sep 17 00:00:00 2001 From: SteveScorfield Date: Mon, 5 Feb 2024 08:40:35 +0000 Subject: [PATCH 6/9] Have ran mvn format --- .../casesvc/service/CaseGroupServiceTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) 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 270b35b10..0dbba6f56 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 @@ -6,7 +6,6 @@ import static org.mockito.Mockito.verify; import java.util.*; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -299,23 +298,24 @@ public void CaseGroupFindForExecutedCaseIsNullThrowsException() throws CTPExcept } @Test - public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenStatusChangeTimestampIsUpdated() + public void + givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenStatusChangeTimestampIsUpdated() throws Exception { // Given CaseGroup caseGroup = - CaseGroup.builder() - .id(UUID.randomUUID()) - .collectionExerciseId(UUID.randomUUID()) - .partyId(UUID.randomUUID()) - .sampleUnitRef("12345") - .sampleUnitType("B") - .status(CaseGroupStatus.NOTSTARTED) - .build(); + CaseGroup.builder() + .id(UUID.randomUUID()) + .collectionExerciseId(UUID.randomUUID()) + .partyId(UUID.randomUUID()) + .sampleUnitRef("12345") + .sampleUnitType("B") + .status(CaseGroupStatus.NOTSTARTED) + .build(); CategoryDTO.CategoryName categoryName = - CategoryDTO.CategoryName.COLLECTION_INSTRUMENT_DOWNLOADED; + CategoryDTO.CategoryName.COLLECTION_INSTRUMENT_DOWNLOADED; given(caseGroupStatusTransitionManager.transition(caseGroup.getStatus(), categoryName)) - .willReturn(CaseGroupStatus.COMPLETE); + .willReturn(CaseGroupStatus.COMPLETE); // When caseGroupService.transitionCaseGroupStatus(caseGroup, categoryName, caseGroup.getPartyId()); From 42c4827cdbdeb9c81cbb3c1263e68f185fdb4293 Mon Sep 17 00:00:00 2001 From: SteveScorfield Date: Mon, 5 Feb 2024 13:18:19 +0000 Subject: [PATCH 7/9] I have removed the test and just added the check within the first test --- .../casesvc/service/CaseGroupServiceTest.java | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) 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 0dbba6f56..143c6ce60 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 @@ -65,6 +65,8 @@ public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsS caseGroupService.transitionCaseGroupStatus(caseGroup, categoryName, caseGroup.getPartyId()); // Then + Assert.assertNotNull(caseGroup.getStatusChangeTimestamp()); + Assert.assertEquals(caseGroup.getStatus(), CaseGroupStatus.COMPLETE); verify(caseGroupRepo).saveAndFlush(caseGroup); } @@ -91,6 +93,7 @@ public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsA caseGroupService.transitionCaseGroupStatus(caseGroup, categoryName, caseGroup.getPartyId()); // Then + verify(caseGroupAuditService).updateAuditTable(caseGroup, caseGroup.getPartyId()); } @@ -296,31 +299,4 @@ public void CaseGroupFindForExecutedCaseIsNullThrowsException() throws CTPExcept // Then throws CTPException } - - @Test - public void - givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenStatusChangeTimestampIsUpdated() - throws Exception { - // Given - CaseGroup caseGroup = - CaseGroup.builder() - .id(UUID.randomUUID()) - .collectionExerciseId(UUID.randomUUID()) - .partyId(UUID.randomUUID()) - .sampleUnitRef("12345") - .sampleUnitType("B") - .status(CaseGroupStatus.NOTSTARTED) - .build(); - - CategoryDTO.CategoryName categoryName = - CategoryDTO.CategoryName.COLLECTION_INSTRUMENT_DOWNLOADED; - given(caseGroupStatusTransitionManager.transition(caseGroup.getStatus(), categoryName)) - .willReturn(CaseGroupStatus.COMPLETE); - - // When - caseGroupService.transitionCaseGroupStatus(caseGroup, categoryName, caseGroup.getPartyId()); - - // Then - Assert.assertNotNull(caseGroup.getStatusChangeTimestamp()); - } } From 9914eba6f522ceb33d888b2d1811902a8764022d Mon Sep 17 00:00:00 2001 From: SteveScorfield Date: Mon, 5 Feb 2024 14:09:07 +0000 Subject: [PATCH 8/9] Have made changes based on recommendations and have updated name of audit test --- .../response/casesvc/service/CaseGroupServiceTest.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 143c6ce60..032460804 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 @@ -6,7 +6,6 @@ import static org.mockito.Mockito.verify; import java.util.*; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -43,7 +42,7 @@ public class CaseGroupServiceTest { private static final UUID SURVEY_ID = UUID.fromString("cb8accda-6118-4d3b-85a3-149e28960c54"); @Test - public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsSaved() + public void testCaseGroupCorrectlyTransitionsToNewStatus() throws Exception { // Given CaseGroup caseGroup = @@ -65,13 +64,13 @@ public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsS caseGroupService.transitionCaseGroupStatus(caseGroup, categoryName, caseGroup.getPartyId()); // Then - Assert.assertNotNull(caseGroup.getStatusChangeTimestamp()); - Assert.assertEquals(caseGroup.getStatus(), CaseGroupStatus.COMPLETE); + assertNotNull(caseGroup.getStatusChangeTimestamp()); + assertEquals(caseGroup.getStatus(), CaseGroupStatus.COMPLETE); verify(caseGroupRepo).saveAndFlush(caseGroup); } @Test - public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsAudited() + public void testCaseGroupStatusChangeIsCorrectlyAudited() throws Exception { // Given CaseGroup caseGroup = @@ -93,7 +92,6 @@ public void givenCaseGroupStatusWhenCaseGroupStatusTransitionedThenTransitionIsA caseGroupService.transitionCaseGroupStatus(caseGroup, categoryName, caseGroup.getPartyId()); // Then - verify(caseGroupAuditService).updateAuditTable(caseGroup, caseGroup.getPartyId()); } From 3ba32fe3b8607908ec0a43cfb4a281afab12e228 Mon Sep 17 00:00:00 2001 From: SteveScorfield Date: Mon, 5 Feb 2024 14:12:22 +0000 Subject: [PATCH 9/9] Forgot to format --- .../ctp/response/casesvc/service/CaseGroupServiceTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 032460804..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 testCaseGroupCorrectlyTransitionsToNewStatus() - throws Exception { + public void testCaseGroupCorrectlyTransitionsToNewStatus() throws Exception { // Given CaseGroup caseGroup = CaseGroup.builder() @@ -70,8 +69,7 @@ public void testCaseGroupCorrectlyTransitionsToNewStatus() } @Test - public void testCaseGroupStatusChangeIsCorrectlyAudited() - throws Exception { + public void testCaseGroupStatusChangeIsCorrectlyAudited() throws Exception { // Given CaseGroup caseGroup = CaseGroup.builder()