forked from apache/incubator-kie-kogito-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…apache#3491) * [Fix apache#3475] Parsing the errorMessage metadata keys in end nodes * [Fix apache#3475] Do not abort process instance * [Fix apache#3475] Adding IT test
- Loading branch information
1 parent
54ad37c
commit 0a93241
Showing
5 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...main/java/org/kie/kogito/serverless/workflow/suppliers/ErrorExpressionActionSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.kie.kogito.serverless.workflow.suppliers; | ||
|
||
import org.jbpm.compiler.canonical.ExpressionSupplier; | ||
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.ErrorExpressionAction; | ||
|
||
import com.github.javaparser.ast.expr.Expression; | ||
import com.github.javaparser.ast.expr.ObjectCreationExpr; | ||
|
||
public class ErrorExpressionActionSupplier extends ErrorExpressionAction implements ExpressionSupplier { | ||
|
||
private ObjectCreationExpr expression; | ||
|
||
public ErrorExpressionActionSupplier(String lang, String expr, String inputVar) { | ||
super(lang, expr, inputVar); | ||
this.expression = ExpressionUtils.getObjectCreationExpr(ErrorExpressionAction.class, lang, expr, inputVar); | ||
} | ||
|
||
@Override | ||
public Expression get(KogitoNode node, ProcessMetaData metadata) { | ||
return expression; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ntime/src/main/java/org/kie/kogito/serverless/workflow/actions/ErrorExpressionAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.kie.kogito.serverless.workflow.actions; | ||
|
||
import org.jbpm.process.instance.ProcessInstance; | ||
import org.jbpm.workflow.instance.NodeInstance; | ||
import org.kie.kogito.internal.process.runtime.KogitoProcessContext; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
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()) { | ||
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) context.getProcessInstance()).setErrorState((NodeInstance) context.getNodeInstance(), new IllegalArgumentException(error)); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...quarkus-serverless-workflow-integration-test/src/main/resources/errorWithMetadata.sw.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": "errorWithMetadata", | ||
"version": "1.0", | ||
"name": "Workflow Error example with metadata", | ||
"description": "An example of how to abort a workflow with error given a condition", | ||
"start": "checkEven", | ||
"states": [ | ||
{ | ||
"name": "checkEven", | ||
"type": "operation", | ||
"actions": [], | ||
"end" : true, | ||
"metadata": { | ||
"errorMessage": "if .number % 2 != 0 then \"Is Odd number!!!!\" else null end" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters