From 6f408bcc8a9bc552baec69d28b9241c87872a5cb Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 25 Jul 2014 10:35:43 +0000 Subject: [PATCH] Minor Update git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@98985 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/client/rpc/TDGWTService.java | 4 +- .../client/rpc/TDGWTServiceAsync.java | 4 +- .../gwtservice/server/TDGWTServiceImpl.java | 5 +- .../td/gwtservice/shared/csv/CSVFileUtil.java | 15 ++++-- .../td/gwtservice/shared/csv/CSVRowError.java | 8 ++- .../shared/csv/CheckCSVSession.java | 52 +++++++++++++++++++ 6 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CheckCSVSession.java diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java index 4b4e2f8..7b1a9e6 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTService.java @@ -11,7 +11,7 @@ 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.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; -import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CheckCSVSession; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession; import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; @@ -569,7 +569,7 @@ public interface TDGWTService extends RemoteService { * @return * @throws TDGWTServiceException */ - public ArrayList checkCSV(long errorsLimit) + public CheckCSVSession checkCSV(long errorsLimit) throws TDGWTServiceException; /** diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java index 0eee400..188e702 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/client/rpc/TDGWTServiceAsync.java @@ -11,7 +11,7 @@ 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.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; -import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CheckCSVSession; import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession; import org.gcube.portlets.user.td.gwtservice.shared.file.FileUploadMonitor; import org.gcube.portlets.user.td.gwtservice.shared.file.HeaderPresence; @@ -186,7 +186,7 @@ public interface TDGWTServiceAsync { void configureCSVParser(String encoding, HeaderPresence headerPresence, char delimiter, char comment, AsyncCallback> callback); - void checkCSV(long errorsLimit, AsyncCallback> callback); + void checkCSV(long errorsLimit, AsyncCallback callback); void startCSVImport(CSVImportSession csvImportSession, AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index cb14381..ac7709f 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -132,7 +132,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVFileUtil; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportMonitor; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVParserConfiguration; -import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVRowError; +import org.gcube.portlets.user.td.gwtservice.shared.csv.CheckCSVSession; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession; @@ -2680,7 +2680,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements /** * {@inheritDoc} */ - public ArrayList checkCSV(long errorsLimit) + @Override + public CheckCSVSession checkCSV(long errorsLimit) throws TDGWTServiceException { HttpSession session = this.getThreadLocalRequest().getSession(); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVFileUtil.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVFileUtil.java index 918eb15..6fae5a8 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVFileUtil.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVFileUtil.java @@ -126,18 +126,19 @@ public class CSVFileUtil { return outCSVFile; } - public static ArrayList checkCSV(File csvFile, + public static CheckCSVSession checkCSV(File csvFile, CSVParserConfiguration config, long errorsLimit) throws ParseException, IOException { return checkCSV(csvFile, config.getCharset(), config.getDelimiter(), config.getComment(), errorsLimit); } - public static ArrayList checkCSV(File csvFile, + public static CheckCSVSession checkCSV(File csvFile, Charset charset, char delimiter, char comment, long errorsLimit) throws IOException { logger.trace("checkCSV charset: " + charset + " delimiter: " + delimiter + " comment: " + comment); + CheckCSVSession checkCSVSesssion; ArrayList errors = new ArrayList(); Reader fileReader = new InputStreamReader(new FileInputStream(csvFile), @@ -185,8 +186,14 @@ public class CSVFileUtil { } while (count >= 0 && errors.size() < errorsLimit && maxRowCheck < MAXROWCHECK); - - return errors; + + if(maxRowCheck < MAXROWCHECK){ + checkCSVSesssion=new CheckCSVSession(errors, false); + } else { + checkCSVSesssion=new CheckCSVSession(errors, true); + } + + return checkCSVSesssion; } public static void toJson(File csvFile, Charset inputCharset, diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVRowError.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVRowError.java index 70bc698..9c6f28d 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVRowError.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CSVRowError.java @@ -5,9 +5,13 @@ package org.gcube.portlets.user.td.gwtservice.shared.csv; import java.io.Serializable; + /** - * An error for a row in the CSV. - * @author Federico De Faveri defaveri@isti.cnr.it + * Errors for row + * + * @author "Giancarlo Panichi" + * email: g.panichi@isti.cnr.it + * */ public class CSVRowError implements Serializable { diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CheckCSVSession.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CheckCSVSession.java new file mode 100644 index 0000000..b01bf3d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/csv/CheckCSVSession.java @@ -0,0 +1,52 @@ +package org.gcube.portlets.user.td.gwtservice.shared.csv; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * + * @author "Giancarlo Panichi" email: g.panichi@isti.cnr.it + * + */ +public class CheckCSVSession implements Serializable { + + private static final long serialVersionUID = 7775024048559018931L; + + protected ArrayList csvRowErrorList; + protected boolean csvFileUpperMaxSizeCheck; + + public CheckCSVSession() { + + } + + public CheckCSVSession(ArrayList csvRowErrorList, + boolean csvFileUpperMaxSizeCheck) { + this.csvFileUpperMaxSizeCheck = csvFileUpperMaxSizeCheck; + this.csvRowErrorList = csvRowErrorList; + } + + public ArrayList getCsvRowErrorList() { + return csvRowErrorList; + } + + public void setCsvRowErrorList(ArrayList csvRowErrorList) { + this.csvRowErrorList = csvRowErrorList; + } + + public boolean isCsvFileUpperMaxSizeCheck() { + return csvFileUpperMaxSizeCheck; + } + + public void setCsvFileUpperMaxSizeCheck(boolean csvFileUpperMaxSizeCheck) { + this.csvFileUpperMaxSizeCheck = csvFileUpperMaxSizeCheck; + } + + @Override + public String toString() { + return "CheckCSVSession [csvRowErrorList=" + csvRowErrorList + + ", csvFileUpperMaxSizeCheck=" + csvFileUpperMaxSizeCheck + + "]"; + } + +}