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

SSCSCI-1137 - Update Docmosis address logic #4093

Merged
merged 22 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
891a28d
Implement logic to handle international addresses for Docmosis templa…
Ziziou91 Oct 28, 2024
1233555
Implement logic to handle international addresses for Docmosis templa…
Ziziou91 Oct 28, 2024
a3d21bc
Merge branch 'master' into SSCSCI-1137
Ziziou91 Oct 28, 2024
f06697c
Remove unused files.
Ziziou91 Oct 28, 2024
6589b3e
Merge branch 'SSCSCI-1137' of https://github.com/hmcts/sscs-tribunals…
Ziziou91 Oct 28, 2024
2339f44
update path for APPEAL_RECEIVED docmosis letter template
Ziziou91 Oct 29, 2024
66d6645
update LetterUtils imports and revert appeal-received letter template…
Ziziou91 Oct 29, 2024
c8d87e5
Update appeal-received letter template name to IBA
Ziziou91 Oct 31, 2024
9c1b6a7
Update notification tests.
Ziziou91 Oct 31, 2024
250b932
Refactor to use Address method getFullAddress.
Ziziou91 Nov 1, 2024
04254d5
Refactor to use Address method getFullAddress.
Ziziou91 Nov 1, 2024
9c49a70
Revert back to using lines for addresses to satisfy IssueFurtherEvide…
Ziziou91 Nov 4, 2024
40b7208
lines now returns List<String>
Ziziou91 Nov 4, 2024
c2e62a5
Update to use correct mapping constants. Refactor to allow unit testing.
Ziziou91 Nov 5, 2024
4bfb671
Update LETTER_ADDRESS_POSTCODE in PlaceholderConstants
Ziziou91 Nov 5, 2024
357c032
remove System.out.println
Ziziou91 Nov 5, 2024
fef1245
Correct formatting of Ile-de-France.
Ziziou91 Nov 6, 2024
3e10e2a
Add 10 seconds to delay to allow respons from simulateCcdCallback
Ziziou91 Nov 6, 2024
82f19a5
Refactor letter services to use getAddressPlaceholders and remove wil…
Ziziou91 Nov 9, 2024
2c3fb4b
Refactor letter services to use getAddressPlaceholders and remove wil…
Ziziou91 Nov 9, 2024
19a218d
Merge branch 'master' into SSCSCI-1137
Ziziou91 Nov 10, 2024
b2bc5ff
Merge branch 'master' into SSCSCI-1137
Ziziou91 Nov 11, 2024
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
Empty file added cftlib_log_file_IS_UNDEFINED
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed? Can it be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for flagging. Wasn't needed and has been removed.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
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.PlaceholderUtility.defaultToEmptyStringIfNull;
import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderUtility.truncateAddressLine;
import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.lines;

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;
Expand Down Expand Up @@ -104,14 +105,14 @@ private String getAppealReference(SscsCaseData caseData) {

private Map<String, Object> getAddressPlaceHolders(Address address) {
var addressPlaceHolders = new HashMap<String, Object>();
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};
List<String> addressConstants = List.of(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])));
}
List<String> lines = lines(address);

for (int i = 0; i < lines.size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that this same logic is repeated for most calls to lines(), is it worth incorporating it into the method (or creating a separate method that calls it), and passing a boolean to decide whether or not to truncate

addressPlaceHolders.put(addressConstants.get(i), truncateAddressLine(defaultToEmptyStringIfNull(lines.get(i))));
}
return addressPlaceHolders;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderConstants.*;
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.lines;

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;
Expand Down Expand Up @@ -113,29 +113,13 @@ public boolean hasRegionalProcessingCenter(SscsCaseData ccdResponse) {
}

private void buildRecipientAddressPlaceholders(Address address, Map<String, Object> placeholders) {
String[] lines = lines(address);
List<String> 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);

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])));
}
}
List<String> lines = lines(address);

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);
for (int i = 0; i < lines.size(); i++) {
placeholders.put(addressConstants.get(i), truncateAddressLine(defaultToEmptyStringIfNull(lines.get(i))));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
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.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmcts style guidelines recommend not using wildcard imports

import static uk.gov.hmcts.reform.sscs.evidenceshare.service.placeholders.PlaceholderService.lines;
import static uk.gov.hmcts.reform.sscs.tyanotifications.service.LetterUtils.lines;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -174,14 +175,14 @@ private static boolean isValidName(Name name) {

static Map<String, Object> getAddressPlaceHolders(Address address) {
var addressPlaceHolders = new HashMap<String, Object>();
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};
List<String> addressConstants = List.of(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])));
}
List<String> lines = lines(address);

