Search in sources :

Example 11 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class InvocationPropertyConverter method wbFromDMN.

public static Invocation wbFromDMN(final org.kie.dmn.model.api.Invocation dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (dmn == null) {
        return null;
    }
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
    final Invocation result = new Invocation();
    result.setId(id);
    result.setDescription(description);
    result.setTypeRef(typeRef);
    final Expression convertedExpression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
    result.setExpression(convertedExpression);
    if (convertedExpression != null) {
        convertedExpression.setParent(result);
    }
    for (org.kie.dmn.model.api.Binding b : dmn.getBinding()) {
        final Binding bConverted = BindingPropertyConverter.wbFromDMN(b, hasComponentWidthsConsumer);
        if (bConverted != null) {
            bConverted.setParent(result);
        }
        result.getBinding().add(bConverted);
    }
    return result;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 12 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class ListPropertyConverter method dmnFromWB.

public static org.kie.dmn.model.api.List dmnFromWB(final List wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
    final org.kie.dmn.model.api.List result = new org.kie.dmn.model.v1_2.TList();
    result.setId(wb.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (HasExpression hasExpression : wb.getExpression()) {
        final Expression e = hasExpression.getExpression();
        final org.kie.dmn.model.api.Expression eConverted = ExpressionPropertyConverter.dmnFromWB(e, componentWidthsConsumer);
        if (Objects.nonNull(eConverted)) {
            eConverted.setParent(result);
        }
        result.getExpression().add(eConverted);
    }
    return result;
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression)

Example 13 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class ListPropertyConverter method wbFromDMN.

public static List wbFromDMN(final org.kie.dmn.model.api.List dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
    final java.util.List<HasExpression> expression = new ArrayList<>();
    final List result = new List(id, description, typeRef, expression);
    for (org.kie.dmn.model.api.Expression e : dmn.getExpression()) {
        final Expression eConverted = ExpressionPropertyConverter.wbFromDMN(e, hasComponentWidthsConsumer);
        final HasExpression hasExpression = HasExpression.wrap(result, eConverted);
        expression.add(hasExpression);
    }
    for (HasExpression hasExpression : expression) {
        final Expression e = hasExpression.getExpression();
        if (Objects.nonNull(e)) {
            e.setParent(result);
        }
    }
    return result;
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ArrayList(java.util.ArrayList) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) List(org.kie.workbench.common.dmn.api.definition.model.List) ArrayList(java.util.ArrayList) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 14 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class LiteralExpressionPMMLDocumentEditorDefinitionTest method testEditor.

@Test
public void testEditor() {
    when(hasExpression.getExpression()).thenReturn(definition.getModelClass().get());
    final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> oEditor = definition.getEditor(parent, Optional.empty(), hasExpression, hasName, false, 0);
    assertTrue(oEditor.isPresent());
    final GridWidget editor = oEditor.get();
    assertTrue(editor instanceof LiteralExpressionPMMLGrid);
}
Also used : LiteralExpressionPMMLGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.pmml.LiteralExpressionPMMLGrid) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) Test(org.junit.Test)

Example 15 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.

the class FunctionGridTest method assertSetKind.

@SuppressWarnings("unchecked")
private void assertSetKind(final ExpressionEditorDefinition definition, final BaseExpressionGrid editor, final FunctionDefinition.Kind expectedKind, final Class<?> expectedExpressionType, final Class<?> expectedEditorType) {
    verify(grid).doSetKind(eq(expectedKind), eq(expression.get()), expressionDefinitionCaptor.capture());
    verify(definition).enrich(any(Optional.class), eq(hasExpression), any(Optional.class));
    final ExpressionEditorDefinition<Expression> expressionDefinition = expressionDefinitionCaptor.getValue().get();
    assertThat(expectedExpressionType).isAssignableFrom(expressionDefinition.getModelClass().get().getClass());
    verify(sessionCommandManager).execute(eq(canvasHandler), setKindCommandCaptor.capture());
    final SetKindCommand setKindCommand = setKindCommandCaptor.getValue();
    setKindCommand.execute(canvasHandler);
    final GridCellValue<?> gcv = grid.getModel().getCell(0, 1).getValue();
    assertTrue(gcv instanceof ExpressionCellValue);
    final ExpressionCellValue ecv = (ExpressionCellValue) gcv;
    assertThat(expectedEditorType).isAssignableFrom(ecv.getValue().get().getClass());
    verify(editor).resize(eq(BaseExpressionGrid.RESIZE_EXISTING));
    verify(editor).selectFirstCell();
    verify(gridLayer).batch(redrawCommandCaptor.capture());
    redrawCommandCaptor.getValue().execute();
    verify(gridLayer).draw();
    // Check undo operation
    reset(grid, gridLayer);
    setKindCommand.undo(canvasHandler);
    verify(grid).resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
    verify(grid).selectFirstCell();
    verify(gridLayer).batch(redrawCommandCaptor.capture());
    assertThat(redrawCommandCaptor.getAllValues()).hasSize(2);
    redrawCommandCaptor.getAllValues().get(1).execute();
    verify(gridLayer).draw();
}
Also used : SetKindCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetKindCommand) Optional(java.util.Optional) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Aggregations

Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)75 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)41 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)29 Test (org.junit.Test)27 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)26 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)26 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)14 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)11 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)10 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)9 ArrayList (java.util.ArrayList)8 Context (org.kie.workbench.common.dmn.api.definition.model.Context)8 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)8 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)7 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)7