From 467f0d717e16096cae6bfbe151f880bd1ccb0ba0 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 30 Oct 2014 16:01:43 +0000 Subject: [PATCH] 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 --- .../BackgroundOperationMonitorCreator.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java index 850b6d2..c2d2582 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java @@ -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"); + } + } + }