Search in sources :

Example 1 with UserTaskModelMetaData

use of org.jbpm.compiler.canonical.UserTaskModelMetaData in project kogito-runtimes by kiegroup.

the class ProcessResourceGenerator method generate.

public String generate() {
    TemplatedGenerator.Builder templateBuilder = TemplatedGenerator.builder().withFallbackContext(QuarkusKogitoBuildContext.CONTEXT_NAME);
    CompilationUnit clazz = templateBuilder.build(context, getRestTemplateName()).compilationUnitOrThrow();
    clazz.setPackageDeclaration(process.getPackageName());
    clazz.addImport(modelfqcn);
    ClassOrInterfaceDeclaration template = clazz.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow(() -> new NoSuchElementException("Compilation unit doesn't contain a class or interface declaration!"));
    template.setName(resourceClazzName);
    AtomicInteger index = new AtomicInteger(0);
    // Generate signals endpoints
    Optional.ofNullable(signals).ifPresent(signalsMap -> {
        // using template class to the endpoints generation
        CompilationUnit signalClazz = templateBuilder.build(context, REST_SIGNAL_TEMPLATE_NAME).compilationUnitOrThrow();
        ClassOrInterfaceDeclaration signalTemplate = signalClazz.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow(() -> new NoSuchElementException("SignalResourceTemplate class not found!"));
        signalsMap.entrySet().stream().filter(e -> Objects.nonNull(e.getKey())).forEach(entry -> {
            String methodName = "signal_" + index.getAndIncrement();
            String outputType = modelfqcn;
            String signalName = entry.getKey();
            String signalType = entry.getValue();
            signalTemplate.findAll(MethodDeclaration.class).forEach(md -> {
                MethodDeclaration cloned = md.clone();
                BlockStmt body = cloned.getBody().get();
                if (signalType == null) {
                    body.findAll(NameExpr.class, nameExpr -> "data".equals(nameExpr.getNameAsString())).forEach(name -> name.replace(new NullLiteralExpr()));
                }
                template.addMethod(methodName, Keyword.PUBLIC).setType(outputType).setParameters(signalType == null ? NodeList.nodeList(cloned.getParameter(0)) : cloned.getParameters()).setBody(body).setAnnotations(cloned.getAnnotations());
            });
            if (signalType != null) {
                template.findAll(ClassOrInterfaceType.class).forEach(name -> {
                    String identifier = name.getNameAsString();
                    name.setName(identifier.replace("$signalType$", signalType));
                });
            }
            template.findAll(StringLiteralExpr.class).forEach(vv -> {
                String s = vv.getValue();
                String interpolated = s.replace("$signalName$", signalName);
                interpolated = interpolated.replace("$signalPath$", sanitizeName(signalName));
                vv.setString(interpolated);
            });
        });
    });
    // security must be applied before user tasks are added to make sure that user task
    // endpoints are not security annotated as they should restrict access based on user assignments
    securityAnnotated(template);
    Map<String, String> typeInterpolations = new HashMap<>();
    taskModelFactoryUnit = parse(this.getClass().getResourceAsStream("/class-templates/TaskModelFactoryTemplate.java"));
    String taskModelFactorySimpleClassName = ucFirst(ProcessToExecModelGenerator.extractProcessId(processId) + "_" + "TaskModelFactory");
    taskModelFactoryUnit.setPackageDeclaration(process.getPackageName());
    taskModelFactoryClassName = process.getPackageName() + "." + taskModelFactorySimpleClassName;
    ClassOrInterfaceDeclaration taskModelFactoryClass = taskModelFactoryUnit.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow(IllegalStateException::new);
    taskModelFactoryClass.setName(taskModelFactorySimpleClassName);
    typeInterpolations.put("$TaskModelFactory$", taskModelFactoryClassName);
    if (userTasks != null && !userTasks.isEmpty()) {
        CompilationUnit userTaskClazz = templateBuilder.build(context, REST_USER_TASK_TEMPLATE_NAME).compilationUnitOrThrow();
        ClassOrInterfaceDeclaration userTaskTemplate = userTaskClazz.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow(() -> new NoSuchElementException("Compilation unit doesn't contain a class or interface declaration!"));
        MethodDeclaration taskModelFactoryMethod = taskModelFactoryClass.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("from")).orElseThrow(IllegalStateException::new);
        SwitchStmt switchExpr = taskModelFactoryMethod.getBody().map(b -> b.findFirst(SwitchStmt.class).orElseThrow(IllegalStateException::new)).orElseThrow(IllegalStateException::new);
        for (UserTaskModelMetaData userTask : userTasks) {
            String methodSuffix = sanitizeName(userTask.getName()) + "_" + index.getAndIncrement();
            userTaskTemplate.findAll(MethodDeclaration.class).forEach(md -> {
                MethodDeclaration cloned = md.clone();
                template.addMethod(cloned.getName() + "_" + methodSuffix, Keyword.PUBLIC).setType(cloned.getType()).setParameters(cloned.getParameters()).setBody(cloned.getBody().get()).setAnnotations(cloned.getAnnotations());
            });
            template.findAll(StringLiteralExpr.class).forEach(s -> interpolateUserTaskStrings(s, userTask));
            template.findAll(ClassOrInterfaceType.class).forEach(c -> interpolateUserTaskTypes(c, userTask));
            template.findAll(NameExpr.class).forEach(c -> interpolateUserTaskNameExp(c, userTask));
            if (!userTask.isAdHoc()) {
                template.findAll(MethodDeclaration.class).stream().filter(md -> md.getNameAsString().equals("signal_" + methodSuffix)).collect(Collectors.toList()).forEach(template::remove);
            }
            switchExpr.getEntries().add(0, userTask.getModelSwitchEntry());
        }
    }
    typeInterpolations.put("$Clazz$", resourceClazzName);
    typeInterpolations.put("$Type$", dataClazzName);
    template.findAll(StringLiteralExpr.class).forEach(this::interpolateStrings);
    template.findAll(ClassOrInterfaceType.class).forEach(cls -> interpolateTypes(cls, typeInterpolations));
    TagResourceGenerator.addTags(clazz, process);
    template.findAll(MethodDeclaration.class).forEach(this::interpolateMethods);
    if (context.hasDI()) {
        template.findAll(FieldDeclaration.class, CodegenUtils::isProcessField).forEach(fd -> context.getDependencyInjectionAnnotator().withNamedInjection(fd, processId));
    } else {
        template.findAll(FieldDeclaration.class, CodegenUtils::isProcessField).forEach(this::initializeProcessField);
    }
    // if triggers are not empty remove createResource method as there is another trigger to start process instances
    if ((!startable && !dynamic) || !isPublic()) {
        Optional<MethodDeclaration> createResourceMethod = template.findFirst(MethodDeclaration.class).filter(md -> md.getNameAsString().equals("createResource_" + processName));
        createResourceMethod.ifPresent(template::remove);
    }
    if (context.hasDI()) {
        context.getDependencyInjectionAnnotator().withApplicationComponent(template);
    }
    enableValidation(template);
    template.getMembers().sort(new BodyDeclarationComparator());
    return clazz.toString();
}
Also used : TemplatedGenerator(org.kie.kogito.codegen.api.template.TemplatedGenerator) CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ProcessToExecModelGenerator(org.jbpm.compiler.canonical.ProcessToExecModelGenerator) Parameter(com.github.javaparser.ast.body.Parameter) StaticJavaParser.parse(com.github.javaparser.StaticJavaParser.parse) HashMap(java.util.HashMap) BodyDeclarationComparator(org.kie.kogito.codegen.core.BodyDeclarationComparator) GeneratorConfig(org.kie.kogito.codegen.core.GeneratorConfig) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Type(com.github.javaparser.ast.type.Type) UserTaskModelMetaData(org.jbpm.compiler.canonical.UserTaskModelMetaData) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Map(java.util.Map) SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) CodegenUtils.interpolateTypes(org.kie.kogito.codegen.core.CodegenUtils.interpolateTypes) CompilationUnit(com.github.javaparser.ast.CompilationUnit) NoSuchElementException(java.util.NoSuchElementException) Keyword(com.github.javaparser.ast.Modifier.Keyword) NodeList(com.github.javaparser.ast.NodeList) SimpleName(com.github.javaparser.ast.expr.SimpleName) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) TemplatedGenerator(org.kie.kogito.codegen.api.template.TemplatedGenerator) StringUtils.ucFirst(org.drools.util.StringUtils.ucFirst) NameExpr(com.github.javaparser.ast.expr.NameExpr) Collectors(java.util.stream.Collectors) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) Objects(java.util.Objects) List(java.util.List) QuarkusKogitoBuildContext(org.kie.kogito.codegen.api.context.impl.QuarkusKogitoBuildContext) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) StringUtils(org.drools.util.StringUtils) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) CodegenUtils(org.kie.kogito.codegen.core.CodegenUtils) Optional(java.util.Optional) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) UserTaskModelMetaData(org.jbpm.compiler.canonical.UserTaskModelMetaData) SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) HashMap(java.util.HashMap) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) 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) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BodyDeclarationComparator(org.kie.kogito.codegen.core.BodyDeclarationComparator) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with UserTaskModelMetaData

