Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- callActions : function(component, event, helper){
- var params;
- var result;
- var message;
- component.set("v.isLoading",true);
- var stage = event.getSource().get("v.value");
- var action = component.get("c.checkActionConditions");
- var header = component.get("v.actionHeaderMAP")[stage];
- console.log('***header: ' + JSON.stringify(header));
- action.setParams({
- "recordId" : component.get("v.recordId"),
- "logicConditions" : header.hasOwnProperty('logicConditions') ? header.logicConditions : null,
- "message" : header.hasOwnProperty('message') ? header.message : null,
- "conditionLIST" : header.hasOwnProperty('conditionLIST') ? header.conditionLIST : null,
- "parentAction" : header.hasOwnProperty('parentAction') ? header.parentAction : null
- });
- action.setCallback(this, function(response){
- if(response.getState() === 'SUCCESS'){
- result = response.getReturnValue();
- if(result.success){
- //Start processing
- if(header.hasOwnProperty('actionHeaderStepLIST') && header.actionHeaderStepLIST.length > 0){
- component.set("v.header", header);
- helper.manageActionsOneByOne(component);
- }
- //No actions to process
- else{
- message = 'No se encuentran acciones a gestionar para el proceso ' + header.name;
- params = {"title":"Error","message":message,"duration":5000,"type":"error"};
- helper.generateToast(params);
- component.set("v.isLoading",false);
- }
- }
- else{
- message = result.message;
- params = {"title":"Error","message":message,"duration":5000,"type":"error"};
- helper.generateToast(params);
- component.set("v.isLoading",false);
- }
- }
- else{
- console.log('****error: '+ JSON.stringify(response.getError()));
- message = helper.getErrorMessage(response.getError()[0]);
- params = {"title":"Error","message":message,"duration":5000,"type":"error"};
- helper.generateToast(params);
- component.set("v.isLoading",false);
- }
- });
- $A.enqueueAction(action);
- @AuraEnabled
- public static BI_LEX_GenericApprovalActionControl.response checkActionConditions(String recordId, String logicConditions, String message, List<BI_LEX_Condition__c> conditionLIST, String parentAction){
- BI_LEX_GenericApprovalActionControl.response result = new BI_LEX_GenericApprovalActionControl.response();
- String query;
- String auxString;
- //Auxiliar BI_LEX_Condition__c record
- BI_LEX_Condition__c cd;
- List<SObject> checkLIST;
- Boolean byPassParent = true;
- //Map of condition by BI_LEX_Numero_condicion__c or generic index (if logicConditions has no value)
- Map<String,String> conditionByNumberMAP = new Map<String,String>();
- //For boolean values check
- Set<String> booleanSET = new Set<String>{'true','false'};
- //Check parent action if found
- if(parentAction != null){
- result = BI_LEX_GenericApprovalActionControl.parentActionCheck(parentAction);
- byPassParent = result.success;
- }
- //No parent action or parent action previously approved
- if(byPassParent){
- //Check conditions for record
- if(conditionLIST != null && !conditionLIST.isEmpty()){
- checkLIST = new List<SObject>();
- for(Integer i=0; i<conditionLIST.size(); i++){
- cd = conditionLIST[i];
- 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 + ''');
- //Logic conditions and number of condition is not null
- if(logicConditions != null && !String.isEmpty(logicConditions) && cd.BI_LEX_Numero_condicion__c != null){
- conditionByNumberMAP.put(String.valueOf(cd.BI_LEX_Numero_condicion__c), auxString);
- }
- //All conditions joined by AND
- else{
- conditionByNumberMAP.put(String.valueOf(i), auxString);
- }
- }
- //Get conditions (based on logic)
- if(logicConditions != null && !String.isEmpty(logicConditions)){
- //Replace conditions with valid ones
- List<String> charList = logicConditions.split('');
- for(String key : charLIST){
- if(key.isNumeric() && conditionByNumberMAP.containsKey(key)){
- charLIST[charLIST.indexOf(key)] = conditionByNumberMAP.get(key);
- }
- }
- logicConditions = String.join(charLIST, '');
- }
- //Add them as AND string
- else{
- logicConditions = '';
- for(String key : conditionByNumberMAP.keySet()){
- logicConditions += String.isEmpty(logicConditions) ? conditionByNumberMAP.get(key) : ' AND ' + conditionByNumberMAP.get(key);
- }
- }
- query = 'SELECT Id FROM ' + Id.valueOf(recordId).getSObjectType().getDescribe().getName() + ' WHERE Id = :recordId AND ' + logicConditions;
- checkLIST = Database.query(query);
- result.success = checkLIST.isEmpty() ? false : true;
- result.message = checkLIST.isEmpty() ? message : null;
- }
- //No conditions to check
- else{
- result.success = true;
- }
- }
- return result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement