Skip to content
Snippets Groups Projects
Commit 3d203177 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

#9 Add actions for predefined existing value

(add to predefined values / delete rule)
parent be6c14fe
No related branches found
No related tags found
No related merge requests found
package de.unikoblenz.fgbks.core.dmn.verification.verifier.impl;
import static de.unikoblenz.fgbks.core.dmn.domain.vdmn.utils.VDmnFunctions.templateDecisionColumn;
import static de.unikoblenz.fgbks.core.dmn.verification.result.VerificationResultEntry.VerificationClassification.WARNING;
import static de.unikoblenz.fgbks.core.dmn.verification.result.actions.ActionScope.INPUT_COLUMN;
import static de.unikoblenz.fgbks.core.dmn.verification.result.actions.ActionScope.OUTPUT_COLUMN;
import static de.unikoblenz.fgbks.core.dmn.verification.result.actions.ActionScope.RULE;
import static de.unikoblenz.fgbks.core.dmn.verification.result.actions.VerificationFix.SHOW_INPUT_ENTRIES;
import static de.unikoblenz.fgbks.core.dmn.verification.result.actions.VerificationFix.SHOW_OUTPUT_ENTRIES;
......@@ -12,8 +16,10 @@ import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnOutputValue;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VDmnValue;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.utils.VDmnFunctions;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerificationResultEntry.VerificationClassification;
import de.unikoblenz.fgbks.core.dmn.verification.result.VerificationResultEntryElement;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.Action;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.ActionType;
import de.unikoblenz.fgbks.core.dmn.verification.result.actions.VerificationFix;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.AbstractVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.DmnVerifier;
import de.unikoblenz.fgbks.core.dmn.verification.verifier.types.PredefinedExistingValueVerification;
......@@ -76,13 +82,36 @@ public class PredefinedExistingValueVerifier extends AbstractVerifier {
}
private void addToResult(VDmnValue stringValue, String missingStringValue) {
vreFactory.addElement(VerificationResultEntryElement.create(stringValue));
vreFactory.addVerificationFix(
stringValue.isInputValue() ? SHOW_INPUT_ENTRIES : SHOW_OUTPUT_ENTRIES);
vreFactory.addToEntry(
VerificationClassification.WARNING,
templateDecisionColumn(stringValue.getVDmnColumn())
+ "String value \"%s\" was not found in the list of predefined values.",
missingStringValue);
vreFactory
.addElement(VerificationResultEntryElement.create(stringValue))
.addVerificationFix(stringValue.isInputValue() ? SHOW_INPUT_ENTRIES : SHOW_OUTPUT_ENTRIES)
.addVerificationFix(
VerificationFix.getBuilder()
.withFixName("Add predefined value \"" + missingStringValue + "\"")
.addAction(
Action.getBuilder()
.withActionType(ActionType.UPDATE)
.withActionScope(stringValue.isInputValue() ? INPUT_COLUMN : OUTPUT_COLUMN)
.addIdValue(stringValue.getDecisionId())
.addIdValue(stringValue.getVDmnColumn().getId())
.addValue("addPredVal", missingStringValue)
.build())
.build())
.addVerificationFix(
VerificationFix.getBuilder()
.withFixName("Delete rule " + stringValue.getVDmnRule().getRowNumber())
.addAction(
Action.getBuilder()
.withActionType(ActionType.DELETE)
.withActionScope(RULE)
.addIdValue(stringValue.getDecisionId())
.addIdValue(stringValue.getRuleId())
.build())
.build())
.addToEntry(
WARNING,
templateDecisionColumn(stringValue.getVDmnColumn())
+ "String value \"%s\" was not found in the list of predefined values.",
missingStringValue);
}
}
......@@ -343,9 +343,13 @@ function performVerificationFixUPDATE(verificationEntry, fixAction) {
case 'DECISION':
updateDecision(verificationEntry, fixAction);
break;
case 'RULE':
case 'INPUT_COLUMN':
updateColumn(verificationEntry, fixAction, 'inputId');
break;
case 'OUTPUT_COLUMN':
updateColumn(verificationEntry, fixAction, 'outputId');
break;
case 'RULE':
case 'INPUT_ENTRY':
case 'OUTPUT_ENTRY':
default:
......@@ -396,6 +400,44 @@ function updateDecision(verificationEntry, fixAction) {
openViewWithId(verificationEntry.elements[0].identifier['definitionId']);
}
// ACTION CREATE PREDEFINED VALUE
// )
/**
*
* @param {VerificationEntry} verificationEntry
* @param {Action} fixAction
* @param {String} idName (inputId or outputId)
*/
function updateColumn(verificationEntry, fixAction, idName) {
openViewWithId(fixAction.actionValues['decisionId']);
let column = getSheetElementWithId(fixAction.actionValues[idName]);
if (column) {
if (fixAction.actionValues['name']) {
if (idName === 'outputId') {
column.businessObject.name = fixAction.actionValues['name'];
} else {
column.businessObject.inputExpression.text = fixAction.actionValues['name'];
}
}
if (fixAction.actionValues['addPredVal']) {
let inputVals = [];
if (column.businessObject.inputValues) {
inputVals = column.businessObject.inputValues.text.split(",");
}
let value = fixAction.actionValues['addPredVal'];
if (!value.startsWith('"')) {
value = '"' + value;
}
if (!value.endsWith('"')) {
value = value + '"';
}
inputVals.push(value);
getCurrentModeler().editAllowedValues(column.businessObject, inputVals);
}
}
}
// get a rule:
/**
* Get a col by ID
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment