use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class ChecklistExample method main.
public static void main(String[] args) {
try {
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(new UserGroupCallback() {
public List<String> getGroupsForUser(String userId) {
List<String> result = new ArrayList<String>();
if ("actor4".equals(userId)) {
result.add("group1");
}
return result;
}
public boolean existsUser(String arg0) {
return true;
}
public boolean existsGroup(String arg0) {
return true;
}
}).addAsset(KieServices.Factory.get().getResources().newClassPathResource("checklist/SampleChecklistProcess.bpmn"), ResourceType.BPMN2).get();
ChecklistManager checklistManager = new DefaultChecklistManager(environment);
long c1 = checklistManager.createContext("org.jbpm.examples.checklist.sample1", "actor1");
List<ChecklistItem> items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task1");
ChecklistItem item1 = findChecklistItem(items, "Task1");
checklistManager.completeTask("actor1", item1.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Adding Extra Task");
String[] actorIds = new String[] { "actor5" };
ChecklistItem itemExtra = checklistManager.addTask("actor5", actorIds, new String[0], "TaskExtra", "2+", c1);
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task2");
ChecklistItem item2 = findChecklistItem(items, "Task2");
checklistManager.claimTask("actor4", item2.getTaskId());
checklistManager.completeTask("actor4", item2.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task3b");
ChecklistItem item3b = findChecklistItem(items, "Task3b");
checklistManager.claimTask("actor3", item3b.getTaskId());
checklistManager.completeTask("actor3", item3b.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task3a");
ChecklistItem item3a = findChecklistItem(items, "Task3a");
checklistManager.completeTask("actor1", item3a.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Extra Task");
itemExtra = findChecklistItem(items, "TaskExtra");
checklistManager.completeTask("actor5", itemExtra.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task4");
ChecklistItem item4 = findChecklistItem(items, "Task4");
checklistManager.completeTask("actor1", item4.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
} catch (Throwable t) {
t.printStackTrace();
}
System.exit(0);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class EvaluationExample method getRuntimeManager.
private static RuntimeManager getRuntimeManager(String process) {
// load up the knowledge base
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().addAsset(KieServices.Factory.get().getResources().newClassPathResource(process), ResourceType.BPMN2).get();
return RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class MultipleInstanceExample method getRuntimeManager.
private static RuntimeManager getRuntimeManager(String process) {
// load up the knowledge base
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().addAsset(KieServices.Factory.get().getResources().newClassPathResource(process), ResourceType.BPMN2).get();
return RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm-work-items by kiegroup.
the class JPAWorkItemHandlerTest method startJPAWIHProcess.
private void startJPAWIHProcess(String action, Product prod) throws Exception {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
RuntimeEnvironment env = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addEnvironmentEntry("org.kie.internal.runtime.manager.TaskServiceFactory", new TaskServiceFactory() {
@Override
public TaskService newTaskService() {
return null;
}
@Override
public void close() {
}
}).addAsset(ResourceFactory.newClassPathResource("JPAWIH.bpmn2"), ResourceType.BPMN2).get();
RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(env);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
KieSession kSession = engine.getKieSession();
JPAWorkItemHandler jpaWih = new JPAWorkItemHandler(P_UNIT, this.getClass().getClassLoader());
kSession.getWorkItemManager().registerWorkItemHandler("JPAWIH", jpaWih);
HashMap<String, Object> params = new HashMap<>();
params.put("action", action);
params.put("obj", prod);
params.put("id", prod.getId());
kSession.startProcess("org.jbpm.JPA_WIH", params);
manager.disposeRuntimeEngine(engine);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class AsyncContinuationSupportTest method testAsyncScriptTask.
@Test(timeout = 10000)
public void testAsyncScriptTask() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-AsyncScriptTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("ExecutorService", executorService).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new SystemOutWorkItemHandler());
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("AsyncScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
processInstance = runtime.getKieSession().getProcessInstance(processInstanceId);
assertNull(processInstance);
List<? extends NodeInstanceLog> logs = runtime.getAuditService().findNodeInstances(processInstanceId);
assertNotNull(logs);
assertEquals(8, logs.size());
}
Aggregations