forked from forcedotcom/AnalyticsApexSteps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWDController.cls
101 lines (79 loc) · 3.95 KB
/
WDController.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Returns data from a Workday Reporting as a Service report (RaaS)
* It requires that you setup a Named Credential in Salesforce Setup
* so you don't have to show the login/pw credentials in the code
*
*
* @author geoffrothman
*/
@RestResource(urlMapping='/wdraas')
global class WDController {
@HttpPost
global static String wdraas() {
// fetch data
HttpRequest request = new HttpRequest();
Http http = new Http();
// make sure this domain is whitelisted in the proxy
//request.setEndpoint('https://wd2-impl-services1.workday.com/ccx/service/customreport2/salesforce9/sfdc_integration_user1/Einstein-Job-Catalog?format=json');
request.setEndpoint('callout:WorkdayRaaS_Named_Credential');
request.setMethod('GET');
try {
HTTPResponse response = http.send(request);
JSONParser parser = JSON.createParser(response.getBody());
while (parser.nextToken() != null) {
// find the report entry part of the json
if (parser.getCurrentToken() == JSONToken.START_OBJECT) {
WDClass responseObject = (WDClass)parser.readValueAs(WDClass.class);
List<ReturnItem> returnItems = new List<ReturnItem>();
for (WDClass.Report_Entry currWDRecord : responseObject.Report_Entry) {
returnItems.add(new ReturnItem(1,currWDRecord.Comp_Plan_Id, currWDRecord.Job_Profile, currWDRecord.Job_Code, currWDRecord.Is_Commission_Plan, currWDRecord.Is_Bonus_Plan));
}
Integer NumItems = returnItems.size();
System.debug('Final JSON -->' + JSON.serialize(new PackagedReturnItem(returnItems,NumItems),TRUE));
return JSON.serialize(new PackagedReturnItem(returnItems,NumItems),TRUE);
}
}
} catch(Exception exp) {
System.debug('exception '+exp);
}
return '';
}
public class ReturnItem {
public Integer Count;
public String Comp_Plan_Id;
public String Job_Profile;
public String Job_Code;
public String Is_Commission_Plan;
public String Is_Bonus_Plan;
public ReturnItem(Integer Count, String Comp_Plan_Id, String Job_Profile, String Job_Code, String Is_Commission_Plan, String Is_Bonus_Plan) {
this.Count = Count;
this.Comp_Plan_Id = Comp_Plan_Id;
this.Job_Profile = Job_Profile;
this.Job_Profile = Job_Code;
this.Job_Profile = Is_Commission_Plan;
this.Job_Profile = Is_Bonus_Plan;
}
}
public class ReturnMetadata {
public List<String> strings;
public List<String> numbers;
public List<String> groups;
public ReturnMetadata(List<String> strings, List<String> numbers, List<String> groups) {
this.strings = strings;
this.numbers = numbers;
this.groups = groups;
}
}
public class PackagedReturnItem {
public List<ReturnItem> data;
public ReturnMetadata metadata;
public Integer NumItems;
// put the actual values in this method
public PackagedReturnItem(List<ReturnItem> data, Integer NumItems) {
this.data = data;
//this.metadata = new ReturnMetadata(new List<String>{'Comp_Plan_Id','Job_Code','Is_Commission_Plan','Is_Bonus_Plan','Job_Profile'}, new List<String>{'Count'}, new List<String>{'Comp_Plan_Id'});
this.metadata = new ReturnMetadata(new List<String>{'Comp_Plan_Id','Job_Code','Is_Commission_Plan','Is_Bonus_Plan','Job_Profile'}, new List<String>{'Count'}, new List<String>());
this.NumItems = NumItems;
}
}
}