Search in sources :

Example 16 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class ActivityTest method testUserTaskWithAssignment.

@Test
public void testUserTaskWithAssignment() throws Exception {
    ProcessDialectRegistry.setDialect("custom", new ProcessDialect() {

        @Override
        public ReturnValueEvaluatorBuilder getReturnValueEvaluatorBuilder() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public ProcessClassBuilder getProcessClassBuilder() {
            return null;
        }

        @Override
        public AssignmentBuilder getAssignmentBuilder() {
            return new AssignmentBuilder() {

                @Override
                public void build(PackageBuildContext context, Assignment assignment, List<DataDefinition> sourceExpr, DataDefinition targetExpr) {
                    assertEquals("from_expression", assignment.getFrom().getExpression());
                    assertEquals("to_expression", assignment.getTo().getExpression());
                }
            };
        }

        @Override
        public ActionBuilder getActionBuilder() {
            return null;
        }

        @Override
        public void addProcess(ProcessBuildContext context) {
        }
    });
    kruntime = createKogitoProcessRuntime("BPMN2-DataOutputAssignmentCustomExpressionLang.bpmn2");
    Process scriptProcess = kruntime.getKieBase().getProcess("process");
    assertThat(scriptProcess).isNotNull();
    Node[] nodes = ((NodeContainer) scriptProcess).getNodes();
    assertThat(nodes).hasSize(3);
    assertThat(nodes).filteredOn(n -> n instanceof WorkItemNode).allMatch(this::matchExpectedAssociationSetup);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> params = new HashMap<>();
    params.put("name", "John");
    KogitoProcessInstance processInstance = kruntime.startProcess("process", params);
    kruntime.abortProcessInstance(processInstance.getStringId());
    assertProcessInstanceAborted(processInstance);
}
Also used : BeforeMatchFiredEvent(org.kie.api.event.rule.BeforeMatchFiredEvent) Address(org.jbpm.bpmn2.objects.Address) Account(org.jbpm.bpmn2.objects.Account) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HelloService(org.jbpm.bpmn2.objects.HelloService) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) Disabled(org.junit.jupiter.api.Disabled) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) Assignment(org.jbpm.workflow.core.node.Assignment) KogitoNodeInstanceContainer(org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer) BigDecimal(java.math.BigDecimal) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) Map(java.util.Map) ProcessBuildContext(org.jbpm.process.builder.ProcessBuildContext) ProcessDialectRegistry(org.jbpm.process.builder.dialect.ProcessDialectRegistry) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) ActionBuilder(org.jbpm.process.builder.ActionBuilder) ProcessClassBuilder(org.jbpm.process.builder.ProcessClassBuilder) RuleAwareProcessEventListener(org.jbpm.process.instance.event.listeners.RuleAwareProcessEventListener) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) Process(org.kie.api.definition.process.Process) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) SendTaskHandler(org.jbpm.bpmn2.handler.SendTaskHandler) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Assertions.fail(org.assertj.core.api.Assertions.fail) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Person(org.jbpm.bpmn2.objects.Person) KogitoWorkItemManager(org.kie.kogito.internal.process.runtime.KogitoWorkItemManager) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) NodeContainer(org.kie.api.definition.process.NodeContainer) DynamicUtils(org.jbpm.workflow.instance.node.DynamicUtils) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AssignmentBuilder(org.jbpm.process.builder.AssignmentBuilder) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) NodeInstance(org.kie.api.runtime.process.NodeInstance) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) ExecutableCommand(org.kie.api.command.ExecutableCommand) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) ArrayList(java.util.ArrayList) TriggerRulesEventListener(org.jbpm.process.instance.event.listeners.TriggerRulesEventListener) DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) DataTransformer(org.kie.api.runtime.process.DataTransformer) ActionNode(org.jbpm.workflow.core.node.ActionNode) ReturnValueEvaluatorBuilder(org.jbpm.process.builder.ReturnValueEvaluatorBuilder) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) PackageBuildContext(org.drools.compiler.rule.builder.PackageBuildContext) DataTransformerRegistry(org.jbpm.process.core.impl.DataTransformerRegistry) Node(org.kie.api.definition.process.Node) NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) MatchCreatedEvent(org.kie.api.event.rule.MatchCreatedEvent) Collections(java.util.Collections) Timeout(org.junit.jupiter.api.Timeout) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) MatchCancelledEvent(org.kie.api.event.rule.MatchCancelledEvent) ReceiveTaskHandler(org.jbpm.bpmn2.handler.ReceiveTaskHandler) TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) ActionBuilder(org.jbpm.process.builder.ActionBuilder) HashMap(java.util.HashMap) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) Node(org.kie.api.definition.process.Node) Process(org.kie.api.definition.process.Process) NodeContainer(org.kie.api.definition.process.NodeContainer) ProcessDialect(org.jbpm.process.builder.dialect.ProcessDialect) AssignmentBuilder(org.jbpm.process.builder.AssignmentBuilder) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition) ProcessClassBuilder(org.jbpm.process.builder.ProcessClassBuilder) Assignment(org.jbpm.workflow.core.node.Assignment) PackageBuildContext(org.drools.compiler.rule.builder.PackageBuildContext) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ProcessBuildContext(org.jbpm.process.builder.ProcessBuildContext) ReturnValueEvaluatorBuilder(org.jbpm.process.builder.ReturnValueEvaluatorBuilder) Test(org.junit.jupiter.api.Test)

