Skip to content

for FEAT-VALIDATION_RULE SUPPORT -1 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion force-app/main/default/classes/CodeUnitContainerSchema.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ public class MethodSchema {
executedLinesAndSubUnits = new List<ExecutedLineAndSubUnitSchema>();
}

//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;
Expand Down
20 changes: 20 additions & 0 deletions force-app/main/default/classes/UtilityMethods.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -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<String> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
21 changes: 20 additions & 1 deletion force-app/main/default/classes/utilityVariables.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>{
'^[0-9:.]+\\s\\([0-9]+\\)\\|(STATEMENT_EXECUTE\\|)\\[[0-9]+\\]' => 'Statement-Execute'
Expand Down Expand Up @@ -91,6 +92,15 @@ public class utilityVariables {
'VARIABLE_SCOPE_BEGIN' => new Map<String, String>{
'^[0-9:.]+\\s\\([0-9]+\\)\\|(VARIABLE_SCOPE_BEGIN\\|)(\\[([0-9]+|(EXTERNAL))\\]\\|)(.+\\|.+\\|((true)|(false))\\|((true)|(false)))' => 'Variable-Scope-Generic'
},
'VALIDATION_RULE' => new Map<String, String>{
'^[0-9:.]+\\s\\([0-9]+\\)\\|(VALIDATION_RULE\\|)[\\w\\d]+(\\|)[\\w]+' => 'Valid-Rule-Generic'
},
'VALIDATION_PASS' => new Map<String, String>{
'^[0-9:.]+\\s\\([0-9]+\\)\\|(VALIDATION_PASS)' => 'Valid-Rule-Pass'
},
'VALIDATION_FAIL' => new Map<String, String>{
'^[0-9:.]+\\s\\([0-9]+\\)\\|(VALIDATION_FAIL)' => 'Valid-Rule-Fail'
},
'CODE_UNIT_FINISHED' => new Map<String, String>{
'^[0-9:.]+\\s\\([0-9]+\\)\\|(CODE_UNIT_FINISHED\\|).*' => 'Finished-Generic'
},
Expand Down Expand Up @@ -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<String> 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()) {
Expand Down
6 changes: 6 additions & 0 deletions force-app/main/default/lwc/logLineWrapper/logLineWrapper.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion force-app/main/default/lwc/logLineWrapper/logLineWrapper.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<thead>
<tr class="slds-line-height_reset">
<th scope="col">
<div class="slds-truncate" title="Line No.">Line No.</div>
<div class="slds-truncate" title="Line No.">Line</div>
</th>
<th scope="col">
<div class="slds-truncate" title="Event">Event</div>
Expand Down Expand Up @@ -112,6 +112,26 @@
</div>
</td>
</template>

<!-- FATAL ERROR -->
<template lwc:if={line.logLineData.isValidRulePass}>
<td class="slds-text-body_small slds-cell-wrap line-content">
<div class="slds-line-clamp" title="Validation Rule Passed">
<span class="slds-text-font_monospace">
Validation Rule Passed
</span>
</div>
</td>
</template>
<template lwc:if={line.isValidRuleFail}>
<td class="slds-text-body_small slds-cell-wrap line-content">
<div class="slds-line-clamp" title="Validation Rule Failed">
<span class="slds-text-font_monospace">
Validation Rule Failed
</span>
</div>
</td>
</template>
</template>

<!-- Unit -->
Expand Down
12 changes: 11 additions & 1 deletion force-app/main/default/lwc/logLineWrapper/logLineWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,17 @@ export default class LogLineWrapper extends LightningElement {
// <!-- FATAL_ERROR -->
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));
}

// <!-- VALIDATION_FAIL -->
else if (logTemp.logLineData.type === "VALFL") {
logTemp.eventClassComb = "slds-line-clamp valfl";
logTemp.isValidRuleFail = true;
}
// <!-- VALIDATION_PASS -->
else if (logTemp.logLineData.type === "VALPS") {
logTemp.eventClassComb = "slds-line-clamp valps";
}
log = logTemp;
} else if (log.type === "unit") {
Expand Down
Loading