Search in sources :

Example 1 with UserTaskModelMetaData

use of io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData in project automatiko-engine by automatiko-io.

the class ProcessCodegen method populateSubprocesses.

protected List<AbstractResourceGenerator> populateSubprocesses(WorkflowProcess parentProcess, ProcessMetaData metaData, Map<String, ProcessMetaData> processIdToMetadata, Map<String, ModelClassGenerator> processIdToModelGenerator, List<ProcessExecutableModelGenerator> processExecutableModelGenerators, Map<String, List<UserTaskModelMetaData>> processIdToUserTaskModel) {
    List<AbstractResourceGenerator> subprocesses = new ArrayList<AbstractResourceGenerator>();
    for (Entry<String, String> entry : metaData.getSubProcesses().entrySet()) {
        ProcessExecutableModelGenerator execModelGen = processExecutableModelGenerators.stream().filter(p -> p.getProcessId().equals(entry.getValue())).findFirst().orElse(null);
        if (execModelGen != null) {
            WorkflowProcess workFlowProcess = execModelGen.process();
            ModelClassGenerator modelClassGenerator = processIdToModelGenerator.get(entry.getValue());
            Optional.of(new SubprocessResourceGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName)).map(r -> r.withDependencyInjection(annotator).withParentProcess(parentProcess).withUserTasks(processIdToUserTaskModel.get(execModelGen.getProcessId())).withSignals(processIdToMetadata.get(execModelGen.getProcessId()).getSignals()).withTriggers(processIdToMetadata.get(execModelGen.getProcessId()).isStartable(), processIdToMetadata.get(execModelGen.getProcessId()).isDynamic()).withSubProcesses(populateSubprocesses(workFlowProcess, processIdToMetadata.get(execModelGen.getProcessId()), processIdToMetadata, processIdToModelGenerator, processExecutableModelGenerators, processIdToUserTaskModel))).ifPresent(subprocesses::add);
        }
    }
    return subprocesses;
}
Also used : Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) XmlProcessReader(io.automatiko.engine.workflow.compiler.xml.XmlProcessReader) Type(io.automatiko.engine.codegen.GeneratedFile.Type) LoggerFactory(org.slf4j.LoggerFactory) ApplicationSection(io.automatiko.engine.codegen.ApplicationSection) ApplicationGenerator.log(io.automatiko.engine.codegen.ApplicationGenerator.log) DefaultResourceGeneratorFactory(io.automatiko.engine.codegen.DefaultResourceGeneratorFactory) Resource(io.automatiko.engine.api.io.Resource) Map(java.util.Map) ZipFile(java.util.zip.ZipFile) TriggerMetaData(io.automatiko.engine.workflow.compiler.canonical.TriggerMetaData) DependencyInjectionAnnotator(io.automatiko.engine.codegen.di.DependencyInjectionAnnotator) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) Process(io.automatiko.engine.api.definition.process.Process) BPMNExtensionsSemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNExtensionsSemanticModule) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) StandardCharsets(java.nio.charset.StandardCharsets) InternalResource(io.automatiko.engine.services.io.InternalResource) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) BPMNDISemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNDISemanticModule) SAXException(org.xml.sax.SAXException) Entry(java.util.Map.Entry) ResourceType.determineResourceType(io.automatiko.engine.api.io.ResourceType.determineResourceType) Optional(java.util.Optional) ModelMetaData(io.automatiko.engine.workflow.compiler.canonical.ModelMetaData) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ResourceGeneratorFactory(io.automatiko.engine.codegen.ResourceGeneratorFactory) ProcessToExecModelGenerator(io.automatiko.engine.workflow.compiler.canonical.ProcessToExecModelGenerator) SemanticModules(io.automatiko.engine.workflow.compiler.xml.SemanticModules) ServerlessWorkflowParser(io.automatiko.engine.workflow.serverless.parser.ServerlessWorkflowParser) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IoUtils.readBytesFromInputStream(io.automatiko.engine.services.utils.IoUtils.readBytesFromInputStream) StringUtils(io.automatiko.engine.services.utils.StringUtils) ResourceType(io.automatiko.engine.api.io.ResourceType) FileSystemResource(io.automatiko.engine.services.io.FileSystemResource) LinkedHashSet(java.util.LinkedHashSet) UserTaskModelMetaData(io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData) CodegenUtils(io.automatiko.engine.codegen.CodegenUtils) BaseFunctions(io.automatiko.engine.services.execution.BaseFunctions) ConfigGenerator(io.automatiko.engine.codegen.ConfigGenerator) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ApplicationGenerator(io.automatiko.engine.codegen.ApplicationGenerator) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) IOException(java.io.IOException) ProcessConfigGenerator(io.automatiko.engine.codegen.process.config.ProcessConfigGenerator) BPMNSemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNSemanticModule) File(java.io.File) OpenAPIMetaData(io.automatiko.engine.workflow.compiler.canonical.OpenAPIMetaData) ProcessMetaData(io.automatiko.engine.workflow.compiler.canonical.ProcessMetaData) Paths(java.nio.file.Paths) AbstractGenerator(io.automatiko.engine.codegen.AbstractGenerator) Functions(io.automatiko.engine.api.Functions) Collections(java.util.Collections) ArrayList(java.util.ArrayList) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess)

