Added Codelist Mapping Import
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@96552 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
18ee35ceef
commit
c80f775f59
|
@ -5,6 +5,8 @@ package org.gcube.portlets.user.td.gwtservice.client.rpc;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingMonitor;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
||||||
|
@ -721,8 +723,7 @@ public interface TDGWTService extends RemoteService {
|
||||||
* @return
|
* @return
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
*/
|
*/
|
||||||
public AddColumnMonitor getAddColumnMonitor()
|
public AddColumnMonitor getAddColumnMonitor() throws TDGWTServiceException;
|
||||||
throws TDGWTServiceException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start add column
|
* Start add column
|
||||||
|
@ -734,8 +735,6 @@ public interface TDGWTService extends RemoteService {
|
||||||
public void startAddColumn(AddColumnSession addColumnSession)
|
public void startAddColumn(AddColumnSession addColumnSession)
|
||||||
throws TDGWTServiceException;
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Operation Monitor during the Delete Column operation
|
* Get Operation Monitor during the Delete Column operation
|
||||||
*
|
*
|
||||||
|
@ -907,22 +906,40 @@ public interface TDGWTService extends RemoteService {
|
||||||
*/
|
*/
|
||||||
OpHistory getLastOperationInfo(TRId trId) throws TDGWTServiceException;
|
OpHistory getLastOperationInfo(TRId trId) throws TDGWTServiceException;
|
||||||
|
|
||||||
// Extract Codelist
|
// Helper Extract Codelist
|
||||||
/**
|
/**
|
||||||
* Get Operation Monitor during the Extract Codelist operation
|
* Get Operation Monitor during the Extract Codelist operation
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
*/
|
*/
|
||||||
public ExtractCodelistMonitor getExtractCodelistMonitor() throws TDGWTServiceException;
|
public ExtractCodelistMonitor getExtractCodelistMonitor()
|
||||||
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start Extract Codelist and invokes the client library
|
* Start Extract Codelist and invokes the client library
|
||||||
*
|
*
|
||||||
* @param extractCodelistSession
|
* @param extractCodelistSession
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
*/
|
*/
|
||||||
public void startExtractCodelist(ExtractCodelistSession extractCodelistSession)
|
public void startExtractCodelist(
|
||||||
|
ExtractCodelistSession extractCodelistSession)
|
||||||
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
|
// Helper Codelist Mapping Import
|
||||||
|
public CodelistMappingMonitor getCodelistMappingMonitor()
|
||||||
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
|
public void setCodelistMappingSession(
|
||||||
|
CodelistMappingSession codelistMappingSession)
|
||||||
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
|
public void getFileFromWorkspace(
|
||||||
|
CodelistMappingSession codelistMappingSession)
|
||||||
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
|
public void startCodelistMappingImport(
|
||||||
|
CodelistMappingSession codelistMappingSession)
|
||||||
throws TDGWTServiceException;
|
throws TDGWTServiceException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ package org.gcube.portlets.user.td.gwtservice.client.rpc;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingMonitor;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
||||||
|
@ -161,9 +163,10 @@ public interface TDGWTServiceAsync {
|
||||||
|
|
||||||
void startSDMXImport(SDMXImportSession sdmxImportSession,AsyncCallback<Void> callback);
|
void startSDMXImport(SDMXImportSession sdmxImportSession,AsyncCallback<Void> callback);
|
||||||
|
|
||||||
//Import CSV
|
//File Upload Monitor
|
||||||
void getFileUploadMonitor(AsyncCallback<FileUploadMonitor> callback);
|
void getFileUploadMonitor(AsyncCallback<FileUploadMonitor> callback);
|
||||||
|
|
||||||
|
//Import CSV
|
||||||
void getCSVImportMonitor(AsyncCallback<CSVImportMonitor> callback);
|
void getCSVImportMonitor(AsyncCallback<CSVImportMonitor> callback);
|
||||||
|
|
||||||
void setCSVSession(CSVImportSession csvImportSession, AsyncCallback<Void> callback);
|
void setCSVSession(CSVImportSession csvImportSession, AsyncCallback<Void> callback);
|
||||||
|
@ -185,7 +188,6 @@ public interface TDGWTServiceAsync {
|
||||||
|
|
||||||
//Export SDMX
|
//Export SDMX
|
||||||
void getSDMXExportMonitor(AsyncCallback<SDMXExportMonitor> callback);
|
void getSDMXExportMonitor(AsyncCallback<SDMXExportMonitor> callback);
|
||||||
|
|
||||||
void startSDMXExport(SDMXExportSession exportSession, AsyncCallback<Void> callback);
|
void startSDMXExport(SDMXExportSession exportSession, AsyncCallback<Void> callback);
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,8 +240,15 @@ public interface TDGWTServiceAsync {
|
||||||
void getLastOperationInfo(AsyncCallback<OpHistory> callback);
|
void getLastOperationInfo(AsyncCallback<OpHistory> callback);
|
||||||
void getLastOperationInfo(TRId trId, AsyncCallback<OpHistory> callback);
|
void getLastOperationInfo(TRId trId, AsyncCallback<OpHistory> callback);
|
||||||
|
|
||||||
//Extract Codelist
|
//Helper Extract Codelist
|
||||||
void getExtractCodelistMonitor(AsyncCallback<ExtractCodelistMonitor> callback);
|
void getExtractCodelistMonitor(AsyncCallback<ExtractCodelistMonitor> callback);
|
||||||
void startExtractCodelist(ExtractCodelistSession extractCodelistSession, AsyncCallback<Void> callback);
|
void startExtractCodelist(ExtractCodelistSession extractCodelistSession, AsyncCallback<Void> callback);
|
||||||
|
|
||||||
|
//Helper Codelist Mapping Import
|
||||||
|
void getCodelistMappingMonitor(AsyncCallback<CodelistMappingMonitor> callback);
|
||||||
|
void setCodelistMappingSession(CodelistMappingSession codelistMappingSession, AsyncCallback<Void> callback);
|
||||||
|
void getFileFromWorkspace(CodelistMappingSession codelistMappingSession, AsyncCallback<Void> callback);
|
||||||
|
void startCodelistMappingImport(CodelistMappingSession codelistMappingSession, AsyncCallback<Void> callback);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession;
|
import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVFileUtil;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVFileUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -58,7 +58,7 @@ public class CSVImportFileServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
logger.info("CSVImportFileServlet import session id: "+session.getId());
|
logger.info("CSVImportFileServlet import session id: "+session.getId());
|
||||||
|
|
||||||
FileUploadSession fileUploadSession=SessionUtil.getFileUploadSession(session);
|
CSVFileUploadSession fileUploadSession=SessionUtil.getCSVFileUploadSession(session);
|
||||||
|
|
||||||
if (fileUploadSession == null)
|
if (fileUploadSession == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,168 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.td.gwtservice.server;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.apache.commons.fileupload.FileItem;
|
||||||
|
import org.apache.commons.fileupload.FileItemFactory;
|
||||||
|
import org.apache.commons.fileupload.FileUploadException;
|
||||||
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.server.file.CodelistMappingFileUploadSession;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadListener;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingMonitor;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadState;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.allen_sauer.gwt.log.client.Log;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CodelistMappingUploadServlet extends HttpServlet {
|
||||||
|
|
||||||
|
protected static Logger logger = LoggerFactory.getLogger(CodelistMappingUploadServlet.class);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -4197748678713054285L;
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
|
||||||
|
logger.trace("Post");
|
||||||
|
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
|
||||||
|
if(session==null){
|
||||||
|
logger.error("Error getting the upload session, no session valid found: "+session);
|
||||||
|
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ERROR-Error getting the user session, no session found"+session);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
logger.info("Codelist Mapping session id: "+session.getId());
|
||||||
|
|
||||||
|
CodelistMappingFileUploadSession codelistMappingFileUploadSession=new CodelistMappingFileUploadSession();
|
||||||
|
CodelistMappingMonitor codelistMappingMonitor=new CodelistMappingMonitor();
|
||||||
|
FileUploadMonitor fileUploadMonitor=new FileUploadMonitor();
|
||||||
|
|
||||||
|
codelistMappingFileUploadSession.setId(session.getId());
|
||||||
|
codelistMappingFileUploadSession.setFileUploadState(FileUploadState.STARTED);
|
||||||
|
codelistMappingFileUploadSession.setCodelistMappingMonitor(codelistMappingMonitor);
|
||||||
|
codelistMappingFileUploadSession.setFileUploadMonitor(fileUploadMonitor);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
SessionUtil.setCodelistMappingFileUploadSession(session,codelistMappingFileUploadSession);
|
||||||
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new ServletException(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FileItemFactory factory = new DiskFileItemFactory();
|
||||||
|
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||||
|
|
||||||
|
|
||||||
|
FileUploadListener uploadListener = new FileUploadListener(fileUploadMonitor);
|
||||||
|
upload.setProgressListener(uploadListener);
|
||||||
|
|
||||||
|
FileItem uploadItem = null;
|
||||||
|
Log.info("Start upload file ");
|
||||||
|
try {
|
||||||
|
List items = upload.parseRequest(request);
|
||||||
|
Iterator it = items.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
FileItem item = (FileItem) it.next();
|
||||||
|
if (!item.isFormField() && "uploadFormElement".equals(item.getFieldName())) {
|
||||||
|
uploadItem = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (FileUploadException e) {
|
||||||
|
codelistMappingFileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request", FileUtil.exceptionDetailMessage(e));
|
||||||
|
codelistMappingFileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
||||||
|
try {
|
||||||
|
SessionUtil.setCodelistMappingFileUploadSession(session, codelistMappingFileUploadSession);
|
||||||
|
} catch (TDGWTSessionExpiredException e1) {
|
||||||
|
logger.error(e1.getLocalizedMessage());
|
||||||
|
e1.printStackTrace();
|
||||||
|
throw new ServletException(e1.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
logger.error("Error processing request in upload servlet", e);
|
||||||
|
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ERROR-Error during request processing: "+e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uploadItem == null) {
|
||||||
|
codelistMappingFileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request: No file found", "Upload request without file");
|
||||||
|
codelistMappingFileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
||||||
|
try {
|
||||||
|
SessionUtil.setCodelistMappingFileUploadSession(session, codelistMappingFileUploadSession);
|
||||||
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new ServletException(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
logger.error("Error processing request in upload servlet: No file to upload");
|
||||||
|
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No file to upload");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String contentType = uploadItem.getContentType();
|
||||||
|
|
||||||
|
logger.trace("ContentType: "+contentType);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileUtil.setImportFileCodelistMapping(codelistMappingFileUploadSession, uploadItem.getInputStream(), uploadItem.getName(), contentType);
|
||||||
|
} catch (Exception e) {
|
||||||
|
codelistMappingFileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));
|
||||||
|
codelistMappingFileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
||||||
|
try {
|
||||||
|
SessionUtil.setCodelistMappingFileUploadSession(session, codelistMappingFileUploadSession);
|
||||||
|
} catch (TDGWTSessionExpiredException e1) {
|
||||||
|
logger.error(e1.getLocalizedMessage());
|
||||||
|
e1.printStackTrace();
|
||||||
|
throw new ServletException(e1.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
logger.error("Error elaborating the stream", e);
|
||||||
|
uploadItem.delete();
|
||||||
|
response.getWriter().write("ERROR-"+e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadItem.delete();
|
||||||
|
|
||||||
|
logger.trace("changing state");
|
||||||
|
codelistMappingFileUploadSession.getFileUploadMonitor().setState(FileUploadState.COMPLETED);
|
||||||
|
try {
|
||||||
|
SessionUtil.setCodelistMappingFileUploadSession(session, codelistMappingFileUploadSession);
|
||||||
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new ServletException(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
response.getWriter().write("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ import org.apache.commons.fileupload.FileUploadException;
|
||||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadListener;
|
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadListener;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession;
|
import org.gcube.portlets.user.td.gwtservice.server.file.CSVFileUploadSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil;
|
import org.gcube.portlets.user.td.gwtservice.server.file.FileUtil;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
||||||
|
@ -61,7 +61,7 @@ public class LocalUploadServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
logger.info("CSV Import session id: "+session.getId());
|
logger.info("CSV Import session id: "+session.getId());
|
||||||
|
|
||||||
FileUploadSession fileUploadSession=new FileUploadSession();
|
CSVFileUploadSession fileUploadSession=new CSVFileUploadSession();
|
||||||
CSVImportMonitor csvImportMonitor=new CSVImportMonitor();
|
CSVImportMonitor csvImportMonitor=new CSVImportMonitor();
|
||||||
FileUploadMonitor fileUploadMonitor=new FileUploadMonitor();
|
FileUploadMonitor fileUploadMonitor=new FileUploadMonitor();
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class LocalUploadServlet extends HttpServlet {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SessionUtil.setFileUploadSession(session,fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session,fileUploadSession);
|
||||||
} catch (TDGWTSessionExpiredException e) {
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -102,7 +102,7 @@ public class LocalUploadServlet extends HttpServlet {
|
||||||
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request", FileUtil.exceptionDetailMessage(e));
|
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request", FileUtil.exceptionDetailMessage(e));
|
||||||
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
||||||
try {
|
try {
|
||||||
SessionUtil.setFileUploadSession(session, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session, fileUploadSession);
|
||||||
} catch (TDGWTSessionExpiredException e1) {
|
} catch (TDGWTSessionExpiredException e1) {
|
||||||
logger.error(e1.getLocalizedMessage());
|
logger.error(e1.getLocalizedMessage());
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
@ -117,7 +117,7 @@ public class LocalUploadServlet extends HttpServlet {
|
||||||
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request: No file found", "Upload request without file");
|
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the HTTP request: No file found", "Upload request without file");
|
||||||
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
||||||
try {
|
try {
|
||||||
SessionUtil.setFileUploadSession(session, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session, fileUploadSession);
|
||||||
} catch (TDGWTSessionExpiredException e) {
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -134,12 +134,12 @@ public class LocalUploadServlet extends HttpServlet {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileUtil.setImportFile(fileUploadSession, uploadItem.getInputStream(), uploadItem.getName(), contentType);
|
FileUtil.setImportFileCSV(fileUploadSession, uploadItem.getInputStream(), uploadItem.getName(), contentType);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));
|
fileUploadSession.getFileUploadMonitor().setFailed("An error occured elaborating the file", FileUtil.exceptionDetailMessage(e));
|
||||||
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
||||||
try {
|
try {
|
||||||
SessionUtil.setFileUploadSession(session, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session, fileUploadSession);
|
||||||
} catch (TDGWTSessionExpiredException e1) {
|
} catch (TDGWTSessionExpiredException e1) {
|
||||||
logger.error(e1.getLocalizedMessage());
|
logger.error(e1.getLocalizedMessage());
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
@ -156,7 +156,7 @@ public class LocalUploadServlet extends HttpServlet {
|
||||||
logger.trace("changing state");
|
logger.trace("changing state");
|
||||||
fileUploadSession.getFileUploadMonitor().setState(FileUploadState.COMPLETED);
|
fileUploadSession.getFileUploadMonitor().setState(FileUploadState.COMPLETED);
|
||||||
try {
|
try {
|
||||||
SessionUtil.setFileUploadSession(session, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session, fileUploadSession);
|
||||||
} catch (TDGWTSessionExpiredException e) {
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -23,8 +23,8 @@ public class SessionConstants {
|
||||||
protected static final String CSV_IMPORT_SESSION = "CSV_IMPORT";
|
protected static final String CSV_IMPORT_SESSION = "CSV_IMPORT";
|
||||||
protected static final String CSV_IMPORT_FILE_UPLOAD_SESSION = "CSV_IMPORT_FILE_UPLOAD";
|
protected static final String CSV_IMPORT_FILE_UPLOAD_SESSION = "CSV_IMPORT_FILE_UPLOAD";
|
||||||
protected static final String CSV_IMPORT_TASK = "CSV_IMPORT_TASK";
|
protected static final String CSV_IMPORT_TASK = "CSV_IMPORT_TASK";
|
||||||
protected static final String CSV_IMPORT_TABULAR_RESOURCE = "CSV_IMPORT_TABULAR_RESOURCE";
|
protected static final String CSV_IMPORT_TABULAR_RESOURCE = "CSV_IMPORT_TABULAR_RESOURCE";
|
||||||
|
|
||||||
protected static final String CSV_EXPORT_SESSION = "CSV_EXPORT_SESSION";
|
protected static final String CSV_EXPORT_SESSION = "CSV_EXPORT_SESSION";
|
||||||
protected static final String CSV_EXPORT_TASK = "CSV_EXPORT_TASK";
|
protected static final String CSV_EXPORT_TASK = "CSV_EXPORT_TASK";
|
||||||
protected static final String CSV_EXPORT_END = "CSV_EXPORT_END";
|
protected static final String CSV_EXPORT_END = "CSV_EXPORT_END";
|
||||||
|
@ -102,7 +102,11 @@ public class SessionConstants {
|
||||||
protected static final String MERGE_COLUMN_MONITOR = "MERGE_COLUMN_MONITOR";
|
protected static final String MERGE_COLUMN_MONITOR = "MERGE_COLUMN_MONITOR";
|
||||||
protected static final String MERGE_COLUMN_TASK = "MERGE_COLUMN_TASK";
|
protected static final String MERGE_COLUMN_TASK = "MERGE_COLUMN_TASK";
|
||||||
|
|
||||||
|
protected static final String CODELIST_MAPPING_SESSION = "CODELIST_MAPPING_SESSION";
|
||||||
|
protected static final String CODELIST_MAPPING_FILE_UPLOAD_SESSION = "CODELIST_MAPPING_FILE_UPLOAD_SESSION";
|
||||||
|
protected static final String CODELIST_MAPPING_TASK = "CODELIST_MAPPING_TASK";
|
||||||
|
protected static final String CODELIST_MAPPING_MONITOR = "CODELIST_MAPPING_MONITOR";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,12 @@ import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.data.analysis.tabulardata.service.operation.Task;
|
import org.gcube.data.analysis.tabulardata.service.operation.Task;
|
||||||
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
|
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
|
||||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession;
|
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.trservice.TRTasksManager;
|
import org.gcube.portlets.user.td.gwtservice.server.trservice.TRTasksManager;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
|
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingMonitor;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
||||||
|
@ -303,10 +306,10 @@ public class SessionUtil {
|
||||||
return exportSession;
|
return exportSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setFileUploadSession(HttpSession httpSession,
|
public static void setCSVFileUploadSession(HttpSession httpSession,
|
||||||
FileUploadSession s) throws TDGWTSessionExpiredException {
|
CSVFileUploadSession s) throws TDGWTSessionExpiredException {
|
||||||
|
|
||||||
FileUploadSession session = (FileUploadSession) httpSession
|
CSVFileUploadSession session = (CSVFileUploadSession) httpSession
|
||||||
.getAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION);
|
.getAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION);
|
||||||
if (session != null)
|
if (session != null)
|
||||||
httpSession.removeAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION);
|
httpSession.removeAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION);
|
||||||
|
@ -315,15 +318,41 @@ public class SessionUtil {
|
||||||
ScopeProvider.instance.set(aslSession.getScope().toString());
|
ScopeProvider.instance.set(aslSession.getScope().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileUploadSession getFileUploadSession(HttpSession httpSession) {
|
public static CSVFileUploadSession getCSVFileUploadSession(HttpSession httpSession) {
|
||||||
FileUploadSession fileUploadSession = (FileUploadSession) httpSession
|
CSVFileUploadSession fileUploadSession = (CSVFileUploadSession) httpSession
|
||||||
.getAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION);
|
.getAttribute(SessionConstants.CSV_IMPORT_FILE_UPLOAD_SESSION);
|
||||||
if (fileUploadSession == null) {
|
if (fileUploadSession == null) {
|
||||||
logger.error("FileUploadSession was not acquired");
|
logger.error("FileUploadSession was not acquired");
|
||||||
}
|
}
|
||||||
return fileUploadSession;
|
return fileUploadSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
public static void setCodelistMappingFileUploadSession(HttpSession httpSession,
|
||||||
|
CodelistMappingFileUploadSession s) throws TDGWTSessionExpiredException {
|
||||||
|
|
||||||
|
CodelistMappingFileUploadSession session = (CodelistMappingFileUploadSession) httpSession
|
||||||
|
.getAttribute(SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION);
|
||||||
|
if (session != null)
|
||||||
|
httpSession.removeAttribute(SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION);
|
||||||
|
httpSession.setAttribute(SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION, s);
|
||||||
|
ASLSession aslSession = getAslSession(httpSession);
|
||||||
|
ScopeProvider.instance.set(aslSession.getScope().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CodelistMappingFileUploadSession getCodelistMappingFileUploadSession(HttpSession httpSession) {
|
||||||
|
CodelistMappingFileUploadSession fileUploadSession = (CodelistMappingFileUploadSession) httpSession
|
||||||
|
.getAttribute(SessionConstants.CODELIST_MAPPING_FILE_UPLOAD_SESSION);
|
||||||
|
if (fileUploadSession == null) {
|
||||||
|
logger.error("CodelistMappingFileUploadSession was not acquired");
|
||||||
|
}
|
||||||
|
return fileUploadSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
public static ArrayList<Codelist> retrieveCodelists(HttpSession httpSession)
|
public static ArrayList<Codelist> retrieveCodelists(HttpSession httpSession)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
logger.info("SessionUtil retriveCodelists");
|
logger.info("SessionUtil retriveCodelists");
|
||||||
|
@ -1745,6 +1774,69 @@ public class SessionUtil {
|
||||||
httpSession.removeAttribute(SessionConstants.MERGE_COLUMN_TASK);
|
httpSession.removeAttribute(SessionConstants.MERGE_COLUMN_TASK);
|
||||||
httpSession.setAttribute(SessionConstants.MERGE_COLUMN_TASK, task);
|
httpSession.setAttribute(SessionConstants.MERGE_COLUMN_TASK, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
public static CodelistMappingSession getCodelistMappingSession(HttpSession httpSession) {
|
||||||
|
CodelistMappingSession importSession = (CodelistMappingSession) httpSession
|
||||||
|
.getAttribute(SessionConstants.CODELIST_MAPPING_SESSION);
|
||||||
|
if (importSession == null) {
|
||||||
|
logger.error("CSVImportSession was not acquired");
|
||||||
|
}
|
||||||
|
return importSession;
|
||||||
|
}
|
||||||
|
public static void setCodelistMappingSession(HttpSession httpSession,
|
||||||
|
CodelistMappingSession codelistMappingSession) throws TDGWTSessionExpiredException {
|
||||||
|
|
||||||
|
CodelistMappingSession session = (CodelistMappingSession) httpSession
|
||||||
|
.getAttribute(SessionConstants.CODELIST_MAPPING_SESSION);
|
||||||
|
if (session != null)
|
||||||
|
httpSession.removeAttribute(SessionConstants.CODELIST_MAPPING_SESSION);
|
||||||
|
httpSession.setAttribute(SessionConstants.CODELIST_MAPPING_SESSION, codelistMappingSession);
|
||||||
|
ASLSession aslSession = getAslSession(httpSession);
|
||||||
|
ScopeProvider.instance.set(aslSession.getScope().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CodelistMappingMonitor getCodelistMappingMonitor(
|
||||||
|
HttpSession httpSession) {
|
||||||
|
CodelistMappingMonitor codelistMappingMonitor = (CodelistMappingMonitor) httpSession
|
||||||
|
.getAttribute(SessionConstants.CODELIST_MAPPING_MONITOR);
|
||||||
|
if (codelistMappingMonitor != null) {
|
||||||
|
return codelistMappingMonitor;
|
||||||
|
} else {
|
||||||
|
codelistMappingMonitor = new CodelistMappingMonitor();
|
||||||
|
httpSession
|
||||||
|
.setAttribute(SessionConstants.CODELIST_MAPPING_MONITOR, codelistMappingMonitor);
|
||||||
|
return codelistMappingMonitor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCodelistMappingMonitor(HttpSession httpSession,
|
||||||
|
CodelistMappingMonitor codelistMappingMonitor) {
|
||||||
|
CodelistMappingMonitor cmm = (CodelistMappingMonitor) httpSession
|
||||||
|
.getAttribute(SessionConstants.CODELIST_MAPPING_MONITOR);
|
||||||
|
if (cmm != null) {
|
||||||
|
httpSession.removeAttribute(SessionConstants.CODELIST_MAPPING_MONITOR);
|
||||||
|
}
|
||||||
|
httpSession.setAttribute(SessionConstants.CODELIST_MAPPING_MONITOR, codelistMappingMonitor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task getCodelistMappingTask(HttpSession httpSession) {
|
||||||
|
Task monitor = (Task) httpSession.getAttribute(SessionConstants.CODELIST_MAPPING_TASK);
|
||||||
|
if (monitor == null) {
|
||||||
|
logger.error("CODELIST_MAPPING_TASK was not acquired");
|
||||||
|
}
|
||||||
|
return monitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCodelistMappingTask(HttpSession httpSession, Task task) {
|
||||||
|
Task monitor = (Task) httpSession.getAttribute(SessionConstants.CODELIST_MAPPING_TASK);
|
||||||
|
if (monitor != null)
|
||||||
|
httpSession.removeAttribute(SessionConstants.CODELIST_MAPPING_TASK);
|
||||||
|
httpSession.setAttribute(SessionConstants.CODELIST_MAPPING_TASK, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,8 @@ import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryDescriptor;
|
||||||
import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryInterfaceType;
|
import org.gcube.datapublishing.sdmx.api.model.SDMXRegistryInterfaceType;
|
||||||
import org.gcube.datapublishing.sdmx.impl.model.GCubeSDMXRegistryDescriptor;
|
import org.gcube.datapublishing.sdmx.impl.model.GCubeSDMXRegistryDescriptor;
|
||||||
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTService;
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTService;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.file.FileUploadSession;
|
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.file.FileUtil;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage;
|
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
|
import org.gcube.portlets.user.td.gwtservice.server.trservice.ColumnDataTypeMap;
|
||||||
|
@ -112,6 +113,8 @@ import org.gcube.portlets.user.td.gwtservice.server.trservice.TaskStateMap;
|
||||||
import org.gcube.portlets.user.td.gwtservice.server.trservice.ValueMap;
|
import org.gcube.portlets.user.td.gwtservice.server.trservice.ValueMap;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.Constants;
|
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.OperationsId;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingMonitor;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.AvailableCharsetList;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportMonitor;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
||||||
|
@ -137,6 +140,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts;
|
import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.share.ShareInfo;
|
import org.gcube.portlets.user.td.gwtservice.shared.share.ShareInfo;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource;
|
import org.gcube.portlets.user.td.gwtservice.shared.source.SDMXRegistrySource;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.source.SourceType;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.task.InvocationS;
|
import org.gcube.portlets.user.td.gwtservice.shared.task.InvocationS;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.task.JobS;
|
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.State;
|
||||||
|
@ -337,8 +341,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"CURRENT_TABULAR_RESOURCE has TRId null");
|
"CURRENT_TABULAR_RESOURCE has TRId null");
|
||||||
}
|
}
|
||||||
logger.debug("Current TRId: "+currentTR
|
logger.debug("Current TRId: " + currentTR.getTrId());
|
||||||
.getTrId());
|
|
||||||
|
|
||||||
ArrayList<TRMetadata> trMetadatas = getTRMetadata(currentTR
|
ArrayList<TRMetadata> trMetadatas = getTRMetadata(currentTR
|
||||||
.getTrId());
|
.getTrId());
|
||||||
|
@ -2492,8 +2495,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error retrieving the session: null");
|
"Error retrieving the session: null");
|
||||||
}
|
}
|
||||||
FileUploadSession fileUploadSession = SessionUtil
|
CSVFileUploadSession fileUploadSession = SessionUtil
|
||||||
.getFileUploadSession(session);
|
.getCSVFileUploadSession(session);
|
||||||
if (fileUploadSession == null) {
|
if (fileUploadSession == null) {
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error retrieving the fileUploadSession: null");
|
"Error retrieving the fileUploadSession: null");
|
||||||
|
@ -2531,8 +2534,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
+ " headerPresence: " + headerPresence + " delimiter: "
|
+ " headerPresence: " + headerPresence + " delimiter: "
|
||||||
+ delimiter + " comment: " + comment);
|
+ delimiter + " comment: " + comment);
|
||||||
|
|
||||||
FileUploadSession fileUploadSession = SessionUtil
|
CSVFileUploadSession fileUploadSession = SessionUtil
|
||||||
.getFileUploadSession(session);
|
.getCSVFileUploadSession(session);
|
||||||
if (fileUploadSession == null) {
|
if (fileUploadSession == null) {
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error retrieving the fileUploadSession: null");
|
"Error retrieving the fileUploadSession: null");
|
||||||
|
@ -2548,7 +2551,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
parserConfiguration.update(encoding, delimiter, comment,
|
parserConfiguration.update(encoding, delimiter, comment,
|
||||||
headerPresence);
|
headerPresence);
|
||||||
}
|
}
|
||||||
SessionUtil.setFileUploadSession(session, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session, fileUploadSession);
|
||||||
try {
|
try {
|
||||||
return CSVFileUtil.getHeader(fileUploadSession.getCsvFile(),
|
return CSVFileUtil.getHeader(fileUploadSession.getCsvFile(),
|
||||||
fileUploadSession.getParserConfiguration());
|
fileUploadSession.getParserConfiguration());
|
||||||
|
@ -2572,8 +2575,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
"Error retrieving the session: null");
|
"Error retrieving the session: null");
|
||||||
}
|
}
|
||||||
logger.debug("Session:" + session.getId());
|
logger.debug("Session:" + session.getId());
|
||||||
FileUploadSession fileUploadSession = SessionUtil
|
CSVFileUploadSession fileUploadSession = SessionUtil
|
||||||
.getFileUploadSession(session);
|
.getCSVFileUploadSession(session);
|
||||||
if (fileUploadSession == null) {
|
if (fileUploadSession == null) {
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error retrieving the fileUploadSession: null");
|
"Error retrieving the fileUploadSession: null");
|
||||||
|
@ -2612,8 +2615,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
logger.debug("StartCSVImport: " + csvImportSession.toString());
|
logger.debug("StartCSVImport: " + csvImportSession.toString());
|
||||||
|
|
||||||
FileUploadSession fileUploadSession = SessionUtil
|
CSVFileUploadSession fileUploadSession = SessionUtil
|
||||||
.getFileUploadSession(session);
|
.getCSVFileUploadSession(session);
|
||||||
if (fileUploadSession == null) {
|
if (fileUploadSession == null) {
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error retrieving the fileUploadSession: null");
|
"Error retrieving the fileUploadSession: null");
|
||||||
|
@ -2632,7 +2635,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected Map<String, Object> csvImportFileParameter(
|
protected Map<String, Object> csvImportFileParameter(
|
||||||
String fileUrlOnStorage, FileUploadSession fileUploadSession,
|
String fileUrlOnStorage, CSVFileUploadSession fileUploadSession,
|
||||||
CSVImportSession csvImportSession) {
|
CSVImportSession csvImportSession) {
|
||||||
Map<String, Object> parameterInstances = new HashMap<String, Object>();
|
Map<String, Object> parameterInstances = new HashMap<String, Object>();
|
||||||
parameterInstances.put(Constants.PARAMETER_URL, fileUrlOnStorage);
|
parameterInstances.put(Constants.PARAMETER_URL, fileUrlOnStorage);
|
||||||
|
@ -2663,7 +2666,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
*/
|
*/
|
||||||
protected void importCSVFileOnService(HttpSession session,
|
protected void importCSVFileOnService(HttpSession session,
|
||||||
ASLSession aslSession, String user,
|
ASLSession aslSession, String user,
|
||||||
FileUploadSession fileUploadSession,
|
CSVFileUploadSession fileUploadSession,
|
||||||
CSVImportSession csvImportSession) throws TDGWTServiceException {
|
CSVImportSession csvImportSession) throws TDGWTServiceException {
|
||||||
|
|
||||||
logger.debug("File Storage Access");
|
logger.debug("File Storage Access");
|
||||||
|
@ -2893,7 +2896,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
"Error retrieving the item on workspace" + wi);
|
"Error retrieving the item on workspace" + wi);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUploadSession fileUploadSession = new FileUploadSession();
|
CSVFileUploadSession fileUploadSession = new CSVFileUploadSession();
|
||||||
CSVImportMonitor csvImportMonitor = new CSVImportMonitor();
|
CSVImportMonitor csvImportMonitor = new CSVImportMonitor();
|
||||||
FileUploadMonitor fileUploadMonitor = new FileUploadMonitor();
|
FileUploadMonitor fileUploadMonitor = new FileUploadMonitor();
|
||||||
|
|
||||||
|
@ -2902,15 +2905,15 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
fileUploadSession.setCsvImportMonitor(csvImportMonitor);
|
fileUploadSession.setCsvImportMonitor(csvImportMonitor);
|
||||||
fileUploadSession.setFileUploadMonitor(fileUploadMonitor);
|
fileUploadSession.setFileUploadMonitor(fileUploadMonitor);
|
||||||
|
|
||||||
SessionUtil.setFileUploadSession(session, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session, fileUploadSession);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
InputStream is = filesStorage.retriveImputStream(
|
InputStream is = filesStorage.retriveImputStream(
|
||||||
aslSession.getUsername(), wi);
|
aslSession.getUsername(), wi);
|
||||||
|
|
||||||
FileUtil.setImportFile(fileUploadSession, is, wi.getName(),
|
FileUtil.setImportFileCSV(fileUploadSession, is, wi.getName(),
|
||||||
"text/csv");
|
Constants.FILE_CSV_MIMETYPE);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
fileUploadSession/**
|
fileUploadSession/**
|
||||||
* Get informations on tabular resource
|
* Get informations on tabular resource
|
||||||
|
@ -2922,7 +2925,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
"An error occured elaborating the file",
|
"An error occured elaborating the file",
|
||||||
FileUtil.exceptionDetailMessage(e));
|
FileUtil.exceptionDetailMessage(e));
|
||||||
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
||||||
SessionUtil.setFileUploadSession(session, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session, fileUploadSession);
|
||||||
logger.error("Error elaborating the input stream", e);
|
logger.error("Error elaborating the input stream", e);
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error in importCSV getFileFromWorkspace: "
|
"Error in importCSV getFileFromWorkspace: "
|
||||||
|
@ -2932,7 +2935,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.trace("changing state");
|
logger.trace("changing state");
|
||||||
fileUploadSession.getFileUploadMonitor().setState(
|
fileUploadSession.getFileUploadMonitor().setState(
|
||||||
FileUploadState.COMPLETED);
|
FileUploadState.COMPLETED);
|
||||||
SessionUtil.setFileUploadSession(session, fileUploadSession);
|
SessionUtil.setCSVFileUploadSession(session, fileUploadSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3052,7 +3055,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
AuthorizationProvider.instance.set(new AuthorizationToken(
|
AuthorizationProvider.instance.set(new AuthorizationToken(
|
||||||
aslSession.getUsername()));
|
aslSession.getUsername()));
|
||||||
TabularDataService service = TabularDataServiceFactory.getService();
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
//TODO
|
// TODO
|
||||||
TabularResource tr = service
|
TabularResource tr = service
|
||||||
.getTabularResource(new TabularResourceId(Long.valueOf(trId
|
.getTabularResource(new TabularResourceId(Long.valueOf(trId
|
||||||
.getId())));
|
.getId())));
|
||||||
|
@ -4137,9 +4140,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
ColumnDataType.Text);
|
ColumnDataType.Text);
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
||||||
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, TDTypeValueMap.map(
|
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE,
|
||||||
ColumnDataType.Text,
|
TDTypeValueMap.map(ColumnDataType.Text,
|
||||||
defNewColumn.getDefaultValue()));
|
defNewColumn.getDefaultValue()));
|
||||||
invocation = new OperationExecution(
|
invocation = new OperationExecution(
|
||||||
operationDefinition.getOperationId(), map);
|
operationDefinition.getOperationId(), map);
|
||||||
break;
|
break;
|
||||||
|
@ -4165,9 +4168,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
ColumnDataType.Text);
|
ColumnDataType.Text);
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
||||||
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, TDTypeValueMap.map(
|
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE,
|
||||||
ColumnDataType.Text,
|
TDTypeValueMap.map(ColumnDataType.Text,
|
||||||
defNewColumn.getDefaultValue()));
|
defNewColumn.getDefaultValue()));
|
||||||
invocation = new OperationExecution(
|
invocation = new OperationExecution(
|
||||||
operationDefinition.getOperationId(), map);
|
operationDefinition.getOperationId(), map);
|
||||||
break;
|
break;
|
||||||
|
@ -4179,9 +4182,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
ColumnDataType.Text);
|
ColumnDataType.Text);
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
||||||
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, TDTypeValueMap.map(
|
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE,
|
||||||
ColumnDataType.Text,
|
TDTypeValueMap.map(ColumnDataType.Text,
|
||||||
defNewColumn.getDefaultValue()));
|
defNewColumn.getDefaultValue()));
|
||||||
invocation = new OperationExecution(
|
invocation = new OperationExecution(
|
||||||
operationDefinition.getOperationId(), map);
|
operationDefinition.getOperationId(), map);
|
||||||
break;
|
break;
|
||||||
|
@ -4193,9 +4196,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
ColumnDataType.Text);
|
ColumnDataType.Text);
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
||||||
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, TDTypeValueMap.map(
|
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE,
|
||||||
ColumnDataType.Text,
|
TDTypeValueMap.map(ColumnDataType.Text,
|
||||||
defNewColumn.getDefaultValue()));
|
defNewColumn.getDefaultValue()));
|
||||||
invocation = new OperationExecution(
|
invocation = new OperationExecution(
|
||||||
operationDefinition.getOperationId(), map);
|
operationDefinition.getOperationId(), map);
|
||||||
break;
|
break;
|
||||||
|
@ -4205,9 +4208,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
.getColumnType()));
|
.getColumnType()));
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
||||||
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, TDTypeValueMap.map(
|
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE,
|
||||||
ColumnDataType.Text,
|
TDTypeValueMap.map(ColumnDataType.Text,
|
||||||
defNewColumn.getDefaultValue()));
|
defNewColumn.getDefaultValue()));
|
||||||
invocation = new OperationExecution(
|
invocation = new OperationExecution(
|
||||||
operationDefinition.getOperationId(), map);
|
operationDefinition.getOperationId(), map);
|
||||||
break;
|
break;
|
||||||
|
@ -4231,9 +4234,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
.getColumnType()));
|
.getColumnType()));
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
map.put(Constants.PARAMETER_ADD_COLUMN_LABEL,
|
||||||
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
new ImmutableLocalizedText(defNewColumn.getLabel()));
|
||||||
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE, TDTypeValueMap.map(
|
map.put(Constants.PARAMETER_ADD_COLUMN_VALUE,
|
||||||
ColumnDataType.Text,
|
TDTypeValueMap.map(ColumnDataType.Text,
|
||||||
defNewColumn.getDefaultValue()));
|
defNewColumn.getDefaultValue()));
|
||||||
invocation = new OperationExecution(
|
invocation = new OperationExecution(
|
||||||
operationDefinition.getOperationId(), map);
|
operationDefinition.getOperationId(), map);
|
||||||
break;
|
break;
|
||||||
|
@ -4396,6 +4399,34 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
return invocation;
|
return invocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param service
|
||||||
|
* @param changeTableTypeSession
|
||||||
|
* @return
|
||||||
|
* @throws TDGWTServiceException
|
||||||
|
*/
|
||||||
|
protected OperationExecution retrieveOperationExecution(
|
||||||
|
TabularDataService service,
|
||||||
|
CodelistMappingSession codelistMappingSession, String importUrl)
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
|
||||||
|
OperationExecution invocation = null;
|
||||||
|
|
||||||
|
logger.debug(codelistMappingSession.toString());
|
||||||
|
OperationDefinition operationDefinition;
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
operationDefinition = OperationDefinitionMap.map(
|
||||||
|
OperationsId.CodelistMappingImport.toString(), service);
|
||||||
|
map.put(Constants.PARAMETER_URL, importUrl);
|
||||||
|
|
||||||
|
invocation = new OperationExecution(
|
||||||
|
operationDefinition.getOperationId(), map);
|
||||||
|
|
||||||
|
return invocation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param service
|
* @param service
|
||||||
|
@ -5521,15 +5552,16 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
AuthorizationProvider.instance.set(new AuthorizationToken(
|
AuthorizationProvider.instance.set(new AuthorizationToken(
|
||||||
aslSession.getUsername()));
|
aslSession.getUsername()));
|
||||||
logger.debug("CloneTabularResourceSession: "+cloneTabularResourceSession);
|
logger.debug("CloneTabularResourceSession: "
|
||||||
|
+ cloneTabularResourceSession);
|
||||||
|
|
||||||
TabularDataService service = TabularDataServiceFactory.getService();
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
|
|
||||||
TabularResourceId serviceTR = new TabularResourceId(
|
TabularResourceId serviceTR = new TabularResourceId(
|
||||||
Long.valueOf(cloneTabularResourceSession.getTrId().getId()));
|
Long.valueOf(cloneTabularResourceSession.getTrId().getId()));
|
||||||
|
|
||||||
TabularResource cloned = service.cloneTabularResource(serviceTR);
|
TabularResource cloned = service.cloneTabularResource(serviceTR);
|
||||||
logger.debug("Clone: "+cloned.toString());
|
logger.debug("Clone: " + cloned.toString());
|
||||||
Table table = service.getLastTable(cloned.getId());
|
Table table = service.getLastTable(cloned.getId());
|
||||||
|
|
||||||
Table viewTable = null;
|
Table viewTable = null;
|
||||||
|
@ -7688,8 +7720,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
throws TDGWTServiceException {
|
throws TDGWTServiceException {
|
||||||
try {
|
try {
|
||||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
ExtractCodelistSession extractCodelistSession = SessionUtil
|
SplitColumnSession splitColumnSession = SessionUtil
|
||||||
.getExtractCodelistSession(session);
|
.getSplitColumnSession(session);
|
||||||
|
|
||||||
Task task = SessionUtil.getSplitColumnTask(session);
|
Task task = SessionUtil.getSplitColumnTask(session);
|
||||||
SplitColumnMonitor splitColumnMonitor = new SplitColumnMonitor();
|
SplitColumnMonitor splitColumnMonitor = new SplitColumnMonitor();
|
||||||
|
@ -7731,7 +7763,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.debug("Task Result:" + task.getResult());
|
logger.debug("Task Result:" + task.getResult());
|
||||||
splitColumnMonitor.setProgress(task.getProgress());
|
splitColumnMonitor.setProgress(task.getProgress());
|
||||||
trId = new TRId();
|
trId = new TRId();
|
||||||
trId.setId(extractCodelistSession.getTrId().getId());
|
trId.setId(splitColumnSession.getColumnData().getTrId().getId());
|
||||||
trId = retrieveTabularResourceBasicData(trId);
|
trId = retrieveTabularResourceBasicData(trId);
|
||||||
splitColumnMonitor.setTrId(trId);
|
splitColumnMonitor.setTrId(trId);
|
||||||
tabResource = SessionUtil.getTabResource(session);
|
tabResource = SessionUtil.getTabResource(session);
|
||||||
|
@ -7753,8 +7785,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.debug("Task Result:" + task.getResult());
|
logger.debug("Task Result:" + task.getResult());
|
||||||
splitColumnMonitor.setProgress(task.getProgress());
|
splitColumnMonitor.setProgress(task.getProgress());
|
||||||
|
|
||||||
trId = retrieveTabularResourceBasicData(extractCodelistSession
|
trId = retrieveTabularResourceBasicData(splitColumnSession
|
||||||
.getTrId());
|
.getColumnData().getTrId());
|
||||||
|
|
||||||
splitColumnMonitor.setTrId(trId);
|
splitColumnMonitor.setTrId(trId);
|
||||||
tabResource = SessionUtil.getTabResource(session);
|
tabResource = SessionUtil.getTabResource(session);
|
||||||
|
@ -7832,8 +7864,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
throws TDGWTServiceException {
|
throws TDGWTServiceException {
|
||||||
try {
|
try {
|
||||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
ExtractCodelistSession extractCodelistSession = SessionUtil
|
MergeColumnSession mergeColumnSession = SessionUtil
|
||||||
.getExtractCodelistSession(session);
|
.getMergeColumnSession(session);
|
||||||
|
|
||||||
Task task = SessionUtil.getMergeColumnTask(session);
|
Task task = SessionUtil.getMergeColumnTask(session);
|
||||||
MergeColumnMonitor mergeColumnMonitor = new MergeColumnMonitor();
|
MergeColumnMonitor mergeColumnMonitor = new MergeColumnMonitor();
|
||||||
|
@ -7875,7 +7907,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.debug("Task Result:" + task.getResult());
|
logger.debug("Task Result:" + task.getResult());
|
||||||
mergeColumnMonitor.setProgress(task.getProgress());
|
mergeColumnMonitor.setProgress(task.getProgress());
|
||||||
trId = new TRId();
|
trId = new TRId();
|
||||||
trId.setId(extractCodelistSession.getTrId().getId());
|
trId.setId(mergeColumnSession.getColumnData().getTrId().getId());
|
||||||
trId = retrieveTabularResourceBasicData(trId);
|
trId = retrieveTabularResourceBasicData(trId);
|
||||||
mergeColumnMonitor.setTrId(trId);
|
mergeColumnMonitor.setTrId(trId);
|
||||||
tabResource = SessionUtil.getTabResource(session);
|
tabResource = SessionUtil.getTabResource(session);
|
||||||
|
@ -7896,8 +7928,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
logger.debug("Task Result:" + task.getResult());
|
logger.debug("Task Result:" + task.getResult());
|
||||||
mergeColumnMonitor.setProgress(task.getProgress());
|
mergeColumnMonitor.setProgress(task.getProgress());
|
||||||
|
trId = retrieveTabularResourceBasicData(mergeColumnSession.getColumnData()
|
||||||
trId = retrieveTabularResourceBasicData(extractCodelistSession
|
|
||||||
.getTrId());
|
.getTrId());
|
||||||
|
|
||||||
mergeColumnMonitor.setTrId(trId);
|
mergeColumnMonitor.setTrId(trId);
|
||||||
|
@ -7928,4 +7959,312 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCodelistMappingSession(
|
||||||
|
CodelistMappingSession codelistMappingSession)
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
try {
|
||||||
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
|
SessionUtil.setCodelistMappingSession(session,
|
||||||
|
codelistMappingSession);
|
||||||
|
return;
|
||||||
|
|
||||||
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error(
|
||||||
|
"Error setting CodelistMappingSession parameter: "
|
||||||
|
+ e.getLocalizedMessage(), e);
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error setting CodelistMappingSession parameter: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getFileFromWorkspace(
|
||||||
|
CodelistMappingSession codelistMappingSession)
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
||||||
|
Workspace w = null;
|
||||||
|
WorkspaceItem wi = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
HomeManagerFactory factory = HomeLibrary.getHomeManagerFactory();
|
||||||
|
|
||||||
|
HomeManager manager = factory.getHomeManager();
|
||||||
|
|
||||||
|
Home home = manager.getHome(aslSession.getUsername());
|
||||||
|
|
||||||
|
w = home.getWorkspace();
|
||||||
|
wi = w.getItem(codelistMappingSession.getItemId());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in import Codelist Mapping getFileFromWorkspace accessing the workspace: "
|
||||||
|
+ e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wi == null) {
|
||||||
|
logger.error("Error retrieving the item on workspace"
|
||||||
|
+ codelistMappingSession.getItemId());
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error retrieving the item on workspace"
|
||||||
|
+ codelistMappingSession.getItemId());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.debug("WorkspaceItem [id:" + wi.getId() + " name:"
|
||||||
|
+ wi.getName() + " remotePath:" + wi.getRemotePath() + "]");
|
||||||
|
} catch (InternalErrorException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error retrieving the item on workspace" + wi);
|
||||||
|
}
|
||||||
|
|
||||||
|
CodelistMappingFileUploadSession fileUploadSession = new CodelistMappingFileUploadSession();
|
||||||
|
CodelistMappingMonitor codelistMappingMonitor = new CodelistMappingMonitor();
|
||||||
|
FileUploadMonitor fileUploadMonitor = new FileUploadMonitor();
|
||||||
|
|
||||||
|
fileUploadSession.setId(session.getId());
|
||||||
|
fileUploadSession.setFileUploadState(FileUploadState.STARTED);
|
||||||
|
fileUploadSession.setCodelistMappingMonitor(codelistMappingMonitor);
|
||||||
|
fileUploadSession.setFileUploadMonitor(fileUploadMonitor);
|
||||||
|
|
||||||
|
SessionUtil.setCodelistMappingFileUploadSession(session,
|
||||||
|
fileUploadSession);
|
||||||
|
|
||||||
|
try {
|
||||||
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
|
InputStream is = filesStorage.retriveImputStream(
|
||||||
|
aslSession.getUsername(), wi);
|
||||||
|
|
||||||
|
FileUtil.setImportFileCodelistMapping(fileUploadSession, is,
|
||||||
|
wi.getName(), Constants.FILE_XML_MIMETYPE);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
fileUploadSession/**
|
||||||
|
* Get informations on tabular resource
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws TDGWTServiceException
|
||||||
|
*/
|
||||||
|
.getFileUploadMonitor().setFailed(
|
||||||
|
"An error occured elaborating the file",
|
||||||
|
FileUtil.exceptionDetailMessage(e));
|
||||||
|
fileUploadSession.setFileUploadState(FileUploadState.FAILED);
|
||||||
|
SessionUtil.setCodelistMappingFileUploadSession(session,
|
||||||
|
fileUploadSession);
|
||||||
|
logger.error("Error elaborating the input stream", e);
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in import Codelist Mapping getFileFromWorkspace: "
|
||||||
|
+ e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.trace("changing state");
|
||||||
|
fileUploadSession.getFileUploadMonitor().setState(
|
||||||
|
FileUploadState.COMPLETED);
|
||||||
|
SessionUtil.setCodelistMappingFileUploadSession(session,
|
||||||
|
fileUploadSession);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startCodelistMappingImport(
|
||||||
|
CodelistMappingSession codelistMappingSession)
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
try {
|
||||||
|
|
||||||
|
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);
|
||||||
|
if (aslSession == null) {
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error retrieving the asl session: null");
|
||||||
|
}
|
||||||
|
String user = aslSession.getUsername();
|
||||||
|
logger.debug("Session User:" + user);
|
||||||
|
|
||||||
|
logger.debug("StartCodelistMappingImport: "
|
||||||
|
+ codelistMappingSession.toString());
|
||||||
|
|
||||||
|
CodelistMappingFileUploadSession codelistMappingFileUploadSession = SessionUtil
|
||||||
|
.getCodelistMappingFileUploadSession(session);
|
||||||
|
if (codelistMappingFileUploadSession == null) {
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error retrieving the codelistMappingFileUploadSession: null");
|
||||||
|
}
|
||||||
|
|
||||||
|
importCodelistMappingFileOnService(session, aslSession, user,
|
||||||
|
codelistMappingFileUploadSession, codelistMappingSession);
|
||||||
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TDGWTServiceException("Error in Codelist Mapping import: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CodelistMappingMonitor getCodelistMappingMonitor()
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
try {
|
||||||
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
|
CodelistMappingSession codelistMappingSession = SessionUtil
|
||||||
|
.getCodelistMappingSession(session);
|
||||||
|
|
||||||
|
Task task = SessionUtil.getMergeColumnTask(session);
|
||||||
|
CodelistMappingMonitor codelistMappingMonitor = new CodelistMappingMonitor();
|
||||||
|
|
||||||
|
if (task == null) {
|
||||||
|
logger.debug("Task null");
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in CodelistMappingMonitor task null");
|
||||||
|
} else {
|
||||||
|
TaskStatus status = task.getStatus();
|
||||||
|
if (status == null) {
|
||||||
|
logger.debug("Services TaskStatus : null");
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in CodelistMappingMonitor Status null");
|
||||||
|
} else {
|
||||||
|
logger.debug("Services TaskStatus: " + task.getStatus());
|
||||||
|
|
||||||
|
codelistMappingMonitor.setStatus(TaskStateMap.map(task
|
||||||
|
.getStatus()));
|
||||||
|
|
||||||
|
TRId trId;
|
||||||
|
TabResource tabResource;
|
||||||
|
switch (codelistMappingMonitor.getStatus()) {
|
||||||
|
case FAILED:
|
||||||
|
if (task.getResult() != null) {
|
||||||
|
logger.debug("Task exception:"
|
||||||
|
+ task.getErrorCause());
|
||||||
|
task.getErrorCause().printStackTrace();
|
||||||
|
codelistMappingMonitor.setError(new Throwable(task
|
||||||
|
.getErrorCause()));
|
||||||
|
} else {
|
||||||
|
logger.debug("Task exception: Error In CodelistMappingMonitor");
|
||||||
|
codelistMappingMonitor.setError(new Throwable(
|
||||||
|
"Error task resume"));
|
||||||
|
}
|
||||||
|
codelistMappingMonitor.setProgress(task.getProgress());
|
||||||
|
break;
|
||||||
|
case SUCCEDED:
|
||||||
|
logger.debug("Task Result:" + task.getResult());
|
||||||
|
codelistMappingMonitor.setProgress(task.getProgress());
|
||||||
|
trId = new TRId();
|
||||||
|
trId.setId(codelistMappingSession.getTrId().getId());
|
||||||
|
trId = retrieveTabularResourceBasicData(trId);
|
||||||
|
codelistMappingMonitor.setTrId(trId);
|
||||||
|
tabResource = SessionUtil.getTabResource(session);
|
||||||
|
tabResource.setTrId(trId);
|
||||||
|
SessionUtil.setTabResource(session, tabResource);
|
||||||
|
SessionUtil.setTRId(session, trId);
|
||||||
|
break;
|
||||||
|
case IN_PROGRESS:
|
||||||
|
codelistMappingMonitor.setProgress(task.getProgress());
|
||||||
|
break;
|
||||||
|
case VALIDATING_RULES:
|
||||||
|
codelistMappingMonitor.setProgress(task.getProgress());
|
||||||
|
break;
|
||||||
|
case GENERATING_VIEW:
|
||||||
|
break;
|
||||||
|
case ABORTED:
|
||||||
|
break;
|
||||||
|
case STOPPED:
|
||||||
|
logger.debug("Task Result:" + task.getResult());
|
||||||
|
codelistMappingMonitor.setProgress(task.getProgress());
|
||||||
|
trId = retrieveTabularResourceBasicData(codelistMappingSession
|
||||||
|
.getTrId());
|
||||||
|
|
||||||
|
codelistMappingMonitor.setTrId(trId);
|
||||||
|
tabResource = SessionUtil.getTabResource(session);
|
||||||
|
tabResource.setTrId(trId);
|
||||||
|
SessionUtil.setTabResource(session, tabResource);
|
||||||
|
SessionUtil.setTRId(session, trId);
|
||||||
|
break;
|
||||||
|
case INITIALIZING:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SessionUtil.setCodelistMappingTask(session, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("CodelistMappingMonitor(): " + codelistMappingMonitor);
|
||||||
|
return codelistMappingMonitor;
|
||||||
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.debug("Error in CodelistMappingMonitor: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TDGWTServiceException("Error: " + e.getLocalizedMessage());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* @param codelistMappingFileUploadSession
|
||||||
|
* @param codelistMappingSession
|
||||||
|
* @throws TDGWTServiceException
|
||||||
|
*/
|
||||||
|
protected void importCodelistMappingFileOnService(HttpSession session,
|
||||||
|
ASLSession aslSession, String user,
|
||||||
|
CodelistMappingFileUploadSession codelistMappingFileUploadSession,
|
||||||
|
CodelistMappingSession codelistMappingSession) throws Throwable {
|
||||||
|
|
||||||
|
String importUrl = null;
|
||||||
|
|
||||||
|
if (codelistMappingSession.getSource().getId()
|
||||||
|
.compareTo(SourceType.URL.toString()) == 0) {
|
||||||
|
importUrl = codelistMappingSession.getUrl();
|
||||||
|
} else {
|
||||||
|
logger.debug("File Storage Access");
|
||||||
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
|
String fileUrlOnStorage = filesStorage
|
||||||
|
.storageCodelistMappingTempFile(user,
|
||||||
|
codelistMappingFileUploadSession
|
||||||
|
.getCodelistMappingFile());
|
||||||
|
logger.debug("File Url On Storage:" + fileUrlOnStorage);
|
||||||
|
codelistMappingFileUploadSession.getCodelistMappingFile().delete();
|
||||||
|
|
||||||
|
if (fileUrlOnStorage == null || fileUrlOnStorage.isEmpty()) {
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Tabular Data Service error loading file on storage");
|
||||||
|
}
|
||||||
|
importUrl = fileUrlOnStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
AuthorizationProvider.instance.set(new AuthorizationToken(aslSession
|
||||||
|
.getUsername()));
|
||||||
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
|
|
||||||
|
OperationExecution invocation = retrieveOperationExecution(service,
|
||||||
|
codelistMappingSession, importUrl);
|
||||||
|
if (invocation == null) {
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in invocation: Operation not supported");
|
||||||
|
}
|
||||||
|
Long id = Long.valueOf(codelistMappingSession.getTrId().getId());
|
||||||
|
|
||||||
|
TabularResourceId serviceTR = new TabularResourceId(id);
|
||||||
|
logger.debug("OperationInvocation: \n" + invocation.toString());
|
||||||
|
Task trTask = service.execute(invocation, serviceTR);
|
||||||
|
logger.debug("Codelist Mapping Import on service: TaskId "
|
||||||
|
+ trTask.getId());
|
||||||
|
SessionUtil.setCodelistMappingTask(session, trTask);
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadState;
|
||||||
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FileUploadSession implements Serializable {
|
public class CSVFileUploadSession implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -7906477664944910362L;
|
private static final long serialVersionUID = -7906477664944910362L;
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
package org.gcube.portlets.user.td.gwtservice.server.file;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingMonitor;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CodelistMappingFileUploadSession implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5683392670926072167L;
|
||||||
|
|
||||||
|
protected String id;
|
||||||
|
|
||||||
|
protected FileUploadState fileUploadState;
|
||||||
|
|
||||||
|
protected File codelistMappingFile;
|
||||||
|
protected String codelistMappingName;
|
||||||
|
|
||||||
|
protected FileUploadMonitor fileUploadMonitor;
|
||||||
|
|
||||||
|
protected CodelistMappingMonitor codelistMappingMonitor;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileUploadState getFileUploadState() {
|
||||||
|
return fileUploadState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileUploadState(FileUploadState fileUploadState) {
|
||||||
|
this.fileUploadState = fileUploadState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileUploadMonitor getFileUploadMonitor() {
|
||||||
|
return fileUploadMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileUploadMonitor(FileUploadMonitor fileUploadMonitor) {
|
||||||
|
this.fileUploadMonitor = fileUploadMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getCodelistMappingFile() {
|
||||||
|
return codelistMappingFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodelistMappingFile(File codelistMappingFile) {
|
||||||
|
this.codelistMappingFile = codelistMappingFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCodelistMappingName() {
|
||||||
|
return codelistMappingName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodelistMappingName(String codelistMappingName) {
|
||||||
|
this.codelistMappingName = codelistMappingName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CodelistMappingMonitor getCodelistMappingMonitor() {
|
||||||
|
return codelistMappingMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodelistMappingMonitor(
|
||||||
|
CodelistMappingMonitor codelistMappingMonitor) {
|
||||||
|
this.codelistMappingMonitor = codelistMappingMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CodelistMappingFileUploadSession [id=" + id
|
||||||
|
+ ", fileUploadState=" + fileUploadState
|
||||||
|
+ ", codelistMappingFile=" + codelistMappingFile
|
||||||
|
+ ", codelistMappingName=" + codelistMappingName
|
||||||
|
+ ", fileUploadMonitor=" + fileUploadMonitor
|
||||||
|
+ ", codelistMappingMonitor=" + codelistMappingMonitor + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,45 +17,47 @@ import org.apache.commons.io.IOUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
|
|
||||||
protected static final Logger logger = LoggerFactory.getLogger(FileUtil.class);
|
protected static final Logger logger = LoggerFactory
|
||||||
|
.getLogger(FileUtil.class);
|
||||||
|
|
||||||
public static final String[] ZIP_MIMETYPES = new String[]{
|
public static final String[] ZIP_MIMETYPES = new String[] {
|
||||||
"application/x-compress",
|
"application/x-compress", "application/x-compressed",
|
||||||
"application/x-compressed",
|
"application/x-gzip", "application/x-winzip", "application/x-zip",
|
||||||
"application/x-gzip",
|
"application/zip", "multipart/x-zip" };
|
||||||
"application/x-winzip",
|
|
||||||
"application/x-zip",
|
|
||||||
"application/zip",
|
|
||||||
"multipart/x-zip"};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the content type is a zip type.
|
* Check if the content type is a zip type.
|
||||||
* @param contentType the content type to check.
|
*
|
||||||
|
* @param contentType
|
||||||
|
* the content type to check.
|
||||||
* @return <code>true</code> if is a zip file, <code>false</code> otherwise.
|
* @return <code>true</code> if is a zip file, <code>false</code> otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isZipContentType(String contentType)
|
public static boolean isZipContentType(String contentType) {
|
||||||
{
|
for (String zip_mimetype : ZIP_MIMETYPES)
|
||||||
for (String zip_mimetype:ZIP_MIMETYPES) if (zip_mimetype.equals(contentType)) return true;
|
if (zip_mimetype.equals(contentType))
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unzip the specified stream
|
* Unzip the specified stream
|
||||||
* @param is the zip stream.
|
*
|
||||||
* @param os the output stream.
|
* @param is
|
||||||
|
* the zip stream.
|
||||||
|
* @param os
|
||||||
|
* the output stream.
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static String unZip(InputStream is, OutputStream os) throws Exception
|
public static String unZip(InputStream is, OutputStream os)
|
||||||
{
|
throws Exception {
|
||||||
try {
|
try {
|
||||||
ZipInputStream zis = new ZipInputStream(is);
|
ZipInputStream zis = new ZipInputStream(is);
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
|
|
||||||
while ((entry = zis.getNextEntry())!=null && !entry.isDirectory());
|
while ((entry = zis.getNextEntry()) != null && !entry.isDirectory())
|
||||||
|
;
|
||||||
|
|
||||||
if (entry == null || entry.isDirectory()) {
|
if (entry == null || entry.isDirectory()) {
|
||||||
zis.close();
|
zis.close();
|
||||||
|
@ -68,16 +70,13 @@ public class FileUtil {
|
||||||
os.close();
|
os.close();
|
||||||
return entry.getName();
|
return entry.getName();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
} catch(IOException e)
|
throw new Exception("Unzip error: " + e.getMessage(), e);
|
||||||
{
|
|
||||||
throw new Exception("Unzip error: "+e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String exceptionDetailMessage(Throwable t)
|
public static String exceptionDetailMessage(Throwable t) {
|
||||||
{
|
|
||||||
StringWriter out = new StringWriter();
|
StringWriter out = new StringWriter();
|
||||||
PrintWriter writer = new PrintWriter(out);
|
PrintWriter writer = new PrintWriter(out);
|
||||||
t.printStackTrace(writer);
|
t.printStackTrace(writer);
|
||||||
|
@ -88,28 +87,47 @@ public class FileUtil {
|
||||||
return message.toString();
|
return message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setImportFile(FileUploadSession fileUploadSession, InputStream is, String name, String mimeType) throws Exception
|
public static void setImportFileCSV(CSVFileUploadSession fileUploadSession,
|
||||||
{
|
InputStream is, String name, String mimeType) throws Exception {
|
||||||
File csvTmp = File.createTempFile("import", ".csv");
|
|
||||||
|
|
||||||
csvTmp.deleteOnExit();
|
|
||||||
|
|
||||||
logger.trace("mimeType: "+mimeType);
|
|
||||||
if (isZipContentType(mimeType)){
|
|
||||||
//we need to unzip
|
|
||||||
logger.trace("is a zip file");
|
|
||||||
name = unZip(is, new FileOutputStream(csvTmp));
|
|
||||||
} else {
|
|
||||||
logger.trace("is a text file");
|
|
||||||
IOUtils.copy(is, new FileOutputStream(csvTmp));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.trace("upload completed");
|
File csvTmp = setImportFile(is, "import", ".csv", name, mimeType);
|
||||||
|
|
||||||
fileUploadSession.setCsvName(name);
|
fileUploadSession.setCsvName(name);
|
||||||
fileUploadSession.setCsvFile(csvTmp);
|
fileUploadSession.setCsvFile(csvTmp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setImportFileCodelistMapping(CodelistMappingFileUploadSession fileUploadSession,
|
||||||
|
InputStream is, String name, String mimeType) throws Exception {
|
||||||
|
|
||||||
|
File xmlTmp = setImportFile(is, "importCodMap", ".xml", name, mimeType);
|
||||||
|
|
||||||
|
fileUploadSession.setCodelistMappingName(name);
|
||||||
|
fileUploadSession.setCodelistMappingFile(xmlTmp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static File setImportFile(InputStream is, String tempName,
|
||||||
|
String extention, String name, String mimeType) throws Exception {
|
||||||
|
File fileTmp = File.createTempFile(tempName, extention);
|
||||||
|
|
||||||
|
fileTmp.deleteOnExit();
|
||||||
|
|
||||||
|
logger.trace("mimeType: " + mimeType);
|
||||||
|
if (isZipContentType(mimeType)) {
|
||||||
|
// we need to unzip
|
||||||
|
logger.trace("is a zip file");
|
||||||
|
name = unZip(is, new FileOutputStream(fileTmp));
|
||||||
|
} else {
|
||||||
|
logger.trace("is a text file");
|
||||||
|
IOUtils.copy(is, new FileOutputStream(fileTmp));
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.trace("upload completed");
|
||||||
|
|
||||||
|
return fileTmp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,26 @@ public class FilesStorage {
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String storageCodelistMappingTempFile(String user, File file) {
|
||||||
|
String url = null;
|
||||||
|
try {
|
||||||
|
IClient client = new StorageClient(user, AccessType.PUBLIC,
|
||||||
|
MemoryType.VOLATILE).getClient();
|
||||||
|
String remotePath = "/CodelistMappingImport/" + file.getName();
|
||||||
|
logger.debug("remotePath: " + remotePath);
|
||||||
|
client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
|
||||||
|
url = client.getUrl().RFile(remotePath);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error("Error no codelist mapping file loaded on storage"
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* user
|
* user
|
||||||
|
|
|
@ -14,7 +14,10 @@ public class Constants {
|
||||||
public final static String VERSION = "2.1.0";
|
public final static String VERSION = "2.1.0";
|
||||||
public final static String DEFAULT_USER = "test.user";
|
public final static String DEFAULT_USER = "test.user";
|
||||||
public final static String DEFAULT_SCOPE = "/gcube/devsec";
|
public final static String DEFAULT_SCOPE = "/gcube/devsec";
|
||||||
|
|
||||||
|
public final static String FILE_XML_MIMETYPE="application/xml";
|
||||||
|
public final static String FILE_CSV_MIMETYPE="text/csv";
|
||||||
|
|
||||||
public static final String PARAMETER_ENCODING = "encoding";
|
public static final String PARAMETER_ENCODING = "encoding";
|
||||||
public static final String PARAMETER_HASHEADER = "hasHeader";
|
public static final String PARAMETER_HASHEADER = "hasHeader";
|
||||||
public static final String PARAMETER_FIELDMASK = "fieldMask";
|
public static final String PARAMETER_FIELDMASK = "fieldMask";
|
||||||
|
|
|
@ -114,7 +114,8 @@ public enum OperationsId {
|
||||||
ValidateTable("5011"),
|
ValidateTable("5011"),
|
||||||
ValidateDataSet("5012"),
|
ValidateDataSet("5012"),
|
||||||
ValidateGeneric("5013"),
|
ValidateGeneric("5013"),
|
||||||
ExtractCodelist("11001");
|
ExtractCodelist("11001"),
|
||||||
|
CodelistMappingImport("12001");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param text
|
* @param text
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.gcube.portlets.user.td.gwtservice.shared.codelisthelper;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.OperationMonitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CodelistMappingMonitor extends OperationMonitor implements Serializable {
|
||||||
|
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -9004720851025676043L;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.gcube.portlets.user.td.gwtservice.shared.codelisthelper;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.source.Source;
|
||||||
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||||
|
|
||||||
|
public class CodelistMappingSession implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 2381185326076784908L;
|
||||||
|
|
||||||
|
protected TRId trId;
|
||||||
|
protected Source source;
|
||||||
|
protected String url;
|
||||||
|
protected String localFileName;
|
||||||
|
protected String itemId;
|
||||||
|
|
||||||
|
public TRId getTrId() {
|
||||||
|
return trId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrId(TRId trId) {
|
||||||
|
this.trId = trId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocalFileName() {
|
||||||
|
return localFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocalFileName(String localFileName) {
|
||||||
|
this.localFileName = localFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemId(String itemId) {
|
||||||
|
this.itemId = itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Source getSource() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSource(Source source) {
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CodelistMappingSession [trId=" + trId + ", source=" + source
|
||||||
|
+ ", url=" + url + ", localFileName=" + localFileName
|
||||||
|
+ ", itemId=" + itemId + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.gcube.portlets.user.td.gwtservice.shared.resource;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ResourceTD implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -6324769323093791963L;
|
||||||
|
protected String name;
|
||||||
|
protected String description;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ResourceTD [name=" + name + ", description=" + description
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -14,7 +14,7 @@ public class FileSource implements Source {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return "File";
|
return SourceType.FILE.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class SDMXRegistrySource implements Source {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return "SDMXRegistry";
|
return SourceType.SDMXRegistry.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.gcube.portlets.user.td.gwtservice.shared.source;
|
||||||
|
|
||||||
|
public enum SourceType {
|
||||||
|
FILE("File"),
|
||||||
|
URL("Url"),
|
||||||
|
WORKSPACE("Workspace"),
|
||||||
|
SDMXRegistry("SDMXRegistry");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param text
|
||||||
|
*/
|
||||||
|
private SourceType(final String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -14,7 +14,7 @@ public class UrlSource implements Source {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return "Url";
|
return SourceType.URL.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class WorkspaceSource implements Source {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return "Workspace";
|
return SourceType.WORKSPACE.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
<servlet-class>org.gcube.portlets.user.td.gwtservice.server.LocalUploadServlet</servlet-class>
|
<servlet-class>org.gcube.portlets.user.td.gwtservice.server.LocalUploadServlet</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>CodelistMappingUploadServlet</servlet-name>
|
||||||
|
<servlet-class>org.gcube.portlets.user.td.gwtservice.server.CodelistMappingUploadServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>jUnitHostImpl</servlet-name>
|
<servlet-name>jUnitHostImpl</servlet-name>
|
||||||
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
|
<servlet-class>com.google.gwt.junit.server.JUnitHostImpl</servlet-class>
|
||||||
|
@ -44,6 +49,11 @@
|
||||||
<url-pattern>/tdgwtservice/LocalUploadServlet</url-pattern>
|
<url-pattern>/tdgwtservice/LocalUploadServlet</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>CodelistMappingUploadServlet</servlet-name>
|
||||||
|
<url-pattern>/tdgwtservice/CodelistMappingUploadServlet</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>jUnitHostImpl</servlet-name>
|
<servlet-name>jUnitHostImpl</servlet-name>
|
||||||
<url-pattern>TDServiceManagerWidgets/junithost/*</url-pattern>
|
<url-pattern>TDServiceManagerWidgets/junithost/*</url-pattern>
|
||||||
|
|
Loading…
Reference in New Issue