use of org.jbpm.process.instance.impl.actions.ProcessInstanceCompensationAction in project kogito-runtimes by kiegroup.
the class EndNodeVisitor method visitNode.
@Override
public void visitNode(String factoryField, EndNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, EndNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "End")).addStatement(getFactoryMethod(getNodeId(node), METHOD_TERMINATE, new BooleanLiteralExpr(node.isTerminate())));
// if there is trigger defined on end event create TriggerMetaData for it
Optional<ProcessInstanceCompensationAction> compensationAction = getAction(node, ProcessInstanceCompensationAction.class);
Optional<ExpressionSupplier> supplier = getAction(node, ExpressionSupplier.class);
if (compensationAction.isPresent()) {
String compensateNode = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + metadata.getProcessId();
if (compensationAction.get().getActivityRef() != null) {
compensateNode = compensationAction.get().getActivityRef();
}
LambdaExpr lambda = buildCompensationLambdaExpr(compensateNode);
body.addStatement(getFactoryMethod(getNodeId(node), ActionNodeFactory.METHOD_ACTION, lambda));
} else if (supplier.isPresent()) {
body.addStatement(getFactoryMethod(getNodeId(node), ActionNodeFactory.METHOD_ACTION, supplier.get().get(node, metadata)));
} 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), (String) node.getMetaData(VARIABLE), (String) node.getMetaData(MAPPING_VARIABLE_INPUT), (String) node.getMetaData(CUSTOM_SCOPE))));
}
addNodeMappings(node, body, getNodeId(node));
visitMetaData(node.getMetaData(), body, getNodeId(node));
body.addStatement(getDoneMethod(getNodeId(node)));
}
use of org.jbpm.process.instance.impl.actions.ProcessInstanceCompensationAction in project kogito-runtimes by kiegroup.
the class ProcessHandler method handleIntermediateOrEndThrowCompensationEvent.
protected void handleIntermediateOrEndThrowCompensationEvent(ExtendedNodeImpl throwEventNode) {
if (throwEventNode.getMetaData("compensation-activityRef") != null) {
String activityRef = (String) throwEventNode.getMetaData().remove("compensation-activityRef");
NodeContainer nodeParent = throwEventNode.getParentContainer();
if (nodeParent instanceof EventSubProcessNode) {
boolean compensationEventSubProcess = false;
List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers();
CESP_CHECK: for (Trigger trigger : startTriggers) {
if (trigger instanceof EventTrigger) {
for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
if (((EventTypeFilter) filter).getType().equals(Metadata.EVENT_TYPE_COMPENSATION)) {
compensationEventSubProcess = true;
break CESP_CHECK;
}
}
}
}
if (compensationEventSubProcess) {
// BPMN2 spec, p. 252, p. 248: intermediate and end compensation event visibility scope
nodeParent = ((NodeImpl) nodeParent).getParentContainer();
}
}
String parentId;
if (nodeParent instanceof RuleFlowProcess) {
parentId = ((RuleFlowProcess) nodeParent).getId();
} else {
parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId");
}
String compensationEvent;
if (activityRef.isEmpty()) {
// general/implicit compensation
compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + parentId;
} else {
// specific compensation
compensationEvent = activityRef;
}
DroolsConsequenceAction compensationAction = new DroolsConsequenceAction("java", "");
compensationAction.setMetaData("Action", new ProcessInstanceCompensationAction(compensationEvent));
if (throwEventNode instanceof ActionNode) {
((ActionNode) throwEventNode).setAction(compensationAction);
} else if (throwEventNode instanceof EndNode) {
List<DroolsAction> actions = new ArrayList<>();
actions.add(compensationAction);
((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
}
}
}
use of org.jbpm.process.instance.impl.actions.ProcessInstanceCompensationAction in project kogito-runtimes by kiegroup.
the class ActionNodeVisitor method visitNode.
@Override
public void visitNode(String factoryField, ActionNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, ActionNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Script"));
Optional<ExpressionSupplier> supplierAction = getAction(node, ExpressionSupplier.class);
if (isIntermediateCompensation(node)) {
ProcessInstanceCompensationAction action = (ProcessInstanceCompensationAction) node.getAction().getMetaData(Metadata.ACTION);
String compensateNode = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + metadata.getProcessId();
if (action != null) {
compensateNode = action.getActivityRef();
}
LambdaExpr lambda = buildCompensationLambdaExpr(compensateNode);
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
} else if (supplierAction.isPresent()) {
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, supplierAction.get().get(node, metadata)));
} 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), (String) node.getMetaData(VARIABLE), (String) node.getMetaData(MAPPING_VARIABLE_INPUT), (String) node.getMetaData(CUSTOM_SCOPE))));
} else if (node.getAction() instanceof DroolsConsequenceAction) {
String consequence = getActionConsequence(node.getAction());
if (consequence == null || consequence.trim().isEmpty()) {
throw new IllegalStateException("Action node " + node.getId() + " name " + node.getName() + " has no action defined");
}
BlockStmt actionBody = new BlockStmt();
List<Variable> 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);
LambdaExpr lambda = new LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
}
addNodeMappings(node, body, getNodeId(node));
visitMetaData(node.getMetaData(), body, getNodeId(node));
body.addStatement(getDoneMethod(getNodeId(node)));
}
Aggregations