Example 2 with UserTaskModelMetaData

use of io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData in project automatiko-engine by automatiko-io.

the class ProcessGenerator method userTaskInputModels.

private MethodDeclaration userTaskInputModels(ProcessMetaData processMetaData) {
    ReturnStmt returnStmt = new ReturnStmt(new NullLiteralExpr());
    BlockStmt body = new BlockStmt();
    if (userTasks != null && !userTasks.isEmpty()) {
        body = new BlockStmt();
        for (UserTaskModelMetaData userTask : userTasks) {
            body.addStatement(new IfStmt(new MethodCallExpr(new StringLiteralExpr(userTask.getTaskName()), "equals", NodeList.nodeList(new NameExpr("taskName"))), new ReturnStmt(new MethodCallExpr(new NameExpr(userTask.getInputModelClassName()), new SimpleName("fromMap")).addArgument(new NameExpr("taskId")).addArgument(new NameExpr("taskName")).addArgument(new NameExpr("taskData"))), null));
        }
    }
    body.addStatement(returnStmt);
    MethodDeclaration methodDeclaration = new MethodDeclaration();
    methodDeclaration.setName("taskInputs").addModifier(Modifier.Keyword.PUBLIC).addParameter(String.class.getCanonicalName(), "taskId").addParameter(String.class.getCanonicalName(), "taskName").addParameter(Map.class.getCanonicalName(), "taskData").setType(Object.class.getCanonicalName()).setBody(body);
    return methodDeclaration;
}
Also used : NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) UserTaskModelMetaData(io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData) IfStmt(com.github.javaparser.ast.stmt.IfStmt) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) SimpleName(com.github.javaparser.ast.expr.SimpleName) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) Map(java.util.Map) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 3 with UserTaskModelMetaData

use of io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData in project automatiko-engine by automatiko-io.

the class ProcessGenerator method userTaskOutputModels.

private MethodDeclaration userTaskOutputModels(ProcessMetaData processMetaData) {
    ReturnStmt returnStmt = new ReturnStmt(new NullLiteralExpr());
    BlockStmt body = new BlockStmt();
    if (userTasks != null && !userTasks.isEmpty()) {
        body = new BlockStmt();
        for (UserTaskModelMetaData userTask : userTasks) {
            body.addStatement(new IfStmt(new MethodCallExpr(new StringLiteralExpr(userTask.getTaskName()), "equals", NodeList.nodeList(new NameExpr("taskName"))), new ReturnStmt(new MethodCallExpr(new NameExpr(userTask.getOutputModelClassName()), new SimpleName("fromMap")).addArgument(new NameExpr("taskId")).addArgument(new NameExpr("taskName")).addArgument(new NameExpr("taskData"))), null));
        }
    }
    body.addStatement(returnStmt);
    MethodDeclaration methodDeclaration = new MethodDeclaration();
    methodDeclaration.setName("taskOutputs").addModifier(Modifier.Keyword.PUBLIC).addParameter(String.class.getCanonicalName(), "taskId").addParameter(String.class.getCanonicalName(), "taskName").addParameter(Map.class.getCanonicalName(), "taskData").setType(Object.class.getCanonicalName()).setBody(body);
    return methodDeclaration;
}
Also used : NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) UserTaskModelMetaData(io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData) IfStmt(com.github.javaparser.ast.stmt.IfStmt) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) SimpleName(com.github.javaparser.ast.expr.SimpleName) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) Map(java.util.Map) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 4 with UserTaskModelMetaData

