Skip to content

Commit

Permalink
Merge branch 'main' into complete-to-not-started
Browse files Browse the repository at this point in the history
  • Loading branch information
arroyoAle authored Feb 6, 2024
2 parents 72d64c2 + d4d13dd commit e18b4bb
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions _infra/helm/case/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ version: 12.0.20
# 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.20

Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/database/changelog-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,7 @@ databaseChangeLog:
file: database/changes/release-34/changelog.yml

- include:
file: database/changes/release-35/changelog.yml
file: database/changes/release-35/changelog.yml

- include:
file: database/changes/release-36/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE ONLY casesvc.casegroup
ADD status_change_timestamp timestamp with time zone;
11 changes: 11 additions & 0 deletions src/main/resources/database/changes/release-36/changelog.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit e18b4bb

Please sign in to comment.