From a02d3c5a47e4bd2450cebb8d0a7c9c1a1452cb4d Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 09:33:30 +0100 Subject: [PATCH 01/10] Add NotificationRequestBuilder --- .../config/CourtDetails.java | 1 + .../helper/ConsentedApplicationHelper.java | 2 +- .../AbstractNotificationRequestMapper.java | 20 + .../NotificationRequestBuilder.java | 347 ++++++++++++++++++ .../NotificationRequestBuilderFactory.java | 23 ++ .../notification/NotificationRequest.java | 2 + .../mapper/CourtDetailsMapperTest.java | 4 +- ...NotificationRequestBuilderFactoryTest.java | 23 ++ .../NotificationRequestBuilderTest.java | 272 ++++++++++++++ .../domain/NotificationRequestTest.java | 5 +- 10 files changed, 696 insertions(+), 3 deletions(-) create mode 100644 src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/AbstractNotificationRequestMapper.java create mode 100644 src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilder.java create mode 100644 src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactory.java create mode 100644 src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactoryTest.java create mode 100644 src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderTest.java diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetails.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetails.java index 133289be9e1..d0b266425ee 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetails.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetails.java @@ -14,4 +14,5 @@ public class CourtDetails { private String courtAddress; private String phoneNumber; private String email; + private String emailReplyToId; } diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/helper/ConsentedApplicationHelper.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/helper/ConsentedApplicationHelper.java index f9bac92f21d..685400e5163 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/helper/ConsentedApplicationHelper.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/helper/ConsentedApplicationHelper.java @@ -59,7 +59,7 @@ public void setConsentVariationOrderLabelField(Map caseData) { } } - public Boolean isVariationOrder(final FinremCaseData caseData) { + public boolean isVariationOrder(final FinremCaseData caseData) { List natureOfApplicationList = caseData.getNatureApplicationWrapper().getNatureOfApplication2(); log.info("Nature list {}", natureOfApplicationList); return (!CollectionUtils.isEmpty(natureOfApplicationList) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/AbstractNotificationRequestMapper.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/AbstractNotificationRequestMapper.java new file mode 100644 index 00000000000..50b7bf08eb4 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/AbstractNotificationRequestMapper.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +class AbstractNotificationRequestMapper { + + private final NotificationRequestBuilderFactory builderFactory; + + /** + * Creates a new instance of {@link NotificationRequestBuilder} to build + * {@link uk.gov.hmcts.reform.finrem.caseorchestration.model.notification.NotificationRequest}. + * @return a new instance of {@link NotificationRequestBuilder} + */ + protected NotificationRequestBuilder notificationRequestBuilder() { + return builderFactory.newInstance(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilder.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilder.java new file mode 100644 index 00000000000..2236fdddf25 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilder.java @@ -0,0 +1,347 @@ +package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest; + +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.finrem.caseorchestration.config.CourtDetailsConfiguration; +import uk.gov.hmcts.reform.finrem.caseorchestration.helper.ConsentedApplicationHelper; +import uk.gov.hmcts.reform.finrem.caseorchestration.helper.CourtHelper; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CaseType; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseData; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseDetails; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.notification.NotificationRequest; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.wrapper.SolicitorCaseDataKeysWrapper; +import uk.gov.hmcts.reform.finrem.caseorchestration.notifications.service.EmailService; + +import java.util.Objects; +import java.util.Optional; + +import static uk.gov.hmcts.reform.finrem.caseorchestration.OrchestrationConstants.CTSC_OPENING_HOURS; + +@Component +@Scope(value = "prototype") +@RequiredArgsConstructor +public class NotificationRequestBuilder { + + private final CourtDetailsConfiguration courtDetailsConfiguration; + private final ConsentedApplicationHelper consentedApplicationHelper; + + private String caseReferenceNumber; + private String solicitorReferenceNumber; + private String divorceCaseNumber; + private String name; + private String notificationEmail; + private String selectedCourt; + private String caseType; + private String generalEmailBody; + private String phoneOpeningHours; + private String caseOrderType; + private String camelCaseOrderType; + private String generalApplicationRejectionReason; + private String applicantName; + private String respondentName; + private String barristerReferenceNumber; + private String hearingType; + private String intervenerSolicitorReferenceNumber; + private String intervenerFullName; + private String intervenerSolicitorFirm; + private byte[] documentContents; + private Boolean isNotDigital; + private String hearingDate; + private String judgeName; + private String oldestDraftOrderDate; + private String judgeFeedback; + private String documentName; + private String contactCourtName; + private String contactCourtEmail; + private String emailReplyToId; + + /** + * Sets default values for the NotificationRequestBuilder based on the provided case details. + * This method sets the following fields: + *
    + *
  • applicantName
  • + *
  • camelCaseOrderType
  • + *
  • caseOrderType
  • + *
  • caseReferenceNumber
  • + *
  • caseType
  • + *
  • contactCourtName
  • + *
  • contactCourtEmail
  • + *
  • divorceCaseNumber
  • + *
  • emailReplyToId
  • + *
  • phoneOpeningHours
  • + *
  • respondentName
  • + *
  • selectedCourt
  • + *
+ * + * @param caseDetails the case details + * @return the NotificationRequestBuilder instance with default values set + */ + public NotificationRequestBuilder withCaseDefaults(FinremCaseDetails caseDetails) { + FinremCaseData caseData = caseDetails.getData(); + + caseReferenceNumber = String.valueOf(caseDetails.getId()); + applicantName = caseData.getFullApplicantName(); + caseType = CaseType.CONTESTED.equals(caseDetails.getCaseType()) ? EmailService.CONTESTED : EmailService.CONSENTED; + divorceCaseNumber = caseData.getDivorceCaseNumber(); + phoneOpeningHours = CTSC_OPENING_HOURS; + addSelectedCourtDetails(caseData); + + if (caseData.isConsentedApplication()) { + setConsentedDefaults(caseData); + } + + if (caseDetails.getData().isContestedApplication()) { + setContestedDefaults(caseDetails); + } + + return this; + } + + private void addSelectedCourtDetails(FinremCaseData caseData) { + Optional.ofNullable(caseData.getSelectedAllocatedCourt()) + .map(courtDetailsConfiguration.getCourts()::get) + .ifPresent(court -> { + contactCourtName = court.getCourtName(); + contactCourtEmail = court.getEmail(); + emailReplyToId = court.getEmailReplyToId(); + }); + } + + private void setContestedDefaults(FinremCaseDetails caseDetails) { + respondentName = caseDetails.getData().getRespondentFullName(); + selectedCourt = CourtHelper.getSelectedFrc(caseDetails); + } + + private void setConsentedDefaults(FinremCaseData caseData) { + respondentName = caseData.getFullRespondentNameConsented(); + + if (consentedApplicationHelper.isVariationOrder(caseData)) { + caseOrderType = "variation"; + } else { + caseOrderType = "consent"; + } + camelCaseOrderType = StringUtils.capitalize(caseOrderType); + } + + /** + * Sets the notification email destination to the court's email based on the selected allocated court in the case details. + * + * @param caseDetails the case details + * @return the NotificationRequestBuilder instance + */ + public NotificationRequestBuilder withCourtAsEmailDestination(FinremCaseDetails caseDetails) { + String selectedAllocatedCourt = caseDetails.getData().getSelectedAllocatedCourt(); + notificationEmail = courtDetailsConfiguration.getCourts().get(selectedAllocatedCourt).getEmail(); + + return this; + } + + /** + * Sets solicitor-related fields in the NotificationRequestBuilder using the provided solicitor case data. + * This method sets the following fields: + *
    + *
  • isNotDigital
  • + *
  • name
  • + *
  • notificationEmail
  • + *
  • solicitorReferenceNumber
  • + *
+ * + * @param solicitorCaseData the solicitor case data wrapper + * @return the NotificationRequestBuilder instance with solicitor data set + */ + public NotificationRequestBuilder withSolicitorCaseData(SolicitorCaseDataKeysWrapper solicitorCaseData) { + solicitorReferenceNumber = Objects.toString(solicitorCaseData.getSolicitorReferenceKey(), ""); + name = Objects.toString(solicitorCaseData.getSolicitorNameKey(), ""); + notificationEmail = Objects.toString(solicitorCaseData.getSolicitorEmailKey(), ""); + isNotDigital = solicitorCaseData.getSolicitorIsNotDigitalKey(); + + return this; + } + + /** + * Builds a NotificationRequest object using the values set in the builder. + * + * @return a NotificationRequest + */ + public NotificationRequest build() { + NotificationRequest notificationRequest = new NotificationRequest(); + notificationRequest.setCaseReferenceNumber(caseReferenceNumber); + notificationRequest.setSolicitorReferenceNumber(solicitorReferenceNumber); + notificationRequest.setDivorceCaseNumber(divorceCaseNumber); + notificationRequest.setName(name); + notificationRequest.setNotificationEmail(notificationEmail); + notificationRequest.setSelectedCourt(selectedCourt); + notificationRequest.setCaseType(caseType); + notificationRequest.setGeneralEmailBody(generalEmailBody); + notificationRequest.setPhoneOpeningHours(phoneOpeningHours); + notificationRequest.setCaseOrderType(caseOrderType); + notificationRequest.setCamelCaseOrderType(camelCaseOrderType); + notificationRequest.setGeneralApplicationRejectionReason(generalApplicationRejectionReason); + notificationRequest.setApplicantName(applicantName); + notificationRequest.setRespondentName(respondentName); + notificationRequest.setBarristerReferenceNumber(barristerReferenceNumber); + notificationRequest.setHearingType(hearingType); + notificationRequest.setIntervenerSolicitorReferenceNumber(intervenerSolicitorReferenceNumber); + notificationRequest.setIntervenerFullName(intervenerFullName); + notificationRequest.setIntervenerSolicitorFirm(intervenerSolicitorFirm); + notificationRequest.setDocumentContents(documentContents); + notificationRequest.setIsNotDigital(isNotDigital); + notificationRequest.setHearingDate(hearingDate); + notificationRequest.setJudgeName(judgeName); + notificationRequest.setOldestDraftOrderDate(oldestDraftOrderDate); + notificationRequest.setJudgeFeedback(judgeFeedback); + notificationRequest.setDocumentName(documentName); + notificationRequest.setContactCourtName(contactCourtName); + notificationRequest.setContactCourtEmail(contactCourtEmail); + notificationRequest.setEmailReplyToId(emailReplyToId); + + return notificationRequest; + } + + public NotificationRequestBuilder caseReferenceNumber(String caseReferenceNumber) { + this.caseReferenceNumber = caseReferenceNumber; + return this; + } + + public NotificationRequestBuilder solicitorReferenceNumber(String solicitorReferenceNumber) { + this.solicitorReferenceNumber = solicitorReferenceNumber; + return this; + } + + public NotificationRequestBuilder divorceCaseNumber(String divorceCaseNumber) { + this.divorceCaseNumber = divorceCaseNumber; + return this; + } + + public NotificationRequestBuilder name(String name) { + this.name = name; + return this; + } + + public NotificationRequestBuilder notificationEmail(String notificationEmail) { + this.notificationEmail = notificationEmail; + return this; + } + + public NotificationRequestBuilder selectedCourt(String selectedCourt) { + this.selectedCourt = selectedCourt; + return this; + } + + public NotificationRequestBuilder caseType(String caseType) { + this.caseType = caseType; + return this; + } + + public NotificationRequestBuilder generalEmailBody(String generalEmailBody) { + this.generalEmailBody = generalEmailBody; + return this; + } + + public NotificationRequestBuilder phoneOpeningHours(String phoneOpeningHours) { + this.phoneOpeningHours = phoneOpeningHours; + return this; + } + + public NotificationRequestBuilder caseOrderType(String caseOrderType) { + this.caseOrderType = caseOrderType; + return this; + } + + public NotificationRequestBuilder camelCaseOrderType(String camelCaseOrderType) { + this.camelCaseOrderType = camelCaseOrderType; + return this; + } + + public NotificationRequestBuilder generalApplicationRejectionReason(String generalApplicationRejectionReason) { + this.generalApplicationRejectionReason = generalApplicationRejectionReason; + return this; + } + + public NotificationRequestBuilder applicantName(String applicantName) { + this.applicantName = applicantName; + return this; + } + + public NotificationRequestBuilder respondentName(String respondentName) { + this.respondentName = respondentName; + return this; + } + + public NotificationRequestBuilder barristerReferenceNumber(String barristerReferenceNumber) { + this.barristerReferenceNumber = barristerReferenceNumber; + return this; + } + + public NotificationRequestBuilder hearingType(String hearingType) { + this.hearingType = hearingType; + return this; + } + + public NotificationRequestBuilder intervenerSolicitorReferenceNumber(String intervenerSolicitorReferenceNumber) { + this.intervenerSolicitorReferenceNumber = intervenerSolicitorReferenceNumber; + return this; + } + + public NotificationRequestBuilder intervenerFullName(String intervenerFullName) { + this.intervenerFullName = intervenerFullName; + return this; + } + + public NotificationRequestBuilder intervenerSolicitorFirm(String intervenerSolicitorFirm) { + this.intervenerSolicitorFirm = intervenerSolicitorFirm; + return this; + } + + public NotificationRequestBuilder documentContents(byte[] documentContents) { + this.documentContents = documentContents; + return this; + } + + public NotificationRequestBuilder isNotDigital(Boolean isNotDigital) { + this.isNotDigital = isNotDigital; + return this; + } + + public NotificationRequestBuilder hearingDate(String hearingDate) { + this.hearingDate = hearingDate; + return this; + } + + public NotificationRequestBuilder judgeName(String judgeName) { + this.judgeName = judgeName; + return this; + } + + public NotificationRequestBuilder oldestDraftOrderDate(String oldestDraftOrderDate) { + this.oldestDraftOrderDate = oldestDraftOrderDate; + return this; + } + + public NotificationRequestBuilder judgeFeedback(String judgeFeedback) { + this.judgeFeedback = judgeFeedback; + return this; + } + + public NotificationRequestBuilder documentName(String documentName) { + this.documentName = documentName; + return this; + } + + public NotificationRequestBuilder contactCourtName(String contactCourtName) { + this.contactCourtName = contactCourtName; + return this; + } + + public NotificationRequestBuilder contactCourtEmail(String contactCourtEmail) { + this.contactCourtEmail = contactCourtEmail; + return this; + } + + public NotificationRequestBuilder emailReplyToId(String emailReplyToId) { + this.emailReplyToId = emailReplyToId; + return this; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactory.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactory.java new file mode 100644 index 00000000000..acfe7d6dba7 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactory.java @@ -0,0 +1,23 @@ +package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest; + + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class NotificationRequestBuilderFactory { + + private final ObjectProvider builderProvider; + + /** + * Creates a new instance of {@link NotificationRequestBuilder} to build + * {@link uk.gov.hmcts.reform.finrem.caseorchestration.model.notification.NotificationRequest}. + * This method is used to ensure that each NotificationRequest can be built independently without side effects. + * @return a new instance of {@link NotificationRequestBuilder} + */ + public NotificationRequestBuilder newInstance() { + return builderProvider.getObject(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/model/notification/NotificationRequest.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/model/notification/NotificationRequest.java index 1b66e6fecc7..4ee2f0cdb0f 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/model/notification/NotificationRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/model/notification/NotificationRequest.java @@ -65,5 +65,7 @@ public class NotificationRequest { private String judgeFeedback; @JsonProperty("documentName") private String documentName; + private String contactCourtName; + private String contactCourtEmail; private String emailReplyToId; } diff --git a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/CourtDetailsMapperTest.java b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/CourtDetailsMapperTest.java index 41dff06be77..2218cd93dee 100644 --- a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/CourtDetailsMapperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/CourtDetailsMapperTest.java @@ -238,7 +238,8 @@ void givenValidCourtField_whenConvertToFrcCourtDetails_thenReturnExpectedCourtDe // Mocking the court details map when(courtDetailsConfiguration.getCourts()).thenReturn(Map.of( "FR_s_CFCList_2", new CourtDetails("Croydon County Court And Family Court", - "Croydon County Court, Altyre Road, Croydon, CR9 5AB", "0300 123 5577", "FRCLondon@justice.gov.uk") + "Croydon County Court, Altyre Road, Croydon, CR9 5AB", "0300 123 5577", + "FRCLondon@justice.gov.uk", "42b18e70-18e8-4290-bb85-9c5254548345") )); // Setting up the test data @@ -263,6 +264,7 @@ void givenValidCourtField_whenConvertToFrcCourtDetails_thenReturnExpectedCourtDe assertEquals("Croydon County Court, Altyre Road, Croydon, CR9 5AB", courtDetails.getCourtAddress()); assertEquals("FRCLondon@justice.gov.uk", courtDetails.getEmail()); assertEquals("0300 123 5577", courtDetails.getPhoneNumber()); + assertEquals("42b18e70-18e8-4290-bb85-9c5254548345", courtDetails.getEmailReplyToId()); } @Test diff --git a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactoryTest.java b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactoryTest.java new file mode 100644 index 00000000000..74d1357c08e --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactoryTest.java @@ -0,0 +1,23 @@ +package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.ObjectProvider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class NotificationsRequestBuilderFactoryTest { + + @Test + void testNewInstance() { + @SuppressWarnings("unchecked") + ObjectProvider builderProvider = mock(ObjectProvider.class); + when(builderProvider.getObject()).thenReturn(mock(NotificationRequestBuilder.class)); + NotificationRequestBuilderFactory factory = new NotificationRequestBuilderFactory(builderProvider); + + NotificationRequestBuilder builder = factory.newInstance(); + + assertThat(builder).isInstanceOf(NotificationRequestBuilder.class); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderTest.java b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderTest.java new file mode 100644 index 00000000000..93c991f15d5 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderTest.java @@ -0,0 +1,272 @@ +package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.finrem.caseorchestration.config.CourtDetails; +import uk.gov.hmcts.reform.finrem.caseorchestration.config.CourtDetailsConfiguration; +import uk.gov.hmcts.reform.finrem.caseorchestration.helper.ConsentedApplicationHelper; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CaseType; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseData; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseDetails; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.NorthWalesCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.Region; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.wrapper.AllocatedRegionWrapper; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.wrapper.ContactDetailsWrapper; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.wrapper.DefaultCourtListWrapper; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.wrapper.RegionWrapper; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.notification.NotificationRequest; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.wrapper.SolicitorCaseDataKeysWrapper; +import uk.gov.hmcts.reform.finrem.caseorchestration.notifications.service.EmailService; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.finrem.caseorchestration.OrchestrationConstants.CTSC_OPENING_HOURS; +import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.CAERNARFON; +import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.RegionWalesFrc.NORTH_WALES; + +@ExtendWith(MockitoExtension.class) +class NotificationRequestBuilderTest { + + @InjectMocks + private NotificationRequestBuilder builder; + @Mock + private CourtDetailsConfiguration courtDetailsConfiguration; + @Mock + private ConsentedApplicationHelper consentedApplicationHelper; + + @Test + void givenConsentedCase_whenWithCaseDefaults_thenCaseDetailsPopulated() { + mockCourtDetailsConfiguration(); + mockConsentedVariationOrder(false); + FinremCaseDetails caseDetails = createConsentedCase(); + + NotificationRequest notificationRequest = builder + .withCaseDefaults(caseDetails) + .build(); + + assertThat(notificationRequest.getApplicantName()).isEqualTo("Doris Duck"); + assertThat(notificationRequest.getCamelCaseOrderType()).isEqualTo("Consent"); + assertThat(notificationRequest.getCaseOrderType()).isEqualTo("consent"); + assertThat(notificationRequest.getCaseReferenceNumber()).isEqualTo("3456865498462385"); + assertThat(notificationRequest.getCaseType()).isEqualTo(EmailService.CONSENTED); + assertThat(notificationRequest.getContactCourtName()).isEqualTo("Test Court"); + assertThat(notificationRequest.getContactCourtEmail()).isEqualTo("test.court@test.com"); + assertThat(notificationRequest.getDivorceCaseNumber()).isEqualTo("3657-4535-2355-7545"); + assertThat(notificationRequest.getEmailReplyToId()).isEqualTo("3f6a1cd4-812a-48d6-8fd9-067bf4884fd2"); + assertThat(notificationRequest.getPhoneOpeningHours()).isEqualTo(CTSC_OPENING_HOURS); + assertThat(notificationRequest.getRespondentName()).isEqualTo("Davey Duck"); + assertThat(notificationRequest.getSelectedCourt()).isNull(); + } + + @Test + void givenConsentedVariationOrderCase_whenWithCaseDefaults_thenCaseDetailsPopulated() { + mockCourtDetailsConfiguration(); + mockConsentedVariationOrder(true); + FinremCaseDetails caseDetails = createConsentedCase(); + + NotificationRequest notificationRequest = builder + .withCaseDefaults(caseDetails) + .build(); + + assertThat(notificationRequest.getApplicantName()).isEqualTo("Doris Duck"); + assertThat(notificationRequest.getCamelCaseOrderType()).isEqualTo("Variation"); + assertThat(notificationRequest.getCaseOrderType()).isEqualTo("variation"); + assertThat(notificationRequest.getCaseReferenceNumber()).isEqualTo("3456865498462385"); + assertThat(notificationRequest.getCaseType()).isEqualTo(EmailService.CONSENTED); + assertThat(notificationRequest.getContactCourtName()).isEqualTo("Test Court"); + assertThat(notificationRequest.getContactCourtEmail()).isEqualTo("test.court@test.com"); + assertThat(notificationRequest.getDivorceCaseNumber()).isEqualTo("3657-4535-2355-7545"); + assertThat(notificationRequest.getEmailReplyToId()).isEqualTo("3f6a1cd4-812a-48d6-8fd9-067bf4884fd2"); + assertThat(notificationRequest.getPhoneOpeningHours()).isEqualTo(CTSC_OPENING_HOURS); + assertThat(notificationRequest.getRespondentName()).isEqualTo("Davey Duck"); + assertThat(notificationRequest.getSelectedCourt()).isNull(); + } + + @Test + void givenContestedCase_whenWithDefaults_thenCaseDetailsPopulated() { + mockCourtDetailsConfiguration(); + FinremCaseDetails caseDetails = createContestedCase(); + + NotificationRequest notificationRequest = builder + .withCaseDefaults(caseDetails) + .build(); + + assertThat(notificationRequest.getApplicantName()).isEqualTo("Doris Duck"); + assertThat(notificationRequest.getCamelCaseOrderType()).isNull(); + assertThat(notificationRequest.getCaseOrderType()).isNull(); + assertThat(notificationRequest.getCaseReferenceNumber()).isEqualTo("3456865498462385"); + assertThat(notificationRequest.getCaseType()).isEqualTo(EmailService.CONTESTED); + assertThat(notificationRequest.getContactCourtName()).isEqualTo("Test Court"); + assertThat(notificationRequest.getContactCourtEmail()).isEqualTo("test.court@test.com"); + assertThat(notificationRequest.getDivorceCaseNumber()).isEqualTo("3657-4535-2355-7545"); + assertThat(notificationRequest.getEmailReplyToId()).isEqualTo("3f6a1cd4-812a-48d6-8fd9-067bf4884fd2"); + assertThat(notificationRequest.getPhoneOpeningHours()).isEqualTo(CTSC_OPENING_HOURS); + assertThat(notificationRequest.getRespondentName()).isEqualTo("Davey Duck"); + assertThat(notificationRequest.getSelectedCourt()).isEqualTo(NORTH_WALES.getValue()); + } + + @Test + void givenAllPropertiesSet_whenBuild_thenAllPropertiesPopulated() { + byte[] documentContents = {1, 2, 3}; + NotificationRequest notificationRequest = builder + .caseReferenceNumber("123456789") + .solicitorReferenceNumber("SOL123") + .divorceCaseNumber("DIV123") + .name("John Doe") + .notificationEmail("john.doe@example.com") + .selectedCourt("London Court") + .caseType("consented") + .generalEmailBody("Email body") + .phoneOpeningHours("9-5") + .caseOrderType("Consent Order") + .camelCaseOrderType("ConsentOrder") + .generalApplicationRejectionReason("Missing docs") + .applicantName("Jane Smith") + .respondentName("Richard Roe") + .barristerReferenceNumber("BAR123") + .hearingType("Directions") + .intervenerSolicitorReferenceNumber("INT123") + .intervenerFullName("Intervener Name") + .intervenerSolicitorFirm("Intervener Firm") + .documentContents(documentContents) + .isNotDigital(Boolean.TRUE) + .hearingDate("2024-06-01") + .judgeName("Judge Judy") + .oldestDraftOrderDate("2024-05-01") + .judgeFeedback("Approved") + .documentName("Order.pdf") + .contactCourtEmail("test.court@test.net") + .contactCourtName("Local Court") + .emailReplyToId("909cb736-eab0-46ac-a7f0-d28d89c8950c") + .build(); + + // Assert all fields are non-null + String[] fieldNames = Arrays.stream(NotificationRequest.class.getDeclaredFields()) + .map(Field::getName) + .toArray(String[]::new); + + assertThat(notificationRequest) + .extracting(fieldNames) + .doesNotContainNull(); + + // For array fields, check content equality + assertThat(notificationRequest.getDocumentContents()).isEqualTo(documentContents); + } + + @Test + void givenSolicitorData_whenWithSolicitorCaseData_thenSolicitorDetailsPopulated() { + SolicitorCaseDataKeysWrapper solicitorCaseData = SolicitorCaseDataKeysWrapper.builder() + .solicitorEmailKey("sol@test.com") + .solicitorNameKey("Stella Artois") + .solicitorReferenceKey("DGEE34343") + .solicitorIsNotDigitalKey(true) + .build(); + + NotificationRequest notificationRequest = builder + .withSolicitorCaseData(solicitorCaseData) + .build(); + + assertThat(notificationRequest.getName()).isEqualTo("Stella Artois"); + assertThat(notificationRequest.getNotificationEmail()).isEqualTo("sol@test.com"); + assertThat(notificationRequest.getSolicitorReferenceNumber()).isEqualTo("DGEE34343"); + assertThat(notificationRequest.getIsNotDigital()).isTrue(); + } + + @Test + void givenMissingSolicitorData_whenWithSolicitorCaseData_thenSolicitorDetailsNotPopulated() { + SolicitorCaseDataKeysWrapper solicitorCaseData = SolicitorCaseDataKeysWrapper.builder() + .build(); + + NotificationRequest notificationRequest = builder + .withSolicitorCaseData(solicitorCaseData) + .build(); + + assertThat(notificationRequest.getName()).isEmpty(); + assertThat(notificationRequest.getNotificationEmail()).isEmpty(); + assertThat(notificationRequest.getSolicitorReferenceNumber()).isEmpty(); + assertThat(notificationRequest.getIsNotDigital()).isNull(); + } + + @Test + void givenCase_whenWithCourtAsEmailDestination_thenNotificationEmailPopulated() { + mockCourtDetailsConfiguration(); + FinremCaseDetails caseDetails = createContestedCase(); + + NotificationRequest notificationRequest = builder + .withCourtAsEmailDestination(caseDetails) + .build(); + + assertThat(notificationRequest.getNotificationEmail()).isEqualTo("test.court@test.com"); + } + + private FinremCaseDetails createConsentedCase() { + FinremCaseData caseData = FinremCaseData.builder() + .regionWrapper(createRegionWrapper()) + .contactDetailsWrapper(ContactDetailsWrapper.builder() + .applicantFmName("Doris") + .applicantLname("Duck") + .appRespondentFmName("Davey") + .appRespondentLName("Duck") + .build()) + .ccdCaseType(CaseType.CONSENTED) + .divorceCaseNumber("3657-4535-2355-7545") + .build(); + return FinremCaseDetails.builder() + .id(3456865498462385L) + .caseType(CaseType.CONSENTED) + .data(caseData) + .build(); + } + + private FinremCaseDetails createContestedCase() { + FinremCaseData caseData = FinremCaseData.builder() + .regionWrapper(createRegionWrapper()) + .contactDetailsWrapper(ContactDetailsWrapper.builder() + .applicantFmName("Doris") + .applicantLname("Duck") + .respondentFmName("Davey") + .respondentLname("Duck") + .build()) + .ccdCaseType(CaseType.CONTESTED) + .divorceCaseNumber("3657-4535-2355-7545") + .build(); + return FinremCaseDetails.builder() + .id(3456865498462385L) + .caseType(CaseType.CONTESTED) + .data(caseData) + .build(); + } + + private RegionWrapper createRegionWrapper() { + return RegionWrapper.builder() + .allocatedRegionWrapper(AllocatedRegionWrapper.builder() + .regionList(Region.WALES) + .walesFrcList(NORTH_WALES) + .courtListWrapper(DefaultCourtListWrapper.builder() + .northWalesCourtList(NorthWalesCourt.CAERNARFON) + .build()) + .build()) + .build(); + } + + private void mockCourtDetailsConfiguration() { + CourtDetails courtDetails = CourtDetails.builder() + .courtName("Test Court") + .email("test.court@test.com") + .emailReplyToId("3f6a1cd4-812a-48d6-8fd9-067bf4884fd2") + .build(); + when(courtDetailsConfiguration.getCourts()).thenReturn(Map.of(CAERNARFON, courtDetails)); + } + + private void mockConsentedVariationOrder(boolean variationOrder) { + when(consentedApplicationHelper.isVariationOrder(any(FinremCaseData.class))).thenReturn(variationOrder); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/domain/NotificationRequestTest.java b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/domain/NotificationRequestTest.java index 0f5a43d1a04..afb899bb544 100644 --- a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/domain/NotificationRequestTest.java +++ b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/domain/NotificationRequestTest.java @@ -22,7 +22,8 @@ void shouldGetHwfNotificationRequestData() { "nottingham", CONTESTED, "body", PHONE_OPENING_HOURS, "consent", "Consent", "rejectedReason", "app", "res", "1234567890", "", "", "", "", null, null, - "2024-01-01", "judgeName", "2024-01-01", "Feedback by Mr. judge", "ABC.doc", emailReplyToId); + "2024-01-01", "judgeName", "2024-01-01", "Feedback by Mr. judge", "ABC.doc", + "A Court Name", "test@test.com", emailReplyToId); assertEquals("123456", underTest.getCaseReferenceNumber()); assertEquals("45623", underTest.getSolicitorReferenceNumber()); assertEquals("D123", underTest.getDivorceCaseNumber()); @@ -41,6 +42,8 @@ void shouldGetHwfNotificationRequestData() { assertEquals("2024-01-01", underTest.getOldestDraftOrderDate()); assertEquals("Feedback by Mr. judge", underTest.getJudgeFeedback()); assertEquals("ABC.doc", underTest.getDocumentName()); + assertEquals("A Court Name", underTest.getContactCourtName()); + assertEquals("test@test.com", underTest.getContactCourtEmail()); assertEquals(emailReplyToId, underTest.getEmailReplyToId()); } From b380c3427ff7ab36b21c6b9340f80cf2e276530c Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 09:37:16 +0100 Subject: [PATCH 02/10] Minor cleanup --- .../mapper/notificationrequest/NotificationRequestBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilder.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilder.java index 2236fdddf25..0686b282712 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilder.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilder.java @@ -92,7 +92,7 @@ public NotificationRequestBuilder withCaseDefaults(FinremCaseDetails caseDetails setConsentedDefaults(caseData); } - if (caseDetails.getData().isContestedApplication()) { + if (caseData.isContestedApplication()) { setContestedDefaults(caseDetails); } From a3ad5c0da2184308e2406a965e7ee86db0c282bf Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 09:53:48 +0100 Subject: [PATCH 03/10] Checkstyle errors --- .../notificationrequest/NotificationRequestBuilderFactory.java | 1 - .../NotificationRequestBuilderFactoryTest.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactory.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactory.java index acfe7d6dba7..cf92b9536ba 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactory.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactory.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest; - import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.ObjectProvider; import org.springframework.stereotype.Service; diff --git a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactoryTest.java b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactoryTest.java index 74d1357c08e..02f38e1c692 100644 --- a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactoryTest.java +++ b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/NotificationRequestBuilderFactoryTest.java @@ -7,7 +7,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -class NotificationsRequestBuilderFactoryTest { +class NotificationRequestBuilderFactoryTest { @Test void testNewInstance() { From 5dd6b9ba1c2ee037cab41b7ed12ef408aca513c7 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 14:07:56 +0100 Subject: [PATCH 04/10] Use NotificationRequestBuilder for General Emails --- .../FinremNotificationRequestMapper.java | 24 ++++++++++---- .../notifications/service/EmailService.java | 14 ++++++++- .../service/NotificationService.java | 1 - .../FinremNotificationRequestMapperTest.java | 26 ++++++++++++++-- .../service/EmailServiceTest.java | 31 ++++++++++++++++--- 5 files changed, 80 insertions(+), 16 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/FinremNotificationRequestMapper.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/FinremNotificationRequestMapper.java index 812e8185a08..269f5cb145c 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/FinremNotificationRequestMapper.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/FinremNotificationRequestMapper.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.finrem.caseorchestration.mapper.notificationrequest; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.finrem.caseorchestration.helper.ConsentedApplicationHelper; @@ -29,14 +28,20 @@ @Service @Slf4j -@RequiredArgsConstructor -public class FinremNotificationRequestMapper { +public class FinremNotificationRequestMapper extends AbstractNotificationRequestMapper { private static final String RESPONDENT = "Respondent"; private static final String CONSENTED = "consented"; private static final String CONTESTED = "contested"; + private static final String EMPTY_STRING = ""; + private final ConsentedApplicationHelper consentedApplicationHelper; - protected static final String EMPTY_STRING = ""; + + public FinremNotificationRequestMapper(NotificationRequestBuilderFactory notificationRequestBuilderFactory, + ConsentedApplicationHelper consentedApplicationHelper) { + super(notificationRequestBuilderFactory); + this.consentedApplicationHelper = consentedApplicationHelper; + } public NotificationRequest getNotificationRequestForRespondentSolicitor(FinremCaseDetails caseDetails) { return buildNotificationRequest(caseDetails, getRespondentSolicitorCaseData(caseDetails.getData())); @@ -201,8 +206,15 @@ public NotificationRequest buildNotificationRequest(FinremCaseDetails caseDetail * @return the populated notification request */ public NotificationRequest getNotificationRequestForGeneralEmail(FinremCaseDetails caseDetails) { - SolicitorCaseDataKeysWrapper caseDataKeysWrapper = getApplicantSolicitorCaseData(caseDetails.getData()); - return buildNotificationRequest(caseDetails, caseDataKeysWrapper); + FinremCaseData caseData = caseDetails.getData(); + SolicitorCaseDataKeysWrapper solicitorCaseData = getApplicantSolicitorCaseData(caseData); + + return notificationRequestBuilder() + .withCaseDefaults(caseDetails) + .withSolicitorCaseData(solicitorCaseData) + .notificationEmail(caseData.getGeneralEmailWrapper().getGeneralEmailRecipient()) + .generalEmailBody(caseData.getGeneralEmailWrapper().getGeneralEmailBody()) + .build(); } private void setCaseOrderType(NotificationRequest notificationRequest, FinremCaseData caseData) { diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java index a611b7b0530..e54de3b905f 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java @@ -90,7 +90,11 @@ protected Map buildTemplateVars(NotificationRequest notification templateVars.put("respondentName", notificationRequest.getRespondentName()); templateVars.put("hearingType", notificationRequest.getHearingType()); - //contested emails notifications require the court information, consented does not + // Contested emails notifications require the court information, consented does not + // This block of code can be removed once all NotificationRequests are updated + // to populate contactCourtName and contactCourtEmail. + // The code block would only be required if emails needed to show the FRC email address + // rather than the court email address if ((CONTESTED.equals(notificationRequest.getCaseType()) || CONSENTED_LIST_FOR_HEARING.equals(templateName)) && !isEmpty(notificationRequest.getSelectedCourt())) { Map courtDetails = contestedContactEmails.get(notificationRequest.getSelectedCourt()); @@ -99,6 +103,14 @@ protected Map buildTemplateVars(NotificationRequest notification templateVars.put("courtEmail", courtDetails.get("email")); } + // Override court name/email address values if present in the request + if (notificationRequest.getContactCourtName() != null) { + templateVars.put("courtName", notificationRequest.getContactCourtName()); + } + if (notificationRequest.getContactCourtEmail() != null) { + templateVars.put("courtEmail", notificationRequest.getContactCourtEmail()); + } + if (FR_ASSIGNED_TO_JUDGE.equals(templateName)) { templateVars.put("isNotDigital", notificationRequest.getIsNotDigital()); } diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/service/NotificationService.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/service/NotificationService.java index 38ed16e6924..3f0965c4ba3 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/service/NotificationService.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/service/NotificationService.java @@ -684,7 +684,6 @@ private void addGeneralEmailAttachment(FinremCaseDetails caseDetails, Notificati private void sendGeneralEmail(FinremCaseDetails caseDetails, String authToken, EmailTemplateNames templateName) { NotificationRequest notificationRequest = finremNotificationRequestMapper.getNotificationRequestForGeneralEmail(caseDetails); - notificationRequest.setNotificationEmail(caseDetails.getData().getGeneralEmailWrapper().getGeneralEmailRecipient()); if (isGeneralEmailWithAttachment(caseDetails)) { addGeneralEmailAttachment(caseDetails, notificationRequest, authToken); } diff --git a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/FinremNotificationRequestMapperTest.java b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/FinremNotificationRequestMapperTest.java index 1cb50680359..03eebea95fc 100644 --- a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/FinremNotificationRequestMapperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/mapper/notificationrequest/FinremNotificationRequestMapperTest.java @@ -12,6 +12,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.finrem.caseorchestration.config.CourtDetailsConfiguration; import uk.gov.hmcts.reform.finrem.caseorchestration.helper.ConsentedApplicationHelper; import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.Barrister; import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.ChangedRepresentative; @@ -39,6 +40,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.params.provider.Arguments.arguments; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.finrem.caseorchestration.OrchestrationConstants.CTSC_OPENING_HOURS; import static uk.gov.hmcts.reform.finrem.caseorchestration.TestConstants.TEST_DIVORCE_CASE_NUMBER; import static uk.gov.hmcts.reform.finrem.caseorchestration.TestConstants.TEST_RESP_SOLICITOR_EMAIL; @@ -65,7 +68,10 @@ class FinremNotificationRequestMapperTest { ObjectMapper mapper; @Mock ConsentedApplicationHelper consentedApplicationHelper; + @Mock + NotificationRequestBuilderFactory builderFactory; + private CourtDetailsConfiguration courtDetailsConfiguration; private FinremCaseDetails consentedFinremCaseDetails; private FinremCaseDetails contestedFinremCaseDetails; @@ -73,6 +79,8 @@ class FinremNotificationRequestMapperTest { void setup() { // Register the JavaTimeModule for Java 8 Date/Time support mapper.registerModule(new JavaTimeModule()); + + courtDetailsConfiguration = mock(CourtDetailsConfiguration.class); consentedFinremCaseDetails = getConsentedFinremCaseDetails(); contestedFinremCaseDetails = getContestedFinremCaseDetails(); } @@ -387,8 +395,12 @@ void shouldCreateNotificationRequestForBarristerNotification() { @Test void givenContestedCaseData_whenGeneralEmail_thenBuildNotificationRequest() { + mockNotificationRequestBuilderFactory(); + + String emailRecipient = "test@test.com"; String emailBody = "This is a contested case test email"; contestedFinremCaseDetails.getData().setGeneralEmailWrapper(GeneralEmailWrapper.builder() + .generalEmailRecipient(emailRecipient) .generalEmailBody(emailBody) .build()); NotificationRequest notificationRequest = notificationRequestMapper.getNotificationRequestForGeneralEmail(contestedFinremCaseDetails); @@ -397,7 +409,7 @@ void givenContestedCaseData_whenGeneralEmail_thenBuildNotificationRequest() { assertEquals(TEST_SOLICITOR_REFERENCE, notificationRequest.getSolicitorReferenceNumber()); assertEquals(TEST_DIVORCE_CASE_NUMBER, notificationRequest.getDivorceCaseNumber()); assertEquals(TEST_SOLICITOR_NAME, notificationRequest.getName()); - assertEquals(TEST_SOLICITOR_EMAIL, notificationRequest.getNotificationEmail()); + assertEquals(emailRecipient, notificationRequest.getNotificationEmail()); assertEquals(emailBody, notificationRequest.getGeneralEmailBody()); assertEquals("contested", notificationRequest.getCaseType()); assertEquals("nottingham", notificationRequest.getSelectedCourt()); @@ -407,8 +419,12 @@ void givenContestedCaseData_whenGeneralEmail_thenBuildNotificationRequest() { @Test void givenConsentedCaseData_whenGeneralEmail_thenBuildNotificationRequest() { + mockNotificationRequestBuilderFactory(); + + String emailRecipient = "test@test.com"; String emailBody = "This is a consented case test email"; consentedFinremCaseDetails.getData().setGeneralEmailWrapper(GeneralEmailWrapper.builder() + .generalEmailRecipient(emailRecipient) .generalEmailBody(emailBody) .build()); NotificationRequest notificationRequest = notificationRequestMapper.getNotificationRequestForGeneralEmail(consentedFinremCaseDetails); @@ -417,8 +433,7 @@ void givenConsentedCaseData_whenGeneralEmail_thenBuildNotificationRequest() { assertEquals(TEST_SOLICITOR_REFERENCE, notificationRequest.getSolicitorReferenceNumber()); assertEquals(TEST_DIVORCE_CASE_NUMBER, notificationRequest.getDivorceCaseNumber()); assertEquals(TEST_SOLICITOR_NAME, notificationRequest.getName()); - assertEquals(TEST_SOLICITOR_EMAIL, notificationRequest.getNotificationEmail()); - assertEquals(emailBody, notificationRequest.getGeneralEmailBody()); + assertEquals(emailRecipient, notificationRequest.getNotificationEmail()); assertEquals("consented", notificationRequest.getCaseType()); assertEquals("consent", notificationRequest.getCaseOrderType()); assertEquals("Consent", notificationRequest.getCamelCaseOrderType()); @@ -426,6 +441,11 @@ void givenConsentedCaseData_whenGeneralEmail_thenBuildNotificationRequest() { assertEquals("Victoria Goodman", notificationRequest.getApplicantName()); } + private void mockNotificationRequestBuilderFactory() { + NotificationRequestBuilder builder = new NotificationRequestBuilder(courtDetailsConfiguration, consentedApplicationHelper); + when(builderFactory.newInstance()).thenReturn(builder); + } + @SneakyThrows private List getChangeOfRepresentationListJson(String party, String latestSolicitorName, diff --git a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailServiceTest.java b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailServiceTest.java index ede9e665340..fbc21712a37 100644 --- a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailServiceTest.java @@ -434,30 +434,51 @@ public void shouldBuildTemplateVarsForContested() { Map returnedTemplateVars = emailService.buildTemplateVars(notificationRequest, FR_CONTESTED_HWF_SUCCESSFUL.name()); - assertEquals("Nottingham FRC", returnedTemplateVars.get("courtName")); assertEquals("FRCNottingham@justice.gov.uk", returnedTemplateVars.get("courtEmail")); assertNull(returnedTemplateVars.get("generalEmailBody")); } + @Test + public void shouldBuildTemplateVarsWithCourtDataForContested() { + setContestedData(); + notificationRequest.setContactCourtEmail("contact.court@test.com"); + notificationRequest.setContactCourtName("Local Court"); + + Map returnedTemplateVars = emailService.buildTemplateVars(notificationRequest, FR_CONTESTED_HWF_SUCCESSFUL.name()); + + assertEquals("Local Court", returnedTemplateVars.get("courtName")); + assertEquals("contact.court@test.com", returnedTemplateVars.get("courtEmail")); + assertNull(returnedTemplateVars.get("generalEmailBody")); + } + @Test public void shouldBuildTemplateVarsForConsented() { setConsentedData(); Map returnedTemplateVars = emailService.buildTemplateVars(notificationRequest, FR_HWF_SUCCESSFUL.name()); - assertContestedTemplateVariablesAreAbsent(returnedTemplateVars); } + @Test + public void shouldBuildTemplateVarsWithCourtDataForConsented() { + setConsentedData(); + notificationRequest.setContactCourtEmail("contact.court@test.com"); + notificationRequest.setContactCourtName("Local Court"); + + Map returnedTemplateVars = emailService.buildTemplateVars(notificationRequest, FR_HWF_SUCCESSFUL.name()); + + assertEquals("Local Court", returnedTemplateVars.get("courtName")); + assertEquals("contact.court@test.com", returnedTemplateVars.get("courtEmail")); + } + @Test public void shouldBuildTemplateVarsForGeneralEmailContested() { setContestedData(); notificationRequest.setGeneralEmailBody("test email body"); - Map returnedTemplateVars = - - emailService.buildTemplateVars(notificationRequest, FR_CONTESTED_GENERAL_EMAIL.name()); + Map returnedTemplateVars = emailService.buildTemplateVars(notificationRequest, FR_CONTESTED_GENERAL_EMAIL.name()); assertEquals("Nottingham FRC", returnedTemplateVars.get("courtName")); assertEquals("FRCNottingham@justice.gov.uk", returnedTemplateVars.get("courtEmail")); From bdf68f064705b24c285abebfdc8307208a3a3b0e Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 16:38:14 +0100 Subject: [PATCH 05/10] Map consented courts to corresponding contested court --- .../config/CourtDetailsConfiguration.java | 213 ++++++++++++++++++ .../config/CourtDetailsConfigurationTest.java | 14 +- 2 files changed, 226 insertions(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java index bc1467e7c4f..770d5e926af 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java @@ -4,6 +4,18 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Getter; import org.springframework.stereotype.Component; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.BirminghamCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CfcCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.ClevelandCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.HumberCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.KentSurreyCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.LiverpoolCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.LondonCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.ManchesterCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.NewportCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.NottinghamCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.NwYorkshireCourt; +import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.SwanseaCourt; import java.io.IOException; import java.io.InputStream; @@ -14,11 +26,212 @@ public class CourtDetailsConfiguration { private final Map courts; + private final Map midlandsConsentedCourtMap = Map.ofEntries( + Map.entry(NottinghamCourt.CONSENTED_NOTTINGHAM_COUNTY_COURT_AND_FAMILY_COURT.getId(), + NottinghamCourt.NOTTINGHAM_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(NottinghamCourt.CONSENTED_DERBY_COMBINED_COURT_CENTRE.getId(), + NottinghamCourt.DERBY_COMBINED_COURT_CENTRE.getId()), + Map.entry(NottinghamCourt.CONSENTED_LEICESTER_COUNTY_COURT_AND_FAMILY_COURT.getId(), + NottinghamCourt.LEICESTER_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(NottinghamCourt.CONSENTED_LINCOLN_COUNTY_COURT_AND_FAMILY_COURT.getId(), + NottinghamCourt.LINCOLN_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(NottinghamCourt.CONSENTED_NORTHAMPTON_CROWN_COUNTY_AND_FAMILY_COURT.getId(), + NottinghamCourt.NORTHAMPTON_CROWN_COUNTY_AND_FAMILY_COURT.getId()), + Map.entry(NottinghamCourt.CONSENTED_CHESTERFIELD_COUNTY_COURT.getId(), + NottinghamCourt.CHESTERFIELD_COUNTY_COURT.getId()), + Map.entry(NottinghamCourt.CONSENTED_MANSFIELD_MAGISTRATES_AND_COUNTY_COURT.getId(), + NottinghamCourt.MANSFIELD_MAGISTRATES_AND_COUNTY_COURT.getId()), + Map.entry(NottinghamCourt.CONSENTED_BOSTON_COUNTY_COURT_AND_FAMILY_COURT.getId(), + NottinghamCourt.BOSTON_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(BirminghamCourt.CONSENTED_BIRMINGHAM_CIVIL_AND_FAMILY_JUSTICE_CENTRE.getId(), + BirminghamCourt.BIRMINGHAM_CIVIL_AND_FAMILY_JUSTICE_CENTRE.getId()), + Map.entry(BirminghamCourt.CONSENTED_COVENTRY_COMBINED_COURT_CENTRE.getId(), + BirminghamCourt.COVENTRY_COMBINED_COURT_CENTRE.getId()), + Map.entry(BirminghamCourt.CONSENTED_TELFORD_COUNTY_COURT_AND_FAMILY_COURT.getId(), + BirminghamCourt.TELFORD_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(BirminghamCourt.CONSENTED_WOLVERHAMPTON_COMBINED_COURT_CENTRE.getId(), + BirminghamCourt.WOLVERHAMPTON_COMBINED_COURT_CENTRE.getId()), + Map.entry(BirminghamCourt.CONSENTED_DUDLEY_COUNTY_COURT_AND_FAMILY_COURT.getId(), + BirminghamCourt.DUDLEY_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(BirminghamCourt.CONSENTED_WALSALL_COUNTY_AND_FAMILY_COURT.getId(), + BirminghamCourt.WALSALL_COUNTY_AND_FAMILY_COURT.getId()), + Map.entry(BirminghamCourt.CONSENTED_STOKE_ON_TRENT_COMBINED_COURT.getId(), + BirminghamCourt.STOKE_ON_TRENT_COMBINED_COURT.getId()), + Map.entry(BirminghamCourt.CONSENTED_WORCESTER_COMBINED_COURT.getId(), + BirminghamCourt.WORCESTER_COMBINED_COURT.getId()), + Map.entry(BirminghamCourt.CONSENTED_STAFFORD_COMBINED_COURT.getId(), + BirminghamCourt.STAFFORD_COMBINED_COURT.getId()), + Map.entry(BirminghamCourt.CONSENTED_HEREFORD_COUNTY_COURT_AND_FAMILY_COURT.getId(), + BirminghamCourt.HEREFORD_COUNTY_COURT_AND_FAMILY_COURT.getId()) + ); + + private final Map londonConsentedCourtMap = Map.ofEntries( + Map.entry(LondonCourt.CENTRAL_FAMILY_COURT.getId(), + CfcCourt.CENTRAL_FAMILY_COURT.getId()), + Map.entry(LondonCourt.WILLESDEN_COUNTY_COURT_AND_FAMILY_COURT.getId(), + CfcCourt.WILLESDEN_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(LondonCourt.UXBRIDGE_COUNTY_COURT_AND_FAMILY_COURT.getId(), + CfcCourt.UXBRIDGE_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(LondonCourt.EAST_LONDON_FAMILY_COURT.getId(), + CfcCourt.EAST_LONDON_FAMILY_COURT.getId()), + Map.entry(LondonCourt.BRENTFORD_COUNTY_AND_FAMILY_COURT.getId(), + CfcCourt.BRENTFORD_COUNTY_AND_FAMILY_COURT.getId()), + Map.entry(LondonCourt.BARNET_CIVIL_AND_FAMILY_COURTS_CENTRE.getId(), + CfcCourt.BARNET_CIVIL_AND_FAMILY_COURTS_CENTRE.getId()), + Map.entry(LondonCourt.ROMFORDCOUNTY_AND_FAMILY_COURT.getId(), + CfcCourt.ROMFORDCOUNTY_AND_FAMILY_COURT.getId()), + Map.entry(LondonCourt.KINGSTON_UPON_THAMES_COUNTY_COURT_AND_FAMILY_COURT.getId(), + CfcCourt.KINGSTON_UPON_THAMES_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(LondonCourt.EDMONTON_COUNTY_COURT_AND_FAMILY_COURT.getId(), + CfcCourt.EDMONTON_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(LondonCourt.CROYDON_COUNTY_COURT_AND_FAMILY_COURT.getId(), + CfcCourt.CROYDON_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(LondonCourt.BROMLEY_COUNTY_COURT_AND_FAMILY_COURT.getId(), + CfcCourt.BROMLEY_COUNTY_COURT_AND_FAMILY_COURT.getId()), + Map.entry(LondonCourt.THE_ROYAL_COURT_OF_JUSTICE.getId(), + CfcCourt.THE_ROYAL_COURT_OF_JUSTICE.getId()) + ); + + private final Map northWestConsentedCourtMap = Map.ofEntries( + // North West + Map.entry(LiverpoolCourt.CONSENTED_LIVERPOOL_CIVIL_FAMILY_COURT.getId(), + LiverpoolCourt.LIVERPOOL_CIVIL_FAMILY_COURT.getId()), + Map.entry(LiverpoolCourt.CONSENTED_CHESTER_CIVIL_FAMILY_JUSTICE.getId(), + LiverpoolCourt.CHESTER_CIVIL_FAMILY_JUSTICE.getId()), + Map.entry(LiverpoolCourt.CONSENTED_CREWE_COUNTY_FAMILY_COURT.getId(), + LiverpoolCourt.CREWE_COUNTY_FAMILY_COURT.getId()), + Map.entry(LiverpoolCourt.CONSENTED_ST_HELENS_COUNTY_FAMILY_COURT.getId(), + LiverpoolCourt.ST_HELENS_COUNTY_FAMILY_COURT.getId()), + Map.entry(LiverpoolCourt.CONSENTED_BIRKENHEAD_COUNTY_FAMILY_COURT.getId(), + LiverpoolCourt.BIRKENHEAD_COUNTY_FAMILY_COURT.getId()), + Map.entry(ManchesterCourt.CONSENTED_MANCHESTER_COURT.getId(), + ManchesterCourt.MANCHESTER_COURT.getId()), + Map.entry(ManchesterCourt.CONSENTED_STOCKPORT_COURT.getId(), + ManchesterCourt.STOCKPORT_COURT.getId()), + Map.entry(ManchesterCourt.CONSENTED_WIGAN_COURT.getId(), + ManchesterCourt.WIGAN_COURT.getId()) + ); + + private final Map northEastConsentedCourtMap = Map.ofEntries( + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_1.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_1.getId()), + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_2.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_2.getId()), + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_3.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_3.getId()), + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_4.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_4.getId()), + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_5.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_5.getId()), + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_6.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_6.getId()), + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_7.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_7.getId()), + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_8.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_8.getId()), + Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_9.getId(), + ClevelandCourt.FR_CLEVELAND_HC_LIST_9.getId()), + Map.entry(NwYorkshireCourt.CONSENTED_HARROGATE_COURT.getId(), + NwYorkshireCourt.HARROGATE_COURT.getId()), + Map.entry(NwYorkshireCourt.CONSENTED_BRADFORD_COURT.getId(), + NwYorkshireCourt.BRADFORD_COURT.getId()), + Map.entry(NwYorkshireCourt.CONSENTED_HUDDERSFIELD_COURT.getId(), + NwYorkshireCourt.HUDDERSFIELD_COURT.getId()), + Map.entry(NwYorkshireCourt.CONSENTED_WAKEFIELD_COURT.getId(), + NwYorkshireCourt.WAKEFIELD_COURT.getId()), + Map.entry(NwYorkshireCourt.CONSENTED_YORK_COURT.getId(), + NwYorkshireCourt.YORK_COURT.getId()), + Map.entry(NwYorkshireCourt.CONSENTED_SCARBOROUGH_COURT.getId(), + NwYorkshireCourt.SCARBOROUGH_COURT.getId()), + Map.entry(NwYorkshireCourt.CONSENTED_LEEDS_COURT.getId(), + NwYorkshireCourt.LEEDS_COURT.getId()), + Map.entry(NwYorkshireCourt.CONSENTED_PRESTON_COURT.getId(), + NwYorkshireCourt.PRESTON_COURT.getId()), + Map.entry(HumberCourt.CONSENTED_FR_humberList_1.getId(), + HumberCourt.FR_humberList_1.getId()), + Map.entry(HumberCourt.CONSENTED_FR_humberList_2.getId(), + HumberCourt.FR_humberList_2.getId()), + Map.entry(HumberCourt.CONSENTED_FR_humberList_3.getId(), + HumberCourt.FR_humberList_3.getId()), + Map.entry(HumberCourt.CONSENTED_FR_humberList_4.getId(), + HumberCourt.FR_humberList_4.getId()), + Map.entry(HumberCourt.CONSENTED_FR_humberList_5.getId(), + HumberCourt.FR_humberList_5.getId()) + ); + + private final Map southEastConsentedCourtMap = Map.ofEntries( + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_1.getId(), + KentSurreyCourt.FR_kent_surreyList_1.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_2.getId(), + KentSurreyCourt.FR_kent_surreyList_2.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_3.getId(), + KentSurreyCourt.FR_kent_surreyList_3.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_4.getId(), + KentSurreyCourt.FR_kent_surreyList_4.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_5.getId(), + KentSurreyCourt.FR_kent_surreyList_5.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_6.getId(), + KentSurreyCourt.FR_kent_surreyList_6.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_7.getId(), + KentSurreyCourt.FR_kent_surreyList_7.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_8.getId(), + KentSurreyCourt.FR_kent_surreyList_8.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_9.getId(), + KentSurreyCourt.FR_kent_surreyList_9.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_10.getId(), + KentSurreyCourt.FR_kent_surreyList_10.getId()), + Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_11.getId(), + KentSurreyCourt.FR_kent_surreyList_11.getId()) + ); + + private final Map walesConsentedCourtMap = Map.ofEntries( + Map.entry(NewportCourt.CONSENTED_FR_newportList_1.getId(), + NewportCourt.FR_newportList_1.getId()), + Map.entry(NewportCourt.CONSENTED_FR_newportList_2.getId(), + NewportCourt.FR_newportList_2.getId()), + Map.entry(NewportCourt.CONSENTED_FR_newportList_3.getId(), + NewportCourt.FR_newportList_3.getId()), + Map.entry(NewportCourt.CONSENTED_FR_newportList_4.getId(), + NewportCourt.FR_newportList_4.getId()), + Map.entry(NewportCourt.CONSENTED_FR_newportList_5.getId(), + NewportCourt.FR_newportList_5.getId()), + Map.entry(SwanseaCourt.CONSENTED_FR_swanseaList_1.getId(), + SwanseaCourt.FR_swanseaList_1.getId()), + Map.entry(SwanseaCourt.CONSENTED_FR_swanseaList_2.getId(), + SwanseaCourt.FR_swanseaList_2.getId()), + Map.entry(SwanseaCourt.CONSENTED_FR_swanseaList_3.getId(), + SwanseaCourt.FR_swanseaList_3.getId()), + Map.entry(SwanseaCourt.CONSENTED_FR_swanseaList_4.getId(), + SwanseaCourt.FR_swanseaList_4.getId()), + Map.entry(SwanseaCourt.CONSENTED_FR_swanseaList_5.getId(), + SwanseaCourt.FR_swanseaList_5.getId()), + Map.entry(SwanseaCourt.CONSENTED_FR_swanseaList_6.getId(), + SwanseaCourt.FR_swanseaList_6.getId()) + ); + public CourtDetailsConfiguration(ObjectMapper objectMapper) throws IOException { try (InputStream inputStream = CourtDetailsConfiguration.class .getResourceAsStream("/json/court-details.json")) { courts = objectMapper.readValue(inputStream, new TypeReference<>() { }); + addConsentedCourts(); } } + + private void addConsentedCourts() { + addConsentedCourts(midlandsConsentedCourtMap); + addConsentedCourts(londonConsentedCourtMap); + addConsentedCourts(northWestConsentedCourtMap); + addConsentedCourts(northEastConsentedCourtMap); + addConsentedCourts(southEastConsentedCourtMap); + addConsentedCourts(walesConsentedCourtMap); + } + + private void addConsentedCourts(Map consentedCourtMap) { + consentedCourtMap.forEach((key, value) -> { + CourtDetails courtDetails = courts.get(value); + assert courtDetails != null : "No court details found for key: " + value; + courts.put(key, courtDetails); + }); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfigurationTest.java b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfigurationTest.java index 36c61402369..8f889cf5b1f 100644 --- a/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfigurationTest.java +++ b/src/test/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfigurationTest.java @@ -6,6 +6,7 @@ import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; +import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.ManchesterCourt.CONSENTED_MANCHESTER_COURT; class CourtDetailsConfigurationTest { @@ -13,7 +14,6 @@ class CourtDetailsConfigurationTest { void testConstructor() throws IOException { CourtDetailsConfiguration config = new CourtDetailsConfiguration(new ObjectMapper()); - assertThat(config.getCourts()).hasSize(137); config.getCourts().forEach((k,v) -> { assertThat(k).isNotNull(); assertThat(v).isNotNull(); @@ -25,4 +25,16 @@ void testConstructor() throws IOException { assertThat(courtDetails.getPhoneNumber()).isEqualTo("0300 123 5577"); assertThat(courtDetails.getEmail()).isEqualTo("FRCLondon@justice.gov.uk"); } + + @Test + void givenMappedConsentedCourt_whenGetCourtDetails_thenReturnCourtDetails() throws IOException { + CourtDetailsConfiguration config = new CourtDetailsConfiguration(new ObjectMapper()); + + CourtDetails courtDetails = config.getCourts().get(CONSENTED_MANCHESTER_COURT.getId()); + + assertThat(courtDetails.getCourtName()).isEqualTo("Manchester County And Family Court"); + assertThat(courtDetails.getCourtAddress()).isEqualTo("1 Bridge Street West, Manchester, M60 9DJ"); + assertThat(courtDetails.getPhoneNumber()).isEqualTo("0300 123 5577"); + assertThat(courtDetails.getEmail()).isEqualTo("manchesterdivorce@justice.gov.uk"); + } } From bf2656118bce691948a56ad41259544a8429fdf9 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 16:38:38 +0100 Subject: [PATCH 06/10] Add emailReplyToId values --- src/main/resources/json/court-details.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/resources/json/court-details.json b/src/main/resources/json/court-details.json index a2e1a122822..8b0a51fc90f 100644 --- a/src/main/resources/json/court-details.json +++ b/src/main/resources/json/court-details.json @@ -123,7 +123,8 @@ "courtName": "Birmingham Civil And Family Justice Centre", "courtAddress": "Priory Courts, 33 Bull Street, Birmingham, B4 6DS", "phoneNumber": "0300 123 5577", - "email": "FRCBirmingham@justice.gov.uk" + "email": "FRCBirmingham@justice.gov.uk", + "emailReplyToId": "22a13617-b938-433e-a2d3-6390354f8c4d" }, "FR_birmingham_hc_list_2": { "courtName": "Coventry Combined Court Centre", @@ -225,7 +226,8 @@ "courtName": "Darlington County Court and Family Court", "courtAddress": "4 Coniscliffe Road, Darlington, DL3 7RL", "phoneNumber": "0300 123 5577", - "email": "Family.newcastle.countycourt@justice.gov.uk" + "email": "Family.newcastle.countycourt@justice.gov.uk", + "emailReplyToId": "88906b91-2295-4887-8ffc-848f2c84171e" }, "FR_cleaveland_hc_list_9": { "courtName": "Darlington Magistrates Court", @@ -591,7 +593,8 @@ "courtName": "Bedford County Court and Family Hearing Centre", "courtAddress": "Shire Hall, 3 St Paul's square, Bedford, MK40 1SQ", "phoneNumber": "0300 123 5577", - "email": "Lutoncountyfamily@Justice.gov.uk" + "email": "Lutoncountyfamily@Justice.gov.uk", + "emailReplyToId": "ec36ee15-3191-42c6-b0ee-7ce94fd0bf58" }, "FR_bedfordshireList_9": { "courtName": "Luton Justice Centre", @@ -759,7 +762,8 @@ "courtName": "Bath Law Courts", "courtAddress": "The Law Courts, North Parade Road, Bath, BA1 5AF", "phoneNumber": "0300 123 5577", - "email": "BristolFRC.bristol.countycourt@justice.gov.uk" + "email": "BristolFRC.bristol.countycourt@justice.gov.uk", + "emailReplyToId": "06eb50b8-dacc-41d7-a688-0d227309435b" }, "FR_bristolList_6": { "courtName": "Weston Super Mare County and Family Court", From 68430da6bf15e9ef6be7c759ae6a36b8e26e18ed Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 16:43:16 +0100 Subject: [PATCH 07/10] Minor changed --- .../caseorchestration/config/CourtDetailsConfiguration.java | 1 - .../notifications/service/EmailService.java | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java index 770d5e926af..f107a072f4e 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java @@ -93,7 +93,6 @@ public class CourtDetailsConfiguration { ); private final Map northWestConsentedCourtMap = Map.ofEntries( - // North West Map.entry(LiverpoolCourt.CONSENTED_LIVERPOOL_CIVIL_FAMILY_COURT.getId(), LiverpoolCourt.LIVERPOOL_CIVIL_FAMILY_COURT.getId()), Map.entry(LiverpoolCourt.CONSENTED_CHESTER_CIVIL_FAMILY_JUSTICE.getId(), diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java index e54de3b905f..352dd720bdb 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java @@ -90,11 +90,7 @@ protected Map buildTemplateVars(NotificationRequest notification templateVars.put("respondentName", notificationRequest.getRespondentName()); templateVars.put("hearingType", notificationRequest.getHearingType()); - // Contested emails notifications require the court information, consented does not - // This block of code can be removed once all NotificationRequests are updated - // to populate contactCourtName and contactCourtEmail. - // The code block would only be required if emails needed to show the FRC email address - // rather than the court email address + //contested emails notifications require the court information, consented does not if ((CONTESTED.equals(notificationRequest.getCaseType()) || CONSENTED_LIST_FOR_HEARING.equals(templateName)) && !isEmpty(notificationRequest.getSelectedCourt())) { Map courtDetails = contestedContactEmails.get(notificationRequest.getSelectedCourt()); From 834c8049abc1a5758ec006043ec2b59aa6c11ec5 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 16:56:17 +0100 Subject: [PATCH 08/10] Add comments --- .../config/CourtDetailsConfiguration.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java index f107a072f4e..5d34e899f60 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java @@ -26,7 +26,7 @@ public class CourtDetailsConfiguration { private final Map courts; - private final Map midlandsConsentedCourtMap = Map.ofEntries( + private final Map midlandsCourtMap = Map.ofEntries( Map.entry(NottinghamCourt.CONSENTED_NOTTINGHAM_COUNTY_COURT_AND_FAMILY_COURT.getId(), NottinghamCourt.NOTTINGHAM_COUNTY_COURT_AND_FAMILY_COURT.getId()), Map.entry(NottinghamCourt.CONSENTED_DERBY_COMBINED_COURT_CENTRE.getId(), @@ -65,7 +65,7 @@ public class CourtDetailsConfiguration { BirminghamCourt.HEREFORD_COUNTY_COURT_AND_FAMILY_COURT.getId()) ); - private final Map londonConsentedCourtMap = Map.ofEntries( + private final Map londonCourtMap = Map.ofEntries( Map.entry(LondonCourt.CENTRAL_FAMILY_COURT.getId(), CfcCourt.CENTRAL_FAMILY_COURT.getId()), Map.entry(LondonCourt.WILLESDEN_COUNTY_COURT_AND_FAMILY_COURT.getId(), @@ -92,7 +92,7 @@ public class CourtDetailsConfiguration { CfcCourt.THE_ROYAL_COURT_OF_JUSTICE.getId()) ); - private final Map northWestConsentedCourtMap = Map.ofEntries( + private final Map northWestCourtMap = Map.ofEntries( Map.entry(LiverpoolCourt.CONSENTED_LIVERPOOL_CIVIL_FAMILY_COURT.getId(), LiverpoolCourt.LIVERPOOL_CIVIL_FAMILY_COURT.getId()), Map.entry(LiverpoolCourt.CONSENTED_CHESTER_CIVIL_FAMILY_JUSTICE.getId(), @@ -111,7 +111,7 @@ public class CourtDetailsConfiguration { ManchesterCourt.WIGAN_COURT.getId()) ); - private final Map northEastConsentedCourtMap = Map.ofEntries( + private final Map northEastCourtMap = Map.ofEntries( Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_1.getId(), ClevelandCourt.FR_CLEVELAND_HC_LIST_1.getId()), Map.entry(ClevelandCourt.FR_CLEVELAND_LIST_2.getId(), @@ -158,7 +158,7 @@ public class CourtDetailsConfiguration { HumberCourt.FR_humberList_5.getId()) ); - private final Map southEastConsentedCourtMap = Map.ofEntries( + private final Map southEastCourtMap = Map.ofEntries( Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_1.getId(), KentSurreyCourt.FR_kent_surreyList_1.getId()), Map.entry(KentSurreyCourt.CONSENTED_FR_kent_surreyList_2.getId(), @@ -183,7 +183,7 @@ public class CourtDetailsConfiguration { KentSurreyCourt.FR_kent_surreyList_11.getId()) ); - private final Map walesConsentedCourtMap = Map.ofEntries( + private final Map walesCourtMap = Map.ofEntries( Map.entry(NewportCourt.CONSENTED_FR_newportList_1.getId(), NewportCourt.FR_newportList_1.getId()), Map.entry(NewportCourt.CONSENTED_FR_newportList_2.getId(), @@ -218,18 +218,23 @@ public CourtDetailsConfiguration(ObjectMapper objectMapper) throws IOException { } private void addConsentedCourts() { - addConsentedCourts(midlandsConsentedCourtMap); - addConsentedCourts(londonConsentedCourtMap); - addConsentedCourts(northWestConsentedCourtMap); - addConsentedCourts(northEastConsentedCourtMap); - addConsentedCourts(southEastConsentedCourtMap); - addConsentedCourts(walesConsentedCourtMap); + addConsentedCourts(midlandsCourtMap); + addConsentedCourts(londonCourtMap); + addConsentedCourts(northWestCourtMap); + addConsentedCourts(northEastCourtMap); + addConsentedCourts(southEastCourtMap); + addConsentedCourts(walesCourtMap); } - private void addConsentedCourts(Map consentedCourtMap) { - consentedCourtMap.forEach((key, value) -> { + /** + * Adds court details for a consented court id by finding its contested equivalent + * + * @param courtMap map of consented to contested court ids + */ + private void addConsentedCourts(Map courtMap) { + courtMap.forEach((key, value) -> { CourtDetails courtDetails = courts.get(value); - assert courtDetails != null : "No court details found for key: " + value; + assert courtDetails != null : "No contested court details found for id: " + value; courts.put(key, courtDetails); }); } From 5f49a7f37d9ee4048084a0f1cd94e21678624b33 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 3 Sep 2025 17:06:18 +0100 Subject: [PATCH 09/10] Fix checkstyle error --- .../caseorchestration/config/CourtDetailsConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java index 5d34e899f60..6379324319b 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/config/CourtDetailsConfiguration.java @@ -227,7 +227,7 @@ private void addConsentedCourts() { } /** - * Adds court details for a consented court id by finding its contested equivalent + * Adds court details for a consented court id by finding its contested equivalent. * * @param courtMap map of consented to contested court ids */ From 1836143f827264962e71cec47d2c79b50ac1694f Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 4 Sep 2025 09:50:37 +0100 Subject: [PATCH 10/10] Add check for empty strings --- .../notifications/service/EmailService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java index 352dd720bdb..7fd83f29e27 100644 --- a/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java +++ b/src/main/java/uk/gov/hmcts/reform/finrem/caseorchestration/notifications/service/EmailService.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; @@ -100,10 +101,10 @@ protected Map buildTemplateVars(NotificationRequest notification } // Override court name/email address values if present in the request - if (notificationRequest.getContactCourtName() != null) { + if (StringUtils.isNotBlank(notificationRequest.getContactCourtName())) { templateVars.put("courtName", notificationRequest.getContactCourtName()); } - if (notificationRequest.getContactCourtEmail() != null) { + if (StringUtils.isNotBlank(notificationRequest.getContactCourtEmail())) { templateVars.put("courtEmail", notificationRequest.getContactCourtEmail()); }