use of com.github.javaparser.ast.expr.LambdaExpr in project kogito-runtimes by kiegroup.
the class SplitNodeVisitor method visitNode.
@Override
public void visitNode(String factoryField, Split node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, SplitFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Split")).addStatement(getFactoryMethod(getNodeId(node), METHOD_TYPE, new IntegerLiteralExpr(node.getType())));
visitMetaData(node.getMetaData(), body, getNodeId(node));
if (node.getType() == Split.TYPE_OR || node.getType() == Split.TYPE_XOR) {
for (Entry<ConnectionRef, Constraint> entry : node.getConstraints().entrySet()) {
if (entry.getValue() != null) {
Expression returnValueEvaluator;
if (entry.getValue() instanceof ReturnValueConstraintEvaluator && ((ReturnValueConstraintEvaluator) entry.getValue()).getReturnValueEvaluator() instanceof Supplier) {
returnValueEvaluator = ((Supplier<Expression>) ((ReturnValueConstraintEvaluator) entry.getValue()).getReturnValueEvaluator()).get();
} else if ("FEEL".equals(entry.getValue().getDialect())) {
returnValueEvaluator = FEELDialectCanonicalUtils.buildFEELReturnValueEvaluator(variableScope, entry);
} else {
BlockStmt actionBody = new BlockStmt();
LambdaExpr lambda = new LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
for (Variable v : variableScope.getVariables()) {
actionBody.addStatement(makeAssignment(v));
}
BlockStmt blockStmt = StaticJavaParser.parseBlock("{" + entry.getValue().getConstraint() + "}");
blockStmt.getStatements().forEach(actionBody::addStatement);
returnValueEvaluator = lambda;
}
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_CONSTRAINT, new LongLiteralExpr(entry.getKey().getNodeId()), new StringLiteralExpr(getOrDefault(entry.getKey().getConnectionId(), "")), new StringLiteralExpr(entry.getKey().getToType()), new StringLiteralExpr(entry.getValue().getDialect()), returnValueEvaluator, new IntegerLiteralExpr(entry.getValue().getPriority()), new BooleanLiteralExpr(entry.getValue().isDefault())));
}
}
}
body.addStatement(getDoneMethod(getNodeId(node)));
}
use of com.github.javaparser.ast.expr.LambdaExpr in project kogito-runtimes by kiegroup.
the class AbstractNodeVisitor method createLambdaExpr.
protected static LambdaExpr createLambdaExpr(String consequence, VariableScope scope) {
BlockStmt conditionBody = new BlockStmt();
List<Variable> variables = scope.getVariables();
variables.stream().map(ActionNodeVisitor::makeAssignment).forEach(conditionBody::addStatement);
conditionBody.addStatement(new ReturnStmt(new EnclosedExpr(new NameExpr(consequence))));
return new LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), conditionBody);
}
use of com.github.javaparser.ast.expr.LambdaExpr in project kogito-runtimes by kiegroup.
the class AbstractNodeVisitor method buildCompensationLambdaExpr.
public static LambdaExpr buildCompensationLambdaExpr(String compensationRef) {
BlockStmt actionBody = new BlockStmt();
MethodCallExpr getProcessInstance = new MethodCallExpr(new NameExpr(KCONTEXT_VAR), "getProcessInstance");
MethodCallExpr signalEvent = new MethodCallExpr(getProcessInstance, "signalEvent").addArgument(new StringLiteralExpr(Metadata.EVENT_TYPE_COMPENSATION)).addArgument(new StringLiteralExpr(compensationRef));
actionBody.addStatement(signalEvent);
return new LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
}
use of com.github.javaparser.ast.expr.LambdaExpr in project kogito-runtimes by kiegroup.
the class ActionNodeVisitor method visitNode.
@Override
public void visitNode(String factoryField, ActionNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
body.addStatement(getAssignedFactoryMethod(factoryField, ActionNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Script"));
Optional<ExpressionSupplier> supplierAction = getAction(node, ExpressionSupplier.class);
if (isIntermediateCompensation(node)) {
ProcessInstanceCompensationAction action = (ProcessInstanceCompensationAction) node.getAction().getMetaData(Metadata.ACTION);
String compensateNode = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + metadata.getProcessId();
if (action != null) {
compensateNode = action.getActivityRef();
}
LambdaExpr lambda = buildCompensationLambdaExpr(compensateNode);
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
} else if (supplierAction.isPresent()) {
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, supplierAction.get().get(node, metadata)));
} else if (node.getMetaData(TRIGGER_REF) != null) {
// if there is trigger defined on end event create TriggerMetaData for it
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildProducerAction(node, metadata)));
} else if (node.getMetaData(REF) != null && EVENT_TYPE_SIGNAL.equals(node.getMetaData(EVENT_TYPE))) {
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, buildAction((String) node.getMetaData(REF), (String) node.getMetaData(VARIABLE), (String) node.getMetaData(MAPPING_VARIABLE_INPUT), (String) node.getMetaData(CUSTOM_SCOPE))));
} else if (node.getAction() instanceof DroolsConsequenceAction) {
String consequence = getActionConsequence(node.getAction());
if (consequence == null || consequence.trim().isEmpty()) {
throw new IllegalStateException("Action node " + node.getId() + " name " + node.getName() + " has no action defined");
}
BlockStmt actionBody = new BlockStmt();
List<Variable> variables = variableScope.getVariables();
variables.stream().filter(v -> consequence.contains(v.getName())).map(ActionNodeVisitor::makeAssignment).forEach(actionBody::addStatement);
BlockStmt blockStmt = StaticJavaParser.parseBlock("{" + consequence + "}");
blockStmt.getStatements().forEach(actionBody::addStatement);
LambdaExpr lambda = new LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
body.addStatement(getFactoryMethod(getNodeId(node), METHOD_ACTION, lambda));
}
addNodeMappings(node, body, getNodeId(node));
visitMetaData(node.getMetaData(), body, getNodeId(node));
body.addStatement(getDoneMethod(getNodeId(node)));
}
use of com.github.javaparser.ast.expr.LambdaExpr in project kogito-runtimes by kiegroup.
the class ProcessContainerGenerator method addProcessToApplication.
public void addProcessToApplication(ProcessGenerator r) {
ObjectCreationExpr newProcess = new ObjectCreationExpr().setType(r.targetCanonicalName()).addArgument("application").addArgument(new NullLiteralExpr());
MethodCallExpr expr = new MethodCallExpr(newProcess, "configure");
MethodCallExpr method = new MethodCallExpr(new NameExpr("mappedProcesses"), "computeIfAbsent", nodeList(new StringLiteralExpr(r.processId()), new LambdaExpr(new Parameter(new UnknownType(), "k"), expr)));
IfStmt byProcessId = new IfStmt(new MethodCallExpr(new StringLiteralExpr(r.processId()), "equals", nodeList(new NameExpr("processId"))), new ReturnStmt(method), null);
byProcessIdBody.addStatement(byProcessId);
}
Aggregations