Skip to content

Instantly share code, notes, and snippets.

@miguno
Created July 19, 2017 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguno/bdaa2100255ffd88a1ad81ec19b7c260 to your computer and use it in GitHub Desktop.
Save miguno/bdaa2100255ffd88a1ad81ec19b7c260 to your computer and use it in GitHub Desktop.
public static List<KeyValue<SpecificRecord, OutboundMessage>> generateAlerts(AccountEntry accountEntry,
CustomerAlertSettings settings) {
/* Generates addressed alerts for an AccountEntry, using the alert settings with the following steps:
* 1) Settings are for a specific account, drop AccountEntries not for this account
* 2) Match each setting with all alerts to generate appropriate messages
* 3) Address the generated messages
*/
if (settings == null) {
return new ArrayList<>();
}
return settings.getAccountAlertSettings().stream()
.filter(accountAlertSettings -> matchAccount(accountEntry, accountAlertSettings))
.flatMap(accountAlertSettings -> accountAlertSettings.getSettings().stream())
.flatMap(accountAlertSetting -> Stream.of(
generateBalanceAbove(accountEntry, accountAlertSetting),
generateBalanceBelow(accountEntry, accountAlertSetting),
generateCreditedAbove(accountEntry, accountAlertSetting),
generateDebitedAbove(accountEntry, accountAlertSetting))
)
.filter(Optional::isPresent).map(Optional::get)
.flatMap(messageWithChannels -> mapAddresses(messageWithChannels.getValue0(), settings.getAddresses())
.map(address -> KeyValue.pair(address, messageWithChannels.getValue1())))
.collect(toList());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment