diff --git a/dmn-core/src/main/java/com/gs/dmn/transformation/AddMissingImportPrefixInDTTransformer.java b/dmn-core/src/main/java/com/gs/dmn/transformation/AddMissingImportPrefixInDTTransformer.java index da4acfff3..955ecd46b 100644 --- a/dmn-core/src/main/java/com/gs/dmn/transformation/AddMissingImportPrefixInDTTransformer.java +++ b/dmn-core/src/main/java/com/gs/dmn/transformation/AddMissingImportPrefixInDTTransformer.java @@ -115,6 +115,10 @@ private void transform(DMNModelRepository repository, TDecision decision, TDecis for (TLiteralExpression exp: rule.getOutputEntry()) { addMissingPrefix(exp, names); } + // Annotation + for (TRuleAnnotation annotation: rule.getAnnotationEntry()) { + addMissingPrefix(annotation, names); + } } } @@ -132,6 +136,13 @@ private void addMissingPrefix(TUnaryTests test, Set names) { } } + private void addMissingPrefix(TRuleAnnotation annotation, Set names) { + if (annotation != null) { + String newText = addMissingPrefix(annotation.getText(), names); + annotation.setText(newText); + } + } + String addMissingPrefix(String text, Set names) { if (StringUtils.isEmpty(text)) { return text; diff --git a/dmn-core/src/test/java/com/gs/dmn/transformation/AddMissingImportPrefixInDTTransformerTest.java b/dmn-core/src/test/java/com/gs/dmn/transformation/AddMissingImportPrefixInDTTransformerTest.java index cee4d1c67..8c1493ba0 100644 --- a/dmn-core/src/test/java/com/gs/dmn/transformation/AddMissingImportPrefixInDTTransformerTest.java +++ b/dmn-core/src/test/java/com/gs/dmn/transformation/AddMissingImportPrefixInDTTransformerTest.java @@ -12,6 +12,8 @@ */ package com.gs.dmn.transformation; +import com.gs.dmn.DMNModelRepository; +import com.gs.dmn.ast.*; import com.gs.dmn.runtime.Pair; import org.junit.jupiter.api.Test; @@ -26,6 +28,79 @@ public class AddMissingImportPrefixInDTTransformerTest { private final AddMissingImportPrefixInDTTransformer transformer = new AddMissingImportPrefixInDTTransformer(); private final Set names = new LinkedHashSet<>(Arrays.asList("ident1", "ident2")); + @Test + public void testModel() { + String literalExpressionText = "person.age"; + String unaryTestsText = "> person.age"; + String annotationText = "\"rule triggered\" + person.age"; + + ObjectFactory objectFactory = new ObjectFactory(); + TDefinitions definitions = objectFactory.createTDefinitions(); + + // Create input + TInputData inputData = objectFactory.createTInputData(); + inputData.setName("person"); + inputData.setId("person"); + definitions.getDrgElement().add(inputData); + + // Create child decision + TDecision child = objectFactory.createTDecision(); + child.setName("child"); + child.setId("child"); + definitions.getDrgElement().add(child); + + // Create decision + TDecision decision = objectFactory.createTDecision(); + decision.setName("decision"); + decision.setId("decision"); + // Create IRs + TInformationRequirement inputDataRequirement = objectFactory.createTInformationRequirement(); + TDMNElementReference inputDataReference = objectFactory.createTDMNElementReference(); + inputDataReference.setHref("#person"); + inputDataRequirement.setRequiredInput(inputDataReference); + decision.getInformationRequirement().add(inputDataRequirement); + TInformationRequirement childRequirement = objectFactory.createTInformationRequirement(); + TDMNElementReference decisionReference = objectFactory.createTDMNElementReference(); + decisionReference.setHref("#child"); + childRequirement.setRequiredDecision(decisionReference); + decision.getInformationRequirement().add(childRequirement); + // Create decision table + TDecisionTable decisionTable = objectFactory.createTDecisionTable(); + // Create input clause + TInputClause inputClause = objectFactory.createTInputClause(); + TLiteralExpression inputExpression = objectFactory.createTLiteralExpression(); + inputExpression.setText(literalExpressionText); + inputClause.setInputExpression(inputExpression); + decisionTable.getInput().add(inputClause); + // Create output clause + TOutputClause outputClause = objectFactory.createTOutputClause(); + TUnaryTests outputClauseTest = objectFactory.createTUnaryTests(); + outputClauseTest.setText(unaryTestsText); + outputClause.setOutputValues(outputClauseTest); + decisionTable.getOutput().add(outputClause); + // Create rule + TDecisionRule rule = objectFactory.createTDecisionRule(); + TUnaryTests inputEntryTests = objectFactory.createTUnaryTests(); + rule.getInputEntry().add(inputEntryTests); + TLiteralExpression ruleOutputExpression = objectFactory.createTLiteralExpression(); + ruleOutputExpression.setText(literalExpressionText); + rule.getOutputEntry().add(ruleOutputExpression); + TRuleAnnotation ruleAnnotation = objectFactory.createTRuleAnnotation(); + ruleAnnotation.setText(annotationText); + rule.getAnnotationEntry().add(ruleAnnotation); + decisionTable.getRule().add(rule); + decision.setExpression(decisionTable); + definitions.getDrgElement().add(decision); + + transformer.transform(new DMNModelRepository(definitions)); + + // Check replacements in + assertEquals("person.person . age", inputClause.getInputExpression().getText()); + assertEquals("> person.person . age", outputClause.getOutputValues().getText()); + assertEquals("person.person . age", rule.getOutputEntry().get(0).getText()); + assertEquals("\"rule triggered\" + person.person . age", rule.getAnnotationEntry().get(0).getText()); + } + @Test public void testAddMissingPrefix() { List> testCases = Arrays.asList( @@ -49,5 +124,4 @@ public void testAddMissingPrefix() { assertEquals(pair.getRight(), newText); } } - } \ No newline at end of file