Created
July 17, 2017 22:45
-
-
Save manjuapu/b1059d6a66c1aacb51268165d6e2efdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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