Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. callActions : function(component, event, helper){
  2. var params;
  3. var result;
  4. var message;
  5. component.set("v.isLoading",true);
  6. var stage = event.getSource().get("v.value");
  7. var action = component.get("c.checkActionConditions");
  8. var header = component.get("v.actionHeaderMAP")[stage];
  9. console.log('***header: ' + JSON.stringify(header));
  10. action.setParams({
  11. "recordId" : component.get("v.recordId"),
  12. "logicConditions" : header.hasOwnProperty('logicConditions') ? header.logicConditions : null,
  13. "message" : header.hasOwnProperty('message') ? header.message : null,
  14. "conditionLIST" : header.hasOwnProperty('conditionLIST') ? header.conditionLIST : null,
  15. "parentAction" : header.hasOwnProperty('parentAction') ? header.parentAction : null
  16. });
  17. action.setCallback(this, function(response){
  18. if(response.getState() === 'SUCCESS'){
  19. result = response.getReturnValue();
  20. if(result.success){
  21. //Start processing
  22. if(header.hasOwnProperty('actionHeaderStepLIST') && header.actionHeaderStepLIST.length > 0){
  23. component.set("v.header", header);
  24. helper.manageActionsOneByOne(component);
  25. }
  26. //No actions to process
  27. else{
  28. message = 'No se encuentran acciones a gestionar para el proceso ' + header.name;
  29. params = {"title":"Error","message":message,"duration":5000,"type":"error"};
  30. helper.generateToast(params);
  31. component.set("v.isLoading",false);
  32. }
  33. }
  34. else{
  35. message = result.message;
  36. params = {"title":"Error","message":message,"duration":5000,"type":"error"};
  37. helper.generateToast(params);
  38. component.set("v.isLoading",false);
  39. }
  40. }
  41. else{
  42. console.log('****error: '+ JSON.stringify(response.getError()));
  43. message = helper.getErrorMessage(response.getError()[0]);
  44. params = {"title":"Error","message":message,"duration":5000,"type":"error"};
  45. helper.generateToast(params);
  46. component.set("v.isLoading",false);
  47. }
  48. });
  49. $A.enqueueAction(action);
  50.  
  51. @AuraEnabled
  52. public static BI_LEX_GenericApprovalActionControl.response checkActionConditions(String recordId, String logicConditions, String message, List<BI_LEX_Condition__c> conditionLIST, String parentAction){
  53. BI_LEX_GenericApprovalActionControl.response result = new BI_LEX_GenericApprovalActionControl.response();
  54. String query;
  55. String auxString;
  56. //Auxiliar BI_LEX_Condition__c record
  57. BI_LEX_Condition__c cd;
  58. List<SObject> checkLIST;
  59. Boolean byPassParent = true;
  60. //Map of condition by BI_LEX_Numero_condicion__c or generic index (if logicConditions has no value)
  61. Map<String,String> conditionByNumberMAP = new Map<String,String>();
  62. //For boolean values check
  63. Set<String> booleanSET = new Set<String>{'true','false'};
  64. //Check parent action if found
  65. if(parentAction != null){
  66. result = BI_LEX_GenericApprovalActionControl.parentActionCheck(parentAction);
  67. byPassParent = result.success;
  68. }
  69. //No parent action or parent action previously approved
  70. if(byPassParent){
  71. //Check conditions for record
  72. if(conditionLIST != null && !conditionLIST.isEmpty()){
  73. checkLIST = new List<SObject>();
  74. for(Integer i=0; i<conditionLIST.size(); i++){
  75. cd = conditionLIST[i];
  76. auxString = cd.BI_LEX_FieldAPIName__c + ' = ' + (cd.BI_LEX_FieldValue__c.isNumeric() || booleanSET.contains(cd.BI_LEX_FieldValue__c.toLowerCase()) ? cd.BI_LEX_FieldValue__c : ''' + cd.BI_LEX_FieldValue__c + ''');
  77. //Logic conditions and number of condition is not null
  78. if(logicConditions != null && !String.isEmpty(logicConditions) && cd.BI_LEX_Numero_condicion__c != null){
  79. conditionByNumberMAP.put(String.valueOf(cd.BI_LEX_Numero_condicion__c), auxString);
  80. }
  81. //All conditions joined by AND
  82. else{
  83. conditionByNumberMAP.put(String.valueOf(i), auxString);
  84. }
  85. }
  86. //Get conditions (based on logic)
  87. if(logicConditions != null && !String.isEmpty(logicConditions)){
  88. //Replace conditions with valid ones
  89. List<String> charList = logicConditions.split('');
  90. for(String key : charLIST){
  91. if(key.isNumeric() && conditionByNumberMAP.containsKey(key)){
  92. charLIST[charLIST.indexOf(key)] = conditionByNumberMAP.get(key);
  93. }
  94. }
  95. logicConditions = String.join(charLIST, '');
  96. }
  97. //Add them as AND string
  98. else{
  99. logicConditions = '';
  100. for(String key : conditionByNumberMAP.keySet()){
  101. logicConditions += String.isEmpty(logicConditions) ? conditionByNumberMAP.get(key) : ' AND ' + conditionByNumberMAP.get(key);
  102. }
  103. }
  104. query = 'SELECT Id FROM ' + Id.valueOf(recordId).getSObjectType().getDescribe().getName() + ' WHERE Id = :recordId AND ' + logicConditions;
  105. checkLIST = Database.query(query);
  106. result.success = checkLIST.isEmpty() ? false : true;
  107. result.message = checkLIST.isEmpty() ? message : null;
  108. }
  109. //No conditions to check
  110. else{
  111. result.success = true;
  112. }
  113. }
  114. return result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement