Skip to content

Commit

Permalink
Update EmailAggregator.java
Browse files Browse the repository at this point in the history
  • Loading branch information
g-duval committed Jul 4, 2024
1 parent cd563ed commit fbbdc92
Showing 1 changed file with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,18 @@ private void aggregationBasedOnEmailAggregation(EmailAggregationKey aggregationK
endpoints
.stream()
.map(EndpointRecipientSettings::new),
getActionRecipientSettings(aggregation)
getActionRecipientSettings(aggregation.getPayload())
).collect(toSet()),
subscribers,
unsubscribers,
eventType.isSubscribedByDefault()
);
} catch (Exception ex) {
Log.error("Error calling external recipients resolver service", ex);
recipients = getRecipients(aggregationKey.getOrgId(), subscribers, getActionRecipientSettings(aggregation), endpoints);
recipients = getRecipients(aggregationKey.getOrgId(), subscribers, getActionRecipientSettings(aggregation.getPayload()), endpoints);
}
} else {
recipients = getRecipients(aggregationKey.getOrgId(), subscribers, getActionRecipientSettings(aggregation), endpoints);
recipients = getRecipients(aggregationKey.getOrgId(), subscribers, getActionRecipientSettings(aggregation.getPayload()), endpoints);
}

/*
Expand Down Expand Up @@ -210,18 +210,18 @@ private void aggregationBasedOnEvent(EventAggregationCriteria eventAggregationCr
endpoints
.stream()
.map(EndpointRecipientSettings::new),
getActionRecipientSettings(aggregation)
getActionRecipientSettings(new JsonObject(aggregation.getPayload()))
).collect(toSet()),
subscribers,
unsubscribers,
eventType.isSubscribedByDefault()
);
} catch (Exception ex) {
Log.error("Error calling external recipients resolver service", ex);
recipients = getRecipients(aggregation.getOrgId(), subscribers, getActionRecipientSettings(aggregation), endpoints);
recipients = getRecipients(aggregation.getOrgId(), subscribers, getActionRecipientSettings(new JsonObject(aggregation.getPayload())), endpoints);
}
} else {
recipients = getRecipients(aggregation.getOrgId(), subscribers, getActionRecipientSettings(aggregation), endpoints);
recipients = getRecipients(aggregation.getOrgId(), subscribers, getActionRecipientSettings(new JsonObject(aggregation.getPayload())), endpoints);
}

/*
Expand Down Expand Up @@ -260,22 +260,7 @@ private String getEventType(EmailAggregation aggregation) {
return aggregation.getPayload().getString(EVENT_TYPE_KEY);
}

private Stream<ActionRecipientSettings> getActionRecipientSettings(EmailAggregation emailAggregation) {
if (emailAggregation.getPayload().containsKey(RECIPIENTS_KEY)) {
JsonArray recipients = emailAggregation.getPayload().getJsonArray(RECIPIENTS_KEY);
if (!recipients.isEmpty()) {
return recipients.stream().map(r -> {
JsonObject recipient = (JsonObject) r;
return recipient.mapTo(Recipient.class);
}).map(r -> new ActionRecipientSettings(r.getOnlyAdmins(), r.getIgnoreUserPreferences(), r.getUsers(), r.getEmails()));
}

}
return Stream.empty();
}

private Stream<ActionRecipientSettings> getActionRecipientSettings(Event emailAggregation) {
JsonObject payload = new JsonObject(emailAggregation.getPayload());
private Stream<ActionRecipientSettings> getActionRecipientSettings(JsonObject payload) {
if (payload.containsKey(RECIPIENTS_KEY)) {
JsonArray recipients = payload.getJsonArray(RECIPIENTS_KEY);
if (!recipients.isEmpty()) {
Expand All @@ -287,5 +272,4 @@ private Stream<ActionRecipientSettings> getActionRecipientSettings(Event emailAg
}
return Stream.empty();
}

}

0 comments on commit fbbdc92

Please sign in to comment.