Skip to content

Commit

Permalink
[Fix #3475] Do not abort process instance
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Apr 30, 2024
1 parent e5bfa81 commit 741372e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
import org.kie.kogito.serverless.workflow.SWFConstants;
import org.kie.kogito.serverless.workflow.parser.ParserContext;
import org.kie.kogito.serverless.workflow.parser.ServerlessWorkflowParser;
import org.kie.kogito.serverless.workflow.suppliers.AbortExpressionActionSupplier;
import org.kie.kogito.serverless.workflow.suppliers.CollectorActionSupplier;
import org.kie.kogito.serverless.workflow.suppliers.CompensationActionSupplier;
import org.kie.kogito.serverless.workflow.suppliers.ErrorExpressionActionSupplier;
import org.kie.kogito.serverless.workflow.suppliers.ExpressionActionSupplier;
import org.kie.kogito.serverless.workflow.suppliers.MergeActionSupplier;
import org.kie.kogito.serverless.workflow.suppliers.ProduceEventActionSupplier;
Expand Down Expand Up @@ -527,10 +527,10 @@ protected final void createTimerNode(RuleFlowNodeContainerFactory<?, ?> factory,

Map<String, String> metadata = state.getMetadata();
if (metadata != null) {
String errorMessage = state.getMetadata().get("errorMessage");
String errorMessage = metadata.get("errorMessage");
if (errorMessage != null && !errorMessage.isBlank()) {
NodeFactory<?, ?> errorMessageNode =
factory.actionNode(parserContext.newId()).action(new AbortExpressionActionSupplier(workflow.getExpressionLang(), errorMessage, SWFConstants.DEFAULT_WORKFLOW_VAR));
factory.actionNode(parserContext.newId()).action(new ErrorExpressionActionSupplier(workflow.getExpressionLang(), errorMessage, SWFConstants.DEFAULT_WORKFLOW_VAR));
connect(errorMessageNode, startNode);
startNode = errorMessageNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
import org.jbpm.compiler.canonical.ProcessMetaData;
import org.jbpm.compiler.canonical.descriptors.ExpressionUtils;
import org.kie.kogito.internal.process.runtime.KogitoNode;
import org.kie.kogito.serverless.workflow.actions.AbortExpressionAction;
import org.kie.kogito.serverless.workflow.actions.ErrorExpressionAction;

import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.ObjectCreationExpr;

public class AbortExpressionActionSupplier extends AbortExpressionAction implements ExpressionSupplier {
public class ErrorExpressionActionSupplier extends ErrorExpressionAction implements ExpressionSupplier {

private ObjectCreationExpr expression;

public AbortExpressionActionSupplier(String lang, String expr, String inputVar) {
public ErrorExpressionActionSupplier(String lang, String expr, String inputVar) {
super(lang, expr, inputVar);
this.expression = ExpressionUtils.getObjectCreationExpr(AbortExpressionAction.class, lang, expr, inputVar);
this.expression = ExpressionUtils.getObjectCreationExpr(ErrorExpressionAction.class, lang, expr, inputVar);
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@
import org.jbpm.process.instance.ProcessInstance;
import org.jbpm.workflow.instance.NodeInstance;
import org.kie.kogito.internal.process.runtime.KogitoProcessContext;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;

public class AbortExpressionAction extends BaseExpressionAction {
import com.fasterxml.jackson.databind.JsonNode;

public AbortExpressionAction(String lang, String expr, String inputVar) {
public class ErrorExpressionAction extends BaseExpressionAction {

public ErrorExpressionAction(String lang, String expr, String inputVar) {
super(lang, expr, inputVar);
}

public void execute(KogitoProcessContext context) throws Exception {
if (expr.isValid()) {
String error = evaluate(context, String.class);
if (error != null) {
setError(context, error);
JsonNode error = evaluate(context, JsonNode.class);
if (!error.isNull() && error.isTextual()) {
String errorStr = error.asText();
if (!errorStr.isBlank()) {
setError(context, errorStr);
}
}
} else {
setError(context, expr.toString());
}
}

private void setError(KogitoProcessContext context, String error) {
ProcessInstance pi = (ProcessInstance) context.getProcessInstance();
pi.setErrorState((NodeInstance) context.getNodeInstance(), new AbortExpressionException(error));
pi.setState(KogitoProcessInstance.STATE_ABORTED);
((ProcessInstance) context.getProcessInstance()).setErrorState((NodeInstance) context.getNodeInstance(), new IllegalArgumentException(error));
}
}

0 comments on commit 741372e

Please sign in to comment.