Skip to content

Commit

Permalink
Merge pull request #50 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored Jul 8, 2024
2 parents a6591bc + c13c48a commit 3626ece
Show file tree
Hide file tree
Showing 143 changed files with 3,544 additions and 2,091 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkItemExceptionInfo> exceptionInfoList = new ArrayDeque<>(loggedExceptionsLimit);

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@
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;
import org.jbpm.workflow.core.DroolsAction;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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<DataDefinition> readSources(org.w3c.dom.Node parent, Function<String, DataDefinition> variableResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -104,7 +113,7 @@ public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
visitConnectionsAndAssociations(dynamicNode, xmlDump, metaDataType);

if (dynamicNode.isAutoComplete()) {
xmlDump.append(" <completionCondition xsi:type=\"tFormalExpression\">" + AUTOCOMPLETE_COMPLETION_CONDITION + "</completionCondition>" + EOL);
xmlDump.append("<completionCondition xsi:type=\"tFormalExpression\" language=\"" + dynamicNode.getLanguage() + "\">" + AUTOCOMPLETE_COMPLETION_CONDITION + "</completionCondition>" + EOL);
}
endNode("adHocSubProcess", xmlDump);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
Expand All @@ -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<EventFilter> 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<EventFilter> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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 <escalationEventDefintions>
// are _required_ to reference a specific escalation(-code).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,28 +91,33 @@ 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();
linkNode.setId(node.getId());
node = linkNode;
setThrowVariable(ioSpecification, node);
handleLinkNode(element, node, xmlNode, parser);
node.setMetaData(EVENT_TYPE, EVENT_TYPE_LINK);
}
xmlNode = xmlNode.getNextSibling();
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 3626ece

Please sign in to comment.