Example 17 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method writeCatchIO.

protected void writeCatchIO(IOSpecification ioSpecification, StringBuilder xmlDump) {
    for (DataDefinition output : ioSpecification.getDataOutput().values()) {
        xmlDump.append("        <dataOutput id=\"" + output.getId() + "\" name=\"" + output.getLabel() + "\" />" + EOL);
    }
    for (DataAssociation output : ioSpecification.getDataOutputAssociation()) {
        xmlDump.append("      <dataOutputAssociation>" + EOL);
        writeDataAssociation(output, xmlDump);
        xmlDump.append("      </dataOutputAssociation>" + EOL);
    }
}
Also used : DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Example 18 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method writeDataAssociation.

protected void writeDataAssociation(DataAssociation input, StringBuilder xmlDump) {
    for (DataDefinition source : input.getSources()) {
        xmlDump.append("        <sourceRef>" + source.getId() + "</sourceRef>" + EOL);
    }
    if (input.getTarget() != null) {
        xmlDump.append("<targetRef>" + input.getTarget().getId() + "</targetRef>" + EOL);
    }
    if (!input.getAssignments().isEmpty()) {
        for (Assignment assignment : input.getAssignments()) {
            xmlDump.append("        <assignment>" + EOL);
            xmlDump.append("             <from xsi:type=\"tFormalExpression\">" + assignment.getFrom().getExpression() + "</from>");
            xmlDump.append("             <to xsi:type=\"tFormalExpression\">" + assignment.getTo().getExpression() + "</to>");
            xmlDump.append("        </assignment>" + EOL);
        }
    }
}
Also used : Assignment(org.jbpm.workflow.core.node.Assignment) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Example 19 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method readDataAssociation.

protected Optional<DataAssociation> readDataAssociation(ExtensibleXmlParser parser, org.w3c.dom.Element element, Function<String, DataDefinition> sourceResolver, Function<String, DataDefinition> targetResolver) {
    List<DataDefinition> sources = readSources(element, sourceResolver);
    DataDefinition target = readTarget(element, targetResolver);
    List<Assignment> assignments = readAssignments(element, target, src -> {
        if (".".equals(src)) {
            return sources.get(0);
        }
        return sourceResolver.apply(src);
    }, dst -> {
        if (".".equals(dst)) {
            return target;
        }
        return targetResolver.apply(dst);
    });
    Transformation transformation = readTransformation(element);
    DataAssociation da = new DataAssociation(sources, target, assignments, transformation);
    if (da.getTarget() != null && da.getSources().isEmpty() && da.getAssignments().isEmpty()) {
        // incomplete description we ignore it
        logger.debug("Read incomplete data association, will be ignored\n{}", da);
        return Optional.empty();
    }
    return Optional.of(da);
}
Also used : Assignment(org.jbpm.workflow.core.node.Assignment) Transformation(org.jbpm.workflow.core.node.Transformation) DataAssociation(org.jbpm.workflow.core.impl.DataAssociation) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Example 20 with DataDefinition

use of org.jbpm.workflow.core.impl.DataDefinition in project kogito-runtimes by kiegroup.

the class AbstractNodeHandler method readMultiInstanceSpecification.

