diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/handler/LoggingTaskHandlerDecorator.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/handler/LoggingTaskHandlerDecorator.java index be049745f4f..087d09ece76 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/handler/LoggingTaskHandlerDecorator.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/handler/LoggingTaskHandlerDecorator.java @@ -65,7 +65,7 @@ */ public class LoggingTaskHandlerDecorator extends AbstractExceptionHandlingTaskHandler { - private static final Logger logger = LoggerFactory.getLogger(LoggingTaskHandlerDecorator.class); + private static Logger logger = LoggerFactory.getLogger(LoggingTaskHandlerDecorator.class); private int loggedExceptionsLimit = 100; private Queue exceptionInfoList = new ArrayDeque<>(loggedExceptionsLimit); @@ -210,6 +210,10 @@ public synchronized void handleAbortException(Throwable cause, KogitoWorkItem wo logMessage(false, workItem, cause); } + public static void setLogger(Logger logger) { + LoggingTaskHandlerDecorator.logger = logger; + } + private void logMessage(boolean onExecute, KogitoWorkItem workItem, Throwable cause) { String handlerMethodStem = "execut"; if (!onExecute) { diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java index 7a16ef7380e..e8429c2272c 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AbstractNodeHandler.java @@ -49,7 +49,8 @@ import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.core.datatype.DataTypeResolver; -import org.jbpm.process.core.impl.DataTransformerRegistry; +import org.jbpm.process.instance.impl.MVELInterpretedReturnValueEvaluator; +import org.jbpm.process.instance.impl.ReturnValueEvaluator; import org.jbpm.ruleflow.core.RuleFlowProcess; import org.jbpm.ruleflow.core.WorkflowElementIdentifierFactory; import org.jbpm.util.PatternConstants; @@ -57,6 +58,7 @@ import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.NodeContainer; import org.jbpm.workflow.core.impl.DataAssociation; +import org.jbpm.workflow.core.impl.DataAssociation.DataAssociationType; import org.jbpm.workflow.core.impl.DataDefinition; import org.jbpm.workflow.core.impl.DroolsConsequenceAction; import org.jbpm.workflow.core.impl.ExtendedNodeImpl; @@ -74,7 +76,6 @@ import org.jbpm.workflow.core.node.StateNode; import org.jbpm.workflow.core.node.TimerNode; import org.jbpm.workflow.core.node.Transformation; -import org.kie.api.runtime.process.DataTransformer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; @@ -425,7 +426,10 @@ protected IOSpecification readCatchSpecification(Parser parser, Element element) while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("dataOutputAssociation".equals(nodeName)) { - readDataAssociation((Element) xmlNode, id -> ioSpec.getDataOutput().get(id), id -> getVariableDataSpec(parser, id)).ifPresent(e -> ioSpec.getDataOutputAssociation().add(e)); + readDataAssociation((Element) xmlNode, id -> ioSpec.getDataOutput().get(id), id -> getVariableDataSpec(parser, id)).ifPresent(e -> { + e.setType(DataAssociationType.OUTPUT); + ioSpec.getDataOutputAssociation().add(e); + }); } xmlNode = xmlNode.getNextSibling(); } @@ -440,7 +444,10 @@ protected IOSpecification readThrowSpecification(Parser parser, Element element) while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("dataInputAssociation".equals(nodeName)) { - readDataAssociation((Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> ioSpec.getDataInputAssociation().add(e)); + readDataAssociation((Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> { + e.setType(DataAssociationType.INPUT); + ioSpec.getDataInputAssociation().add(e); + }); } xmlNode = xmlNode.getNextSibling(); } @@ -457,9 +464,15 @@ protected IOSpecification readIOEspecification(Parser parser, Element element) { ioSpec.getDataInputs().addAll(readDataInput(parser, xmlNode)); ioSpec.getDataOutputs().addAll(readDataOutput(parser, xmlNode)); } else if ("dataInputAssociation".equals(nodeName)) { - readDataAssociation((Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> ioSpec.getDataInputAssociation().add(e)); + readDataAssociation((Element) xmlNode, id -> getVariableDataSpec(parser, id), id -> ioSpec.getDataInput().get(id)).ifPresent(e -> { + e.setType(DataAssociationType.INPUT); + ioSpec.getDataInputAssociation().add(e); + }); } else if ("dataOutputAssociation".equals(nodeName)) { - readDataAssociation((Element) xmlNode, id -> ioSpec.getDataOutput().get(id), id -> getVariableDataSpec(parser, id)).ifPresent(e -> ioSpec.getDataOutputAssociation().add(e)); + readDataAssociation((Element) xmlNode, id -> ioSpec.getDataOutput().get(id), id -> getVariableDataSpec(parser, id)).ifPresent(e -> { + e.setType(DataAssociationType.OUTPUT); + ioSpec.getDataOutputAssociation().add(e); + }); } xmlNode = xmlNode.getNextSibling(); } @@ -561,11 +574,11 @@ private Transformation readTransformation(Element parent) { String lang = element.get().getAttribute("language"); String expression = element.get().getTextContent(); - DataTransformer transformer = DataTransformerRegistry.get().find(lang); - if (transformer == null) { - throw new ProcessParsingValidationException("No transformer registered for language " + lang); + ReturnValueEvaluator evaluator = null; + if (lang.toLowerCase().contains("mvel")) { + evaluator = new MVELInterpretedReturnValueEvaluator(expression); } - return new Transformation(lang, expression); + return new Transformation(lang, expression, evaluator); } protected List readSources(org.w3c.dom.Node parent, Function variableResolver) { diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AdHocSubProcessHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AdHocSubProcessHandler.java index 8d11bbc3dc5..89a24f95137 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AdHocSubProcessHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/AdHocSubProcessHandler.java @@ -63,17 +63,26 @@ protected Node handleNode(final Node node, final Element element, final String u if ("false".equals(cancelRemainingInstances)) { dynamicNode.setCancelRemainingInstances(false); } + + dynamicNode.setLanguage("http://www.java.com/java"); + // by default it should not autocomplete as it's adhoc org.w3c.dom.Node xmlNode = element.getFirstChild(); dynamicNode.setActivationCondition((String) node.getMetaData().get(CUSTOM_ACTIVATION_CONDITION)); while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if (COMPLETION_CONDITION.equals(nodeName)) { + Element completeConditionElement = (Element) xmlNode; + String dialect = completeConditionElement.getAttribute("language"); + String expression = xmlNode.getTextContent(); if (AUTOCOMPLETE_EXPRESSIONS.contains(expression)) { dynamicNode.setAutoComplete(true); } else { dynamicNode.setCompletionCondition(expression); + if (!dialect.isBlank()) { + dynamicNode.setLanguage(dialect); + } } } xmlNode = xmlNode.getNextSibling(); @@ -104,7 +113,7 @@ public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) { visitConnectionsAndAssociations(dynamicNode, xmlDump, metaDataType); if (dynamicNode.isAutoComplete()) { - xmlDump.append(" " + AUTOCOMPLETE_COMPLETION_CONDITION + "" + EOL); + xmlDump.append("" + AUTOCOMPLETE_COMPLETION_CONDITION + "" + EOL); } endNode("adHocSubProcess", xmlDump); } diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/BoundaryEventHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/BoundaryEventHandler.java index d3ef36e0dec..1e338e8896b 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/BoundaryEventHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/BoundaryEventHandler.java @@ -141,6 +141,7 @@ protected void handleEscalationNode(final Node node, final Element element, fina while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); if ("escalationEventDefinition".equals(nodeName)) { + String type = null; String escalationRef = ((Element) xmlNode).getAttribute("escalationRef"); if (escalationRef != null && escalationRef.trim().length() > 0) { Map escalations = (Map) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS); @@ -151,16 +152,15 @@ protected void handleEscalationNode(final Node node, final Element element, fina if (escalation == null) { throw new ProcessParsingValidationException("Could not find escalation " + escalationRef); } - List eventFilters = new ArrayList<>(); - EventTypeFilter eventFilter = new EventTypeFilter(); - String type = escalation.getEscalationCode(); - eventFilter.setType("Escalation-" + attachedTo + "-" + type); - eventFilters.add(eventFilter); - eventNode.setEventFilters(eventFilters); - eventNode.setMetaData("EscalationEvent", type); - } else { - throw new UnsupportedOperationException("General escalation is not yet supported."); + type = escalation.getEscalationCode(); } + List eventFilters = new ArrayList<>(); + EventTypeFilter eventFilter = new EventTypeFilter(); + + eventFilter.setType("Escalation-" + attachedTo + (type != null ? "-" + type : "")); + eventFilters.add(eventFilter); + eventNode.setEventFilters(eventFilters); + eventNode.setMetaData("EscalationEvent", type); } xmlNode = xmlNode.getNextSibling(); } diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/EndEventHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/EndEventHandler.java index 2043d99ca5c..db3395a9a7f 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/EndEventHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/EndEventHandler.java @@ -89,6 +89,7 @@ protected Node handleNode(Node newNode, Element element, String uri, String loca handleMessageNode(node, element, uri, localName, parser); } else if ("errorEventDefinition".equals(nodeName)) { FaultNode faultNode = new FaultNode(); + faultNode.setMetaData(node.getMetaData()); faultNode.setId(node.getId()); faultNode.setName(node.getName()); faultNode.setTerminateParent(true); @@ -100,6 +101,7 @@ protected Node handleNode(Node newNode, Element element, String uri, String loca break; } else if ("escalationEventDefinition".equals(nodeName)) { FaultNode faultNode = new FaultNode(); + faultNode.setMetaData(node.getMetaData()); faultNode.setId(node.getId()); faultNode.setName(node.getName()); node = faultNode; @@ -258,6 +260,7 @@ public void handleEscalationNode(final Node node, final Element element, final S throw new ProcessParsingValidationException("Could not find escalation " + escalationRef); } faultNode.setFaultName(escalation.getEscalationCode()); + faultNode.setMetaData("FaultCode", escalation.getEscalationCode()); } else { // BPMN2 spec, p. 83: end event's with // are _required_ to reference a specific escalation(-code). diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/IntermediateThrowEventHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/IntermediateThrowEventHandler.java index 033076b8abb..689215bd423 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/IntermediateThrowEventHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/IntermediateThrowEventHandler.java @@ -49,7 +49,11 @@ import static org.jbpm.bpmn2.xml.ProcessHandler.createJavaAction; import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_COMPENSATION; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_ESCALATION; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_LINK; import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_MESSAGE; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_SIGNAL; import static org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE; import static org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE_INPUT; import static org.jbpm.ruleflow.core.Metadata.MESSAGE_TYPE; @@ -87,21 +91,25 @@ protected Node handleNode(Node newNode, Element element, String uri, String loca // reuse already created ActionNode setThrowVariable(ioSpecification, node); handleSignalNode(node, element, uri, localName, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_SIGNAL); break; } else if ("messageEventDefinition".equals(nodeName)) { // reuse already created ActionNode setThrowVariable(ioSpecification, node); handleMessageNode(node, element, uri, localName, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_MESSAGE); break; } else if ("escalationEventDefinition".equals(nodeName)) { // reuse already created ActionNode setThrowVariable(ioSpecification, node); handleEscalationNode(node, element, uri, localName, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_ESCALATION); break; } else if ("compensateEventDefinition".equals(nodeName)) { // reuse already created ActionNode setThrowVariable(ioSpecification, node); handleThrowCompensationEventNode(node, element, uri, localName, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_COMPENSATION); break; } else if ("linkEventDefinition".equals(nodeName)) { ThrowLinkNode linkNode = new ThrowLinkNode(); @@ -109,6 +117,7 @@ protected Node handleNode(Node newNode, Element element, String uri, String loca node = linkNode; setThrowVariable(ioSpecification, node); handleLinkNode(element, node, xmlNode, parser); + node.setMetaData(EVENT_TYPE, EVENT_TYPE_LINK); } xmlNode = xmlNode.getNextSibling(); } @@ -300,7 +309,7 @@ public void handleEscalationNode(final Node node, final Element element, DroolsConsequenceAction action = createJavaAction(new HandleEscalationAction(faultName, variable)); actionNode.setAction(action); } else { - throw new ProcessParsingValidationException("General escalation is not yet supported"); + throw new ProcessParsingValidationException("Invalid throw escalation. escalation code is required"); } } xmlNode = xmlNode.getNextSibling(); diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/ProcessHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/ProcessHandler.java index e9c8b060e50..210a59d2234 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/ProcessHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/ProcessHandler.java @@ -480,8 +480,9 @@ private static void linkBoundaryEscalationEvent(Node node, String attachedTo, No String variable = ((EventNode) node).getVariableName(); ActionExceptionHandler exceptionHandler = new ActionExceptionHandler(); + String signalName = "Escalation-" + attachedTo + (escalationCode != null ? "-" + escalationCode : ""); DroolsConsequenceAction action = - createJavaAction(new SignalProcessInstanceAction("Escalation-" + attachedTo + "-" + escalationCode, variable, null, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE)); + createJavaAction(new SignalProcessInstanceAction(signalName, variable, null, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE)); exceptionHandler.setAction(action); exceptionHandler.setFaultVariable(variable); exceptionScope.setExceptionHandler(escalationCode, exceptionHandler); @@ -873,8 +874,7 @@ private void postProcessNodes(RuleFlowProcess process, NodeContainer container) String type = ((EventTypeFilter) filter).getType(); if (type.startsWith("Error-") || type.startsWith("Escalation")) { - String faultCode = (String) subNode.getMetaData().get("FaultCode"); - String replaceRegExp = "Error-|Escalation-"; + String faultCode = (String) subNode.getMetaData().get(Metadata.FAULT_CODE); final String signalType = type; ExceptionScope exceptionScope = @@ -894,13 +894,8 @@ private void postProcessNodes(RuleFlowProcess process, NodeContainer container) action.setMetaData("Action", new SignalProcessInstanceAction(signalType, faultVariable, null, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE)); exceptionHandler.setAction(action); exceptionHandler.setFaultVariable(faultVariable); - if (faultCode != null) { - String trimmedType = type.replaceFirst(replaceRegExp, ""); - exceptionScope.setExceptionHandler(trimmedType, exceptionHandler); - eventSubProcessHandlers.add(trimmedType); - } else { - exceptionScope.setExceptionHandler(faultCode, exceptionHandler); - } + eventSubProcessHandlers.add(faultCode); + exceptionScope.setExceptionHandler(faultCode, exceptionHandler); } else if (type.equals("Compensation")) { // 1. Find the parent sub-process to this event sub-process NodeContainer parentSubProcess = null; diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/StartEventHandler.java b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/StartEventHandler.java index b6b276cb92c..4382928954f 100755 --- a/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/StartEventHandler.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/StartEventHandler.java @@ -48,7 +48,15 @@ import org.xml.sax.SAXException; import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_COMPENSATION; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_CONDITIONAL; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_ERROR; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_ESCALATION; import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_MESSAGE; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_NONE; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_SIGNAL; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_TIMER; +import static org.jbpm.ruleflow.core.Metadata.FAULT_CODE; import static org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE; import static org.jbpm.ruleflow.core.Metadata.MESSAGE_REF; import static org.jbpm.ruleflow.core.Metadata.MESSAGE_TYPE; @@ -89,7 +97,7 @@ protected Node handleNode(final Node node, final Element element, final String u findSourceMappingVar(startNode.getIoSpecification().getDataOutputAssociation()).ifPresent(data -> { startNode.getMetaData().put(TRIGGER_MAPPING_INPUT, data.getLabel()); }); - + startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_NONE); org.w3c.dom.Node xmlNode = element.getFirstChild(); while (xmlNode != null) { String nodeName = xmlNode.getNodeName(); @@ -106,6 +114,7 @@ protected Node handleNode(final Node node, final Element element, final String u } ConstraintTrigger trigger = new ConstraintTrigger(); trigger.setConstraint(constraint); + startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_CONDITIONAL); startNode.addTrigger(trigger); break; } else if ("signalEventDefinition".equals(nodeName)) { @@ -116,6 +125,7 @@ protected Node handleNode(final Node node, final Element element, final String u if (type != null && type.trim().length() > 0) { addTriggerWithInMappings(startNode, type); } + startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_SIGNAL); startNode.setMetaData(MESSAGE_TYPE, type); startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.Signal.name()); Signal signal = findSignalByName(parser, type); @@ -143,6 +153,7 @@ protected Node handleNode(final Node node, final Element element, final String u addTriggerWithInMappings(startNode, "Message-" + message.getName(), message.getId(), ((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager()); } else if ("timerEventDefinition".equals(nodeName)) { + startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_TIMER); handleTimerNode(startNode, element, uri, localName, parser); // following event definitions are only for event sub process and will be validated to not be included in top process definitions } else if ("errorEventDefinition".equals(nodeName)) { @@ -150,7 +161,7 @@ protected Node handleNode(final Node node, final Element element, final String u // - a in an Event Sub-Process // - *without* the 'isInterupting' attribute always interrupts (containing process) startNode.setInterrupting(true); - + startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_ERROR); String errorRef = ((Element) xmlNode).getAttribute("errorRef"); if (errorRef != null && errorRef.trim().length() > 0) { List errors = (List) ((ProcessBuildData) parser.getData()).getMetaData("Errors"); @@ -166,7 +177,7 @@ protected Node handleNode(final Node node, final Element element, final String u if (error == null) { throw new ProcessParsingValidationException("Could not find error " + errorRef); } - startNode.setMetaData("FaultCode", error.getErrorCode()); + startNode.setMetaData(FAULT_CODE, error.getErrorCode()); startNode.setMetaData(MESSAGE_TYPE, error.getErrorCode()); startNode.setMetaData(TRIGGER_REF, error.getErrorCode()); startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.Signal.name()); @@ -174,6 +185,7 @@ protected Node handleNode(final Node node, final Element element, final String u addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode()); } } else if ("escalationEventDefinition".equals(nodeName)) { + startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_ESCALATION); String escalationRef = ((Element) xmlNode).getAttribute("escalationRef"); if (escalationRef != null && escalationRef.trim().length() > 0) { Map escalations = (Map) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS); @@ -184,10 +196,15 @@ protected Node handleNode(final Node node, final Element element, final String u if (escalation == null) { throw new ProcessParsingValidationException("Could not find escalation " + escalationRef); } - + startNode.setMetaData(FAULT_CODE, escalation.getEscalationCode()); + startNode.setMetaData(TRIGGER_REF, "Escalation-" + escalation.getEscalationCode()); addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode()); + } else { + startNode.setMetaData(TRIGGER_REF, "Escalation-"); + addTriggerWithInMappings(startNode, "Escalation-"); } } else if ("compensateEventDefinition".equals(nodeName)) { + startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_COMPENSATION); handleCompensationNode(startNode, xmlNode); } xmlNode = xmlNode.getNextSibling(); diff --git a/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnProcesses.java b/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnProcesses.java index 931a0ee8861..ab043f7d3b8 100644 --- a/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnProcesses.java +++ b/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnProcesses.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.kie.kogito.Model; import org.kie.kogito.process.Process; @@ -44,4 +45,22 @@ public Process processById(String processId) { public Collection processIds() { return mappedProcesses.keySet(); } + + @Override + public int hashCode() { + return Objects.hash(mappedProcesses.keySet()); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BpmnProcesses other = (BpmnProcesses) obj; + return Objects.equals(mappedProcesses, other.mappedProcesses); + } + } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java index 27595fe2e74..1b21e056e78 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractNodeVisitor.java @@ -24,21 +24,28 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import org.jbpm.compiler.canonical.builtin.ReturnValueEvaluatorBuilderService; import org.jbpm.process.builder.action.ActionCompilerRegistry; -import org.jbpm.process.builder.transformation.DataTransformerCompilerRegistry; +import org.jbpm.process.core.Context; import org.jbpm.process.core.ContextContainer; +import org.jbpm.process.core.ContextResolver; import org.jbpm.process.core.context.variable.Mappable; import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; +import org.jbpm.process.core.datatype.DataTypeResolver; +import org.jbpm.process.instance.impl.actions.HandleEscalationAction; import org.jbpm.process.instance.impl.actions.ProduceEventAction; import org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction; import org.jbpm.ruleflow.core.Metadata; import org.jbpm.ruleflow.core.factory.MappableNodeFactory; +import org.jbpm.util.JbpmClassLoaderUtil; import org.jbpm.workflow.core.impl.ConnectionImpl; import org.jbpm.workflow.core.impl.DataAssociation; +import org.jbpm.workflow.core.impl.DataAssociation.DataAssociationType; import org.jbpm.workflow.core.impl.DataDefinition; import org.jbpm.workflow.core.impl.DroolsConsequenceAction; import org.jbpm.workflow.core.impl.ExtendedNodeImpl; +import org.jbpm.workflow.core.impl.NodeImpl; import org.jbpm.workflow.core.node.Assignment; import org.jbpm.workflow.core.node.HumanTaskNode; import org.jbpm.workflow.core.node.StartNode; @@ -46,6 +53,7 @@ import org.kie.api.definition.process.Connection; import org.kie.api.definition.process.Node; +import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.expr.AssignExpr; @@ -215,24 +223,25 @@ protected Statement makeAssignmentFromModel(Variable v, String name) { protected void addNodeMappings(Mappable node, BlockStmt body, String variableName) { for (DataAssociation entry : node.getInAssociations()) { - body.addStatement(getFactoryMethod(variableName, MappableNodeFactory.METHOD_IN_ASSOCIATION, buildDataAssociationExpression(entry))); + body.addStatement(getFactoryMethod(variableName, MappableNodeFactory.METHOD_IN_ASSOCIATION, buildDataAssociationExpression((NodeImpl) node, entry))); } for (DataAssociation entry : node.getOutAssociations()) { - body.addStatement(getFactoryMethod(variableName, MappableNodeFactory.METHOD_OUT_ASSOCIATION, buildDataAssociationExpression(entry))); + body.addStatement(getFactoryMethod(variableName, MappableNodeFactory.METHOD_OUT_ASSOCIATION, buildDataAssociationExpression((NodeImpl) node, entry))); } } - protected Expression buildDataAssociationsExpression(List dataAssociations) { - NodeList expressions = NodeList.nodeList(dataAssociations.stream().map(this::buildDataAssociationExpression).collect(Collectors.toList())); + protected Expression buildDataAssociationsExpression(NodeImpl node, List dataAssociations) { + NodeList expressions = NodeList.nodeList(dataAssociations.stream().map(da -> buildDataAssociationExpression(node, da)).collect(Collectors.toList())); return new MethodCallExpr(null, "java.util.Arrays.asList", NodeList.nodeList(expressions)); } - protected Expression buildDataAssociationExpression(DataAssociation dataAssociation) { + protected Expression buildDataAssociationExpression(NodeImpl node, DataAssociation dataAssociation) { List sourceExpr = dataAssociation.getSources(); DataDefinition targetExpr = dataAssociation.getTarget(); Transformation transformation = dataAssociation.getTransformation(); List assignments = dataAssociation.getAssignments(); - return toDataAssociation(toDataDef(sourceExpr), toDataDef(targetExpr), toAssignmentExpr(assignments), toTransformation(sourceExpr, singletonList(targetExpr), transformation)); + return toDataAssociation(toDataDef(sourceExpr), toDataDef(targetExpr), toAssignmentExpr(assignments), + toTransformation(node, dataAssociation.getType(), sourceExpr, singletonList(targetExpr), transformation)); } private Expression toAssignmentExpr(List assignments) { @@ -252,18 +261,46 @@ private Expression toAssignmentExpr(List assignments) { return new MethodCallExpr(null, "java.util.Arrays.asList", NodeList.nodeList(expressions)); } - protected Expression toTransformation(List inputs, List outputs, Transformation transformation) { + protected Expression toTransformation(NodeImpl node, DataAssociationType type, List inputs, List outputs, Transformation transformation) { if (transformation == null) { return new NullLiteralExpr(); } + Expression lang = new StringLiteralExpr(transformation.getLanguage()); - Expression expression = new StringLiteralExpr(transformation.getExpression()); - Expression compiledExpression = DataTransformerCompilerRegistry.instance().find(transformation.getLanguage()).compile(inputs, outputs, transformation); - ClassOrInterfaceType clazz = new ClassOrInterfaceType(null, "org.jbpm.workflow.core.node.Transformation"); - return new ObjectCreationExpr(null, clazz, NodeList.nodeList(lang, expression, compiledExpression)); + Expression expression = new StringLiteralExpr(sanitizeString(transformation.getExpression())); + + ContextResolver contextResolver = type.equals(DataAssociationType.INPUT) ? node : wrapContextResolver(node, inputs); + + ReturnValueEvaluatorBuilderService service = ReturnValueEvaluatorBuilderService.instance(); + Expression returnValueEvaluatorExpression = service.build(contextResolver, transformation.getLanguage(), transformation.getExpression(), Object.class, null); + ClassOrInterfaceType clazz = StaticJavaParser.parseClassOrInterfaceType(Transformation.class.getName()); + return new ObjectCreationExpr(null, clazz, NodeList.nodeList(lang, expression, returnValueEvaluatorExpression)); } + private ContextResolver wrapContextResolver(NodeImpl node, List variables) { + VariableScope variableScope = new VariableScope(); + + for (DataDefinition variable : variables) { + Variable var = new Variable(); + var.setId(variable.getId()); + var.setName(variable.getLabel()); + var.setType(DataTypeResolver.fromType(variable.getType(), JbpmClassLoaderUtil.findClassLoader())); + variableScope.addVariable(var); + } + return new ContextResolver() { + + @Override + public Context resolveContext(String contextId, Object param) { + if (VariableScope.VARIABLE_SCOPE.equals(contextId)) { + return variableScope.resolveContext(param); + } + return null; + } + + }; + } + protected Expression toDataAssociation(Expression sourceExprs, Expression target, Expression transformation, Expression assignments) { ClassOrInterfaceType clazz = new ClassOrInterfaceType(null, "org.jbpm.workflow.core.impl.DataAssociation"); return new ObjectCreationExpr(null, clazz, NodeList.nodeList(sourceExprs, target, transformation, assignments)); @@ -335,7 +372,7 @@ protected static LambdaExpr createLambdaExpr(String consequence, VariableScope s conditionBody); } - public static ObjectCreationExpr buildAction(String signalName, String variable, String inputVariable, String scope) { + public static ObjectCreationExpr buildSignalAction(String signalName, String variable, String inputVariable, String scope) { return new ObjectCreationExpr(null, parseClassOrInterfaceType(SignalProcessInstanceAction.class.getCanonicalName()), new NodeList<>(new StringLiteralExpr(signalName), variable != null ? new StringLiteralExpr(variable.replace("\"", "\\\"")) @@ -347,6 +384,15 @@ public static ObjectCreationExpr buildAction(String signalName, String variable, parseClassOrInterfaceType(String.class.getCanonicalName()), new NullLiteralExpr()))); } + public static ObjectCreationExpr buildEscalationAction(String faultName, String inputVariable) { + return new ObjectCreationExpr(null, + parseClassOrInterfaceType(HandleEscalationAction.class.getCanonicalName()), + new NodeList<>( + faultName != null ? new StringLiteralExpr(faultName) : new NullLiteralExpr(), + inputVariable != null ? new StringLiteralExpr(inputVariable) : new NullLiteralExpr())); + + } + public static LambdaExpr buildCompensationLambdaExpr(String compensationRef) { BlockStmt actionBody = new BlockStmt(); MethodCallExpr getProcessInstance = new MethodCallExpr(new NameExpr(KCONTEXT_VAR), "getProcessInstance"); @@ -360,7 +406,7 @@ public static LambdaExpr buildCompensationLambdaExpr(String compensationRef) { } protected ObjectCreationExpr buildProducerAction(Node node, ProcessMetaData metadata) { - TriggerMetaData trigger = TriggerMetaData.of(node); + TriggerMetaData trigger = TriggerMetaData.of(node, (String) node.getMetaData().get(Metadata.MAPPING_VARIABLE_INPUT)); return buildProducerAction(parseClassOrInterfaceType(ProduceEventAction.class.getCanonicalName()).setTypeArguments(NodeList.nodeList(parseClassOrInterfaceType(trigger.getDataType()))), trigger, metadata); @@ -369,8 +415,10 @@ protected ObjectCreationExpr buildProducerAction(Node node, ProcessMetaData meta public static ObjectCreationExpr buildProducerAction(ClassOrInterfaceType actionClass, TriggerMetaData trigger, ProcessMetaData metadata) { metadata.addTrigger(trigger); return new ObjectCreationExpr(null, actionClass, NodeList.nodeList( - new StringLiteralExpr(trigger.getName()), new StringLiteralExpr(trigger.getModelRef()), - new LambdaExpr(NodeList.nodeList(), new NameExpr("producer_" + trigger.getOwnerId())))); + new StringLiteralExpr(trigger.getName()), + new StringLiteralExpr(trigger.getModelRef()), + new LambdaExpr(NodeList.nodeList(), + new NameExpr("producer_" + trigger.getOwnerId())))); } protected void visitCompensationScope(ContextContainer process, BlockStmt body) { diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ActionNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ActionNodeVisitor.java index 86ae851d3d9..415f67b873c 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ActionNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ActionNodeVisitor.java @@ -24,6 +24,7 @@ import org.jbpm.process.core.context.exception.CompensationScope; import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; +import org.jbpm.process.instance.impl.actions.HandleEscalationAction; import org.jbpm.process.instance.impl.actions.ProcessInstanceCompensationAction; import org.jbpm.ruleflow.core.Metadata; import org.jbpm.ruleflow.core.factory.ActionNodeFactory; @@ -79,27 +80,34 @@ public void visitNode(String factoryField, ActionNode node, BlockStmt body, Vari } else if (node.getMetaData(TRIGGER_REF) != null) { // if there is trigger defined on end event create TriggerMetaData for it body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildProducerAction(node, metadata))); } else if (node.getMetaData(REF) != null && EVENT_TYPE_SIGNAL.equals(node.getMetaData(EVENT_TYPE))) { - body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildAction((String) node.getMetaData(REF), + body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildSignalAction((String) node.getMetaData(REF), (String) node.getMetaData(VARIABLE), (String) node.getMetaData(MAPPING_VARIABLE_INPUT), (String) node.getMetaData(CUSTOM_SCOPE)))); } else if (node.getAction() instanceof DroolsConsequenceAction) { - BlockStmt actionBody = new BlockStmt(); - String consequence = getActionConsequence(node.getAction()); - if (consequence == null || consequence.trim().isEmpty()) { - LOGGER.warn("Action node {} name {} has no action defined!", node.getId().toExternalFormat(), node.getName()); + DroolsConsequenceAction droolsConsequenceAction = (DroolsConsequenceAction) node.getAction(); + if (droolsConsequenceAction.getMetaData("Action") instanceof HandleEscalationAction) { + HandleEscalationAction action = (HandleEscalationAction) droolsConsequenceAction.getMetaData("Action"); + body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildEscalationAction(action.getFaultName(), action.getVariableName()))); } else { - List variables = variableScope.getVariables(); - variables.stream() - .filter(v -> consequence.contains(v.getName())) - .map(ActionNodeVisitor::makeAssignment) - .forEach(actionBody::addStatement); + BlockStmt actionBody = new BlockStmt(); + String consequence = getActionConsequence(node.getAction()); + if (consequence == null || consequence.trim().isEmpty()) { + LOGGER.warn("Action node {} name {} has no action defined!", node.getId().toExternalFormat(), node.getName()); + } else { + List variables = variableScope.getVariables(); + variables.stream() + .filter(v -> consequence.contains(v.getName())) + .map(ActionNodeVisitor::makeAssignment) + .forEach(actionBody::addStatement); - BlockStmt blockStmt = StaticJavaParser.parseBlock("{" + consequence + "}"); - blockStmt.getStatements().forEach(actionBody::addStatement); + BlockStmt blockStmt = StaticJavaParser.parseBlock("{" + consequence + "}"); + blockStmt.getStatements().forEach(actionBody::addStatement); + } + LambdaExpr lambda = new LambdaExpr( + new Parameter(new UnknownType(), KCONTEXT_VAR), // (kcontext) -> + actionBody); + body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda)); } - LambdaExpr lambda = new LambdaExpr( - new Parameter(new UnknownType(), KCONTEXT_VAR), // (kcontext) -> - actionBody); - body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda)); + } addNodeMappings(node, body, getNodeId(node)); body.addStatement(getDoneMethod(getNodeId(node))); diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/DynamicNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/DynamicNodeVisitor.java index 6535aa5466f..f2bd31f7b19 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/DynamicNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/DynamicNodeVisitor.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.stream.Stream; +import org.jbpm.compiler.canonical.builtin.ReturnValueEvaluatorBuilderService; import org.jbpm.compiler.canonical.node.NodeVisitorBuilderService; import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.ruleflow.core.factory.DynamicNodeFactory; @@ -35,8 +36,11 @@ public class DynamicNodeVisitor extends CompositeContextNodeVisitor { - public DynamicNodeVisitor(NodeVisitorBuilderService nodeVisitorService) { + private ReturnValueEvaluatorBuilderService builder; + + public DynamicNodeVisitor(NodeVisitorBuilderService nodeVisitorService, ClassLoader classLoader) { super(nodeVisitorService); + this.builder = ReturnValueEvaluatorBuilderService.instance(classLoader); } @Override @@ -56,22 +60,23 @@ protected String getDefaultName() { @Override public Stream visitCustomFields(DynamicNode node, VariableScope variableScope) { + Collection methods = new ArrayList<>(); methods.add(getFactoryMethod(getNodeId(node), METHOD_LANGUAGE, getOrNullExpr(node.getLanguage()))); - if (node.getActivationCondition() != null && !node.getActivationCondition().trim().isEmpty()) { - methods.add(getActivationConditionStatement(node, variableScope)); + if (node.getActivationCondition() != null && !node.getActivationCondition().isBlank()) { + methods.add(getActivationConditionStatement(node)); } - if (node.getCompletionCondition() != null && !node.getCompletionCondition().trim().isEmpty()) { - methods.add(getCompletionConditionStatement(node, variableScope)); + if (!node.isAutoComplete() && node.getCompletionCondition() != null && !node.getCompletionCondition().isBlank()) { + methods.add(getCompletionConditionStatement(node)); } return methods.stream(); } - private MethodCallExpr getActivationConditionStatement(DynamicNode node, VariableScope scope) { - return getFactoryMethod(getNodeId(node), METHOD_ACTIVATION_EXPRESSION, createLambdaExpr(node.getActivationCondition(), scope)); + private MethodCallExpr getActivationConditionStatement(DynamicNode node) { + return getFactoryMethod(getNodeId(node), METHOD_ACTIVATION_EXPRESSION, builder.build(node, node.getLanguage(), node.getActivationCondition(), Boolean.class, (String) null)); } - private MethodCallExpr getCompletionConditionStatement(DynamicNode node, VariableScope scope) { - return getFactoryMethod(getNodeId(node), METHOD_COMPLETION_EXPRESSION, createLambdaExpr(node.getCompletionCondition(), scope)); + private MethodCallExpr getCompletionConditionStatement(DynamicNode node) { + return getFactoryMethod(getNodeId(node), METHOD_COMPLETION_EXPRESSION, builder.build(node, node.getLanguage(), node.getCompletionCondition(), Boolean.class, (String) null)); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/EndNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/EndNodeVisitor.java index a875f862ef9..23f4edffed2 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/EndNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/EndNodeVisitor.java @@ -75,7 +75,7 @@ public void visitNode(String factoryField, EndNode node, BlockStmt body, Variabl } else if (node.getMetaData(TRIGGER_REF) != null) { body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildProducerAction(node, metadata))); } else if (node.getMetaData(REF) != null && EVENT_TYPE_SIGNAL.equals(node.getMetaData(EVENT_TYPE))) { - body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildAction((String) node.getMetaData(REF), + body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildSignalAction((String) node.getMetaData(REF), (String) node.getMetaData(VARIABLE), (String) node.getMetaData(MAPPING_VARIABLE_INPUT), (String) node.getMetaData(CUSTOM_SCOPE)))); } addNodeMappings(node, body, getNodeId(node)); diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java index 30316ea7293..39605eafc5e 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ProcessVisitor.java @@ -304,14 +304,13 @@ private void visitContextExceptionScope(Context context, BlockStmt body) { String faultCode = e.getKey(); ActionExceptionHandler handler = (ActionExceptionHandler) e.getValue(); Optional faultVariable = Optional.ofNullable(handler.getFaultVariable()); - SignalProcessInstanceAction action = - (SignalProcessInstanceAction) handler.getAction().getMetaData("Action"); + SignalProcessInstanceAction action = (SignalProcessInstanceAction) handler.getAction().getMetaData("Action"); String signalName = action.getSignalName(); body.addStatement(getFactoryMethod(getFieldName(context.getContextContainer()), METHOD_ERROR_EXCEPTION_HANDLER, new StringLiteralExpr(signalName), - new StringLiteralExpr(faultCode), - faultVariable. map(StringLiteralExpr::new) - .orElse(new NullLiteralExpr()))); + faultCode != null ? new StringLiteralExpr(faultCode) : new NullLiteralExpr(), + faultVariable. map(StringLiteralExpr::new).orElse(new NullLiteralExpr()))); + }); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/StartNodeVisitor.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/StartNodeVisitor.java index de5c641a6fe..5bb88d149c8 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/StartNodeVisitor.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/StartNodeVisitor.java @@ -19,10 +19,12 @@ package org.jbpm.compiler.canonical; import java.util.Map; +import java.util.Optional; import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.core.timer.Timer; +import org.jbpm.ruleflow.core.Metadata; import org.jbpm.ruleflow.core.factory.StartNodeFactory; import org.jbpm.workflow.core.node.StartNode; @@ -31,11 +33,10 @@ import com.github.javaparser.ast.expr.StringLiteralExpr; import com.github.javaparser.ast.stmt.BlockStmt; -import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_SIGNAL; +import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE; import static org.jbpm.ruleflow.core.Metadata.MESSAGE_TYPE; import static org.jbpm.ruleflow.core.Metadata.TRIGGER_MAPPING; import static org.jbpm.ruleflow.core.Metadata.TRIGGER_REF; -import static org.jbpm.ruleflow.core.Metadata.TRIGGER_TYPE; import static org.jbpm.ruleflow.core.factory.StartNodeFactory.METHOD_INTERRUPTING; import static org.jbpm.ruleflow.core.factory.StartNodeFactory.METHOD_TIMER; import static org.jbpm.ruleflow.core.factory.StartNodeFactory.METHOD_TRIGGER; @@ -48,65 +49,78 @@ protected String getNodeKey() { } @Override - public void visitNode(String factoryField, StartNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) { - body.addStatement(getAssignedFactoryMethod(factoryField, StartNodeFactory.class, getNodeId(node), getNodeKey(), getWorkflowElementConstructor(node.getId()))) - .addStatement(getNameMethod(node, "Start")) - .addStatement(getFactoryMethod(getNodeId(node), METHOD_INTERRUPTING, new BooleanLiteralExpr(node.isInterrupting()))); - - addNodeMappings(node, body, getNodeId(node)); - visitMetaData(node.getMetaData(), body, getNodeId(node)); - body.addStatement(getDoneMethod(getNodeId(node))); - if (node.getTimer() != null) { - Timer timer = node.getTimer(); - body.addStatement(getFactoryMethod(getNodeId(node), METHOD_TIMER, getOrNullExpr(timer.getDelay()), - getOrNullExpr(timer.getPeriod()), - getOrNullExpr(timer.getDate()), - new IntegerLiteralExpr(node.getTimer().getTimeType()))); - - } else if (node.getTriggers() != null && !node.getTriggers().isEmpty()) { - TriggerMetaData triggerMetaData = buildTriggerMetadata(node); - metadata.addTrigger(triggerMetaData); - handleSignal(node, node.getMetaData(), body, variableScope, metadata); - } else { - // since there is start node without trigger then make sure it is startable - metadata.setStartable(true); + public void visitNode(String factoryField, StartNode startNode, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) { + body.addStatement(getAssignedFactoryMethod(factoryField, StartNodeFactory.class, getNodeId(startNode), getNodeKey(), getWorkflowElementConstructor(startNode.getId()))) + .addStatement(getNameMethod(startNode, "Start")) + .addStatement(getFactoryMethod(getNodeId(startNode), METHOD_INTERRUPTING, new BooleanLiteralExpr(startNode.isInterrupting()))); + visitMetaData(startNode.getMetaData(), body, getNodeId(startNode)); + addNodeMappings(startNode, body, getNodeId(startNode)); + Map nodeMetaData = startNode.getMetaData(); + String eventType = (String) startNode.getMetaData(EVENT_TYPE); + switch (eventType) { + case Metadata.EVENT_TYPE_TIMER: { + Timer timer = startNode.getTimer(); + body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TIMER, getOrNullExpr(timer.getDelay()), + getOrNullExpr(timer.getPeriod()), + getOrNullExpr(timer.getDate()), + new IntegerLiteralExpr(startNode.getTimer().getTimeType()))); + break; + } + case Metadata.EVENT_TYPE_SIGNAL: + case Metadata.EVENT_TYPE_MESSAGE: { + TriggerMetaData triggerMetaData = buildTriggerMetadata(startNode); + metadata.addTrigger(triggerMetaData); + handleIO(startNode, startNode.getMetaData(), body, variableScope, metadata); + metadata.addSignal((String) nodeMetaData.get(TRIGGER_REF), computePayloadType(startNode, variableScope).orElse(null)); + break; + } + case Metadata.EVENT_TYPE_ERROR: + case Metadata.EVENT_TYPE_ESCALATION: + case Metadata.EVENT_TYPE_COMPENSATION: + case Metadata.EVENT_TYPE_CONDITIONAL: + handleIO(startNode, startNode.getMetaData(), body, variableScope, metadata); + metadata.addSignal((String) nodeMetaData.get(TRIGGER_REF), null); + break; + default: + // since there is start node without trigger then make sure it is startable + metadata.setStartable(true); + break; } + body.addStatement(getDoneMethod(getNodeId(startNode))); } private TriggerMetaData buildTriggerMetadata(StartNode node) { return TriggerMetaData.of(node, (String) node.getMetaData(TRIGGER_MAPPING)); } - protected void handleSignal(StartNode startNode, Map nodeMetaData, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) { - if (EVENT_TYPE_SIGNAL.equalsIgnoreCase((String) startNode.getMetaData(TRIGGER_TYPE))) { - Variable variable = null; - if (!startNode.getIoSpecification().getDataOutputAssociation().isEmpty()) { + protected void handleIO(StartNode startNode, Map nodeMetaData, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) { + if (nodeMetaData.containsKey(MESSAGE_TYPE)) { + body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TRIGGER, + new StringLiteralExpr((String) nodeMetaData.get(TRIGGER_REF)), + buildDataAssociationsExpression(startNode, startNode.getIoSpecification().getDataOutputAssociation()))); + } else if (nodeMetaData.containsKey(TRIGGER_REF)) { + body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TRIGGER, + new StringLiteralExpr((String) nodeMetaData.get(TRIGGER_REF)), + buildDataAssociationsExpression(startNode, startNode.getIoSpecification().getDataOutputAssociation()))); + } + } - body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TRIGGER, - new StringLiteralExpr((String) nodeMetaData.get(TRIGGER_REF)), - buildDataAssociationsExpression(startNode.getIoSpecification().getDataOutputAssociation()))); + public Optional computePayloadType(StartNode startNode, VariableScope variableScope) { - String triggerMapping = (String) nodeMetaData.get(TRIGGER_MAPPING); - variable = variableScope.findVariable(triggerMapping); + String triggerMapping = (String) startNode.getMetaData(TRIGGER_MAPPING); + if (triggerMapping == null) { + return Optional.empty(); + } - if (variable == null) { - // check parent node container - VariableScope vscope = (VariableScope) startNode.resolveContext(VariableScope.VARIABLE_SCOPE, triggerMapping); - variable = vscope.findVariable(triggerMapping); - } + Variable variable = null; + variable = variableScope.findVariable(triggerMapping); - metadata.addSignal((String) nodeMetaData.get(MESSAGE_TYPE), variable != null ? variable.getType().getStringType() : null); - } else { - body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TRIGGER, - new StringLiteralExpr((String) nodeMetaData.get(MESSAGE_TYPE)), - buildDataAssociationsExpression(startNode.getIoSpecification().getDataOutputAssociation()))); - } - metadata.addSignal((String) nodeMetaData.get(MESSAGE_TYPE), variable != null ? variable.getType().getStringType() : null); - } else { - body.addStatement(getFactoryMethod(getNodeId(startNode), METHOD_TRIGGER, - new StringLiteralExpr((String) nodeMetaData.get(TRIGGER_REF)), - buildDataAssociationsExpression(startNode.getIoSpecification().getDataOutputAssociation()))); + if (variable == null) { + // check parent node container + VariableScope vscope = (VariableScope) startNode.resolveContext(VariableScope.VARIABLE_SCOPE, triggerMapping); + variable = vscope.findVariable(triggerMapping); } + return Optional.ofNullable(variable != null ? variable.getType().getStringType() : null); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java index d85f3fe76ba..ae82b5fb7ec 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/builtin/JavaConstraintEvaluatorBuilder.java @@ -26,12 +26,14 @@ import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; +import com.github.javaparser.ParseProblemException; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.LambdaExpr; import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.stmt.BlockStmt; +import com.github.javaparser.ast.stmt.ReturnStmt; import com.github.javaparser.ast.type.UnknownType; public class JavaConstraintEvaluatorBuilder implements ReturnValueEvaluatorBuilder { @@ -48,7 +50,19 @@ public Expression build(ContextResolver resolver, String expression, Class ty new Parameter(new UnknownType(), KCONTEXT_VAR), // (kcontext) -> actionBody); - BlockStmt blockStmt = StaticJavaParser.parseBlock("{" + expression + "}"); + BlockStmt blockStmt = parseIdentifier(expression); + + if (blockStmt == null) { + blockStmt = parseExpression(expression); + } + + if (blockStmt == null) { + blockStmt = parseStatement(expression); + } + + if (blockStmt == null) { + blockStmt = StaticJavaParser.parseBlock("{" + expression + "}"); + } Set identifiers = new HashSet<>(blockStmt.findAll(NameExpr.class)); for (NameExpr v : identifiers) { @@ -57,7 +71,7 @@ public Expression build(ContextResolver resolver, String expression, Class ty continue; } Variable variable = variableScope.findVariable(v.getNameAsString()); - actionBody.addStatement(AbstractNodeVisitor.makeAssignment(variable)); + actionBody.addStatement(0, AbstractNodeVisitor.makeAssignment(variable)); } blockStmt.getStatements().forEach(actionBody::addStatement); @@ -65,4 +79,33 @@ public Expression build(ContextResolver resolver, String expression, Class ty return lambda; } + private BlockStmt parseStatement(String expression) { + try { + BlockStmt block = new BlockStmt(); + block.addStatement(StaticJavaParser.parseStatement(expression)); + return block; + } catch (ParseProblemException e) { + return null; + } + } + + private BlockStmt parseExpression(String expression) { + try { + BlockStmt block = new BlockStmt(); + block.addStatement(new ReturnStmt(StaticJavaParser.parseExpression(expression))); + return block; + } catch (ParseProblemException e) { + return null; + } + } + + private BlockStmt parseIdentifier(String expression) { + try { + BlockStmt block = new BlockStmt(); + block.addStatement(new ReturnStmt(new NameExpr(StaticJavaParser.parseSimpleName(expression.trim())))); + return block; + } catch (ParseProblemException e) { + return null; + } + } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/node/DynamicNodeVisitorBuilder.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/node/DynamicNodeVisitorBuilder.java index f463651f74a..fdf5f54821c 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/node/DynamicNodeVisitorBuilder.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/node/DynamicNodeVisitorBuilder.java @@ -32,7 +32,7 @@ public Class type() { @Override public AbstractNodeVisitor visitor(NodeVisitorBuilderService nodeVisitorService, ClassLoader classLoader) { - return new DynamicNodeVisitor(nodeVisitorService); + return new DynamicNodeVisitor(nodeVisitorService, classLoader); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/EventNodeBuilder.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/EventNodeBuilder.java index 57ba54137ed..b5f0aaba9a9 100755 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/EventNodeBuilder.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/EventNodeBuilder.java @@ -22,12 +22,10 @@ import java.util.Map; import org.drools.drl.ast.descr.ProcessDescr; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.workflow.core.WorkflowProcess; import org.jbpm.workflow.core.node.Transformation; import org.kie.api.definition.process.Node; import org.kie.api.definition.process.Process; -import org.kie.api.runtime.process.DataTransformer; public class EventNodeBuilder implements ProcessNodeBuilder { @@ -40,8 +38,6 @@ public void build(Process process, ProcessDescr processDescr, ProcessBuildContex parameters.put("imports", wfProcess.getImports()); parameters.put("classloader", context.getConfiguration().getClassLoader()); - DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage()); - transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters)); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/ExtendedNodeBuilder.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/ExtendedNodeBuilder.java index 64238c7abae..9f86aaea125 100755 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/ExtendedNodeBuilder.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/ExtendedNodeBuilder.java @@ -27,17 +27,14 @@ import org.drools.drl.ast.descr.ProcessDescr; import org.jbpm.process.builder.dialect.ProcessDialect; import org.jbpm.process.builder.dialect.ProcessDialectRegistry; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.workflow.core.DroolsAction; import org.jbpm.workflow.core.impl.DataAssociation; import org.jbpm.workflow.core.impl.DroolsConsequenceAction; import org.jbpm.workflow.core.impl.ExtendedNodeImpl; import org.jbpm.workflow.core.impl.NodeImpl; import org.jbpm.workflow.core.node.Assignment; -import org.jbpm.workflow.core.node.Transformation; import org.kie.api.definition.process.Node; import org.kie.api.definition.process.Process; -import org.kie.api.runtime.process.DataTransformer; public class ExtendedNodeBuilder implements @@ -71,13 +68,6 @@ protected void buildAction(DroolsAction droolsAction, ProcessBuildContext contex protected void buildDataAssociation(PackageBuildContext context, Collection dataAssociations, Map parameters) { for (DataAssociation dataAssociation : dataAssociations) { - Transformation transformation = dataAssociation.getTransformation(); - if (transformation != null) { - - DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage()); - transformation.setCompiledExpression(transformer.compile(transformation.getExpression(), parameters)); - - } List assignments = dataAssociation.getAssignments(); if (assignments != null) { for (Assignment assignment : assignments) { diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompilerRegistry.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompilerRegistry.java deleted file mode 100755 index 54f506da76e..00000000000 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompilerRegistry.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.process.builder.transformation; - -import java.util.ArrayList; -import java.util.List; -import java.util.ServiceLoader; - -import org.jbpm.util.JbpmClassLoaderUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Registry for all available on runtime DataTransformers for performing - * data input and output transformation. - * There is MVEL based transformer available out of the box that is registered under - * http://www.mvel.org/2.0 key. - *
- * Custom implementations can be provided and if they are compliant with JSR 223 then follows above registration approach - * otherwise they need to be registered manually with register method. - * - */ -public class DataTransformerCompilerRegistry { - - private static final Logger logger = LoggerFactory.getLogger(DataTransformerCompilerRegistry.class); - - private static DataTransformerCompilerRegistry INSTANCE; - - private List registry; - - public static DataTransformerCompilerRegistry instance() { - if (INSTANCE == null) { - INSTANCE = new DataTransformerCompilerRegistry(); - } - return INSTANCE; - } - - protected DataTransformerCompilerRegistry() { - this.registry = new ArrayList<>(); - ServiceLoader.load(DataTransformerCompiler.class, JbpmClassLoaderUtil.findClassLoader()).forEach(registry::add); - } - - public void register(DataTransformerCompiler transformer) { - this.registry.add(transformer); - logger.debug("Manual registration of scripting language {} with instance {}", transformer.dialects(), transformer); - } - - public DataTransformerCompiler find(String language) { - for (DataTransformerCompiler transformer : registry) { - if (transformer.accept(language)) { - return transformer; - } - } - throw new IllegalArgumentException("transformer not support for dialect " + language); - } -} diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DefaultDataTransformerCompiler.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DefaultDataTransformerCompiler.java deleted file mode 100644 index 377076b3466..00000000000 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DefaultDataTransformerCompiler.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.process.builder.transformation; - -import java.util.Collections; -import java.util.List; - -import org.jbpm.process.core.impl.DataTransformerRegistry; -import org.jbpm.workflow.core.impl.DataDefinition; -import org.jbpm.workflow.core.node.Transformation; -import org.kie.kogito.internal.utils.ConversionUtils; - -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.FieldAccessExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; - -public class DefaultDataTransformerCompiler implements DataTransformerCompiler { - - @Override - public String[] dialects() { - return new String[] { "http://www.mvel.org/2.0" }; - } - - @Override - public Expression compile(List inputs, List outputs, Transformation transformation) { - Expression expr = null; - expr = new FieldAccessExpr(new NameExpr(DataTransformerRegistry.class.getPackageName()), DataTransformerRegistry.class.getSimpleName()); - expr = new MethodCallExpr(expr, "get"); - expr = new MethodCallExpr(expr, "find", NodeList.nodeList(new StringLiteralExpr(transformation.getLanguage()))); - - Expression emptyCollection = new MethodCallExpr(new FieldAccessExpr(new NameExpr(Collections.class.getPackageName()), Collections.class.getSimpleName()), "emptyMap"); - - expr = new MethodCallExpr(expr, "compile", NodeList. nodeList( - new StringLiteralExpr(ConversionUtils.sanitizeString(transformation.getExpression())), emptyCollection)); - return expr; - } - -} diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java deleted file mode 100644 index d2dc13c0521..00000000000 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/JavaDataTransformerCompiler.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.process.builder.transformation; - -import java.util.List; -import java.util.Map; - -import org.jbpm.workflow.core.impl.DataDefinition; -import org.jbpm.workflow.core.node.Transformation; - -import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.NodeList; -import com.github.javaparser.ast.body.Parameter; -import com.github.javaparser.ast.expr.AssignExpr; -import com.github.javaparser.ast.expr.CastExpr; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.expr.LambdaExpr; -import com.github.javaparser.ast.expr.MethodCallExpr; -import com.github.javaparser.ast.expr.NameExpr; -import com.github.javaparser.ast.expr.StringLiteralExpr; -import com.github.javaparser.ast.expr.VariableDeclarationExpr; -import com.github.javaparser.ast.stmt.BlockStmt; -import com.github.javaparser.ast.type.ClassOrInterfaceType; - -public class JavaDataTransformerCompiler implements DataTransformerCompiler { - - @Override - public String[] dialects() { - return new String[] { "http://www.java.com/java" }; - } - - @Override - public Expression compile(List inputs, List outputs, Transformation transformation) { - // build lambda function - BlockStmt body = StaticJavaParser.parseBlock("{" + transformation.getExpression() + "}"); - for (DataDefinition input : inputs) { - ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType(input.getType()); - VariableDeclarationExpr target = new VariableDeclarationExpr(type, input.getLabel()); - Expression source = new CastExpr(type, new MethodCallExpr(new NameExpr("parameters"), "get", NodeList.nodeList(new StringLiteralExpr(input.getLabel())))); - AssignExpr assignment = new AssignExpr(target, source, AssignExpr.Operator.ASSIGN); - body.addStatement(0, assignment); - } - - Expression lambda = new LambdaExpr(NodeList.nodeList(new Parameter(StaticJavaParser.parseClassOrInterfaceType(Map.class.getName()), "parameters")), body, true); - ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType("java.util.function.Function"); - return new CastExpr(type, lambda); - } - -} diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeLeftCountDownProcessEventListener.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeLeftCountDownProcessEventListener.java index f2eb0bae104..92e5fb4a535 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeLeftCountDownProcessEventListener.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeLeftCountDownProcessEventListener.java @@ -20,21 +20,17 @@ import org.kie.api.event.process.ProcessNodeLeftEvent; -public class NodeLeftCountDownProcessEventListener extends NodeCountDownProcessEventListener { +public class NodeLeftCountDownProcessEventListener extends DefaultCountDownProcessEventListener { - private boolean reactOnBeforeNodeLeft = false; + private String nodeName; public NodeLeftCountDownProcessEventListener() { } public NodeLeftCountDownProcessEventListener(String nodeName, int threads) { - super(nodeName, threads); - } - - public NodeLeftCountDownProcessEventListener(String nodeName, int threads, boolean reactOnBeforeNodeLeft) { - super(nodeName, threads); - this.reactOnBeforeNodeLeft = reactOnBeforeNodeLeft; + super(threads); + this.nodeName = nodeName; } @Override @@ -43,11 +39,4 @@ public void afterNodeLeft(ProcessNodeLeftEvent event) { countDown(); } } - - @Override - public void beforeNodeLeft(ProcessNodeLeftEvent event) { - if (reactOnBeforeNodeLeft && nodeName.equals(event.getNodeInstance().getNodeName())) { - countDown(); - } - } } \ No newline at end of file diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeCountDownProcessEventListener.java b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeTriggeredProcessEventListener.java similarity index 69% rename from jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeCountDownProcessEventListener.java rename to jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeTriggeredProcessEventListener.java index 5b9aa106d2b..5de91c0eec1 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeCountDownProcessEventListener.java +++ b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/test/util/NodeTriggeredProcessEventListener.java @@ -18,23 +18,26 @@ */ package org.jbpm.test.util; -import java.util.concurrent.CountDownLatch; +import org.kie.api.event.process.ProcessNodeTriggeredEvent; -public class NodeCountDownProcessEventListener extends DefaultCountDownProcessEventListener { +public class NodeTriggeredProcessEventListener extends DefaultCountDownProcessEventListener { protected String nodeName; - public NodeCountDownProcessEventListener() { + public NodeTriggeredProcessEventListener() { } - public NodeCountDownProcessEventListener(String nodeName, int threads) { - super(threads); - this.nodeName = nodeName; + @Override + public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { + if (nodeName.equals(event.getNodeInstance().getNodeName())) { + countDown(); + } } - public void reset(String nodeName, int threads) { + public NodeTriggeredProcessEventListener(String nodeName, int threads) { + super(threads); this.nodeName = nodeName; - this.latch = new CountDownLatch(threads); } + } \ No newline at end of file diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/impl/DataTransformerRegistry.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/impl/DataTransformerRegistry.java deleted file mode 100755 index 5cd596786e4..00000000000 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/impl/DataTransformerRegistry.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.process.core.impl; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.jbpm.process.core.transformation.JavaDataTransformer; -import org.jbpm.process.core.transformation.MVELDataTransformer; -import org.kie.api.runtime.process.DataTransformer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Registry for all available on runtime DataTransformers for performing - * data input and output transformation. - * There is MVEL based transformer available out of the box that is registered under - * http://www.mvel.org/2.0 key. - *
- * Custom implementations can be provided and if they are compliant with JSR 223 then follows above registration approach - * otherwise they need to be registered manually with register method. - * - */ -public class DataTransformerRegistry { - - private static final Logger logger = LoggerFactory.getLogger(DataTransformerRegistry.class); - private static final DataTransformerRegistry INSTANCE = new DataTransformerRegistry(); - - private Map registry; - - protected DataTransformerRegistry() { - this.registry = new ConcurrentHashMap<>(); - this.registry.put("http://www.mvel.org/2.0", new MVELDataTransformer()); - this.registry.put("http://www.java.com/java", new JavaDataTransformer()); - } - - public static DataTransformerRegistry get() { - return INSTANCE; - } - - public synchronized void register(String language, DataTransformer transformer) { - this.registry.put(language, transformer); - logger.debug("Manual registration of scripting language {} with instance {}", language, transformer); - } - - public DataTransformer find(String language) { - return this.registry.get(language); - } -} diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/JavaDataTransformer.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/JavaDataTransformer.java deleted file mode 100644 index daefaf43cc9..00000000000 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/JavaDataTransformer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.process.core.transformation; - -import java.util.Map; -import java.util.function.Function; - -import org.kie.api.runtime.process.DataTransformer; - -public class JavaDataTransformer implements DataTransformer { - - @Override - public Object compile(String expression, Map parameters) { - return null; - } - - @SuppressWarnings("unchecked") - @Override - public Object transform(Object expression, Map parameters) { - return ((Function, Object>) expression).apply(parameters); - } - -} diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/MVELDataTransformer.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/MVELDataTransformer.java deleted file mode 100755 index b884e9babcf..00000000000 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/transformation/MVELDataTransformer.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.process.core.transformation; - -import java.util.Map; -import java.util.Set; - -import org.jbpm.workflow.instance.impl.MVELProcessHelper; -import org.kie.api.runtime.process.DataTransformer; -import org.mvel2.MVEL; -import org.mvel2.ParserConfiguration; -import org.mvel2.ParserContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * MVEL based DataTransformer implementation - * - */ -public class MVELDataTransformer implements DataTransformer { - - private static final Logger logger = LoggerFactory.getLogger(MVELDataTransformer.class); - - @Override - public Object compile(String expression, Map parameters) { - logger.debug("About to compile mvel expression {}", expression); - ClassLoader classLoader = (ClassLoader) parameters.get("classloader"); - if (classLoader == null) { - classLoader = this.getClass().getClassLoader(); - } - ParserConfiguration config = new ParserConfiguration(); - config.setClassLoader(classLoader); - ParserContext context = new ParserContext(config); - if (parameters != null) { - @SuppressWarnings("unchecked") - Set imports = (Set) parameters.get("imports"); - if (imports != null) { - for (String clazz : imports) { - try { - Class cl = Class.forName(clazz, true, classLoader); - context.addImport(cl.getSimpleName(), cl); - } catch (ClassNotFoundException e) { - logger.warn("Unable to load class {} due to {}", clazz, e.getException()); - } - ; - } - } - } - return MVEL.compileExpression(expression, context); - } - - @Override - public Object transform(Object expression, Map parameters) { - logger.debug("About to execute mvel expression {} with parameters {}", expression, parameters); - return MVELProcessHelper.evaluator().executeExpression(expression, parameters); - } - -} diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/KogitoProcessContextImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/KogitoProcessContextImpl.java index 1b2bba1bda2..5258ea7e2ee 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/KogitoProcessContextImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/KogitoProcessContextImpl.java @@ -50,7 +50,7 @@ public boolean isVariableResolvable(String variableId) { return resolver.resolveContext(VariableScope.VARIABLE_SCOPE, variableId) != null; } - return nodeInstance.getVariable(variableId) != null; + return getVariable(variableId) != null; } @Override diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/MVELInterpretedReturnValueEvaluator.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/MVELInterpretedReturnValueEvaluator.java index 5a969fbb5b0..0ca4c8fbd1f 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/MVELInterpretedReturnValueEvaluator.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/MVELInterpretedReturnValueEvaluator.java @@ -45,12 +45,12 @@ public Object eval(Function resolver) { @Override public boolean isResolveable(String name) { - return resolver.apply("#{" + name + "}") != null; + return resolver.apply(name) != null; }; @Override public VariableResolver getVariableResolver(String name) { - return new SimpleValueResolver(resolver.apply("#{" + name + "}")); + return new SimpleValueResolver(resolver.apply(name)); }; }; return MVEL.eval(expression, factory); diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/XPATHReturnValueEvaluator.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/XPATHReturnValueEvaluator.java index 3c9fa372d66..8abd66e6265 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/XPATHReturnValueEvaluator.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/XPATHReturnValueEvaluator.java @@ -42,7 +42,7 @@ public XPATHReturnValueEvaluator() { super("XPath", "true()"); } - public XPATHReturnValueEvaluator(final String expression) { + public XPATHReturnValueEvaluator(String expression) { super("XPath", expression); } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/HandleEscalationAction.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/HandleEscalationAction.java index dff678aa3f5..ad1e861835d 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/HandleEscalationAction.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/HandleEscalationAction.java @@ -45,6 +45,14 @@ public HandleEscalationAction(String faultName, String variableName) { this.variableName = variableName; } + public String getFaultName() { + return faultName; + } + + public String getVariableName() { + return variableName; + } + @Override public void execute(KogitoProcessContext context) throws Exception { ExceptionScopeInstance scopeInstance = (ExceptionScopeInstance) ((NodeInstance) context.getNodeInstance()).resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, @@ -53,12 +61,13 @@ public void execute(KogitoProcessContext context) throws Exception { Object event = variableName == null ? null : context.getVariable(variableName); NodeInstanceImpl impl = ((NodeInstanceImpl) context.getNodeInstance()); // for event nodes we create a "virtual assignment and we process it" - Map outputSet = Collections.singletonMap(variableName, event); + Map outputSet = variableName != null ? Collections.singletonMap(variableName, event) : Collections.emptyMap(); NodeIoHelper.processOutputs(impl, varRef -> outputSet.get(varRef), target -> impl.getVariable(target)); - context.getContextData().put("Exception", context.getVariable(variableName)); + if (variableName != null) { + context.getContextData().put("Exception", context.getVariable(variableName)); + } scopeInstance.handleException(faultName, context); } else { - ((ProcessInstance) context.getProcessInstance()).setState(STATE_ABORTED); } } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/ProduceEventAction.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/ProduceEventAction.java index 61c38c3c76d..c9f9c3c385e 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/ProduceEventAction.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/actions/ProduceEventAction.java @@ -19,11 +19,14 @@ package org.jbpm.process.instance.impl.actions; import java.io.Serializable; +import java.util.Map; import java.util.function.Supplier; import org.drools.core.common.InternalKnowledgeRuntime; import org.jbpm.process.instance.InternalProcessRuntime; import org.jbpm.process.instance.impl.Action; +import org.jbpm.workflow.core.impl.NodeIoHelper; +import org.jbpm.workflow.instance.impl.NodeInstanceImpl; import org.kie.kogito.event.impl.MessageProducer; import org.kie.kogito.internal.process.runtime.KogitoProcessContext; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; @@ -44,7 +47,8 @@ public ProduceEventAction(String triggerName, String varName, Supplier inputs = NodeIoHelper.processInputs((NodeInstanceImpl) context.getNodeInstance(), var -> context.getVariable(var)); + Object object = inputs.get(varName); KogitoProcessInstance pi = context.getProcessInstance(); InternalKnowledgeRuntime runtime = (InternalKnowledgeRuntime) context.getKieRuntime(); InternalProcessRuntime process = (InternalProcessRuntime) runtime.getProcessRuntime(); diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/Metadata.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/Metadata.java index 5b9f6a14286..bb3e9d71d5b 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/Metadata.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/Metadata.java @@ -36,6 +36,7 @@ public class Metadata { public static final String TRIGGER_MAPPING_INPUT = "TriggerMappingInput"; public static final String MAPPING_VARIABLE = "MappingVariable"; public static final String MAPPING_VARIABLE_INPUT = "MappingVariableInput"; + public static final String FAULT_CODE = "FaultCode"; public static final String EVENT_TYPE = "EventType"; public static final String EVENT_TYPE_TIMER = "Timer"; public static final String EVENT_TYPE_SIGNAL = "signal"; @@ -43,7 +44,9 @@ public class Metadata { public static final String EVENT_TYPE_COMPENSATION = "Compensation"; public static final String EVENT_TYPE_ERROR = "error"; public static final String EVENT_TYPE_CONDITIONAL = "conditional"; + public static final String EVENT_TYPE_NONE = "none"; public static final String EVENT_TYPE_LINK = "link"; + public static final String EVENT_TYPE_ESCALATION = "Escalation"; public static final String CUSTOM_SCOPE = "customScope"; public static final String ATTACHED_TO = "AttachedTo"; public static final String TIME_CYCLE = "TimeCycle"; diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/factory/DynamicNodeFactory.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/factory/DynamicNodeFactory.java index 53acb5bcdcf..c956b051983 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/factory/DynamicNodeFactory.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/factory/DynamicNodeFactory.java @@ -18,13 +18,11 @@ */ package org.jbpm.ruleflow.core.factory; -import java.util.function.Predicate; - +import org.jbpm.process.instance.impl.ReturnValueEvaluator; import org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory; import org.jbpm.workflow.core.NodeContainer; import org.jbpm.workflow.core.node.DynamicNode; import org.kie.api.definition.process.WorkflowElementIdentifier; -import org.kie.api.runtime.process.ProcessContext; public class DynamicNodeFactory> extends AbstractCompositeNodeFactory, T> { @@ -45,12 +43,12 @@ public DynamicNodeFactory language(String language) { return this; } - public DynamicNodeFactory activationExpression(Predicate activationExpression) { + public DynamicNodeFactory activationExpression(ReturnValueEvaluator activationExpression) { getDynamicNode().setActivationExpression(activationExpression); return this; } - public DynamicNodeFactory completionExpression(Predicate completionExpression) { + public DynamicNodeFactory completionExpression(ReturnValueEvaluator completionExpression) { getDynamicNode().setCompletionExpression(completionExpression); return this; } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataAssociation.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataAssociation.java index 2d2dc86fd4c..468115c508b 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataAssociation.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/DataAssociation.java @@ -29,12 +29,18 @@ public class DataAssociation implements Serializable { + public enum DataAssociationType { + INPUT, + OUTPUT + } + private static final long serialVersionUID = 5L; private List sources; private DataDefinition target; private List assignments; private Transformation transformation; + private DataAssociationType type; public DataAssociation(Assignment assignment) { this(Collections.emptyList(), null, Collections.singletonList(assignment), null); @@ -49,6 +55,14 @@ public DataAssociation(List sources, DataDefinition target, this.assignments.forEach(this::buildInterpretedAssignment); } + public DataAssociationType getType() { + return type; + } + + public void setType(DataAssociationType type) { + this.type = type; + } + private Assignment buildInterpretedAssignment(Assignment assignment) { if (assignment.getDialect() != null) { return assignment; diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeIoHelper.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeIoHelper.java index f4d800fc7c4..5eaa8f0d982 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeIoHelper.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/NodeIoHelper.java @@ -25,14 +25,12 @@ import java.util.Map; import java.util.function.Function; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.process.instance.KogitoProcessContextImpl; import org.jbpm.process.instance.impl.AssignmentAction; import org.jbpm.process.instance.impl.AssignmentProducer; import org.jbpm.workflow.core.node.Assignment; import org.jbpm.workflow.core.node.Transformation; import org.jbpm.workflow.instance.impl.NodeInstanceImpl; -import org.kie.api.runtime.process.DataTransformer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,10 +82,9 @@ private void processDataAssociation( try { if (mapping.getTransformation() != null) { Transformation transformation = mapping.getTransformation(); - DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage()); Object parameterValue = null; - if (transformer != null) { - parameterValue = transformer.transform(transformation.getCompiledExpression(), dataSet); + if (transformation != null) { + parameterValue = transformation.getCompiledExpression().eval(var -> dataSet.get(var)); } if (parameterValue != null) { producer.accept(mapping.getTarget().getLabel(), parameterValue); diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/DynamicNode.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/DynamicNode.java index d09348f1e5f..d38584d943d 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/DynamicNode.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/DynamicNode.java @@ -20,12 +20,12 @@ import java.util.Arrays; import java.util.List; -import java.util.function.Predicate; import java.util.stream.Collectors; +import org.jbpm.process.instance.impl.ReturnValueEvaluator; import org.kie.api.definition.process.Node; import org.kie.api.definition.process.WorkflowElementIdentifier; -import org.kie.api.runtime.process.ProcessContext; +import org.kie.kogito.internal.process.runtime.KogitoProcessContext; import static org.jbpm.ruleflow.core.Metadata.CUSTOM_AUTO_START; @@ -42,8 +42,8 @@ public class DynamicNode extends CompositeContextNode { */ private String completionCondition; - private Predicate activationPredicate; - private Predicate completionPredicate; + private ReturnValueEvaluator activationPredicate; + private ReturnValueEvaluator completionPredicate; private String language; public DynamicNode() { @@ -89,22 +89,22 @@ public void setCompletionCondition(String completionCondition) { this.completionCondition = completionCondition; } - public DynamicNode setActivationExpression(Predicate activationPredicate) { + public DynamicNode setActivationExpression(ReturnValueEvaluator activationPredicate) { this.activationPredicate = activationPredicate; return this; } - public DynamicNode setCompletionExpression(Predicate copmletionPredicate) { + public DynamicNode setCompletionExpression(ReturnValueEvaluator copmletionPredicate) { this.completionPredicate = copmletionPredicate; return this; } - public boolean canActivate(ProcessContext context) { - return activationPredicate == null || activationPredicate.test(context); + public boolean canActivate(KogitoProcessContext context) { + return activationPredicate == null || (Boolean) activationPredicate.evaluate(context); } - public boolean canComplete(ProcessContext context) { - return isAutoComplete() || (completionPredicate != null && completionPredicate.test(context)); + public boolean canComplete(KogitoProcessContext context) { + return isAutoComplete() || (completionPredicate != null && (Boolean) completionPredicate.evaluate(context)); } public boolean hasCompletionCondition() { diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/StartNode.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/StartNode.java index f1062e67d60..cfc91ddeec9 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/StartNode.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/StartNode.java @@ -22,6 +22,7 @@ import java.util.List; import org.jbpm.process.core.timer.Timer; +import org.jbpm.ruleflow.core.Metadata; import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.impl.ExtendedNodeImpl; import org.kie.api.definition.process.Connection; @@ -42,6 +43,10 @@ public class StartNode extends ExtendedNodeImpl { private Timer timer; + public StartNode() { + setMetaData(Metadata.EVENT_TYPE, Metadata.EVENT_TYPE_NONE); + } + public void addTrigger(Trigger trigger) { if (triggers == null) { triggers = new ArrayList<>(); diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/Transformation.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/Transformation.java index 97533ec90a0..a5e7491c6c8 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/Transformation.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/node/Transformation.java @@ -20,19 +20,21 @@ import java.io.Serializable; +import org.jbpm.process.instance.impl.ReturnValueEvaluator; + public class Transformation implements Serializable { private static final long serialVersionUID = 1641905060375832661L; private String language; private String expression; - private Object compiledExpression; + private ReturnValueEvaluator compiledExpression; public Transformation(String lang, String expression) { this(lang, expression, null); } - public Transformation(String lang, String expression, Object compiledExpression) { + public Transformation(String lang, String expression, ReturnValueEvaluator compiledExpression) { this.language = lang; this.expression = expression; this.compiledExpression = compiledExpression; @@ -54,11 +56,11 @@ public void setExpression(String expression) { this.expression = expression; } - public Object getCompiledExpression() { + public ReturnValueEvaluator getCompiledExpression() { return compiledExpression; } - public void setCompiledExpression(Object compliedExpression) { + public void setCompiledExpression(ReturnValueEvaluator compliedExpression) { this.compiledExpression = compliedExpression; } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstanceContainer.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstanceContainer.java index 3fb400cc16d..736c4b2d3a4 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstanceContainer.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstanceContainer.java @@ -20,11 +20,13 @@ import java.util.Collection; import java.util.Map; +import java.util.function.Predicate; import org.jbpm.workflow.core.node.AsyncEventNode; import org.kie.api.definition.process.Node; import org.kie.api.definition.process.NodeContainer; import org.kie.api.definition.process.WorkflowElementIdentifier; +import org.kie.kogito.internal.process.runtime.KogitoNode; import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer; @@ -61,12 +63,11 @@ public interface NodeInstanceContainer extends KogitoNodeInstanceContainer { NodeInstance getNodeInstance(String nodeInstanceId, boolean recursive); - default NodeInstance getByNodeDefinitionId(final String nodeDefinitionId, NodeContainer nodeContainer) { + default NodeInstance getNodeByPredicate(NodeContainer nodeContainer, Predicate nodeTest) { for (Node node : nodeContainer.getNodes()) { - - if (nodeDefinitionId.equals(node.getUniqueId())) { + if (nodeTest.test((KogitoNode) node)) { if (nodeContainer instanceof Node) { - Collection nodeInstances = getKogitoNodeInstances(ni -> ni.getNode().getId() == (((Node) nodeContainer).getId()), true); + Collection nodeInstances = getKogitoNodeInstances(ni -> ni.getNode().getId().equals(((Node) nodeContainer).getId()), true); if (nodeInstances.isEmpty()) { return ((NodeInstanceContainer) getNodeInstance((Node) nodeContainer)).getNodeInstance(node); } else { @@ -78,15 +79,21 @@ default NodeInstance getByNodeDefinitionId(final String nodeDefinitionId, NodeCo } if (node instanceof NodeContainer) { - NodeInstance ni = getByNodeDefinitionId(nodeDefinitionId, ((NodeContainer) node)); - + NodeInstance ni = getNodeByPredicate(((NodeContainer) node), nodeTest); if (ni != null) { return ni; } } } + return null; + } - throw new IllegalArgumentException("Node with definition id " + nodeDefinitionId + " was not found"); + default NodeInstance getByNodeDefinitionId(String nodeDefinitionId, NodeContainer nodeContainer) { + NodeInstance nodeInstance = getNodeByPredicate(nodeContainer, ni -> nodeDefinitionId.equals(ni.getUniqueId())); + if (nodeInstance == null) { + throw new IllegalArgumentException("Node with definition id " + nodeDefinitionId + " was not found"); + } + return nodeInstance; } default Node resolveAsync(Node node) { diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java index e23c5b4bc82..f71a5ef44f4 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java @@ -258,6 +258,7 @@ public final void trigger(KogitoNodeInstance from, String type) { protected void captureError(Exception e) { logger.error("capture error", e); + e.printStackTrace(); getProcessInstance().setErrorState(this, e); } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java index 1646335437a..434aca19b33 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java @@ -41,6 +41,7 @@ import org.drools.core.common.InternalKnowledgeRuntime; import org.drools.mvel.util.MVELEvaluator; import org.jbpm.process.core.ContextContainer; +import org.jbpm.process.core.ContextResolver; import org.jbpm.process.core.context.variable.Variable; import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.core.timer.BusinessCalendar; @@ -539,7 +540,7 @@ public void configureTimers() { public TimerInstance configureSLATimer(String slaDueDateExpression) { // setup SLA if provided - slaDueDateExpression = resolveVariable(slaDueDateExpression); + slaDueDateExpression = resolveVariable(slaDueDateExpression).toString(); if (slaDueDateExpression == null || slaDueDateExpression.trim().isEmpty()) { logger.debug("Sla due date expression resolved to no value '{}'", slaDueDateExpression); return null; @@ -593,7 +594,7 @@ private void registerExternalEventNodeListeners() { for (String type : events) { addEventListener(type, EMPTY_EVENT_LISTENER, true); if (isVariableExpression(type)) { - addEventListener(resolveVariable(type), EMPTY_EVENT_LISTENER, true); + addEventListener(resolveVariable(type).toString(), EMPTY_EVENT_LISTENER, true); } } } @@ -731,7 +732,7 @@ private Function getResolver(org.kie.api.definition.process.Node if (nodeInstances != null && !nodeInstances.isEmpty()) { StringBuilder st = new StringBuilder(); for (NodeInstance ni : nodeInstances) { - String result = resolveVariable(e, new NodeInstanceResolverFactory(ni)); + Object result = resolveVariable(e, new NodeInstanceResolverFactory(ni)); st.append(result).append("###"); } return st.toString(); @@ -745,14 +746,19 @@ private Function getResolver(org.kie.api.definition.process.Node } protected List resolveVariables(List events) { - return events.stream().map(this::resolveVariable).collect(Collectors.toList()); + return events.stream().map(this::resolveVariable).map(Object::toString).collect(Collectors.toList()); } - private String resolveVariable(String s) { + private Object resolveVariable(String s) { return resolveVariable(s, new ProcessInstanceResolverFactory(this)); } - private String resolveVariable(String s, VariableResolverFactory factory) { + private Object resolveVariable(String s, VariableResolverFactory factory) { + VariableScope var = (VariableScope) ((ContextResolver) this.getProcess()).resolveContext(VariableScope.VARIABLE_SCOPE, s); + if (var != null) { + return getVariable(s); + } + Map replacements = new HashMap<>(); Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(s); while (matcher.find()) { @@ -1228,4 +1234,5 @@ public final void wrap(ProcessInstance kogitoProcessInstance) { public final ProcessInstance unwrap() { return this.kogitoProcessInstance; } + } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/HumanTaskNodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/HumanTaskNodeInstance.java index e9738f7f4af..3c1bc2a3415 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/HumanTaskNodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/node/HumanTaskNodeInstance.java @@ -215,14 +215,12 @@ private boolean checkAndReassign(Map timers, @Override protected void addWorkItemListener() { super.addWorkItemListener(); - getProcessInstance().addEventListener(TIMER_TRIGGERED_EVENT, this, false); getProcessInstance().addEventListener(WORK_ITEM_TRANSITION, this, false); } @Override protected void removeWorkItemListener() { super.removeWorkItemListener(); - getProcessInstance().removeEventListener(TIMER_TRIGGERED_EVENT, this, false); getProcessInstance().removeEventListener(WORK_ITEM_TRANSITION, this, false); } diff --git a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcess.java b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcess.java index 3881821765d..2d09b5b141e 100644 --- a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcess.java +++ b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcess.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -310,4 +311,21 @@ public String[] getEventTypes() { return new String[0]; } } + + @Override + public int hashCode() { + return id().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AbstractProcess other = (AbstractProcess) obj; + return Objects.equals(id(), other.id()); + } } diff --git a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java index 9f49340e952..a035be6bf4e 100644 --- a/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/kie/kogito/process/impl/AbstractProcessInstance.java @@ -40,7 +40,6 @@ import org.jbpm.workflow.core.Node; import org.jbpm.workflow.core.WorkflowProcess; import org.jbpm.workflow.instance.NodeInstance; -import org.jbpm.workflow.instance.NodeInstanceContainer; import org.jbpm.workflow.instance.WorkflowProcessInstance; import org.jbpm.workflow.instance.impl.NodeInstanceImpl; import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl; @@ -441,17 +440,13 @@ public void triggerNode(String nodeId) { WorkflowProcessInstance wfpi = processInstance(); RuleFlowProcess rfp = ((RuleFlowProcess) wfpi.getProcess()); - org.kie.api.definition.process.Node node = rfp.getNodesRecursively() - .stream() - .filter(ni -> Objects.equals(nodeId, ni.getUniqueId()) || Objects.equals(nodeId, ni.getName()) || Objects.equals(nodeId, ni.getId().toExternalFormat())) - .findFirst() - .orElseThrow(() -> new NodeNotFoundException(this.id, nodeId)); - - org.kie.api.definition.process.Node parentNode = rfp.getParentNode(node.getId()); - - NodeInstanceContainer nodeInstanceContainerNode = parentNode == null ? wfpi : ((NodeInstanceContainer) wfpi.getNodeInstance(parentNode)); - - nodeInstanceContainerNode.getNodeInstance(node).trigger(null, Node.CONNECTION_DEFAULT_TYPE); + // we avoid create containers incorrectly + NodeInstance nodeInstance = wfpi.getNodeByPredicate(rfp, + ni -> Objects.equals(nodeId, ni.getName()) || Objects.equals(nodeId, ni.getId().toExternalFormat())); + if (nodeInstance == null) { + throw new NodeNotFoundException(this.id, nodeId); + } + nodeInstance.trigger(null, Node.CONNECTION_DEFAULT_TYPE); addToUnitOfWork(pi -> ((MutableProcessInstances) process.instances()).update(pi.id(), pi)); } diff --git a/jbpm/jbpm-flow/src/test/java/org/kie/kogito/process/impl/AbstractProcessInstanceTest.java b/jbpm/jbpm-flow/src/test/java/org/kie/kogito/process/impl/AbstractProcessInstanceTest.java index d2b9ec8cf30..cb882217601 100644 --- a/jbpm/jbpm-flow/src/test/java/org/kie/kogito/process/impl/AbstractProcessInstanceTest.java +++ b/jbpm/jbpm-flow/src/test/java/org/kie/kogito/process/impl/AbstractProcessInstanceTest.java @@ -120,7 +120,7 @@ private NodeInstance givenExistingNode(String nodeId) { when(process.getNodesRecursively()).thenReturn(Arrays.asList(node)); NodeInstance nodeInstance = mock(NodeInstance.class); - when(wpi.getNodeInstance(node)).thenReturn(nodeInstance); + when(wpi.getNodeByPredicate(any(), any())).thenReturn(nodeInstance); return nodeInstance; } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Account.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Account.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Account.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Account.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Address.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Address.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Address.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Address.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/ExceptionOnPurposeHandler.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/ExceptionService.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/ExceptionService.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/ExceptionService.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/ExceptionService.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/HelloService.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/HelloService.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/HelloService.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/HelloService.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/MyError.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/MyError.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/MyError.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/MyError.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/NotAvailableGoodsReport.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Order.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Order.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Order.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Order.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Person.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Person.java similarity index 74% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Person.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Person.java index 15696358264..8a358de78fc 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Person.java +++ b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Person.java @@ -19,6 +19,7 @@ package org.jbpm.bpmn2.objects; import java.io.Serializable; +import java.util.Objects; import jakarta.xml.bind.annotation.XmlRootElement; @@ -37,6 +38,11 @@ public Person(String name) { this.name = name; } + public Person(long id, String name) { + this.id = id; + this.name = name; + } + public String getName() { return name; } @@ -65,4 +71,22 @@ public void setAge(Integer age) { public String toString() { return "Person [id=" + id + ", name=" + name + ", age=" + age + "]"; } + + @Override + public int hashCode() { + return Objects.hash(age, id, name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Person other = (Person) obj; + return Objects.equals(age, other.age) && Objects.equals(id, other.id) && Objects.equals(name, other.name); + } + } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Status.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Status.java similarity index 100% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/Status.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/Status.java diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java similarity index 96% rename from jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java index 48a5612d5a5..9d6a939a11b 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java +++ b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/objects/TestWorkItemHandler.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.jbpm.process.instance.impl.humantask.InternalHumanTaskWorkItem; import org.jbpm.process.instance.impl.workitem.Active; @@ -73,6 +74,7 @@ public List getWorkItems() { public void transitionToPhase(KogitoWorkItem workItem, KogitoWorkItemManager manager, Transition transition) { if (transition.phase().equals(Complete.ID)) { + ((InternalKogitoWorkItem) workItem).setResults((Map) transition.data()); ((InternalKogitoWorkItemManager) manager).internalCompleteWorkItem((InternalKogitoWorkItem) workItem); } } diff --git a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompiler.java b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/services/Interface1.java similarity index 60% rename from jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompiler.java rename to jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/services/Interface1.java index 0e85a0b0b0a..9fe7b02d265 100644 --- a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/process/builder/transformation/DataTransformerCompiler.java +++ b/jbpm/jbpm-tests/src/main/java/org/jbpm/bpmn2/services/Interface1.java @@ -16,24 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.jbpm.process.builder.transformation; -import java.util.List; +package org.jbpm.bpmn2.services; -import org.jbpm.workflow.core.impl.DataDefinition; -import org.jbpm.workflow.core.node.Transformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import com.github.javaparser.ast.expr.Expression; +public class Interface1 { -public interface DataTransformerCompiler { + Logger LOGGER = LoggerFactory.getLogger(Interface1.class); - default String[] dialects() { - return new String[0]; + public void operation1(String value) { + LOGGER.info("operation1 in interface1 = {}", value); } - - default boolean accept(String dialect) { - return List.of(dialects()).contains(dialect); - } - - Expression compile(List inputs, List outputs, Transformation source); } diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessAutoComplete.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessAutoComplete.bpmn2 similarity index 95% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessAutoComplete.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessAutoComplete.bpmn2 index 3c942c209ad..b2dd1c612b6 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessAutoComplete.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessAutoComplete.bpmn2 @@ -30,7 +30,7 @@ xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.jboss.org/drools"> - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessAutoCompleteExpression.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessAutoCompleteExpression.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessAutoCompleteExpression.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessAutoCompleteExpression.bpmn2 index 205c19e6d57..06ebccda424 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessAutoCompleteExpression.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessAutoCompleteExpression.bpmn2 @@ -31,7 +31,7 @@ xmlns:tns="http://www.jboss.org/drools"> - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessEmptyCompleteExpression.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessEmptyCompleteExpression.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessEmptyCompleteExpression.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessEmptyCompleteExpression.bpmn2 index 533b6c68e5e..6c078136eea 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocSubProcessEmptyCompleteExpression.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocSubProcessEmptyCompleteExpression.bpmn2 @@ -31,7 +31,7 @@ xmlns:tns="http://www.jboss.org/drools"> - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocTerminateEndEvent.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocTerminateEndEvent.bpmn2 similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocTerminateEndEvent.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocTerminateEndEvent.bpmn2 index 151b557c713..319d62e9052 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-AdHocTerminateEndEvent.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/adhoc/BPMN2-AdHocTerminateEndEvent.bpmn2 @@ -20,7 +20,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/error/BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/error/BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2 new file mode 100755 index 00000000000..4d6825d15c4 --- /dev/null +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/error/BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2 @@ -0,0 +1,195 @@ + + + + + + + + + + + _2_InMessage + + + + + + SequenceFlow_4 + + + SequenceFlow_2 + SequenceFlow_6 + + + + + + + + + _DataInput_26 + _DataInput_27 + _DataInput_28 + _DataInput_29 + _DataInput_30 + _DataInput_31 + + + + + _DataInput_26 + + + _DataInput_27 + + + _DataInput_28 + + + _DataInput_29 + + + _DataInput_30 + + + _DataInput_31 + + + + john + + + + + SequenceFlow_3 + SequenceFlow_5 + + + + + _2_param + + + _2_result + + + + s + _2_param + + + _2_result + s + + + + SequenceFlow_4 + SequenceFlow_2 + SequenceFlow_3 + + + + + + SequenceFlow_5 + + + + + SequenceFlow_6 + + + SequenceFlow_7 + + + + SequenceFlow_7 + SequenceFlow_8 + + + + + + SequenceFlow_8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jbpm/jbpm-tests/src/test/resources/escalation/BPMN2-EscalationBoundaryEventWithTask.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-EscalationBoundaryEventWithTask.bpmn2 similarity index 92% rename from jbpm/jbpm-tests/src/test/resources/escalation/BPMN2-EscalationBoundaryEventWithTask.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-EscalationBoundaryEventWithTask.bpmn2 index df9e975bbaf..9d4823f3bd7 100755 --- a/jbpm/jbpm-tests/src/test/resources/escalation/BPMN2-EscalationBoundaryEventWithTask.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-EscalationBoundaryEventWithTask.bpmn2 @@ -33,7 +33,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -57,14 +57,16 @@ + + + + + + - - - - diff --git a/jbpm/jbpm-tests/src/test/resources/escalation/BPMN2-EventSubprocessEscalation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-EventSubprocessEscalation.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/escalation/BPMN2-EventSubprocessEscalation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-EventSubprocessEscalation.bpmn2 index 2931fda2ddf..17313c09afc 100755 --- a/jbpm/jbpm-tests/src/test/resources/escalation/BPMN2-EventSubprocessEscalation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-EventSubprocessEscalation.bpmn2 @@ -20,7 +20,7 @@ - + SequenceFlow_2 diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-Multiescalation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-Multiescalation.bpmn2 new file mode 100644 index 00000000000..053b00c8824 --- /dev/null +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-Multiescalation.bpmn2 @@ -0,0 +1,414 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _A0422A4F-E3B8-42C2-8C6F-234CE1780524 + + + + + + + + _546538EF-7FD3-4F2A-94D7-E6164020D828 + _A0422A4F-E3B8-42C2-8C6F-234CE1780524 + + + + + _98D1ACAF-B077-4259-88D6-A98A8A0BA915_TaskNameInputX + _98D1ACAF-B077-4259-88D6-A98A8A0BA915_SkippableInputX + + + + _98D1ACAF-B077-4259-88D6-A98A8A0BA915_TaskNameInputX + + + + + + + _98D1ACAF-B077-4259-88D6-A98A8A0BA915_SkippableInputX + + + + + + + + jdoe + + + + + _7F78C4C4-0339-447F-9B38-BC61BAA82721 + + + from_embedded + _C0638AB0-B291-4FA3-A23B-32795AADD598_dataInputX + + + _C0638AB0-B291-4FA3-A23B-32795AADD598_dataInputX + + + + + + + + + + _FDDE6BE2-4698-449E-BD81-C1F984217F59 + _7F78C4C4-0339-447F-9B38-BC61BAA82721 + System.out.println("Main - going to escalate"); +System.out.println("from_embedded: " + from_embedded); + + + + + + + + _62F7D3F8-F64F-4C45-B8B6-F73E3EAA0617 + _546538EF-7FD3-4F2A-94D7-E6164020D828 + System.out.println("Main - before"); + + + _6461CD5F-1BBB-4848-AC4C-92780D4EB928 + _62F7D3F8-F64F-4C45-B8B6-F73E3EAA0617 + + + data + _A3EA3450-0072-494E-814E-FE79EFCB14C7_dataInputX + + + _A3EA3450-0072-494E-814E-FE79EFCB14C7_dataInputX + + + + + + + + + + _2207CDA7-0D9A-475F-A82F-4F7C00032203 + _6461CD5F-1BBB-4848-AC4C-92780D4EB928 + System.out.println("Main - before"); +System.out.println("Data: " + data); + + + + + + + + _2207CDA7-0D9A-475F-A82F-4F7C00032203 + + + + + + + + + + + + + + + + + + + _D4DDD98E-F8CC-4DE2-A83A-CD98FE0090C9 + + + _D45B7BB5-B555-4CED-9812-B26810F92B54_escalation_dataOutputX + embedded_data + + + _D45B7BB5-B555-4CED-9812-B26810F92B54_escalation_dataOutputX + + + + + _F648A8EA-A514-428D-9F0E-FE22D10869AB + + + + + + + + _FB7D37EF-2B85-4BF7-AF1F-3B30F641A65F + _F648A8EA-A514-428D-9F0E-FE22D10869AB + System.out.println("Embedded - after"); + + + _717B70E1-D44A-41B2-BB35-372195C4B8C2 + _FB7D37EF-2B85-4BF7-AF1F-3B30F641A65F + + + + + + + + + _D4DDD98E-F8CC-4DE2-A83A-CD98FE0090C9 + _717B70E1-D44A-41B2-BB35-372195C4B8C2 + System.out.println("Embedded - before"); +System.out.println("embedded_data: " + embedded_data); + + + + _FDDE6BE2-4698-449E-BD81-C1F984217F59 + + + _D36A9FBC-C0A5-4E4D-93DE-154A0CAA3BA6_embedded_dataOutputX + from_embedded + + + _D36A9FBC-C0A5-4E4D-93DE-154A0CAA3BA6_embedded_dataOutputX + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _4D6UQA-DED2fZdcCquQDuw + _4D6UQA-DED2fZdcCquQDuw + + \ No newline at end of file diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-TopLevelEscalation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-TopLevelEscalation.bpmn2 new file mode 100644 index 00000000000..140b641e691 --- /dev/null +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/escalation/BPMN2-TopLevelEscalation.bpmn2 @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + _9F387975-3BC6-4C9E-A993-91A84BF8A727 + + + + + + + + _1B1AE7E4-585B-4DE2-92EE-AEB5FA650595 + _9F387975-3BC6-4C9E-A993-91A84BF8A727 + + + + + + + _75AFFB28-C6CE-40D8-9DA0-29593E1BB636_TaskNameInputX + _75AFFB28-C6CE-40D8-9DA0-29593E1BB636_dataInputX + _75AFFB28-C6CE-40D8-9DA0-29593E1BB636_SkippableInputX + + + _75AFFB28-C6CE-40D8-9DA0-29593E1BB636_dataOutputX + + + + _75AFFB28-C6CE-40D8-9DA0-29593E1BB636_TaskNameInputX + + + + + + + data + _75AFFB28-C6CE-40D8-9DA0-29593E1BB636_dataInputX + + + _75AFFB28-C6CE-40D8-9DA0-29593E1BB636_SkippableInputX + + + + + + + _75AFFB28-C6CE-40D8-9DA0-29593E1BB636_dataOutputX + data + + + + jdoe + + + + + _1B1AE7E4-585B-4DE2-92EE-AEB5FA650595 + + + _A4C8228C-1359-4663-A82B-4AA1C98C3871_dataOutputX + data + + + _A4C8228C-1359-4663-A82B-4AA1C98C3871_dataOutputX + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _ioNE0A98ED2kMdINZFf-yQ + _ioNE0A98ED2kMdINZFf-yQ + + \ No newline at end of file diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 index 5f18c6cfebe..877c96ebe26 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 @@ -26,7 +26,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 new file mode 100755 index 00000000000..470d99feab0 --- /dev/null +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + + + + + SequenceFlow_3 + + + SequenceFlow_3 + SequenceFlow_4 + + SequenceFlow_5 + SequenceFlow_6 + + + + + + + + + + + _DataInput_9 + _DataInput_10 + _DataInput_11 + _DataInput_12 + _DataInput_13 + _DataInput_14 + _DataInput_15 + + + + + + _DataInput_9 + + + _DataInput_10 + + + _DataInput_11 + + + _DataInput_12 + + + _DataInput_13 + + + _DataInput_14 + + + _DataInput_15 + + + + SequenceFlow_5 + + + + SequenceFlow_6 + + + + + + + SequenceFlow_7 + + + DataOutput_1 + var1 + + + DataOutput_1 + + + + + SequenceFlow_7 + SequenceFlow_8 + System.out.println("Error is handled : var1 = " + var1); + + + + SequenceFlow_8 + + + + SequenceFlow_4 + SequenceFlow_9 + System.out.println("Process is finishing"); + + + SequenceFlow_9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 index 0d29ebbcaab..5c77c5460dd 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 @@ -26,7 +26,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundarySignalWithNameEventOnTaskbpmn2.bpmn b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundarySignalWithNameEventOnTask.bpmn similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BoundarySignalWithNameEventOnTaskbpmn2.bpmn rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundarySignalWithNameEventOnTask.bpmn index dda36a9bac5..f459e7f2968 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundarySignalWithNameEventOnTaskbpmn2.bpmn +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundarySignalWithNameEventOnTask.bpmn @@ -21,7 +21,7 @@ - + SequenceFlow_1 diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryTimerCycleCron.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryTimerCycleISO.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryTimerCycleCron.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryTimerCycleISO.bpmn2 index ae50cb8a525..6ad7b854842 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryTimerCycleCron.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryTimerCycleISO.bpmn2 @@ -21,7 +21,7 @@ - + @@ -69,7 +69,7 @@ _1206D165-6704-439E-99E6-7A02989A8C3C - 0/1 * * * * ? + R3/PT0.1S diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryTimerCycleCronVariable.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryTimerCycleISOVariable.bpmn2 similarity index 99% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryTimerCycleCronVariable.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryTimerCycleISOVariable.bpmn2 index a82655cc6d9..7b63f6cdccf 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryTimerCycleCronVariable.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-BoundaryTimerCycleISOVariable.bpmn2 @@ -21,7 +21,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-MessageEndEvent.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-MessageEndEvent.bpmn2 similarity index 100% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-MessageEndEvent.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/event/BPMN2-MessageEndEvent.bpmn2 diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BooleanStructureRef.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-BooleanStructureRef.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BooleanStructureRef.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-BooleanStructureRef.bpmn2 index efd2d260d99..f0c429f79dd 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BooleanStructureRef.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-BooleanStructureRef.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BrokenStructureRef.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-BrokenStructureRef.bpmn2 similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BrokenStructureRef.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-BrokenStructureRef.bpmn2 index 14605f2e86a..b96b93bb7ab 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BrokenStructureRef.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-BrokenStructureRef.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-DataInputAssociations-two-assigns.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DataInputAssociationsTwoAssigns.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-DataInputAssociations-two-assigns.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DataInputAssociationsTwoAssigns.bpmn2 index daa4fb172c8..514f2f3e191 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-DataInputAssociations-two-assigns.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DataInputAssociationsTwoAssigns.bpmn2 @@ -31,7 +31,7 @@ xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.jboss.org/drools"> - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-DataOutputAssociations-HumanTask.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DataOutputAssociationsHumanTask.bpmn2 similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-DataOutputAssociations-HumanTask.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DataOutputAssociationsHumanTask.bpmn2 index 5056fb2cff9..bffd771c49c 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-DataOutputAssociations-HumanTask.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DataOutputAssociationsHumanTask.bpmn2 @@ -31,7 +31,7 @@ xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.jboss.org/drools"> - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-DefaultObjectStructureRef.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DefaultObjectStructureRef.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-DefaultObjectStructureRef.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DefaultObjectStructureRef.bpmn2 index b6fe48d5783..f2229bf8d42 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-DefaultObjectStructureRef.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-DefaultObjectStructureRef.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-FloatStructureRef.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-FloatStructureRef.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-FloatStructureRef.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-FloatStructureRef.bpmn2 index 3f003861d66..9bafb0d064a 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-FloatStructureRef.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-FloatStructureRef.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntegerStructureRef.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-IntegerStructureRef.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntegerStructureRef.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-IntegerStructureRef.bpmn2 index 3da64df5076..3395dbb2d39 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntegerStructureRef.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-IntegerStructureRef.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-NullVariableInScriptTaskProcess.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-NullVariableInScriptTaskProcess.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-NullVariableInScriptTaskProcess.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-NullVariableInScriptTaskProcess.bpmn2 index 70289725257..401eb978613 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-NullVariableInScriptTaskProcess.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-NullVariableInScriptTaskProcess.bpmn2 @@ -34,9 +34,9 @@ + tns:packageName="org.jbpm.bpmn2.flow" > diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ObjectStructureRef.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-ObjectStructureRef.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ObjectStructureRef.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-ObjectStructureRef.bpmn2 index 450babc2fd8..f8cd0a03e42 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ObjectStructureRef.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-ObjectStructureRef.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ProcessEmptyScript.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-ProcessEmptyScript.bpmn2 similarity index 95% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ProcessEmptyScript.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-ProcessEmptyScript.bpmn2 index d163a0e99b9..719d4f88c6f 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ProcessEmptyScript.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/flow/BPMN2-ProcessEmptyScript.bpmn2 @@ -27,7 +27,7 @@ xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" xmlns:tns="http://www.jboss.org/drools"> - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 similarity index 95% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 index 60418fb8b20..5cdbbde7fa8 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2 @@ -36,7 +36,7 @@ - + @@ -61,11 +61,11 @@ - + _4_Output x - param.toUpperCase(); + param.toUpperCase() _4_Output diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 index b0321b3ff70..cde461dea9c 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignal2.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal2.bpmn2 similarity index 99% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignal2.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal2.bpmn2 index 9df9412c66f..61dfb3559be 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignal2.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal2.bpmn2 @@ -33,7 +33,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 similarity index 95% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 index cb584c39813..48b9f21223f 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2 @@ -33,7 +33,7 @@ - + @@ -58,11 +58,11 @@ - + _4_Output x - param.toUpperCase(); + param.toUpperCase() _4_Output diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 index ef1434ed147..1af6a32fb10 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycle3.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 similarity index 95% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 index 344f25ddfa2..5b49feb3dbe 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerCycleCron.bpmn2 @@ -32,7 +32,7 @@ - + @@ -41,7 +41,7 @@ - 0/1 * * * * ? + R3/PT1S diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 similarity index 91% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 index 160a79bf31c..0512b88a5f7 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2 @@ -22,10 +22,8 @@ - - - - + + _1-_3 @@ -40,8 +38,11 @@ _3-_4 _4-_5 - kcontext.getKieRuntime().getGlobal("TestOK").toString(); - + + System.out.println("TestOK: " + TestOK); + kcontext.setVariable("TestOK", Boolean.TRUE); + System.out.println("TestOK: " + kcontext.getVariable("TestOK")); + _4-_5 diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 index df400244748..422828e10cb 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2 @@ -31,7 +31,7 @@ xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.jboss.org/drools"> - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessage.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessage.bpmn2 similarity index 100% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessage.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessage.bpmn2 diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 similarity index 91% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 index 1323d06a34c..12d711ca829 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2 @@ -35,7 +35,7 @@ - + @@ -47,7 +47,7 @@ x _2_Input - param.toUpperCase(); + x.toUpperCase() _2_Input diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 similarity index 91% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 index 1913d572900..4a366a99720 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/intermediate/BPMN2-IntermediateThrowEventSignalWithTransformation.bpmn2 @@ -32,7 +32,7 @@ - + @@ -44,7 +44,7 @@ x _2_Input - param.toUpperCase(); + x.toUpperCase() _2_Input diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcess.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcess.bpmn2 similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcess.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcess.bpmn2 index ab68586d063..a86de045b3b 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcess.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcess.bpmn2 @@ -40,7 +40,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithCustomTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithCustomTransformation.bpmn2 similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithCustomTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithCustomTransformation.bpmn2 index 35dacbb1e2b..0e12a854894 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithCustomTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithCustomTransformation.bpmn2 @@ -40,7 +40,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 similarity index 91% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 index 69cbf479adf..b6d1225cdab 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2 @@ -41,7 +41,7 @@ - + @@ -53,8 +53,8 @@ - - + + _2_param @@ -70,7 +70,7 @@ _2_result list - Arrays.asList(Result.split(",")) + java.util.Arrays.asList(Result.split(",")) diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 similarity index 83% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 index 35c7edd85cc..3cbf0c31538 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2 @@ -40,7 +40,7 @@ - + @@ -56,7 +56,7 @@ - + _2_param @@ -67,18 +67,28 @@ s _2_param - + JAXBContext.newInstance(Person.class, Address.class).createMarshaller().marshal(s, result); + return result.toString(); + } catch(Throwable th) { + throw new RuntimeException(th); + } + ]]> _2_result s - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 index 2b1a8c1ca66..217d34edbfc 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceProcessWithMvelTransformation.bpmn2 @@ -40,7 +40,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceTask.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceTask.bpmn2 similarity index 91% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceTask.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceTask.bpmn2 index cdd54812030..8e280875447 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceTask.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceTask.bpmn2 @@ -18,9 +18,18 @@ ~ under the License. --> - + - + EAID_DE09F4BA_6B35_4699_8AC9_84819B916A98 @@ -48,8 +57,8 @@ - - + + EAID_137CB429_F782_4fee_8CC8_D57206264E3E diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceTask-web-service.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceTaskWebService.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceTask-web-service.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceTaskWebService.bpmn2 index dd1777fba92..f340b2b894f 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ServiceTask-web-service.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/service/BPMN2-ServiceTaskWebService.bpmn2 @@ -27,12 +27,12 @@ - - + + _2_InMessage - + SequenceFlow_3 diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-SignalStartWithTransformation.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/start/BPMN2-SignalStartWithTransformation.bpmn2 similarity index 95% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-SignalStartWithTransformation.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/start/BPMN2-SignalStartWithTransformation.bpmn2 index 73f8ff10dd3..92060fb056d 100644 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-SignalStartWithTransformation.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/start/BPMN2-SignalStartWithTransformation.bpmn2 @@ -32,7 +32,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionServiceProcess-ErrorSignalling.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionServiceProcessErrorSignalling.bpmn2 similarity index 97% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionServiceProcess-ErrorSignalling.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionServiceProcessErrorSignalling.bpmn2 index ee463734de9..f2b3d63627a 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionServiceProcess-ErrorSignalling.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionServiceProcessErrorSignalling.bpmn2 @@ -49,7 +49,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionServiceProcess-Signalling.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionServiceProcessSignalling.bpmn2 similarity index 96% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionServiceProcess-Signalling.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionServiceProcessSignalling.bpmn2 index a19dc5623a4..aa3663715a8 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionServiceProcess-Signalling.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionServiceProcessSignalling.bpmn2 @@ -49,7 +49,9 @@ - + diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionThrowingServiceProcess.bpmn2 b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionThrowingServiceProcess.bpmn2 similarity index 95% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionThrowingServiceProcess.bpmn2 rename to jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionThrowingServiceProcess.bpmn2 index 25d3e932c0d..9e07fce205c 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-ExceptionThrowingServiceProcess.bpmn2 +++ b/jbpm/jbpm-tests/src/test/bpmn/org/jbpm/bpmn2/subprocess/BPMN2-ExceptionThrowingServiceProcess.bpmn2 @@ -40,7 +40,7 @@ - + diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java index 84904b83d14..2578981db0b 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ActivityTest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -34,6 +35,8 @@ import org.jbpm.bpmn2.activity.ScriptTaskProcess; import org.jbpm.bpmn2.activity.ScriptTaskWithIOModel; import org.jbpm.bpmn2.activity.ScriptTaskWithIOProcess; +import org.jbpm.bpmn2.activity.UserTaskWithParametrizedInputModel; +import org.jbpm.bpmn2.activity.UserTaskWithParametrizedInputProcess; import org.jbpm.bpmn2.activity.UserTaskWithSimulationMetaDataModel; import org.jbpm.bpmn2.activity.UserTaskWithSimulationMetaDataProcess; import org.jbpm.bpmn2.adhoc.SubProcessInAdHocProcessModel; @@ -56,18 +59,34 @@ import org.jbpm.bpmn2.flow.XORSameTargetProcess; import org.jbpm.bpmn2.handler.ReceiveTaskHandler; import org.jbpm.bpmn2.handler.SendTaskHandler; -import org.jbpm.bpmn2.handler.ServiceTaskHandler; import org.jbpm.bpmn2.objects.Account; import org.jbpm.bpmn2.objects.Address; import org.jbpm.bpmn2.objects.HelloService; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.service.ServiceProcessModel; +import org.jbpm.bpmn2.service.ServiceProcessProcess; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelCollectionTransformationModel; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelCollectionTransformationProcess; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelJaxbTransformationModel; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelJaxbTransformationProcess; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelTransformationModel; +import org.jbpm.bpmn2.service.ServiceProcessWithMvelTransformationProcess; +import org.jbpm.bpmn2.service.ServiceTaskModel; +import org.jbpm.bpmn2.service.ServiceTaskProcess; +import org.jbpm.bpmn2.service.ServiceTaskWebServiceModel; +import org.jbpm.bpmn2.service.ServiceTaskWebServiceProcess; import org.jbpm.bpmn2.subprocess.AssignmentProcessModel; import org.jbpm.bpmn2.subprocess.AssignmentProcessProcess; import org.jbpm.bpmn2.subprocess.AssignmentSubProcessModel; import org.jbpm.bpmn2.subprocess.AssignmentSubProcessProcess; +import org.jbpm.bpmn2.subprocess.CallActivity2Model; +import org.jbpm.bpmn2.subprocess.CallActivity2Process; +import org.jbpm.bpmn2.subprocess.CallActivityMIModel; +import org.jbpm.bpmn2.subprocess.CallActivityMIProcess; import org.jbpm.bpmn2.subprocess.CallActivityModel; import org.jbpm.bpmn2.subprocess.CallActivityProcess; +import org.jbpm.bpmn2.subprocess.CallActivitySubProcessModel; import org.jbpm.bpmn2.subprocess.CallActivitySubProcessProcess; import org.jbpm.bpmn2.subprocess.CallActivityWithIOexpressionModel; import org.jbpm.bpmn2.subprocess.CallActivityWithIOexpressionProcess; @@ -83,6 +102,8 @@ import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcess; import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcessScopeModel; import org.jbpm.bpmn2.subprocess.SubProcessWithTerminateEndEventProcessScopeProcess; +import org.jbpm.bpmn2.subprocess.SubProcessWithTypeVariableModel; +import org.jbpm.bpmn2.subprocess.SubProcessWithTypeVariableProcess; import org.jbpm.bpmn2.subprocess.SubprocessGroupAssignmentModel; import org.jbpm.bpmn2.subprocess.SubprocessGroupAssignmentProcess; import org.jbpm.bpmn2.task.ReceiveTaskModel; @@ -98,7 +119,6 @@ import org.jbpm.process.builder.dialect.ProcessDialect; import org.jbpm.process.builder.dialect.ProcessDialectRegistry; import org.jbpm.process.core.context.variable.VariableScope; -import org.jbpm.process.core.impl.DataTransformerRegistry; import org.jbpm.process.instance.event.listeners.RuleAwareProcessEventListener; import org.jbpm.process.instance.event.listeners.TriggerRulesEventListener; import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler; @@ -117,10 +137,10 @@ import org.jbpm.workflow.instance.node.EndNodeInstance; import org.jbpm.workflow.instance.node.StartNodeInstance; import org.jbpm.workflow.instance.node.WorkItemNodeInstance; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; -import org.kie.api.command.ExecutableCommand; import org.kie.api.definition.process.Node; import org.kie.api.definition.process.NodeContainer; import org.kie.api.definition.process.Process; @@ -134,17 +154,19 @@ import org.kie.api.event.rule.BeforeMatchFiredEvent; import org.kie.api.event.rule.MatchCancelledEvent; import org.kie.api.event.rule.MatchCreatedEvent; -import org.kie.api.runtime.process.DataTransformer; import org.kie.api.runtime.process.NodeInstance; import org.kie.kogito.Application; import org.kie.kogito.auth.SecurityPolicy; +import org.kie.kogito.handlers.HelloService_hello__2_Handler; +import org.kie.kogito.handlers.HelloService_validate__2_Handler; +import org.kie.kogito.handlers.Interface1_operation1_EAID_3344916D_2BAC_4ab6_92D4_F739156D0933_Handler; +import org.kie.kogito.handlers.Interface1_operation1_ServiceTask_2_Handler; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoNode; -import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer; +import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime; import org.kie.kogito.internal.process.runtime.KogitoWorkItem; -import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager; import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance; import org.kie.kogito.process.ProcessInstance; import org.kie.kogito.process.workitems.InternalKogitoWorkItem; @@ -448,40 +470,38 @@ public void testUserTask() { } @Test - public void testUserTaskVerifyParameters() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/activity/BPMN2-UserTask.bpmn2"); - - kruntime.getKieSession().getEnvironment().set("deploymentId", "test-deployment-id"); + public void testUserTaskVerifyParameters() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("UserTask"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process process = UserTaskProcess.newProcess(app); + UserTaskModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); assertThat(workItem.getParameter("ActorId")).isEqualTo("john"); - final String pId = processInstance.getStringId(); - - kruntime.getKieSession().execute((ExecutableCommand) context -> { - - KogitoProcessInstance processInstance1 = kruntime.getProcessInstance(pId); - assertThat(processInstance1).isNotNull(); - NodeInstance nodeInstance = ((KogitoNodeInstanceContainer) processInstance1) - .getNodeInstance(((InternalKogitoWorkItem) workItem).getNodeInstanceStringId()); - - assertThat(nodeInstance).isNotNull().isInstanceOf(WorkItemNodeInstance.class); - String deploymentId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getDeploymentId(); - String nodeInstanceId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeInstanceStringId(); - WorkflowElementIdentifier nodeId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeId(); - - assertThat(deploymentId).isEqualTo(((InternalKogitoWorkItem) workItem).getDeploymentId()); - assertThat(nodeId).isEqualTo(((InternalKogitoWorkItem) workItem).getNodeId()); - assertThat(nodeInstanceId).isEqualTo(((InternalKogitoWorkItem) workItem).getNodeInstanceStringId()); - - return null; - }); - - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); + final String pId = processInstance.id(); + Optional> processInstance1 = process.instances().stream() + .filter(instance -> instance.id().equals(pId)).findFirst(); + assertThat(processInstance1).isNotNull(); + Assertions.assertTrue(processInstance1.isPresent()); + Optional nodeInstance = processInstance1.get().findNodes(node -> node.getStringId().equals(workItem.getNodeInstance().getStringId())) + .stream().findFirst(); + assertThat(nodeInstance).isNotNull(); + Assertions.assertTrue(nodeInstance.isPresent()); + assertThat(nodeInstance.get()).isInstanceOf(WorkItemNodeInstance.class); + String deploymentId = ((InternalKogitoWorkItem) workItem).getDeploymentId(); + String nodeInstanceId = ((InternalKogitoWorkItem) workItem).getNodeInstanceStringId(); + WorkflowElementIdentifier nodeId = ((InternalKogitoWorkItem) workItem).getNodeId(); + + assertThat(deploymentId).isEqualTo(((InternalKogitoWorkItem) workItem).getDeploymentId()); + assertThat(nodeId).isEqualTo(((InternalKogitoWorkItem) workItem).getNodeId()); + assertThat(nodeInstanceId).isEqualTo(((InternalKogitoWorkItem) workItem).getNodeInstanceStringId()); + processInstance.completeWorkItem(workItem.getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test @@ -547,13 +567,13 @@ public void testCallActivity() { } @Test - public void testCallActivityMI() throws Exception { - kruntime = createKogitoProcessRuntime( - "org/jbpm/bpmn2/subprocess/BPMN2-CallActivityMI.bpmn2", - "org/jbpm/bpmn2/subprocess/BPMN2-CallActivitySubProcess.bpmn2"); - + public void testCallActivityMI() { + Application app = ProcessTestHelper.newApplication(); + TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", + workItemHandler); final List subprocessStarted = new ArrayList<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { + DefaultKogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { @Override public void beforeProcessStarted(ProcessStartedEvent event) { @@ -562,47 +582,47 @@ public void beforeProcessStarted(ProcessStartedEvent event) { } } - }); - + }; + ProcessTestHelper.registerProcessEventListener(app, listener); + CallActivitySubProcessProcess.newProcess(app); + org.kie.kogito.process.Process process = CallActivityMIProcess.newProcess(app); + CallActivityMIModel model = process.createModel(); List list = new ArrayList<>(); list.add("first"); list.add("second"); List listOut = new ArrayList<>(); + model.setX("oldValue"); + model.setList(list); + model.setListOut(listOut); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); - Map params = new HashMap<>(); - params.put("x", "oldValue"); - params.put("list", list); - params.put("listOut", listOut); - - KogitoProcessInstance processInstance = kruntime.startProcess("CallActivityMI", params); - assertProcessInstanceCompleted(processInstance); + assertThat(processInstance.status()).isEqualTo(org.jbpm.process.instance.ProcessInstance.STATE_COMPLETED); assertThat(subprocessStarted).hasSize(2); - - listOut = (List) ((KogitoWorkflowProcessInstance) processInstance).getVariable("listOut"); + listOut = processInstance.variables().getListOut(); assertThat(listOut).isNotNull().hasSize(2).containsExactly("new value", "new value"); } @Test - public void testCallActivity2() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-CallActivity2.bpmn2", - "org/jbpm/bpmn2/subprocess/BPMN2-CallActivitySubProcess.bpmn2"); + public void testCallActivity2() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); - Map params = new HashMap<>(); - params.put("x", "oldValue"); - KogitoProcessInstance processInstance = kruntime.startProcess( - "CallActivity2", params); - assertProcessInstanceActive(processInstance); - assertThat(((KogitoWorkflowProcessInstance) processInstance).getVariable("y")).isEqualTo("new value"); + org.kie.kogito.process.Process callActivitySubProcess = CallActivitySubProcessProcess.newProcess(app); + org.kie.kogito.process.Process process = CallActivity2Process.newProcess(app); + CallActivity2Model model = process.createModel(); + model.setX("oldValue"); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + assertThat(processInstance.status()).isEqualTo(org.jbpm.process.instance.ProcessInstance.STATE_ACTIVE); + assertThat(processInstance.variables().getY()).isEqualTo("new value"); org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); assertThat(workItem.getParameter("ActorId")).isEqualTo("krisv"); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - - assertProcessInstanceFinished(processInstance, kruntime); + processInstance.completeWorkItem(workItem.getStringId(), null); + assertThat(processInstance.status()).isEqualTo(org.jbpm.process.instance.ProcessInstance.STATE_COMPLETED); } @Test @@ -797,121 +817,32 @@ public void testAdHocProcessDynamicSubProcess() throws Exception { @Test public void testServiceTask() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcess.bpmn2"); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "john"); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcess", params); - assertProcessInstanceFinished(processInstance, kruntime); - assertThat(processInstance.getVariable("s")).isEqualTo("Hello john!"); - } - - @Test - public void testServiceTaskWithAccessToWorkItemInfo() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcess.bpmn2"); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler() { - - @Override - public void executeWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem, KogitoWorkItemManager manager) { - assertThat(workItem.getProcessInstance()).isNotNull(); - assertThat(workItem.getNodeInstance()).isNotNull(); - super.executeWorkItem(workItem, manager); - } - - }); - Map params = new HashMap<>(); - params.put("s", "john"); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("ServiceProcess", params); - assertProcessInstanceFinished(processInstance, kruntime); - assertThat(processInstance.getVariable("s")).isEqualTo("Hello john!"); - } - - @Test - public void testServiceTaskWithMvelTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelTransformation.bpmn2"); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "JoHn"); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcessWithMvelTransformation", params); - assertProcessInstanceFinished(processInstance, kruntime); - assertThat(processInstance.getVariable("s")).isEqualTo("hello john!"); - } - - @Test - public void testServiceTaskWithCustomTransformation() throws Exception { - DataTransformerRegistry.get().register("http://custom/transformer", new DataTransformer() { - - @Override - public Object transform(Object expression, Map parameters) { - // support only single object - String value = parameters.values().iterator().next().toString(); - Object result = null; - if ("caplitalizeFirst".equals(expression)) { - String first = value.substring(0, 1); - String main = value.substring(1, value.length()); - - result = first.toUpperCase() + main; - } else if ("caplitalizeLast".equals(expression)) { - String last = value.substring(value.length() - 1); - String main = value.substring(0, value.length() - 1); - - result = main + last.toUpperCase(); - } else { - throw new IllegalArgumentException("Unknown expression " + expression); - } - return result; - } + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_hello__2_Handler", new HelloService_hello__2_Handler()); + org.kie.kogito.process.Process definition = ServiceProcessProcess.newProcess(app); - @Override - public Object compile(String expression, Map parameters) { - // compilation not supported - return expression; - } - }); - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithCustomTransformation.bpmn2"); + ServiceProcessModel model = definition.createModel(); + model.setS("john"); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "john doe"); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getS()).isEqualTo("Hello john!"); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcess", params); - assertProcessInstanceFinished(processInstance, kruntime); - assertThat(processInstance.getVariable("s")).isEqualTo("John doE"); } @Test public void testServiceTaskNoInterfaceName() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask-web-service.bpmn2"); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.services.Interface1_operation1_ServiceTask_2_Handler", new Interface1_operation1_ServiceTask_2_Handler()); + org.kie.kogito.process.Process definition = ServiceTaskWebServiceProcess.newProcess(app); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new SystemOutWorkItemHandler() { + ServiceTaskWebServiceModel model = definition.createModel(); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); - @Override - public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) { - assertThat(workItem.getParameter("Interface")).isEqualTo("SimpleService"); - assertThat(workItem.getParameter("Operation")).isEqualTo("hello"); - assertThat(workItem.getParameter("ParameterType")).isEqualTo("java.lang.String"); - assertThat(workItem.getParameter("implementation")).isEqualTo("##WebService"); - assertThat(workItem.getParameter("operationImplementationRef")).isEqualTo("hello"); - assertThat(workItem.getParameter("interfaceImplementationRef")).isEqualTo("SimpleService"); - super.executeWorkItem(workItem, manager); - } + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); - }); - Map params = new HashMap<>(); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("org.jboss.qa.jbpm.CallWS", params); - assertProcessInstanceFinished(processInstance, kruntime); } @Test @@ -1175,17 +1106,16 @@ public void testInvalidServiceTask() { assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> createKogitoProcessRuntime("BPMN2-InvalidServiceProcess.bpmn2")); } - @Test // JBPM-3951 + @Test public void testServiceTaskInterface() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceTask.bpmn2"); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new SystemOutWorkItemHandler()); - Map params = new HashMap<>(); - - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("EAID_DP000000_23D3_4e7e_80FE_6D8C0AF83CAA", params); - assertProcessInstanceFinished(processInstance, kruntime); + Application app = ProcessTestHelper.newApplication(); + Interface1_operation1_EAID_3344916D_2BAC_4ab6_92D4_F739156D0933_Handler handler = new Interface1_operation1_EAID_3344916D_2BAC_4ab6_92D4_F739156D0933_Handler(); + ProcessTestHelper.registerHandler(app, handler.getName(), handler); + org.kie.kogito.process.Process definition = ServiceTaskProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @SuppressWarnings("unchecked") @@ -1243,39 +1173,58 @@ public void beforeProcessStarted(ProcessStartedEvent event) { assertThat(((KogitoWorkflowProcessInstance) instances.get(1)).getVariable("subY")).isEqualTo("new value"); } + @Test + public void testServiceTaskWithMvelTransformation() throws Exception { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_hello__2_Handler", new HelloService_hello__2_Handler()); + org.kie.kogito.process.Process definition = ServiceProcessWithMvelTransformationProcess.newProcess(app); + ServiceProcessWithMvelTransformationModel model = definition.createModel(); + + model.setS("JoHn"); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + + assertThat(instance.variables().getS()).isEqualTo("hello john!"); + + } + @Test public void testServiceTaskWithMvelCollectionTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelCollectionTransformation.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "john,poul,mary"); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcess", params); - assertProcessInstanceFinished(processInstance, kruntime); - @SuppressWarnings("unchecked") - List result = (List) processInstance.getVariable("list"); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_hello__2_Handler", new HelloService_hello__2_Handler()); + org.kie.kogito.process.Process definition = ServiceProcessWithMvelCollectionTransformationProcess.newProcess(app); + ServiceProcessWithMvelCollectionTransformationModel model = definition.createModel(); + + model.setS("john,poul,mary"); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + + List result = (List) instance.variables().getList(); assertThat(result).hasSize(3); + } @Test public void testServiceTaskWithMvelJaxbTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcessWithMvelJaxbTransformation.bpmn2"); + HelloService.VALIDATE_STRING = "123john"; + + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_validate__2_Handler", new HelloService_validate__2_Handler()); + org.kie.kogito.process.Process definition = ServiceProcessWithMvelJaxbTransformationProcess.newProcess(app); + ServiceProcessWithMvelJaxbTransformationModel model = definition.createModel(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", - new ServiceTaskHandler()); - Map params = new HashMap<>(); Person person = new Person(); person.setId(123); person.setName("john"); - params.put("s", person); + model.setS(person); - HelloService.VALIDATE_STRING = "123john"; + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime - .startProcess("ServiceProcessWithMvelJaxbTransformation", params); - assertProcessInstanceFinished(processInstance, kruntime); + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); } @@ -1333,46 +1282,43 @@ public void testInvalidSubProcessNoOutgoingSF() throws Exception { } @Test - public void testAdHocSubProcessEmptyCompleteExpression() throws Exception { - try { - createKogitoProcessRuntime("BPMN2-AdHocSubProcessEmptyCompleteExpression.bpmn2"); - fail("Process should be invalid, there should be build errors"); - } catch (RuntimeException e) { - // there should be build errors - } - } - - @Test - public void testSubProcessWithTypeVariable() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/subprocess/BPMN2-SubProcessWithTypeVariable.bpmn2"); - + public void testSubProcessWithTypeVariable() { + Application app = ProcessTestHelper.newApplication(); final List list = new ArrayList<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { + DefaultKogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { public void afterNodeTriggered(ProcessNodeTriggeredEvent event) { if (event.getNodeInstance().getNodeName().equals("Read Map")) { list.add(event.getNodeInstance().getNodeName()); } } - }); - KogitoProcessInstance processInstance = kruntime.startProcess("SubProcessWithTypeVariable"); - assertProcessInstanceCompleted(processInstance); + }; + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process process = SubProcessWithTypeVariableProcess.newProcess(app); + SubProcessWithTypeVariableModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); + + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(list).hasSize(2); } @Test - public void testUserTaskParametrizedInput() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/activity/BPMN2-UserTaskWithParametrizedInput.bpmn2"); + public void testUserTaskParametrizedInput() { + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process process = UserTaskWithParametrizedInputProcess.newProcess(app); + UserTaskWithParametrizedInputModel model = process.createModel(); + ProcessInstance processInstance = process.createInstance(model); + processInstance.start(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("UserTaskWithParametrizedInput"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); org.kie.kogito.internal.process.runtime.KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); - assertThat(workItem.getParameter("Description").toString().trim()).isEqualTo("Executing task of process instance " + processInstance.getStringId() + " as work item with Hello"); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); + assertThat(workItem.getParameter("Description").toString().trim()).isEqualTo("Executing task of process instance " + processInstance.id() + " as work item with Hello"); + processInstance.completeWorkItem(workItem.getStringId(), null); + assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/BrokenStructureRefTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/BrokenStructureRefTest.java index cb3ac9e3a31..3207102510b 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/BrokenStructureRefTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/BrokenStructureRefTest.java @@ -31,7 +31,7 @@ public class BrokenStructureRefTest { @Test public void testProcessWithBrokenItemDefinitionUri() throws Exception { - String inputBpmn = getClass().getResource("/BPMN2-BrokenStructureRef.bpmn2").getPath(); + String inputBpmn = getClass().getResource("/org/jbpm/bpmn2/flow/BPMN2-BrokenStructureRef.bpmn2").getPath(); XmlProcessDumper dumper = XmlProcessDumperFactory.getXmlProcessDumperFactoryService().newXmlProcessDumper(); assertThat(dumper).isNotNull(); String processXml = new String(Files.readAllBytes(Paths.get(inputBpmn))); diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java index 2f46fa66c53..7794b06b60e 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/DataTest.java @@ -32,6 +32,8 @@ import org.jbpm.bpmn2.core.Association; import org.jbpm.bpmn2.core.DataStore; import org.jbpm.bpmn2.core.Definitions; +import org.jbpm.bpmn2.flow.DataOutputAssociationsHumanTaskModel; +import org.jbpm.bpmn2.flow.DataOutputAssociationsHumanTaskProcess; import org.jbpm.bpmn2.xml.ProcessHandler; import org.jbpm.process.core.datatype.impl.type.ObjectDataType; import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler; @@ -358,8 +360,8 @@ public void executeWorkItem(KogitoWorkItem workItem, @Test public void testDataOutputAssociationsforHumanTask() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-DataOutputAssociations-HumanTask.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new KogitoWorkItemHandler() { public void abortWorkItem(KogitoWorkItem manager, @@ -396,10 +398,11 @@ public void executeWorkItem(KogitoWorkItem workItem, } }); - Map params = new HashMap<>(); - KogitoProcessInstance processInstance = kruntime.startProcess("process", - params); + org.kie.kogito.process.Process definition = DataOutputAssociationsHumanTaskProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + + instance.start(); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/EndEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/EndEventTest.java index 389ba67b275..ee949594ca3 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/EndEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/EndEventTest.java @@ -23,14 +23,15 @@ import java.util.List; import java.util.Map; -import org.jbpm.bpmn2.handler.SendTaskHandler; -import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.event.MessageEndEventModel; +import org.jbpm.bpmn2.event.MessageEndEventProcess; import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler; +import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.kie.api.definition.process.WorkflowElementIdentifier; +import org.kie.kogito.Application; +import org.kie.kogito.event.impl.MessageProducer; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; -import org.kie.kogito.process.workitems.InternalKogitoWorkItem; import static org.assertj.core.api.Assertions.assertThat; @@ -74,54 +75,22 @@ public void testSignalEnd() throws Exception { @Test public void testMessageEnd() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-MessageEndEvent.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", - new SendTaskHandler()); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess( - "MessageEndEvent", params); - assertProcessInstanceCompleted(processInstance); - - } - - @Test - public void testMessageEndVerifyDeploymentId() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-MessageEndEvent.bpmn2"); - - TestWorkItemHandler handler = new TestWorkItemHandler(); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", handler); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess("MessageEndEvent", params); - assertProcessInstanceCompleted(processInstance); - - InternalKogitoWorkItem workItem = (InternalKogitoWorkItem) handler.getWorkItem(); - assertThat(workItem).isNotNull(); - - String nodeInstanceId = workItem.getNodeInstanceStringId(); - WorkflowElementIdentifier nodeId = workItem.getNodeId(); - String deploymentId = workItem.getDeploymentId(); - - assertThat(nodeId).isNotNull(); - assertThat(nodeInstanceId).isNotNull(); - assertThat(deploymentId).isNull(); - - // now set deployment id as part of kruntime's env - kruntime.getKieRuntime().getEnvironment().set("deploymentId", "testDeploymentId"); - - processInstance = kruntime.startProcess("MessageEndEvent", params); - assertProcessInstanceCompleted(processInstance); - - workItem = (InternalKogitoWorkItem) handler.getWorkItem(); - assertThat(workItem).isNotNull(); - - nodeInstanceId = workItem.getNodeInstanceStringId(); - nodeId = workItem.getNodeId(); - - assertThat(nodeId).isNotNull(); - assertThat(nodeInstanceId).isNotNull(); + Application app = ProcessTestHelper.newApplication(); + MessageEndEventProcess definition = (MessageEndEventProcess) MessageEndEventProcess.newProcess(app); + StringBuilder message = new StringBuilder(); + definition.setProducer__2(new MessageProducer() { + + @Override + public void produce(KogitoProcessInstance pi, String eventData) { + message.append(eventData); + } + }); + MessageEndEventModel model = definition.createModel(); + model.setX("MyValue"); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(message.toString()).isEqualTo("MyValue"); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java index 6930c8557b5..98611a1f179 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/ErrorEventTest.java @@ -19,20 +19,33 @@ package org.jbpm.bpmn2; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jbpm.bpmn2.error.EndErrorModel; import org.jbpm.bpmn2.error.EndErrorProcess; +import org.jbpm.bpmn2.error.ErrorBoundaryEventOnServiceTaskModel; +import org.jbpm.bpmn2.error.ErrorBoundaryEventOnServiceTaskProcess; import org.jbpm.bpmn2.error.ErrorVariableModel; import org.jbpm.bpmn2.error.ErrorVariableProcess; -import org.jbpm.bpmn2.handler.ServiceTaskHandler; +import org.jbpm.bpmn2.event.BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRefModel; +import org.jbpm.bpmn2.event.BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRefProcess; +import org.jbpm.bpmn2.event.BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRefModel; +import org.jbpm.bpmn2.event.BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRefProcess; +import org.jbpm.bpmn2.event.BoundaryErrorEventSubProcessExceptionMappingModel; +import org.jbpm.bpmn2.event.BoundaryErrorEventSubProcessExceptionMappingProcess; import org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator; import org.jbpm.bpmn2.objects.ExceptionOnPurposeHandler; +import org.jbpm.bpmn2.objects.ExceptionService; import org.jbpm.bpmn2.objects.MyError; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.service.ExceptionServiceProcessErrorSignallingModel; +import org.jbpm.bpmn2.service.ExceptionServiceProcessErrorSignallingProcess; +import org.jbpm.bpmn2.subprocess.ExceptionServiceProcessSignallingModel; +import org.jbpm.bpmn2.subprocess.ExceptionServiceProcessSignallingProcess; import org.jbpm.process.instance.event.listeners.RuleAwareProcessEventListener; import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler; import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler; @@ -44,6 +57,10 @@ import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.kogito.Application; import org.kie.kogito.handlers.AlwaysThrowingComponent_throwException__8DA0CD88_0714_43C1_B492_A70FADE42361_Handler; +import org.kie.kogito.handlers.ExceptionService_handleException__X_2_Handler; +import org.kie.kogito.handlers.ExceptionService_throwException__2_Handler; +import org.kie.kogito.handlers.ExceptionService_throwException__3_Handler; +import org.kie.kogito.handlers.HelloService_helloException_ServiceTask_2_Handler; import org.kie.kogito.handlers.LoggingComponent_logException__E5B0E78B_0112_42F4_89FF_0DCC4FCB6BCD_Handler; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.event.KogitoProcessEventListener; @@ -220,24 +237,36 @@ public void testErrorBoundaryEventOnTask() throws Exception { @Test public void testErrorBoundaryEventOnServiceTask() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2"); + Application app = ProcessTestHelper.newApplication(); + EventTrackerProcessListener listener = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, listener); TestWorkItemHandler handler = new TestWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", handler); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.HelloService_helloException_ServiceTask_2_Handler", new HelloService_helloException_ServiceTask_2_Handler()); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "test"); - KogitoProcessInstance processInstance = kruntime.startProcess("BPMN2-ErrorBoundaryEventOnServiceTask", params); + org.kie.kogito.process.Process definition = ErrorBoundaryEventOnServiceTaskProcess.newProcess(app); + + ErrorBoundaryEventOnServiceTaskModel model = definition.createModel(); + model.setS("test"); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); List workItems = handler.getWorkItems(); assertThat(workItems).hasSize(1); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItems.get(0).getStringId(), null); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "start", "split", "User Task", "Service task error attached", "end0", - "Script Task", "error2"); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + + assertThat(listener.tracked()) + .anyMatch(ProcessTestHelper.triggered("start")) + .anyMatch(ProcessTestHelper.triggered("split")) + .anyMatch(ProcessTestHelper.triggered("User Task")) + .anyMatch(ProcessTestHelper.triggered("Service task error attached")) + .anyMatch(ProcessTestHelper.triggered("end0")) + .anyMatch(ProcessTestHelper.triggered("Script Task")) + .anyMatch(ProcessTestHelper.triggered("error2")) + .noneMatch(ProcessTestHelper.triggered("end")); - assertNotNodeTriggered(processInstance.getStringId(), "end"); } @Test @@ -310,16 +339,53 @@ public void abortWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager @Test public void testErrorSignallingExceptionServiceTask() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ExceptionServiceProcess-ErrorSignalling.bpmn2"); + String input = "this is my service input"; - StandaloneBPMNProcessTest.runTestErrorSignallingExceptionServiceTask(kruntime); + Application app = ProcessTestHelper.newApplication(); + SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ExceptionService_throwException__3_Handler.class, "Error-code"); + signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName); + Object[] caughtEventObjectHolder = new Object[1]; + caughtEventObjectHolder[0] = null; + ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder); + + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.ExceptionService_throwException__3_Handler", signallingTaskWrapper); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.ExceptionService_handleException__X_2_Handler", new ExceptionService_handleException__X_2_Handler()); + org.kie.kogito.process.Process definition = ExceptionServiceProcessErrorSignallingProcess.newProcess(app); + + ExceptionServiceProcessErrorSignallingModel model = definition.createModel(); + model.setServiceInputItem(input); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ABORTED); + assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof KogitoWorkItem).withFailMessage("Event was not passed to Event Subprocess.").isTrue(); } @Test public void testSignallingExceptionServiceTask() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ExceptionServiceProcess-Signalling.bpmn2"); + String input = "this is my service input"; + + SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ExceptionService_throwException__2_Handler.class, "exception-signal"); + signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName); + Object[] caughtEventObjectHolder = new Object[1]; + caughtEventObjectHolder[0] = null; + ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder); + + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.ExceptionService_throwException__2_Handler", signallingTaskWrapper); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.ExceptionService_handleException__X_2_Handler", new ExceptionService_handleException__X_2_Handler()); + org.kie.kogito.process.Process definition = ExceptionServiceProcessSignallingProcess.newProcess(app); + + ExceptionServiceProcessSignallingModel model = definition.createModel(); + model.setServiceInputItem(input); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof KogitoWorkItem).withFailMessage("Event was not passed to Event Subprocess.").isTrue(); - StandaloneBPMNProcessTest.runTestSignallingExceptionServiceTask(kruntime); } @Test @@ -394,35 +460,56 @@ public void testBoundaryErrorEventDefaultHandlerWithErrorCodeWithoutStructureRef @Test public void testBoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2"); + Application app = ProcessTestHelper.newApplication(); + EventTrackerProcessListener listener = new EventTrackerProcessListener(); ExceptionWorkItemHandler handler = new ExceptionWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); + ProcessTestHelper.registerHandler(app, "Human Task", handler); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process definition = + BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRefProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); - KogitoProcessInstance processInstance = kruntime.startProcess("com.sample.bpmn.hello"); + assertThat(listener.tracked()) + .anyMatch(ProcessTestHelper.triggered("Start")) + .anyMatch(ProcessTestHelper.triggered("User Task")) + .anyMatch(ProcessTestHelper.left("MyBoundaryErrorEvent")); - assertNodeTriggered(processInstance.getStringId(), "Start", "User Task", "MyBoundaryErrorEvent"); } @Test public void testBoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2"); - ExceptionWorkItemHandler handler = new ExceptionWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - KogitoProcessInstance processInstance = kruntime.startProcess("com.sample.bpmn.hello"); + Application app = ProcessTestHelper.newApplication(); + EventTrackerProcessListener listener = new EventTrackerProcessListener(); + ExceptionWorkItemHandler handler = new ExceptionWorkItemHandler(); + ProcessTestHelper.registerHandler(app, "Human Task", handler); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process definition = + BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRefProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); - assertNodeTriggered(processInstance.getStringId(), "Start", "User Task", "MyBoundaryErrorEvent"); + assertThat(listener.tracked()) + .anyMatch(ProcessTestHelper.triggered("Start")) + .anyMatch(ProcessTestHelper.triggered("User Task")) + .anyMatch(ProcessTestHelper.left("MyBoundaryErrorEvent")); } @Test public void testBoundaryErrorEventSubProcessExceptionMapping() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2"); + Application app = ProcessTestHelper.newApplication(); ExceptionWorkItemHandler handler = new ExceptionWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); + ProcessTestHelper.registerHandler(app, "Human Task", handler); + org.kie.kogito.process.Process definition = + BoundaryErrorEventSubProcessExceptionMappingProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); - KogitoProcessInstance processInstance = kruntime.startProcess("com.sample.bpmn.hello"); + assertThat(instance.variables().getVar1()) + .isNotNull() + .isInstanceOf(RuntimeException.class); - assertThat(getProcessVarValue(processInstance, "var1")).isEqualTo("java.lang.RuntimeException"); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/EscalationEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/EscalationEventTest.java index cb5420383c3..f2f8c232be3 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/EscalationEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/EscalationEventTest.java @@ -19,22 +19,40 @@ package org.jbpm.bpmn2; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jbpm.bpmn2.escalation.EscalationBoundaryEventWithTaskModel; +import org.jbpm.bpmn2.escalation.EscalationBoundaryEventWithTaskProcess; +import org.jbpm.bpmn2.escalation.EventSubprocessEscalationModel; +import org.jbpm.bpmn2.escalation.EventSubprocessEscalationProcess; +import org.jbpm.bpmn2.escalation.MultiEscalationModel; +import org.jbpm.bpmn2.escalation.MultiEscalationProcess; +import org.jbpm.bpmn2.escalation.TopLevelEscalationModel; +import org.jbpm.bpmn2.escalation.TopLevelEscalationProcess; import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.test.utils.EventTrackerProcessListener; +import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; +import org.kie.api.event.process.ProcessStartedEvent; +import org.kie.api.event.process.SignalEvent; +import org.kie.api.runtime.process.ProcessInstance; +import org.kie.kogito.Application; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.event.KogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; import org.kie.kogito.internal.process.runtime.KogitoWorkItem; +import org.kie.kogito.process.impl.Sig; import static org.assertj.core.api.Assertions.assertThat; +import static org.jbpm.test.utils.ProcessTestHelper.left; +import static org.jbpm.test.utils.ProcessTestHelper.triggered; public class EscalationEventTest extends JbpmBpmn2TestCase { @@ -62,39 +80,85 @@ public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { }; + @Test + public void testMultiEscalation() throws Exception { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void onSignal(SignalEvent event) { + logger.info("on signal {}", event); + } + }); + org.kie.kogito.process.Process definition = MultiEscalationProcess.newProcess(app); + MultiEscalationModel model = definition.createModel(); + model.setData("data"); + model.setEnddata("end_data"); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ABORTED); + } + + @Test + public void testTopLevelEscalation() throws Exception { + Application app = ProcessTestHelper.newApplication(); + List instances = new ArrayList<>(); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void beforeProcessStarted(ProcessStartedEvent event) { + instances.add(event.getProcessInstance().getId()); + } + }); + org.kie.kogito.process.Process definition = TopLevelEscalationProcess.newProcess(app); + TopLevelEscalationModel model = definition.createModel(); + model.setData("data"); + definition.send(Sig.of("Escalation-START_NEW", "data")); + assertThat(instances).hasSize(1); + } + @Test public void testEventSubprocessEscalation() throws Exception { - kruntime = createKogitoProcessRuntime("escalation/BPMN2-EventSubprocessEscalation.bpmn2"); final List executednodes = new ArrayList<>(); KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() { @Override public void afterNodeLeft(ProcessNodeLeftEvent event) { - if (event.getNodeInstance().getNodeName() - .equals("Script Task 1")) { + if (event.getNodeInstance().getNodeName().equals("Script Task 1")) { executednodes.add(((KogitoNodeInstance) event.getNodeInstance()).getStringId()); } } }; - - kruntime.getProcessEventManager().addEventListener(listener); + EventTrackerProcessListener tracker = new EventTrackerProcessListener(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - KogitoProcessInstance processInstance = kruntime - .startProcess("BPMN2-EventSubprocessEscalation"); - assertProcessInstanceActive(processInstance); - kruntime.getProcessEventManager().addEventListener(listener); + + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerProcessEventListener(app, tracker); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + + org.kie.kogito.process.Process processDefinition = EventSubprocessEscalationProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(processDefinition.createModel()); + instance.start(); + + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE); KogitoWorkItem workItem = workItemHandler.getWorkItem(); assertThat(workItem).isNotNull(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "start", "User Task 1", - "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub"); + + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(executednodes).hasSize(1); + assertThat(tracker.tracked()) + .anyMatch(triggered("start")) + .anyMatch(triggered("User Task 1")) + .anyMatch(triggered("end")) + .anyMatch(left("Sub Process 1")) + .anyMatch(left("start-sub")) + .anyMatch(triggered("Script Task 1")) + .anyMatch(triggered("end-sub")); + } @Test @@ -135,22 +199,22 @@ public void testEscalationIntermediateThrowEventProcess() throws Exception { } @Test - @Disabled("General escalation is not yet supported.") - // TODO: implement general escalation - // TODO: implement asynchronous escalation public void testGeneralEscalationBoundaryEventWithTask() throws Exception { - kruntime = createKogitoProcessRuntime("escalation/BPMN2-EscalationBoundaryEventWithTask.bpmn2"); - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", handler); - Map params = new HashMap<>(); - params.put("x", "0"); - KogitoProcessInstance processInstance = kruntime.startProcess("non-interrupting-escalation", params); - kruntime.getKogitoWorkItemManager().completeWorkItem(handler.getWorkItem().getStringId(), null); - assertProcessInstanceCompleted(processInstance); - // Did escalation fire? - assertProcessVarValue(processInstance, "x", "1"); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", handler); + + org.kie.kogito.process.Process processDefinition = EscalationBoundaryEventWithTaskProcess.newProcess(app); + EscalationBoundaryEventWithTaskModel model = processDefinition.createModel(); + model.setX("0"); + org.kie.kogito.process.ProcessInstance instance = processDefinition.createInstance(model); + instance.start(); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getX()).isEqualTo("1"); + } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java index f5d2dd08227..6cf41494546 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/IntermediateEventTest.java @@ -21,17 +21,49 @@ import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.jbpm.bpmn2.activity.BoundarySignalEventOnTaskWithTransformationModel; import org.jbpm.bpmn2.activity.BoundarySignalEventOnTaskWithTransformationProcess; +import org.jbpm.bpmn2.event.BoundarySignalWithNameEventOnTaskModel; +import org.jbpm.bpmn2.event.BoundarySignalWithNameEventOnTaskProcess; +import org.jbpm.bpmn2.event.BoundaryTimerCycleISOModel; +import org.jbpm.bpmn2.event.BoundaryTimerCycleISOProcess; +import org.jbpm.bpmn2.event.BoundaryTimerCycleISOVariableModel; +import org.jbpm.bpmn2.event.BoundaryTimerCycleISOVariableProcess; import org.jbpm.bpmn2.handler.ReceiveTaskHandler; import org.jbpm.bpmn2.handler.SendTaskHandler; +import org.jbpm.bpmn2.intermediate.EventSubprocessErrorSignalEmbeddedModel; +import org.jbpm.bpmn2.intermediate.EventSubprocessErrorSignalEmbeddedProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageWithTransformationModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventMessageWithTransformationProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignal2Model; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignal2Process; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalWithTransformationModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventSignalWithTransformationProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle3Model; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycle3Process; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerCycleCronProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcess; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcessInstance; +import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalBetweenUserTasksModel; +import org.jbpm.bpmn2.intermediate.IntermediateCatchSignalBetweenUserTasksProcess; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageModel; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageProcess; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageWithTransformationModel; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageWithTransformationProcess; import org.jbpm.bpmn2.intermediate.IntermediateThrowEventSignalModel; import org.jbpm.bpmn2.intermediate.IntermediateThrowEventSignalProcess; import org.jbpm.bpmn2.objects.Person; @@ -43,21 +75,23 @@ import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler; import org.jbpm.test.util.NodeLeftCountDownProcessEventListener; import org.jbpm.test.util.ProcessCompletedCountDownProcessEventListener; +import org.jbpm.test.utils.EventTrackerProcessListener; import org.jbpm.test.utils.ProcessTestHelper; +import org.jbpm.test.utils.ProcessTestHelper.CompletionKogitoEventListener; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.api.command.ExecutableCommand; -import org.kie.api.definition.process.WorkflowElementIdentifier; +import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.runtime.rule.FactHandle; import org.kie.kogito.Application; +import org.kie.kogito.event.impl.MessageProducer; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.event.KogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; -import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime; import org.kie.kogito.internal.process.runtime.KogitoWorkItem; import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler; import org.kie.kogito.internal.process.runtime.KogitoWorkItemManager; @@ -65,7 +99,7 @@ import org.kie.kogito.process.EventDescription; import org.kie.kogito.process.NamedDataType; import org.kie.kogito.process.ProcessInstance; -import org.kie.kogito.process.workitems.InternalKogitoWorkItem; +import org.kie.kogito.process.impl.Sig; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -101,6 +135,34 @@ public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) { * TESTS! */ + @Test + public void testBoundaryTimerCycleISO() { + Application app = ProcessTestHelper.newApplication(); + NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Send Update Timer", 3); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process definition = BoundaryTimerCycleISOProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + listener.waitTillCompleted(); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + } + + @Test + public void testBoundaryTimerCycleISOVariable() { + Application app = ProcessTestHelper.newApplication(); + NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Send Update Timer", 3); + ProcessTestHelper.registerProcessEventListener(app, listener); + org.kie.kogito.process.Process definition = BoundaryTimerCycleISOVariableProcess.newProcess(app); + BoundaryTimerCycleISOVariableModel model = definition.createModel(); + model.setCronStr("R3/PT0.1S"); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + listener.waitTillCompleted(); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + } + @Test public void testSignalBoundaryEvent() throws Exception { kruntime = createKogitoProcessRuntime( @@ -212,15 +274,18 @@ public void testSignalBoundaryEventOnTask() throws Exception { @Test public void testSignalBoundaryEventOnTaskWithSignalName() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BoundarySignalWithNameEventOnTaskbpmn2.bpmn"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - new TestWorkItemHandler()); - kruntime.getProcessEventManager().addEventListener(LOGGING_EVENT_LISTENER); - KogitoProcessInstance processInstance = kruntime - .startProcess("BoundarySignalOnTask"); - kruntime.signalEvent("MySignal", "value"); - assertProcessInstanceFinished(processInstance, kruntime); + Application app = ProcessTestHelper.newApplication(); + + ProcessTestHelper.registerHandler(app, "Human Task", new TestWorkItemHandler()); + ProcessTestHelper.registerProcessEventListener(app, LOGGING_EVENT_LISTENER); + org.kie.kogito.process.Process definition = + BoundarySignalWithNameEventOnTaskProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + + instance.send(Sig.of("MySignal", "value")); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @@ -985,56 +1050,27 @@ public void afterNodeLeft(ProcessNodeLeftEvent event) { @Test public void testMessageIntermediateThrow() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessage.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler()); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess( - "IntermediateThrowEventMessage", params); - assertProcessInstanceCompleted(processInstance); - - } - - @Test - public void testMessageIntermediateThrowVerifyWorkItemData() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessage.bpmn2"); - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", handler); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventMessage", params); - assertProcessInstanceCompleted(processInstance); - - KogitoWorkItem workItem = handler.getWorkItem(); - assertThat(workItem).isNotNull().isInstanceOf(KogitoWorkItem.class); + Application app = ProcessTestHelper.newApplication(); - String nodeInstanceId = ((InternalKogitoWorkItem) workItem).getNodeInstanceStringId(); - WorkflowElementIdentifier nodeId = ((InternalKogitoWorkItem) workItem).getNodeId(); - - assertThat(nodeId).isNotNull(); - assertThat(nodeInstanceId).isNotNull(); - } + ProcessTestHelper.registerHandler(app, "Send Task", new SendTaskHandler()); + IntermediateThrowEventMessageProcess definition = (IntermediateThrowEventMessageProcess) IntermediateThrowEventMessageProcess.newProcess(app); + StringBuilder builder = new StringBuilder(); + definition.setProducer__2(new MessageProducer() { + @Override + public void produce(KogitoProcessInstance pi, String eventData) { + builder.append(eventData); + } + }); + IntermediateThrowEventMessageModel model = definition.createModel(); - @Test - public void testMessageIntermediateThrowVerifyWorkItemDataDeploymentId() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessage.bpmn2"); - TestWorkItemHandler handler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", handler); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventMessage", params); - assertProcessInstanceCompleted(processInstance); + model.setX("MyValue"); - KogitoWorkItem workItem = handler.getWorkItem(); - assertThat(workItem).isNotNull().isInstanceOf(KogitoWorkItem.class); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); - String nodeInstanceId = ((InternalKogitoWorkItem) workItem).getNodeInstanceStringId(); - WorkflowElementIdentifier nodeId = ((InternalKogitoWorkItem) workItem).getNodeId(); - String deploymentId = ((InternalKogitoWorkItem) workItem).getDeploymentId(); + assertThat(builder.toString()).isEqualTo("MyValue"); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); - assertThat(nodeId).isNotNull(); - assertThat(nodeInstanceId).isNotNull(); - assertThat(deploymentId).isNull(); } @Test @@ -1596,12 +1632,6 @@ public void testConditionalBoundaryEventInterrupting() throws Exception { } - @Test - public void testSignallingExceptionServiceTask() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ExceptionServiceProcess-Signalling.bpmn2"); - StandaloneBPMNProcessTest.runTestSignallingExceptionServiceTask(kruntime); - } - @Test public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() throws Exception { kruntime = createKogitoProcessRuntime( @@ -1622,34 +1652,35 @@ public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() throws Exc @Test public void testIntermediateCatchEventSameSignalOnTwokruntimes() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-IntermediateCatchEventSignal.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEventSignal"); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); - KogitoProcessRuntime kruntime2 = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventSignal2.bpmn2"); - kruntime2.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance2 = kruntime2.startProcess("IntermediateCatchEventSignal2"); + org.kie.kogito.process.Process definition1 = IntermediateCatchEventSignalProcess.newProcess(app); + org.kie.kogito.process.Process definition2 = IntermediateCatchEventSignal2Process.newProcess(app); - assertProcessInstanceActive(processInstance); - assertProcessInstanceActive(processInstance2); + org.kie.kogito.process.ProcessInstance instance1 = definition1.createInstance(definition1.createModel()); + org.kie.kogito.process.ProcessInstance instance2 = definition2.createInstance(definition2.createModel()); - // now signal process instance - kruntime.signalEvent("MyMessage", "SomeValue"); - assertProcessInstanceFinished(processInstance, kruntime); - assertProcessInstanceActive(processInstance2); + instance1.start(); + instance2.start(); + assertThat(instance1.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + assertThat(instance2.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + instance1.send(Sig.of("MyMessage", "SomeValue")); + assertThat(instance1.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance2.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - // now signal the other one - kruntime2.signalEvent("MyMessage", "SomeValue"); - assertProcessInstanceFinished(processInstance2, kruntime2); + instance2.send(Sig.of("MyMessage", "SomeValue")); + assertThat(instance1.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance2.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); - kruntime2.getKieSession().dispose(); // kruntime's session is disposed in the @AfterEach method } @Test + @Disabled public void testIntermediateCatchEventNoIncommingConnection() throws Exception { try { kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventNoIncommingConnection.bpmn2"); - } catch (RuntimeException e) { assertThat(e.getMessage()).isNotNull(); assertThat(e.getMessage()).contains("has no incoming connection"); @@ -1818,62 +1849,127 @@ public void testSignalBoundaryEventWithTransformation() throws Exception { } @Test - @Disabled("Transfomer has been disabled") + public void testMessageIntermediateThrowWithTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2"); - final StringBuffer messageContent = new StringBuffer(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", - new SendTaskHandler() { - - @Override - public void executeWorkItem(KogitoWorkItem workItem, KogitoWorkItemManager manager) { - // collect message content for verification - messageContent.append(workItem.getParameter("Message")); - super.executeWorkItem(workItem, manager); - } - - }); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess( - "MessageIntermediateEvent", params); - assertProcessInstanceCompleted(processInstance); + StringBuilder messageContent = new StringBuilder(); + Application application = ProcessTestHelper.newApplication(); + IntermediateThrowEventMessageWithTransformationProcess definition = + (IntermediateThrowEventMessageWithTransformationProcess) IntermediateThrowEventMessageWithTransformationProcess.newProcess(application); + definition.setProducer__2(new MessageProducer() { + @Override + public void produce(KogitoProcessInstance pi, String eventData) { + messageContent.append(eventData); + } + }); + IntermediateThrowEventMessageWithTransformationModel model = definition.createModel(); + model.setX("MyValue"); + ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED); assertThat(messageContent).hasToString("MYVALUE"); } @Test - @Disabled("Transfomer has been disabled") public void testIntermediateCatchEventSignalWithTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventSignalWithTransformation.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEvent"); - assertProcessInstanceActive(processInstance); + Application app = ProcessTestHelper.newApplication(); + EventTrackerProcessListener listener = new EventTrackerProcessListener(); + ProcessTestHelper.registerProcessEventListener(app, listener); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + org.kie.kogito.process.Process definition = IntermediateCatchEventSignalWithTransformationProcess.newProcess(app); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("MyMessage", "SomeValue")); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getX()).isNotNull().isEqualTo("SOMEVALUE"); + assertThat(listener.tracked()) + .anyMatch(ProcessTestHelper.triggered("StartProcess")) + .anyMatch(ProcessTestHelper.triggered("UserTask")) + .anyMatch(ProcessTestHelper.triggered("EndProcess")) + .anyMatch(ProcessTestHelper.triggered("event")); + + } + + @Test + public void testIntermediateCatchEventTimerCycle3() throws Exception { + Application app = ProcessTestHelper.newApplication(); + + final CountDownLatch latch = new CountDownLatch(3); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void afterProcessCompleted(ProcessCompletedEvent event) { + latch.countDown(); + } + }); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycle3Process.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + latch.await(5, TimeUnit.SECONDS); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.abort(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ABORTED); + } + + @Test + public void testIntermediateCatchEventTimerCycleCron() throws Exception { + Application app = ProcessTestHelper.newApplication(); + + final CountDownLatch latch = new CountDownLatch(3); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { + @Override + public void afterProcessCompleted(ProcessCompletedEvent event) { + latch.countDown(); + } + }); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerCycleCronProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + latch.await(5, TimeUnit.SECONDS); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + } + + @Test + public void testIntermediateCatchSignalBetweenUserTasksModel() throws Exception { + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + org.kie.kogito.process.Process definition = IntermediateCatchSignalBetweenUserTasksProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("MySignal", null)); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + } + + @Test + public void testIntermediateCatchEventTimerDurationWithError() throws Exception { + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process definition = IntermediateCatchEventTimerDurationWithErrorProcess.newProcess(app); + IntermediateCatchEventTimerDurationWithErrorProcessInstance instance = (IntermediateCatchEventTimerDurationWithErrorProcessInstance) definition.createInstance(definition.createModel()); + instance.start(); + CompletionKogitoEventListener listener = ProcessTestHelper.registerCompletionEventListener(instance); + listener.await(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getTestOK()).isEqualTo(Boolean.TRUE); - // now signal process instance - kruntime.signalEvent("MyMessage", "SomeValue", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - assertNodeTriggered(processInstance.getStringId(), "StartProcess", "UserTask", "EndProcess", "event"); - String var = getProcessVarValue(processInstance, "x"); - assertThat(var).isNotNull().isEqualTo("SOMEVALUE"); } @Test - @Disabled("Transfomer has been disabled") public void testIntermediateCatchEventMessageWithTransformation() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventMessageWithTransformation.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - new SystemOutWorkItemHandler()); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEvent"); - assertProcessInstanceActive(processInstance); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Human Task", new SystemOutWorkItemHandler()); + org.kie.kogito.process.Process definition = IntermediateCatchEventMessageWithTransformationProcess.newProcess(app); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + instance.send(Sig.of("Message-HelloMessage", "SomeValue")); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getX()).isNotNull().isEqualTo("SOMEVALUE"); - // now signal process instance - kruntime.signalEvent("Message-HelloMessage", "SomeValue", processInstance.getStringId()); - assertProcessInstanceFinished(processInstance, kruntime); - String var = getProcessVarValue(processInstance, "x"); - assertThat(var).isNotNull().isEqualTo("SOMEVALUE"); } @Test @@ -2283,20 +2379,17 @@ public void testEventBasedSplitWithCronTimerAndSignal() throws Exception { @Test public void testEventSubprocessWithEmbeddedSignals() throws Exception { - kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/intermediate/BPMN2-EventSubprocessErrorSignalEmbedded.bpmn2"); - KogitoProcessInstance processInstance = kruntime.startProcess("EventSubprocessErrorSignalEmbedded"); - - assertProcessInstanceActive(processInstance.getStringId(), kruntime); - assertProcessInstanceActive(processInstance); - kruntime.signalEvent("signal1", null, processInstance.getStringId()); - assertProcessInstanceActive(processInstance.getStringId(), kruntime); - - kruntime.signalEvent("signal2", null, processInstance.getStringId()); - assertProcessInstanceActive(processInstance.getStringId(), kruntime); - - kruntime.signalEvent("signal3", null, processInstance.getStringId()); - - assertProcessInstanceFinished(processInstance, kruntime); + Application app = ProcessTestHelper.newApplication(); + + org.kie.kogito.process.Process definition = EventSubprocessErrorSignalEmbeddedProcess.newProcess(app); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + instance.send(Sig.of("signal1", null)); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("signal2", null)); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + instance.send(Sig.of("signal3", null)); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ABORTED); } @Test diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java index d83fe47a3a9..640515b1e1d 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StandaloneBPMNProcessTest.java @@ -24,17 +24,24 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.parsers.DocumentBuilderFactory; +import org.jbpm.bpmn2.adhoc.AdHocSubProcessAutoCompleteExpressionModel; +import org.jbpm.bpmn2.adhoc.AdHocSubProcessAutoCompleteExpressionProcess; +import org.jbpm.bpmn2.adhoc.AdHocSubProcessAutoCompleteModel; +import org.jbpm.bpmn2.adhoc.AdHocSubProcessAutoCompleteProcess; +import org.jbpm.bpmn2.adhoc.AdHocSubProcessEmptyCompleteExpressionProcess; +import org.jbpm.bpmn2.adhoc.AdHocTerminateEndEventModel; +import org.jbpm.bpmn2.adhoc.AdHocTerminateEndEventProcess; import org.jbpm.bpmn2.handler.ReceiveTaskHandler; import org.jbpm.bpmn2.handler.SendTaskHandler; -import org.jbpm.bpmn2.handler.ServiceTaskHandler; -import org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator; -import org.jbpm.bpmn2.objects.ExceptionService; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageModel; +import org.jbpm.bpmn2.intermediate.IntermediateThrowEventMessageProcess; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; import org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler; @@ -42,20 +49,23 @@ import org.jbpm.process.instance.impl.humantask.InternalHumanTaskWorkItem; import org.jbpm.test.util.NodeLeftCountDownProcessEventListener; import org.jbpm.test.util.ProcessCompletedCountDownProcessEventListener; +import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.io.Resource; import org.kie.internal.io.ResourceFactory; +import org.kie.kogito.Application; +import org.kie.kogito.event.impl.MessageProducer; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; -import org.kie.kogito.internal.process.runtime.KogitoProcessRuntime; import org.kie.kogito.internal.process.runtime.KogitoWorkItem; import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance; import org.w3c.dom.Document; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class StandaloneBPMNProcessTest extends JbpmBpmn2TestCase { @@ -506,24 +516,70 @@ public void testAdHocSubProcess() throws Exception { } @Test - @Disabled("Process does not complete.") public void testAdHocSubProcessAutoComplete() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-AdHocSubProcessAutoComplete.bpmn2"); + // this autocomplete when we detect + // getActivityInstanceAttribute("numberOfActiveInstances") == 0 + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process definition = AdHocSubProcessAutoCompleteProcess.newProcess(app); - TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("AdHocSubProcess"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - KogitoWorkItem workItem = workItemHandler.getWorkItem(); - assertThat(workItem).isNull(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - kruntime.getKieSession().fireAllRules(); - workItem = workItemHandler.getWorkItem(); - assertThat(workItem).withFailMessage("KogitoWorkItem should not be null.").isNotNull(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); + // adhoc we need to trigger the human task + instance.triggerNode("_2-1"); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); + } + + @Test + public void testAdHocSubProcessAutoCompleteExpression() throws Exception { + // this autocomplete when we detect + // getActivityInstanceAttribute("numberOfActiveInstances") == 0 + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process definition = AdHocSubProcessAutoCompleteExpressionProcess.newProcess(app); + AdHocSubProcessAutoCompleteExpressionModel model = definition.createModel(); + model.setCounter(3); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + + // adhoc we need to trigger the human task + instance.triggerNode("_2-1"); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.singletonMap("testHT", 0)); + + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); + } + + @Test + public void testAdHocTerminateEndEvent() throws Exception { + // this autocomplete when we detect + // terminate end event within adhoc process the adhoc should finish + Application app = ProcessTestHelper.newApplication(); + org.kie.kogito.process.Process definition = AdHocTerminateEndEventProcess.newProcess(app); + AdHocTerminateEndEventModel model = definition.createModel(); + model.setComplete(false); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + + // adhoc we need to trigger the human task + instance.triggerNode("_560E157E-3173-4CFD-9CC6-26676D8B0A02"); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.emptyMap()); + + assertThat(instance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); + } + + @Test + public void testAdHocSubProcessEmptyCompleteExpression() throws Exception { + try { + Application app = ProcessTestHelper.newApplication(); + AdHocSubProcessEmptyCompleteExpressionProcess.newProcess(app); + fail("Process should be invalid, there should be build errors"); + } catch (RuntimeException e) { + // there should be build errors + } } @Test @@ -591,18 +647,6 @@ public void testErrorEndEventProcess() throws Exception { assertProcessInstanceAborted(processInstance.getStringId(), kruntime); } - @Test - public void testServiceTask() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ServiceProcess.bpmn2"); - - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler()); - Map params = new HashMap<>(); - params.put("s", "john"); - KogitoWorkflowProcessInstance processInstance = (KogitoWorkflowProcessInstance) kruntime.startProcess("ServiceProcess", params); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); - assertThat(processInstance.getVariable("s")).isEqualTo("Hello john!"); - } - @Test public void testSendTask() throws Exception { kruntime = createKogitoProcessRuntime("org/jbpm/bpmn2/task/BPMN2-SendTask.bpmn2"); @@ -696,24 +740,25 @@ public void afterProcessStarted(ProcessStartedEvent event) { assertThat(list).hasSize(1); } - @Test - public void testMessageEnd() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-MessageEndEvent.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler()); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess("MessageEndEvent", params); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); - } - @Test public void testMessageIntermediateThrow() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntermediateThrowEventMessage.bpmn2"); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler()); - Map params = new HashMap<>(); - params.put("x", "MyValue"); - KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateThrowEventMessage", params); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); + Application app = ProcessTestHelper.newApplication(); + ProcessTestHelper.registerHandler(app, "Send Task", new SendTaskHandler()); + IntermediateThrowEventMessageProcess definition = (IntermediateThrowEventMessageProcess) IntermediateThrowEventMessageProcess.newProcess(app); + StringBuilder builder = new StringBuilder(); + definition.setProducer__2(new MessageProducer() { + @Override + public void produce(KogitoProcessInstance pi, String eventData) { + builder.append(eventData); + } + }); + IntermediateThrowEventMessageModel model = definition.createModel(); + model.setX("MyValue"); + + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(builder.toString()).isEqualTo("MyValue"); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test @@ -732,60 +777,6 @@ public void testNoneIntermediateThrow() throws Exception { assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED); } - @Test - public void testErrorSignallingExceptionServiceTask() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ExceptionServiceProcess-ErrorSignalling.bpmn2"); - - runTestErrorSignallingExceptionServiceTask(kruntime); - } - - public static void runTestErrorSignallingExceptionServiceTask(KogitoProcessRuntime kruntime) throws Exception { - - // Setup - String eventType = "Error-code"; - SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType); - signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper); - - Object[] caughtEventObjectHolder = new Object[1]; - caughtEventObjectHolder[0] = null; - ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder); - - TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); - // Start process - Map params = new HashMap<>(); - String input = "this is my service input"; - params.put("serviceInputItem", input); - KogitoProcessInstance processInstance = kruntime.startProcess("ServiceProcess", params); - - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - - KogitoWorkItem workItem = workItemHandler.getWorkItem(); - assertThat(workItem).isNotNull(); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - // Check that event was passed to Event SubProcess (and grabbed by WorkItemHandler); - assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof KogitoWorkItem).withFailMessage("Event was not passed to Event Subprocess.").isTrue(); - workItem = (KogitoWorkItem) caughtEventObjectHolder[0]; - Object throwObj = workItem.getParameter(ExceptionService.exceptionParameterName); - assertThat(throwObj).withFailMessage("KogitoWorkItem doesn't contain Throwable.").isInstanceOf(Throwable.class); - assertThat(((Throwable) throwObj).getMessage()).withFailMessage("Exception message does not match service input.").endsWith(input); - - // Complete process - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - assertThat(processInstance == null || processInstance.getState() == KogitoProcessInstance.STATE_ABORTED).withFailMessage("Process instance has not been aborted.").isTrue(); - - } - - @Test - public void testSignallingExceptionServiceTask() throws Exception { - // dump/reread functionality seems to work for this test - // .. but I'm pretty sure that's more coincidence than design (mriet, 2013-03-06) - kruntime = createKogitoProcessRuntime("BPMN2-ExceptionServiceProcess-Signalling.bpmn2"); - - runTestSignallingExceptionServiceTask(kruntime); - } - @Test public void testXXEProcessVulnerability() throws Exception { Resource processResource = ResourceFactory.newClassPathResource("xxe-protection/BPMN2-XXE-Process.bpmn2"); @@ -837,38 +828,4 @@ public void testVariableRefInIntermediateThrowEvent() throws Exception { assertThat(processInstance).isNotNull(); } - public static void runTestSignallingExceptionServiceTask(KogitoProcessRuntime kruntime) throws Exception { - - // Setup - String eventType = "exception-signal"; - SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType); - signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper); - - Object[] caughtEventObjectHolder = new Object[1]; - caughtEventObjectHolder[0] = null; - ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder); - - // Start process - Map params = new HashMap<>(); - String input = "this is my service input"; - params.put("serviceInputItem", input); - KogitoProcessInstance processInstance = kruntime.startProcess("ServiceProcess", params); - - // Check that event was passed to Event SubProcess (and grabbed by WorkItemHandler); - assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof KogitoWorkItem).withFailMessage("Event was not passed to Event Subprocess.").isTrue(); - KogitoWorkItem workItem = (KogitoWorkItem) caughtEventObjectHolder[0]; - Object throwObj = workItem.getParameter(ExceptionService.exceptionParameterName); - assertThat(throwObj).withFailMessage("KogitoWorkItem doesn't contain Throwable.").isInstanceOf(Throwable.class); - assertThat(((Throwable) throwObj).getMessage()).withFailMessage("Exception message does not match service input.").endsWith(input); - - // Complete process - assertThat(processInstance.getState()).withFailMessage("Process instance is not active.").isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null); - processInstance = kruntime.getProcessInstance(processInstance.getStringId()); - if (processInstance != null) { - assertThat(processInstance.getState()).withFailMessage("Process instance is not completed.").isEqualTo(KogitoProcessInstance.STATE_COMPLETED); - } // otherwise, persistence use => processInstance == null => process is completed - } - } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StartEventTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StartEventTest.java index 3785a11a6d0..b85d0b41ef5 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StartEventTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/StartEventTest.java @@ -23,6 +23,7 @@ import java.nio.file.Paths; import java.time.OffsetDateTime; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -31,17 +32,23 @@ import org.jbpm.bpmn2.objects.NotAvailableGoodsReport; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; +import org.jbpm.bpmn2.start.SignalStartWithTransformationModel; +import org.jbpm.bpmn2.start.SignalStartWithTransformationProcess; import org.jbpm.test.util.NodeLeftCountDownProcessEventListener; +import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieRepository; import org.kie.api.event.process.ProcessStartedEvent; import org.kie.api.io.Resource; import org.kie.api.runtime.KieContainer; +import org.kie.api.runtime.process.ProcessInstance; import org.kie.internal.io.ResourceFactory; +import org.kie.kogito.Application; import org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; import org.kie.kogito.internal.process.runtime.KogitoWorkItem; +import org.kie.kogito.process.impl.Sig; import org.kie.kogito.process.workitems.InternalKogitoWorkItem; import static org.assertj.core.api.Assertions.assertThat; @@ -474,22 +481,24 @@ public void testTimerCycle() throws Exception { @Test public void testSignalStartWithTransformation() throws Exception { + Application app = ProcessTestHelper.newApplication(); NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1); - kruntime = createKogitoProcessRuntime("BPMN2-SignalStartWithTransformation.bpmn2"); - kruntime.getProcessEventManager().addEventListener(countDownListener); - final List list = new ArrayList<>(); - kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() { + + ProcessTestHelper.registerProcessEventListener(app, countDownListener); + final List list = new ArrayList<>(); + ProcessTestHelper.registerProcessEventListener(app, new DefaultKogitoProcessEventListener() { @Override public void beforeProcessStarted(ProcessStartedEvent event) { - list.add((KogitoProcessInstance) event.getProcessInstance()); + list.add(event.getProcessInstance()); } }); - kruntime.signalEvent("MySignal", "NewValue"); + org.kie.kogito.process.Process definition = SignalStartWithTransformationProcess.newProcess(app); + + definition.send(Sig.of("MySignal", "NewValue")); + countDownListener.waitTillCompleted(); - assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1); - assertThat(list).isNotNull().hasSize(1); - String var = getProcessVarValue(list.get(0), "x"); - assertThat(var).isEqualTo("NEWVALUE"); + assertThat(list).extracting(e -> e.getProcessId()).containsExactly("SignalStartWithTransformation"); + assertThat(list).extracting(e -> ((KogitoProcessInstance) e).getVariables()).containsExactly(Collections.singletonMap("x", "NEWVALUE")); } /** diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/handler/LoggingTaskHandlerWrapperTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/handler/LoggingTaskHandlerWrapperTest.java index d830287b1b9..9668f485b03 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/handler/LoggingTaskHandlerWrapperTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/handler/LoggingTaskHandlerWrapperTest.java @@ -19,31 +19,47 @@ package org.jbpm.bpmn2.handler; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import org.jbpm.bpmn2.JbpmBpmn2TestCase; import org.jbpm.bpmn2.handler.LoggingTaskHandlerDecorator.InputParameter; +import org.jbpm.bpmn2.subprocess.ExceptionThrowingServiceProcessModel; +import org.jbpm.bpmn2.subprocess.ExceptionThrowingServiceProcessProcess; +import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Test; +import org.kie.kogito.Application; +import org.kie.kogito.handlers.ExceptionService_throwException__2_Handler; +import org.slf4j.LoggerFactory; + +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; import static org.assertj.core.api.Assertions.assertThat; -public class LoggingTaskHandlerWrapperTest extends JbpmBpmn2TestCase { +public class LoggingTaskHandlerWrapperTest { @Test public void testLimitExceptionInfoList() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ExceptionThrowingServiceProcess.bpmn2"); + Application app = ProcessTestHelper.newApplication(); - LoggingTaskHandlerDecorator loggingTaskHandlerWrapper = new LoggingTaskHandlerDecorator(ServiceTaskHandler.class, 2); - loggingTaskHandlerWrapper.setPrintStackTrace(false); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", loggingTaskHandlerWrapper); + LoggingTaskHandlerDecorator loggingTaskHandlerWrapper = new LoggingTaskHandlerDecorator(ExceptionService_throwException__2_Handler.class, 2); + + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.ExceptionService_throwException__2_Handler", loggingTaskHandlerWrapper); + + org.kie.kogito.process.Process definition = ExceptionThrowingServiceProcessProcess.newProcess(app); + ExceptionThrowingServiceProcessModel model = definition.createModel(); + model.setServiceInputItem("exception message"); + org.kie.kogito.process.ProcessInstance instance1 = definition.createInstance(model); + instance1.start(); + assertThat(instance1.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - Map params = new HashMap<>(); - params.put("serviceInputItem", "exception message"); - kruntime.startProcess("ServiceProcess", params); - kruntime.startProcess("ServiceProcess", params); - kruntime.startProcess("ServiceProcess", params); + org.kie.kogito.process.ProcessInstance instance2 = definition.createInstance(model); + instance2.start(); + assertThat(instance2.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + org.kie.kogito.process.ProcessInstance instance3 = definition.createInstance(model); + instance3.start(); + assertThat(instance3.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); int size = loggingTaskHandlerWrapper.getWorkItemExceptionInfoList().size(); assertThat(size).as("WorkItemExceptionInfoList is too large: " + size).isEqualTo(2); @@ -51,26 +67,41 @@ public void testLimitExceptionInfoList() throws Exception { @Test public void testFormatLoggingError() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-ExceptionThrowingServiceProcess.bpmn2"); + ListAppender logAppender = new ListAppender<>(); + LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); + logAppender.setContext(loggerContext); + ch.qos.logback.classic.Logger decoratorLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(LoggingTaskHandlerDecorator.class); + decoratorLogger.addAppender(logAppender); + + logAppender.start(); + + Application app = ProcessTestHelper.newApplication(); - LoggingTaskHandlerDecorator loggingTaskHandlerWrapper = new LoggingTaskHandlerDecorator(ServiceTaskHandler.class, 2); + LoggingTaskHandlerDecorator loggingTaskHandlerWrapper = new LoggingTaskHandlerDecorator(ExceptionService_throwException__2_Handler.class, 2); + LoggingTaskHandlerDecorator.setLogger(decoratorLogger); loggingTaskHandlerWrapper.setLoggedMessageFormat("{0} - {1} - {2} - {3}"); List inputParameters = new ArrayList(); inputParameters.add(InputParameter.EXCEPTION_CLASS); inputParameters.add(InputParameter.WORK_ITEM_ID); inputParameters.add(InputParameter.WORK_ITEM_NAME); inputParameters.add(InputParameter.PROCESS_INSTANCE_ID); - loggingTaskHandlerWrapper.setLoggedMessageInput(inputParameters); - loggingTaskHandlerWrapper.setPrintStackTrace(false); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Service Task", loggingTaskHandlerWrapper); - Map params = new HashMap<>(); - params.put("serviceInputItem", "exception message"); - kruntime.startProcess("ServiceProcess", params); - kruntime.startProcess("ServiceProcess", params); - kruntime.startProcess("ServiceProcess", params); + ProcessTestHelper.registerHandler(app, "org.jbpm.bpmn2.objects.ExceptionService_throwException__2_Handler", loggingTaskHandlerWrapper); + + org.kie.kogito.process.Process definition = ExceptionThrowingServiceProcessProcess.newProcess(app); + ExceptionThrowingServiceProcessModel model = definition.createModel(); + model.setServiceInputItem("exception message"); + org.kie.kogito.process.ProcessInstance instance1 = definition.createInstance(model); + instance1.start(); + assertThat(instance1.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + String wid = loggingTaskHandlerWrapper.getWorkItemExceptionInfoList().get(0).getWorkItemId(); + assertThat(logAppender.list.get(0).getFormattedMessage()).isEqualTo("RuntimeException - " + wid + " - org.jbpm.bpmn2.objects.ExceptionService_throwException__2_Handler - " + instance1.id()); + + decoratorLogger.detachAppender(logAppender); + } } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/structureref/StructureRefTest.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/structureref/StructureRefTest.java index 45f04b90d8f..8042b5f97a3 100755 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/structureref/StructureRefTest.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/structureref/StructureRefTest.java @@ -19,16 +19,29 @@ package org.jbpm.bpmn2.structureref; import java.io.StringReader; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.jbpm.bpmn2.JbpmBpmn2TestCase; +import org.jbpm.bpmn2.flow.BooleanStructureRefModel; +import org.jbpm.bpmn2.flow.BooleanStructureRefProcess; +import org.jbpm.bpmn2.flow.DefaultObjectStructureRefModel; +import org.jbpm.bpmn2.flow.DefaultObjectStructureRefProcess; +import org.jbpm.bpmn2.flow.FloatStructureRefModel; +import org.jbpm.bpmn2.flow.FloatStructureRefProcess; +import org.jbpm.bpmn2.flow.IntegerStructureRefModel; +import org.jbpm.bpmn2.flow.IntegerStructureRefProcess; +import org.jbpm.bpmn2.flow.ObjectStructureRefModel; +import org.jbpm.bpmn2.flow.ObjectStructureRefProcess; import org.jbpm.bpmn2.objects.Person; import org.jbpm.bpmn2.objects.TestWorkItemHandler; -import org.jbpm.process.core.context.variable.VariableScope; import org.jbpm.process.core.datatype.impl.coverter.TypeConverterRegistry; +import org.jbpm.test.utils.ProcessTestHelper; import org.junit.jupiter.api.Test; +import org.kie.kogito.Application; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; +import org.kie.kogito.process.bpmn2.BpmnVariables; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBException; @@ -59,62 +72,67 @@ public void testStringStructureRef() throws Exception { @Test public void testBooleanStructureRef() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BooleanStructureRef.bpmn2"); + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("StructureRef"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process definition = BooleanStructureRefProcess.newProcess(app); - Map res = new HashMap<>(); - res.put("testHT", "true"); - kruntime.getKogitoWorkItemManager().completeWorkItem( - workItemHandler.getWorkItem().getStringId(), res); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(definition.createModel()); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.singletonMap("testHT", "true")); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); } @Test public void testIntegerStructureRef() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntegerStructureRef.bpmn2"); + String value = "25"; + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("StructureRef"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + IntegerStructureRefProcess definition = (IntegerStructureRefProcess) IntegerStructureRefProcess.newProcess(app); - Map res = new HashMap<>(); - res.put("testHT", "25"); - kruntime.getKogitoWorkItemManager().completeWorkItem( - workItemHandler.getWorkItem().getStringId(), res); + IntegerStructureRefModel model = definition.createModel(); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + ProcessTestHelper.completeWorkItem(instance, "john", Collections.singletonMap("testHT", value)); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getTest()).isEqualTo(Integer.valueOf(value)); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); } @Test public void testFloatStructureRef() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-FloatStructureRef.bpmn2"); + String value = "5.5"; + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("StructureRef"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + FloatStructureRefProcess definition = (FloatStructureRefProcess) FloatStructureRefProcess.newProcess(app); - Map res = new HashMap<>(); - res.put("testHT", "5.5"); - kruntime.getKogitoWorkItemManager().completeWorkItem( - workItemHandler.getWorkItem().getStringId(), res); + FloatStructureRefModel model = definition.createModel(); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + ProcessTestHelper.completeWorkItem(instance, "john", Collections.singletonMap("testHT", value)); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getTest()).isEqualTo(Float.valueOf(value)); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); } @Test public void testObjectStructureRef() throws Exception { JAXBContext context = JAXBContext.newInstance(Person.class); - String personAsXml = "1john"; + TypeConverterRegistry.get().register("org.jbpm.bpmn2.objects.Person", (s) -> { try { return context.createUnmarshaller().unmarshal(new StringReader(s)); @@ -122,86 +140,89 @@ public void testObjectStructureRef() throws Exception { throw new RuntimeException(e); } }); - kruntime = createKogitoProcessRuntime("BPMN2-ObjectStructureRef.bpmn2"); + String value = "1john"; + + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("StructureRef"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + ObjectStructureRefProcess definition = (ObjectStructureRefProcess) ObjectStructureRefProcess.newProcess(app); - Map res = new HashMap<>(); - res.put("testHT", personAsXml); - kruntime.getKogitoWorkItemManager().completeWorkItem( - workItemHandler.getWorkItem().getStringId(), res); + ObjectStructureRefModel model = definition.createModel(); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + ProcessTestHelper.completeWorkItem(instance, "john", Collections.singletonMap("testHT", value)); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getTest()).isEqualTo(new Person(1, "john")); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); } @Test public void testDefaultObjectStructureRef() throws Exception { - String value = "simple text for testing"; - kruntime = createKogitoProcessRuntime("BPMN2-DefaultObjectStructureRef.bpmn2"); - + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - KogitoProcessInstance processInstance = kruntime.startProcess("StructureRef"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + DefaultObjectStructureRefProcess definition = (DefaultObjectStructureRefProcess) DefaultObjectStructureRefProcess.newProcess(app); - Map res = new HashMap<>(); - res.put("testHT", value); - kruntime.getKogitoWorkItemManager().completeWorkItem( - workItemHandler.getWorkItem().getStringId(), res); + DefaultObjectStructureRefModel model = definition.createModel(); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + + ProcessTestHelper.completeWorkItem(instance, "john", Collections.singletonMap("testHT", value)); + + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_COMPLETED); + assertThat(instance.variables().getTest()).isEqualTo(value); - assertProcessInstanceCompleted(processInstance.getStringId(), kruntime); } @Test public void testNotExistingVarBooleanStructureRefOnStart() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BooleanStructureRef.bpmn2"); + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - - Map params = new HashMap<>(); - params.put("not existing", "invalid boolean"); - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> kruntime.startProcess("StructureRef", params)); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process definition = BooleanStructureRefProcess.newProcess(app); + org.kie.kogito.Model model = BpmnVariables.create(Collections.singletonMap("not existing", "invalid boolean")); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + assertThat(instance.variables().toMap()).doesNotContainKey("non existing"); } @Test public void testInvalidBooleanStructureRefOnStart() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BooleanStructureRef.bpmn2"); + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process definition = BooleanStructureRefProcess.newProcess(app); + org.kie.kogito.Model model = BpmnVariables.create(Collections.singletonMap("test", "invalid boolean")); - Map params = new HashMap<>(); - params.put("test", "invalid boolean"); - assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> kruntime.startProcess("StructureRef", params)); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + }); } @Test public void testInvalidBooleanStructureRefOnWIComplete() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntegerStructureRef.bpmn2"); + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + IntegerStructureRefProcess definition = (IntegerStructureRefProcess) IntegerStructureRefProcess.newProcess(app); - KogitoProcessInstance processInstance = kruntime.startProcess("StructureRef"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - - Map res = new HashMap<>(); - res.put("testHT", true); + IntegerStructureRefModel model = definition.createModel(); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); try { - kruntime.getKogitoWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getStringId(), res); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.singletonMap("testHT", true)); fail(""); } catch (IllegalArgumentException iae) { logger.info("Expected IllegalArgumentException caught: " + iae); @@ -209,67 +230,48 @@ public void testInvalidBooleanStructureRefOnWIComplete() throws Exception { fail(""); } + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); } @Test public void testInvalidBooleanStructureRefOnStartVerifyErrorMsg() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-BooleanStructureRef.bpmn2"); + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + org.kie.kogito.process.Process definition = BooleanStructureRefProcess.newProcess(app); + org.kie.kogito.Model model = BpmnVariables.create(Collections.singletonMap("test", "invalid boolean")); + try { - Map params = new HashMap<>(); - params.put("test", "invalid boolean"); - kruntime.startProcess("StructureRef", params); + definition.createInstance(model); } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isEqualTo("Variable 'test' has incorrect data type expected:java.lang.Boolean actual:java.lang.String"); + assertThat(e.getMessage()).isEqualTo("Can not set java.lang.Boolean field org.jbpm.bpmn2.flow.BooleanStructureRefModel.test to java.lang.String"); } } - @Test - public void testInvalidBooleanStructureRefOnStartWithDisabledCheck() throws Exception { - // Temporarily disable check for variables strict that is enabled by default for tests - VariableScope.setVariableStrictOption(false); - kruntime = createKogitoProcessRuntime("BPMN2-BooleanStructureRef.bpmn2"); - - TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - - Map params = new HashMap<>(); - params.put("test", "invalid boolean"); - kruntime.startProcess("StructureRef", params); - // enable it back for other tests - VariableScope.setVariableStrictOption(true); - } - @Test public void testNotExistingBooleanStructureRefOnWIComplete() throws Exception { - kruntime = createKogitoProcessRuntime("BPMN2-IntegerStructureRef.bpmn2"); + String wrongDataOutput = "not existing"; + Application app = ProcessTestHelper.newApplication(); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); - kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", - workItemHandler); - - KogitoProcessInstance processInstance = kruntime.startProcess("StructureRef"); - assertThat(processInstance.getState()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE); - - String wrongDataOutput = "not existing"; + ProcessTestHelper.registerHandler(app, "Human Task", workItemHandler); + IntegerStructureRefProcess definition = (IntegerStructureRefProcess) IntegerStructureRefProcess.newProcess(app); - Map res = new HashMap<>(); - res.put(wrongDataOutput, true); + IntegerStructureRefModel model = definition.createModel(); + org.kie.kogito.process.ProcessInstance instance = definition.createInstance(model); + instance.start(); + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); try { - kruntime.getKogitoWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getStringId(), res); - fail(""); - } catch (IllegalArgumentException iae) { - System.out.println("Expected IllegalArgumentException catched: " + iae); - assertThat(iae.getMessage()).isEqualTo("Data output '" + wrongDataOutput + "' is not defined in process 'StructureRef' for task 'User Task'"); - } catch (Exception e) { - fail(""); + ProcessTestHelper.completeWorkItem(instance, "john", Collections.singletonMap(wrongDataOutput, true)); + fail("it should not work!"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage()).isEqualTo("Data output '" + wrongDataOutput + "' is not defined in process 'IntegerStructureRef' for task 'User Task'"); } + assertThat(instance.status()).isEqualTo(org.kie.kogito.process.ProcessInstance.STATE_ACTIVE); + } } diff --git a/jbpm/jbpm-tests/src/test/java/org/jbpm/test/utils/ProcessTestHelper.java b/jbpm/jbpm-tests/src/test/java/org/jbpm/test/utils/ProcessTestHelper.java index 6c1d8ac54a0..3db866f82bd 100644 --- a/jbpm/jbpm-tests/src/test/java/org/jbpm/test/utils/ProcessTestHelper.java +++ b/jbpm/jbpm-tests/src/test/java/org/jbpm/test/utils/ProcessTestHelper.java @@ -20,16 +20,20 @@ import java.util.List; import java.util.Map; +import java.util.concurrent.CountDownLatch; import java.util.function.Consumer; import java.util.function.Predicate; +import org.jbpm.bpmn2.intermediate.IntermediateCatchEventTimerDurationWithErrorProcessInstance; import org.kie.api.event.process.ProcessNodeEvent; +import org.kie.api.event.process.ProcessNodeLeftEvent; import org.kie.api.event.process.ProcessNodeTriggeredEvent; import org.kie.kogito.Application; import org.kie.kogito.Model; import org.kie.kogito.StaticApplication; import org.kie.kogito.StaticConfig; import org.kie.kogito.auth.SecurityPolicy; +import org.kie.kogito.internal.process.event.KogitoEventListener; import org.kie.kogito.internal.process.event.KogitoProcessEventListener; import org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler; import org.kie.kogito.process.ProcessConfig; @@ -41,11 +45,15 @@ import org.kie.kogito.process.impl.StaticProcessConfig; import org.kie.kogito.services.uow.CollectingUnitOfWorkFactory; import org.kie.kogito.services.uow.DefaultUnitOfWorkManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static java.util.Collections.emptyList; public class ProcessTestHelper { + private static Logger LOGGER = LoggerFactory.getLogger(ProcessTestHelper.class); + public static Application newApplication() { BpmnProcesses bpmnProcesses = new BpmnProcesses(); StaticProcessConfig staticConfig = @@ -85,4 +93,47 @@ public static Predicate triggered(String nodeNam }; } + public static Predicate left(String nodeName) { + return e -> { + return e instanceof ProcessNodeLeftEvent && nodeName.equals(((ProcessNodeLeftEvent) e).getNodeInstance().getNodeName()); + }; + } + + public static class CompletionKogitoEventListener implements KogitoEventListener { + + private String id; + private CountDownLatch latch; + + public CompletionKogitoEventListener(String id) { + this.id = id; + this.latch = new CountDownLatch(1); + } + + @Override + public void signalEvent(String type, Object event) { + latch.countDown(); + LOGGER.info("Completion was invoked"); + } + + @Override + public String[] getEventTypes() { + return new String[] { "processInstanceCompleted:" + id }; + } + + public void await() { + try { + latch.await(); + } catch (InterruptedException e) { + LOGGER.info("Completion was interrupted", e); + } + } + + } + + public static CompletionKogitoEventListener registerCompletionEventListener(IntermediateCatchEventTimerDurationWithErrorProcessInstance instance) { + CompletionKogitoEventListener completionEventListener = new CompletionKogitoEventListener(instance.id()); + instance.internalGetProcessInstance().addEventListener("processInstanceCompleted:" + instance.id(), completionEventListener, false); + return completionEventListener; + } + } diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java index 6988db18b30..8095f68c4f0 100644 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/main/java/org/jbpm/tools/maven/ProcessCodeGenerationSupport.java @@ -37,6 +37,7 @@ import org.jbpm.compiler.canonical.ProcessMetaData; import org.jbpm.compiler.canonical.ProcessToExecModelGenerator; import org.jbpm.compiler.canonical.TemplateHelper; +import org.jbpm.compiler.canonical.TriggerMetaData; import org.jbpm.compiler.xml.XmlProcessReader; import org.jbpm.compiler.xml.core.SemanticModules; import org.jbpm.ruleflow.core.RuleFlowProcess; @@ -46,13 +47,21 @@ import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.Modifier.Keyword; import com.github.javaparser.ast.Node.TreeTraversal; import com.github.javaparser.ast.PackageDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.ConstructorDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.body.VariableDeclarator; +import com.github.javaparser.ast.expr.AssignExpr; +import com.github.javaparser.ast.expr.FieldAccessExpr; +import com.github.javaparser.ast.expr.NameExpr; import com.github.javaparser.ast.expr.ObjectCreationExpr; +import com.github.javaparser.ast.expr.ThisExpr; import com.github.javaparser.ast.expr.VariableDeclarationExpr; +import com.github.javaparser.ast.stmt.BlockStmt; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.printer.DefaultPrettyPrinter; import com.github.javaparser.printer.Printer; @@ -148,6 +157,7 @@ private void generateJavaCode(KogitoWorkflowProcess process) throws IOException // process CompilationUnit processUnit = metadata.getGeneratedClassModel(); + addMembers(metadata, processUnit); RuleFlowProcess ruleFlowProcess = (RuleFlowProcess) process; for (String importClass : ruleFlowProcess.getImports()) { @@ -232,4 +242,39 @@ private void writeCompilationUnit(CompilationUnit unit) throws IOException { LOG.debug("{} generated", modelType.getNameAsString()); Files.write(Paths.get(outputFolder.toString(), modelType.getName().asString() + ".java"), modelSource.getBytes()); } + + private void addMembers(ProcessMetaData processMetaData, CompilationUnit compilationUnit) { + ClassOrInterfaceDeclaration cls = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).get(); + if (!processMetaData.getTriggers().isEmpty()) { + + for (TriggerMetaData trigger : processMetaData.getTriggers()) { + // add message produces as field + if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) { + ClassOrInterfaceType type = StaticJavaParser.parseClassOrInterfaceType(org.kie.kogito.event.impl.MessageProducer.class.getName() + "<" + trigger.getDataType() + ">"); + String producerFieldName = "producer_" + trigger.getOwnerId(); + String producerFieldNameCapitalized = "Producer_" + trigger.getOwnerId(); + + FieldDeclaration producerFieldDeclaration = new FieldDeclaration() + .addVariable(new VariableDeclarator(type, producerFieldName)); + cls.addMember(producerFieldDeclaration); + + MethodDeclaration setMethod = new MethodDeclaration(); + setMethod.addParameter(type, producerFieldName); + setMethod.setModifier(Keyword.PUBLIC, true); + setMethod.setName("set" + producerFieldNameCapitalized); + setMethod.setType(StaticJavaParser.parseType("void")); + AssignExpr assignExpr = new AssignExpr( + new FieldAccessExpr(new ThisExpr(), producerFieldName), + new NameExpr(producerFieldName), + AssignExpr.Operator.ASSIGN); + + BlockStmt body = new BlockStmt(); + body.addStatement(assignExpr); + setMethod.setBody(body); + + cls.addMember(setMethod); + } + } + } + } } diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 new file mode 100755 index 00000000000..877c96ebe26 --- /dev/null +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithStructureRef.bpmn2 @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + + + + + SequenceFlow_3 + + + SequenceFlow_3 + SequenceFlow_4 + + SequenceFlow_5 + SequenceFlow_6 + + + + + + + + + + + _DataInput_9 + _DataInput_10 + _DataInput_11 + _DataInput_12 + _DataInput_13 + _DataInput_14 + _DataInput_15 + + + + + + _DataInput_9 + + + _DataInput_10 + + + _DataInput_11 + + + _DataInput_12 + + + _DataInput_13 + + + _DataInput_14 + + + _DataInput_15 + + + + SequenceFlow_5 + + + + SequenceFlow_6 + + + + + + + SequenceFlow_7 + + + DataOutput_1 + var1 + + + DataOutput_1 + + + + + SequenceFlow_7 + SequenceFlow_8 + System.out.println("Error is handled : var1 = " + var1); + + + + SequenceFlow_8 + + + + SequenceFlow_4 + SequenceFlow_9 + System.out.println("Process is finishing"); + + + SequenceFlow_9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 new file mode 100755 index 00000000000..470d99feab0 --- /dev/null +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + + + + + SequenceFlow_3 + + + SequenceFlow_3 + SequenceFlow_4 + + SequenceFlow_5 + SequenceFlow_6 + + + + + + + + + + + _DataInput_9 + _DataInput_10 + _DataInput_11 + _DataInput_12 + _DataInput_13 + _DataInput_14 + _DataInput_15 + + + + + + _DataInput_9 + + + _DataInput_10 + + + _DataInput_11 + + + _DataInput_12 + + + _DataInput_13 + + + _DataInput_14 + + + _DataInput_15 + + + + SequenceFlow_5 + + + + SequenceFlow_6 + + + + + + + SequenceFlow_7 + + + DataOutput_1 + var1 + + + DataOutput_1 + + + + + SequenceFlow_7 + SequenceFlow_8 + System.out.println("Error is handled : var1 = " + var1); + + + + SequenceFlow_8 + + + + SequenceFlow_4 + SequenceFlow_9 + System.out.println("Process is finishing"); + + + SequenceFlow_9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 similarity index 98% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 rename to jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 index 0d29ebbcaab..5c77c5460dd 100755 --- a/jbpm/jbpm-tests/src/test/resources/BPMN2-BoundaryErrorEventDefaultHandlerWithoutErrorCodeWithoutStructureRef.bpmn2 +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundaryErrorEventSubProcessExceptionMapping.bpmn2 @@ -26,7 +26,7 @@ - + diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn deleted file mode 100755 index d6eb0a8cb47..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-BoundarySignalEventOnTaskWithTransformation.bpmn +++ /dev/null @@ -1,194 +0,0 @@ - - - - - - - - - SequenceFlow_1 - - - SequenceFlow_5 - SequenceFlow_4 - - - - SequenceFlow_4 - - - - SequenceFlow_1 - SequenceFlow_2 - - - - - - - - - _DataInput_2 - _DataInput_3 - _DataInput_4 - _DataInput_5 - _DataInput_6 - _DataInput_7 - - - - - _DataInput_2 - - - _DataInput_3 - - - _DataInput_4 - - - _DataInput_5 - - - _DataInput_6 - - - _DataInput_7 - - - - john - - - - - SequenceFlow_5 - - - _4_Output - x - param.toUpperCase(); - - - _4_Output - - - - - - - - - SequenceFlow_3 - - - - SequenceFlow_2 - SequenceFlow_3 - - - - - - - - - _DataInput_8 - _DataInput_9 - _DataInput_10 - _DataInput_11 - _DataInput_12 - _DataInput_13 - - - - - _DataInput_8 - - - _DataInput_9 - - - _DataInput_10 - - - _DataInput_11 - - - _DataInput_12 - - - _DataInput_13 - - - - john - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataInputAssociations-two-assigns.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataInputAssociations-two-assigns.bpmn2 deleted file mode 100755 index e514a8b2b2b..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataInputAssociations-two-assigns.bpmn2 +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - _BF09B923-BE11-4447-BECB-609BD86C59EF_Comment - - - - instanceMetadata - _BF09B923-BE11-4447-BECB-609BD86C59EF_Comment - - . - foo - - - . - foo/bar - - - - - true() - - - - - - - - - - count($instanceMetadata/user) = 2 - - - - - - - - - diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataOutputAssociations-HumanTask.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataOutputAssociations-HumanTask.bpmn2 deleted file mode 100755 index 6dbff6573dc..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-DataOutputAssociations-HumanTask.bpmn2 +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - _BF09B923-BE11-4447-BECB-609BD86C59EF_PreviousOwner - - - - _BF09B923-BE11-4447-BECB-609BD86C59EF_PreviousOwner - instanceMetadata - - @primaryname - previoustasksowner - - - - - true() - - - - - - - - - - count($instanceMetadata/user) = 2 - - - - - - - - - diff --git a/jbpm/jbpm-tests/src/test/resources/BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2 similarity index 100% rename from jbpm/jbpm-tests/src/test/resources/BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2 rename to jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2 diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-EventSubprocessErrorSignalEmbedded.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-EventSubprocessErrorSignalEmbedded.bpmn2 new file mode 100755 index 00000000000..ebafacec5b2 --- /dev/null +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-EventSubprocessErrorSignalEmbedded.bpmn2 @@ -0,0 +1,342 @@ + + + + + + + + + + + _39010054-5D46-4E8C-A9FA-64E46B4E293A + + + _39010054-5D46-4E8C-A9FA-64E46B4E293A + _FCC2871C-1D99-46E5-BE85-294F2F5EC58A + + + + + _FCC2871C-1D99-46E5-BE85-294F2F5EC58A + _05EE3913-3EAD-424B-92DC-6465CFA11A50 + + + + + _05EE3913-3EAD-424B-92DC-6465CFA11A50 + + + + + + _87AD2D24-CFFC-4352-BC76-DA18AE611768 + + + + _87AD2D24-CFFC-4352-BC76-DA18AE611768 + _4099F2E8-745B-4C8A-81F5-177D8B3D09A3 + + + + _4099F2E8-745B-4C8A-81F5-177D8B3D09A3 + _C970DF27-4230-4477-9D81-0C34636CE8BB + + + + _C970DF27-4230-4477-9D81-0C34636CE8BB + _52E875AC-A9EA-41CF-A168-3C02CEB2AA06 + + + + _52E875AC-A9EA-41CF-A168-3C02CEB2AA06 + _AA209FC7-33F3-483C-ABAB-541246AD4445 + + + + _AA209FC7-33F3-483C-ABAB-541246AD4445 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _pgP6sHTaEeaoApuNXeI-uQ + _pgP6sHTaEeaoApuNXeI-uQ + + \ No newline at end of file diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-MessageEndEvent.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-MessageEndEvent.bpmn2 new file mode 100755 index 00000000000..9d8f225ba59 --- /dev/null +++ b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-MessageEndEvent.bpmn2 @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + x + _2_Input + + + _2_Input + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-SubProcessWithEntryExitScripts.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-SubProcessWithEntryExitScripts.bpmn2 deleted file mode 100755 index 82c335553bc..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-SubProcessWithEntryExitScripts.bpmn2 +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - - - - - - - - - _1-_2 - SequenceFlow_11 - System.err.println("Task 1, var1 = 10"); -kcontext.setVariable("var1", new Integer(10)); - - - - _1-_2 - - - - SequenceFlow_12 - SequenceFlow_7 - System.err.println("Task 3, var3 = 30"); -kcontext.setVariable("var3",30); - - - - - SequenceFlow_8 - - - - SequenceFlow_7 - SequenceFlow_8 - - - - - - - - - - _DataInput_150 - _DataInput_151 - _DataInput_152 - _DataInput_153 - _DataInput_154 - _DataInput_155 - _DataInput_156 - - - - - _DataInput_150 - - - _DataInput_151 - - - _DataInput_152 - - - _DataInput_153 - - - _DataInput_154 - - - _DataInput_155 - - - _DataInput_156 - - - - - - - System.err.println("SubProcess, var4 = 40"); -kcontext.setVariable("var4",40); - - - - System.err.println("SubProcess, var5 = 50"); -kcontext.setVariable("var5",50); - - - - SequenceFlow_11 - SequenceFlow_12 - - SequenceFlow_10 - - - - SequenceFlow_10 - SequenceFlow_9 - System.err.println("Task 2, var2 = 20"); -kcontext.setVariable("var2",20); - - - - - SequenceFlow_9 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-XpathExpression.bpmn2 b/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-XpathExpression.bpmn2 deleted file mode 100755 index 93d72711cfd..00000000000 --- a/jbpm/jbpm-tools/jbpm-tools-maven-plugin/src/test/resources/unit/project/src/main/bpmn/BPMN2-XpathExpression.bpmn2 +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - count($instanceMetadata/instanceMetadata/user[@approved='true']) = 1 - - - count($instanceMetadata/instanceMetadata/user[@approved='false']) = 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/CaseWithTwoStages.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/CaseWithTwoStages.bpmn2 index e67cca2bf4e..d854e1173da 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/CaseWithTwoStages.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/CaseWithTwoStages.bpmn2 @@ -85,7 +85,7 @@ - + diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/CaseWithTwoStagesConditions.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/CaseWithTwoStagesConditions.bpmn2 index df17ff046c7..b6dfe0b1e9c 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/CaseWithTwoStagesConditions.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/CaseWithTwoStagesConditions.bpmn2 @@ -92,7 +92,7 @@ - + @@ -148,7 +148,7 @@ - + diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/EmptyCaseStage.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/EmptyCaseStage.bpmn2 index 6ae7c39e110..0f518be6452 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/EmptyCaseStage.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/EmptyCaseStage.bpmn2 @@ -26,7 +26,7 @@ - + @@ -39,7 +39,7 @@ - + diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/NoStartNodeCaseWithBoundaryTimerStage.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/NoStartNodeCaseWithBoundaryTimerStage.bpmn2 index bb758b2ff34..3c5f3a3eed7 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/NoStartNodeCaseWithBoundaryTimerStage.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/NoStartNodeCaseWithBoundaryTimerStage.bpmn2 @@ -146,7 +146,7 @@ System.out.println("timer on stage 1"); - caseFile_stage1_finished + caseFile_stage1_finished diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/activation/NoStartNodeAdhocCaseWithActivationCondition.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/activation/NoStartNodeAdhocCaseWithActivationCondition.bpmn2 index 647155ba384..0366fd805cc 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/activation/NoStartNodeAdhocCaseWithActivationCondition.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/activation/NoStartNodeAdhocCaseWithActivationCondition.bpmn2 @@ -134,7 +134,7 @@ - + diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/activation/NoStartNodeAdhocCaseWithActivationConditionNoTerminate.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/activation/NoStartNodeAdhocCaseWithActivationConditionNoTerminate.bpmn2 index 38e5852d794..4f34d60e670 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/activation/NoStartNodeAdhocCaseWithActivationConditionNoTerminate.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/activation/NoStartNodeAdhocCaseWithActivationConditionNoTerminate.bpmn2 @@ -118,7 +118,7 @@ - + diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataBoolean.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataBoolean.bpmn2 index 6547c40853f..eaca3ade592 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataBoolean.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataBoolean.bpmn2 @@ -75,7 +75,7 @@ - + diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataInteger.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataInteger.bpmn2 index 4aab9983620..b9318144803 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataInteger.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataInteger.bpmn2 @@ -75,7 +75,7 @@ - + diff --git a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataString.bpmn2 b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataString.bpmn2 index 89aae6b6561..d6502a51f1b 100644 --- a/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataString.bpmn2 +++ b/kogito-codegen-modules/kogito-codegen-processes-integration-tests/src/test/resources/cases/stage/completion/StageWithTaskCaseDataString.bpmn2 @@ -75,7 +75,7 @@ - + diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/NodeFactoryUtils.java b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/NodeFactoryUtils.java index 18590dc51e6..ab2b73b91c8 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/NodeFactoryUtils.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/NodeFactoryUtils.java @@ -78,10 +78,11 @@ public class NodeFactoryUtils { return actionNode .name(name) .metaData(Metadata.EVENT_TYPE, "message") - .metaData(Metadata.MAPPING_VARIABLE, inputVar) + .metaData(Metadata.MAPPING_VARIABLE_INPUT, inputVar) .metaData(Metadata.TRIGGER_REF, type) .metaData(Metadata.MESSAGE_TYPE, JSON_NODE) - .metaData(Metadata.TRIGGER_TYPE, "ProduceMessage"); + .metaData(Metadata.TRIGGER_TYPE, "ProduceMessage") + .inMapping(inputVar, inputVar); } public static , P extends RuleFlowNodeContainerFactory> T startMessageNode(T nodeFactory, EventDefinition eventDefinition, String inputVar, String outputVar) { diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/suppliers/ProduceEventActionSupplier.java b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/suppliers/ProduceEventActionSupplier.java index 71001997875..e53e57f69c9 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/suppliers/ProduceEventActionSupplier.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/suppliers/ProduceEventActionSupplier.java @@ -38,6 +38,7 @@ import io.serverlessworkflow.api.Workflow; import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType; +import static org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE_INPUT; public class ProduceEventActionSupplier extends SWFProduceEventAction implements ExpressionSupplier { @@ -49,7 +50,8 @@ public ProduceEventActionSupplier(Workflow workflow, String trigger, String varN @Override public Expression get(KogitoNode node, ProcessMetaData metadata) { - return AbstractNodeVisitor.buildProducerAction(parseClassOrInterfaceType(SWFProduceEventAction.class.getCanonicalName()), TriggerMetaData.of(node), metadata) + return AbstractNodeVisitor.buildProducerAction(parseClassOrInterfaceType(SWFProduceEventAction.class.getCanonicalName()), TriggerMetaData.of(node, (String) node.getMetaData() + .get(MAPPING_VARIABLE_INPUT)), metadata) .addArgument(new StringLiteralExpr(exprLang)) .addArgument(data != null ? new StringLiteralExpr().setString(data) : new NullLiteralExpr()); } diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/ServerlessWorkflowParsingTest.java b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/ServerlessWorkflowParsingTest.java index f0f5a11337a..e140cb54b87 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/ServerlessWorkflowParsingTest.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/ServerlessWorkflowParsingTest.java @@ -425,7 +425,7 @@ public void testProduceEventOnTransition(String workflowLocation) throws Excepti ActionNode actionNode = (ActionNode) process.getNodes()[4]; assertThat(actionNode.getName()).isEqualTo("TestKafkaEvent"); assertThat(actionNode.getMetaData("TriggerType")).isEqualTo("ProduceMessage"); - assertThat(actionNode.getMetaData("MappingVariable")).isEqualTo("workflowdata"); + assertThat(actionNode.getMetaData("MappingVariableInput")).isEqualTo("workflowdata"); assertThat(actionNode.getMetaData("TriggerRef")).isEqualTo("kafka"); assertThat(actionNode.getMetaData("MessageType")).isEqualTo("com.fasterxml.jackson.databind.JsonNode"); } diff --git a/pom.xml b/pom.xml index d4a05d4f29f..51c1a4f9b58 100644 --- a/pom.xml +++ b/pom.xml @@ -165,4 +165,43 @@ springboot + + + reproducible-build + + + reproducible + + + + + + org.apache.maven.plugins + maven-artifact-plugin + + + check-buildplan + + check-buildplan + + + validate + + + compare + + compare + + + install + + + + + + + +