@Test public void testDMNFromWB() { final FunctionDefinition wb = new FunctionDefinition(); final LiteralExpression literalExpression = new LiteralExpression(); literalExpression.getComponentWidths().set(0, 200.0); literalExpression.getId().setValue(EXPRESSION_UUID); wb.getId().setValue(FUNCTION_DEFINITION_UUID); wb.getDescription().setValue(FUNCTION_DEFINITION_DESCRIPTION); wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI, FUNCTION_DEFINITION_QNAME_LOCALPART)); wb.setKind(FunctionDefinition.Kind.JAVA); wb.setExpression(literalExpression); final org.kie.dmn.model.api.FunctionDefinition dmn = FunctionDefinitionPropertyConverter.dmnFromWB(wb, componentWidthsConsumer); assertThat(dmn).isNotNull(); assertThat(dmn.getId()).isNotNull(); assertThat(dmn.getId()).isEqualTo(FUNCTION_DEFINITION_UUID); assertThat(dmn.getDescription()).isNotNull(); assertThat(dmn.getDescription()).isEqualTo(FUNCTION_DEFINITION_DESCRIPTION); assertThat(dmn.getTypeRef()).isNotNull(); assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(FUNCTION_DEFINITION_QNAME_LOCALPART); assertThat(dmn.getKind()).isNotNull(); assertThat(dmn.getKind()).isEqualTo(FunctionKind.JAVA); 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); }
public static org.kie.dmn.model.api.FunctionDefinition dmnFromWB(final FunctionDefinition wb, final Consumer<ComponentWidths> componentWidthsConsumer) { if (wb == null) { return null; } final org.kie.dmn.model.api.FunctionDefinition result = new org.kie.dmn.model.v1_2.TFunctionDefinition(); result.setId(wb.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription())); QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef); result.setExpression(ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer)); final Kind kind = wb.getKind(); switch (kind) { case FEEL: result.setKind(FunctionKind.FEEL); break; case JAVA: result.setKind(FunctionKind.JAVA); break; case PMML: result.setKind(FunctionKind.PMML); break; default: result.setKind(FunctionKind.FEEL); break; } for (InformationItem ii : wb.getFormalParameter()) { final org.kie.dmn.model.api.InformationItem iiConverted = InformationItemPropertyConverter.dmnFromWB(ii); if (iiConverted != null) { iiConverted.setParent(result); } result.getFormalParameter().add(iiConverted); } return result; }
FunctionDefinitionPropertyConverter { public static org.kie.dmn.model.api.FunctionDefinition dmnFromWB(final FunctionDefinition wb, final Consumer<ComponentWidths> componentWidthsConsumer) { if (wb == null) { return null; } final org.kie.dmn.model.api.FunctionDefinition result = new org.kie.dmn.model.v1_2.TFunctionDefinition(); result.setId(wb.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription())); QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef); result.setExpression(ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer)); final Kind kind = wb.getKind(); switch (kind) { case FEEL: result.setKind(FunctionKind.FEEL); break; case JAVA: result.setKind(FunctionKind.JAVA); break; case PMML: result.setKind(FunctionKind.PMML); break; default: result.setKind(FunctionKind.FEEL); break; } for (InformationItem ii : wb.getFormalParameter()) { final org.kie.dmn.model.api.InformationItem iiConverted = InformationItemPropertyConverter.dmnFromWB(ii); if (iiConverted != null) { iiConverted.setParent(result); } result.getFormalParameter().add(iiConverted); } return result; } }
FunctionDefinitionPropertyConverter { public static org.kie.dmn.model.api.FunctionDefinition dmnFromWB(final FunctionDefinition wb, final Consumer<ComponentWidths> componentWidthsConsumer) { if (wb == null) { return null; } final org.kie.dmn.model.api.FunctionDefinition result = new org.kie.dmn.model.v1_2.TFunctionDefinition(); result.setId(wb.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription())); QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef); result.setExpression(ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer)); final Kind kind = wb.getKind(); switch (kind) { case FEEL: result.setKind(FunctionKind.FEEL); break; case JAVA: result.setKind(FunctionKind.JAVA); break; case PMML: result.setKind(FunctionKind.PMML); break; default: result.setKind(FunctionKind.FEEL); break; } for (InformationItem ii : wb.getFormalParameter()) { final org.kie.dmn.model.api.InformationItem iiConverted = InformationItemPropertyConverter.dmnFromWB(ii); if (iiConverted != null) { iiConverted.setParent(result); } result.getFormalParameter().add(iiConverted); } return result; }  }
FunctionDefinitionPropertyConverter { public static org.kie.dmn.model.api.FunctionDefinition dmnFromWB(final FunctionDefinition wb, final Consumer<ComponentWidths> componentWidthsConsumer) { if (wb == null) { return null; } final org.kie.dmn.model.api.FunctionDefinition result = new org.kie.dmn.model.v1_2.TFunctionDefinition(); result.setId(wb.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription())); QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef); result.setExpression(ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer)); final Kind kind = wb.getKind(); switch (kind) { case FEEL: result.setKind(FunctionKind.FEEL); break; case JAVA: result.setKind(FunctionKind.JAVA); break; case PMML: result.setKind(FunctionKind.PMML); break; default: result.setKind(FunctionKind.FEEL); break; } for (InformationItem ii : wb.getFormalParameter()) { final org.kie.dmn.model.api.InformationItem iiConverted = InformationItemPropertyConverter.dmnFromWB(ii); if (iiConverted != null) { iiConverted.setParent(result); } result.getFormalParameter().add(iiConverted); } return result; }  static FunctionDefinition wbFromDMN(final org.kie.dmn.model.api.FunctionDefinition dmn,
                                               final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer); static org.kie.dmn.model.api.FunctionDefinition dmnFromWB(final FunctionDefinition wb,
                                                                     final Consumer<ComponentWidths> componentWidthsConsumer); }
FunctionDefinitionPropertyConverter { public static org.kie.dmn.model.api.FunctionDefinition dmnFromWB(final FunctionDefinition wb, final Consumer<ComponentWidths> componentWidthsConsumer) { if (wb == null) { return null; } final org.kie.dmn.model.api.FunctionDefinition result = new org.kie.dmn.model.v1_2.TFunctionDefinition(); result.setId(wb.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription())); QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef); result.setExpression(ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer)); final Kind kind = wb.getKind(); switch (kind) { case FEEL: result.setKind(FunctionKind.FEEL); break; case JAVA: result.setKind(FunctionKind.JAVA); break; case PMML: result.setKind(FunctionKind.PMML); break; default: result.setKind(FunctionKind.FEEL); break; } for (InformationItem ii : wb.getFormalParameter()) { final org.kie.dmn.model.api.InformationItem iiConverted = InformationItemPropertyConverter.dmnFromWB(ii); if (iiConverted != null) { iiConverted.setParent(result); } result.getFormalParameter().add(iiConverted); } return result; }  static FunctionDefinition wbFromDMN(final org.kie.dmn.model.api.FunctionDefinition dmn,
                                               final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer); static org.kie.dmn.model.api.FunctionDefinition dmnFromWB(final FunctionDefinition wb,
                                                                     final Consumer<ComponentWidths> componentWidthsConsumer);  }