RecordAlertProvider Example Implementation

This is an example implementation of the fscwmgen.RecordAlertProvider interface.

The following example tests the implementation:

1global class CoreBankingAlertProvider implements fscwmgen.RecordAlertProvider {
2
3    public List<fscwmgen.RecordAlertInfo> getAlertsByWhatId(String whatId) {
4        HttpRequest req = new HttpRequest();
5        // This callout is specific to the Core banking.
6        req.setEndpoint('callout:My_Named_Credential/get_by_whatId');
7        req.setMethod('GET');
8        Http http = new Http();
9        HTTPResponse res = http.send(req);
10        Map<String, Object> jsonResp = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
11        List<Object> results = (List<Object>) jsonResp.get('results');
12
13        List<fscwmgen.RecordAlertInfo> newAlerts = new List<fscwmgen.RecordAlertInfo>();
14        // Assuming CoreBankingResult is an apex class holding the result from CoreBanking.
15        for(CoreBankingResult res : results){
16            fscwmgen.RecordAlertInfo newAlert = convertCoreBankingAlertToSalesforceAlert(res, whatId, null);
17            newAlerts.add(newAlert);
18        }
19
20        // Return the list of alerts
21        return newAlerts;
22    }
23
24    public List<fscwmgen.RecordAlertInfo> getAlertsByParentId(String parentId) {
25        HttpRequest req = new HttpRequest();
26        // This callout is specific to the Core banking.
27        req.setEndpoint('callout:My_Named_Credential/get_by_parentId');
28        req.setMethod('GET');
29        Http http = new Http();
30        HTTPResponse res = http.send(req);
31        Map<String, Object> jsonResp = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
32        List<Object> results = (List<Object>) jsonResp.get('results');
33
34        List<fscwmgen.RecordAlertInfo> newAlerts = new List<fscwmgen.RecordAlertInfo>();
35        // Assuming CoreBankingResult is an apex class holding the result from CoreBanking.
36        for(CoreBankingResult res : results){
37            // Retrieve whatId for this specific alert. Can be queried from Salesforce or provided by CoreBanking.
38            String whatId = retrieveWhatId();
39            fscwmgen.RecordAlertInfo newAlert = convertCoreBankingAlertToSalesforceAlert(res, whatId, parentId);
40            newAlerts.add(newAlert);
41        }
42
43        // Return the list of alerts
44        return newAlerts;
45    }
46
47    public List<fscwmgen.RecordAlertInfo> getAlertsByWhatIdAndParentId(String whatId, String parentId) {
48        HttpRequest req = new HttpRequest();
49        // This callout is specific to the Core banking.
50        req.setEndpoint('callout:My_Named_Credential/get_by_whatId_and_parentId');
51        req.setMethod('GET');
52        Http http = new Http();
53        HTTPResponse res = http.send(req);
54        Map<String, Object> jsonResp = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
55        List<Object> results = (List<Object>) jsonResp.get('results');
56
57        List<fscwmgen.RecordAlertInfo> newAlerts = new List<fscwmgen.RecordAlertInfo>();
58        // Assuming CoreBankingResult is an apex class holding the result from CoreBanking.
59        for(CoreBankingResult res : results){
60            fscwmgen.RecordAlertInfo newAlert = convertCoreBankingAlertToSalesforceAlert(res, whatId, parentId);
61            newAlerts.add(newAlert);
62        }
63
64        // Return the list of alerts
65        return newAlerts;
66    }
67
68    public fscwmgen.RecordAlertInfo snoozeAlert(String alertId, Datetime snoozeUntilDate){
69        HttpRequest req = new HttpRequest();
70        // This callout is specific to the Core banking.
71        req.setEndpoint('callout:My_Named_Credential/snoozeAlert');
72        req.setMethod('GET');
73        Http http = new Http();
74        HTTPResponse res = http.send(req);
75        // Perform error handling on response. Below code is when the response is valid.
76        Map<String, Object> jsonResp = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
77        List<Object> results = (List<Object>) jsonResp.get('results');
78        // Retrieve whatId from corebanking result. Other mechanism is to lookup from salesforce.
79        String whatId = results.get(0).getId();
80        return convertCoreBankingAlertToSalesforceAlert(results.get(0));
81    }
82
83    public fscwmgen.RecordAlertInfo dismissAlert(String alertId) {
84        HttpRequest req = new HttpRequest();
85        // This callout is specific to the Core banking.
86        req.setEndpoint('callout:My_Named_Credential/snoozeAlert');
87        req.setMethod('GET');
88        Http http = new Http();
89        HTTPResponse res = http.send(req);
90        // Perform error handling on response. Below code is when the response is valid.
91        Map<String, Object> jsonResp = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
92        List<Object> results = (List<Object>) jsonResp.get('results');
93        / Retrieve whatId from corebanking result. Other mechanism is to lookup from salesforce.
94        String whatId = results.get(0).getId();
95        return convertCoreBankingAlertToSalesforceAlert(results.get(0));
96    }
97
98    private RecordAlertInfo convertCoreBankingAlertToSalesforceAlert(CoreBankingResult alert, String whatId, String parentId) {
99        fscwmgen.RecordAlertInfo newAlert = new fscwmgen.RecordAlertInfo();
100        newAlert.subject = alert.getSubject();
101        newAlert.description = alert.getDescription();
102        newAlert.sourceSystemId = alert.getId();
103        newAlert.parentId = parentId;
104        newAlert.whatId = whatId;
105        // This could also use conversion from Core Banking category to salesforce RecordAlertCategory
106        newAlert.categoryFullName = 'Fraud';
107
108        newAlert.actionInfoList = new List<fscwmgen.RecordAlertActionInfo>();
109        // snooze Action
110        fscwmgen.RecordAlertActionInfo snooze = new fscwmgen.RecordAlertActionInfo();
111        snooze.actionName = 'snooze';
112        snooze.parameters = new List<String>();
113        // SnoozeUntilDate is required parameter
114        snooze.parameters.add('snoozeUntilDate');
115        newAlert.actionInfoList.add(snooze);
116
117        // Dismiss Action
118        fscwmgen.RecordAlertActionInfo dismiss = new fscwmgen.RecordAlertActionInfo();
119        dismiss.actionName = 'dismiss';
120        newAlert.actionInfoList.add(dismiss);
121
122        return newAlert;
123    }
124}