Added JSON Export

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@100380 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-02 14:18:41 +00:00
parent bbb0a965af
commit 180e295d2e
10 changed files with 515 additions and 83 deletions

View File

@ -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
*

View File

@ -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<String> callback);
// Export JSON
void startJSONExport(JSONExportSession jsonExportSession,
AsyncCallback<String> callback);
// Table Operation
void startChangeTableType(ChangeTableTypeSession changeTableTypeSession,
AsyncCallback<String> callback);

View File

@ -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";

View File

@ -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<String,TaskWrapper> getAbortedTaskMap(HttpSession httpSession) {
public static HashMap<String, TaskWrapper> getAbortedTaskMap(
HttpSession httpSession) {
@SuppressWarnings("unchecked")
HashMap<String, TaskWrapper> tasksAborted = (HashMap<String, TaskWrapper>) 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<String,TaskWrapper> getHiddenTaskMap(HttpSession httpSession) {
public static HashMap<String, TaskWrapper> getHiddenTaskMap(
HttpSession httpSession) {
@SuppressWarnings("unchecked")
HashMap<String, TaskWrapper> hiddenTasks = (HashMap<String, TaskWrapper>) 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<String,TaskWrapper> getTaskInBackgroundMap(HttpSession httpSession) {
public static HashMap<String, TaskWrapper> getTaskInBackgroundMap(
HttpSession httpSession) {
@SuppressWarnings("unchecked")
HashMap<String, TaskWrapper> tasksInBackground = (HashMap<String, TaskWrapper>) 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) {

View File

@ -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<String, Object> csvExportFileParameter(
CSVExportSession exportSession) {
Map<String, Object> parameterInstances = new HashMap<String, Object>();
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<String, Object> 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();

View File

@ -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: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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<String, Object> map = new HashMap<String, Object>();
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);
}
}

View File

@ -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: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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<String, Object> map = new HashMap<String, Object>();
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);
}
}

View File

@ -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: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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<ColumnData> columns;
protected boolean exportViewColumns;
public JSONExportSession() {
super();
}
public ArrayList<ColumnData> getColumns() {
return columns;
}
public void setColumns(ArrayList<ColumnData> columns) {
this.columns = columns;
}
public ArrayList<String> getColumnsAsString() {
ArrayList<String> columnsAsString = new ArrayList<String>();
for (ColumnData cData : columns) {
columnsAsString.add(cData.getColumnId());
}
return columnsAsString;
}
public String[] getColumnsAsArrayOfString() {
ArrayList<String> columnsAsString = new ArrayList<String>();
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 + "]";
}
}

View File

@ -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");
}
}

View File

@ -3,6 +3,7 @@
date="Next">
<Change>Updated Discard</Change>
<Change>Updated CSVExportSession</Change>
<Change>Added JSON Export</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.2-4-0"
date="2014-09-12">