use of io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData in project automatiko-engine by automatiko-io.

the class ProcessCodegen method populateSubprocessesGraphQL.

protected List<AbstractResourceGenerator> populateSubprocessesGraphQL(WorkflowProcess parentProcess, ProcessMetaData metaData, Map<String, ProcessMetaData> processIdToMetadata, Map<String, ModelClassGenerator> processIdToModelGenerator, List<ProcessExecutableModelGenerator> processExecutableModelGenerators, Map<String, List<UserTaskModelMetaData>> processIdToUserTaskModel) {
    List<AbstractResourceGenerator> subprocesses = new ArrayList<AbstractResourceGenerator>();
    for (Entry<String, String> entry : metaData.getSubProcesses().entrySet()) {
        ProcessExecutableModelGenerator execModelGen = processExecutableModelGenerators.stream().filter(p -> p.getProcessId().equals(entry.getValue())).findFirst().orElse(null);
        if (execModelGen != null) {
            WorkflowProcess workFlowProcess = execModelGen.process();
            ModelClassGenerator modelClassGenerator = processIdToModelGenerator.get(entry.getValue());
            Optional.of(new SubprocessGraphQLResourceGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName)).map(r -> r.withDependencyInjection(annotator).withParentProcess(parentProcess).withUserTasks(processIdToUserTaskModel.get(execModelGen.getProcessId())).withSignals(processIdToMetadata.get(execModelGen.getProcessId()).getSignals()).withTriggers(processIdToMetadata.get(execModelGen.getProcessId()).isStartable(), processIdToMetadata.get(execModelGen.getProcessId()).isDynamic()).withSubProcesses(populateSubprocessesGraphQL(workFlowProcess, processIdToMetadata.get(execModelGen.getProcessId()), processIdToMetadata, processIdToModelGenerator, processExecutableModelGenerators, processIdToUserTaskModel))).ifPresent(subprocesses::add);
        }
    }
    return subprocesses;
}
Also used : Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) XmlProcessReader(io.automatiko.engine.workflow.compiler.xml.XmlProcessReader) Type(io.automatiko.engine.codegen.GeneratedFile.Type) LoggerFactory(org.slf4j.LoggerFactory) ApplicationSection(io.automatiko.engine.codegen.ApplicationSection) ApplicationGenerator.log(io.automatiko.engine.codegen.ApplicationGenerator.log) DefaultResourceGeneratorFactory(io.automatiko.engine.codegen.DefaultResourceGeneratorFactory) Resource(io.automatiko.engine.api.io.Resource) Map(java.util.Map) ZipFile(java.util.zip.ZipFile) TriggerMetaData(io.automatiko.engine.workflow.compiler.canonical.TriggerMetaData) DependencyInjectionAnnotator(io.automatiko.engine.codegen.di.DependencyInjectionAnnotator) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) Process(io.automatiko.engine.api.definition.process.Process) BPMNExtensionsSemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNExtensionsSemanticModule) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) StandardCharsets(java.nio.charset.StandardCharsets) InternalResource(io.automatiko.engine.services.io.InternalResource) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) BPMNDISemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNDISemanticModule) SAXException(org.xml.sax.SAXException) Entry(java.util.Map.Entry) ResourceType.determineResourceType(io.automatiko.engine.api.io.ResourceType.determineResourceType) Optional(java.util.Optional) ModelMetaData(io.automatiko.engine.workflow.compiler.canonical.ModelMetaData) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ResourceGeneratorFactory(io.automatiko.engine.codegen.ResourceGeneratorFactory) ProcessToExecModelGenerator(io.automatiko.engine.workflow.compiler.canonical.ProcessToExecModelGenerator) SemanticModules(io.automatiko.engine.workflow.compiler.xml.SemanticModules) ServerlessWorkflowParser(io.automatiko.engine.workflow.serverless.parser.ServerlessWorkflowParser) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IoUtils.readBytesFromInputStream(io.automatiko.engine.services.utils.IoUtils.readBytesFromInputStream) StringUtils(io.automatiko.engine.services.utils.StringUtils) ResourceType(io.automatiko.engine.api.io.ResourceType) FileSystemResource(io.automatiko.engine.services.io.FileSystemResource) LinkedHashSet(java.util.LinkedHashSet) UserTaskModelMetaData(io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData) CodegenUtils(io.automatiko.engine.codegen.CodegenUtils) BaseFunctions(io.automatiko.engine.services.execution.BaseFunctions) ConfigGenerator(io.automatiko.engine.codegen.ConfigGenerator) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ApplicationGenerator(io.automatiko.engine.codegen.ApplicationGenerator) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) IOException(java.io.IOException) ProcessConfigGenerator(io.automatiko.engine.codegen.process.config.ProcessConfigGenerator) BPMNSemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNSemanticModule) File(java.io.File) OpenAPIMetaData(io.automatiko.engine.workflow.compiler.canonical.OpenAPIMetaData) ProcessMetaData(io.automatiko.engine.workflow.compiler.canonical.ProcessMetaData) Paths(java.nio.file.Paths) AbstractGenerator(io.automatiko.engine.codegen.AbstractGenerator) Functions(io.automatiko.engine.api.Functions) Collections(java.util.Collections) ArrayList(java.util.ArrayList) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess)

