Skip to content

Commit

Permalink
LPD-28121 DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
brianchandotcom committed Jun 11, 2024
1 parent e2e785f commit 0028e9e
Showing 1 changed file with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private void _postNotificationQueueEntry(
HttpHeaders.AUTHORIZATION, authorization
).build();

NotificationTemplate notificationTemplate = null;
NotificationTemplate notificationTemplate;

try {
notificationTemplate =
Expand All @@ -375,18 +375,13 @@ private void _postNotificationQueueEntry(
NotificationQueueEntry notificationQueueEntry =
new NotificationQueueEntry();

String body = notificationTemplate.getBody(
).get(
"en_US"
);

for (Map.Entry<String, String> entry : map.entrySet()) {
body = StringUtil.replace(body, entry.getKey(), entry.getValue());
}

String finalBody = body;

notificationQueueEntry.setBody(() -> finalBody);
notificationQueueEntry.setBody(
() -> _replace(
notificationTemplate.getBody(
).get(
"en_US"
),
map));

JSONArray jsonArray = new JSONObject(
String.valueOf(notificationTemplate)
Expand All @@ -412,20 +407,13 @@ private void _postNotificationQueueEntry(
).build()
});

String subject = notificationTemplate.getSubject(
).get(
"en_US"
);

for (Map.Entry<String, String> entry : map.entrySet()) {
subject = StringUtil.replace(
subject, entry.getKey(), entry.getValue());
}

String finalSubject = subject;

notificationQueueEntry.setSubject(() -> finalSubject);

notificationQueueEntry.setSubject(
() -> _replace(
notificationTemplate.getSubject(
).get(
"en_US"
),
map));
notificationQueueEntry.setType(notificationTemplate::getType);

notificationQueueEntryResource.postNotificationQueueEntry(
Expand Down Expand Up @@ -479,6 +467,15 @@ private PortalInstance _postPortalInstance(
return portalInstance;
}

private String _replace(String string, Map<String, String> map) {
for (Map.Entry<String, String> entry : map.entrySet()) {
string = StringUtil.replace(
string, entry.getKey(), entry.getValue());
}

return string;
}

private void _updateOrder(
Map<String, ?> customFields, long orderId, int orderStatus)
throws Exception {
Expand Down

0 comments on commit 0028e9e

Please sign in to comment.