use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class ExpressionPropertyConverter method wbFromDMN.
public static Expression wbFromDMN(final org.kie.dmn.model.api.Expression dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
if (dmn instanceof org.kie.dmn.model.api.LiteralExpression) {
final LiteralExpression e = LiteralExpressionPropertyConverter.wbFromDMN((org.kie.dmn.model.api.LiteralExpression) dmn);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.Context) {
final Context e = ContextPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Context) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.Relation) {
final Relation e = RelationPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Relation) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.List) {
final List e = ListPropertyConverter.wbFromDMN((org.kie.dmn.model.api.List) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.Invocation) {
final Invocation e = InvocationPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Invocation) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.FunctionDefinition) {
final FunctionDefinition e = FunctionDefinitionPropertyConverter.wbFromDMN((org.kie.dmn.model.api.FunctionDefinition) dmn, hasComponentWidthsConsumer);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
} else if (dmn instanceof org.kie.dmn.model.api.DecisionTable) {
final DecisionTable e = DecisionTablePropertyConverter.wbFromDMN((org.kie.dmn.model.api.DecisionTable) dmn);
hasComponentWidthsConsumer.accept(dmn.getId(), e);
return e;
}
return null;
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class AddParameterCommandTest method setup.
@Before
public void setup() {
this.function = new FunctionDefinition();
this.parameter = new InformationItem();
this.command = new AddParameterCommand(function, parameter, canvasOperation);
doReturn(ruleManager).when(handler).getRuleManager();
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method test_function_java_WB_model.
@Test
public void test_function_java_WB_model() throws IOException {
final DMNMarshallerStandalone m = getDMNMarshaller();
@SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final Stream<Node<?, ?>> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(g.nodes().iterator(), Spliterator.ORDERED), false);
final Optional<Decision> wbDecision = stream.filter(n -> n.getContent() instanceof ViewImpl).map(n -> (ViewImpl) n.getContent()).filter(n -> n.getDefinition() instanceof Decision).map(n -> (Decision) n.getDefinition()).findFirst();
wbDecision.ifPresent(d -> {
assertTrue(d.getExpression() instanceof FunctionDefinition);
final FunctionDefinition wbFunction = (FunctionDefinition) d.getExpression();
// This is what the WB expects
assertEquals(FunctionDefinition.Kind.JAVA, wbFunction.getKind());
});
final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final DMNModel dmnModel = runtime.getModels().get(0);
final BusinessKnowledgeModelNode bkmNode = dmnModel.getBusinessKnowledgeModels().iterator().next();
final org.kie.dmn.model.api.FunctionDefinition dmnFunction = bkmNode.getBusinessKnowledModel().getEncapsulatedLogic();
assertEquals(FunctionKind.JAVA, dmnFunction.getKind());
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class FunctionUIModelMapperTest method setup.
@SuppressWarnings("unchecked")
public void setup(final boolean isOnlyVisualChangeAllowedSupplier) {
this.uiModel = new BaseGridData();
this.uiModel.appendRow(new BaseGridRow());
this.uiModel.appendRow(new BaseGridRow());
this.uiModel.appendColumn(uiExpressionEditorColumn);
when(uiExpressionEditorColumn.getIndex()).thenReturn(0);
when(gridWidget.getModel()).thenReturn(uiModel);
// Core Editor definitions
final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
expressionEditorDefinitions.add(literalExpressionEditorDefinition);
when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
// Supplementary Editor definitions
final ExpressionEditorDefinitions supplementaryEditorDefinitions = new ExpressionEditorDefinitions();
supplementaryEditorDefinitions.add(supplementaryEditorDefinition);
when(supplementaryEditorDefinitionsSupplier.get()).thenReturn(supplementaryEditorDefinitions);
when(supplementaryEditorDefinition.getModelClass()).thenReturn(Optional.of(context));
when(supplementaryEditor.getExpression()).thenReturn(() -> Optional.of(context));
when(supplementaryEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(supplementaryEditor));
this.function = new FunctionDefinition();
this.mapper = new FunctionUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(function), () -> isOnlyVisualChangeAllowedSupplier, expressionEditorDefinitionsSupplier, supplementaryEditorDefinitionsSupplier, listSelector, 1);
this.cellValueSupplier = Optional::empty;
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class FunctionKindRowColumnHeaderMetaDataTest method setup.
@Before
public void setup() {
this.function = new FunctionDefinition();
this.functionSupplier = () -> Optional.ofNullable(function);
this.functionKindRow = new FunctionKindRowColumnHeaderMetaData(functionSupplier, cellEditorControls, editor, gridWidget);
}
Aggregations