use of com.github.javaparser.ast.expr.LambdaExpr in project automatiko-engine by automatiko-io.
the class RuleSetNodeVisitor method handleDecision.
private MethodCallExpr handleDecision(RuleSetNode.RuleType.Decision ruleType) {
StringLiteralExpr namespace = new StringLiteralExpr(ruleType.getNamespace());
StringLiteralExpr model = new StringLiteralExpr(ruleType.getModel());
Expression decision = ruleType.getDecision() == null ? new NullLiteralExpr() : new StringLiteralExpr(ruleType.getDecision());
MethodCallExpr decisionModels = new MethodCallExpr(new NameExpr("app"), "decisionModels");
MethodCallExpr decisionModel = new MethodCallExpr(decisionModels, "getDecisionModel").addArgument(namespace).addArgument(model);
BlockStmt actionBody = new BlockStmt();
LambdaExpr lambda = new LambdaExpr(new Parameter(new UnknownType(), "()"), actionBody);
actionBody.addStatement(new ReturnStmt(decisionModel));
return new MethodCallExpr(METHOD_DECISION).addArgument(namespace).addArgument(model).addArgument(decision).addArgument(lambda);
}
use of com.github.javaparser.ast.expr.LambdaExpr in project automatiko-engine by automatiko-io.
the class SplitNodeVisitor method visitNode.
@Override
public void visitNode(WorkflowProcess process, 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) {
String dialect = entry.getValue().getDialect();
if ("jq".equals(dialect)) {
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()), new StringLiteralExpr(entry.getValue().getConstraint()), new IntegerLiteralExpr(entry.getValue().getPriority())));
} else {
BlockStmt actionBody = new BlockStmt();
LambdaExpr lambda = new // (kcontext) ->
LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
for (Variable v : variableScope.getVariables()) {
actionBody.addStatement(makeAssignment(v));
}
variableScope.getVariables().stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(ActionNodeVisitor::makeAssignmentVersions).forEach(actionBody::addStatement);
if (entry.getValue().getConstraint().contains(System.getProperty("line.separator"))) {
BlockStmt constraintBody = new BlockStmt();
constraintBody.addStatement(entry.getValue().getConstraint());
actionBody.addStatement(constraintBody);
} else {
actionBody.addStatement(new ReturnStmt(new EnclosedExpr(new NameExpr(entry.getValue().getConstraint()))));
}
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()), lambda, new IntegerLiteralExpr(entry.getValue().getPriority())));
}
}
}
}
body.addStatement(getDoneMethod(getNodeId(node)));
}
use of com.github.javaparser.ast.expr.LambdaExpr in project automatiko-engine by automatiko-io.
the class TriggerMetaData method buildLambdaExpr.
public static LambdaExpr buildLambdaExpr(Node node, ProcessMetaData metadata, VariableScope variableScope) {
Map<String, Object> nodeMetaData = node.getMetaData();
TriggerMetaData triggerMetaData = new TriggerMetaData((String) nodeMetaData.get(TRIGGER_REF), (String) nodeMetaData.get(TRIGGER_TYPE), (String) nodeMetaData.get(MESSAGE_TYPE), (String) nodeMetaData.get(MAPPING_VARIABLE), String.valueOf(node.getId()), node.getName()).validate();
triggerMetaData.addContext(node.getMetaData());
triggerMetaData.addContext(Collections.singletonMap("_node_", node));
metadata.addTrigger(triggerMetaData);
// and add trigger action
BlockStmt actionBody = new BlockStmt();
Expression variable;
if (metadata.isServerless()) {
variable = new CastExpr(new ClassOrInterfaceType(null, triggerMetaData.getDataType()), new MethodCallExpr(null, "variableExpression").addArgument(new NameExpr(KCONTEXT_VAR)).addArgument(new StringLiteralExpr(triggerMetaData.getModelRef())));
} else {
Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(triggerMetaData.getModelRef());
if (matcher.find()) {
String expression = matcher.group(1);
List<Variable> variables = variableScope.getVariables();
variables.stream().filter(v -> expression.contains(v.getName())).map(ActionNodeVisitor::makeAssignment).forEach(actionBody::addStatement);
variables.stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(ActionNodeVisitor::makeAssignmentVersions).forEach(actionBody::addStatement);
variable = new CastExpr(new ClassOrInterfaceType(null, triggerMetaData.getDataType()), new NameExpr(expression));
} else {
variable = new CastExpr(new ClassOrInterfaceType(null, triggerMetaData.getDataType()), new MethodCallExpr(new NameExpr(KCONTEXT_VAR), "getVariable").addArgument(new StringLiteralExpr(triggerMetaData.getModelRef())));
}
}
MethodCallExpr producerMethodCall = new MethodCallExpr(new NameExpr("producer_" + node.getId()), "produce").addArgument(new MethodCallExpr(new NameExpr("context"), "getProcessInstance")).addArgument(variable);
actionBody.addStatement(producerMethodCall);
return new // (kcontext) ->
LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
}
use of com.github.javaparser.ast.expr.LambdaExpr in project gin by gintool.
the class CloneVisitorCopyIDs method visit.
@Override
public Visitable visit(final LambdaExpr n, final Object arg) {
Visitable r = checkForReplacement(n);
if (r == null) {
r = super.visit(n, arg);
((LambdaExpr) r).setData(SourceFileTree.NODEKEY_ID, n.containsData(SourceFileTree.NODEKEY_ID) ? n.getData(SourceFileTree.NODEKEY_ID) : SourceFileTree.NODE_NULL_ID);
}
return r;
}
use of com.github.javaparser.ast.expr.LambdaExpr in project automatiko-engine by automatiko-io.
the class TriggerMetaData method buildLambdaExpr.
public static LambdaExpr buildLambdaExpr(Node node, ProcessMetaData metadata) {
Map<String, Object> nodeMetaData = node.getMetaData();
TriggerMetaData triggerMetaData = new TriggerMetaData((String) nodeMetaData.get(TRIGGER_REF), (String) nodeMetaData.get(TRIGGER_TYPE), (String) nodeMetaData.get(MESSAGE_TYPE), (String) nodeMetaData.get(MAPPING_VARIABLE), String.valueOf(node.getId()), node.getName()).validate();
triggerMetaData.addContext(node.getMetaData());
triggerMetaData.addContext(Collections.singletonMap("_node_", node));
metadata.addTrigger(triggerMetaData);
// and add trigger action
BlockStmt actionBody = new BlockStmt();
Expression variable;
if (metadata.isServerless()) {
variable = new CastExpr(new ClassOrInterfaceType(null, triggerMetaData.getDataType()), new MethodCallExpr(null, "variableExpression").addArgument(new NameExpr(KCONTEXT_VAR)).addArgument(new StringLiteralExpr(triggerMetaData.getModelRef())));
} else {
variable = new CastExpr(new ClassOrInterfaceType(null, triggerMetaData.getDataType()), new MethodCallExpr(new NameExpr(KCONTEXT_VAR), "getVariable").addArgument(new StringLiteralExpr(triggerMetaData.getModelRef())));
}
MethodCallExpr producerMethodCall = new MethodCallExpr(new NameExpr("producer_" + node.getId()), "produce").addArgument(new MethodCallExpr(new NameExpr("context"), "getProcessInstance")).addArgument(variable);
actionBody.addStatement(producerMethodCall);
return new // (kcontext) ->
LambdaExpr(// (kcontext) ->
new Parameter(new UnknownType(), KCONTEXT_VAR), actionBody);
}
Aggregations