use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ExpressionPropertyConverter method dmnFromWB.
public static org.kie.dmn.model.api.Expression dmnFromWB(final Expression wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
if (Objects.isNull(wb)) {
return null;
}
final String uuid = wb.getId().getValue();
if (Objects.nonNull(uuid)) {
final ComponentWidths componentWidths = new ComponentWidths();
componentWidths.setDmnElementRef(new QName(uuid));
componentWidths.setWidths(new ArrayList<>(wb.getComponentWidths()));
componentWidthsConsumer.accept(componentWidths);
}
if (wb instanceof IsLiteralExpression) {
return LiteralExpressionPropertyConverter.dmnFromWB((IsLiteralExpression) wb);
} else if (wb instanceof Context) {
return ContextPropertyConverter.dmnFromWB((Context) wb, componentWidthsConsumer);
} else if (wb instanceof Relation) {
return RelationPropertyConverter.dmnFromWB((Relation) wb, componentWidthsConsumer);
} else if (wb instanceof List) {
return ListPropertyConverter.dmnFromWB((List) wb, componentWidthsConsumer);
} else if (wb instanceof Invocation) {
return InvocationPropertyConverter.dmnFromWB((Invocation) wb, componentWidthsConsumer);
} else if (wb instanceof FunctionDefinition) {
return FunctionDefinitionPropertyConverter.dmnFromWB((FunctionDefinition) wb, componentWidthsConsumer);
} else if (wb instanceof DecisionTable) {
return DecisionTablePropertyConverter.dmnFromWB((DecisionTable) wb);
}
return null;
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class ContextEditorDefinitionTest method testModelEnrichment.
@Test
public void testModelEnrichment() {
final Optional<Context> oModel = definition.getModelClass();
definition.enrich(Optional.empty(), hasExpression, oModel);
final Context model = oModel.get();
assertEquals(2, model.getContextEntry().size());
assertNotNull(model.getContextEntry().get(0).getVariable());
assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "1", model.getContextEntry().get(0).getVariable().getName().getValue());
assertNull(model.getContextEntry().get(1).getVariable());
assertNull(model.getContextEntry().get(1).getExpression());
model.getContextEntry().forEach(ce -> assertEquals(model, ce.getParent()));
assertEquals(model.getContextEntry().get(0), model.getContextEntry().get(0).getVariable().getParent());
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_wrong_context.
@Test
@SuppressWarnings("unchecked")
public void test_wrong_context() throws IOException {
// DROOLS-2217
final ErrorsAndDMNModelAsSerialized result = roundTripUnmarshalMarshalThenUnmarshalDMNexpectingErrors(this.getClass().getResourceAsStream("/wrong_context.dmn"));
// although the DMN file is schema valid but is not a valid-DMN (a context-entry value is a literal expression missing text, which is null)
// DROOLS-3152: once roundtripped through the Stunner marshaller it will receive an empty text. (empty expression, but a LiteralExpression with an empty text child xml element)
// this will still naturally throw some error because unable to FEEL-parse/compile an empty expression.
assertTrue(result.hasErrors());
// identify the error message for context-entry "ciao":
DMNMessage m0 = (DMNMessage) result.messages.get(0);
assertTrue("expected a message identifying the problem on a context entry for 'ciao'", // DROOLS-3152 please notice FEEL reporting indeed an empty expression.
m0.getMessage().startsWith("Error compiling FEEL expression '' for name "));
org.kie.dmn.model.api.Decision d0 = (org.kie.dmn.model.api.Decision) result.definitions.getDrgElement().stream().filter(d -> d.getId().equals("_653b3426-933a-4050-9568-ab2a66b43c36")).findFirst().get();
// the identified DMN Decision is composed of a DMN Context where the first context-entry value is a literal expression missing text (text is null).
org.kie.dmn.model.api.Context d0c = (org.kie.dmn.model.api.Context) d0.getExpression();
org.kie.dmn.model.api.Expression contextEntryValue = d0c.getContextEntry().get(0).getExpression();
assertTrue(contextEntryValue instanceof org.kie.dmn.model.api.LiteralExpression);
// DROOLS-3152
assertEquals("", ((org.kie.dmn.model.api.LiteralExpression) contextEntryValue).getText());
// -- Stunner side.
DMNMarshallerStandalone m = getDMNMarshaller();
Graph<?, ?> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/wrong_context.dmn"));
Node<?, ?> decisionNode = g.getNode("_653b3426-933a-4050-9568-ab2a66b43c36");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
View<Decision> view = ((View<Decision>) decisionNode.getContent());
// the identified DMN Decision is composed of a DMN Context where the first context-entry has missing Expression.
Context expression = (Context) view.getDefinition().getExpression();
// DROOLS-3116 empty Literal Expression is preserved
assertNotNull(expression.getContextEntry().get(0).getExpression());
assertEquals(LiteralExpression.class, expression.getContextEntry().get(0).getExpression().getClass());
LiteralExpression le = (LiteralExpression) expression.getContextEntry().get(0).getExpression();
// DROOLS-3152
assertEquals("", le.getText().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkDecisionWithContextWithDefaultResult.
private void checkDecisionWithContextWithDefaultResult(Graph<?, Node<?, ?>> g) {
Node<?, ?> decisionNode = g.getNode("_30810b88-8416-4c02-8ed1-8c19b7606243");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
Context context = (Context) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getExpression();
InformationItem defaultResultVariable = context.getContextEntry().get(1).getVariable();
assertNull("Default result variable", defaultResultVariable);
Expression defaultResultExpression = context.getContextEntry().get(1).getExpression();
assertNotNull("Default result expression", defaultResultExpression);
assertEquals("defaultResultExpression's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (defaultResultExpression).getParent().getParent()).getId().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkDecisionWithContext.
@SuppressWarnings("unchecked")
private void checkDecisionWithContext(Graph<?, Node<?, ?>> g) {
Node<?, ?> decisionNode = g.getNode("_30810b88-8416-4c02-8ed1-8c19b7606243");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
Node<?, ?> rootNode = DMNMarshallerStandalone.findDMNDiagramRoot((Graph) g);
assertNotNull(rootNode);
assertRootNodeConnectedTo(rootNode, decisionNode);
assertEquals("decisionNode parent is Definitions DMN root", "_153e2b47-3bd2-4db0-828c-db3fce0b3199", ((DMNElement) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getParent()).getId().getValue());
Context context = (Context) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getExpression();
assertEquals("contextNode's parent is decisionNode", "_30810b88-8416-4c02-8ed1-8c19b7606243", ((DMNElement) context.getParent()).getId().getValue());
Expression literalExpression1 = context.getContextEntry().get(0).getExpression();
assertEquals("literalExpression1's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (literalExpression1).getParent().getParent()).getId().getValue());
Expression literalExpression2 = context.getContextEntry().get(1).getExpression();
assertEquals("literalExpression2's parent-parent is contextNode", "_0f38d114-5d6e-40dd-aa9c-9f031f9b0571", ((DMNElement) (literalExpression2).getParent().getParent()).getId().getValue());
}
Aggregations