Search in sources :

Example 6 with VariableScope

use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.

the class CompositeContextNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    CompositeContextNode compositeNode = (CompositeContextNode) node;
    String nodeType = "subProcess";
    if (node.getMetaData().get("Transaction") != null) {
        nodeType = "transaction";
    }
    writeNode(nodeType, compositeNode, xmlDump, metaDataType);
    if (compositeNode instanceof EventSubProcessNode) {
        xmlDump.append(" triggeredByEvent=\"true\" ");
    }
    Object isForCompensationObject = compositeNode.getMetaData("isForCompensation");
    if (isForCompensationObject != null && ((Boolean) isForCompensationObject)) {
        xmlDump.append("isForCompensation=\"true\" ");
    }
    xmlDump.append(">" + EOL);
    writeExtensionElements(compositeNode, xmlDump);
    // variables
    VariableScope variableScope = (VariableScope) compositeNode.getDefaultContext(VariableScope.VARIABLE_SCOPE);
    if (variableScope != null && !variableScope.getVariables().isEmpty()) {
        xmlDump.append("    <!-- variables -->" + EOL);
        for (Variable variable : variableScope.getVariables()) {
            xmlDump.append("    <property id=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "\" ");
            if (variable.getType() != null) {
                xmlDump.append("itemSubjectRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(compositeNode) + "-" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(variable.getName()) + "Item\"");
            }
            // TODO: value
            xmlDump.append("/>" + EOL);
        }
    }
    // nodes
    List<Node> subNodes = getSubNodes(compositeNode);
    XmlBPMNProcessDumper.INSTANCE.visitNodes(subNodes, xmlDump, metaDataType);
    // connections
    visitConnectionsAndAssociations(compositeNode, xmlDump, metaDataType);
    endNode(nodeType, xmlDump);
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.workflow.process.core.Node) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 7 with VariableScope

use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.

the class DataObjectHandler method start.

@SuppressWarnings("unchecked")
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String id = attrs.getValue("id");
    final String name = attrs.getValue("name");
    final String itemSubjectRef = attrs.getValue("itemSubjectRef");
    Object parent = parser.getParent();
    if (parent instanceof ContextContainer) {
        ContextContainer contextContainer = (ContextContainer) parent;
        VariableScope variableScope = (VariableScope) contextContainer.getDefaultContext(VariableScope.VARIABLE_SCOPE);
        if (variableScope == null) {
            return null;
        }
        List variables = variableScope.getVariables();
        Variable variable = new Variable();
        variable.setMetaData("DataObject", "true");
        variable.setId(id);
        variable.setName(name);
        variable.setMetaData(id, variable.getName());
        if (localName.equals("dataInput")) {
            variable.setMetaData("DataInput", true);
        } else if (localName.equals("dataOutput")) {
            variable.setMetaData("DataOutput", true);
        }
        // retrieve type from item definition
        DataType dataType = new ObjectDataType();
        Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
        if (itemDefinitions != null) {
            ItemDefinition itemDefinition = itemDefinitions.get(itemSubjectRef);
            if (itemDefinition != null) {
                String structureRef = itemDefinition.getStructureRef();
                if ("java.lang.Boolean".equals(structureRef) || "Boolean".equals(structureRef)) {
                    dataType = new BooleanDataType();
                } else if ("java.lang.Integer".equals(structureRef) || "Integer".equals(structureRef)) {
                    dataType = new IntegerDataType();
                } else if ("java.lang.Float".equals(structureRef) || "Float".equals(structureRef)) {
                    dataType = new FloatDataType();
                } else if ("java.lang.String".equals(structureRef) || "String".equals(structureRef)) {
                    dataType = new StringDataType();
                } else if ("java.lang.Object".equals(structureRef) || "Object".equals(structureRef)) {
                    // use FQCN of Object
                    dataType = new ObjectDataType(java.lang.Object.class, structureRef);
                } else {
                    dataType = new ObjectDataType(constructClass(structureRef, parser.getClassLoader()), structureRef);
                }
            }
        }
        variable.setType(dataType);
        variables.add(variable);
        return variable;
    }
    return new Variable();
}
Also used : FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) DataType(io.automatiko.engine.api.workflow.datatype.DataType) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) FloatDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.FloatDataType) IntegerDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.IntegerDataType) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) StringDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.StringDataType) List(java.util.List) BooleanDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.BooleanDataType) Map(java.util.Map) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 8 with VariableScope

use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.

the class LambdaSubProcessNodeVisitor method bind.

