diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index c0d36b1..2661f51 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -16,6 +16,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.file.HeaderPresence; import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; +import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor; @@ -541,6 +542,17 @@ public interface TDGWTService extends RemoteService { public String startSDMXExport(SDMXExportSession exportSession) throws TDGWTServiceException; + // Export JSON + /** + * Start JSON Export and invokes the client library + * + * @param jsonExportSession + * @return + * @throws TDGWTServiceException + */ + public String startJSONExport(JSONExportSession jsonExportSession) + throws TDGWTServiceException; + // Table Operations /** @@ -864,7 +876,6 @@ public interface TDGWTService extends RemoteService { OperationMonitorSession operationMonitorSession) throws TDGWTServiceException; - /** * Get List of Background Operation Monitor * diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index d096c46..e393687 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -15,6 +15,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.file.HeaderPresence; import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; +import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor; @@ -212,6 +213,10 @@ public interface TDGWTServiceAsync { void startSDMXExport(SDMXExportSession exportSession, AsyncCallback callback); + // Export JSON + void startJSONExport(JSONExportSession jsonExportSession, + AsyncCallback callback); + // Table Operation void startChangeTableType(ChangeTableTypeSession changeTableTypeSession, AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java index fd1ea5e..eeddaab 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionConstants.java @@ -35,6 +35,9 @@ public class SessionConstants { protected static final String CSV_EXPORT_SESSION = "CSV_EXPORT_SESSION"; protected static final String CSV_EXPORT_END = "CSV_EXPORT_END"; + protected static final String JSON_EXPORT_SESSION = "JSON_EXPORT_SESSION"; + protected static final String JSON_EXPORT_END = "JSON_EXPORT_END"; + protected static final String CLONE_TABULAR_RESOURCE_SESSION = "CLONE_TABULAR_RESOURCE_SESSION"; protected static final String CHANGE_COLUMN_TYPE_SESSION = "CHANGE_COLUMN_TYPE_SESSION"; diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java index 891338d..7e162b6 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/SessionUtil.java @@ -24,6 +24,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpire import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession; import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; +import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession; import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource; @@ -76,7 +77,7 @@ public class SessionUtil { ASLSession session; if (username == null) { logger.warn("no user found in session, using test one"); - throw new TDGWTSessionExpiredException("Session Expired!"); + throw new TDGWTSessionExpiredException("Session Expired!"); // Remove comment for Test /* @@ -308,6 +309,29 @@ public class SessionUtil { return exportSession; } + // + public static void setJSONExportSession(HttpSession httpSession, + JSONExportSession s) throws TDGWTSessionExpiredException { + + JSONExportSession session = (JSONExportSession) httpSession + .getAttribute(SessionConstants.JSON_EXPORT_SESSION); + if (session != null) + httpSession.removeAttribute(SessionConstants.JSON_EXPORT_SESSION); + httpSession.setAttribute(SessionConstants.JSON_EXPORT_SESSION, s); + ASLSession aslSession = getAslSession(httpSession); + ScopeProvider.instance.set(aslSession.getScope().toString()); + } + + public static JSONExportSession getJSONExportSession(HttpSession httpSession) { + JSONExportSession exportSession = (JSONExportSession) httpSession + .getAttribute(SessionConstants.JSON_EXPORT_SESSION); + if (exportSession == null) { + logger.error("JSONExportSession was not acquired"); + } + return exportSession; + } + + // public static void setCSVFileUploadSession(HttpSession httpSession, CSVFileUploadSession s) throws TDGWTSessionExpiredException { @@ -447,6 +471,7 @@ public class SessionUtil { return sdmxClient; } + // public static void setCSVExportEnd(HttpSession httpSession, Boolean end) { Boolean fin = (Boolean) httpSession .getAttribute(SessionConstants.CSV_EXPORT_END); @@ -466,6 +491,27 @@ public class SessionUtil { return end; } + // + public static void setJSONExportEnd(HttpSession httpSession, Boolean end) { + Boolean fin = (Boolean) httpSession + .getAttribute(SessionConstants.JSON_EXPORT_END); + if (fin != null) + httpSession.removeAttribute(SessionConstants.JSON_EXPORT_END); + httpSession.setAttribute(SessionConstants.JSON_EXPORT_END, end); + } + + public static Boolean getJSONExportEnd(HttpSession httpSession) { + Boolean end = (Boolean) httpSession + .getAttribute(SessionConstants.JSON_EXPORT_END); + logger.debug("getJSONExportEnd(): " + end); + if (end == null) { + logger.error("JSON_EXPORT_END was not acquired"); + end = false; + } + return end; + } + + // public static TRTasksManager getTRTasksManager(HttpSession httpSession) { TRTasksManager tasksManager = (TRTasksManager) httpSession .getAttribute(SessionConstants.TR_TASK_MANAGER); @@ -633,7 +679,7 @@ public class SessionUtil { filterColumnSession); } - + // public static ReplaceColumnByExpressionSession getReplaceColumnByExpressionSession( HttpSession httpSession) { @@ -643,24 +689,28 @@ public class SessionUtil { return replaceColumnByExpressionSession; } else { replaceColumnByExpressionSession = new ReplaceColumnByExpressionSession(); - httpSession.setAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, + httpSession.setAttribute( + SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, replaceColumnByExpressionSession); return replaceColumnByExpressionSession; } } - public static void setReplaceColumnByExpressionSession(HttpSession httpSession, + public static void setReplaceColumnByExpressionSession( + HttpSession httpSession, ReplaceColumnByExpressionSession replaceColumnByExpressionSession) { ReplaceColumnByExpressionSession rce = (ReplaceColumnByExpressionSession) httpSession .getAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION); if (rce != null) { - httpSession.removeAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION); + httpSession + .removeAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION); } - httpSession.setAttribute(SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, + httpSession.setAttribute( + SessionConstants.REPLACE_COLUMN_BY_EXPRESSION_SESSION, replaceColumnByExpressionSession); } - + // public static TaskResubmitSession getTaskResubmitSession( HttpSession httpSession) { @@ -1278,8 +1328,7 @@ public class SessionUtil { } return taskWrapper; }; - - + public static void removeStartedTask(HttpSession httpSession, TaskWrapper taskWrapper) { if (taskWrapper == null) { @@ -1303,14 +1352,12 @@ public class SessionUtil { httpSession .removeAttribute(SessionConstants.OPERATIONS_TASKS_STARTED); } - - + tasksStarted.remove(taskWrapper.getTask().getId().getValue()); httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_STARTED, tasksStarted); } - public static void setStartedTask(HttpSession httpSession, TaskWrapper taskWrapper) { @@ -1335,22 +1382,21 @@ public class SessionUtil { httpSession .removeAttribute(SessionConstants.OPERATIONS_TASKS_STARTED); } - - + tasksStarted.put(taskWrapper.getTask().getId().getValue(), taskWrapper); httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_STARTED, tasksStarted); } - - public static HashMap getAbortedTaskMap(HttpSession httpSession) { + + public static HashMap getAbortedTaskMap( + HttpSession httpSession) { @SuppressWarnings("unchecked") HashMap tasksAborted = (HashMap) httpSession .getAttribute(SessionConstants.OPERATIONS_TASKS_ABORTED); return tasksAborted; }; - - + public static void setAbortedTasks(HttpSession httpSession, TaskWrapper taskWrapper) { if (taskWrapper == null) { @@ -1379,16 +1425,15 @@ public class SessionUtil { tasksAborted); } - - - public static HashMap getHiddenTaskMap(HttpSession httpSession) { + + public static HashMap getHiddenTaskMap( + HttpSession httpSession) { @SuppressWarnings("unchecked") HashMap hiddenTasks = (HashMap) httpSession .getAttribute(SessionConstants.OPERATIONS_TASKS_HIDDEN); return hiddenTasks; }; - - + public static void setHiddenTask(HttpSession httpSession, TaskWrapper taskWrapper) { if (taskWrapper == null) { @@ -1417,18 +1462,15 @@ public class SessionUtil { hiddenTasks); } - - - public static HashMap getTaskInBackgroundMap(HttpSession httpSession) { + + public static HashMap getTaskInBackgroundMap( + HttpSession httpSession) { @SuppressWarnings("unchecked") HashMap tasksInBackground = (HashMap) httpSession .getAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND); return tasksInBackground; }; - - - public static void setTaskInBackground(HttpSession httpSession, TaskWrapper taskWrapper) { if (taskWrapper == null) { @@ -1452,12 +1494,14 @@ public class SessionUtil { httpSession .removeAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND); } - tasksInBackground.put(taskWrapper.getTask().getId().getValue(), taskWrapper); - httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND, + tasksInBackground.put(taskWrapper.getTask().getId().getValue(), + taskWrapper); + httpSession.setAttribute( + SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND, tasksInBackground); } - + public static void removeTaskInBackground(HttpSession httpSession, TaskWrapper taskWrapper) { if (taskWrapper == null) { @@ -1482,11 +1526,11 @@ public class SessionUtil { .removeAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND); } tasksInBackground.remove(taskWrapper.getTask().getId().getValue()); - httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND, + httpSession.setAttribute( + SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND, tasksInBackground); } - // public static FileUploadMonitor getFileUploadMonitor(HttpSession httpSession) { diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index 3f0b029..adafde0 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -106,6 +106,7 @@ import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession; import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4AddColumn; +import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4CSVExport; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ChangeColumnType; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ChangeTableType; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Clone; @@ -118,6 +119,7 @@ import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Edit import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4ExtractCodelist; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4FilterColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4GroupBy; +import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4JSONExport; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4LabelColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4MergeColumn; import org.gcube.portlets.user.td.gwtservice.server.opexecution.OpExecution4Normalization; @@ -153,6 +155,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadState; import org.gcube.portlets.user.td.gwtservice.shared.file.HeaderPresence; import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory; import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession; +import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData; import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorCreator; import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession; @@ -3417,25 +3420,6 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } - /** - * - * @param exportSession - * @return - */ - protected Map csvExportFileParameter( - CSVExportSession exportSession) { - Map parameterInstances = new HashMap(); - parameterInstances.put(Constants.PARAMETER_ENCODING, - exportSession.getEncoding()); - parameterInstances.put(Constants.PARAMETER_SEPARATOR, - exportSession.getSeparator()); - parameterInstances.put(Constants.PARAMETER_VIEW_COLUMNS, - exportSession.isExportViewColumns()); - parameterInstances.put(Constants.PARAMETER_COLUMNS, - exportSession.getColumnsAsString()); - return parameterInstances; - } - /** * * @param exportSession @@ -3644,26 +3628,21 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } + + /** * * {@inheritDoc} */ + @Override public String startCSVExport(CSVExportSession exportSession) throws TDGWTServiceException { try { logger.debug("Start CSV Export"); HttpSession session = this.getThreadLocalRequest().getSession(); - if (session == null) { - throw new TDGWTServiceException( - "Error retrieving the session: null"); - } - logger.debug("Session:" + session.getId()); - ASLSession aslSession = SessionUtil.getAslSession(session); - - logger.debug("Session User:" + aslSession.getUsername()); - + TRId trId = SessionUtil.getTRId(session); if (trId == null) { throw new TDGWTServiceException( @@ -3677,28 +3656,28 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements SessionUtil.setCSVExportSession(session, exportSession); - Map parameterInstance = csvExportFileParameter(exportSession); - - logger.debug("Tabular Data Service"); - AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); checkTabularResourceLocked(service, trId); - // Export CSV file - OperationDefinition exportCSVFileOperation = OperationDefinitionMap - .map(OperationsId.CSVExport.toString(), service); + OpExecution4CSVExport opEx = new OpExecution4CSVExport( + session, service, exportSession); + OpExecutionDirector director = new OpExecutionDirector(); + director.setOperationExecutionBuilder(opEx); + director.constructOperationExecution(); + OperationExecution invocation = director.getOperationExecution(); - OperationExecution invocation = new OperationExecution( - exportCSVFileOperation.getOperationId(), parameterInstance); + if (invocation == null) { + throw new TDGWTServiceException( + "Error in CSVExport: Operation not supported for now!"); + } + TabularResourceId serviceTR = new TabularResourceId( + Long.valueOf(trId.getId())); logger.debug("OperationInvocation: \n" + invocation.toString()); - Task trTask = service.execute(invocation, new TabularResourceId( - Long.valueOf(trId.getId()))); + Task trTask = service.execute(invocation, serviceTR); logger.debug("Start Task on service: TaskId " + trTask.getId()); - SessionUtil.setCSVExportEnd(session, false); - TaskWrapper taskWrapper = new TaskWrapper(trTask, UIOperationsId.CSVExport, trId); SessionUtil.setStartedTask(session, taskWrapper); @@ -3713,11 +3692,83 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements "Security exception, you haven't rights!"); } catch (Throwable e) { e.printStackTrace(); - throw new TDGWTServiceException("Error in CSVExport: " + throw new TDGWTServiceException("Error in JSON Export: " + e.getLocalizedMessage()); } } + + + + /** + * + * {@inheritDoc} + */ + @Override + public String startJSONExport(JSONExportSession exportSession) + throws TDGWTServiceException { + try { + + logger.debug("Start JSON Export"); + HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + + TRId trId = SessionUtil.getTRId(session); + if (trId == null) { + throw new TDGWTServiceException( + "Error no tabular resource in session"); + } + + if (trId.getTableId() == null) { + throw new TDGWTServiceException( + "Error no table present in session"); + } + + SessionUtil.setJSONExportSession(session, exportSession); + + AuthorizationProvider.instance.set(new AuthorizationToken( + aslSession.getUsername(), aslSession.getScope())); + TabularDataService service = TabularDataServiceFactory.getService(); + checkTabularResourceLocked(service, trId); + + OpExecution4JSONExport opEx = new OpExecution4JSONExport( + session, service, exportSession); + OpExecutionDirector director = new OpExecutionDirector(); + director.setOperationExecutionBuilder(opEx); + director.constructOperationExecution(); + OperationExecution invocation = director.getOperationExecution(); + + if (invocation == null) { + throw new TDGWTServiceException( + "Error in JSONExport: Operation not supported for now!"); + } + + TabularResourceId serviceTR = new TabularResourceId( + Long.valueOf(trId.getId())); + logger.debug("OperationInvocation: \n" + invocation.toString()); + Task trTask = service.execute(invocation, serviceTR); + logger.debug("Start Task on service: TaskId " + trTask.getId()); + TaskWrapper taskWrapper = new TaskWrapper(trTask, + UIOperationsId.JSONExport, trId); + SessionUtil.setStartedTask(session, taskWrapper); + + return trTask.getId().getValue(); + + } catch (TDGWTServiceException e) { + throw e; + } catch (SecurityException e) { + e.printStackTrace(); + throw new TDGWTServiceException( + "Security exception, you haven't rights!"); + } catch (Throwable e) { + e.printStackTrace(); + throw new TDGWTServiceException("Error in JSON Export: " + + e.getLocalizedMessage()); + } + + } + + // TODO UpThis Monitor not updated @@ -3730,10 +3781,11 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements throws TDGWTServiceException { try { HttpSession session = this.getThreadLocalRequest().getSession(); + ASLSession aslSession = SessionUtil.getAslSession(session); + SessionUtil.setChangeColumnTypeSession(session, changeColumnTypeSession); - ASLSession aslSession = SessionUtil.getAslSession(session); - + AuthorizationProvider.instance.set(new AuthorizationToken( aslSession.getUsername(), aslSession.getScope())); TabularDataService service = TabularDataServiceFactory.getService(); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4CSVExport.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4CSVExport.java new file mode 100644 index 0000000..080bc45 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4CSVExport.java @@ -0,0 +1,69 @@ +package org.gcube.portlets.user.td.gwtservice.server.opexecution; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; +import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; +import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +import org.gcube.portlets.user.td.gwtservice.shared.Constants; +import org.gcube.portlets.user.td.gwtservice.shared.OperationsId; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Operation Execution for CSV Export + * + * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it + * + */ +public class OpExecution4CSVExport extends OpExecutionBuilder { + protected static Logger logger = LoggerFactory + .getLogger(OpExecution4CSVExport.class); + + private HttpSession session; + private TabularDataService service; + private CSVExportSession csvExportSession; + + + public OpExecution4CSVExport(HttpSession session, TabularDataService service, + CSVExportSession csvExportSession) { + this.service = service; + this.csvExportSession = csvExportSession; + this.session=session; + } + + @Override + public void buildOpEx() throws TDGWTServiceException { + logger.debug(csvExportSession.toString()); + + SessionUtil.setCSVExportEnd(session, false); + + OperationDefinition operationDefinition; + operationDefinition = OperationDefinitionMap.map( + OperationsId.CSVExport.toString(), service); + Map map = new HashMap(); + + map.put(Constants.PARAMETER_ENCODING, + csvExportSession.getEncoding()); + map.put(Constants.PARAMETER_SEPARATOR, + csvExportSession.getSeparator()); + map.put(Constants.PARAMETER_VIEW_COLUMNS, + csvExportSession.isExportViewColumns()); + map.put(Constants.PARAMETER_COLUMNS, + csvExportSession.getColumnsAsString()); + + OperationExecution invocation = new OperationExecution( + operationDefinition.getOperationId(), map); + + operationExecutionSpec.setOp(invocation); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4JSONExport.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4JSONExport.java new file mode 100644 index 0000000..c78121c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/opexecution/OpExecution4JSONExport.java @@ -0,0 +1,65 @@ +package org.gcube.portlets.user.td.gwtservice.server.opexecution; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationDefinition; +import org.gcube.data.analysis.tabulardata.commons.webservice.types.operations.OperationExecution; +import org.gcube.data.analysis.tabulardata.service.TabularDataService; +import org.gcube.portlets.user.td.gwtservice.server.SessionUtil; +import org.gcube.portlets.user.td.gwtservice.server.trservice.OperationDefinitionMap; +import org.gcube.portlets.user.td.gwtservice.shared.Constants; +import org.gcube.portlets.user.td.gwtservice.shared.OperationsId; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; +import org.gcube.portlets.user.td.gwtservice.shared.json.JSONExportSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Operation Execution for JSON Export + * + * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it + * + */ +public class OpExecution4JSONExport extends OpExecutionBuilder { + protected static Logger logger = LoggerFactory + .getLogger(OpExecution4JSONExport.class); + + private HttpSession session; + private TabularDataService service; + private JSONExportSession jsonExportSession; + + + public OpExecution4JSONExport(HttpSession session, TabularDataService service, + JSONExportSession jsonExportSession) { + this.service = service; + this.jsonExportSession = jsonExportSession; + this.session=session; + } + + @Override + public void buildOpEx() throws TDGWTServiceException { + logger.debug(jsonExportSession.toString()); + + SessionUtil.setJSONExportEnd(session, false); + + OperationDefinition operationDefinition; + operationDefinition = OperationDefinitionMap.map( + OperationsId.JSONExport.toString(), service); + Map map = new HashMap(); + + map.put(Constants.PARAMETER_VIEW_COLUMNS, + jsonExportSession.isExportViewColumns()); + map.put(Constants.PARAMETER_COLUMNS, + jsonExportSession.getColumnsAsString()); + + OperationExecution invocation = new OperationExecution( + operationDefinition.getOperationId(), map); + + operationExecutionSpec.setOp(invocation); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/json/JSONExportSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/json/JSONExportSession.java new file mode 100644 index 0000000..012ea8b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/json/JSONExportSession.java @@ -0,0 +1,117 @@ +/** + * + */ +package org.gcube.portlets.user.td.gwtservice.shared.json; + +import java.io.Serializable; +import java.util.ArrayList; + +import org.gcube.portlets.user.td.gwtservice.shared.destination.Destination; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; + +/** + * + * @author giancarlo email: g.panichi@isti.cnr.it + * + */ +public class JSONExportSession implements Serializable { + + private static final long serialVersionUID = 407790340509190329L; + + protected String id; + protected Destination destination; + protected String itemId; + protected String fileName; + protected String fileDescription; + protected ArrayList columns; + protected boolean exportViewColumns; + + public JSONExportSession() { + super(); + } + + public ArrayList getColumns() { + return columns; + } + + public void setColumns(ArrayList columns) { + this.columns = columns; + } + + public ArrayList getColumnsAsString() { + ArrayList columnsAsString = new ArrayList(); + for (ColumnData cData : columns) { + columnsAsString.add(cData.getColumnId()); + } + return columnsAsString; + } + + public String[] getColumnsAsArrayOfString() { + ArrayList columnsAsString = new ArrayList(); + for (ColumnData cData : columns) { + columnsAsString.add(cData.getColumnId()); + } + return columnsAsString.toArray(new String[columnsAsString.size()]); + } + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Destination getDestination() { + return destination; + } + + public void setDestination(Destination destination) { + this.destination = destination; + } + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getFileDescription() { + return fileDescription; + } + + public void setFileDescription(String fileDescription) { + this.fileDescription = fileDescription; + } + + public boolean isExportViewColumns() { + return exportViewColumns; + } + + public void setExportViewColumns(boolean exportViewColumns) { + this.exportViewColumns = exportViewColumns; + } + + @Override + public String toString() { + return "JSONExportSession [id=" + id + ", destination=" + destination + + ", itemId=" + itemId + ", fileName=" + fileName + + ", fileDescription=" + fileDescription + ", columns=" + + columns + ", exportViewColumns=" + exportViewColumns + "]"; + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java index a9d0d53..1acb622 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java @@ -26,6 +26,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; @@ -230,8 +231,9 @@ public class OperationMonitorCreator { TRId trId; TabResource tabResource; Table table; + TabExportMetadata trExportMetadata; ExportMetadata exportMetadata; - + switch (taskWrapper.getOperationId()) { case CSVExport: table = taskWrapper.getTask().getResult().getPrimaryTable(); @@ -241,7 +243,6 @@ public class OperationMonitorCreator { operationMonitor.setTrId(SessionUtil.getTRId(session)); - TabExportMetadata trExportMetadata; trExportMetadata = new TabExportMetadata(); trExportMetadata.setUrl(exportMetadata.getUri()); trExportMetadata.setDestinationType(exportMetadata @@ -258,6 +259,23 @@ public class OperationMonitorCreator { 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()); @@ -349,7 +367,7 @@ public class OperationMonitorCreator { } /** - * Save export data on Workspace + * Save export csv data on Workspace * * @param session * @param user @@ -390,7 +408,54 @@ public class OperationMonitorCreator { } else { logger.error("Destination No Present"); throw new TDGWTServiceException( - "Error in exportCSV CSVExportMonitor: no destination present"); + "Error in export csv: no destination present"); + } + } + + + /** + * 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"); } } diff --git a/templates/changelog.xml b/templates/changelog.xml index d8b8528..d90675f 100644 --- a/templates/changelog.xml +++ b/templates/changelog.xml @@ -3,6 +3,7 @@ date="Next"> Updated Discard Updated CSVExportSession + Added JSON Export