This is an automated email from the ASF dual-hosted git repository.
fjtiradosarti pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-runtimes.git
The following commit(s) were added to refs/heads/main by this push:
new 4b39444595 [Fix #3406] Avoid publishing internal variables (#3407)
4b39444595 is described below
commit 4b39444595c286becc2db176e147e67243e24033
Author: Francisco Javier Tirado Sarti
<[email protected]>
AuthorDate: Fri Feb 16 21:19:19 2024 +0100
[Fix #3406] Avoid publishing internal variables (#3407)
* [Fix #3406] Avoid publishing internal variables
* [Fix_#3406] Neus comment
---
.../org/kie/kogito/internal/utils/KogitoTags.java | 30 ++++++++++++++++++++++
.../event/impl/ProcessInstanceEventBatch.java | 5 +++-
.../kie/kogito/process/bpmn2/BpmnVariables.java | 7 ++---
.../jbpm/compiler/canonical/AbstractVisitor.java | 5 ++--
.../org/jbpm/compiler/canonical/ModelMetaData.java | 3 ++-
.../compiler/canonical/VariableDeclarations.java | 7 ++---
.../process/core/context/variable/Variable.java | 14 +++-------
.../core/context/variable/VariableScope.java | 5 ++--
.../ruleflow/core/factory/ForEachNodeFactory.java | 3 ++-
.../workflow/parser/handlers/StateHandler.java | 4 +--
10 files changed, 58 insertions(+), 25 deletions(-)
diff --git
a/api/kogito-api/src/main/java/org/kie/kogito/internal/utils/KogitoTags.java
b/api/kogito-api/src/main/java/org/kie/kogito/internal/utils/KogitoTags.java
new file mode 100644
index 0000000000..a514146fb3
--- /dev/null
+++ b/api/kogito-api/src/main/java/org/kie/kogito/internal/utils/KogitoTags.java
@@ -0,0 +1,30 @@
+/*
+ * 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.internal.utils;
+
+public class KogitoTags {
+
+ public static final String VARIABLE_TAGS = "customTags";
+ public static final String READONLY_TAG = "readonly";
+ public static final String REQUIRED_TAG = "required";
+ public static final String INTERNAL_TAG = "internal";
+ public static final String INPUT_TAG = "input";
+ public static final String OUTPUT_TAG = "output";
+
+}
diff --git
a/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java
b/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java
index 4f153ec5fd..0802570959 100644
---
a/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java
+++
b/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java
@@ -74,6 +74,7 @@ import
org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.internal.process.runtime.KogitoWorkItem;
import org.kie.kogito.internal.process.runtime.KogitoWorkItemNodeInstance;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance;
+import org.kie.kogito.internal.utils.KogitoTags;
import org.kie.kogito.process.workitem.HumanTaskWorkItem;
public class ProcessInstanceEventBatch implements EventBatch {
@@ -120,7 +121,9 @@ public class ProcessInstanceEventBatch implements
EventBatch {
}
private void handleProcessVariableEvent(ProcessVariableChangedEvent event)
{
-
+ if (event.getTags().contains(KogitoTags.INTERNAL_TAG)) {
+ return;
+ }
Map<String, Object> metadata =
buildProcessMetadata((KogitoWorkflowProcessInstance)
event.getProcessInstance());
KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance)
event.getProcessInstance();
ProcessInstanceVariableEventBody.Builder builder =
ProcessInstanceVariableEventBody.create()
diff --git
a/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnVariables.java
b/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnVariables.java
index 4d2f0629cc..65e772dc89 100644
---
a/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnVariables.java
+++
b/jbpm/jbpm-bpmn2/src/main/java/org/kie/kogito/process/bpmn2/BpmnVariables.java
@@ -28,12 +28,13 @@ import java.util.stream.Collectors;
import org.jbpm.process.core.context.variable.Variable;
import org.kie.kogito.Model;
+import org.kie.kogito.internal.utils.KogitoTags;
public class BpmnVariables implements Model {
- public static final Predicate<Variable> OUTPUTS_ONLY = v ->
v.hasTag(Variable.OUTPUT_TAG);
- public static final Predicate<Variable> INPUTS_ONLY = v ->
v.hasTag(Variable.INPUT_TAG);
- public static final Predicate<Variable> INTERNAL_ONLY = v ->
v.hasTag(Variable.INTERNAL_TAG);
+ public static final Predicate<Variable> OUTPUTS_ONLY = v ->
v.hasTag(KogitoTags.OUTPUT_TAG);
+ public static final Predicate<Variable> INPUTS_ONLY = v ->
v.hasTag(KogitoTags.INPUT_TAG);
+ public static final Predicate<Variable> INTERNAL_ONLY = v ->
v.hasTag(KogitoTags.INTERNAL_TAG);
private final Map<String, Object> variables = new HashMap<>();
diff --git
a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractVisitor.java
b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractVisitor.java
index 2dda39c0c3..3f206bc417 100644
---
a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractVisitor.java
+++
b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/AbstractVisitor.java
@@ -30,6 +30,7 @@ import org.jbpm.process.core.context.variable.VariableScope;
import org.jbpm.process.core.datatype.DataTypeResolver;
import org.kie.api.definition.process.NodeContainer;
import org.kie.kogito.internal.process.runtime.KogitoNode;
+import org.kie.kogito.internal.utils.KogitoTags;
import com.github.javaparser.ast.expr.ClassExpr;
import com.github.javaparser.ast.expr.Expression;
@@ -87,12 +88,12 @@ public abstract class AbstractVisitor {
if (!visitedVariables.add(variable.getName())) {
continue;
}
- String tags = (String)
variable.getMetaData(Variable.VARIABLE_TAGS);
+ String tags = (String)
variable.getMetaData(KogitoTags.VARIABLE_TAGS);
Object defaultValue = variable.getValue();
body.tryAddImportToParentCompilationUnit(variable.getType().getClass());
body.addStatement(getFactoryMethod(field, METHOD_VARIABLE, new
StringLiteralExpr(variable.getName()),
new MethodCallExpr(DataTypeResolver.class.getName() +
".fromClass", new
ClassExpr(parseClassOrInterfaceType(variable.getType().getStringType()).removeTypeArguments())),
- defaultValue != null ? new
StringLiteralExpr(defaultValue.toString()) : new NullLiteralExpr(), new
StringLiteralExpr(Variable.VARIABLE_TAGS),
+ defaultValue != null ? new
StringLiteralExpr(defaultValue.toString()) : new NullLiteralExpr(), new
StringLiteralExpr(KogitoTags.VARIABLE_TAGS),
tags != null ? new StringLiteralExpr(tags) : new
NullLiteralExpr()));
}
}
diff --git
a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ModelMetaData.java
b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ModelMetaData.java
index b377be1cc8..c374c7a031 100644
---
a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ModelMetaData.java
+++
b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/ModelMetaData.java
@@ -31,6 +31,7 @@ import org.jbpm.process.core.context.variable.Variable;
import org.kie.kogito.codegen.Generated;
import org.kie.kogito.codegen.VariableInfo;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess;
+import org.kie.kogito.internal.utils.KogitoTags;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.javaparser.ast.CompilationUnit;
@@ -237,7 +238,7 @@ public class ModelMetaData {
if (supportsValidation) {
fd.addAnnotation("jakarta.validation.Valid");
- if (tags != null && tags.contains(Variable.REQUIRED_TAG)) {
+ if (tags != null && tags.contains(KogitoTags.REQUIRED_TAG)) {
fd.addAnnotation("jakarta.validation.constraints.NotNull");
}
}
diff --git
a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/VariableDeclarations.java
b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/VariableDeclarations.java
index 1e6f33c452..af9907335d 100644
---
a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/VariableDeclarations.java
+++
b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/VariableDeclarations.java
@@ -27,13 +27,14 @@ import java.util.function.Predicate;
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.kie.kogito.internal.utils.KogitoTags;
public class VariableDeclarations {
public static VariableDeclarations of(VariableScope vscope) {
HashMap<String, Variable> vs = new HashMap<>();
for (Variable variable : vscope.getVariables()) {
- if (variable.hasTag(Variable.INTERNAL_TAG)) {
+ if (variable.hasTag(KogitoTags.INTERNAL_TAG)) {
continue;
}
@@ -44,12 +45,12 @@ public class VariableDeclarations {
public static VariableDeclarations ofInput(VariableScope vscope) {
- return of(vscope, variable -> variable.hasTag(Variable.INTERNAL_TAG)
|| variable.hasTag(Variable.OUTPUT_TAG));
+ return of(vscope, variable -> variable.hasTag(KogitoTags.INTERNAL_TAG)
|| variable.hasTag(KogitoTags.OUTPUT_TAG));
}
public static VariableDeclarations ofOutput(VariableScope vscope) {
- return of(vscope, variable -> variable.hasTag(Variable.INTERNAL_TAG)
|| variable.hasTag(Variable.INPUT_TAG));
+ return of(vscope, variable -> variable.hasTag(KogitoTags.INTERNAL_TAG)
|| variable.hasTag(KogitoTags.INPUT_TAG));
}
public static VariableDeclarations of(VariableScope vscope,
Predicate<Variable> filterOut) {
diff --git
a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/Variable.java
b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/Variable.java
index e81f4f55e2..e33a97a6da 100755
---
a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/Variable.java
+++
b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/Variable.java
@@ -35,6 +35,7 @@ import org.jbpm.process.core.ValueObject;
import org.jbpm.process.core.datatype.DataType;
import org.jbpm.process.core.datatype.impl.coverter.CloneHelper;
import org.jbpm.process.core.datatype.impl.type.UndefinedDataType;
+import org.kie.kogito.internal.utils.KogitoTags;
/**
* Default implementation of a variable.
@@ -44,13 +45,6 @@ public class Variable implements TypeObject, ValueObject,
Serializable {
private static final long serialVersionUID = 510l;
- public static final String VARIABLE_TAGS = "customTags";
-
- public static final String READONLY_TAG = "readonly";
- public static final String REQUIRED_TAG = "required";
- public static final String INTERNAL_TAG = "internal";
- public static final String INPUT_TAG = "input";
- public static final String OUTPUT_TAG = "output";
public static final String BUSINESS_RELEVANT = "business-relevant";
public static final String TRACKED = "tracked";
public static final Set<String> KOGITO_RESERVED = Set.of("id");
@@ -146,7 +140,7 @@ public class Variable implements TypeObject, ValueObject,
Serializable {
public void setMetaData(String name, Object value) {
this.metaData.put(name, value);
- if (VARIABLE_TAGS.equals(name) && value != null) {
+ if (KogitoTags.VARIABLE_TAGS.equals(name) && value != null) {
tags = Arrays.asList(value.toString().split(","));
}
}
@@ -165,8 +159,8 @@ public class Variable implements TypeObject, ValueObject,
Serializable {
}
public List<String> getTags() {
- if (tags.isEmpty() && this.metaData.containsKey(VARIABLE_TAGS)) {
- tags =
Arrays.asList(metaData.get(VARIABLE_TAGS).toString().split(","));
+ if (tags.isEmpty() &&
this.metaData.containsKey(KogitoTags.VARIABLE_TAGS)) {
+ tags =
Arrays.asList(metaData.get(KogitoTags.VARIABLE_TAGS).toString().split(","));
}
return tags;
diff --git
a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/VariableScope.java
b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/VariableScope.java
index dd2ecf6677..613926aaf7 100755
---
a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/VariableScope.java
+++
b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/context/variable/VariableScope.java
@@ -24,6 +24,7 @@ import java.util.List;
import org.jbpm.process.core.Context;
import org.jbpm.process.core.context.AbstractContext;
+import org.kie.kogito.internal.utils.KogitoTags;
public class VariableScope extends AbstractContext {
@@ -110,7 +111,7 @@ public class VariableScope extends AbstractContext {
Variable v = findVariable(name);
if (v != null) {
- return v.hasTag(Variable.READONLY_TAG);
+ return v.hasTag(KogitoTags.READONLY_TAG);
}
return false;
}
@@ -119,7 +120,7 @@ public class VariableScope extends AbstractContext {
Variable v = findVariable(name);
if (v != null) {
- return v.hasTag(Variable.REQUIRED_TAG);
+ return v.hasTag(KogitoTags.REQUIRED_TAG);
}
return false;
}
diff --git
a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/factory/ForEachNodeFactory.java
b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/factory/ForEachNodeFactory.java
index aa462310ae..4ee362d81b 100755
---
a/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/factory/ForEachNodeFactory.java
+++
b/jbpm/jbpm-flow/src/main/java/org/jbpm/ruleflow/core/factory/ForEachNodeFactory.java
@@ -27,6 +27,7 @@ import org.jbpm.workflow.core.NodeContainer;
import org.jbpm.workflow.core.impl.DataDefinition;
import org.jbpm.workflow.core.node.CompositeContextNode;
import org.jbpm.workflow.core.node.ForEachNode;
+import org.kie.kogito.internal.utils.KogitoTags;
public class ForEachNodeFactory<T extends RuleFlowNodeContainerFactory<T, ?>>
extends AbstractCompositeNodeFactory<ForEachNodeFactory<T>, T> {
@@ -99,7 +100,7 @@ public class ForEachNodeFactory<T extends
RuleFlowNodeContainerFactory<T, ?>> ex
private ForEachNodeFactory<T> addVariable(String varRef, String
variableName, DataType dataType, boolean eval) {
Variable variable = getForEachNode().addContextVariable(varRef,
variableName, dataType);
variable.setMetaData(Metadata.EVAL_VARIABLE, eval);
- variable.setMetaData(Variable.VARIABLE_TAGS, Variable.INTERNAL_TAG);
+ variable.setMetaData(KogitoTags.VARIABLE_TAGS,
KogitoTags.INTERNAL_TAG);
return this;
}
diff --git
a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/StateHandler.java
b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/StateHandler.java
index 6ef53ad49c..c29571ed3c 100644
---
a/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/StateHandler.java
+++
b/kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/StateHandler.java
@@ -28,7 +28,6 @@ import java.util.Optional;
import org.jbpm.compiler.canonical.descriptors.ExpressionReturnValueSupplier;
import org.jbpm.process.core.context.exception.CompensationScope;
-import org.jbpm.process.core.context.variable.Variable;
import org.jbpm.process.core.datatype.impl.type.ObjectDataType;
import org.jbpm.ruleflow.core.Metadata;
import org.jbpm.ruleflow.core.RuleFlowNodeContainerFactory;
@@ -44,6 +43,7 @@ import org.jbpm.ruleflow.core.factory.SupportsAction;
import org.jbpm.ruleflow.core.factory.TimerNodeFactory;
import org.jbpm.workflow.core.node.Join;
import org.jbpm.workflow.core.node.Split;
+import org.kie.kogito.internal.utils.KogitoTags;
import org.kie.kogito.serverless.workflow.SWFConstants;
import org.kie.kogito.serverless.workflow.parser.ParserContext;
import org.kie.kogito.serverless.workflow.parser.ServerlessWorkflowParser;
@@ -423,7 +423,7 @@ public abstract class StateHandler<S extends State> {
boolean shouldMerge, FilterableNodeSupplier nodeSupplier) {
if (isTempVariable(actionVarName)) {
- embeddedSubProcess.variable(actionVarName, new
ObjectDataType(JsonNode.class.getCanonicalName()), Variable.VARIABLE_TAGS,
Variable.INTERNAL_TAG);
+ embeddedSubProcess.variable(actionVarName, new
ObjectDataType(JsonNode.class.getCanonicalName()), KogitoTags.VARIABLE_TAGS,
KogitoTags.INTERNAL_TAG);
}
NodeFactory<?, ?> startNode, currentNode;
if (fromStateExpr != null) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]