Search in sources :

Example 66 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context in project bmoth by hhu-stups.

the class InvariantSatisfiabilityChecker method doInvariantSatisfiabilityCheck.

static InvariantSatisfiabilityCheckingResult doInvariantSatisfiabilityCheck(MachineNode machine) {
    Context ctx = new Context();
    Solver solver = Z3SolverFactory.getZ3Solver(ctx);
    MachineToZ3Translator machineTranslator = new MachineToZ3Translator(machine, ctx);
    final BoolExpr invariant = machineTranslator.getInvariantConstraint();
    solver.add(invariant);
    Status check = solver.check();
    return new InvariantSatisfiabilityCheckingResult(check);
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Solver(com.microsoft.z3.Solver) MachineToZ3Translator(de.bmoth.backend.z3.MachineToZ3Translator)

Example 67 with Context

use of org.kie.workbench.common.dmn.api.definition.v1_1.Context in project bmoth by hhu-stups.

the class TestUsingZ3 method setup.

@Before
public void setup() {
    z3Context = new Context();
    z3Solver = z3Context.mkSolver();
}
Also used : Context(com.microsoft.z3.Context) Before(org.junit.Before)

Example 68 with Context

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

the class DMNMarshallerTest method test_wrong_context.

@Test
public void test_wrong_context() throws IOException {
    // DROOLS-2217
    // SPECIAL CASE: to represent a partially edited DMN file.
    // consider a LiteralExpression with null text as missing expression altogether.
    final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/wrong_context.dmn"));
    DMNModel dmnModel = runtime.getModels().get(0);
    // the DMN file is schema valid but is not a valid-DMN (a context-entry value is a literal expression missing text, which is null)
    assertTrue(dmnModel.hasErrors());
    // identify the error message for context-entry "ciao":
    DMNMessage m0 = dmnModel.getMessages(DMNMessage.Severity.ERROR).get(0);
    assertTrue("expected a message identifying the problem on a context entry for 'ciao'", m0.getMessage().startsWith("No expression defined for name 'ciao'"));
    DecisionNode d0 = dmnModel.getDecisionById("_653b3426-933a-4050-9568-ab2a66b43c36");
    // the identified DMN Decision is composed of a DMN Context where the first context-entry value is a literal expression missing text (text is null).
    org.kie.dmn.model.v1_1.Context d0c = (org.kie.dmn.model.v1_1.Context) d0.getDecision().getExpression();
    org.kie.dmn.model.v1_1.Expression contextEntryValue = d0c.getContextEntry().get(0).getExpression();
    assertTrue(contextEntryValue instanceof org.kie.dmn.model.v1_1.LiteralExpression);
    assertEquals(null, ((org.kie.dmn.model.v1_1.LiteralExpression) contextEntryValue).getText());
    // -- Stunner side.
    DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    Graph<?, ?> g = m.unmarshall(null, this.getClass().getResourceAsStream("/wrong_context.dmn"));
    DiagramImpl diagram = new DiagramImpl("", null);
    Node<?, ?> decisionNode = g.getNode("_653b3426-933a-4050-9568-ab2a66b43c36");
    assertNodeContentDefinitionIs(decisionNode, Decision.class);
    View<Decision> view = ((View<Decision>) decisionNode.getContent());
    // the identified DMN Decision is composed of a DMN Context where the first context-entry has missing Expression.
    Context expression = (Context) view.getDefinition().getExpression();
    assertEquals("a literalexpression with null text is threated as a missing expression altogether.", null, expression.getContextEntry().get(0).getExpression());
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) DMNContext(org.kie.dmn.api.core.DMNContext) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) DMNMessage(org.kie.dmn.api.core.DMNMessage) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 69 with Context

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

the class AddOutputClauseCommand 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().size();
            dtable.getOutput().add(clauseIndex, outputClause);
            dtable.getRule().forEach(rule -> {
                final LiteralExpression le = new LiteralExpression();
                le.setText(OUTPUT_CLAUSE_DEFAULT_VALUE);
                rule.getOutputEntry().add(clauseIndex, le);
            });
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            final int clauseIndex = dtable.getOutput().indexOf(outputClause);
            dtable.getRule().forEach(rule -> rule.getOutputEntry().remove(clauseIndex));
            dtable.getOutput().remove(outputClause);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : 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)

Example 70 with Context

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

the class MoveColumnsCommand method newGraphCommand.

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

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

        private boolean isColumnInValidSection() {
            final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
            return section == DecisionTableSection.INPUT_CLAUSES || section == DecisionTableSection.OUTPUT_CLAUSES;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            return moveClauses(index);
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            return moveClauses(oldIndex);
        }

        private CommandResult<RuleViolation> moveClauses(final int index) {
            final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
            if (section == DecisionTableSection.INPUT_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, oldIndex);
                final List<Integer> inputClauseIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).map(i -> DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getInput(), inputClauseIndexesToMove);
                final List<List<UnaryTests>> decisionRulesInputEntries = dtable.getRule().stream().map(DecisionRule::getInputEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesInputEntries, inputClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else if (section == DecisionTableSection.OUTPUT_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, oldIndex);
                final List<Integer> outputClauseIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).map(i -> DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getOutput(), outputClauseIndexesToMove);
                final List<List<LiteralExpression>> decisionRulesOutputEntries = dtable.getRule().stream().map(DecisionRule::getOutputEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesOutputEntries, outputClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else {
                return GraphCommandResultBuilder.FAILED;
            }
        }

        private <T> void moveClauses(final int relativeIndex, final int relativeOldIndex, final List<T> clauses, final List<Integer> clauseIndexesToMove) {
            final List<T> clausesToMove = clauseIndexesToMove.stream().map(clauses::get).collect(Collectors.toList());
            clauses.removeAll(clausesToMove);
            if (relativeIndex < relativeOldIndex) {
                clauses.addAll(relativeIndex, clausesToMove);
            } else if (relativeIndex > relativeOldIndex) {
                clauses.addAll(relativeIndex - clausesToMove.size() + 1, clausesToMove);
            }
        }

        private <T> void updateDecisionRules(final int relativeIndex, final int relativeOldIndex, final List<List<T>> clauses, final List<Integer> clauseIndexesToMove) {
            clauses.forEach(row -> moveClauses(relativeIndex, relativeOldIndex, row, clauseIndexesToMove));
        }
    };
}
Also used : DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DecisionTable(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable) DecisionTableUIModelMapperHelper(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) VetoExecutionCommand(org.kie.workbench.common.dmn.client.commands.VetoExecutionCommand) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AbstractCanvasCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasCommand) Collectors(java.util.stream.Collectors) AbstractCanvasGraphCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasGraphCommand) ArrayList(java.util.ArrayList) List(java.util.List) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) VetoUndoCommand(org.kie.workbench.common.dmn.client.commands.VetoUndoCommand) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) ArrayList(java.util.ArrayList) List(java.util.List)

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