Search in sources :

Example 11 with ContextEntry

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

the class ContextEntryPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final ContextEntry wb = new ContextEntry();
    final InformationItem informationItem = new InformationItem();
    wb.setVariable(informationItem);
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.setExpression(literalExpression);
    final org.kie.dmn.model.api.ContextEntry dmn = ContextEntryPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getVariable()).isNotNull();
    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);
}
Also used : TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry) Test(org.junit.Test)

Example 12 with ContextEntry

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

the class PMMLIncludedModelHandler method destroy.

@Override
public void destroy(final String oldModelName) {
    final List<Decision> decisions = getDecisions();
    final List<BusinessKnowledgeModel> businessKnowledgeModels = getBusinessKnowledgeModels();
    final List<FunctionDefinition> functions = getPMMLFunctionDefinitions(decisions, businessKnowledgeModels);
    final Map<FunctionDefinition, Context> contexts = getPMMLContexts(functions);
    // The values in the DMN model are stored with quotes
    final String quotedOldModelName = StringUtils.createQuotedString(oldModelName);
    for (final Map.Entry<FunctionDefinition, Context> entry : contexts.entrySet()) {
        final Context context = entry.getValue();
        for (final ContextEntry contextEntry : context.getContextEntry()) {
            if (Objects.equals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, contextEntry.getVariable().getName().getValue())) {
                final Expression expression = contextEntry.getExpression();
                if (expression instanceof IsLiteralExpression) {
                    final IsLiteralExpression ile = (IsLiteralExpression) expression;
                    if (Objects.nonNull(ile.getText())) {
                        final Text text = ile.getText();
                        if (Objects.equals(quotedOldModelName, text.getValue())) {
                            clearContextValues(context);
                            entry.getKey().getFormalParameter().clear();
                        }
                    }
                }
            }
        }
    }
    // Refresh cached grids from the DMN model
    refreshCachedExpressionGrids(decisions, businessKnowledgeModels);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Map(java.util.Map)

Example 13 with ContextEntry

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

the class AddContextEntryCommandTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    this.context = new Context();
    this.contextEntry = new ContextEntry() {

        {
            setVariable(new InformationItem() {

                {
                    setName(new Name("variable"));
                }
            });
        }
    };
    this.defaultResultContextEntry = new ContextEntry();
    this.context.getContextEntry().add(defaultResultContextEntry);
    this.uiModel = new BaseGridData();
    this.uiModelRow = new BaseGridRow();
    this.uiDefaultResultModelRow = new BaseGridRow();
    this.uiModel.appendRow(uiDefaultResultModelRow);
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    doReturn(uiModel).when(gridWidget).getModel();
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiNameColumn).getIndex();
    doReturn(2).when(uiExpressionEditorColumn).getIndex();
    this.uiModel.setCellValue(0, 2, new ExpressionCellValue(Optional.of(undefinedExpressionEditor)));
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    doReturn(parent).when(undefinedExpressionEditor).getParentInformation();
    doReturn(Optional.empty()).when(undefinedExpressionEditorDefinition).getModelClass();
    doReturn(Optional.of(undefinedExpressionEditor)).when(undefinedExpressionEditorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt());
    this.uiModelMapper = new ContextUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(context), () -> false, () -> expressionEditorDefinitions, listSelector, 0);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) ContextUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ContextUIModelMapper) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 14 with ContextEntry

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

the class AddContextEntryCommandTest method testCanvasCommandExecuteMultipleEntries.

@Test
public void testCanvasCommandExecuteMultipleEntries() {
    makeCommand();
    // first row
    command.newGraphCommand(handler).execute(gce);
    final Command<AbstractCanvasHandler, CanvasViolation> firstEntryCanvasCommand = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, firstEntryCanvasCommand.execute(handler));
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    // second row
    final ContextEntry secondRowEntry = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    final GridRow uiSecondModelRow = new BaseGridRow();
    command = spy(new AddContextEntryCommand(context, secondRowEntry, uiModel, uiSecondModelRow, context.getContextEntry().size() - 1, uiModelMapper, canvasOperation));
    command.newGraphCommand(handler).execute(gce);
    final Command<AbstractCanvasHandler, CanvasViolation> secondEntryCanvasCommand = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, secondEntryCanvasCommand.execute(handler));
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    assertEquals(3, uiModel.getRowCount());
    assertEquals(uiModelRow, uiModel.getRows().get(0));
    assertEquals(uiSecondModelRow, uiModel.getRows().get(1));
    assertEquals(uiDefaultResultModelRow, uiModel.getRows().get(2));
    assertEquals(3, uiModel.getColumnCount());
    assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
    assertEquals(uiNameColumn, uiModel.getColumns().get(1));
    assertEquals(uiExpressionEditorColumn, uiModel.getColumns().get(2));
    assertEquals(3, uiModel.getRows().get(0).getCells().size());
    assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
    assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "1", ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(0, 1).getValue().getValue()).getName().getValue());
    assertTrue(uiModel.getCell(0, 2).getValue() instanceof ExpressionCellValue);
    assertEquals(3, uiModel.getRows().get(1).getCells().size());
    assertEquals(2, uiModel.getCell(1, 0).getValue().getValue());
    assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "2", ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(1, 1).getValue().getValue()).getName().getValue());
    assertTrue(uiModel.getCell(1, 2).getValue() instanceof ExpressionCellValue);
    // Default row
    assertEquals(1, uiModel.getRows().get(2).getCells().size());
    assertTrue(uiModel.getCell(2, 2).getValue() instanceof ExpressionCellValue);
    verify(canvasOperation, times(2)).execute();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Test(org.junit.Test)

Example 15 with ContextEntry

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

the class DeleteContextEntryCommandTest method setup.

@Before
public void setup() {
    this.context = new Context();
    this.context.getContextEntry().add(new ContextEntry());
    this.uiModel = new BaseGridData(false);
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiModelColumn).getIndex();
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Before(org.junit.Before)

Aggregations

ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)40 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)22 Context (org.kie.workbench.common.dmn.api.definition.model.Context)19 Test (org.junit.Test)16 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)6 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)5 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)5 TContextEntry (org.kie.dmn.model.v1_2.TContextEntry)4 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)4 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)4 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)4 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)4 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)4 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)3 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)3 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)3