Search in sources :

Example 11 with FunctionDefinition

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

the class ExpressionPropertyConverterTest method testDMNFromWB_FunctionDefinitionConversion.

@Test
public void testDMNFromWB_FunctionDefinitionConversion() {
    final FunctionDefinition wb = new FunctionDefinition();
    final List<Double> wbComponentWidths = wb.getComponentWidths();
    wbComponentWidths.set(0, 100.0);
    wbComponentWidths.set(1, 200.0);
    wb.getId().setValue(EXPRESSION_UUID);
    assertDMNFromWBConversion(wb, TFunctionDefinition.class, 100.0, 200.0);
}
Also used : FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) Test(org.junit.Test)

Example 12 with FunctionDefinition

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

the class FunctionColumnParametersHeaderMetaDataTest method setup.

@Before
public void setup() {
    this.function = new FunctionDefinition();
    this.functionSupplier = () -> Optional.ofNullable(function);
    this.header = new FunctionColumnParametersHeaderMetaData(functionSupplier, translationService, cellEditorControls, parametersEditor, gridWidget);
    when(translationService.getTranslation(Mockito.<String>any())).thenAnswer((i) -> i.getArguments()[0]);
}
Also used : FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Before(org.junit.Before)

Example 13 with FunctionDefinition

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsBKM.

@Test
public void testModelEnrichmentWhenParentIsBKM() {
    final FunctionDefinition functionDefinition = mock(FunctionDefinition.class);
    final DMNModelInstrumentedBase dmnModelInstrumentedBase = mock(DMNModelInstrumentedBase.class);
    final BusinessKnowledgeModel businessKnowledgeModel = new BusinessKnowledgeModel();
    businessKnowledgeModel.setVariable(new InformationItemPrimary(new Id(), new Name(), OUTPUT_DATA_QNAME));
    businessKnowledgeModel.setEncapsulatedLogic(functionDefinition);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(functionDefinition);
    when(functionDefinition.asDMNModelInstrumentedBase()).thenReturn(dmnModelInstrumentedBase);
    when(dmnModelInstrumentedBase.getParent()).thenReturn(businessKnowledgeModel);
    definition.enrich(Optional.empty(), functionDefinition, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    assertStandardInputClauseEnrichment(model);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
    assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 14 with FunctionDefinition

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

the class FunctionGrid method doSetKind.

void doSetKind(final FunctionDefinition.Kind kind, final FunctionDefinition function, final Optional<ExpressionEditorDefinition<Expression>> oDefinition) {
    oDefinition.ifPresent(definition -> {
        final GridCellTuple parent = new GridCellTuple(0, 1, FunctionGrid.this);
        final Optional<Expression> expression = definition.getModelClass();
        definition.enrich(nodeUUID, hasExpression, expression);
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new SetKindCommand(parent, function, kind, expression, (editor) -> {
            editor.ifPresent(e -> {
                e.resize(BaseExpressionGrid.RESIZE_EXISTING);
                e.selectFirstCell();
            });
        }, () -> {
            resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
            selectFirstCell();
        }, () -> {
            Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = Optional.empty();
            editor = definition.getEditor(parent, Optional.empty(), getExpression().get().get(), hasName, isOnlyVisualChangeAllowed, nesting + 1);
            return editor;
        }));
    });
}
Also used : CellEditorControlsView(org.kie.workbench.common.dmn.client.widgets.grid.controls.container.CellEditorControlsView) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) UpdateParameterNameCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.UpdateParameterNameCommand) RemoveParameterCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.RemoveParameterCommand) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) ListSelectorView(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelectorView) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) DMNGridLayer(org.kie.workbench.common.dmn.client.widgets.layer.DMNGridLayer) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) UndefinedExpressionGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionGrid) ClearExpressionTypeCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.ClearExpressionTypeCommand) EventPropagationMode(com.ait.lienzo.shared.core.types.EventPropagationMode) KindPopoverView(org.kie.workbench.common.dmn.client.editors.expressions.types.function.kindselector.KindPopoverView) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) HasParametersControl(org.kie.workbench.common.dmn.client.editors.expressions.types.function.parameters.HasParametersControl) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AddParameterCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.AddParameterCommand) DomainObject(org.kie.workbench.common.stunner.core.domainobject.DomainObject) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) ParametersPopoverView(org.kie.workbench.common.dmn.client.editors.expressions.types.function.parameters.ParametersPopoverView) DefaultCanvasCommandFactory(org.kie.workbench.common.dmn.client.commands.factory.DefaultCanvasCommandFactory) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Optional(java.util.Optional) ValueAndDataTypePopoverView(org.kie.workbench.common.dmn.client.editors.types.ValueAndDataTypePopoverView) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) HasListSelectorControl(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl) ExpressionType(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionType) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionEditorChanged(org.kie.workbench.common.dmn.client.widgets.grid.model.ExpressionEditorChanged) RefreshFormPropertiesEvent(org.kie.workbench.common.stunner.forms.client.event.RefreshFormPropertiesEvent) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) ReadOnlyProvider(org.kie.workbench.common.stunner.core.client.ReadOnlyProvider) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasKindSelectControl(org.kie.workbench.common.dmn.client.editors.expressions.types.function.kindselector.HasKindSelectControl) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) Command(org.uberfire.mvp.Command) Event(javax.enterprise.event.Event) SetKindCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetKindCommand) DMNEditorConstants(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants) DMNGridPanel(org.kie.workbench.common.dmn.client.widgets.panel.DMNGridPanel) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) UndefinedExpressionColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionColumn) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) DomainObjectSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.DomainObjectSelectionEvent) UpdateParameterTypeRefCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.UpdateParameterTypeRefCommand) ExpressionEditorGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.ExpressionEditorGridRow) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) SetKindCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetKindCommand) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Optional(java.util.Optional) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression)

Example 15 with FunctionDefinition

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

the class FunctionEditorDefinitionTest method testModelEnrichment.

@Test
public void testModelEnrichment() {
    final Optional<FunctionDefinition> oModel = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, oModel);
    final FunctionDefinition model = oModel.get();
    assertEquals(FunctionDefinition.Kind.FEEL.code(), model.getKind().code());
    assertTrue(model.getExpression() instanceof LiteralExpression);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Test(org.junit.Test)

Aggregations

FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)40 Test (org.junit.Test)12 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)12 Context (org.kie.workbench.common.dmn.api.definition.model.Context)11 ArrayList (java.util.ArrayList)8 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)8 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)8 Before (org.junit.Before)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 TFunctionDefinition (org.kie.dmn.model.v1_2.TFunctionDefinition)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)5 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)5 IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 List (java.util.List)4 QName (javax.xml.namespace.QName)4 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)4