Search in sources :

Example 6 with BodyDeclarationComparator

use of io.automatiko.engine.codegen.BodyDeclarationComparator in project automatiko-engine by automatiko-io.

the class PersistenceGenerator method fileSystemBasedPersistence.

protected void fileSystemBasedPersistence(List<GeneratedFile> generatedFiles) {
    ClassOrInterfaceDeclaration persistenceProviderClazz = new ClassOrInterfaceDeclaration().setName("ProcessInstancesFactoryImpl").setModifiers(Modifier.Keyword.PUBLIC).addExtendedType("io.automatiko.engine.addons.persistence.AbstractProcessInstancesFactory");
    CompilationUnit compilationUnit = new CompilationUnit("io.automatiko.engine.addons.persistence.impl");
    compilationUnit.getTypes().add(persistenceProviderClazz);
    if (useInjection()) {
        annotator.withApplicationComponent(persistenceProviderClazz);
        FieldDeclaration pathField = new FieldDeclaration().addVariable(new VariableDeclarator().setType(new ClassOrInterfaceType(null, new SimpleName(Optional.class.getCanonicalName()), NodeList.nodeList(new ClassOrInterfaceType(null, String.class.getCanonicalName())))).setName(PATH_NAME));
        annotator.withConfigInjection(pathField, PERSISTENCE_FS_PATH_PROP);
        // allow to inject path for the file system storage
        BlockStmt pathMethodBody = new BlockStmt();
        pathMethodBody.addStatement(new ReturnStmt(new MethodCallExpr(new NameExpr(PATH_NAME), "orElse").addArgument(new StringLiteralExpr("/tmp"))));
        MethodDeclaration pathMethod = new MethodDeclaration().addModifier(Keyword.PUBLIC).setName(PATH_NAME).setType(String.class).setBody(pathMethodBody);
        persistenceProviderClazz.addMember(pathField);
        persistenceProviderClazz.addMember(pathMethod);
        addCodecComponents(persistenceProviderClazz);
    }
    String packageName = compilationUnit.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
    String clazzName = packageName + "." + persistenceProviderClazz.findFirst(ClassOrInterfaceDeclaration.class).map(c -> c.getName().toString()).get();
    generatedFiles.add(new GeneratedFile(GeneratedFile.Type.CLASS, clazzName.replace('.', '/') + ".java", compilationUnit.toString().getBytes(StandardCharsets.UTF_8)));
    persistenceProviderClazz.getMembers().sort(new BodyDeclarationComparator());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) ApplicationSection(io.automatiko.engine.codegen.ApplicationSection) ArrayList(java.util.ArrayList) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Keyword(com.github.javaparser.ast.Modifier.Keyword) DependencyInjectionAnnotator(io.automatiko.engine.codegen.di.DependencyInjectionAnnotator) ConfigGenerator(io.automatiko.engine.codegen.ConfigGenerator) NodeList(com.github.javaparser.ast.NodeList) SimpleName(com.github.javaparser.ast.expr.SimpleName) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) StoredDataCodec(io.automatiko.engine.api.workflow.encrypt.StoredDataCodec) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) Modifier(com.github.javaparser.ast.Modifier) List(java.util.List) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) AbstractGenerator(io.automatiko.engine.codegen.AbstractGenerator) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Optional(java.util.Optional) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) SimpleName(com.github.javaparser.ast.expr.SimpleName) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 7 with BodyDeclarationComparator

use of io.automatiko.engine.codegen.BodyDeclarationComparator in project automatiko-engine by automatiko-io.

the class PersistenceGenerator method cassandraBasedPersistence.

