Skip to content

Commit

Permalink
RAS-940: Questionnaire Completion Rate Information (#288)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
SteveScorfield and ras-rm-pr-bot authored Feb 5, 2024
1 parent a420bf0 commit d4d13dd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions _infra/helm/case/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 d4d13dd

Please sign in to comment.