private JSONObject handleSnapshotExecution(Integer snapshotId) {
JSONObject response= null;
ISnapshotDAO dao;
Snapshot snapshot;
BIObject obj;
String url;
ExecutionInstance executionInstance;
logger.debug("IN");
try {
executionInstance = getContext().getExecutionInstance( ExecutionInstance.class.getName() );
Assert.assertNotNull(executionInstance, "Execution instance cannot be null in order to properly generate execution url");
// we are not executing a subobject, so delete subobject if existing
executionInstance.setSubObject(null);
dao = null;
try {
dao = DAOFactory.getSnapshotDAO();
} catch (EMFUserError e) {
logger.error("Error while istantiating DAO", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Cannot access database", e);
}
Assert.assertNotNull(dao, "An internal error occurred while istantiating DAO. DAO cannot be null.");
snapshot = null;
try {
snapshot = dao.loadSnapshot(snapshotId);
} catch (EMFUserError e) {
logger.error("Snapshot with id = " + snapshotId + " not found", e);
throw new SpagoBIServiceException(SERVICE_NAME, "Scheduled execution not found", e);
}
Assert.assertNotNull(dao, "An internal error occurred while loading snapshot [" + snapshotId + "]. Snapshot cannot be null.");
obj = executionInstance.getBIObject();
if (obj.getId().equals(snapshot.getBiobjId())) {
executionInstance.setSnapshot(snapshot);
url = executionInstance.getSnapshotUrl();
response = new JSONObject();
try {
response.put("url", url);