protected void cassandraBasedPersistence(List<GeneratedFile> generatedFiles) {
    ClassOrInterfaceDeclaration persistenceProviderClazz = new ClassOrInterfaceDeclaration().setName("ProcessInstancesFactoryImpl").setModifiers(Modifier.Keyword.PUBLIC).addExtendedType("io.automatiko.engine.addons.persistence.AbstractProcessInstancesFactory");
    CompilationUnit compilationUnit = new CompilationUnit("io.automatiko.engine.addons.persistence.impl");
    compilationUnit.getTypes().add(persistenceProviderClazz);
    persistenceProviderClazz.addConstructor(Keyword.PUBLIC);
    ConstructorDeclaration constructor = persistenceProviderClazz.addConstructor(Keyword.PUBLIC).addParameter("com.datastax.oss.driver.api.core.CqlSession", "cqlSession").addParameter("io.automatiko.engine.api.config.CassandraPersistenceConfig", "config");
    BlockStmt body = new BlockStmt();
    ExplicitConstructorInvocationStmt superExp = new ExplicitConstructorInvocationStmt(false, null, NodeList.nodeList(new NameExpr("cqlSession"), new NameExpr("config")));
    body.addStatement(superExp);
    constructor.setBody(body);
    if (useInjection()) {
        annotator.withApplicationComponent(persistenceProviderClazz);
        annotator.withInjection(constructor);
        addCodecComponents(persistenceProviderClazz);
    }
    String packageName = compilationUnit.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
    String clazzName = packageName + "." + persistenceProviderClazz.findFirst(ClassOrInterfaceDeclaration.class).map(c -> c.getName().toString()).get();
    generatedFiles.add(new GeneratedFile(GeneratedFile.Type.CLASS, clazzName.replace('.', '/') + ".java", compilationUnit.toString().getBytes(StandardCharsets.UTF_8)));
    persistenceProviderClazz.getMembers().sort(new BodyDeclarationComparator());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) ApplicationSection(io.automatiko.engine.codegen.ApplicationSection) ArrayList(java.util.ArrayList) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Keyword(com.github.javaparser.ast.Modifier.Keyword) DependencyInjectionAnnotator(io.automatiko.engine.codegen.di.DependencyInjectionAnnotator) ConfigGenerator(io.automatiko.engine.codegen.ConfigGenerator) NodeList(com.github.javaparser.ast.NodeList) SimpleName(com.github.javaparser.ast.expr.SimpleName) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) StoredDataCodec(io.automatiko.engine.api.workflow.encrypt.StoredDataCodec) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) Modifier(com.github.javaparser.ast.Modifier) List(java.util.List) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) AbstractGenerator(io.automatiko.engine.codegen.AbstractGenerator) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile)

Example 8 with BodyDeclarationComparator

use of io.automatiko.engine.codegen.BodyDeclarationComparator in project automatiko-engine by automatiko-io.

the class PersistenceGenerator method dynamoDBBasedPersistence.

protected void dynamoDBBasedPersistence(List<GeneratedFile> generatedFiles) {
    ClassOrInterfaceDeclaration persistenceProviderClazz = new ClassOrInterfaceDeclaration().setName("ProcessInstancesFactoryImpl").setModifiers(Modifier.Keyword.PUBLIC).addExtendedType("io.automatiko.engine.addons.persistence.AbstractProcessInstancesFactory");
    CompilationUnit compilationUnit = new CompilationUnit("io.automatiko.engine.addons.persistence.impl");
    compilationUnit.getTypes().add(persistenceProviderClazz);
    persistenceProviderClazz.addConstructor(Keyword.PUBLIC);
    ConstructorDeclaration constructor = persistenceProviderClazz.addConstructor(Keyword.PUBLIC).addParameter("software.amazon.awssdk.services.dynamodb.DynamoDbClient", "dynamodb").addParameter("io.automatiko.engine.api.config.DynamoDBPersistenceConfig", "config");
    BlockStmt body = new BlockStmt();
    ExplicitConstructorInvocationStmt superExp = new ExplicitConstructorInvocationStmt(false, null, NodeList.nodeList(new NameExpr("dynamodb"), new NameExpr("config")));
    body.addStatement(superExp);
    constructor.setBody(body);
    if (useInjection()) {
        annotator.withApplicationComponent(persistenceProviderClazz);
        annotator.withInjection(constructor);
        addCodecComponents(persistenceProviderClazz);
    }
    String packageName = compilationUnit.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
    String clazzName = packageName + "." + persistenceProviderClazz.findFirst(ClassOrInterfaceDeclaration.class).map(c -> c.getName().toString()).get();
    generatedFiles.add(new GeneratedFile(GeneratedFile.Type.CLASS, clazzName.replace('.', '/') + ".java", compilationUnit.toString().getBytes(StandardCharsets.UTF_8)));
    persistenceProviderClazz.getMembers().sort(new BodyDeclarationComparator());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) ApplicationSection(io.automatiko.engine.codegen.ApplicationSection) ArrayList(java.util.ArrayList) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Keyword(com.github.javaparser.ast.Modifier.Keyword) DependencyInjectionAnnotator(io.automatiko.engine.codegen.di.DependencyInjectionAnnotator) ConfigGenerator(io.automatiko.engine.codegen.ConfigGenerator) NodeList(com.github.javaparser.ast.NodeList) SimpleName(com.github.javaparser.ast.expr.SimpleName) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) StoredDataCodec(io.automatiko.engine.api.workflow.encrypt.StoredDataCodec) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) Modifier(com.github.javaparser.ast.Modifier) List(java.util.List) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) AbstractGenerator(io.automatiko.engine.codegen.AbstractGenerator) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile)

