Guest User

Untitled

a guest
Jul 15th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. public class AllocationManager {
  2. String url = 'https://myapi.url';
  3. // Pass in the endpoint to be used using the string url
  4. @AuraEnabled
  5. public AllocationOutput getAllocationBreakdown() {
  6.  
  7. String jsonstr = '{"returnSecurityDetails":"true","displayLevel":"1","portfolios":[{"portfolioName":"Portfolio A","cashBalance":5000,"holdings":[{"symbol":"IVV","holdingValue":50000},{"symbol":"IWM","holdingValue":25000},{"symbol":"VWO","holdingValue":10000},{"symbol":"AAPL","holdingValue":5000}]},{"portfolioName":"Portfolio B","cashBalance":5000,"holdings":[{"symbol":"VIG","holdingValue":50000},{"symbol":"VO","holdingValue":25000},{"symbol":"VB","holdingValue":10000},{"symbol":"EFA","holdingValue":5000}]}]}';
  8. AllocationInput obj = AllocationInput.parse(jsonstr);
  9. String allocInput = JSON.serialize(obj);
  10. //System.debug(allocInput);
  11.  
  12. // Instantiate a new http object
  13. Http h = new Http();
  14.  
  15. // Instantiate a new HTTP request, specify the method (POST) as well as the endpoint
  16. HttpRequest req = new HttpRequest();
  17. req.setHeader('Authorization', 'MY_CLIENT client_id=xxxxxx client_secret=xxxxxxxxxxxxxx');
  18. req.setHeader('Content-Type', 'application/json');
  19. req.setHeader('Accept','application/json');
  20. req.setEndpoint(url);
  21. req.setMethod('POST');
  22. req.setBody(allocInput);
  23.  
  24. // Send the request, and return a response
  25. HttpResponse res = h.send(req);
  26.  
  27. String allocOutput = res.getBody();
  28. //System.debug(allocOutput);
  29. AllocationOutput output = AllocationOutput.parse(allocOutput);
  30. return output;
  31. }
  32. }
  33.  
  34. public class AllocationInput {
  35.  
  36. public class Holdings {
  37. public String symbol;
  38. public Integer holdingValue;
  39. }
  40.  
  41. public String returnSecurityDetails;
  42. public String displayLevel;
  43. public List<Portfolios> portfolios;
  44.  
  45. public class Portfolios {
  46. public String portfolioName;
  47. public Integer cashBalance;
  48. public List<Holdings> holdings;
  49. }
  50.  
  51.  
  52. public static AllocationInput parse(String json) {
  53. return (AllocationInput) System.JSON.deserialize(json, AllocationInput.class);
  54. }
  55. }
  56.  
  57. public class AllocationOutput {
  58.  
  59. public class PortfolioStyles {
  60. public String styleID;
  61. public String styleName;
  62. public String styleAllocation;
  63. public String styleValue;
  64. }
  65.  
  66. public String apiVersion;
  67. public String timestamp;
  68. public String tenantName;
  69. public List<Portfolios> portfolios;
  70. public String asOfDate;
  71.  
  72. public class Portfolios {
  73. public String portfolioName;
  74. public String portfolioValue;
  75. public List<PortfolioStyles> portfolioStyles;
  76. public List<SecurityDetails> securityDetails;
  77. }
  78.  
  79. public class SecurityDetails {
  80. public String securityId;
  81. public String symbol;
  82. public String name;
  83. public List<PortfolioStyles> securityStyles;
  84. }
  85.  
  86.  
  87. public static AllocationOutput parse(String json) {
  88. return (AllocationOutput) System.JSON.deserialize(json, AllocationOutput.class);
  89. }
  90. }
  91.  
  92. <aura:application controller="AllocationManager">
  93. <ltng:require afterScriptsLoaded="{!c.myAction}" />
  94. <aura:attribute name="redString" type="String" />
  95. <div>
  96. <br />
  97. <br />
  98. <p style="color:red;">{!v.redString}</p>
  99. <br />
  100. <br />
  101. </div>
  102. </aura:application>
  103.  
  104. ({
  105. myAction: function(component, event, helper) {
  106.  
  107. var action = component.get("c.getAllocationBreakdown");
  108. var self = this;
  109.  
  110. action.setCallback(this, function(response) {
  111. var state = response.getState();
  112. // console.log(state);
  113. $A.log(response);
  114. if (state === "SUCCESS") {
  115. component.set("v.redString", response.getReturnValue());
  116. // self.updateTotal(component);
  117. console.log("response.getReturnValue() is " + response.getReturnValue());
  118. // console.log(response.getReturnValue());
  119. }
  120. });
  121. $A.enqueueAction(action);
  122. }
  123. })
  124.  
  125. @AuraEnabled
  126. public static AllocationOutput getAllocationBreakdown() {
  127. ...
  128. }
Add Comment
Please, Sign In to add comment