use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class ExpressionPropertyConverter method wbFromDMN.
public static Expression wbFromDMN(final JSITExpression dmn, final JSITExpression parent, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
if (JSITLiteralExpression.instanceOf(dmn)) {
final JSITLiteralExpression jsiExpression = Js.uncheckedCast(dmn);
final LiteralExpression e = LiteralExpressionPropertyConverter.wbFromDMN(jsiExpression);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITContext.instanceOf(dmn)) {
final JSITContext jsiExpression = Js.uncheckedCast(dmn);
final Context e = ContextPropertyConverter.wbFromDMN(jsiExpression, parent, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITRelation.instanceOf(dmn)) {
final JSITRelation jsiExpression = Js.uncheckedCast(dmn);
final Relation e = RelationPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITList.instanceOf(dmn)) {
final JSITList jsiExpression = Js.uncheckedCast(dmn);
final List e = ListPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITInvocation.instanceOf(dmn)) {
final JSITInvocation jsiExpression = Js.uncheckedCast(dmn);
final Invocation e = InvocationPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITFunctionDefinition.instanceOf(dmn)) {
final JSITFunctionDefinition jsiExpression = Js.uncheckedCast(dmn);
final FunctionDefinition e = FunctionDefinitionPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (JSITDecisionTable.instanceOf(dmn)) {
final JSITDecisionTable jsiExpression = Js.uncheckedCast(dmn);
final DecisionTable e = DecisionTablePropertyConverter.wbFromDMN(jsiExpression);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
}
return null;
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DecisionRulePropertyConverter method dmnFromWB.
public static JSITDecisionRule dmnFromWB(final DecisionRule wb) {
final JSITDecisionRule result = new JSITDecisionRule();
result.setId(wb.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
description.ifPresent(result::setDescription);
for (final RuleAnnotationClauseText ruleAnnotationClauseText : wb.getAnnotationEntry()) {
final JSITRuleAnnotation ruleAnnotation = RuleAnnotationClauseTextPropertyConverter.dmnFromWB(ruleAnnotationClauseText);
result.addAnnotationEntry(ruleAnnotation);
}
for (UnaryTests ie : wb.getInputEntry()) {
final JSITUnaryTests inputEntryConverted = UnaryTestsPropertyConverter.dmnFromWB(ie);
result.addInputEntry(inputEntryConverted);
}
for (LiteralExpression oe : wb.getOutputEntry()) {
final JSITLiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.dmnFromWB(oe);
result.addOutputEntry(outputEntryConverted);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DecisionRulePropertyConverter method wbFromDMN.
public static DecisionRule wbFromDMN(final JSITDecisionRule dmn) {
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final DecisionRule result = new DecisionRule();
result.setId(id);
result.setDescription(description);
final List<JSITRuleAnnotation> jsiAnnotationEntries = dmn.getAnnotationEntry();
for (int i = 0; i < jsiAnnotationEntries.size(); i++) {
final JSITRuleAnnotation jsiRuleAnnotation = Js.uncheckedCast(jsiAnnotationEntries.get(i));
final RuleAnnotationClauseText ruleAnnotationClauseText = RuleAnnotationClauseTextPropertyConverter.wbFromDMN(jsiRuleAnnotation);
if (Objects.nonNull(ruleAnnotationClauseText)) {
ruleAnnotationClauseText.setParent(result);
result.getAnnotationEntry().add(ruleAnnotationClauseText);
}
}
if (result.getAnnotationEntry().isEmpty()) {
final RuleAnnotationClauseText annotationEntryText = new RuleAnnotationClauseText();
annotationEntryText.getText().setValue(description.getValue());
annotationEntryText.setParent(result);
result.getAnnotationEntry().add(annotationEntryText);
}
final List<JSITUnaryTests> jsiInputEntries = dmn.getInputEntry();
for (int i = 0; i < jsiInputEntries.size(); i++) {
final JSITUnaryTests jsiInputEntry = Js.uncheckedCast(jsiInputEntries.get(i));
final UnaryTests inputEntryConverted = UnaryTestsPropertyConverter.wbFromDMN(jsiInputEntry);
if (Objects.nonNull(inputEntryConverted)) {
inputEntryConverted.setParent(result);
result.getInputEntry().add(inputEntryConverted);
}
}
final List<JSITLiteralExpression> jsiOutputEntries = dmn.getOutputEntry();
for (int i = 0; i < jsiOutputEntries.size(); i++) {
final JSITLiteralExpression jsiOutputEntry = Js.uncheckedCast(jsiOutputEntries.get(i));
final LiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.wbFromDMN(jsiOutputEntry);
if (Objects.nonNull(outputEntryConverted)) {
outputEntryConverted.setParent(result);
result.getOutputEntry().add(outputEntryConverted);
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverterTest method testDMNFromWB.
@Test
public void testDMNFromWB() {
final BusinessKnowledgeModel wb = new BusinessKnowledgeModel();
final LiteralExpression literalExpression = new LiteralExpression();
final InformationItemPrimary informationItem = new InformationItemPrimary();
final FunctionDefinition functionDefinition = new FunctionDefinition();
literalExpression.getComponentWidths().set(0, 200.0);
literalExpression.getId().setValue(EXPRESSION_UUID);
functionDefinition.getComponentWidths().set(0, 200.0);
functionDefinition.setExpression(literalExpression);
functionDefinition.getId().setValue(FUNCTION_DEFINITION_UUID);
wb.getId().setValue(DECISION_UUID);
wb.getName().setValue(DECISION_NAME);
wb.getDescription().setValue(DECISION_DESCRIPTION);
wb.setVariable(informationItem);
wb.setEncapsulatedLogic(functionDefinition);
final Node<View<BusinessKnowledgeModel>, ?> node = new NodeImpl<>(UUID.uuid());
final View<BusinessKnowledgeModel> view = new ViewImpl<>(wb, Bounds.create());
node.setContent(view);
final org.kie.dmn.model.api.BusinessKnowledgeModel dmn = converter.dmnFromNode(node, componentWidthsConsumer);
assertThat(dmn).isNotNull();
assertThat(dmn.getId()).isNotNull();
assertThat(dmn.getId()).isEqualTo(DECISION_UUID);
assertThat(dmn.getName()).isNotNull();
assertThat(dmn.getName()).isEqualTo(DECISION_NAME);
assertThat(dmn.getDescription()).isNotNull();
assertThat(dmn.getDescription()).isEqualTo(DECISION_DESCRIPTION);
assertThat(dmn.getVariable()).isNotNull();
assertThat(dmn.getVariable().getName()).isEqualTo(DECISION_NAME);
assertThat(dmn.getEncapsulatedLogic()).isNotNull();
assertThat(dmn.getEncapsulatedLogic().getExpression()).isNotNull();
assertThat(dmn.getEncapsulatedLogic().getExpression().getId()).isEqualTo(EXPRESSION_UUID);
verify(componentWidthsConsumer, times(2)).accept(componentWidthsCaptor.capture());
final List<ComponentWidths> componentWidths = componentWidthsCaptor.getAllValues();
assertThat(componentWidths).isNotNull();
assertThat(componentWidths).hasSize(2);
final ComponentWidths componentWidths0 = componentWidths.get(0);
assertThat(componentWidths0.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
assertThat(componentWidths0.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
assertThat(componentWidths0.getWidths().get(0)).isEqualTo(200.0);
final ComponentWidths componentWidths1 = componentWidths.get(1);
assertThat(componentWidths1.getDmnElementRef().getLocalPart()).isEqualTo(FUNCTION_DEFINITION_UUID);
assertThat(componentWidths1.getWidths().size()).isEqualTo(functionDefinition.getRequiredComponentWidthCount());
assertThat(componentWidths1.getWidths().get(0)).isEqualTo(200.0);
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DecisionConverterTest method testDMNFromWB.
@Test
public void testDMNFromWB() {
final Decision wb = new Decision();
final LiteralExpression literalExpression = new LiteralExpression();
final InformationItemPrimary informationItem = new InformationItemPrimary();
literalExpression.getComponentWidths().set(0, 200.0);
literalExpression.getId().setValue(EXPRESSION_UUID);
wb.getId().setValue(DECISION_UUID);
wb.getName().setValue(DECISION_NAME);
wb.getDescription().setValue(DECISION_DESCRIPTION);
wb.setVariable(informationItem);
wb.setExpression(literalExpression);
final Node<View<Decision>, ?> node = new NodeImpl<>(UUID.uuid());
final View<Decision> view = new ViewImpl<>(wb, Bounds.create());
node.setContent(view);
final org.kie.dmn.model.api.Decision dmn = converter.dmnFromNode(node, componentWidthsConsumer);
assertThat(dmn).isNotNull();
assertThat(dmn.getId()).isNotNull();
assertThat(dmn.getId()).isEqualTo(DECISION_UUID);
assertThat(dmn.getName()).isNotNull();
assertThat(dmn.getName()).isEqualTo(DECISION_NAME);
assertThat(dmn.getDescription()).isNotNull();
assertThat(dmn.getDescription()).isEqualTo(DECISION_DESCRIPTION);
assertThat(dmn.getVariable()).isNotNull();
assertThat(dmn.getVariable().getName()).isEqualTo(DECISION_NAME);
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