Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIV-15465 Add solicitor refs to email #5677

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import java.util.Map;

import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.buildPartiesReferencesEmailSubject;

/**
* When an SDO is created it is notified to applicants and defendants.
* This class holds common code for the actual sending of the email.
Expand Down Expand Up @@ -67,13 +69,14 @@ private String getSDOTemplate(CaseData caseData) {
public Map<String, String> addProperties(CaseData caseData) {
if (caseData.isRespondentResponseBilingual()) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
RESPONDENT_NAME, getRespondentLegalName(caseData)
);
}
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
CLAIM_LEGAL_ORG_NAME_SPEC, getRespondentLegalName(caseData)
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
CLAIM_LEGAL_ORG_NAME_SPEC, getRespondentLegalName(caseData),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_APPLICANT_SOLICITOR1_FOR_SPEC_CLAIM_ACKNOWLEDGEMENT_CC;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.buildPartiesReferencesEmailSubject;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -85,7 +86,8 @@ public Map<String, String> addProperties(CaseData caseData) {
return Map.of(
CLAIM_LEGAL_ORG_NAME_SPEC, getApplicantLegalOrganizationName(caseData.getApplicant1OrganisationPolicy()
.getOrganisation().getOrganisationID(), caseData),
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData),
RESPONSE_DEADLINE, formatLocalDate(caseData.getRespondent1ResponseDeadline().toLocalDate(), DATE)
);
}
Expand All @@ -95,7 +97,8 @@ public Map<String, String> addPropertiesForRespondent(CaseData caseData) {
return Map.of(
CLAIM_LEGAL_ORG_NAME_SPEC, getApplicantLegalOrganizationName(
caseData.getRespondent1OrganisationPolicy().getOrganisation().getOrganisationID(), caseData),
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData),
RESPONSE_DEADLINE, formatLocalDate(caseData.getRespondent1ResponseDeadline().toLocalDate(), DATE)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.Party;
import uk.gov.hmcts.reform.civil.notify.NotificationService;
import uk.gov.hmcts.reform.civil.service.OrganisationService;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -26,7 +28,9 @@
import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.buildPartiesReferences;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.buildPartiesReferencesEmailSubject;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.getApplicantLegalOrganizationName;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.getRespondentLegalOrganizationName;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getPartyNameBasedOnType;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getResponseIntentionForEmail;

Expand All @@ -45,6 +49,7 @@ public class AcknowledgeClaimApplicantNotificationHandler extends CallbackHandle

private final NotificationService notificationService;
private final NotificationsProperties notificationsProperties;
private final OrganisationService organisationService;

@Override
protected Map<String, Callback> callbacks() {
Expand All @@ -69,11 +74,14 @@ private CallbackResponse notifyApplicantSolicitorForClaimAcknowledgement(Callbac
? getRespondentSolicitorEmailAddress(caseData)
: caseData.getApplicantSolicitor1UserDetails().getEmail();

Map<String, String> notificationProperties = addProperties(caseData);
notificationProperties.put(CLAIM_LEGAL_ORG_NAME_SPEC, getOrgName(caseData, callbackParams));

if (recipient != null) {
notificationService.sendMail(
recipient,
notificationsProperties.getRespondentSolicitorAcknowledgeClaim(),
addProperties(caseData),
notificationProperties,
String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference())
);
} else {
Expand Down Expand Up @@ -110,13 +118,13 @@ public Map<String, String> addProperties(CaseData caseData) {
}
}

return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
return new HashMap<>(Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
RESPONDENT_NAME, getPartyNameBasedOnType(respondent),
PARTY_REFERENCES, buildPartiesReferences(caseData),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData),
RESPONSE_DEADLINE, formatLocalDate(responseDeadline.toLocalDate(), DATE),
RESPONSE_INTENTION, getResponseIntentionForEmail(caseData)
);
));
}

private boolean isCcNotification(CallbackParams callbackParams) {
Expand Down Expand Up @@ -148,4 +156,10 @@ private String getRespondentSolicitorEmailAddress(CaseData caseData) {
}
return respondentSolicitorEmailAddress;
}

private String getOrgName(CaseData caseData, CallbackParams callbackParams) {
return isCcNotification(callbackParams)
? getRespondentLegalOrganizationName(caseData.getRespondent1OrganisationPolicy(), organisationService)
: getApplicantLegalOrganizationName(caseData, organisationService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.buildPartiesReferencesEmailSubject;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.fetchDefendantName;

@Service
Expand Down Expand Up @@ -100,9 +101,10 @@ CLAIM_LEGAL_ORG_NAME_SPEC, getApplicantLegalOrganizationName(
.getOrganisation().getOrganisationID(),
caseData
),
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
AGREED_EXTENSION_DATE, formatLocalDate(caseData.getRespondentSolicitor1AgreedDeadlineExtension(), DATE),
DEFENDANT_NAME, fetchDefendantName(caseData)
DEFENDANT_NAME, fetchDefendantName(caseData),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData)
);
}

Expand Down Expand Up @@ -132,8 +134,9 @@ public Map<String, String> addPropertiesForRespondent(CaseData caseData) {
return Map.of(
CLAIM_LEGAL_ORG_NAME_SPEC, getApplicantLegalOrganizationName(
caseData.getRespondent1OrganisationPolicy().getOrganisation().getOrganisationID(), caseData),
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
AGREED_EXTENSION_DATE, formatLocalDate(extensionDate, DATE)
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
AGREED_EXTENSION_DATE, formatLocalDate(extensionDate, DATE),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.notify.NotificationService;
import uk.gov.hmcts.reform.civil.service.OrganisationService;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -28,7 +30,9 @@
import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE;
import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.formatLocalDate;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.buildPartiesReferences;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.buildPartiesReferencesEmailSubject;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.getApplicantLegalOrganizationName;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.getRespondentLegalOrganizationName;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.fetchDefendantName;

@Service
Expand All @@ -45,6 +49,7 @@ public class AgreedExtensionDateApplicantNotificationHandler extends CallbackHan

private final NotificationService notificationService;
private final NotificationsProperties notificationsProperties;
private final OrganisationService organisationService;

@Override
protected Map<String, Callback> callbacks() {
Expand All @@ -65,11 +70,13 @@ public List<CaseEvent> handledEvents() {

private CallbackResponse notifyApplicantSolicitorForAgreedExtensionDate(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
Map<String, String> notificationProperties = addProperties(caseData);
notificationProperties.put(CLAIM_LEGAL_ORG_NAME_SPEC, getSolicitorOrgName(callbackParams));

notificationService.sendMail(
getSolicitorEmailAddress(callbackParams),
notificationsProperties.getClaimantSolicitorAgreedExtensionDate(),
addProperties(caseData),
notificationProperties,
String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference())
);
return AboutToStartOrSubmitCallbackResponse.builder().build();
Expand Down Expand Up @@ -99,12 +106,29 @@ public Map<String, String> addProperties(CaseData caseData) {
}
}

return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
return new HashMap<>(Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
AGREED_EXTENSION_DATE, formatLocalDate(extensionDate.toLocalDate(), DATE),
PARTY_REFERENCES, buildPartiesReferences(caseData),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData),
DEFENDANT_NAME, fetchDefendantName(caseData)
);
));
}

private String getSolicitorOrgName(CallbackParams callbackParams) {
String eventId = callbackParams.getRequest().getEventId();
CaseData caseData = callbackParams.getCaseData();

if (eventId.equals(NOTIFY_APPLICANT_SOLICITOR1_FOR_AGREED_EXTENSION_DATE.name())) {
return getApplicantLegalOrganizationName(caseData, organisationService);
}
if (eventId.equals(NOTIFY_APPLICANT_SOLICITOR1_FOR_AGREED_EXTENSION_DATE_CC.name())) {
return getRespondentLegalOrganizationName(caseData.getRespondent1OrganisationPolicy(), organisationService);
}
if (eventId.equals(NOTIFY_RESPONDENT_SOLICITOR2_FOR_AGREED_EXTENSION_DATE_CC.name())) {
return getRespondentLegalOrganizationName(caseData.getRespondent2OrganisationPolicy(), organisationService);
}

throw new CallbackException(String.format("Callback handler received unexpected event id: %s", eventId));
}

private String getSolicitorEmailAddress(CallbackParams callbackParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.notify.NotificationService;
import uk.gov.hmcts.reform.civil.service.OrganisationService;
import uk.gov.hmcts.reform.civil.utils.PartyUtils;
import uk.gov.hmcts.reform.civil.prd.model.Organisation;

import java.util.HashMap;
Expand All @@ -24,6 +23,8 @@
import java.util.Optional;
import java.util.function.Supplier;

import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.buildPartiesReferencesEmailSubject;

@Service
@RequiredArgsConstructor
public class BreathingSpaceEnterNotificationHandler extends CallbackHandler implements NotificationData {
Expand Down Expand Up @@ -119,8 +120,8 @@ private String getOrganisationName(OrganisationPolicy organisationPolicy, Suppli
@Override
public Map<String, String> addProperties(CaseData caseData) {
HashMap<String, String> properties = new HashMap<>();
properties.put(CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference());
properties.put(PARTY_REFERENCES, PartyUtils.buildPartiesReferences(caseData));
properties.put(CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString());
properties.put(PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData));
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_APPLICANT_SOLICITOR1_BREATHING_SPACE_LIFTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_RESPONDENT_SOLICITOR1_BREATHING_SPACE_LIFTED;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.buildPartiesReferencesEmailSubject;
import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getPartyNameBasedOnType;

@Service
Expand Down Expand Up @@ -85,9 +86,10 @@ private CallbackResponse notifySolicitorBreathingSpaceLifted(CallbackParams call

public Map<String, String> addPropertiesForRespondent(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
RESPONDENT_NAME, getPartyNameBasedOnType(caseData.getRespondent1()),
CLAIM_DEFENDANT_LEGAL_ORG_NAME_SPEC, getRespondentLegalOrganizationName(caseData)
CLAIM_DEFENDANT_LEGAL_ORG_NAME_SPEC, getRespondentLegalOrganizationName(caseData),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData)
);
}

Expand All @@ -105,9 +107,10 @@ public String getRespondentLegalOrganizationName(CaseData caseData) {
@Override
public Map<String, String> addProperties(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
RESPONDENT_NAME, getPartyNameBasedOnType(caseData.getRespondent1()),
CLAIM_LEGAL_ORG_NAME_SPEC, getApplicantLegalOrganizationName(caseData)
CLAIM_LEGAL_ORG_NAME_SPEC, getApplicantLegalOrganizationName(caseData),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.notify.NotificationService;
import uk.gov.hmcts.reform.civil.notify.NotificationsProperties;
import uk.gov.hmcts.reform.civil.service.OrganisationService;
import uk.gov.hmcts.reform.civil.utils.PartyUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Objects.nonNull;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_APPLICANT_SOLICITOR1_FOR_BUNDLE_CREATED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_RESPONDENT_SOLICITOR1_FOR_BUNDLE_CREATED;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.buildPartiesReferencesEmailSubject;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.getApplicantLegalOrganizationName;
import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.getRespondentLegalOrganizationName;

@Service
@RequiredArgsConstructor
public class BundleCreatedNotificationHandler extends CallbackHandler implements NotificationData {

private final NotificationService notificationService;
private final OrganisationService organisationService;
private final NotificationsProperties notificationsProperties;
private static final List<CaseEvent> EVENTS = List.of(
NOTIFY_APPLICANT_SOLICITOR1_FOR_BUNDLE_CREATED,
Expand Down Expand Up @@ -64,11 +70,18 @@ private CallbackResponse notifyBundleCreated(CallbackParams callbackParams) {
}
String emailAddress = getRecipientEmail(caseData, taskId);
String template = getReferenceTemplateString(taskId);

Map<String, String> properties = new HashMap<>();
if (!isLip(caseData, taskId)) {
properties = addProperties(caseData);
properties.put(CLAIM_LEGAL_ORG_NAME_SPEC, getOrgName(caseData, CaseEvent.valueOf(callbackParams.getRequest().getEventId())));
}

if (nonNull(emailAddress)) {
notificationService.sendMail(
emailAddress,
getTemplate(caseData, taskId),
isLip(caseData, taskId) ? addPropertiesLip(caseData, taskId) : addProperties(caseData),
isLip(caseData, taskId) ? addPropertiesLip(caseData, taskId) : properties,
String.format(template, caseData.getLegacyCaseReference())
);
}
Expand Down Expand Up @@ -135,10 +148,11 @@ public List<CaseEvent> handledEvents() {

@Override
public Map<String, String> addProperties(CaseData caseData) {
return Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(),
CLAIMANT_V_DEFENDANT, PartyUtils.getAllPartyNames(caseData)
);
return new HashMap<>(Map.of(
CLAIM_REFERENCE_NUMBER, caseData.getCcdCaseReference().toString(),
CLAIMANT_V_DEFENDANT, PartyUtils.getAllPartyNames(caseData),
PARTY_REFERENCES, buildPartiesReferencesEmailSubject(caseData)
));
}

public Map<String, String> addPropertiesLip(CaseData caseData, String taskId) {
Expand Down Expand Up @@ -167,4 +181,22 @@ private boolean isLip(CaseData caseData, String taskId) {
return false;
}
}

private String getOrgName(CaseData caseData, CaseEvent caseEvent) {
return switch (caseEvent) {
case NOTIFY_APPLICANT_SOLICITOR1_FOR_BUNDLE_CREATED -> getApplicantLegalOrganizationName(
caseData,
organisationService
);
case NOTIFY_RESPONDENT_SOLICITOR1_FOR_BUNDLE_CREATED -> getRespondentLegalOrganizationName(
caseData.getRespondent1OrganisationPolicy(),
organisationService
);
case NOTIFY_RESPONDENT_SOLICITOR2_FOR_BUNDLE_CREATED -> getRespondentLegalOrganizationName(
caseData.getRespondent2OrganisationPolicy(),
organisationService
);
default -> throw new IllegalArgumentException("Invalid track type in " + caseEvent);
};
}
}
Loading
Loading