Skip to content

Commit

Permalink
[Fix_#3406] Neus comment
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Feb 16, 2024
1 parent 6ebd678 commit 59cbd26
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
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 {
Expand Down Expand Up @@ -120,7 +121,7 @@ private void addDataEvent(ProcessEvent event) {
}

private void handleProcessVariableEvent(ProcessVariableChangedEvent event) {
if (event.getTags().contains("internal")) {
if (event.getTags().contains(KogitoTags.INTERNAL_TAG)) {
return;
}
Map<String, Object> metadata = buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@

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<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -87,12 +88,12 @@ protected void visitVariableScope(String field, VariableScope variableScope, Blo
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()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -237,7 +238,7 @@ private void applyValidation(FieldDeclaration fd, List<String> tags) {
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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
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;
}

Expand All @@ -44,12 +45,12 @@ public static VariableDeclarations of(VariableScope vscope) {

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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.
Expand All @@ -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");
Expand Down Expand Up @@ -146,7 +140,7 @@ public void setValue(final Object value) {
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(","));
}
}
Expand All @@ -165,8 +159,8 @@ public String toString() {
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

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 {

Expand Down Expand Up @@ -110,7 +111,7 @@ public boolean isReadOnly(String name) {
Variable v = findVariable(name);

if (v != null) {
return v.hasTag(Variable.READONLY_TAG);
return v.hasTag(KogitoTags.READONLY_TAG);
}
return false;
}
Expand All @@ -119,7 +120,7 @@ public boolean isRequired(String name) {
Variable v = findVariable(name);

if (v != null) {
return v.hasTag(Variable.REQUIRED_TAG);
return v.hasTag(KogitoTags.REQUIRED_TAG);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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> {

Expand Down Expand Up @@ -99,7 +100,7 @@ public ForEachNodeFactory<T> tempVariable(String varRef, String variableName, Da
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

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;
Expand All @@ -44,6 +43,7 @@
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;
Expand Down Expand Up @@ -423,7 +423,7 @@ protected final MakeNodeResult filterAndMergeNode(RuleFlowNodeContainerFactory<?
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) {
Expand Down

0 comments on commit 59cbd26

Please sign in to comment.