use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class RequestUI method createKieSession.
private KieSession createKieSession() {
try {
final KieSession ksession = getKieSession();
KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
UIWorkItemHandler handler = new UIWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
handler.setVisible(true);
ksession.getWorkItemManager().registerWorkItemHandler("Email", new WorkItemHandler() {
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println("Sending email ...");
manager.completeWorkItem(workItem.getId(), null);
}
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
});
Person person = new Person("john", "John Doe");
person.setAge(40);
ksession.insert(person);
person = new Person("krisv", "Kris Verlaenen");
person.setAge(30);
ksession.insert(person);
person = new Person("baby", "Baby");
person.setAge(1);
ksession.insert(person);
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
ksession.insert(event);
}
});
return ksession;
} catch (Throwable t) {
throw new RuntimeException("Could not initialize session!", t);
}
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class UIWorkItemHandler method select.
private void select() {
WorkItem workItem = getSelectedWorkItem();
if (workItem != null) {
UIWorkItemHandlerDialog dialog = new UIWorkItemHandlerDialog(UIWorkItemHandler.this, workItem);
dialog.setVisible(true);
}
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class UIWorkItemHandler method reloadWorkItemsList.
private void reloadWorkItemsList() {
List<WorkItemWrapper> result = new ArrayList<WorkItemWrapper>();
for (Iterator<WorkItem> iterator = workItems.keySet().iterator(); iterator.hasNext(); ) {
WorkItem workItem = iterator.next();
result.add(new WorkItemWrapper(workItem));
}
workItemsList.setListData(result.toArray());
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessServiceImpl method abortWorkItem.
@Override
public void abortWorkItem(String deploymentId, Long processInstanceId, Long id) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
if (workItem == null) {
throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
}
ksession.getWorkItemManager().abortWorkItem(id);
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessServiceImpl method getWorkItem.
@Override
public WorkItem getWorkItem(String deploymentId, Long processInstanceId, Long id) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
if (workItem == null) {
throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
}
return workItem;
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
Aggregations