From c1b3b26334caf54574b002db734e10e57481e5dd Mon Sep 17 00:00:00 2001 From: Charan Girijala <82193104+charangirijala@users.noreply.github.com> Date: Sun, 10 Nov 2024 18:28:40 +0530 Subject: [PATCH] for FEAT-VALIDATION_RULE SUPPORT -1 --- .../classes/CodeUnitContainerSchema.cls | 2 +- .../classes/LogLineSchema/LogLineSchema.cls | 3 ++ .../classes/MethodEntryExit/MethodSchema.cls | 5 +- .../main/default/classes/UtilityMethods.cls | 20 +++++++ .../ValidationUnit/ValidationPassFail.cls | 52 +++++++++++++++++++ .../ValidationPassFail.cls-meta.xml | 5 ++ .../ValidationUnit/ValidationRuleUtility.cls | 43 +++++++++++++++ .../ValidationRuleUtility.cls-meta.xml | 5 ++ .../main/default/classes/utilityVariables.cls | 21 +++++++- .../lwc/logLineWrapper/logLineWrapper.css | 6 +++ .../lwc/logLineWrapper/logLineWrapper.html | 22 +++++++- .../lwc/logLineWrapper/logLineWrapper.js | 12 ++++- 12 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 force-app/main/default/classes/ValidationUnit/ValidationPassFail.cls create mode 100644 force-app/main/default/classes/ValidationUnit/ValidationPassFail.cls-meta.xml create mode 100644 force-app/main/default/classes/ValidationUnit/ValidationRuleUtility.cls create mode 100644 force-app/main/default/classes/ValidationUnit/ValidationRuleUtility.cls-meta.xml diff --git a/force-app/main/default/classes/CodeUnitContainerSchema.cls b/force-app/main/default/classes/CodeUnitContainerSchema.cls index 29b7b6b..f7c9888 100644 --- a/force-app/main/default/classes/CodeUnitContainerSchema.cls +++ b/force-app/main/default/classes/CodeUnitContainerSchema.cls @@ -22,7 +22,7 @@ public class CodeUnitContainerSchema { public String triggerObject; @AuraEnabled public String triggerEvent; - //Added for FATAL_ERROR to check if the current methodUnit has error + //Added for FATAL_ERROR to check if the current methodUnit has error can be used for Validation @AuraEnabled public Boolean hasError; @AuraEnabled diff --git a/force-app/main/default/classes/LogLineSchema/LogLineSchema.cls b/force-app/main/default/classes/LogLineSchema/LogLineSchema.cls index 8d96e8f..88d01bb 100644 --- a/force-app/main/default/classes/LogLineSchema/LogLineSchema.cls +++ b/force-app/main/default/classes/LogLineSchema/LogLineSchema.cls @@ -31,4 +31,7 @@ public class LogLineSchema { //Added for FATAL_ERROR @AuraEnabled public String errorMessage; + //Added for Validation Pass or fail + @AuraEnabled + public Boolean isValidRulePass; } diff --git a/force-app/main/default/classes/MethodEntryExit/MethodSchema.cls b/force-app/main/default/classes/MethodEntryExit/MethodSchema.cls index a6dd2cb..e8845b3 100644 --- a/force-app/main/default/classes/MethodEntryExit/MethodSchema.cls +++ b/force-app/main/default/classes/MethodEntryExit/MethodSchema.cls @@ -4,12 +4,15 @@ public class MethodSchema { executedLinesAndSubUnits = new List(); } - //Actual Name of the method + //Actual Name of the method/Validation Rule @AuraEnabled public String methodName; //Total name of the method invoked with class and namespaces @AuraEnabled public String methodTitle; + //18-digit Id of validation rule + @AuraEnabled + public String ruleId; //Id of the class from which method Invoked @AuraEnabled public String classId; diff --git a/force-app/main/default/classes/UtilityMethods.cls b/force-app/main/default/classes/UtilityMethods.cls index 7af77a6..6a40691 100644 --- a/force-app/main/default/classes/UtilityMethods.cls +++ b/force-app/main/default/classes/UtilityMethods.cls @@ -218,6 +218,26 @@ public class UtilityMethods { */ UserDebugUtility.processUserDebug(line); break; + } else if (utilityVariables.currentLineEvent == 'VALIDATION_RULE') { + /* + * 1. Create a new method unit in the name of validation + */ + ValidationRuleUtility.processValidationRule(line); + break; + } else if (utilityVariables.currentLineEvent == 'VALIDATION_PASS') { + /* + * 1. Create a logline indicating validation passed + * 2. pop the validation unit from the methodStack + */ + ValidationPassFail.processValidationPass(line); + break; + } else if (utilityVariables.currentLineEvent == 'VALIDATION_FAIL') { + /* + * 1. Create a logline indicating validation failed + * 2. pop the validation unit from the methodStack + */ + ValidationPassFail.processValidationFail(line); + break; } else if (utilityVariables.currentLineEvent == 'USER_INFO') { /* * 1. get user details and store in the userInfoSchema object and add it to result diff --git a/force-app/main/default/classes/ValidationUnit/ValidationPassFail.cls b/force-app/main/default/classes/ValidationUnit/ValidationPassFail.cls new file mode 100644 index 0000000..e8bc6d1 --- /dev/null +++ b/force-app/main/default/classes/ValidationUnit/ValidationPassFail.cls @@ -0,0 +1,52 @@ +public class ValidationPassFail { + public static void processValidationPass(String line) { + /* + * Create a logLine to push to current validation Method Unit + */ + LogLineSchema logLine = new LogLineSchema(); + logLine.type = 'VALPS'; + logLine.isValidRulePass = true; + pushLogLineAndPop(logLine); + } + public static void processValidationFail(String line) { + /* + * Create a logLine to push to current validation Method Unit + */ + LogLineSchema logLine = new LogLineSchema(); + logLine.type = 'VALFL'; + logLine.isValidRulePass = false; + pushLogLineAndPop(logLine); + } + + private static void pushLogLineAndPop(LogLineSchema log) { + /* + * 1. Get Current MethodUnit and push elss & make hasError true/false for that unit + * 2. Pop the current methodUnit + */ + + if (!utilityVariables.methodUnitsStack.isEmpty()) { + /** + * Get the top of methodUnitsStack and push it to current method Unit + */ + MethodSchema currentMethodUnit = (MethodSchema) utilityVariables.methodUnitsStack.peek(); + //create a new ExecutingLineAndSubUnitSchema and push it to the current MethodUnit + ExecutedLineAndSubUnitSchema elss = new ExecutedLineAndSubUnitSchema(); + elss.logLine = log; + //Add elsss to currentMenthodUnit + currentMethodUnit.executedLinesAndSubUnits.add(elss); + if (log.isValidRulePass) { + currentMethodUnit.hasError = false; + } else { + currentMethodUnit.hasError = true; + } + //System.debug('Pushed to Current MethoDUnit'); + //update currentLog + utilityVariables.currentLog = log; + + /* + * Pop the methodunit from Stack + */ + utilityVariables.methodUnitsStack.pop(); + } + } +} diff --git a/force-app/main/default/classes/ValidationUnit/ValidationPassFail.cls-meta.xml b/force-app/main/default/classes/ValidationUnit/ValidationPassFail.cls-meta.xml new file mode 100644 index 0000000..998805a --- /dev/null +++ b/force-app/main/default/classes/ValidationUnit/ValidationPassFail.cls-meta.xml @@ -0,0 +1,5 @@ + + + 62.0 + Active + diff --git a/force-app/main/default/classes/ValidationUnit/ValidationRuleUtility.cls b/force-app/main/default/classes/ValidationUnit/ValidationRuleUtility.cls new file mode 100644 index 0000000..98536fe --- /dev/null +++ b/force-app/main/default/classes/ValidationUnit/ValidationRuleUtility.cls @@ -0,0 +1,43 @@ +public class ValidationRuleUtility { + public static void processValidationRule(String line) { + /** + * Extract the Rulename and Rule 18-digit Id + */ + analyzeValidation(line); + } + + /* + * Example: 08:03:48.0 (436291)|VALIDATION_RULE|03dIR000000cCy7|Delivery_Schedule_14_Days_Or_Less + * Extract name and Id + * Create a new MethodUnit and send to addMethodtoStack + */ + private static void analyzeValidation(String line) { + MethodSchema methodUnit = new MethodSchema(); + List splitArr = line.split('\\|'); + methodUnit.methodName = splitArr[splitArr.size() - 1]; + methodUnit.ruleId = splitArr[splitArr.size() - 2]; + + addMethodtoStack(methodUnit); + } + + /* + * We need to add methodUnit to only CodeUnit as the validation rules dosen't call another validation + * Check if the current code unit type is validation and then push it + */ + private static void addMethodtoStack(MethodSchema methodUnit) { + if (!utilityVariables.codeUnitsStack.isEmpty()) { + /** + * Get the top of codeUnitsStack and push it to current method Unit + */ + CodeUnitContainerSchema currentCodeUnit = (CodeUnitContainerSchema) utilityVariables.codeUnitsStack.peek(); + //create a new ExecutingLineAndSubUnitSchema and push it to the current codeUnit + ExecutedLineAndSubUnitSchema elss = new ExecutedLineAndSubUnitSchema(); + elss.methodUnit = methodUnit; + //Add the elss to the currentCodeUnit + currentCodeUnit.executedLinesAndSubUnits.add(elss); + // System.debug('----Added methodUnit to current CodeUnit----'); + //Add methodUnit to stack + utilityVariables.methodUnitsStack.push(methodUnit); + } + } +} diff --git a/force-app/main/default/classes/ValidationUnit/ValidationRuleUtility.cls-meta.xml b/force-app/main/default/classes/ValidationUnit/ValidationRuleUtility.cls-meta.xml new file mode 100644 index 0000000..998805a --- /dev/null +++ b/force-app/main/default/classes/ValidationUnit/ValidationRuleUtility.cls-meta.xml @@ -0,0 +1,5 @@ + + + 62.0 + Active + diff --git a/force-app/main/default/classes/utilityVariables.cls b/force-app/main/default/classes/utilityVariables.cls index 9505a32..08c85fc 100644 --- a/force-app/main/default/classes/utilityVariables.cls +++ b/force-app/main/default/classes/utilityVariables.cls @@ -60,7 +60,8 @@ public class utilityVariables { '^[0-9:.]+\\s\\([0-9]+\\)\\|(CODE_UNIT_STARTED\\|)[(0-9)(\\[EXTERNAL\\])]+(\\|)[\\w.]+' => 'Class-Simple', '^[0-9:.]+\\s\\([0-9]+\\)\\|(CODE_UNIT_STARTED\\|)[(0-9)(\\[EXTERNAL\\])]+(\\|TRIGGERS)' => 'Trigger-Simple', '^[0-9:.]+\\s\\([0-9]+\\)\\|(CODE_UNIT_STARTED\\|)[(0-9)(\\[EXTERNAL\\])]+(\\|)\\w+(\\|)[\\w.]+\\s(on)\\s(\\w)+\\s(trigger\\sevent\\s)\\w+(\\|__sfdc_trigger\\/)[\\w\\/]+' => 'Trigger-Detailed', - '^[0-9:.]+\\s\\([0-9]+\\)\\|(CODE_UNIT_STARTED\\|)[(0-9)(\\[EXTERNAL\\])]+(\\|)\\w+;\\w+;\\w+(\\|)[\\w\\.]+' => 'Trigger-Event' + '^[0-9:.]+\\s\\([0-9]+\\)\\|(CODE_UNIT_STARTED\\|)[(0-9)(\\[EXTERNAL\\])]+(\\|)\\w+;\\w+;\\w+(\\|)[\\w\\.]+' => 'Trigger-Event', + '^[0-9:.]+\\s\\([0-9]+\\)\\|(CODE_UNIT_STARTED\\|)[(\\[EXTERNAL\\])(0-9)]+(\\|Validation)\\:[\\w]+\\:[\\w\\d]+' => 'Validation-Generic' }, 'STATEMENT_EXECUTE' => new Map{ '^[0-9:.]+\\s\\([0-9]+\\)\\|(STATEMENT_EXECUTE\\|)\\[[0-9]+\\]' => 'Statement-Execute' @@ -91,6 +92,15 @@ public class utilityVariables { 'VARIABLE_SCOPE_BEGIN' => new Map{ '^[0-9:.]+\\s\\([0-9]+\\)\\|(VARIABLE_SCOPE_BEGIN\\|)(\\[([0-9]+|(EXTERNAL))\\]\\|)(.+\\|.+\\|((true)|(false))\\|((true)|(false)))' => 'Variable-Scope-Generic' }, + 'VALIDATION_RULE' => new Map{ + '^[0-9:.]+\\s\\([0-9]+\\)\\|(VALIDATION_RULE\\|)[\\w\\d]+(\\|)[\\w]+' => 'Valid-Rule-Generic' + }, + 'VALIDATION_PASS' => new Map{ + '^[0-9:.]+\\s\\([0-9]+\\)\\|(VALIDATION_PASS)' => 'Valid-Rule-Pass' + }, + 'VALIDATION_FAIL' => new Map{ + '^[0-9:.]+\\s\\([0-9]+\\)\\|(VALIDATION_FAIL)' => 'Valid-Rule-Fail' + }, 'CODE_UNIT_FINISHED' => new Map{ '^[0-9:.]+\\s\\([0-9]+\\)\\|(CODE_UNIT_FINISHED\\|).*' => 'Finished-Generic' }, @@ -183,10 +193,19 @@ public class utilityVariables { codeUnitDetails.executingNamespace = splitArr1[0]; codeUnitDetails.codeUnitName = splitArr1[1]; } + } else if (pattern == 'Validation-Generic') { + enteredCondtion = true; + codeUnitDetails.codeUnitType = 'Validation'; + codeUnitDetails.isTrigger = false; + List splitArr = line.split(':'); + String name = 'Validation on '; + name += splitArr[splitArr.size() - 2]; + codeUnitDetails.codeUnitName = name; } if (!enteredCondtion) { /** * No condition entered for codeunitProcessing + * Possible code to handle this condition in future */ } else { if (!utilityVariables.codeUnitsStack.isEmpty()) { diff --git a/force-app/main/default/lwc/logLineWrapper/logLineWrapper.css b/force-app/main/default/lwc/logLineWrapper/logLineWrapper.css index 41fefc4..431aa9c 100644 --- a/force-app/main/default/lwc/logLineWrapper/logLineWrapper.css +++ b/force-app/main/default/lwc/logLineWrapper/logLineWrapper.css @@ -13,7 +13,13 @@ .faerr { color: rgb(194, 57, 52); } +.valfl { + color: rgb(194, 57, 52); +} +.valps { + color: rgb(34, 150, 34); +} .slds-line-clamp { line-clamp: 10; -webkit-line-clamp: 10; diff --git a/force-app/main/default/lwc/logLineWrapper/logLineWrapper.html b/force-app/main/default/lwc/logLineWrapper/logLineWrapper.html index 7d7722c..163b81d 100644 --- a/force-app/main/default/lwc/logLineWrapper/logLineWrapper.html +++ b/force-app/main/default/lwc/logLineWrapper/logLineWrapper.html @@ -6,7 +6,7 @@ -
Line No.
+
Line
Event
@@ -112,6 +112,26 @@ + + + + diff --git a/force-app/main/default/lwc/logLineWrapper/logLineWrapper.js b/force-app/main/default/lwc/logLineWrapper/logLineWrapper.js index 5d5d213..e8e376c 100644 --- a/force-app/main/default/lwc/logLineWrapper/logLineWrapper.js +++ b/force-app/main/default/lwc/logLineWrapper/logLineWrapper.js @@ -96,7 +96,17 @@ export default class LogLineWrapper extends LightningElement { // else if (logTemp.logLineData.type === "FAERR") { logTemp.eventClassComb = "slds-line-clamp faerr"; - console.log("Error: ", JSON.stringify(logTemp.logLineData)); + // console.log("Error: ", JSON.stringify(logTemp.logLineData)); + } + + // + else if (logTemp.logLineData.type === "VALFL") { + logTemp.eventClassComb = "slds-line-clamp valfl"; + logTemp.isValidRuleFail = true; + } + // + else if (logTemp.logLineData.type === "VALPS") { + logTemp.eventClassComb = "slds-line-clamp valps"; } log = logTemp; } else if (log.type === "unit") {