Search in sources :

Example 1 with METHOD_PROCESS_ID

use of io.automatiko.engine.workflow.process.executable.core.factory.SubProcessNodeFactory.METHOD_PROCESS_ID 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)

Aggregations

StaticJavaParser.parse (com.github.javaparser.StaticJavaParser.parse)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)1 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)1 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)1 ConditionalExpr (com.github.javaparser.ast.expr.ConditionalExpr)1 Expression (com.github.javaparser.ast.expr.Expression)1 LongLiteralExpr (com.github.javaparser.ast.expr.LongLiteralExpr)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)1 VariableDeclarationExpr (com.github.javaparser.ast.expr.VariableDeclarationExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)1 StringUtils (io.automatiko.engine.services.utils.StringUtils)1 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)1