Example 9 with BodyDeclarationComparator

use of io.automatiko.engine.codegen.BodyDeclarationComparator in project automatiko-engine by automatiko-io.

the class ProcessGenerator method classDeclaration.

public ClassOrInterfaceDeclaration classDeclaration(CompilationUnit compilationUnit) {
    ClassOrInterfaceDeclaration cls = new ClassOrInterfaceDeclaration().setName(targetTypeName).setModifiers(Modifier.Keyword.PUBLIC);
    if (useInjection()) {
        annotator.withNamedApplicationComponent(cls, process.getId() + versionSuffix);
        FieldDeclaration handlersInjectFieldDeclaration = new FieldDeclaration().addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, new SimpleName(annotator.multiInstanceInjectionType()), NodeList.nodeList(new ClassOrInterfaceType(null, WorkItemHandler.class.getCanonicalName()))), "handlers"));
        cls.addMember(handlersInjectFieldDeclaration);
    }
    String processInstanceFQCN = ProcessInstanceGenerator.qualifiedName(packageName, typeName);
    FieldDeclaration fieldDeclaration = new FieldDeclaration().addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, appCanonicalName), "app"));
    ConstructorDeclaration emptyConstructorDeclaration = new ConstructorDeclaration().setName(targetTypeName).addModifier(Modifier.Keyword.PUBLIC);
    ConstructorDeclaration baseConstructorDeclaration = new ConstructorDeclaration().setName(targetTypeName).addModifier(Modifier.Keyword.PUBLIC).addParameter(appCanonicalName, "app").setBody(new BlockStmt().addStatement(new MethodCallExpr(null, "super").addArgument(new MethodCallExpr(new MethodCallExpr(new NameExpr("app"), "config"), "process"))).addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), "app"), new NameExpr("app"), AssignExpr.Operator.ASSIGN)));
    ConstructorDeclaration constructorDeclaration;
    if (useInjection()) {
        constructorDeclaration = new ConstructorDeclaration().setName(targetTypeName).addModifier(Modifier.Keyword.PUBLIC).addParameter(appCanonicalName, "app").addParameter(new ClassOrInterfaceType(null, new SimpleName(annotator.multiInstanceInjectionType()), NodeList.nodeList(new ClassOrInterfaceType(null, WorkItemHandler.class.getCanonicalName()))), "handlers").addParameter(EndOfInstanceStrategy.class.getCanonicalName(), "strategy").setBody(new BlockStmt().addStatement(new MethodCallExpr(null, "super").addArgument(new MethodCallExpr(new MethodCallExpr(new NameExpr("app"), "config"), "process"))).addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), "app"), new NameExpr("app"), AssignExpr.Operator.ASSIGN)).addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), "handlers"), new NameExpr("handlers"), AssignExpr.Operator.ASSIGN)).addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), "endOfInstanceStrategy"), new NameExpr("strategy"), AssignExpr.Operator.ASSIGN)));
    } else {
        constructorDeclaration = new ConstructorDeclaration().setName(targetTypeName).addModifier(Modifier.Keyword.PUBLIC).addParameter(appCanonicalName, "app").addParameter(EndOfInstanceStrategy.class.getCanonicalName(), "strategy").setBody(new BlockStmt().addStatement(new MethodCallExpr(null, "super").addArgument(new MethodCallExpr(new MethodCallExpr(new NameExpr("app"), "config"), "process"))).addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), "app"), new NameExpr("app"), AssignExpr.Operator.ASSIGN)).addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), "endOfInstanceStrategy"), new NameExpr("strategy"), AssignExpr.Operator.ASSIGN)));
    }
    ProcessMetaData processMetaData = processGenerator.generate();
    if (!processMetaData.getSubProcesses().isEmpty()) {
        for (Entry<String, String> subProcess : processMetaData.getSubProcesses().entrySet()) {
            FieldDeclaration subprocessFieldDeclaration = new FieldDeclaration();
            if (processIdToMetadata.get(subProcess.getKey()) != null) {
                String subProcessPackage = processIdToMetadata.get(subProcess.getKey()).getPackageName();
                if (subProcessPackage != null && !subProcessPackage.isEmpty()) {
                    compilationUnit.addImport(subProcessPackage + "." + StringUtils.capitalize(subProcess.getKey() + "Model"));
                }
            }
            String fieldName = "process" + subProcess.getKey();
            ClassOrInterfaceType modelType = new ClassOrInterfaceType(null, new SimpleName(io.automatiko.engine.api.workflow.Process.class.getCanonicalName()), NodeList.nodeList(new ClassOrInterfaceType(null, StringUtils.capitalize(subProcess.getKey() + "Model"))));
            if (useInjection()) {
                subprocessFieldDeclaration.addVariable(new VariableDeclarator(modelType, fieldName));
                constructorDeclaration.addParameter(annotator.withNamed(new Parameter(modelType, fieldName), subProcess.getKey()));
                constructorDeclaration.getBody().addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), fieldName), new NameExpr(fieldName), AssignExpr.Operator.ASSIGN));
            } else {
                // app.processes().processById()
                MethodCallExpr initSubProcessField = new MethodCallExpr(new MethodCallExpr(new NameExpr("app"), "processes"), "processById").addArgument(new StringLiteralExpr(subProcess.getKey()));
                subprocessFieldDeclaration.addVariable(new VariableDeclarator(modelType, fieldName));
                baseConstructorDeclaration.getBody().addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), fieldName), new CastExpr(modelType, initSubProcessField), Operator.ASSIGN));
                constructorDeclaration.getBody().addStatement(new AssignExpr(new FieldAccessExpr(new ThisExpr(), fieldName), new CastExpr(modelType, initSubProcessField), Operator.ASSIGN));
            }
            cls.addMember(subprocessFieldDeclaration);
            subprocessFieldDeclaration.createGetter();
        }
    }
    if (useInjection()) {
        annotator.withInjection(constructorDeclaration);
    } else {
        emptyConstructorDeclaration.setBody(new BlockStmt().addStatement(new MethodCallExpr(null, "this").addArgument(new ObjectCreationExpr().setType(appCanonicalName))));
    }
    MethodDeclaration createModelMethod = new MethodDeclaration().addModifier(Keyword.PUBLIC).setName("createModel").setType(modelTypeName).setBody(new BlockStmt().addStatement(new ReturnStmt(new ObjectCreationExpr(null, new ClassOrInterfaceType(null, modelTypeName), NodeList.nodeList()))));
    cls.addExtendedType(abstractProcessType(modelTypeName)).addMember(fieldDeclaration).addMember(emptyConstructorDeclaration).addMember(baseConstructorDeclaration).addMember(constructorDeclaration).addMember(createInstanceMethod(processInstanceFQCN)).addMember(createInstanceWithBusinessKeyMethod(processInstanceFQCN)).addMember(createModelMethod).addMember(createInstanceGenericMethod(processInstanceFQCN)).addMember(createInstanceGenericWithBusinessKeyMethod(processInstanceFQCN)).addMember(createInstanceGenericWithWorkflowInstanceMethod(processInstanceFQCN)).addMember(createReadOnlyInstanceGenericWithWorkflowInstanceMethod(processInstanceFQCN)).addMember(internalConfigure(processMetaData)).addMember(internalRegisterListeners(processMetaData)).addMember(userTaskInputModels(processMetaData)).addMember(userTaskOutputModels(processMetaData)).addMember(process(processMetaData));
    if (isServiceProject()) {
        SvgProcessImageGenerator imageGenerator = isServerlessWorkflow() ? new SvgServerlessProcessImageGenerator(process) : new SvgBpmnProcessImageGenerator(process);
        String svg = imageGenerator.generate();
        if (svg != null && !svg.isEmpty()) {
            MethodDeclaration processImageMethod = new MethodDeclaration().setName("image").setModifiers(Keyword.PUBLIC).setType(String.class).setBody(new BlockStmt().addStatement(new ReturnStmt(new StringLiteralExpr().setString(svg))));
            cls.addMember(processImageMethod);
        }
    }
    if (useInjection()) {
        MethodDeclaration initMethod = annotator.withInitMethod(new MethodCallExpr(new ThisExpr(), "activate"));
        cls.addMember(initMethod);
    }
    if (!processMetaData.getTriggers().isEmpty()) {
        for (TriggerMetaData trigger : processMetaData.getTriggers()) {
            // add message produces as field
            if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) {
                String producerFieldType = packageName + "." + typeName + "MessageProducer_" + trigger.getOwnerId();
                String producerFielName = "producer_" + trigger.getOwnerId();
                FieldDeclaration producerFieldieldDeclaration = new FieldDeclaration().addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, producerFieldType), producerFielName));
                cls.addMember(producerFieldieldDeclaration);
                if (useInjection()) {
                    annotator.withInjection(producerFieldieldDeclaration);
                } else {
                    AssignExpr assignExpr = new AssignExpr(new FieldAccessExpr(new ThisExpr(), producerFielName), new ObjectCreationExpr().setType(producerFieldType), AssignExpr.Operator.ASSIGN);
                    cls.getConstructors().forEach(c -> c.getBody().addStatement(assignExpr));
                }
            }
        }
    }
    cls.getMembers().sort(new BodyDeclarationComparator());
    return cls;
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) SvgBpmnProcessImageGenerator(io.automatiko.engine.codegen.process.image.SvgBpmnProcessImageGenerator) SimpleName(com.github.javaparser.ast.expr.SimpleName) NameExpr(com.github.javaparser.ast.expr.NameExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) SvgServerlessProcessImageGenerator(io.automatiko.engine.codegen.process.image.SvgServerlessProcessImageGenerator) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) AssignExpr(com.github.javaparser.ast.expr.AssignExpr) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) CastExpr(com.github.javaparser.ast.expr.CastExpr) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) ThisExpr(com.github.javaparser.ast.expr.ThisExpr) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) TriggerMetaData(io.automatiko.engine.workflow.compiler.canonical.TriggerMetaData) WorkItemHandler(io.automatiko.engine.api.runtime.process.WorkItemHandler) SvgProcessImageGenerator(io.automatiko.engine.codegen.process.image.SvgProcessImageGenerator) EndOfInstanceStrategy(io.automatiko.engine.api.workflow.EndOfInstanceStrategy) ProcessMetaData(io.automatiko.engine.workflow.compiler.canonical.ProcessMetaData) Parameter(com.github.javaparser.ast.body.Parameter) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 10 with BodyDeclarationComparator