// this is only for compiling purposes
protected MultiInstanceSpecification readMultiInstanceSpecification(ExtensibleXmlParser parser, org.w3c.dom.Node parent, IOSpecification ioSpecification) {
    MultiInstanceSpecification multiInstanceSpecification = new MultiInstanceSpecification();
    Optional<Element> multiInstanceParent = readSingleChildElementByTag(parent, "multiInstanceLoopCharacteristics");
    if (multiInstanceParent.isEmpty()) {
        return multiInstanceSpecification;
    }
    Element multiInstanceNode = multiInstanceParent.get();
    multiInstanceSpecification.setSequential(Boolean.parseBoolean(multiInstanceNode.getAttribute("isSequential")));
    readSingleChildElementByTag(multiInstanceNode, "inputDataItem").ifPresent(inputDataItem -> {
        String id = inputDataItem.getAttribute("id");
        String name = inputDataItem.getAttribute("name");
        String itemSubjectRef = inputDataItem.getAttribute("itemSubjectRef");
        ItemDefinition itemDefinition = getStructureRef(parser, itemSubjectRef);
        String structureRef = itemDefinition != null ? itemDefinition.getStructureRef() : null;
        DataDefinition input = new DataDefinition(id, name, structureRef);
        multiInstanceSpecification.setInputDataItem(input);
        if (!ioSpecification.containsInputLabel(input.getLabel())) {
            ioSpecification.getDataInputs().add(input);
        }
    });
    readSingleChildElementByTag(multiInstanceNode, "outputDataItem").ifPresent(outputDataItem -> {
        String id = outputDataItem.getAttribute("id");
        String name = outputDataItem.getAttribute("name");
        String itemSubjectRef = outputDataItem.getAttribute("itemSubjectRef");
        ItemDefinition itemDefinition = getStructureRef(parser, itemSubjectRef);
        String structureRef = itemDefinition != null ? itemDefinition.getStructureRef() : null;
        DataDefinition output = new DataDefinition(id, name, structureRef);
        multiInstanceSpecification.setOutputDataItem(output);
        if (!ioSpecification.containsOutputLabel(output.getLabel())) {
            ioSpecification.getDataOutputs().add(output);
        }
    });
    readSingleChildElementByTag(multiInstanceNode, "loopDataOutputRef").ifPresent(loopDataOutputRef -> {
        String expressiontOutput = loopDataOutputRef.getTextContent();
        if (expressiontOutput != null && !expressiontOutput.isEmpty()) {
            multiInstanceSpecification.setLoopDataOutputRef(ioSpecification.getDataOutput().get(expressiontOutput));
        }
    });
    readSingleChildElementByTag(multiInstanceNode, "loopDataInputRef").ifPresent(loopDataInputRef -> {
        String expressionInput = loopDataInputRef.getTextContent();
        if (expressionInput != null && !expressionInput.isEmpty()) {
            multiInstanceSpecification.setLoopDataInputRef(ioSpecification.getDataInput().get(expressionInput));
        }
    });
    readSingleChildElementByTag(multiInstanceNode, COMPLETION_CONDITION).ifPresent(completeCondition -> {
        String completion = completeCondition.getTextContent();
        if (completion != null && !completion.isEmpty()) {
            multiInstanceSpecification.setCompletionCondition(completion);
        }
    });
    return multiInstanceSpecification;
}
Also used : MultiInstanceSpecification(org.jbpm.workflow.core.impl.MultiInstanceSpecification) Element(org.w3c.dom.Element) ItemDefinition(org.jbpm.bpmn2.core.ItemDefinition) DataDefinition(org.jbpm.workflow.core.impl.DataDefinition)

Aggregations

DataDefinition (org.jbpm.workflow.core.impl.DataDefinition)31 DataAssociation (org.jbpm.workflow.core.impl.DataAssociation)12 ArrayList (java.util.ArrayList)9 Assignment (org.jbpm.workflow.core.node.Assignment)9 VariableScope (org.jbpm.process.core.context.variable.VariableScope)8 Element (org.w3c.dom.Element)7 Node (org.jbpm.workflow.core.Node)6 Transformation (org.jbpm.workflow.core.node.Transformation)6 ItemDefinition (org.jbpm.bpmn2.core.ItemDefinition)5 MultiInstanceSpecification (org.jbpm.workflow.core.impl.MultiInstanceSpecification)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Variable (org.jbpm.process.core.context.variable.Variable)4 DataTransformerRegistry (org.jbpm.process.core.impl.DataTransformerRegistry)4 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)3 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)3 Thread.currentThread (java.lang.Thread.currentThread)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3