Example 5 with UserTaskModelMetaData

use of io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData in project automatiko-engine by automatiko-io.

the class ProcessCodegen method generate.

public List<GeneratedFile> generate() {
    if (processes.isEmpty()) {
        return Collections.emptyList();
    }
    List<ProcessGenerator> ps = new ArrayList<>();
    List<ProcessInstanceGenerator> pis = new ArrayList<>();
    List<ProcessExecutableModelGenerator> processExecutableModelGenerators = new ArrayList<>();
    // REST resources
    List<AbstractResourceGenerator> rgs = new ArrayList<>();
    // GraphQL resources
    List<AbstractResourceGenerator> grapggs = new ArrayList<>();
    // Function resources
    List<FunctionGenerator> fgs = new ArrayList<>();
    // Function flow resources
    List<FunctionFlowGenerator> ffgs = new ArrayList<>();
    // message data events
    List<MessageDataEventGenerator> mdegs = new ArrayList<>();
    // message endpoints/consumers
    Set<MessageConsumerGenerator> megs = new LinkedHashSet<>();
    // message producers
    List<MessageProducerGenerator> mpgs = new ArrayList<>();
    // OpenAPI clients
    Set<OpenAPIClientGenerator> opgs = new LinkedHashSet<>();
    List<String> publicProcesses = new ArrayList<>();
    Map<String, ModelMetaData> processIdToModel = new HashMap<>();
    Map<String, ModelClassGenerator> processIdToModelGenerator = new HashMap<>();
    Map<String, InputModelClassGenerator> processIdToInputModelGenerator = new HashMap<>();
    Map<String, OutputModelClassGenerator> processIdToOutputModelGenerator = new HashMap<>();
    Map<String, List<UserTaskModelMetaData>> processIdToUserTaskModel = new HashMap<>();
    Map<String, ProcessMetaData> processIdToMetadata = new HashMap<>();
    String workflowType = Process.WORKFLOW_TYPE;
    if (isFunctionFlowProject()) {
        workflowType = Process.FUNCTION_FLOW_TYPE;
    } else if (isFunctionProject()) {
        workflowType = Process.FUNCTION_TYPE;
    }
    // then we can instantiate the exec model generator
    // with the data classes that we have already resolved
    ProcessToExecModelGenerator execModelGenerator = new ProcessToExecModelGenerator(contextClassLoader, workflowType);
    // first we generate all the data classes from variable declarations
    for (Entry<String, WorkflowProcess> entry : processes.entrySet()) {
        ModelClassGenerator mcg = new ModelClassGenerator(execModelGenerator, context(), entry.getValue());
        processIdToModelGenerator.put(entry.getKey(), mcg);
        processIdToModel.put(entry.getKey(), mcg.generate());
        InputModelClassGenerator imcg = new InputModelClassGenerator(context(), entry.getValue(), workflowType);
        processIdToInputModelGenerator.put(entry.getKey(), imcg);
        OutputModelClassGenerator omcg = new OutputModelClassGenerator(context(), entry.getValue(), workflowType);
        processIdToOutputModelGenerator.put(entry.getKey(), omcg);
        context.addGenerator("ModelClassGenerator", entry.getKey(), mcg);
        context.addGenerator("InputModelClassGenerator", entry.getKey(), imcg);
        context.addGenerator("OutputModelClassGenerator", entry.getKey(), omcg);
    }
    // then we generate user task inputs and outputs if any
    for (Entry<String, WorkflowProcess> entry : processes.entrySet()) {
        UserTasksModelClassGenerator utcg = new UserTasksModelClassGenerator(entry.getValue(), context);
        processIdToUserTaskModel.put(entry.getKey(), utcg.generate());
    }
    List<String> functions = context.getBuildContext().classThatImplement(Functions.class.getCanonicalName());
    // collect all process descriptors (exec model)
    for (Entry<String, WorkflowProcess> entry : processes.entrySet()) {
        ProcessExecutableModelGenerator execModelGen = new ProcessExecutableModelGenerator(entry.getValue(), execModelGenerator);
        String packageName = entry.getValue().getPackageName();
        String id = entry.getKey();
        // add extra meta data to indicate if user task mgmt is available
        if (context.getBuildContext().isUserTaskMgmtSupported()) {
            entry.getValue().getMetaData().put("UserTaskMgmt", "true");
        }
        Set<String> classImports = ((io.automatiko.engine.workflow.process.core.WorkflowProcess) entry.getValue()).getImports();
        if (classImports != null) {
            classImports = new HashSet<>();
            ((io.automatiko.engine.workflow.process.core.WorkflowProcess) entry.getValue()).setImports(classImports);
        }
        classImports.add(BaseFunctions.class.getCanonicalName());
        classImports.addAll(functions);
        try {
            ProcessMetaData generate = execModelGen.generate();
            processIdToMetadata.put(id, generate);
            processExecutableModelGenerators.add(execModelGen);
            context.addProcess(id, generate);
        } catch (RuntimeException e) {
            LOGGER.error(e.getMessage());
            throw new ProcessCodegenException(id, packageName, e);
        }
    }
    // generate Process, ProcessInstance classes and the REST resource
    for (ProcessExecutableModelGenerator execModelGen : processExecutableModelGenerators) {
        String classPrefix = StringUtils.capitalize(execModelGen.extractedProcessId());
        WorkflowProcess workFlowProcess = execModelGen.process();
        ModelClassGenerator modelClassGenerator = processIdToModelGenerator.get(execModelGen.getProcessId());
        ProcessGenerator p = new ProcessGenerator(context, workFlowProcess, execModelGen, classPrefix, modelClassGenerator.className(), applicationCanonicalName, processIdToUserTaskModel.get(execModelGen.getProcessId()), processIdToMetadata).withDependencyInjection(annotator).withPersistence(persistence);
        ProcessInstanceGenerator pi = new ProcessInstanceGenerator(workflowType, context(), execModelGen, workFlowProcess.getPackageName(), classPrefix, modelClassGenerator.generate());
        ProcessMetaData metaData = processIdToMetadata.get(execModelGen.getProcessId());
        if (isFunctionFlowProject()) {
            ffgs.add(new FunctionFlowGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName).withDependencyInjection(annotator).withSignals(metaData.getSignals(), metaData.getSignalNodes()).withTriggers(metaData.getTriggers()));
            if (metaData.getTriggers() != null) {
                for (TriggerMetaData trigger : metaData.getTriggers()) {
                    if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) {
                        MessageDataEventGenerator msgDataEventGenerator = new MessageDataEventGenerator(workFlowProcess, trigger).withDependencyInjection(annotator);
                        mdegs.add(msgDataEventGenerator);
                        mpgs.add(new MessageProducerGenerator(workflowType, context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), msgDataEventGenerator.className(), trigger).withDependencyInjection(annotator));
                    }
                }
            }
        } else if (isFunctionProject()) {
            fgs.add(new FunctionGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName).withDependencyInjection(annotator));
        } else if (isServiceProject()) {
            if (isPublic(workFlowProcess)) {
                // Creating and adding the ResourceGenerator
                resourceGeneratorFactory.create(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName).map(r -> r.withDependencyInjection(annotator).withParentProcess(null).withPersistence(persistence).withUserTasks(processIdToUserTaskModel.get(execModelGen.getProcessId())).withPathPrefix("{id}").withSignals(metaData.getSignals()).withTriggers(metaData.isStartable(), metaData.isDynamic()).withSubProcesses(populateSubprocesses(workFlowProcess, processIdToMetadata.get(execModelGen.getProcessId()), processIdToMetadata, processIdToModelGenerator, processExecutableModelGenerators, processIdToUserTaskModel))).ifPresent(rgs::add);
                if (context.getBuildContext().isGraphQLSupported()) {
                    GraphQLResourceGenerator graphqlGenerator = new GraphQLResourceGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName);
                    graphqlGenerator.withDependencyInjection(annotator).withParentProcess(null).withPersistence(persistence).withUserTasks(processIdToUserTaskModel.get(execModelGen.getProcessId())).withPathPrefix(CodegenUtils.version(workFlowProcess.getVersion())).withSignals(metaData.getSignals()).withTriggers(metaData.isStartable(), metaData.isDynamic()).withSubProcesses(populateSubprocessesGraphQL(workFlowProcess, processIdToMetadata.get(execModelGen.getProcessId()), processIdToMetadata, processIdToModelGenerator, processExecutableModelGenerators, processIdToUserTaskModel));
                    grapggs.add(graphqlGenerator);
                }
            }
            if (metaData.getTriggers() != null) {
                for (TriggerMetaData trigger : metaData.getTriggers()) {
                    // generate message consumers for processes with message events
                    if (isPublic(workFlowProcess) && trigger.getType().equals(TriggerMetaData.TriggerType.ConsumeMessage)) {
                        MessageDataEventGenerator msgDataEventGenerator = new MessageDataEventGenerator(workFlowProcess, trigger).withDependencyInjection(annotator);
                        mdegs.add(msgDataEventGenerator);
                        megs.add(new MessageConsumerGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName, msgDataEventGenerator.className(), trigger).withDependencyInjection(annotator).withPersistence(persistence));
                    } else if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) {
                        MessageDataEventGenerator msgDataEventGenerator = new MessageDataEventGenerator(workFlowProcess, trigger).withDependencyInjection(annotator);
                        mdegs.add(msgDataEventGenerator);
                        mpgs.add(new MessageProducerGenerator(workflowType, context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), msgDataEventGenerator.className(), trigger).withDependencyInjection(annotator));
                    }
                }
            }
        }
        if (metaData.getOpenAPIs() != null) {
            for (OpenAPIMetaData api : metaData.getOpenAPIs()) {
                OpenAPIClientGenerator oagenerator = new OpenAPIClientGenerator(context, workFlowProcess, api).withDependencyInjection(annotator);
                opgs.add(oagenerator);
            }
        }
        moduleGenerator.addProcess(p);
        ps.add(p);
        pis.add(pi);
    }
    for (ModelClassGenerator modelClassGenerator : processIdToModelGenerator.values()) {
        ModelMetaData mmd = modelClassGenerator.generate();
        storeFile(Type.MODEL, modelClassGenerator.generatedFilePath(), mmd.generate(annotator != null ? new String[] { "io.quarkus.runtime.annotations.RegisterForReflection" } : new String[0]));
    }
    for (InputModelClassGenerator modelClassGenerator : processIdToInputModelGenerator.values()) {
        ModelMetaData mmd = modelClassGenerator.generate();
        storeFile(Type.MODEL, modelClassGenerator.generatedFilePath(), mmd.generate(annotator != null ? new String[] { "io.quarkus.runtime.annotations.RegisterForReflection" } : new String[0]));
    }
    for (OutputModelClassGenerator modelClassGenerator : processIdToOutputModelGenerator.values()) {
        ModelMetaData mmd = modelClassGenerator.generate();
        storeFile(Type.MODEL, modelClassGenerator.generatedFilePath(), mmd.generate(annotator != null ? new String[] { "io.quarkus.runtime.annotations.RegisterForReflection" } : new String[0]));
    }
    for (List<UserTaskModelMetaData> utmd : processIdToUserTaskModel.values()) {
        for (UserTaskModelMetaData ut : utmd) {
            storeFile(Type.MODEL, UserTasksModelClassGenerator.generatedFilePath(ut.getInputModelClassName()), ut.generateInput());
            storeFile(Type.MODEL, UserTasksModelClassGenerator.generatedFilePath(ut.getOutputModelClassName()), ut.generateOutput());
        }
    }
    for (AbstractResourceGenerator resourceGenerator : rgs) {
        storeFile(Type.REST, resourceGenerator.generatedFilePath(), resourceGenerator.generate());
    }
    for (AbstractResourceGenerator resourceGenerator : grapggs) {
        storeFile(Type.GRAPHQL, resourceGenerator.generatedFilePath(), resourceGenerator.generate());
    }
    for (FunctionGenerator functionGenerator : fgs) {
        storeFile(Type.FUNCTION, functionGenerator.generatedFilePath(), functionGenerator.generate());
    }
    for (FunctionFlowGenerator functionFlowGenerator : ffgs) {
        storeFile(Type.FUNCTION_FLOW, functionFlowGenerator.generatedFilePath(), functionFlowGenerator.generate());
    }
    for (MessageDataEventGenerator messageDataEventGenerator : mdegs) {
        storeFile(Type.CLASS, messageDataEventGenerator.generatedFilePath(), messageDataEventGenerator.generate());
    }
    for (MessageConsumerGenerator messageConsumerGenerator : megs) {
        storeFile(Type.MESSAGE_CONSUMER, messageConsumerGenerator.generatedFilePath(), messageConsumerGenerator.generate());
    }
    for (MessageProducerGenerator messageProducerGenerator : mpgs) {
        storeFile(Type.MESSAGE_PRODUCER, messageProducerGenerator.generatedFilePath(), messageProducerGenerator.generate());
    }
    for (OpenAPIClientGenerator openApiClientGenerator : opgs) {
        openApiClientGenerator.generate();
        Map<String, String> contents = openApiClientGenerator.generatedClasses();
        for (Entry<String, String> entry : contents.entrySet()) {
            storeFile(Type.CLASS, entry.getKey().replace('.', '/') + ".java", entry.getValue());
        }
    }
    for (ProcessGenerator p : ps) {
        storeFile(Type.PROCESS, p.generatedFilePath(), p.generate());
        p.getAdditionalClasses().forEach(cp -> {
            String packageName = cp.getPackageDeclaration().map(pd -> pd.getName().toString()).orElse("");
            String clazzName = cp.findFirst(ClassOrInterfaceDeclaration.class).map(cls -> cls.getName().toString()).get();
            String path = (packageName + "." + clazzName).replace('.', '/') + ".java";
            storeFile(Type.CLASS, path, cp.toString());
        });
    }
    for (ProcessInstanceGenerator pi : pis) {
        storeFile(Type.PROCESS_INSTANCE, pi.generatedFilePath(), pi.generate());
    }
    for (ProcessExecutableModelGenerator processGenerator : processExecutableModelGenerators) {
        if (processGenerator.isPublic()) {
            publicProcesses.add(processGenerator.extractedProcessId());
        }
    }
    return generatedFiles;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) XmlProcessReader(io.automatiko.engine.workflow.compiler.xml.XmlProcessReader) Type(io.automatiko.engine.codegen.GeneratedFile.Type) LoggerFactory(org.slf4j.LoggerFactory) ApplicationSection(io.automatiko.engine.codegen.ApplicationSection) ApplicationGenerator.log(io.automatiko.engine.codegen.ApplicationGenerator.log) DefaultResourceGeneratorFactory(io.automatiko.engine.codegen.DefaultResourceGeneratorFactory) Resource(io.automatiko.engine.api.io.Resource) Map(java.util.Map) ZipFile(java.util.zip.ZipFile) TriggerMetaData(io.automatiko.engine.workflow.compiler.canonical.TriggerMetaData) DependencyInjectionAnnotator(io.automatiko.engine.codegen.di.DependencyInjectionAnnotator) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) Process(io.automatiko.engine.api.definition.process.Process) BPMNExtensionsSemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNExtensionsSemanticModule) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) StandardCharsets(java.nio.charset.StandardCharsets) InternalResource(io.automatiko.engine.services.io.InternalResource) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) BPMNDISemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNDISemanticModule) SAXException(org.xml.sax.SAXException) Entry(java.util.Map.Entry) ResourceType.determineResourceType(io.automatiko.engine.api.io.ResourceType.determineResourceType) Optional(java.util.Optional) ModelMetaData(io.automatiko.engine.workflow.compiler.canonical.ModelMetaData) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) ResourceGeneratorFactory(io.automatiko.engine.codegen.ResourceGeneratorFactory) ProcessToExecModelGenerator(io.automatiko.engine.workflow.compiler.canonical.ProcessToExecModelGenerator) SemanticModules(io.automatiko.engine.workflow.compiler.xml.SemanticModules) ServerlessWorkflowParser(io.automatiko.engine.workflow.serverless.parser.ServerlessWorkflowParser) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IoUtils.readBytesFromInputStream(io.automatiko.engine.services.utils.IoUtils.readBytesFromInputStream) StringUtils(io.automatiko.engine.services.utils.StringUtils) ResourceType(io.automatiko.engine.api.io.ResourceType) FileSystemResource(io.automatiko.engine.services.io.FileSystemResource) LinkedHashSet(java.util.LinkedHashSet) UserTaskModelMetaData(io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData) CodegenUtils(io.automatiko.engine.codegen.CodegenUtils) BaseFunctions(io.automatiko.engine.services.execution.BaseFunctions) ConfigGenerator(io.automatiko.engine.codegen.ConfigGenerator) GeneratedFile(io.automatiko.engine.codegen.GeneratedFile) Logger(org.slf4j.Logger) Files(java.nio.file.Files) ApplicationGenerator(io.automatiko.engine.codegen.ApplicationGenerator) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) IOException(java.io.IOException) ProcessConfigGenerator(io.automatiko.engine.codegen.process.config.ProcessConfigGenerator) BPMNSemanticModule(io.automatiko.engine.workflow.bpmn2.xml.BPMNSemanticModule) File(java.io.File) OpenAPIMetaData(io.automatiko.engine.workflow.compiler.canonical.OpenAPIMetaData) ProcessMetaData(io.automatiko.engine.workflow.compiler.canonical.ProcessMetaData) Paths(java.nio.file.Paths) AbstractGenerator(io.automatiko.engine.codegen.AbstractGenerator) Functions(io.automatiko.engine.api.Functions) Collections(java.util.Collections) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) UserTaskModelMetaData(io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData) ProcessToExecModelGenerator(io.automatiko.engine.workflow.compiler.canonical.ProcessToExecModelGenerator) BaseFunctions(io.automatiko.engine.services.execution.BaseFunctions) Functions(io.automatiko.engine.api.Functions) TriggerMetaData(io.automatiko.engine.workflow.compiler.canonical.TriggerMetaData) ModelMetaData(io.automatiko.engine.workflow.compiler.canonical.ModelMetaData) UserTaskModelMetaData(io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData) BaseFunctions(io.automatiko.engine.services.execution.BaseFunctions) ProcessMetaData(io.automatiko.engine.workflow.compiler.canonical.ProcessMetaData) OpenAPIMetaData(io.automatiko.engine.workflow.compiler.canonical.OpenAPIMetaData)

Aggregations

UserTaskModelMetaData (io.automatiko.engine.workflow.compiler.canonical.UserTaskModelMetaData)6 Map (java.util.Map)6 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)4 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)4 CodegenUtils (io.automatiko.engine.codegen.CodegenUtils)4 DependencyInjectionAnnotator (io.automatiko.engine.codegen.di.DependencyInjectionAnnotator)4 StringUtils (io.automatiko.engine.services.utils.StringUtils)4 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)3 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)3 NameExpr (com.github.javaparser.ast.expr.NameExpr)3 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)3 SimpleName (com.github.javaparser.ast.expr.SimpleName)3 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)3 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)3 Functions (io.automatiko.engine.api.Functions)3 Process (io.automatiko.engine.api.definition.process.Process)3 Resource (io.automatiko.engine.api.io.Resource)3 ResourceType (io.automatiko.engine.api.io.ResourceType)3 ResourceType.determineResourceType (io.automatiko.engine.api.io.ResourceType.determineResourceType)3 AbstractGenerator (io.automatiko.engine.codegen.AbstractGenerator)3