Updated task in background

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@101262 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-30 16:01:43 +00:00
parent 1f626c7e87
commit 467f0d717e
1 changed files with 64 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import org.gcube.portlets.user.td.gwtservice.server.trservice.WorkerStateMap;
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession;
import org.gcube.portlets.user.td.gwtservice.shared.task.JobS;
import org.gcube.portlets.user.td.gwtservice.shared.task.State;
import org.gcube.portlets.user.td.gwtservice.shared.task.TaskS;
@ -254,6 +255,23 @@ public class BackgroundOperationMonitorCreator {
logger.debug("ExportMetadata: " + exportMetadata);
operationMonitor.setTrId(SessionUtil.getTRId(session));
break;
case JSONExport:
table = taskWrapper.getTask().getResult().getPrimaryTable();
logger.debug("Table retrived: " + table.toString());
exportMetadata = table.getMetadata(ExportMetadata.class);
logger.debug("ExportMetadata: " + exportMetadata);
operationMonitor.setTrId(SessionUtil.getTRId(session));
trExportMetadata = new TabExportMetadata();
trExportMetadata.setUrl(exportMetadata.getUri());
trExportMetadata.setDestinationType(exportMetadata
.getDestinationType());
trExportMetadata.setExportDate(sdf.format(exportMetadata
.getExportDate()));
saveJSONExportInDestination(exportMetadata);
break;
default:
trId = new TRId();
trId.setId(taskWrapper.getTrId().getId());
@ -381,4 +399,50 @@ public class BackgroundOperationMonitorCreator {
}
}
/**
* Save export json data on Workspace
*
* @param session
* @param user
* @param exportMetadata
* @param exportSession
* @throws TDGWTServiceException
*/
protected void saveJSONExportInDestination(ExportMetadata exportMetadata)
throws TDGWTServiceException {
JSONExportSession exportSession = SessionUtil
.getJSONExportSession(session);
String user = aslSession.getUsername();
logger.debug("Save Export In Destination");
logger.debug("Destination: " + exportSession.getDestination().getId());
if (exportSession.getDestination().getId().compareTo("Workspace") == 0) {
logger.debug("Save on Workspace");
boolean end = SessionUtil.getJSONExportEnd(session);
if (end == false) {
SessionUtil.setJSONExportEnd(session, true);
FilesStorage storage = new FilesStorage();
logger.debug("Create Item On Workspace: [ uri: "
+ exportMetadata.getUri() + " ,user: " + user
+ " ,fileName: " + exportSession.getFileName()
+ " ,fileDescription: "
+ exportSession.getFileDescription()
+ " ,mimetype: application/json" + " ,folder: "
+ exportSession.getItemId() + "]");
storage.createItemOnWorkspace(exportMetadata.getUri(), user,
exportSession.getFileName(),
exportSession.getFileDescription(), "application/json",
exportSession.getItemId());
} else {
logger.debug("getJSONExportEnd(): true");
}
} else {
logger.error("Destination No Present");
throw new TDGWTServiceException(
"Error in export json: no destination present");
}
}
}