-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from 15 commits
891a28d
1233555
a3d21bc
f06697c
6589b3e
2339f44
66d6645
c8d87e5
9c1b6a7
250b932
04254d5
9c49a70
40b7208
c2e62a5
4bfb671
357c032
fef1245
3e10e2a
82f19a5
2c3fb4b
19a218d
b2bc5ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -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.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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 |
---|---|---|
@@ -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.*; | ||
|
@@ -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; | ||
|
@@ -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())) { | ||
|
@@ -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 | ||
|
@@ -404,4 +416,8 @@ private static String getDocumentForType(AbstractDocument sscsDocument) { | |
return null; | ||
} | ||
|
||
private static String defaultToEmptyStringIfNull(String value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be in letterUtils? |
||
return (value == null) ? StringUtils.EMPTY : value; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.