use of org.kie.kogito.process.ProcessConfig in project kogito-runtimes by kiegroup.
the class BpmnProcessCompiler method from.
public List<BpmnProcess> from(ProcessConfig config, Resource... resources) {
try {
BpmnProcesses bpmnProcesses = new BpmnProcesses();
StaticApplication application = new StaticApplication(new StaticConfig(null, config), bpmnProcesses);
List<Process> processes = new ArrayList<>();
XmlProcessReader xmlReader = new XmlProcessReader(getSemanticModules(), Thread.currentThread().getContextClassLoader());
configureProcessReader(xmlReader, config);
for (Resource resource : resources) {
processes.addAll(xmlReader.read(resource.getReader()));
}
List<BpmnProcess> bpmnProcessesList = processes.stream().map(p -> create(p, config, application)).collect(Collectors.toList());
bpmnProcessesList.forEach(p -> {
for (Node node : ((WorkflowProcess) p.get()).getNodesRecursively()) {
processNode(node, bpmnProcessesList);
}
});
return bpmnProcessesList;
} catch (Exception e) {
throw new BpmnProcessReaderException(e);
}
}
use of org.kie.kogito.process.ProcessConfig in project kogito-runtimes by kiegroup.
the class ActivityGenerationModelTest method createProcesses.
protected Map<String, BpmnProcess> createProcesses(Map<String, String> classData, Map<String, KogitoWorkItemHandler> handlers) throws Exception {
MemoryFileSystem srcMfs = new MemoryFileSystem();
MemoryFileSystem trgMfs = new MemoryFileSystem();
String[] sources = new String[classData.size()];
int index = 0;
for (Entry<String, String> entry : classData.entrySet()) {
String fileName = entry.getKey().replaceAll("\\.", "/") + ".java";
sources[index++] = fileName;
srcMfs.write(fileName, entry.getValue().getBytes());
}
CompilationResult result = JAVA_COMPILER.compile(sources, srcMfs, trgMfs, this.getClass().getClassLoader());
assertThat(result).isNotNull();
assertThat(result.getErrors()).hasSize(0);
CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
for (Entry<String, KogitoWorkItemHandler> entry : handlers.entrySet()) {
wiConfig.register(entry.getKey(), entry.getValue());
}
ProcessConfig config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null);
TestClassLoader cl = new TestClassLoader(this.getClass().getClassLoader(), trgMfs.getMap());
Map<String, BpmnProcess> processes = new HashMap<>();
BpmnProcesses bpmnProcesses = new BpmnProcesses();
StaticApplication application = new StaticApplication(new StaticConfig(null, config), bpmnProcesses);
for (String className : classData.keySet()) {
Class<?> processClass = Class.forName(className, true, cl);
Method processMethod = processClass.getMethod("process");
Process process = (Process) processMethod.invoke(null);
assertThat(process).isNotNull();
processes.put(process.getId(), new BpmnProcess(process, config, application));
}
return processes;
}
use of org.kie.kogito.process.ProcessConfig in project kogito-runtimes by kiegroup.
the class JsonSchemaUtilTest method testJsonSchemaPhases.
@Test
<T> void testJsonSchemaPhases() throws IOException {
InputStream in = new ByteArrayInputStream(example.getBytes());
Policy<T>[] policies = new Policy[0];
Map<String, Object> schemaMap = JsonSchemaUtil.load(in);
in.close();
Process<T> process = mock(Process.class);
ProcessInstances<T> processInstances = mock(ProcessInstances.class);
when(process.instances()).thenReturn(processInstances);
ProcessInstance<T> processInstance = mock(ProcessInstance.class);
when(processInstances.findById("pepe", ProcessInstanceReadMode.READ_ONLY)).thenReturn((Optional) Optional.of(processInstance));
WorkItem task = mock(WorkItem.class);
when(processInstance.workItem("task", policies)).thenReturn(task);
when(task.getPhase()).thenReturn("active");
Config config = mock(Config.class);
ProcessConfig processConfig = mock(ProcessConfig.class);
when(config.get(any())).thenReturn(processConfig);
WorkItemHandlerConfig workItemHandlerConfig = mock(WorkItemHandlerConfig.class);
when(processConfig.workItemHandlers()).thenReturn(workItemHandlerConfig);
KogitoWorkItemHandler workItemHandler = new HumanTaskWorkItemHandler();
when(workItemHandlerConfig.forName("Human Task")).thenReturn(workItemHandler);
schemaMap = JsonSchemaUtil.addPhases(process, workItemHandler, "pepe", "task", policies, schemaMap);
assertFalse(((Collection) schemaMap.get("phases")).isEmpty());
}
Aggregations