}
public void completeWorkItem(long id, Map<String, Object> results) {
Environment env = this.kruntime.getEnvironment();
// EntityManager em = (EntityManager) env.get(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);
PersistenceContext context = ((PersistenceContextManager) env.get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER )).getCommandScopedPersistenceContext();
WorkItemInfo workItemInfo = null;
if (this.workItems != null) {
workItemInfo = this.workItems.get(id);
if (workItemInfo != null) {
workItemInfo = context.merge(workItemInfo);
}
}
if (workItemInfo == null) {
workItemInfo = context.findWorkItemInfo( id );
}
// work item may have been aborted
if (workItemInfo != null) {
WorkItem workItem = internalGetWorkItem(workItemInfo);
workItem.setResults(results);
ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
workItem.setState(WorkItem.COMPLETED);
// process instance may have finished already
if (processInstance != null) {
processInstance.signalEvent("workItemCompleted", workItem);
}
context.remove(workItemInfo);
if (workItems != null) {
this.workItems.remove(workItem.getId());
}
}
}