diff --git a/.gitignore b/.gitignore index cbf3aaab748..842bf205926 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ definitions/**/*.xlsx# # aat env file .aat-env + +cftlib_log_file_IS_UNDEFINED \ No newline at end of file diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/sscs/functional/tyanotifications/sya/notifications/NotificationsFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/sscs/functional/tyanotifications/sya/notifications/NotificationsFunctionalTest.java index a6e2613db35..dd65739cfd1 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/sscs/functional/tyanotifications/sya/notifications/NotificationsFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/sscs/functional/tyanotifications/sya/notifications/NotificationsFunctionalTest.java @@ -480,6 +480,7 @@ public void shouldSaveReasonableAdjustmentNotificationForAppellant() throws IOEx @Test public void shouldSaveReasonableAdjustmentNotificationForAppellantAndRep() throws IOException, NotificationClientException { simulateCcdCallback(APPEAL_RECEIVED, BASE_PATH_TYAN + APPEAL_RECEIVED.getId() + "AppellantRepReasonableAdjustmentCallback.json"); + delayInSeconds(10); List notifications = tryFetchNotificationsForTestCaseWithFlag(true, null, appealCreatedAppellantEmailId, appealCreatedAppellantSmsId); assertEquals(2, notifications.size()); diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/GenericLetterPlaceholderService.java b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/GenericLetterPlaceholderService.java index 4d5b692f452..87a2f6ecd97 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/GenericLetterPlaceholderService.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/GenericLetterPlaceholderService.java @@ -2,13 +2,35 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import static uk.gov.hmcts.reform.sscs.ccd.domain.Benefit.getBenefitByCodeOrThrowException; -import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.*; -import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderService.lines; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.ADDRESS_NAME; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.APPEAL_REF; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.APPELLANT_NAME; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.BENEFIT_NAME_ACRONYM_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.CASE_ID_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.GENERATED_DATE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.HMCTS2; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.HMCTS_IMG; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.INFO_REQUEST_DETAIL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.IS_OTHER_PARTY; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.IS_REPRESENTATIVE; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.JOINT; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_1; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_2; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_3; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_4; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_POSTCODE; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.NAME; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_PHONE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REPRESENTATIVE_NAME; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.SSCS_URL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.SSCS_URL_LITERAL; import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderUtility.defaultToEmptyStringIfNull; import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderUtility.truncateAddressLine; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressPlaceholders; import java.time.LocalDateTime; import java.util.HashMap; +import java.util.List; import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -31,12 +53,13 @@ public GenericLetterPlaceholderService(PlaceholderService placeholderService) { } public Map populatePlaceholders(SscsCaseData caseData, FurtherEvidenceLetterType letterType, String otherPartyId) { - var placeholders = new HashMap(); - Address address = PlaceholderUtility.getAddress(caseData, letterType, otherPartyId); String name = PlaceholderUtility.getName(caseData, letterType, otherPartyId); - placeholders.putAll(getAddressPlaceHolders(address)); + List addressConstants = List.of(LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, + LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE); + + Map placeholders = new HashMap<>(getAddressPlaceholders(address, addressConstants, true)); if (name != null) { placeholders.put(ADDRESS_NAME, truncateAddressLine(name)); @@ -101,17 +124,4 @@ private String getAppealReference(SscsCaseData caseData) { return isBlank(caseReference) || (caseData.getCreatedInGapsFrom() != null && caseData.getCreatedInGapsFrom().equals("readyToList")) ? caseData.getCcdCaseId() : caseReference; } - - private Map getAddressPlaceHolders(Address address) { - var addressPlaceHolders = new HashMap(); - String[] lines = lines(address); - String[] addressConstants = {LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, - LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE}; - - for (int i = 0; i < lines.length; i++) { - addressPlaceHolders.put(addressConstants[i], truncateAddressLine(defaultToEmptyStringIfNull(lines[i]))); - } - - return addressPlaceHolders; - } } diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderConstants.java b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderConstants.java index 65f08416f84..d26c5918919 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderConstants.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderConstants.java @@ -41,8 +41,7 @@ public final class PlaceholderConstants { public static final String LETTER_ADDRESS_LINE_2 = "letter_address_line_2"; public static final String LETTER_ADDRESS_LINE_3 = "letter_address_line_3"; public static final String LETTER_ADDRESS_LINE_4 = "letter_address_line_4"; - public static final String LETTER_ADDRESS_POSTCODE = "letter_address_postcode"; - + public static final String LETTER_ADDRESS_POSTCODE = "letter_address_line_5"; public static final String BENEFIT_NAME_ACRONYM_LITERAL = "benefit_name_acronym"; public static final String IS_REPRESENTATIVE = "representative"; public static final String IS_OTHER_PARTY = "is_other_party"; diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderService.java b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderService.java index fc03e5cc657..9fb70d078e1 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderService.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderService.java @@ -1,14 +1,40 @@ package uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders; import static java.util.Objects.nonNull; -import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.*; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.APPELLANT_FULL_NAME_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.BENEFIT_TYPE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.CASE_CREATED_DATE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.CASE_ID_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.EXELA_ADDRESS_LINE1_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.EXELA_ADDRESS_LINE2_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.EXELA_ADDRESS_LINE3_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.EXELA_ADDRESS_POSTCODE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.GENERATED_DATE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.NINO_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.RECIPIENT_ADDRESS_LINE_1_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.RECIPIENT_ADDRESS_LINE_2_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.RECIPIENT_ADDRESS_LINE_3_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.RECIPIENT_ADDRESS_LINE_4_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.RECIPIENT_ADDRESS_LINE_5_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_ADDRESS_LINE1_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_ADDRESS_LINE2_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_ADDRESS_LINE3_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_ADDRESS_LINE4_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_COUNTY_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_FAX_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_PHONE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.REGIONAL_OFFICE_POSTCODE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.SC_NUMBER_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.SHOULD_HIDE_NINO; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.SSCS_URL_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.WELSH_CASE_CREATED_DATE_LITERAL; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.WELSH_GENERATED_DATE_LITERAL; import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderUtility.defaultToEmptyStringIfNull; -import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderUtility.truncateAddressLine; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressPlaceholders; import java.time.LocalDateTime; +import java.util.List; import java.util.Map; -import java.util.Objects; -import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -77,7 +103,11 @@ public void build(SscsCaseData caseData, Map placeholders, Addre buildExcelaAddress(caseData.getIsScottishCase(), placeholders); populateRpcPlaceHolders(caseData, placeholders); - buildRecipientAddressPlaceholders(address, placeholders); + + List addressConstants = List.of(RECIPIENT_ADDRESS_LINE_1_LITERAL, RECIPIENT_ADDRESS_LINE_2_LITERAL, RECIPIENT_ADDRESS_LINE_3_LITERAL, + RECIPIENT_ADDRESS_LINE_4_LITERAL, RECIPIENT_ADDRESS_LINE_5_LITERAL); + + placeholders.putAll(getAddressPlaceholders(address, addressConstants, true)); } public void buildExcelaAddress(String isScottish, Map placeholders) { @@ -111,31 +141,4 @@ public boolean hasRegionalProcessingCenter(SscsCaseData ccdResponse) { return nonNull(ccdResponse.getRegionalProcessingCenter()) && nonNull(ccdResponse.getRegionalProcessingCenter().getName()); } - - private void buildRecipientAddressPlaceholders(Address address, Map placeholders) { - String[] lines = lines(address); - - if (lines.length >= 1) { - placeholders.put(RECIPIENT_ADDRESS_LINE_1_LITERAL, truncateAddressLine(defaultToEmptyStringIfNull(lines[0]))); - } - if (lines.length >= 2) { - placeholders.put(RECIPIENT_ADDRESS_LINE_2_LITERAL, truncateAddressLine(defaultToEmptyStringIfNull(lines[1]))); - } - if (lines.length >= 3) { - placeholders.put(RECIPIENT_ADDRESS_LINE_3_LITERAL, truncateAddressLine(defaultToEmptyStringIfNull(lines[2]))); - } - if (lines.length >= 4) { - placeholders.put(RECIPIENT_ADDRESS_LINE_4_LITERAL, truncateAddressLine(defaultToEmptyStringIfNull(lines[3]))); - } - if (lines.length >= 5) { - placeholders.put(RECIPIENT_ADDRESS_LINE_5_LITERAL, truncateAddressLine(defaultToEmptyStringIfNull(lines[4]))); - } - } - - public static String[] lines(Address address) { - return Stream.of(address.getLine1(), address.getLine2(), address.getTown(), address.getCounty(), address.getPostcode()) - .filter(Objects::nonNull) - .toArray(String[]::new); - } - } diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderUtility.java b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderUtility.java index 1acb0a9ce81..13f4b5d42ee 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderUtility.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/PlaceholderUtility.java @@ -3,15 +3,19 @@ import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNoneBlank; import static uk.gov.hmcts.reform.sscs.ccd.domain.YesNo.isYes; -import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.*; -import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderService.lines; -import java.util.HashMap; -import java.util.Map; import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import uk.gov.hmcts.reform.sscs.ccd.domain.*; +import uk.gov.hmcts.reform.sscs.ccd.domain.Address; +import uk.gov.hmcts.reform.sscs.ccd.domain.Appeal; +import uk.gov.hmcts.reform.sscs.ccd.domain.Appellant; +import uk.gov.hmcts.reform.sscs.ccd.domain.Appointee; +import uk.gov.hmcts.reform.sscs.ccd.domain.CcdValue; +import uk.gov.hmcts.reform.sscs.ccd.domain.Name; +import uk.gov.hmcts.reform.sscs.ccd.domain.OtherParty; +import uk.gov.hmcts.reform.sscs.ccd.domain.Representative; +import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; import uk.gov.hmcts.reform.sscs.evidenceshare.domain.FurtherEvidenceLetterType; @Slf4j @@ -23,11 +27,11 @@ public final class PlaceholderUtility { private PlaceholderUtility() { } - static String defaultToEmptyStringIfNull(String value) { + public static String defaultToEmptyStringIfNull(String value) { return (value == null) ? StringUtils.EMPTY : value; } - static String truncateAddressLine(String addressLine) { + public static String truncateAddressLine(String addressLine) { return addressLine != null && addressLine.length() > 45 ? addressLine.substring(0, 45) : addressLine; } @@ -171,17 +175,4 @@ && isValidName(otherPartyValue.getRep().getName())) { private static boolean isValidName(Name name) { return isNoneBlank(name.getFirstName()) && isNoneBlank(name.getLastName()); } - - static Map getAddressPlaceHolders(Address address) { - var addressPlaceHolders = new HashMap(); - String[] lines = lines(address); - String[] addressConstants = {LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, - LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE}; - - for (int i = 0; i < lines.length; i++) { - addressPlaceHolders.put(addressConstants[i], truncateAddressLine(defaultToEmptyStringIfNull(lines[i]))); - } - - return addressPlaceHolders; - } } diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/SorPlaceholderService.java b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/SorPlaceholderService.java index d1619eaedba..1af4c1e30fc 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/SorPlaceholderService.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/SorPlaceholderService.java @@ -2,9 +2,24 @@ import static java.util.Objects.isNull; import static java.util.Objects.requireNonNull; -import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.*; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.ADDRESS_NAME; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.APPEAL_REF; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.APPELLANT_NAME; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.ENTITY_TYPE; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.HEARING_DATE; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.HMCTS2; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.HMCTS_IMG; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_1; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_2; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_3; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_4; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_POSTCODE; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.NAME; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.PHONE_NUMBER; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressPlaceholders; import java.util.HashMap; +import java.util.List; import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -32,13 +47,15 @@ public SorPlaceholderService(PlaceholderService placeholderService) { public Map populatePlaceholders(SscsCaseData caseData, FurtherEvidenceLetterType letterType, String entityType, String otherPartyId) { requireNonNull(caseData, "caseData must not be null"); - - Map placeholders = new HashMap<>(); Address address = PlaceholderUtility.getAddress(caseData, letterType, otherPartyId); + List addressConstants = List.of(LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, + LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE); + + Map placeholders = new HashMap<>(getAddressPlaceholders(address, addressConstants, true)); + placeholderService.build(caseData, placeholders, address, null); String name = PlaceholderUtility.getName(caseData, letterType, otherPartyId); - placeholders.putAll(PlaceholderUtility.getAddressPlaceHolders(address)); if (name != null) { placeholders.put(NAME, name); diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/config/PersonalisationMappingConstants.java b/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/config/PersonalisationMappingConstants.java index f7d120eeb7b..64b1fc4af8d 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/config/PersonalisationMappingConstants.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/config/PersonalisationMappingConstants.java @@ -79,7 +79,8 @@ public final class PersonalisationMappingConstants { public static final String LETTER_ADDRESS_LINE_2 = "letter_address_line_2"; public static final String LETTER_ADDRESS_LINE_3 = "letter_address_line_3"; public static final String LETTER_ADDRESS_LINE_4 = "letter_address_line_4"; - public static final String LETTER_ADDRESS_POSTCODE = "letter_address_postcode"; + public static final String LETTER_ADDRESS_POSTCODE = "letter_address_line_5"; + public static final String NAME = "name"; public static final String MANAGE_EMAILS_LINK_LITERAL = "manage_emails_link"; public static final String MRN_DETAILS_LITERAL = "mrn_details"; diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/LetterUtils.java b/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/LetterUtils.java index e99e9151aae..a84d2863d2e 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/LetterUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/LetterUtils.java @@ -5,6 +5,8 @@ import static org.apache.commons.collections4.CollectionUtils.isNotEmpty; import static org.apache.commons.collections4.ListUtils.emptyIfNull; import static uk.gov.hmcts.reform.sscs.ccd.domain.YesNo.isYes; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderUtility.defaultToEmptyStringIfNull; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderUtility.truncateAddressLine; import static uk.gov.hmcts.reform.sscs.model.PartyItemList.*; import static uk.gov.hmcts.reform.sscs.tyanotifications.config.NotificationEventTypeLists.EVENTS_FOR_ACTION_FURTHER_EVIDENCE; import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationUtils.hasAppointee; @@ -12,7 +14,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; @@ -23,7 +27,14 @@ import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.common.PDRectangle; -import uk.gov.hmcts.reform.sscs.ccd.domain.*; +import uk.gov.hmcts.reform.sscs.ccd.domain.Address; +import uk.gov.hmcts.reform.sscs.ccd.domain.CcdValue; +import uk.gov.hmcts.reform.sscs.ccd.domain.Name; +import uk.gov.hmcts.reform.sscs.ccd.domain.OtherParty; +import uk.gov.hmcts.reform.sscs.ccd.domain.ReasonableAdjustments; +import uk.gov.hmcts.reform.sscs.ccd.domain.Representative; +import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; +import uk.gov.hmcts.reform.sscs.ccd.domain.YesNo; import uk.gov.hmcts.reform.sscs.model.PartyItemList; import uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType; import uk.gov.hmcts.reform.sscs.tyanotifications.domain.NotificationSscsCaseDataWrapper; @@ -322,4 +333,27 @@ static boolean isValidOtherPartyRepresentative(String subscriptionPartyId, Strin } return false; } + + public static List lines(Address address) { + if (isYes(address.getInMainlandUk()) || address.getInMainlandUk() == null) { + return Stream.of(address.getLine1(), address.getLine2(), address.getTown(), address.getCounty(), address.getPostcode()) + .filter(Objects::nonNull) + .toList(); + } else { + return Stream.of(address.getLine1(), address.getLine2(), address.getTown(), address.getPostcode(), address.getCountry()) + .filter(Objects::nonNull) + .toList(); + } + } + + public static Map getAddressPlaceholders(Address address, List addressConstants, boolean truncate) { + HashMap addressPlaceHolders = new HashMap<>(); + + List lines = lines(address); + + for (int i = 0; i < lines.size(); i++) { + addressPlaceHolders.put(addressConstants.get(i), truncate ? truncateAddressLine(defaultToEmptyStringIfNull(lines.get(i))) : defaultToEmptyStringIfNull(lines.get(i))); + } + return addressPlaceHolders; + } } diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/SendNotificationService.java b/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/SendNotificationService.java index ca299aef2e8..9e49f5f2cfc 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/SendNotificationService.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/SendNotificationService.java @@ -1,25 +1,66 @@ package uk.gov.hmcts.reform.sscs.tyanotifications.service; import static java.util.Objects.nonNull; -import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.*; -import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.*; -import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.*; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.ADJOURNMENT_NOTICE; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.AUDIO_VIDEO_EVIDENCE_DIRECTION_NOTICE; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.CORRECTED_DECISION_NOTICE; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.DECISION_NOTICE; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.DIRECTION_NOTICE; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.FINAL_DECISION_NOTICE; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.POSTPONEMENT_REQUEST_DIRECTION_NOTICE; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.STATEMENT_OF_REASONS_GRANTED; +import static uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType.STATEMENT_OF_REASONS_REFUSED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_1; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_2; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_3; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_4; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_5; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.APPEAL_RESPOND_DATE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.APPELLANT_NAME; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.CLAIMANT_NAME; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ENTITY_TYPE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.NAME; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.PARTY_TYPE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.POSTCODE_LITERAL; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.REPRESENTATIVE_NAME; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ACTION_POSTPONEMENT_REQUEST; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ACTION_POSTPONEMENT_REQUEST_WELSH; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ADMIN_CORRECTION_HEADER; import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.CORRECTION_GRANTED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.DECISION_ISSUED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.DECISION_ISSUED_WELSH; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.DIRECTION_ISSUED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.DIRECTION_ISSUED_WELSH; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ISSUE_ADJOURNMENT_NOTICE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ISSUE_ADJOURNMENT_NOTICE_WELSH; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ISSUE_FINAL_DECISION; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ISSUE_FINAL_DECISION_WELSH; import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.PERMISSION_TO_APPEAL_GRANTED; import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.PERMISSION_TO_APPEAL_REFUSED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.PROCESS_AUDIO_VIDEO; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.PROCESS_AUDIO_VIDEO_WELSH; import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.REVIEW_AND_SET_ASIDE; import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.SET_ASIDE_GRANTED; import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.SET_ASIDE_REFUSED; -import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.*; -import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationUtils.*; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.SOR_EXTEND_TIME; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.SOR_REFUSED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.addBlankPageAtTheEndIfOddPage; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.buildBundledLetter; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressPlaceholders; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressToUseForLetter; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getNameToUseForLetter; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.isAlternativeLetterFormatRequired; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationUtils.hasLetterTemplate; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationUtils.isOkToSendEmailNotification; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationUtils.isOkToSendSmsNotification; import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationValidService.isBundledLetter; import java.io.IOException; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Stream; @@ -29,7 +70,11 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.sscs.ccd.callback.DocumentType; -import uk.gov.hmcts.reform.sscs.ccd.domain.*; +import uk.gov.hmcts.reform.sscs.ccd.domain.AbstractDocument; +import uk.gov.hmcts.reform.sscs.ccd.domain.Address; +import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; +import uk.gov.hmcts.reform.sscs.ccd.domain.State; +import uk.gov.hmcts.reform.sscs.ccd.domain.Subscription; import uk.gov.hmcts.reform.sscs.service.PdfStoreService; import uk.gov.hmcts.reform.sscs.tyanotifications.config.AppConstants; import uk.gov.hmcts.reform.sscs.tyanotifications.config.NotificationEventTypeLists; @@ -224,17 +269,15 @@ private boolean sendMandatoryLetterNotification(NotificationWrapper wrapper, Not return false; } - protected void sendLetterNotificationToAddress(NotificationWrapper wrapper, Notification notification, final Address addressToUse, SubscriptionWithType subscriptionWithType) throws NotificationClientException { - if (addressToUse != null) { + protected void sendLetterNotificationToAddress(NotificationWrapper wrapper, Notification notification, final Address address, SubscriptionWithType subscriptionWithType) throws NotificationClientException { + if (address != null) { Map placeholders = notification.getPlaceholders(); String fullNameNoTitle = getNameToUseForLetter(wrapper, subscriptionWithType); placeholders.put(ADDRESS_LINE_1, fullNameNoTitle); - placeholders.put(ADDRESS_LINE_2, addressToUse.getLine1()); - placeholders.put(ADDRESS_LINE_3, isEmpty(addressToUse.getLine2()) ? " " : addressToUse.getLine2()); - placeholders.put(ADDRESS_LINE_4, addressToUse.getTown() == null ? " " : addressToUse.getTown()); - placeholders.put(ADDRESS_LINE_5, addressToUse.getCounty() == null ? " " : addressToUse.getCounty()); - placeholders.put(POSTCODE_LITERAL, addressToUse.getPostcode()); + List addressConstants = List.of(ADDRESS_LINE_2, ADDRESS_LINE_3, ADDRESS_LINE_4, ADDRESS_LINE_5, POSTCODE_LITERAL); + + placeholders.putAll(getAddressPlaceholders(address, addressConstants, false)); placeholders.put(NAME, fullNameNoTitle); if (SubscriptionType.REPRESENTATIVE.equals(subscriptionWithType.getSubscriptionType())) { @@ -250,12 +293,11 @@ protected void sendLetterNotificationToAddress(NotificationWrapper wrapper, Noti } log.info("In sendLetterNotificationToAddress method notificationSender is available {} ", notificationSender != null); - - notificationLog(notification, "GovNotify letter", addressToUse.getPostcode(), wrapper); + notificationLog(notification, "GovNotify letter", address.getPostcode(), wrapper); notificationSender.sendLetter( notification.getLetterTemplate(), - addressToUse, + address, notification.getPlaceholders(), wrapper.getNotificationType(), fullNameNoTitle, @@ -403,5 +445,4 @@ private static String getDocumentForType(AbstractDocument sscsDocument) { } return null; } - } diff --git a/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/docmosis/PdfLetterService.java b/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/docmosis/PdfLetterService.java index aaa7d891d98..39609b1d3e1 100644 --- a/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/docmosis/PdfLetterService.java +++ b/src/main/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/docmosis/PdfLetterService.java @@ -1,9 +1,18 @@ package uk.gov.hmcts.reform.sscs.tyanotifications.service.docmosis; -import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.*; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_1; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_2; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_3; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_4; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_POSTCODE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_NAME; import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.APPEAL_RECEIVED; import static uk.gov.hmcts.reform.sscs.tyanotifications.personalisation.Personalisation.translateToWelshDate; -import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.*; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.addBlankPageAtTheEndIfOddPage; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.buildBundledLetter; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressPlaceholders; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressToUseForLetter; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getNameToUseForLetter; import java.io.IOException; import java.time.LocalDate; @@ -12,7 +21,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -113,7 +121,12 @@ public byte[] generateLetter(NotificationWrapper wrapper, Notification notificat placeholders.put(ADDRESS_NAME, truncateAddressLine(getNameToUseForLetter(wrapper, subscriptionWithType))); Address addressToUse = getAddressToUseForLetter(wrapper, subscriptionWithType); - buildRecipientAddressPlaceholders(addressToUse, placeholders); + + List addressConstants = List.of(LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, + LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE); + + placeholders.putAll(getAddressPlaceholders(addressToUse, addressConstants, true)); + placeholders.put(docmosisTemplatesConfig.getHmctsImgKey(), docmosisTemplatesConfig.getHmctsImgVal()); placeholders.put(docmosisTemplatesConfig.getHmctsWelshImgKey(), docmosisTemplatesConfig.getHmctsWelshImgVal()); @@ -127,32 +140,6 @@ public byte[] generateLetter(NotificationWrapper wrapper, Notification notificat return new byte[0]; } - private void buildRecipientAddressPlaceholders(Address address, Map placeholders) { - String[] lines = lines(address); - - if (lines.length >= 1) { - placeholders.put(LETTER_ADDRESS_LINE_1, truncateAddressLine(defaultToEmptyStringIfNull(lines[0]))); - } - if (lines.length >= 2) { - placeholders.put(LETTER_ADDRESS_LINE_2, truncateAddressLine(defaultToEmptyStringIfNull(lines[1]))); - } - if (lines.length >= 3) { - placeholders.put(LETTER_ADDRESS_LINE_3, truncateAddressLine(defaultToEmptyStringIfNull(lines[2]))); - } - if (lines.length >= 4) { - placeholders.put(LETTER_ADDRESS_LINE_4, truncateAddressLine(defaultToEmptyStringIfNull(lines[3]))); - } - if (lines.length >= 5) { - placeholders.put(LETTER_ADDRESS_POSTCODE, truncateAddressLine(defaultToEmptyStringIfNull(lines[4]))); - } - } - - private static String[] lines(Address address) { - return Stream.of(address.getLine1(), address.getLine2(), address.getTown(), address.getCounty(), address.getPostcode()) - .filter(x -> x != null) - .toArray(String[]::new); - } - private static String defaultToEmptyStringIfNull(String value) { return (value == null) ? StringUtils.EMPTY : value; } @@ -162,4 +149,3 @@ private static String truncateAddressLine(String addressLine) { } } - diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/GenericLetterPlaceholderServiceTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/GenericLetterPlaceholderServiceTest.java index acd7f84b2c6..0ecd5081aed 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/GenericLetterPlaceholderServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/evidenceshare/service/placeholders/GenericLetterPlaceholderServiceTest.java @@ -154,7 +154,6 @@ void shouldReturnEmptyAddressPlaceholdersGivenEmptyAddress() { Map placeholders = genericLetterPlaceholderService.populatePlaceholders(caseData, APPELLANT_LETTER, null); - assertNotNull(placeholders); assertFalse(placeholders.containsKey(LETTER_ADDRESS_LINE_1)); assertFalse(placeholders.containsKey(LETTER_ADDRESS_LINE_2)); diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/LetterUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/LetterUtilsTest.java index 54282682ef9..a8b35c14f59 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/LetterUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/LetterUtilsTest.java @@ -3,13 +3,38 @@ import static java.util.Objects.requireNonNull; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_1; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_2; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_3; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_LINE_4; +import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.LETTER_ADDRESS_POSTCODE; import static uk.gov.hmcts.reform.sscs.model.PartyItemList.DWP; import static uk.gov.hmcts.reform.sscs.model.PartyItemList.HMCTS; import static uk.gov.hmcts.reform.sscs.tyanotifications.config.AppConstants.REP_SALUTATION; -import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.*; -import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.*; -import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.*; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_1; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_2; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_3; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_4; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.ADDRESS_LINE_5; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.PersonalisationMappingConstants.POSTCODE_LITERAL; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.APPELLANT; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.APPOINTEE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.JOINT_PARTY; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.OTHER_PARTY; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.REPRESENTATIVE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.APPEAL_RECEIVED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.LIBERTY_TO_APPLY_REQUEST; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.SYA_APPEAL_CREATED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.addBlankPageAtTheEndIfOddPage; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.buildBundledLetter; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressPlaceholders; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressToUseForLetter; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getNameToUseForLetter; +import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.lines; import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationServiceTest.APPELLANT_WITH_ADDRESS; import static uk.gov.hmcts.reform.sscs.tyanotifications.service.SendNotificationServiceTest.APPELLANT_WITH_ADDRESS_AND_APPOINTEE; import static uk.gov.hmcts.reform.sscs.tyanotifications.service.SendNotificationServiceTest.REP_WITH_ADDRESS; @@ -18,6 +43,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; @@ -32,7 +58,23 @@ import org.junit.Test; import org.junit.jupiter.api.DisplayName; import org.junit.runner.RunWith; -import uk.gov.hmcts.reform.sscs.ccd.domain.*; +import uk.gov.hmcts.reform.sscs.ccd.domain.Address; +import uk.gov.hmcts.reform.sscs.ccd.domain.Appeal; +import uk.gov.hmcts.reform.sscs.ccd.domain.Appellant; +import uk.gov.hmcts.reform.sscs.ccd.domain.Appointee; +import uk.gov.hmcts.reform.sscs.ccd.domain.CcdValue; +import uk.gov.hmcts.reform.sscs.ccd.domain.DynamicList; +import uk.gov.hmcts.reform.sscs.ccd.domain.DynamicListItem; +import uk.gov.hmcts.reform.sscs.ccd.domain.Entity; +import uk.gov.hmcts.reform.sscs.ccd.domain.JointParty; +import uk.gov.hmcts.reform.sscs.ccd.domain.Name; +import uk.gov.hmcts.reform.sscs.ccd.domain.OtherParty; +import uk.gov.hmcts.reform.sscs.ccd.domain.Party; +import uk.gov.hmcts.reform.sscs.ccd.domain.ReasonableAdjustmentDetails; +import uk.gov.hmcts.reform.sscs.ccd.domain.Representative; +import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; +import uk.gov.hmcts.reform.sscs.ccd.domain.Subscription; +import uk.gov.hmcts.reform.sscs.ccd.domain.YesNo; import uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType; import uk.gov.hmcts.reform.sscs.tyanotifications.domain.NotificationSscsCaseDataWrapper; import uk.gov.hmcts.reform.sscs.tyanotifications.domain.SubscriptionWithType; @@ -672,4 +714,302 @@ public NotificationSscsCaseDataWrapper buildBaseWrapperWithCaseData(SscsCaseData .build(); return caseDataWrapper; } + + + @DisplayName("lines returns expected values when given a valid UK address object.") + @Test + public void lines_returns_expected_for_UK_address() { + Address testAddress = Address.builder() + .line1("Somerset House") + .line2("Strand") + .town("London") + .county("Greater London") + .postcode("WC2R 1LA") + .build(); + + List addressLines = lines(testAddress); + List expectedLines = List.of("Somerset House", "Strand", "London", "Greater London", "WC2R 1LA"); + + for (int i = 0; i < addressLines.size(); i++) { + assertEquals(expectedLines.get(i), addressLines.get(i)); + } + } + + @DisplayName("lines returns expected values when given a shorter UK address object.") + @Test + public void lines_returns_expected_for_short_UK_address() { + Address testAddress = Address.builder() + .line1("Elba") + .town("Duns") + .postcode("TD11 3RY") + .build(); + + List addressLines = lines(testAddress); + List expectedLines = List.of("Elba", "Duns", "TD11 3RY"); + + for (int i = 0; i < addressLines.size(); i++) { + assertEquals(expectedLines.get(i), addressLines.get(i)); + } + } + + @DisplayName("lines returns expected values when given a valid UK address object with inMainlandUK YES.") + @Test + public void lines_returns_expected_for_UK_address_with_inMainlandUK() { + Address testAddress = Address.builder() + .line1("Somerset House") + .line2("Strand") + .town("London") + .county("Greater London") + .postcode("WC2R 1LA") + .inMainlandUk(YesNo.YES) + .build(); + + List addressLines = lines(testAddress); + List expectedLines = List.of("Somerset House", "Strand", "London", "Greater London", "WC2R 1LA"); + + for (int i = 0; i < addressLines.size(); i++) { + assertEquals(expectedLines.get(i), addressLines.get(i)); + } + } + + @DisplayName("lines returns expected values when given a valid international address object.") + @Test + public void lines_returns_expected_for_International_address() { + Address testAddress = Address.builder() + .line1("Catherdrale Notre-Dame de Paris") + .line2("6 Parvis Notre-dame - Pl. Jean-Paul II") + .town("Paris") + .county("Ile-de-France") + .postcode("75004") + .country("France") + .inMainlandUk(YesNo.NO) + .build(); + + List addressLines = lines(testAddress); + List expectedLines = List.of("Catherdrale Notre-Dame de Paris", "6 Parvis Notre-dame - Pl. Jean-Paul II", "Paris", "75004", "France"); + + for (int i = 0; i < addressLines.size(); i++) { + assertEquals(expectedLines.get(i), addressLines.get(i)); + } + } + + @DisplayName("lines returns expected values when international address object doesn't include postcode.") + @Test + public void lines_returns_expected_for_International_address_without_Postcode() { + Address testAddress = Address.builder() + .line1("Catherdrale Notre-Dame de Paris") + .line2("6 Parvis Notre-dame - Pl. Jean-Paul II") + .town("Paris") + .county("Ile-de-France") + .country("France") + .inMainlandUk(YesNo.NO) + .build(); + + List addressLines = lines(testAddress); + List expectedLines = List.of("Catherdrale Notre-Dame de Paris", "6 Parvis Notre-dame - Pl. Jean-Paul II", "Paris", "France"); + + for (int i = 0; i < addressLines.size(); i++) { + assertEquals(expectedLines.get(i), addressLines.get(i)); + } + } + + @DisplayName("lines filters out null address lines for UK addresses.") + @Test + public void lines_removes_null_values() { + Address testAddress = Address.builder() + .line1("Test House") + .line2(null) + .town("Test Town") + .county("Test County") + .postcode("Test Postcode") + .build(); + + List addressLines = lines(testAddress); + List expectedLines = List.of("Test House", "Test Town", "Test County", "Test Postcode"); + + for (int i = 0; i < addressLines.size(); i++) { + assertEquals(expectedLines.get(i), addressLines.get(i)); + } + } + + @DisplayName("getAddressPlaceholders returns expected values for a UK address.") + @Test + public void getAddressPlaceholders_returnsExpectedValuesUkAddress() { + Address testAddress = Address.builder() + .line1("Somerset House") + .line2("Strand") + .town("London") + .county("Greater London") + .postcode("WC2R 1LA") + .inMainlandUk(YesNo.YES) + .build(); + + List addressConstants = List.of(LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, + LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE); + Map placeholders = getAddressPlaceholders(testAddress, addressConstants, true); + + assertEquals("Somerset House", placeholders.get(LETTER_ADDRESS_LINE_1)); + assertEquals("Strand", placeholders.get(LETTER_ADDRESS_LINE_2)); + assertEquals("London", placeholders.get(LETTER_ADDRESS_LINE_3)); + assertEquals("Greater London", placeholders.get(LETTER_ADDRESS_LINE_4)); + assertEquals("WC2R 1LA", placeholders.get(LETTER_ADDRESS_POSTCODE)); + } + + @DisplayName("getAddressPlaceholders returns expected values for a UK address.") + @Test + public void getAddressPlaceholders_returnsExpectedValuesShortUkAddress() { + Address testAddress = Address.builder() + .line1("Elba") + .town("Duns") + .postcode("TD11 3RY") + .build(); + + List addressConstants = List.of(LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, + LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE); + Map placeholders = getAddressPlaceholders(testAddress, addressConstants, true); + + assertEquals("Elba", placeholders.get(LETTER_ADDRESS_LINE_1)); + assertEquals("Duns", placeholders.get(LETTER_ADDRESS_LINE_2)); + assertEquals("TD11 3RY", placeholders.get(LETTER_ADDRESS_LINE_3)); + } + + @DisplayName("getAddressPlaceholders returns expected values when using sendLetterNotificationToAddress address placeholders.") + @Test + public void getAddressPlaceholders_returnsExpectedValuesWhenUsingSendLetterNotificationToAddressPlaceholders() { + String fullNameNoTitle = "Jane Doe"; + Address testAddress = Address.builder() + .line1("Somerset House") + .line2("Strand") + .town("London") + .county("Greater London") + .postcode("WC2R 1LA") + .inMainlandUk(YesNo.YES) + .build(); + + List addressConstants = List.of(ADDRESS_LINE_2, ADDRESS_LINE_3, ADDRESS_LINE_4, ADDRESS_LINE_5, POSTCODE_LITERAL); + + Map placeholders = getAddressPlaceholders(testAddress, addressConstants, true); + placeholders.put(ADDRESS_LINE_1, fullNameNoTitle); + + assertEquals("Jane Doe", placeholders.get(ADDRESS_LINE_1)); + assertEquals("Somerset House", placeholders.get(ADDRESS_LINE_2)); + assertEquals("Strand", placeholders.get(ADDRESS_LINE_3)); + assertEquals("London", placeholders.get(ADDRESS_LINE_4)); + assertEquals("Greater London", placeholders.get(ADDRESS_LINE_5)); + assertEquals("WC2R 1LA", placeholders.get(POSTCODE_LITERAL)); + } + + @Test + public void getAddressPlaceholders_returnsExpectedValuesInternationalAddress() { + Address testAddress = Address.builder() + .line1("Catherdrale Notre-Dame de Paris") + .line2("6 Parvis Notre-dame - Pl. Jean-Paul II") + .town("Paris") + .county("Ile-de-France") + .country("France") + .inMainlandUk(YesNo.NO) + .build(); + + List addressConstants = List.of(LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, + LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE); + Map placeholders = getAddressPlaceholders(testAddress, addressConstants, true); + + assertEquals("Catherdrale Notre-Dame de Paris", placeholders.get(LETTER_ADDRESS_LINE_1)); + assertEquals("6 Parvis Notre-dame - Pl. Jean-Paul II", placeholders.get(LETTER_ADDRESS_LINE_2)); + assertEquals("Paris", placeholders.get(LETTER_ADDRESS_LINE_3)); + assertEquals("France", placeholders.get(LETTER_ADDRESS_LINE_4)); + } + + @Test + public void getAddressPlaceholders_returnsExpectedValuesInternationalAddressNoPostcode() { + Address testAddress = Address.builder() + .line1("Catherdrale Notre-Dame de Paris") + .line2("6 Parvis Notre-dame - Pl. Jean-Paul II") + .town("Paris") + .county("Ile-de-France") + .postcode("75004") + .country("France") + .inMainlandUk(YesNo.NO) + .build(); + + List addressConstants = List.of(LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3, + LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE); + Map placeholders = getAddressPlaceholders(testAddress, addressConstants, true); + + assertEquals("Catherdrale Notre-Dame de Paris", placeholders.get(LETTER_ADDRESS_LINE_1)); + assertEquals("6 Parvis Notre-dame - Pl. Jean-Paul II", placeholders.get(LETTER_ADDRESS_LINE_2)); + assertEquals("Paris", placeholders.get(LETTER_ADDRESS_LINE_3)); + assertEquals("75004", placeholders.get(LETTER_ADDRESS_LINE_4)); + assertEquals("France", placeholders.get(LETTER_ADDRESS_POSTCODE)); + + } + + @DisplayName("getAddressPlaceholders returns the expected keys.") + @Test + public void getAddressPlaceholders_returnsExpectedKeys() { + String fullNameNoTitle = "Jane Doe"; + Address testAddress = Address.builder() + .line1("Catherdrale Notre-Dame de Paris") + .line2("6 Parvis Notre-dame - Pl. Jean-Paul II") + .town("Paris") + .county("Ile-de-France") + .postcode("75004") + .country("France") + .inMainlandUk(YesNo.NO) + .build(); + + List addressConstants = List.of(ADDRESS_LINE_2, ADDRESS_LINE_3, ADDRESS_LINE_4, + ADDRESS_LINE_5, POSTCODE_LITERAL); + Map actualPlaceholders = getAddressPlaceholders(testAddress, addressConstants, true); + + actualPlaceholders.put(ADDRESS_LINE_1, fullNameNoTitle); + + for (String addressConstant : addressConstants) { + assertTrue(actualPlaceholders.containsKey(addressConstant) && actualPlaceholders.get(addressConstant) != null); + } + } + + @DisplayName("getAddressPlaceholders truncates address lines over 45 characters when truncate is true.") + @Test + public void getAddressPlaceholders_truncatesLongAddressLinesWhenTruncateTrue() { + Address testAddress = Address.builder() + .line1("This is a very long test address, it should be truncated to a shorter string when getAddressPlaceholders truncate argument is true") + .line2("Test Street") + .town("Test Town") + .county("Test County") + .postcode("TT1 1TT") + .build(); + + List addressConstants = List.of(ADDRESS_LINE_2, ADDRESS_LINE_3, ADDRESS_LINE_4, + ADDRESS_LINE_5, POSTCODE_LITERAL); + + Map placeholders = getAddressPlaceholders(testAddress, addressConstants, true); + assertEquals("This is a very long test address, it should b", placeholders.get(ADDRESS_LINE_2)); + assertEquals("Test Street", placeholders.get(ADDRESS_LINE_3)); + assertEquals("Test Town", placeholders.get(ADDRESS_LINE_4)); + assertEquals("Test County", placeholders.get(ADDRESS_LINE_5)); + assertEquals("TT1 1TT", placeholders.get(POSTCODE_LITERAL)); + } + + @DisplayName("getAddressPlaceholders keeps address lines long when truncate is false.") + @Test + public void getAddressPlaceholders_keepsLongAddressLinesWhenTruncateFalse() { + Address testAddress = Address.builder() + .line1("This is a very long test address, it should be long string when getAddressPlaceholders truncate argument is false") + .line2("Test Street") + .town("Test Town") + .county("Test County") + .postcode("TT1 1TT") + .build(); + + List addressConstants = List.of(ADDRESS_LINE_2, ADDRESS_LINE_3, ADDRESS_LINE_4, + ADDRESS_LINE_5, POSTCODE_LITERAL); + + Map placeholders = getAddressPlaceholders(testAddress, addressConstants, false); + assertEquals("This is a very long test address, it should be long string when getAddressPlaceholders truncate argument is false", placeholders.get(ADDRESS_LINE_2)); + assertEquals("Test Street", placeholders.get(ADDRESS_LINE_3)); + assertEquals("Test Town", placeholders.get(ADDRESS_LINE_4)); + assertEquals("Test County", placeholders.get(ADDRESS_LINE_5)); + assertEquals("TT1 1TT", placeholders.get(POSTCODE_LITERAL)); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/SendNotificationServiceTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/SendNotificationServiceTest.java index 93f1bb293ce..f71c35c17b3 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/SendNotificationServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/SendNotificationServiceTest.java @@ -8,8 +8,14 @@ import static uk.gov.hmcts.reform.sscs.ccd.domain.State.VALID_APPEAL; import static uk.gov.hmcts.reform.sscs.tyanotifications.config.AppConstants.REP_SALUTATION; import static uk.gov.hmcts.reform.sscs.tyanotifications.config.NotificationEventTypeLists.EVENT_TYPES_FOR_BUNDLED_LETTER; -import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.*; -import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.*; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.APPELLANT; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.APPOINTEE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.JOINT_PARTY; +import static uk.gov.hmcts.reform.sscs.tyanotifications.config.SubscriptionType.REPRESENTATIVE; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.APPEAL_RECEIVED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.CASE_UPDATED; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ISSUE_FINAL_DECISION; +import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.STRUCK_OUT; import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.getAddressToUseForLetter; import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationServiceTest.verifyExpectedLogMessage; import static uk.gov.hmcts.reform.sscs.tyanotifications.service.NotificationServiceTest.verifyNoErrorsLogged; @@ -497,6 +503,7 @@ public void givenNonDigitalCase_willNotSendAppealLodgedLetters() { verifyNoInteractions(notificationHandler); } + private void verifyNotificationIsSaved(NotificationHandler.SendNotification sender, NotificationEventType eventType, String ccdCaseId, SubscriptionType subscriptionType) { try { sender.send(); diff --git a/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/docmosis/PdfLetterServiceTest.java b/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/docmosis/PdfLetterServiceTest.java index 66467a92275..4523d7a4dfb 100644 --- a/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/docmosis/PdfLetterServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/sscs/tyanotifications/service/docmosis/PdfLetterServiceTest.java @@ -269,6 +269,7 @@ public void givenAnAddressForARepWithNoName_thenAddressToOrganisationIfExists() ArgumentCaptor> placeholderCaptor = ArgumentCaptor.forClass(Map.class); verify(docmosisPdfService).createPdfFromMap(placeholderCaptor.capture(), eq(notification.getDocmosisLetterTemplate())); + assertEquals("My Company", placeholderCaptor.getValue().get(ADDRESS_NAME)); assertEquals("FirstLine", placeholderCaptor.getValue().get(LETTER_ADDRESS_LINE_1)); assertEquals("SecondLine", placeholderCaptor.getValue().get(LETTER_ADDRESS_LINE_2));