Created
July 19, 2017 09:39
-
-
Save miguno/bdaa2100255ffd88a1ad81ec19b7c260 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()); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full code at https://github.com/Axual/rabo-alerts-blog-post/blob/master/src/main/java/BalanceAlertsGenerator.java