Skip to content

Commit

Permalink
PO-997. Draft Account PATCH to include validated_by_name.
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyHMCTS committed Jan 15, 2025
1 parent 17a0cfe commit 28bd223
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ void testUpdateDraftAccount_success() throws Exception {
.submittedBy("BUUID1")
.validatedDate(testDateTime)
.validatedBy("BUUID1")
.validatedByName("Donald Tester")
.account(validAccountJson())
.accountSnapshot("{\"defendant_name\":\"Company ABC\",\"created_date\":\"2024-10-02T14:30:00Z\","
+ "\"account_type\":\"Fine\",\"submitted_by\":\"BUUID1\","
Expand Down Expand Up @@ -595,6 +596,7 @@ void testUpdateDraftAccount_success() throws Exception {
.andExpect(jsonPath("$.submitted_by").value("BUUID1"))
.andExpect(jsonPath("$.validated_at").value("2024-10-03T14:30:00Z"))
.andExpect(jsonPath("$.validated_by").value("BUUID1"))
.andExpect(jsonPath("$.validated_by_name").value("Donald Tester"))
.andExpect(jsonPath("$.account.defendant.company_name")
.value("company"))
.andExpect(jsonPath("$.account_snapshot.defendant_name").value("Company ABC"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ DraftAccountResponseDto toGetResponseDto(DraftAccountEntity entity) {
.submittedByName(entity.getSubmittedByName())
.validatedDate(toUtcDateTime(entity.getValidatedDate()))
.validatedBy(entity.getValidatedBy())
.validatedByName(entity.getValidatedByName())
.account(entity.getAccount())
.accountSnapshot(entity.getAccountSnapshot())
.accountType(entity.getAccountType())
Expand All @@ -272,6 +273,7 @@ DraftAccountSummaryDto toSummaryDto(DraftAccountEntity entity) {
.submittedBy(entity.getSubmittedBy())
.validatedDate(toUtcDateTime(entity.getValidatedDate()))
.validatedBy(entity.getValidatedBy())
.validatedByName(entity.getValidatedByName())
.accountSnapshot(entity.getAccountSnapshot())
.accountType(entity.getAccountType())
.accountStatus(entity.getAccountStatus())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class DraftAccountResponseDto implements ToJsonString {
@JsonProperty("validated_by")
private String validatedBy;

@JsonProperty("validated_by_name")
private String validatedByName;

@JsonProperty("account")
@JsonRawValue
private String account;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class DraftAccountSummaryDto implements ToJsonString {
@JsonProperty("validated_by")
private String validatedBy;

@JsonProperty("validated_by_name")
private String validatedByName;

@JsonProperty("account_snapshot")
@JsonRawValue
private String accountSnapshot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class UpdateDraftAccountRequestDto implements ToJsonString {
@JsonProperty("validated_by")
private String validatedBy;

@JsonProperty("validated_by_name")
private String validatedByName;

@JsonProperty("business_unit_id")
private Short businessUnitId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class DraftAccountEntity {
@Column(name = "validated_by", length = 20)
private String validatedBy;

// @Column(name = "validate_by_name", length = 100)
// private String validateByName;
@Column(name = "validated_by_name", length = 100)
private String validatedByName;

@Column(name = "account", columnDefinition = "json", nullable = false)
@ColumnTransformer(write = "?::jsonb")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import uk.gov.hmcts.opal.util.JsonPathUtil;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.EnumSet;
Expand Down Expand Up @@ -160,7 +159,9 @@ public DraftAccountEntity updateDraftAccount(Long draftAccountId, UpdateDraftAcc
if (newStatus == DraftAccountStatus.PENDING) {
existingAccount.setValidatedDate(LocalDateTime.now());
existingAccount.setValidatedBy(dto.getValidatedBy());
existingAccount.setValidatedByName(dto.getValidatedByName());
existingAccount.setAccountSnapshot(addSnapshotApprovedDate(existingAccount));
existingAccount.setAccountStatusDate(LocalDateTime.now());
}
// Set the timeline data as received from the front end
existingAccount.setTimelineData(dto.getTimelineData());
Expand All @@ -176,8 +177,7 @@ private String addSnapshotApprovedDate(DraftAccountEntity existingAccount) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = (ObjectNode) mapper.readTree(existingAccount.getAccountSnapshot());

String approvedDate = existingAccount.getValidatedDate()
.atOffset(ZoneOffset.UTC)
String approvedDate = toUtcDateTime(existingAccount.getValidatedDate())
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
rootNode.put("approved_date", approvedDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ DraftAccountResponseDto toGetDto(DraftAccountEntity entity) {
.submittedBy(entity.getSubmittedBy())
.validatedDate(toUtcDateTime(entity.getValidatedDate()))
.validatedBy(entity.getValidatedBy())
.validatedByName(entity.getValidatedByName())
.account(entity.getAccount())
.accountSnapshot(entity.getAccountSnapshot())
.accountType(entity.getAccountType())
Expand All @@ -192,6 +193,7 @@ DraftAccountSummaryDto toSummaryDto(DraftAccountEntity entity) {
.submittedBy(entity.getSubmittedBy())
.validatedDate(toUtcDateTime(entity.getValidatedDate()))
.validatedBy(entity.getValidatedBy())
.validatedByName(entity.getValidatedByName())
.accountSnapshot(entity.getAccountSnapshot())
.accountType(entity.getAccountType())
.accountStatus(entity.getAccountStatus())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ void testUpdateDraftAccount_success() {
.draftAccountId(draftAccountId)
.accountStatus(DraftAccountStatus.PENDING)
.validatedBy("TestValidator")
.validatedByName("Tester McValidator")
.validatedDate(LocalDateTime.now())
.accountSnapshot("{\"created_date\":\"2024-10-01T10:00:00Z\",\"approved_date\":\"2024-10-03T14:30:00Z\"}")
.timelineData("Updated timeline data")
Expand All @@ -364,6 +365,7 @@ void testUpdateDraftAccount_success() {
assertEquals(draftAccountId, result.getDraftAccountId());
assertEquals(DraftAccountStatus.PENDING, result.getAccountStatus());
assertEquals("TestValidator", result.getValidatedBy());
assertEquals("Tester McValidator", result.getValidatedByName());
assertNotNull(result.getValidatedDate());
assertTrue(result.getAccountSnapshot().contains("approved_date"));
assertEquals("Updated timeline data", result.getTimelineData());
Expand Down

0 comments on commit 28bd223

Please sign in to comment.