use of io.automatiko.engine.codegen.BodyDeclarationComparator in project automatiko-engine by automatiko-io.

the class ProcessInstanceGenerator method classDeclaration.

public ClassOrInterfaceDeclaration classDeclaration() {
    ClassOrInterfaceDeclaration classDecl = new ClassOrInterfaceDeclaration().setName(targetTypeName).addModifier(Modifier.Keyword.PUBLIC);
    classDecl.addExtendedType(new ClassOrInterfaceType(null, AbstractProcessInstance.class.getCanonicalName()).setTypeArguments(new ClassOrInterfaceType(null, model.getModelClassSimpleName()))).addMember(constructorDecl()).addMember(constructorWithBusinessKeyDecl()).addMember(constructorWithWorkflowInstanceAndRuntimeDecl()).addMember(constructorWorkflowInstanceDecl()).addMember(bind()).addMember(unbind());
    if (generatorContext.getApplicationProperty("quarkus.automatiko.instance-locking").orElse("true").equalsIgnoreCase("false")) {
        MethodDeclaration configureLock = new MethodDeclaration().setModifiers(Keyword.PROTECTED).setName("configureLock").addParameter(String.class.getCanonicalName(), "businessKey").setType(new VoidType());
        classDecl.addMember(configureLock);
    }
    ProcessMetaData processMetaData = processGenerator.generate();
    if (!processMetaData.getSubProcesses().isEmpty()) {
        classDecl.getMembers().add(subprocessesMethod(processMetaData));
    }
    classDecl.getMembers().sort(new BodyDeclarationComparator());
    return classDecl;
}
Also used : VoidType(com.github.javaparser.ast.type.VoidType) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BodyDeclarationComparator(io.automatiko.engine.codegen.BodyDeclarationComparator) ProcessMetaData(io.automatiko.engine.workflow.compiler.canonical.ProcessMetaData) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Aggregations

ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)14 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)14 BodyDeclarationComparator (io.automatiko.engine.codegen.BodyDeclarationComparator)14 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)12 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)12 CompilationUnit (com.github.javaparser.ast.CompilationUnit)11 NameExpr (com.github.javaparser.ast.expr.NameExpr)11 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)11 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)10 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)10 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)10 DependencyInjectionAnnotator (io.automatiko.engine.codegen.di.DependencyInjectionAnnotator)10 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)9 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)8 Keyword (com.github.javaparser.ast.Modifier.Keyword)7 NodeList (com.github.javaparser.ast.NodeList)7 SimpleName (com.github.javaparser.ast.expr.SimpleName)7 List (java.util.List)7 Optional (java.util.Optional)7 StaticJavaParser.parse (com.github.javaparser.StaticJavaParser.parse)5