use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class AddRelationRowCommand method newGraphCommand.
@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler handler) {
return new AbstractGraphCommand() {
@Override
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext gce) {
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) {
relation.getRow().add(uiRowIndex, row);
relation.getColumn().forEach(ii -> {
final LiteralExpression le = new LiteralExpression();
final HasExpression hasExpression = HasExpression.wrap(ii, le);
row.getExpression().add(hasExpression);
le.setParent(row);
});
row.setParent(relation);
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
relation.getRow().remove(row);
return GraphCommandResultBuilder.SUCCESS;
}
};
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class RegisterNodeCommand method setupEncapsulatedLogic.
private void setupEncapsulatedLogic(final BusinessKnowledgeModel businessKnowledgeModel) {
final LiteralExpression le = new LiteralExpression();
final FunctionDefinition function = new FunctionDefinition();
KindUtilities.setKind(function, FunctionDefinition.Kind.FEEL);
function.setExpression(le);
le.setParent(function);
businessKnowledgeModel.setEncapsulatedLogic(function);
function.setParent(businessKnowledgeModel);
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method testContextEntryDataType.
@Test
@SuppressWarnings("unchecked")
public void testContextEntryDataType() throws Exception {
final DMNMarshallerStandalone marshaller = getDMNMarshaller();
final Context context = new Context();
context.setTypeRef(BuiltInType.DATE_TIME.asQName());
final ContextEntry contextEntry = new ContextEntry();
final LiteralExpression literalExpression = new LiteralExpression();
literalExpression.setTypeRef(BuiltInType.BOOLEAN.asQName());
literalExpression.getText().setValue("feel");
contextEntry.setExpression(literalExpression);
context.getContextEntry().add(contextEntry);
final Diagram<Graph, Metadata> mockedDiagram = newDiagramDecisionWithExpression(context);
final String marshalledSource = marshaller.marshall(mockedDiagram);
final Graph<?, Node<View, ?>> unmarshalledGraph = marshaller.unmarshall(createMetadata(), new StringInputStream(marshalledSource));
assertThat(unmarshalledGraph.nodes()).hasSize(2);
checkDecisionExpression(unmarshalledGraph, context);
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_wrong_decision.
@Test
@SuppressWarnings("unchecked")
public void test_wrong_decision() throws IOException {
// DROOLS-3116 empty Literal Expression to be preserved
final ErrorsAndDMNModelAsSerialized result = roundTripUnmarshalMarshalThenUnmarshalDMNexpectingErrors(this.getClass().getResourceAsStream("/wrong_decision.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 epression.
assertTrue(result.hasErrors());
// identify the error message for the Decision with a Literal Expression decision logic missing the actual expression text.
DMNMessage m0 = (DMNMessage) result.messages.get(0);
assertTrue("expected a message identifying the problem on the literalExpression of 'my decision'", m0.getSourceId().equals("_36dd163c-4862-4308-92bf-40a998b24e39"));
org.kie.dmn.model.api.Decision d0 = (org.kie.dmn.model.api.Decision) result.definitions.getDrgElement().stream().filter(d -> d.getId().equals("_cce32679-9395-444d-a4bf-96af8ee727a0")).findFirst().get();
// the identified DMN Decision is composed a literal expression missing text (text is null).
org.kie.dmn.model.api.Expression d0le = d0.getExpression();
assertTrue(d0le instanceof org.kie.dmn.model.api.LiteralExpression);
// DROOLS-3152
assertEquals("", ((org.kie.dmn.model.api.LiteralExpression) d0le).getText());
// -- Stunner side.
DMNMarshallerStandalone m = getDMNMarshaller();
Graph<?, ?> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/wrong_decision.dmn"));
Node<?, ?> decisionNode = g.getNode("_cce32679-9395-444d-a4bf-96af8ee727a0");
assertNodeContentDefinitionIs(decisionNode, Decision.class);
View<Decision> view = ((View<Decision>) decisionNode.getContent());
// the identified DMN Decision is composed a literal expression missing text (text is null).
Expression expression = view.getDefinition().getExpression();
// DROOLS-3116 empty Literal Expression is preserved
assertNotNull(expression);
assertEquals(LiteralExpression.class, expression.getClass());
LiteralExpression le = (LiteralExpression) expression;
// DROOLS-3152
assertEquals("", le.getText().getValue());
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class BindingPropertyConverterTest method testDMNFromWB.
@Test
public void testDMNFromWB() {
final Binding wb = new Binding();
final InformationItem informationItem = new InformationItem();
wb.setParameter(informationItem);
final LiteralExpression literalExpression = new LiteralExpression();
literalExpression.getComponentWidths().set(0, 200.0);
literalExpression.getId().setValue(EXPRESSION_UUID);
wb.setExpression(literalExpression);
final org.kie.dmn.model.api.Binding dmn = BindingPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
assertThat(dmn).isNotNull();
assertThat(dmn.getParameter()).isNotNull();
assertThat(dmn.getExpression()).isNotNull();
assertThat(dmn.getExpression().getId()).isEqualTo(EXPRESSION_UUID);
verify(componentWidthsConsumer).accept(componentWidthsCaptor.capture());
final ComponentWidths componentWidths = componentWidthsCaptor.getValue();
assertThat(componentWidths).isNotNull();
assertThat(componentWidths.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
assertThat(componentWidths.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
assertThat(componentWidths.getWidths().get(0)).isEqualTo(200.0);
}
Aggregations