Search in sources :

Example 6 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context 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 DMNGridRow();
    this.uiDefaultResultModelRow = new DMNGridRow();
    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), any(Optional.class), anyInt());
    this.uiModelMapper = new ContextUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(context), () -> expressionEditorDefinitions, listSelector, 0);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.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) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) Optional(java.util.Optional) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.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.v1_1.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 7 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context 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() {

                {
                    setName(new Name("last entry"));
                }
            });
        }
    };
    final DMNGridRow uiSecondModelRow = new DMNGridRow();
    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("variable", uiModel.getCell(0, 1).getValue().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("last entry", uiModel.getCell(1, 1).getValue().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) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) ContextEntry(org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 8 with Context

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

the class AddDecisionRuleCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            dtable.getRule().add(uiRowIndex, rule);
            for (int ie = 0; ie < dtable.getInput().size(); ie++) {
                final UnaryTests ut = new UnaryTests();
                ut.setText(AddInputClauseCommand.INPUT_CLAUSE_DEFAULT_VALUE);
                rule.getInputEntry().add(ut);
            }
            for (int oe = 0; oe < dtable.getOutput().size(); oe++) {
                final LiteralExpression le = new LiteralExpression();
                le.setText(AddOutputClauseCommand.OUTPUT_CLAUSE_DEFAULT_VALUE);
                rule.getOutputEntry().add(le);
            }
            final Description d = new Description();
            d.setValue(DESCRIPTION_DEFAULT_VALUE);
            rule.setDescription(d);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            dtable.getRule().remove(rule);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)

Example 9 with Context

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

the class AddInputClauseCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
            dtable.getInput().add(clauseIndex, inputClause);
            dtable.getRule().forEach(rule -> {
                final UnaryTests ut = new UnaryTests();
                ut.setText(INPUT_CLAUSE_DEFAULT_VALUE);
                rule.getInputEntry().add(clauseIndex, ut);
            });
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            final int clauseIndex = dtable.getInput().indexOf(inputClause);
            dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex));
            dtable.getInput().remove(inputClause);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)

Example 10 with Context

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

the class ContextEditorDefinition method getModelClass.

@Override
public Optional<Context> getModelClass() {
    // Add one ContextEntry for the User to start with
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    contextEntry.setVariable(new InformationItem());
    context.getContextEntry().add(contextEntry);
    // Add (default) "result" entry
    final ContextEntry resultEntry = new ContextEntry();
    resultEntry.setExpression(new LiteralExpression());
    context.getContextEntry().add(resultEntry);
    return Optional.of(context);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)36 CoreException (org.eclipse.core.runtime.CoreException)34 Test (org.junit.Test)25 BoolExpr (com.microsoft.z3.BoolExpr)23 List (java.util.List)21 IOException (java.io.IOException)18 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)17 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 HashMap (java.util.HashMap)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)14 File (java.io.File)13 Solver (com.microsoft.z3.Solver)12 Status (com.microsoft.z3.Status)12 IPath (org.eclipse.core.runtime.IPath)11 IStatus (org.eclipse.core.runtime.IStatus)11 Status (org.eclipse.core.runtime.Status)11 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)11 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)10