From 0da2a557e9dd38109b25c8384f68fd351ea4b8d3 Mon Sep 17 00:00:00 2001 From: Daniel Catchpole Date: Mon, 6 Jan 2025 16:04:43 +0000 Subject: [PATCH] DFPL-2639: Move living situation (+ details) to the confidential tab (#5796) Co-authored-by: prabhamuthu15 <78162288+prabhamuthu15@users.noreply.github.com> --- .../uk/gov/hmcts/reform/fpl/model/Child.java | 29 ++++++++++---- .../ConfidentialDetailsServiceTest.java | 39 +++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/Child.java b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/Child.java index b249042401a..4c707bf7661 100644 --- a/service/src/main/java/uk/gov/hmcts/reform/fpl/model/Child.java +++ b/service/src/main/java/uk/gov/hmcts/reform/fpl/model/Child.java @@ -16,6 +16,7 @@ import static java.util.UUID.randomUUID; import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; +import static org.apache.commons.lang3.ObjectUtils.isEmpty; @Data @Builder(toBuilder = true) @@ -49,6 +50,8 @@ public Party toParty() { public Child extractConfidentialDetails() { return this.toBuilder() .party(ChildParty.builder() + .livingSituation(this.party.getLivingSituation()) + .livingSituationDetails(this.party.getLivingSituationDetails()) .firstName(this.party.getFirstName()) .lastName(this.party.getLastName()) .address(this.party.getAddress()) @@ -61,14 +64,24 @@ public Child extractConfidentialDetails() { @Override public Child addConfidentialDetails(Party party) { + ChildParty.ChildPartyBuilder partyBuilder = this.getParty().toBuilder() + .firstName(party.getFirstName()) + .lastName(party.getLastName()) + .address(party.getAddress()) + .telephoneNumber(party.getTelephoneNumber()) + .email(party.getEmail()); + + // Do not nullify old data that may not have been moved over prior to DFPL-2639 + if (!isEmpty(((ChildParty) party).getLivingSituation())) { + partyBuilder.livingSituation(((ChildParty) party).getLivingSituation()); + } + + if (!isEmpty(((ChildParty) party).getLivingSituationDetails())) { + partyBuilder.livingSituationDetails(((ChildParty) party).getLivingSituationDetails()); + } + return this.toBuilder() - .party(this.getParty().toBuilder() - .firstName(party.getFirstName()) - .lastName(party.getLastName()) - .address(party.getAddress()) - .telephoneNumber(party.getTelephoneNumber()) - .email(party.getEmail()) - .build()) + .party(partyBuilder.build()) .build(); } @@ -76,6 +89,8 @@ public Child addConfidentialDetails(Party party) { public Child removeConfidentialDetails() { return this.toBuilder() .party(this.party.toBuilder() + .livingSituation(null) + .livingSituationDetails(null) .address(null) .telephoneNumber(null) .email(null) diff --git a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/ConfidentialDetailsServiceTest.java b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/ConfidentialDetailsServiceTest.java index c17b3ddce90..dbadf430159 100644 --- a/service/src/test/java/uk/gov/hmcts/reform/fpl/service/ConfidentialDetailsServiceTest.java +++ b/service/src/test/java/uk/gov/hmcts/reform/fpl/service/ConfidentialDetailsServiceTest.java @@ -191,6 +191,22 @@ void shouldRemoveConfidentialDetailsFromCaseDetailsWhenNoConfidentialDetails() { assertThat(caseDetails.getData()).isEmpty(); } + @Test + void shouldNotOverrideOldDataIfLivingDetailsNotHiddenYet() { + Element originalChild = childWithRemovedConfidentialFieldsWithLivingSituation(ID); + Element confDetails = childWithConfidentialFieldsAndShowAddressButNoLivingSituation(ID); + CaseData caseData = CaseData.builder() + .children1(List.of(originalChild)) + .confidentialChildren(List.of(confDetails)) + .build(); + + List> updatedChildren = service.prepareCollection(caseData.getAllChildren(), + caseData.getConfidentialChildren(), Child.expandCollection()); + + assertThat(updatedChildren.get(0).getValue().getParty()) + .extracting("livingSituation", "livingSituationDetails") + .containsExactly("Living with parents", "Details here"); + } private ChildParty.ChildPartyBuilder baseChildBuilder(String detailsHidden) { return ChildParty.builder() @@ -205,12 +221,34 @@ private Element childWithRemovedConfidentialFields(UUID id) { .build()); } + private Element childWithRemovedConfidentialFieldsWithLivingSituation(UUID id) { + // Prior to DFPL-2639, living situation + details were not confidential + return element(id, Child.builder() + .party(baseChildBuilder(CONFIDENTIAL) + .livingSituation("Living with parents") + .livingSituationDetails("Details here") + .build()) + .build()); + } + + private Element childWithConfidentialFieldsAndShowAddressButNoLivingSituation(UUID id) { + return element(id, Child.builder() + .party(baseChildBuilder(NO_VALUE) + .email(EmailAddress.builder().email("email@email.com").build()) + .address(Address.builder().addressLine1("Address Line 1").build()) + .telephoneNumber(Telephone.builder().telephoneNumber("01227 831393").build()) + .showAddressInConfidentialTab("Yes") + .build()) + .build()); + } + private Element childWithConfidentialFields(UUID id, String detailsHidden) { return element(id, Child.builder() .party(baseChildBuilder(detailsHidden) .email(EmailAddress.builder().email("email@email.com").build()) .address(Address.builder().addressLine1("Address Line 1").build()) .telephoneNumber(Telephone.builder().telephoneNumber("01227 831393").build()) + .livingSituation("Living in a refuge") .build()) .build()); } @@ -222,6 +260,7 @@ private Element childWithConfidentialFieldsAndShowAddress() { .address(Address.builder().addressLine1("Address Line 1").build()) .telephoneNumber(Telephone.builder().telephoneNumber("01227 831393").build()) .showAddressInConfidentialTab("Yes") + .livingSituation("Living in a refuge") .build()) .build()); }