private BlockStmt bind(VariableScope variableScope, SubProcessNode subProcessNode, ModelMetaData subProcessModel) {
    BlockStmt actionBody = new BlockStmt();
    actionBody.addStatement(subProcessModel.newInstance("model"));
    for (Map.Entry<String, String> e : subProcessNode.getInMappings().entrySet()) {
        // check if given mapping is an expression
        Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(e.getValue());
        if (matcher.find()) {
            String expression = matcher.group(1);
            String topLevelVariable = expression.split("\\.")[0];
            Variable v = variableScope.findVariable(topLevelVariable);
            if (actionBody.findFirst(VariableDeclarationExpr.class, vd -> vd.getVariable(0).getNameAsString().equals(v.getSanitizedName())).isEmpty()) {
                actionBody.addStatement(makeAssignment(v));
            }
            actionBody.addStatement(subProcessModel.callSetter("model", e.getKey(), dotNotationToGetExpression(expression)));
        } else {
            Variable v = variableScope.findVariable(e.getValue());
            if (v != null) {
                if (actionBody.findFirst(VariableDeclarationExpr.class, vd -> vd.getVariable(0).getNameAsString().equals(v.getSanitizedName())).isEmpty()) {
                    actionBody.addStatement(makeAssignment(v));
                }
                actionBody.addStatement(subProcessModel.callSetter("model", e.getKey(), e.getValue()));
            }
        }
    }
    actionBody.addStatement(new ReturnStmt(new NameExpr("model")));
    return actionBody;
}
Also used : SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ConditionalExpr(com.github.javaparser.ast.expr.ConditionalExpr) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) StaticJavaParser.parse(com.github.javaparser.StaticJavaParser.parse) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Matcher(java.util.regex.Matcher) Map(java.util.Map) StringUtils(io.automatiko.engine.services.utils.StringUtils) Expression(com.github.javaparser.ast.expr.Expression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) METHOD_WAIT_FOR_COMPLETION(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_WAIT_FOR_COMPLETION) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) METHOD_PROCESS_ID(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_PROCESS_ID) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) AssignExpr(com.github.javaparser.ast.expr.AssignExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) SubProcessNodeFactory(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ClassUtils.constructClass(io.automatiko.engine.workflow.compiler.util.ClassUtils.constructClass) VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) PatternConstants(io.automatiko.engine.workflow.util.PatternConstants) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Optional(java.util.Optional) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) METHOD_PROCESS_VERSION(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_PROCESS_VERSION) METHOD_PROCESS_NAME(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_PROCESS_NAME) METHOD_INDEPENDENT(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_INDEPENDENT) InputStream(java.io.InputStream) VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Matcher(java.util.regex.Matcher) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) Map(java.util.Map) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt)

Example 9 with VariableScope

use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.

the class LambdaSubProcessNodeVisitor method visitNode.

@Override
public void visitNode(WorkflowProcess process, String factoryField, SubProcessNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    InputStream resourceAsStream = this.getClass().getResourceAsStream("/class-templates/SubProcessFactoryTemplate.java");
    Optional<Expression> retValue = parse(resourceAsStream).findFirst(Expression.class);
    String name = node.getName();
    String subProcessId = node.getProcessId();
    String subProcessVersion = ModelMetaData.version(node.getProcessVersion());
    NodeValidator.of(getNodeKey(), name).notEmpty("subProcessId", subProcessId).validate();
    body.addStatement(getAssignedFactoryMethod(factoryField, SubProcessNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId()))).addStatement(getNameMethod(node, "Call Activity")).addStatement(getFactoryMethod(getNodeId(node), METHOD_PROCESS_ID, new StringLiteralExpr(subProcessId))).addStatement(getFactoryMethod(getNodeId(node), METHOD_PROCESS_NAME, new StringLiteralExpr(getOrDefault(node.getProcessName(), "")))).addStatement(getFactoryMethod(getNodeId(node), METHOD_PROCESS_VERSION, new StringLiteralExpr(getOrDefault(node.getProcessVersion(), "")))).addStatement(getFactoryMethod(getNodeId(node), METHOD_WAIT_FOR_COMPLETION, new BooleanLiteralExpr(node.isWaitForCompletion()))).addStatement(getFactoryMethod(getNodeId(node), METHOD_INDEPENDENT, new BooleanLiteralExpr(node.isIndependent())));
    Map<String, String> inputTypes = (Map<String, String>) node.getMetaData("BPMN.InputTypes");
    String subProcessModelClassName = ProcessToExecModelGenerator.extractModelClassName(subProcessId, subProcessVersion);
    ModelMetaData subProcessModel = new ModelMetaData(process.getType(), subProcessId, subProcessVersion, metadata.getPackageName(), subProcessModelClassName, WorkflowProcess.PRIVATE_VISIBILITY, VariableDeclarations.ofRawInfo(inputTypes), false, "Data model for " + name, "A complete data model for " + name);
    retValue.ifPresent(retValueExpression -> {
        retValueExpression.findAll(ClassOrInterfaceType.class).stream().filter(t -> t.getNameAsString().equals("$Type$")).forEach(t -> t.setName(subProcessModelClassName));
        retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("bind")).ifPresent(m -> m.setBody(bind(variableScope, node, subProcessModel)));
        retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("createInstance")).ifPresent(m -> m.setBody(createInstance(node, metadata)));
        retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("unbind")).ifPresent(m -> m.setBody(unbind(variableScope, node)));
        retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("abortInstance")).ifPresent(m -> m.setBody(abortInstance(node, metadata)));
    });
    if (retValue.isPresent()) {
        body.addStatement(getFactoryMethod(getNodeId(node), getNodeKey(), retValue.get()));
    } else {
        body.addStatement(getFactoryMethod(getNodeId(node), getNodeKey()));
    }
    visitMetaData(node.getMetaData(), body, getNodeId(node));
    body.addStatement(getDoneMethod(getNodeId(node)));
}
Also used : SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ConditionalExpr(com.github.javaparser.ast.expr.ConditionalExpr) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) StaticJavaParser.parse(com.github.javaparser.StaticJavaParser.parse) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Matcher(java.util.regex.Matcher) Map(java.util.Map) StringUtils(io.automatiko.engine.services.utils.StringUtils) Expression(com.github.javaparser.ast.expr.Expression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) METHOD_WAIT_FOR_COMPLETION(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_WAIT_FOR_COMPLETION) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) METHOD_PROCESS_ID(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_PROCESS_ID) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) AssignExpr(com.github.javaparser.ast.expr.AssignExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) SubProcessNodeFactory(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ClassUtils.constructClass(io.automatiko.engine.workflow.compiler.util.ClassUtils.constructClass) VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) PatternConstants(io.automatiko.engine.workflow.util.PatternConstants) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Optional(java.util.Optional) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) METHOD_PROCESS_VERSION(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_PROCESS_VERSION) METHOD_PROCESS_NAME(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_PROCESS_NAME) METHOD_INDEPENDENT(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_INDEPENDENT) InputStream(java.io.InputStream) InputStream(java.io.InputStream) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Expression(com.github.javaparser.ast.expr.Expression) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) SubProcessNodeFactory(io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory) Map(java.util.Map)