use of org.jbpm.compiler.canonical.UserTaskModelMetaData in project kogito-runtimes by kiegroup.

the class ProcessCodegen method internalGenerate.

@Override
protected Collection<GeneratedFile> internalGenerate() {
    List<ProcessGenerator> ps = new ArrayList<>();
    List<ProcessInstanceGenerator> pis = new ArrayList<>();
    List<ProcessExecutableModelGenerator> processExecutableModelGenerators = new ArrayList<>();
    // REST resources
    List<ProcessResourceGenerator> rgs = new ArrayList<>();
    // message endpoints/consumers
    List<MessageConsumerGenerator> megs = new ArrayList<>();
    // message producers
    List<MessageProducerGenerator> mpgs = new ArrayList<>();
    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<>();
    // first we generate all the data classes from variable declarations
    for (WorkflowProcess workFlowProcess : processes.values()) {
        ModelClassGenerator mcg = new ModelClassGenerator(context(), workFlowProcess);
        processIdToModelGenerator.put(workFlowProcess.getId(), mcg);
        InputModelClassGenerator imcg = new InputModelClassGenerator(context(), workFlowProcess);
        processIdToInputModelGenerator.put(workFlowProcess.getId(), imcg);
        OutputModelClassGenerator omcg = new OutputModelClassGenerator(context(), workFlowProcess);
        processIdToOutputModelGenerator.put(workFlowProcess.getId(), omcg);
    }
    // then we generate user task inputs and outputs if any
    for (WorkflowProcess workFlowProcess : processes.values()) {
        UserTasksModelClassGenerator utcg = new UserTasksModelClassGenerator(workFlowProcess);
        processIdToUserTaskModel.put(workFlowProcess.getId(), utcg.generate());
    }
    // then we can instantiate the exec model generator
    // with the data classes that we have already resolved
    ProcessToExecModelGenerator execModelGenerator = new ProcessToExecModelGenerator(context().getClassLoader());
    // collect all process descriptors (exec model)
    for (KogitoWorkflowProcess workFlowProcess : processes.values()) {
        ProcessExecutableModelGenerator execModelGen = new ProcessExecutableModelGenerator(workFlowProcess, execModelGenerator);
        String packageName = workFlowProcess.getPackageName();
        String id = workFlowProcess.getId();
        try {
            ProcessMetaData generate = execModelGen.generate();
            processIdToMetadata.put(id, generate);
            processExecutableModelGenerators.add(execModelGen);
        } catch (RuntimeException e) {
            throw new ProcessCodegenException(id, packageName, e);
        }
    }
    // generate Process, ProcessInstance classes and the REST resource
    for (ProcessExecutableModelGenerator execModelGen : processExecutableModelGenerators) {
        String classPrefix = StringUtils.ucFirst(execModelGen.extractedProcessId());
        KogitoWorkflowProcess workFlowProcess = execModelGen.process();
        ModelClassGenerator modelClassGenerator = processIdToModelGenerator.get(execModelGen.getProcessId());
        ProcessGenerator p = new ProcessGenerator(context(), workFlowProcess, execModelGen, classPrefix, modelClassGenerator.className(), applicationCanonicalName());
        ProcessInstanceGenerator pi = new ProcessInstanceGenerator(workFlowProcess.getPackageName(), classPrefix, modelClassGenerator.generate());
        ProcessMetaData metaData = processIdToMetadata.get(workFlowProcess.getId());
        // Creating and adding the ResourceGenerator
        ProcessResourceGenerator processResourceGenerator = new ProcessResourceGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName());
        processResourceGenerator.withUserTasks(processIdToUserTaskModel.get(workFlowProcess.getId())).withSignals(metaData.getSignals()).withTriggers(metaData.isStartable(), metaData.isDynamic());
        rgs.add(processResourceGenerator);
        if (metaData.getTriggers() != null) {
            for (TriggerMetaData trigger : metaData.getTriggers()) {
                // generate message consumers for processes with message start events
                if (trigger.getType().equals(TriggerMetaData.TriggerType.ConsumeMessage)) {
                    MessageConsumerGenerator messageConsumerGenerator = new MessageConsumerGenerator(context(), workFlowProcess, modelClassGenerator.className(), execModelGen.className(), applicationCanonicalName(), trigger);
                    megs.add(messageConsumerGenerator);
                    metaData.getConsumers().put(trigger.getName(), messageConsumerGenerator.compilationUnit());
                } else if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) {
                    MessageProducerGenerator messageProducerGenerator = new MessageProducerGenerator(context(), workFlowProcess, trigger);
                    mpgs.add(messageProducerGenerator);
                    metaData.getProducers().put(trigger.getName(), messageProducerGenerator.compilationUnit());
                }
            }
        }
        processGenerators.add(p);
        ps.add(p);
        pis.add(pi);
    }
    for (ModelClassGenerator modelClassGenerator : processIdToModelGenerator.values()) {
        ModelMetaData mmd = modelClassGenerator.generate();
        storeFile(MODEL_TYPE, modelClassGenerator.generatedFilePath(), mmd.generate());
    }
    for (InputModelClassGenerator modelClassGenerator : processIdToInputModelGenerator.values()) {
        ModelMetaData mmd = modelClassGenerator.generate();
        storeFile(MODEL_TYPE, modelClassGenerator.generatedFilePath(), mmd.generate());
    }
    for (OutputModelClassGenerator modelClassGenerator : processIdToOutputModelGenerator.values()) {
        ModelMetaData mmd = modelClassGenerator.generate();
        storeFile(MODEL_TYPE, modelClassGenerator.generatedFilePath(), mmd.generate());
    }
    for (List<UserTaskModelMetaData> utmd : processIdToUserTaskModel.values()) {
        for (UserTaskModelMetaData ut : utmd) {
            storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getInputModelClassName()), ut.generateInput());
            storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getOutputModelClassName()), ut.generateOutput());
            storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(ut.getTaskModelClassName()), ut.generateModel());
        }
    }
    // Generating the Producer classes for Dependency Injection
    StaticDependencyInjectionProducerGenerator.of(context()).generate().entrySet().forEach(entry -> storeFile(PRODUCER_TYPE, entry.getKey(), entry.getValue()));
    if (context().hasRESTForGenerator(this)) {
        for (ProcessResourceGenerator resourceGenerator : rgs) {
            storeFile(REST_TYPE, resourceGenerator.generatedFilePath(), resourceGenerator.generate());
            storeFile(MODEL_TYPE, UserTasksModelClassGenerator.generatedFilePath(resourceGenerator.getTaskModelFactoryClassName()), resourceGenerator.getTaskModelFactory());
        }
    }
    for (MessageConsumerGenerator messageConsumerGenerator : megs) {
        storeFile(MESSAGE_CONSUMER_TYPE, messageConsumerGenerator.generatedFilePath(), messageConsumerGenerator.generate());
    }
    for (MessageProducerGenerator messageProducerGenerator : mpgs) {
        storeFile(MESSAGE_PRODUCER_TYPE, messageProducerGenerator.generatedFilePath(), messageProducerGenerator.generate());
    }
    for (ProcessGenerator p : ps) {
        storeFile(PROCESS_TYPE, 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(GeneratedFileType.SOURCE, path, cp.toString());
        });
    }
    if ((context().getAddonsConfig().useProcessSVG())) {
        Map<String, byte[]> svgs = context().getContextAttribute(ContextAttributesConstants.PROCESS_AUTO_SVG_MAPPING, Map.class);
        svgs.keySet().stream().forEach(key -> storeFile(GeneratedFileType.INTERNAL_RESOURCE, "META-INF/processSVG/" + key + ".svg", svgs.get(key)));
    }
    if (context().hasRESTForGenerator(this)) {
        final ProcessCloudEventMetaFactoryGenerator topicsGenerator = new ProcessCloudEventMetaFactoryGenerator(context(), processExecutableModelGenerators);
        storeFile(REST_TYPE, topicsGenerator.generatedFilePath(), topicsGenerator.generate());
    }
    for (ProcessInstanceGenerator pi : pis) {
        storeFile(PROCESS_INSTANCE_TYPE, pi.generatedFilePath(), pi.generate());
    }
    // generate Grafana dashboards
    if (context().getAddonsConfig().usePrometheusMonitoring()) {
        Optional<String> globalDbJson = generateOperationalDashboard(GLOBAL_OPERATIONAL_DASHBOARD_TEMPLATE, "Global", context().getPropertiesMap(), "Global", context().getGAV().orElse(KogitoGAV.EMPTY_GAV), false);
        String globalDbName = buildDashboardName(context().getGAV(), "Global");
        globalDbJson.ifPresent(dashboard -> generatedFiles.addAll(DashboardGeneratedFileUtils.operational(dashboard, globalDbName + ".json")));
        for (KogitoWorkflowProcess process : processes.values()) {
            String dbName = buildDashboardName(context().getGAV(), process.getId());
            Optional<String> dbJson = generateOperationalDashboard(PROCESS_OPERATIONAL_DASHBOARD_TEMPLATE, process.getId(), context().getPropertiesMap(), process.getId(), context().getGAV().orElse(KogitoGAV.EMPTY_GAV), false);
            dbJson.ifPresent(dashboard -> generatedFiles.addAll(DashboardGeneratedFileUtils.operational(dashboard, dbName + ".json")));
        }
    }
    return generatedFiles;
}
Also used : Arrays(java.util.Arrays) ServerlessWorkflowParser(org.kie.kogito.serverless.workflow.parser.ServerlessWorkflowParser) ProcessToExecModelGenerator(org.jbpm.compiler.canonical.ProcessToExecModelGenerator) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) LoggerFactory(org.slf4j.LoggerFactory) ProcessCloudEventMetaFactoryGenerator(org.kie.kogito.codegen.process.events.ProcessCloudEventMetaFactoryGenerator) SemanticModules(org.jbpm.compiler.xml.core.SemanticModules) BPMNSemanticModule(org.jbpm.bpmn2.xml.BPMNSemanticModule) CollectedResource(org.kie.kogito.codegen.api.io.CollectedResource) Map(java.util.Map) ModelMetaData(org.jbpm.compiler.canonical.ModelMetaData) KogitoBuildContext(org.kie.kogito.codegen.api.context.KogitoBuildContext) ValidationLogDecorator(org.kie.kogito.process.validation.ValidationLogDecorator) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) Set(java.util.Set) ApplicationSection(org.kie.kogito.codegen.api.ApplicationSection) Reader(java.io.Reader) BPMNDISemanticModule(org.jbpm.bpmn2.xml.BPMNDISemanticModule) String.format(java.lang.String.format) Resource(org.kie.api.io.Resource) BPMNExtensionsSemanticModule(org.jbpm.bpmn2.xml.BPMNExtensionsSemanticModule) List(java.util.List) Stream(java.util.stream.Stream) ProcessConfigGenerator(org.kie.kogito.codegen.process.config.ProcessConfigGenerator) SAXException(org.xml.sax.SAXException) Optional(java.util.Optional) ValidationException(org.kie.kogito.process.validation.ValidationException) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) GeneratedFileType(org.drools.codegen.common.GeneratedFileType) TriggerMetaData(org.jbpm.compiler.canonical.TriggerMetaData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProcessValidatorRegistry(org.jbpm.process.core.validation.ProcessValidatorRegistry) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) ContextAttributesConstants(org.kie.kogito.codegen.api.context.ContextAttributesConstants) ValidationContext(org.kie.kogito.process.validation.ValidationContext) GrafanaConfigurationWriter.generateOperationalDashboard(org.kie.kogito.grafana.GrafanaConfigurationWriter.generateOperationalDashboard) UserTaskModelMetaData(org.jbpm.compiler.canonical.UserTaskModelMetaData) AbstractGenerator(org.kie.kogito.codegen.core.AbstractGenerator) GrafanaConfigurationWriter.buildDashboardName(org.kie.kogito.grafana.GrafanaConfigurationWriter.buildDashboardName) Logger(org.slf4j.Logger) IOException(java.io.IOException) File(java.io.File) GeneratedInfo(org.kie.kogito.codegen.api.GeneratedInfo) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData) Collectors.toList(java.util.stream.Collectors.toList) KogitoGAV(org.kie.kogito.KogitoGAV) StringUtils(org.drools.util.StringUtils) DashboardGeneratedFileUtils(org.kie.kogito.codegen.core.DashboardGeneratedFileUtils) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) SourceFileCodegenBindEvent(org.kie.kogito.codegen.api.SourceFileCodegenBindEvent) Collections(java.util.Collections) GeneratedFile(org.drools.codegen.common.GeneratedFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) UserTaskModelMetaData(org.jbpm.compiler.canonical.UserTaskModelMetaData) ProcessToExecModelGenerator(org.jbpm.compiler.canonical.ProcessToExecModelGenerator) KogitoWorkflowProcess(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess) ProcessCloudEventMetaFactoryGenerator(org.kie.kogito.codegen.process.events.ProcessCloudEventMetaFactoryGenerator) TriggerMetaData(org.jbpm.compiler.canonical.TriggerMetaData) ModelMetaData(org.jbpm.compiler.canonical.ModelMetaData) UserTaskModelMetaData(org.jbpm.compiler.canonical.UserTaskModelMetaData) ProcessMetaData(org.jbpm.compiler.canonical.ProcessMetaData)

