info=GeneralUtils.buildJSONObject(pid,0);
writeBackToClient( new JSONSuccess(info));
} catch (Exception e) {
String message = "Impossible to write back the responce to the client";
throw new SpagoBIEngineServiceException(getActionName(), message, e);
}
return;
}
super.service(request, response);
HttpSession session=getHttpSession();
// Get document id, must find
// String document_id=null;
// Object document_idO=null;
// document_idO=request.getAttribute("DOCUMENT_ID");
// if(document_idO!=null){
// document_id=document_idO.toString();
// }
// else{
// document_id="";
// logger.error("could not retrieve document id");
// throw new SpagoBIEngineServiceException(getActionName(), "could not find document id");
// }
CommonjWorkContainer container=null;
ProcessesStatusContainer processesStatusContainer = ProcessesStatusContainer.getInstance();
Object o=processesStatusContainer.getPidContainerMap().get(pid);
//recover from session, if does not find means work is completed
//Object o=session.getAttribute("SBI_PROCESS_"+document_id);
try{
int statusWI;
if(o!=null){ // object found in session, work could be not started, running or completed
container=(CommonjWorkContainer)o;
FooRemoteWorkItem fooRwi=container.getFooRemoteWorkItem();
WorkItem wi=container.getWorkItem();
// if WorkItem is not set means work has never been started
if(fooRwi!=null && wi!=null){
statusWI=wi.getStatus();
// if finds that work is finished delete the attribute from session
if(statusWI==WorkEvent.WORK_COMPLETED){
logger.debug("Work is finished - remove from session");
//session.removeAttribute("SBI_PROCESS_"+document_id);
processesStatusContainer.getPidContainerMap().remove(pid);
}
}
else{
// if not workitem is set means that is not started yet or has been cancelled by listener!?!
statusWI=0;
}
}
else{
// No more present in session, so it has been deleted
statusWI=WorkEvent.WORK_COMPLETED;
}
info=GeneralUtils.buildJSONObject(pid,statusWI);
logger.debug(GeneralUtils.getEventMessage(statusWI));
try {
writeBackToClient( new JSONSuccess(info));
} catch (IOException e) {
String message = "Impossible to write back the responce to the client";
throw new SpagoBIEngineServiceException(getActionName(), message, e);
}
}
catch (Exception e) {
logger.error("Error in reading work status");
try {
writeBackToClient( new JSONFailure( e) );
} catch (IOException e1) {
logger.error("Error in reading work status and in writing back to client",e);
throw new SpagoBIEngineServiceException(getActionName(), "Error in reading work status and in writing back to client", e1);
} catch (JSONException e1) {
logger.error("Error in reading work status and in writing back to client",e);
throw new SpagoBIEngineServiceException(getActionName(), "Error in reading work status and in writing back to client", e1);
}
}
logger.debug("OUT");
}