Example 10 with VariableScope

use of io.automatiko.engine.workflow.base.core.context.variable.VariableScope in project automatiko-engine by automatiko-io.

the class ProcessVisitor method visitProcess.

public void visitProcess(WorkflowProcess process, MethodDeclaration processMethod, ProcessMetaData metadata, String workflowType) {
    BlockStmt body = new BlockStmt();
    ClassOrInterfaceType processFactoryType = new ClassOrInterfaceType(null, ExecutableProcessFactory.class.getSimpleName());
    boolean serverless = ProcessToExecModelGenerator.isServerlessWorkflow(process);
    // create local variable factory and assign new fluent process to it
    VariableDeclarationExpr factoryField = new VariableDeclarationExpr(processFactoryType, FACTORY_FIELD_NAME);
    MethodCallExpr assignFactoryMethod = new MethodCallExpr(new NameExpr(processFactoryType.getName().asString()), "createProcess");
    assignFactoryMethod.addArgument(new StringLiteralExpr(process.getId())).addArgument(new StringLiteralExpr(workflowType)).addArgument(new BooleanLiteralExpr(serverless));
    body.addStatement(new AssignExpr(factoryField, assignFactoryMethod, AssignExpr.Operator.ASSIGN));
    // item definitions
    Set<String> visitedVariables = new HashSet<>();
    VariableScope variableScope = (VariableScope) ((io.automatiko.engine.workflow.base.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    visitVariableScope(variableScope, body, visitedVariables);
    visitSubVariableScopes(process.getNodes(), body, visitedVariables);
    Collection<TagDefinition> tagDefinitions = ((io.automatiko.engine.workflow.process.core.WorkflowProcess) process).getTagDefinitions();
    if (tagDefinitions != null) {
        for (TagDefinition tag : tagDefinitions) {
            if (tag instanceof FunctionTagDefinition) {
                String expression = tag.getExpression();
                Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(expression);
                if (matcher.find()) {
                    expression = matcher.group(1);
                }
                BlockStmt actionBody = new BlockStmt();
                if (serverless) {
                    MethodCallExpr evaluate = new MethodCallExpr(null, "expressionAsString").addArgument(new NameExpr("context")).addArgument(new NameExpr("exp"));
                    actionBody.addStatement(new ReturnStmt(evaluate));
                } else {
                    List<Variable> variables = variableScope.getVariables();
                    variables.stream().filter(v -> tag.getExpression().contains(v.getName())).map(ActionNodeVisitor::makeAssignment).forEach(actionBody::addStatement);
                    actionBody.addStatement(new ReturnStmt(new NameExpr(expression)));
                }
                LambdaExpr lambda = new LambdaExpr(NodeList.nodeList(new Parameter(new UnknownType(), "exp"), new Parameter(new UnknownType(), "context")), actionBody);
                body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, "tag", new StringLiteralExpr(tag.getId()), new StringLiteralExpr().setString(tag.getExpression()), lambda));
            } else {
                body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, "tag", new StringLiteralExpr(tag.getId()), new StringLiteralExpr(tag.getExpression()), new NullLiteralExpr()));
            }
        }
        if (((io.automatiko.engine.workflow.process.core.WorkflowProcess) process).getImports() != null && !((io.automatiko.engine.workflow.process.core.WorkflowProcess) process).getImports().isEmpty()) {
            NodeList<Expression> items = NodeList.nodeList(((io.automatiko.engine.workflow.process.core.WorkflowProcess) process).getImports().stream().map(s -> new StringLiteralExpr(s)).collect(Collectors.toList()));
            body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, "imports", items.toArray(Expression[]::new)));
        }
    }
    metadata.setDynamic(((io.automatiko.engine.workflow.process.core.WorkflowProcess) process).isDynamic());
    // the process itself
    body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_NAME, new StringLiteralExpr(process.getName()))).addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_PACKAGE_NAME, new StringLiteralExpr(process.getPackageName()))).addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_DYNAMIC, new BooleanLiteralExpr(metadata.isDynamic()))).addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_VERSION, new StringLiteralExpr(getOrDefault(process.getVersion(), DEFAULT_VERSION)))).addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_VISIBILITY, new StringLiteralExpr(getOrDefault(process.getVisibility(), WorkflowProcess.PUBLIC_VISIBILITY))));
    visitMetaData(process.getMetaData(), body, FACTORY_FIELD_NAME);
    visitHeader(process, body);
    List<Node> processNodes = new ArrayList<>();
    for (io.automatiko.engine.api.definition.process.Node procNode : process.getNodes()) {
        processNodes.add((io.automatiko.engine.workflow.process.core.Node) procNode);
    }
    visitNodes(process, processNodes, body, variableScope, metadata);
    visitConnections(process.getNodes(), body);
    String timeout = (String) process.getMetaData().get("timeout");
    if (timeout != null) {
        String extraNodeIds = (String) process.getMetaData().get("timeoutNodes");
        if (extraNodeIds != null) {
            List<Expression> arguments = new ArrayList<>();
            arguments.add(new IntegerLiteralExpr(process.getNodes().length));
            arguments.add(new StringLiteralExpr(timeout));
            arguments.addAll(Stream.of(extraNodeIds.split(",")).map(s -> new LongLiteralExpr(s)).collect(Collectors.toList()));
            body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_EXEC_TIMEOUT, arguments.toArray(Expression[]::new)));
        } else {
            body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_EXEC_TIMEOUT, new IntegerLiteralExpr(process.getNodes().length), new StringLiteralExpr(timeout)));
        }
    }
    body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_VALIDATE));
    MethodCallExpr getProcessMethod = new MethodCallExpr(new NameExpr(FACTORY_FIELD_NAME), "getProcess");
    body.addStatement(new ReturnStmt(getProcessMethod));
    processMethod.setBody(body);
}
Also used : IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) FunctionTagDefinition(io.automatiko.engine.workflow.base.core.FunctionTagDefinition) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Matcher(java.util.regex.Matcher) TimerNode(io.automatiko.engine.workflow.process.core.node.TimerNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) MilestoneNode(io.automatiko.engine.workflow.process.core.node.MilestoneNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Node(io.automatiko.engine.workflow.process.core.Node) DynamicNode(io.automatiko.engine.workflow.process.core.node.DynamicNode) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ArrayList(java.util.ArrayList) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) AssignExpr(com.github.javaparser.ast.expr.AssignExpr) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) LongLiteralExpr(com.github.javaparser.ast.expr.LongLiteralExpr) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) HashSet(java.util.HashSet) VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) FunctionTagDefinition(io.automatiko.engine.workflow.base.core.FunctionTagDefinition) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) UnknownType(com.github.javaparser.ast.type.UnknownType) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) Expression(com.github.javaparser.ast.expr.Expression) Parameter(com.github.javaparser.ast.body.Parameter) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)40 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)27 Map (java.util.Map)16 HashMap (java.util.HashMap)11 List (java.util.List)10 ContextContainer (io.automatiko.engine.workflow.base.core.ContextContainer)9 ArrayList (java.util.ArrayList)9 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)8 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)8 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)7 Node (io.automatiko.engine.api.definition.process.Node)6 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)6 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)6 Optional (java.util.Optional)6 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)5 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)5 Matcher (java.util.regex.Matcher)5 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)4 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)4 LongLiteralExpr (com.github.javaparser.ast.expr.LongLiteralExpr)4