Example 3 with UserTaskModelMetaData

use of org.jbpm.compiler.canonical.UserTaskModelMetaData in project kogito-runtimes by kiegroup.

the class ActivityGenerationModelTest method testUserTaskProcessWithTaskModels.

@Test
public void testUserTaskProcessWithTaskModels() throws Exception {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    List<UserTaskModelMetaData> models = ProcessToExecModelGenerator.INSTANCE.generateUserTaskModel((WorkflowProcess) process.get());
    for (UserTaskModelMetaData metaData : models) {
        String content = metaData.generateInput();
        assertThat(content).isNotNull();
        log(content);
        content = metaData.generateOutput();
        assertThat(content).isNotNull();
        log(content);
    }
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) UserTaskModelMetaData(org.jbpm.compiler.canonical.UserTaskModelMetaData) ClassPathResource(org.drools.util.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Aggregations

UserTaskModelMetaData (org.jbpm.compiler.canonical.UserTaskModelMetaData)3 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 StringUtils (org.drools.util.StringUtils)2 ProcessToExecModelGenerator (org.jbpm.compiler.canonical.ProcessToExecModelGenerator)2 StaticJavaParser.parse (com.github.javaparser.StaticJavaParser.parse)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 Keyword (com.github.javaparser.ast.Modifier.Keyword)1 NodeList (com.github.javaparser.ast.NodeList)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 Parameter (com.github.javaparser.ast.body.Parameter)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)1 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)1 SimpleName (com.github.javaparser.ast.expr.SimpleName)1 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)1