for (int i = 0; i < lines.size(); i++) {
addressPlaceHolders.put(addressConstants.get(i), truncateAddressLine(defaultToEmptyStringIfNull(lines.get(i))));
}
return addressPlaceHolders;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
nilay913 marked this conversation as resolved.
Show resolved Hide resolved

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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,16 @@ static boolean isValidOtherPartyRepresentative(String subscriptionPartyId, Strin
}
return false;
}

public static List<String> lines(Address address) {
if (isYes(address.getInMainlandUk()) || address.getInMainlandUk() == null) {
return Stream.of(address.getLine1(), address.getLine2(), address.getTown(), address.getCounty(), address.getPostcode())
.filter(x -> x != null)
.toList();
} else {
return Stream.of(address.getLine1(), address.getLine2(), address.getTown(), address.getPostcode(), address.getCountry())
.filter(x -> x != null)
.toList();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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.*;
Expand All @@ -20,11 +19,14 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -224,17 +226,12 @@ 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<String, Object> 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());
placeholders.putAll(getAddressPlaceholders(address, fullNameNoTitle));

placeholders.put(NAME, fullNameNoTitle);
if (SubscriptionType.REPRESENTATIVE.equals(subscriptionWithType.getSubscriptionType())) {
Expand All @@ -250,19 +247,34 @@ 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,
wrapper.getCaseId()
);
}
}

public static Map<String, Object> getAddressPlaceholders(final Address address, String fullNameNoTitle) {
Map<String, Object> addressPlaceHolders = new HashMap<>();

addressPlaceHolders.put(ADDRESS_LINE_1, fullNameNoTitle);

List<String> addressConstants = List.of(ADDRESS_LINE_2, ADDRESS_LINE_3, ADDRESS_LINE_4,
ADDRESS_LINE_5, POSTCODE_LITERAL);

List<String> lines = lines(address);

for (int i = 0; i < lines.size(); i++) {
addressPlaceHolders.put(addressConstants.get(i), defaultToEmptyStringIfNull(lines.get(i)));
}
return addressPlaceHolders;
}

private static boolean isValidLetterAddress(Address addressToUse) {
return null != addressToUse
Expand Down Expand Up @@ -404,4 +416,8 @@ private static String getDocumentForType(AbstractDocument sscsDocument) {
return null;
}

private static String defaultToEmptyStringIfNull(String value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be in letterUtils?

return (value == null) ? StringUtils.EMPTY : value;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package uk.gov.hmcts.reform.sscs.tyanotifications.service.docmosis;

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.*;
import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.APPEAL_RECEIVED;
import static uk.gov.hmcts.reform.sscs.tyanotifications.personalisation.Personalisation.translateToWelshDate;
Expand All @@ -12,7 +17,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;
Expand Down Expand Up @@ -114,6 +118,7 @@ public byte[] generateLetter(NotificationWrapper wrapper, Notification notificat

Address addressToUse = getAddressToUseForLetter(wrapper, subscriptionWithType);
buildRecipientAddressPlaceholders(addressToUse, placeholders);

placeholders.put(docmosisTemplatesConfig.getHmctsImgKey(), docmosisTemplatesConfig.getHmctsImgVal());
placeholders.put(docmosisTemplatesConfig.getHmctsWelshImgKey(), docmosisTemplatesConfig.getHmctsWelshImgVal());

Expand All @@ -128,29 +133,13 @@ public byte[] generateLetter(NotificationWrapper wrapper, Notification notificat
}

private void buildRecipientAddressPlaceholders(Address address, Map<String, Object> placeholders) {
String[] lines = lines(address);
List<String> addressConstants = List.of(LETTER_ADDRESS_LINE_1, LETTER_ADDRESS_LINE_2, LETTER_ADDRESS_LINE_3,
LETTER_ADDRESS_LINE_4, LETTER_ADDRESS_POSTCODE);
List<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])));
for (int i = 0; i < lines.size(); i++) {
placeholders.put(addressConstants.get(i), truncateAddressLine(defaultToEmptyStringIfNull(lines.get(i))));
}
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) {
Expand All @@ -162,4 +151,3 @@ private static String truncateAddressLine(String addressLine) {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ void shouldReturnEmptyAddressPlaceholdersGivenEmptyAddress() {

Map<String, Object> placeholders = genericLetterPlaceholderService.populatePlaceholders(caseData, APPELLANT_LETTER,
null);

assertNotNull(placeholders);
assertFalse(placeholders.containsKey(LETTER_ADDRESS_LINE_1));
assertFalse(placeholders.containsKey(LETTER_ADDRESS_LINE_2));
Expand Down
Loading
Loading