@Test public void testScriptAndWorkItemGeneration() { RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("demo.orders"); factory .variable("order", new ObjectDataType("com.myspace.demo.Order")) .variable("approver", new ObjectDataType("String")) .name("orders") .packageName("com.myspace.demo") .dynamic(false) .version("1.0") .workItemNode(1) .name("Log") .workName("Log") .done() .actionNode(2) .name("Dump order") .action("java", "System.out.println(\"Order has been created \" + order);") .done() .endNode(3) .name("end") .terminate(false) .done() .startNode(4) .name("start") .done() .connection(2, 1) .connection(4, 2) .connection(1, 3); WorkflowProcess process = factory.validate().getProcess(); ProcessMetaData processMetadata = ProcessToExecModelGenerator.INSTANCE.generate(process); assertNotNull(processMetadata, "Dumper should return non null class for process"); logger.debug(processMetadata.getGeneratedClassModel().toString()); assertEquals("orders", processMetadata.getExtractedProcessId()); assertEquals("demo.orders", processMetadata.getProcessId()); assertEquals("orders", processMetadata.getProcessName()); assertEquals("1.0", processMetadata.getProcessVersion()); assertEquals("com.myspace.demo.OrdersProcess", processMetadata.getProcessClassName()); assertNotNull(processMetadata.getGeneratedClassModel()); assertEquals(1, processMetadata.getWorkItems().size()); }
public ProcessMetaData generate(WorkflowProcess process) { CompilationUnit parsedClazzFile = parse(this.getClass().getResourceAsStream(PROCESS_TEMPLATE_FILE)); parsedClazzFile.setPackageDeclaration(process.getPackageName()); Optional<ClassOrInterfaceDeclaration> processClazzOptional = parsedClazzFile.findFirst( ClassOrInterfaceDeclaration.class, sl -> true); String extractedProcessId = extractProcessId(process.getId()); if (!processClazzOptional.isPresent()) { throw new NoSuchElementException("Cannot find class declaration in the template"); } ClassOrInterfaceDeclaration processClazz = processClazzOptional.get(); processClazz.setName(ucFirst(extractedProcessId + PROCESS_CLASS_SUFFIX)); String packageName = parsedClazzFile.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(null); ProcessMetaData metadata = new ProcessMetaData(process.getId(), extractedProcessId, process.getName(), process.getVersion(), packageName, processClazz.getNameAsString()); Optional<MethodDeclaration> processMethod = parsedClazzFile.findFirst(MethodDeclaration.class, sl -> sl .getName() .asString() .equals("process")); processVisitor.visitProcess(process, processMethod.get(), metadata); metadata.setGeneratedClassModel(parsedClazzFile); return metadata; }
ProcessToExecModelGenerator { public ProcessMetaData generate(WorkflowProcess process) { CompilationUnit parsedClazzFile = parse(this.getClass().getResourceAsStream(PROCESS_TEMPLATE_FILE)); parsedClazzFile.setPackageDeclaration(process.getPackageName()); Optional<ClassOrInterfaceDeclaration> processClazzOptional = parsedClazzFile.findFirst( ClassOrInterfaceDeclaration.class, sl -> true); String extractedProcessId = extractProcessId(process.getId()); if (!processClazzOptional.isPresent()) { throw new NoSuchElementException("Cannot find class declaration in the template"); } ClassOrInterfaceDeclaration processClazz = processClazzOptional.get(); processClazz.setName(ucFirst(extractedProcessId + PROCESS_CLASS_SUFFIX)); String packageName = parsedClazzFile.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(null); ProcessMetaData metadata = new ProcessMetaData(process.getId(), extractedProcessId, process.getName(), process.getVersion(), packageName, processClazz.getNameAsString()); Optional<MethodDeclaration> processMethod = parsedClazzFile.findFirst(MethodDeclaration.class, sl -> sl .getName() .asString() .equals("process")); processVisitor.visitProcess(process, processMethod.get(), metadata); metadata.setGeneratedClassModel(parsedClazzFile); return metadata; } }
ProcessToExecModelGenerator { public ProcessMetaData generate(WorkflowProcess process) { CompilationUnit parsedClazzFile = parse(this.getClass().getResourceAsStream(PROCESS_TEMPLATE_FILE)); parsedClazzFile.setPackageDeclaration(process.getPackageName()); Optional<ClassOrInterfaceDeclaration> processClazzOptional = parsedClazzFile.findFirst( ClassOrInterfaceDeclaration.class, sl -> true); String extractedProcessId = extractProcessId(process.getId()); if (!processClazzOptional.isPresent()) { throw new NoSuchElementException("Cannot find class declaration in the template"); } ClassOrInterfaceDeclaration processClazz = processClazzOptional.get(); processClazz.setName(ucFirst(extractedProcessId + PROCESS_CLASS_SUFFIX)); String packageName = parsedClazzFile.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(null); ProcessMetaData metadata = new ProcessMetaData(process.getId(), extractedProcessId, process.getName(), process.getVersion(), packageName, processClazz.getNameAsString()); Optional<MethodDeclaration> processMethod = parsedClazzFile.findFirst(MethodDeclaration.class, sl -> sl .getName() .asString() .equals("process")); processVisitor.visitProcess(process, processMethod.get(), metadata); metadata.setGeneratedClassModel(parsedClazzFile); return metadata; } ProcessToExecModelGenerator(ClassLoader contextClassLoader); }
ProcessToExecModelGenerator { public ProcessMetaData generate(WorkflowProcess process) { CompilationUnit parsedClazzFile = parse(this.getClass().getResourceAsStream(PROCESS_TEMPLATE_FILE)); parsedClazzFile.setPackageDeclaration(process.getPackageName()); Optional<ClassOrInterfaceDeclaration> processClazzOptional = parsedClazzFile.findFirst( ClassOrInterfaceDeclaration.class, sl -> true); String extractedProcessId = extractProcessId(process.getId()); if (!processClazzOptional.isPresent()) { throw new NoSuchElementException("Cannot find class declaration in the template"); } ClassOrInterfaceDeclaration processClazz = processClazzOptional.get(); processClazz.setName(ucFirst(extractedProcessId + PROCESS_CLASS_SUFFIX)); String packageName = parsedClazzFile.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(null); ProcessMetaData metadata = new ProcessMetaData(process.getId(), extractedProcessId, process.getName(), process.getVersion(), packageName, processClazz.getNameAsString()); Optional<MethodDeclaration> processMethod = parsedClazzFile.findFirst(MethodDeclaration.class, sl -> sl .getName() .asString() .equals("process")); processVisitor.visitProcess(process, processMethod.get(), metadata); metadata.setGeneratedClassModel(parsedClazzFile); return metadata; } ProcessToExecModelGenerator(ClassLoader contextClassLoader); ProcessMetaData generate(WorkflowProcess process); MethodDeclaration generateMethod(WorkflowProcess process); ModelMetaData generateModel(WorkflowProcess process); ModelMetaData generateInputModel(WorkflowProcess process); ModelMetaData generateOutputModel(WorkflowProcess process); static String extractModelClassName(String processId); List<UserTaskModelMetaData> generateUserTaskModel(WorkflowProcess process); static String extractProcessId(String processId); }
ProcessToExecModelGenerator { public ProcessMetaData generate(WorkflowProcess process) { CompilationUnit parsedClazzFile = parse(this.getClass().getResourceAsStream(PROCESS_TEMPLATE_FILE)); parsedClazzFile.setPackageDeclaration(process.getPackageName()); Optional<ClassOrInterfaceDeclaration> processClazzOptional = parsedClazzFile.findFirst( ClassOrInterfaceDeclaration.class, sl -> true); String extractedProcessId = extractProcessId(process.getId()); if (!processClazzOptional.isPresent()) { throw new NoSuchElementException("Cannot find class declaration in the template"); } ClassOrInterfaceDeclaration processClazz = processClazzOptional.get(); processClazz.setName(ucFirst(extractedProcessId + PROCESS_CLASS_SUFFIX)); String packageName = parsedClazzFile.getPackageDeclaration().map(NodeWithName::getNameAsString).orElse(null); ProcessMetaData metadata = new ProcessMetaData(process.getId(), extractedProcessId, process.getName(), process.getVersion(), packageName, processClazz.getNameAsString()); Optional<MethodDeclaration> processMethod = parsedClazzFile.findFirst(MethodDeclaration.class, sl -> sl .getName() .asString() .equals("process")); processVisitor.visitProcess(process, processMethod.get(), metadata); metadata.setGeneratedClassModel(parsedClazzFile); return metadata; } ProcessToExecModelGenerator(ClassLoader contextClassLoader); ProcessMetaData generate(WorkflowProcess process); MethodDeclaration generateMethod(WorkflowProcess process); ModelMetaData generateModel(WorkflowProcess process); ModelMetaData generateInputModel(WorkflowProcess process); ModelMetaData generateOutputModel(WorkflowProcess process); static String extractModelClassName(String processId); List<UserTaskModelMetaData> generateUserTaskModel(WorkflowProcess process); static String extractProcessId(String processId); static final ProcessToExecModelGenerator INSTANCE; }