Skip to content

Commit

Permalink
Merge branch 'main' into incubator-kie-issues-1131-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhitocode authored May 29, 2024
2 parents c80d8b0 + bfb00fd commit 4aa8902
Show file tree
Hide file tree
Showing 93 changed files with 4,262 additions and 1,077 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-kogito-runtimes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
github-token: "${{ secrets.GITHUB_TOKEN }}"
definition-file: https://raw.githubusercontent.com/${GROUP:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/pull-request-config.yaml
env:
BUILD_MVN_OPTS_CURRENT: '-T 1.5C'
BUILD_MVN_OPTS_CURRENT: '-T 1.5C -Dvalidate-formatting'
- name: Junit Report
uses: apache/incubator-kie-kogito-pipelines/.ci/actions/action-junit-report@main
if: ${{ always() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ protected DataDefinition getVariableDataSpec(Parser parser, String propertyIdRef
return null;
}
Variable variable = var.get();
return new DataDefinition(variable.getId(), variable.getName(), variable.getType().getStringType());
return new DataDefinition(variable.getId(), variable.getName(), variable);
}

protected ItemDefinition getStructureRef(Parser parser, String id) {
Expand Down Expand Up @@ -630,10 +630,9 @@ private String cleanUp(String expression) {
}

private DataDefinition toDataExpression(String expression) {
DataDefinition dataSpec = new DataDefinition(UUID.randomUUID().toString(), "EXPRESSION (" + expression + ")", null);
DataDefinition dataSpec = new DataDefinition(UUID.randomUUID().toString(), "EXPRESSION (" + expression + ")", (String) null);
dataSpec.setExpression(expression);
return dataSpec;

}

private boolean isExpr(String mvelExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.xml.sax.SAXException;

import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE;
import static org.jbpm.ruleflow.core.Metadata.MESSAGE_REF;

public class BoundaryEventHandler extends AbstractNodeHandler {

Expand Down Expand Up @@ -408,6 +409,7 @@ protected void handleMessageNode(final Node node, final Element element,
eventNode.setMetaData("MessageType", message.getType());
eventNode.setMetaData("TriggerType", "ConsumeMessage");
eventNode.setMetaData("TriggerRef", message.getName());
eventNode.setMetaData(MESSAGE_REF, message.getId());
List<EventFilter> eventFilters = new ArrayList<>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setCorrelationManager(((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_SIGNAL;
import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_TIMER;
import static org.jbpm.ruleflow.core.Metadata.LINK_NAME;
import static org.jbpm.ruleflow.core.Metadata.MESSAGE_REF;
import static org.jbpm.ruleflow.core.Metadata.MESSAGE_TYPE;
import static org.jbpm.ruleflow.core.Metadata.SIGNAL_TYPE;
import static org.jbpm.ruleflow.core.Metadata.TRIGGER_REF;
Expand Down Expand Up @@ -240,6 +241,7 @@ protected void handleMessageNode(final Node node, final Element element,
eventNode.setMetaData(MESSAGE_TYPE, message.getType());
eventNode.setMetaData(TRIGGER_TYPE, CONSUME_MESSAGE);
eventNode.setMetaData(TRIGGER_REF, message.getName());
eventNode.setMetaData(MESSAGE_REF, message.getId());
List<EventFilter> eventFilters = new ArrayList<>();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setCorrelationManager(((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@
import org.jbpm.process.core.correlation.CorrelationManager;
import org.jbpm.process.core.event.EventFilter;
import org.jbpm.process.core.event.EventTypeFilter;
import org.jbpm.process.core.event.MVELMessageExpressionEvaluator;
import org.jbpm.process.core.timer.Timer;
import org.jbpm.process.instance.impl.Action;
import org.jbpm.process.instance.impl.MVELInterpretedReturnValueEvaluator;
import org.jbpm.process.instance.impl.ReturnValueEvaluator;
import org.jbpm.process.instance.impl.actions.CancelNodeInstanceAction;
import org.jbpm.process.instance.impl.actions.ProcessInstanceCompensationAction;
import org.jbpm.process.instance.impl.actions.SignalProcessInstanceAction;
Expand Down Expand Up @@ -240,7 +241,7 @@ private void postProcessCollaborations(RuleFlowProcess process, Parser parser) {
correlationProperty.getMessageRefs().forEach(messageRef -> {

// for now only MVEL expressions
MVELMessageExpressionEvaluator evaluator = new MVELMessageExpressionEvaluator(correlationProperty.getRetrievalExpression(messageRef).getScript());
ReturnValueEvaluator evaluator = new MVELInterpretedReturnValueEvaluator(correlationProperty.getRetrievalExpression(messageRef).getScript());
correlationManager.addMessagePropertyExpression(key.getId(), messageRef, correlationProperty.getId(), evaluator);
});
}
Expand All @@ -251,7 +252,8 @@ private void postProcessCollaborations(RuleFlowProcess process, Parser parser) {
for (CorrelationSubscription subscription : HandlerUtil.correlationSubscription(process).values()) {
correlationManager.subscribeTo(subscription.getCorrelationKeyRef());
for (Map.Entry<String, Expression> binding : subscription.getPropertyExpressions().entrySet()) {
MVELMessageExpressionEvaluator evaluator = new MVELMessageExpressionEvaluator(binding.getValue().getScript());

ReturnValueEvaluator evaluator = new MVELInterpretedReturnValueEvaluator(binding.getValue().getScript());
correlationManager.addProcessSubscriptionPropertyExpression(subscription.getCorrelationKeyRef(), binding.getKey(), evaluator);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE;
import static org.jbpm.ruleflow.core.Metadata.EVENT_TYPE_MESSAGE;
import static org.jbpm.ruleflow.core.Metadata.MAPPING_VARIABLE;
import static org.jbpm.ruleflow.core.Metadata.MESSAGE_REF;
import static org.jbpm.ruleflow.core.Metadata.MESSAGE_TYPE;
import static org.jbpm.ruleflow.core.Metadata.TRIGGER_MAPPING;
import static org.jbpm.ruleflow.core.Metadata.TRIGGER_MAPPING_INPUT;
Expand Down Expand Up @@ -138,6 +139,7 @@ protected Node handleNode(final Node node, final Element element, final String u
startNode.setMetaData(MESSAGE_TYPE, message.getType());
startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.ConsumeMessage.name());
startNode.setMetaData(TRIGGER_REF, message.getName());
startNode.setMetaData(MESSAGE_REF, message.getId());

addTriggerWithInMappings(startNode, "Message-" + message.getName(), message.getId(), ((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
} else if ("timerEventDefinition".equals(nodeName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public void build(final PackageBuildContext context,
String text = descr.getText();

try {
XPATHReturnValueEvaluator expr = new XPATHReturnValueEvaluator(text,
null);
XPATHReturnValueEvaluator expr = new XPATHReturnValueEvaluator(text);

constraintNode.setEvaluator(expr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.stream.Collectors;

import org.jbpm.process.builder.action.ActionCompilerRegistry;
import org.jbpm.process.builder.transformation.DataTransformerCompilerRegistry;
import org.jbpm.process.core.ContextContainer;
import org.jbpm.process.core.context.variable.Mappable;
import org.jbpm.process.core.context.variable.Variable;
Expand Down Expand Up @@ -69,6 +70,7 @@
import com.github.javaparser.ast.type.WildcardType;

import static com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType;
import static java.util.Collections.singletonList;
import static org.drools.util.StringUtils.ucFirst;
import static org.jbpm.ruleflow.core.Metadata.CUSTOM_AUTO_START;
import static org.jbpm.ruleflow.core.Metadata.HIDDEN;
Expand Down Expand Up @@ -230,7 +232,7 @@ protected Expression buildDataAssociationExpression(DataAssociation dataAssociat
DataDefinition targetExpr = dataAssociation.getTarget();
Transformation transformation = dataAssociation.getTransformation();
List<Assignment> assignments = dataAssociation.getAssignments();
return toDataAssociation(toDataDef(sourceExpr), toDataDef(targetExpr), toAssignmentExpr(assignments), toTransformation(transformation));
return toDataAssociation(toDataDef(sourceExpr), toDataDef(targetExpr), toAssignmentExpr(assignments), toTransformation(sourceExpr, singletonList(targetExpr), transformation));
}

private Expression toAssignmentExpr(List<Assignment> assignments) {
Expand All @@ -250,15 +252,15 @@ private Expression toAssignmentExpr(List<Assignment> assignments) {
return new MethodCallExpr(null, "java.util.Arrays.asList", NodeList.nodeList(expressions));
}

protected Expression toTransformation(Transformation transformation) {
protected Expression toTransformation(List<DataDefinition> inputs, List<DataDefinition> outputs, Transformation transformation) {
if (transformation == null) {
return new NullLiteralExpr();
}
Expression lang = new StringLiteralExpr(transformation.getLanguage());
Expression expression = new StringLiteralExpr(transformation.getExpression());
Expression source = new StringLiteralExpr(transformation.getSource());
Expression compiledExpression = DataTransformerCompilerRegistry.instance().find(transformation.getLanguage()).compile(inputs, outputs, transformation);
ClassOrInterfaceType clazz = new ClassOrInterfaceType(null, "org.jbpm.workflow.core.node.Transformation");
return new ObjectCreationExpr(null, clazz, NodeList.nodeList(lang, expression, source));
return new ObjectCreationExpr(null, clazz, NodeList.nodeList(lang, expression, compiledExpression));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import org.kie.api.definition.process.NodeContainer;
import org.kie.api.definition.process.WorkflowElementIdentifier;
import org.kie.kogito.internal.process.runtime.KogitoNode;
import org.kie.kogito.internal.utils.KogitoTags;

import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.expr.ClassExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.FieldAccessExpr;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.expr.NameExpr;
import com.github.javaparser.ast.expr.NullLiteralExpr;
Expand Down Expand Up @@ -102,13 +102,28 @@ protected void visitVariableScope(String field, VariableScope variableScope, Blo
if (!visitedVariables.add(variable.getName())) {
continue;
}
String tags = (String) variable.getMetaData(KogitoTags.VARIABLE_TAGS);

Map<String, Object> metaData = variable.getMetaData();
NodeList<Expression> parameters = new NodeList<>();
for (Map.Entry<String, Object> entry : metaData.entrySet().stream().filter(e -> e.getValue() != null).toList()) {
parameters.add(new StringLiteralExpr(entry.getKey()));
parameters.add(new StringLiteralExpr(entry.getValue().toString()));
}

Expression metadataExpression = new FieldAccessExpr(new NameExpr(Map.class.getPackage().getName()), Map.class.getSimpleName());
metadataExpression = new MethodCallExpr(metadataExpression, "of", parameters);
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(KogitoTags.VARIABLE_TAGS),
tags != null ? new StringLiteralExpr(tags) : new NullLiteralExpr()));

NodeList<Expression> variableFactoryParameters = new NodeList<>();
variableFactoryParameters.add(new StringLiteralExpr(variable.getName()));
variableFactoryParameters
.add(new MethodCallExpr(DataTypeResolver.class.getName() + ".fromClass", new ClassExpr(parseClassOrInterfaceType(variable.getType().getStringType()).removeTypeArguments())));
if (defaultValue != null) {
variableFactoryParameters.add(new StringLiteralExpr(defaultValue.toString()));
}
variableFactoryParameters.add(metadataExpression);
body.addStatement(getFactoryMethod(field, METHOD_VARIABLE, variableFactoryParameters.stream().toArray(Expression[]::new)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ protected String getNodeKey() {
public void visitNode(String factoryField, ActionNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, ActionNodeFactory.class, getNodeId(node), getNodeKey(), getWorkflowElementConstructor(node.getId())))
.addStatement(getNameMethod(node, "Script"));
visitMetaData(node.getMetaData(), body, getNodeId(node));

Optional<ExpressionSupplier> supplierAction = getAction(node, ExpressionSupplier.class);
if (isIntermediateCompensation(node)) {
Expand Down Expand Up @@ -101,7 +102,6 @@ public void visitNode(String factoryField, ActionNode node, BlockStmt body, Vari
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
}
addNodeMappings(node, body, getNodeId(node));
visitMetaData(node.getMetaData(), body, getNodeId(node));
body.addStatement(getDoneMethod(getNodeId(node)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ protected String getNodeKey() {

@Override
public void visitNode(String factoryField, BoundaryEventNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, BoundaryEventNodeFactory.class, getNodeId(node), getNodeKey(), getWorkflowElementConstructor(node.getId())))
.addStatement(getNameMethod(node, "BoundaryEvent"))
body.addStatement(getAssignedFactoryMethod(factoryField, BoundaryEventNodeFactory.class, getNodeId(node), getNodeKey(), getWorkflowElementConstructor(node.getId())));
visitMetaData(node.getMetaData(), body, getNodeId(node));
body.addStatement(getNameMethod(node, "BoundaryEvent"))
.addStatement(getFactoryMethod(getNodeId(node), METHOD_EVENT_TYPE, new StringLiteralExpr(node.getType())))
.addStatement(getFactoryMethod(getNodeId(node), METHOD_ATTACHED_TO, new StringLiteralExpr(node.getAttachedToNodeId())))
.addStatement(getFactoryMethod(getNodeId(node), METHOD_SCOPE, getOrNullExpr(node.getScope())));
Expand All @@ -70,7 +71,6 @@ public void visitNode(String factoryField, BoundaryEventNode node, BlockStmt bod
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ADD_COMPENSATION_HANDLER, new StringLiteralExpr(node.getAttachedToNodeId())));
}
addNodeMappings(node, body, getNodeId(node));
visitMetaData(node.getMetaData(), body, getNodeId(node));
body.addStatement(getDoneMethod(getNodeId(node)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ protected String getNodeKey() {

@Override
public void visitNode(String factoryField, EventNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, EventNodeFactory.class, getNodeId(node), getNodeKey(), getWorkflowElementConstructor(node.getId())))
.addStatement(getNameMethod(node, "Event"))
body.addStatement(getAssignedFactoryMethod(factoryField, EventNodeFactory.class, getNodeId(node), getNodeKey(), getWorkflowElementConstructor(node.getId())));
visitMetaData(node.getMetaData(), body, getNodeId(node));
body.addStatement(getNameMethod(node, "Event"))
.addStatement(getFactoryMethod(getNodeId(node), METHOD_EVENT_TYPE, new StringLiteralExpr(node.getType())));

Variable variable = null;
Expand All @@ -72,7 +73,7 @@ public void visitNode(String factoryField, EventNode node, BlockStmt body, Varia
}
}
addNodeMappings(node, body, getNodeId(node));
visitMetaData(node.getMetaData(), body, getNodeId(node));

body.addStatement(getDoneMethod(getNodeId(node)));
}

Expand Down
Loading

0 comments on commit 4aa8902

Please sign in to comment.