This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository echobase. See https://gitlab.nuiton.org/codelutin/echobase.git commit 5fc7551f8266a512b1b823e99adc98a5d4e7cd1e Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed May 4 12:26:41 2016 +0200 Afficher les fichiers résultats d'import dans le tableau de bord --- .../ui/actions/workingDb/DownloadExportFile.java | 48 +++++++++++++ ...oadImportFile.java => DownloadFileSupport.java} | 9 ++- .../ui/actions/workingDb/DownloadImportFile.java | 80 ++-------------------- .../src/main/resources/config/struts-workingDb.xml | 11 +++ .../resources/i18n/echobase-ui_en_GB.properties | 1 + .../resources/i18n/echobase-ui_fr_FR.properties | 1 + .../webapp/WEB-INF/jsp/workingDb/dashboard.jsp | 70 +++++++++++++------ 7 files changed, 122 insertions(+), 98 deletions(-) diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadExportFile.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadExportFile.java new file mode 100644 index 0000000..7f5ccb8 --- /dev/null +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadExportFile.java @@ -0,0 +1,48 @@ +package fr.ifremer.echobase.ui.actions.workingDb; + +/* + * #%L + * EchoBase :: UI + * %% + * Copyright (C) 2011 - 2015 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.entities.ImportFile; + +import java.sql.Blob; + +/** + * Created on 12/30/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.7.2 + */ +public class DownloadExportFile extends DownloadFileSupport { + + private static final long serialVersionUID = 1L; + + @Override + protected String getFilename(ImportFile importFile) { + return "check-"+importFile.getName(); + } + + @Override + protected Blob getFile(ImportFile importFile) { + return importFile.getCheckFile(); + } + +} \ No newline at end of file diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadImportFile.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadFileSupport.java similarity index 91% copy from echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadImportFile.java copy to echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadFileSupport.java index 849285c..dad8dfb 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadImportFile.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadFileSupport.java @@ -38,7 +38,7 @@ import java.util.zip.GZIPInputStream; * @author Tony Chemit - chemit@codelutin.com * @since 2.7.2 */ -public class DownloadImportFile extends EchoBaseActionSupport { +public abstract class DownloadFileSupport extends EchoBaseActionSupport { private static final long serialVersionUID = 1L; @@ -80,6 +80,9 @@ public class DownloadImportFile extends EchoBaseActionSupport { return contentType; } + protected abstract Blob getFile(ImportFile importFile); + protected abstract String getFilename(ImportFile importFile); + @Override public String execute() throws Exception { @@ -87,11 +90,11 @@ public class DownloadImportFile extends EchoBaseActionSupport { String id = URLDecoder.decode(importFileId, "UTF-8"); ImportFile importFile = userDbPersistenceService.getImportFile(id); - filename = importFile.getName(); + filename = getFilename(importFile); contentType = "application/text"; - Blob file = importFile.getFile(); + Blob file = getFile(importFile); { byte[] bytes; try (InputStream binaryStream = file.getBinaryStream()) { diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadImportFile.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadImportFile.java index 849285c..78b594c 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadImportFile.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/workingDb/DownloadImportFile.java @@ -22,15 +22,8 @@ package fr.ifremer.echobase.ui.actions.workingDb; */ import fr.ifremer.echobase.entities.ImportFile; -import fr.ifremer.echobase.services.service.UserDbPersistenceService; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; -import org.apache.commons.io.IOUtils; -import javax.inject.Inject; -import java.io.InputStream; -import java.net.URLDecoder; import java.sql.Blob; -import java.util.zip.GZIPInputStream; /** * Created on 12/30/14. @@ -38,79 +31,18 @@ import java.util.zip.GZIPInputStream; * @author Tony Chemit - chemit@codelutin.com * @since 2.7.2 */ -public class DownloadImportFile extends EchoBaseActionSupport { +public class DownloadImportFile extends DownloadFileSupport { private static final long serialVersionUID = 1L; - /** id of import file to download. */ - protected String importFileId; - - protected String filename; - - public void setImportFileId(String importFileId) { - this.importFileId = importFileId; - } - - public String getImportFileId() { - return importFileId; - } - - public String getFilename() { - return filename; - } - - /** Input stream of the file to download. */ - protected transient InputStream inputStream; - - public InputStream getInputStream() { - return inputStream; - } - - /** Length of the file to download. */ - protected long contentLength; - - public long getContentLength() { - return contentLength; - } - - /** Content type of the file to download. */ - protected String contentType; - - public String getContentType() { - return contentType; + @Override + protected String getFilename(ImportFile importFile) { + return importFile.getName(); } @Override - public String execute() throws Exception { - - //FIXME Find out why we need to decode id? - String id = URLDecoder.decode(importFileId, "UTF-8"); - ImportFile importFile = userDbPersistenceService.getImportFile(id); - - filename = importFile.getName(); - - contentType = "application/text"; - - Blob file = importFile.getFile(); - { - byte[] bytes; - try (InputStream binaryStream = file.getBinaryStream()) { - bytes = IOUtils.toString(new GZIPInputStream(binaryStream)).getBytes(); - } - contentLength = bytes.length; - } - - inputStream = new GZIPInputStream(file.getBinaryStream(), 65535); - - return SUCCESS; - + protected Blob getFile(ImportFile importFile) { + return importFile.getFile(); } - //------------------------------------------------------------------------// - //-- Injected objects // - //------------------------------------------------------------------------// - - @Inject - protected transient UserDbPersistenceService userDbPersistenceService; - } \ No newline at end of file diff --git a/echobase-ui/src/main/resources/config/struts-workingDb.xml b/echobase-ui/src/main/resources/config/struts-workingDb.xml index 4cb4d00..201af08 100644 --- a/echobase-ui/src/main/resources/config/struts-workingDb.xml +++ b/echobase-ui/src/main/resources/config/struts-workingDb.xml @@ -194,6 +194,17 @@ </result> </action> + <!-- Download export file --> + <action name="downloadExportFile" method="execute" + class="fr.ifremer.echobase.ui.actions.workingDb.DownloadExportFile"> + <interceptor-ref name="prepareParamsStackLogguedWithDb"/> + <result type="stream"> + <param name="contentType">${contentType}</param> + <param name="contentLength">${contentLength}</param> + <param name="contentDisposition">attachment; filename="${filename}"</param> + </result> + </action> + </package> </struts> diff --git a/echobase-ui/src/main/resources/i18n/echobase-ui_en_GB.properties b/echobase-ui/src/main/resources/i18n/echobase-ui_en_GB.properties index 1baf9b3..b05accf 100644 --- a/echobase-ui/src/main/resources/i18n/echobase-ui_en_GB.properties +++ b/echobase-ui/src/main/resources/i18n/echobase-ui_en_GB.properties @@ -411,6 +411,7 @@ echobase.title.exportCoserResult=Coser export results echobase.title.exportDb=Export a complete database echobase.title.exportDbProgress=Export database in progress echobase.title.exportDbResult=Database export results +echobase.title.exportLog.files= echobase.title.exportTable=Export a table echobase.title.importData.selectImportType=Select type of import echobase.title.importDb=Database import diff --git a/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties b/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties index f8fb5ee..7a38c9b 100644 --- a/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties +++ b/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties @@ -414,6 +414,7 @@ echobase.title.exportCoserResult=Résultats de l'export Coser echobase.title.exportDb=Export complet de la base echobase.title.exportDbProgress=Export de la base de données en cours echobase.title.exportDbResult=Résultats de l'export de la base de données +echobase.title.exportLog.files=Fichiers d'export echobase.title.exportTable=Exporter une table echobase.title.importData.selectImportType=Sélection du type d'import echobase.title.importDb=Import d'une base diff --git a/echobase-ui/src/main/webapp/WEB-INF/jsp/workingDb/dashboard.jsp b/echobase-ui/src/main/webapp/WEB-INF/jsp/workingDb/dashboard.jsp index e9a75b0..cf025c1 100644 --- a/echobase-ui/src/main/webapp/WEB-INF/jsp/workingDb/dashboard.jsp +++ b/echobase-ui/src/main/webapp/WEB-INF/jsp/workingDb/dashboard.jsp @@ -56,34 +56,45 @@ $('#importLogDate').html(json['importDate']); $('#importLogImportType').html(json['importType']); - loadImportFiles(json['importFile']); - } - }); - return false; - } + var importFiles = json['importFile']; + var importUrlPrefix = '<s:url action="downloadImportFile" namespace="/workingDb"/>'; - function loadImportFiles(importFiles) { - var importUrlPrefix ='<s:url action="downloadImportFile" namespace="/workingDb"/>'; + var importResult=""; + $(importFiles).each(function () { + var importFile = this; + var importFileId = importFile['topiaId']; + var filename = importFile['name']; + var importUrl = encodeURI($.prepareUrl(importUrlPrefix , {importFileId:importFileId})); - var result=""; - $(importFiles).each(function () { - var importFile = this; - var importFileId = importFile['topiaId']; - var filename = importFile['name']; - var importUrl = encodeURI($.prepareUrl(importUrlPrefix , {importFileId:importFileId})); + importResult += "<li><a href='"+importUrl+"' class='fontsize11'>" + filename + "</a></li>"; + }); - result += "<li><a href='"+importUrl+"' class='fontsize11'>" + filename + "</a></li>"; - }); + if (importResult == "") { + importResult = "<s:text name='echobase.message.noImportFilesFound'/>"; + } + $('#importLogFiles').html(importResult); - if (result == "") { - result = "<s:text name='echobase.message.noImportFilesFound'/>"; - } - $('#importLogFiles').html(result); - } + var exportResult = ""; + var exportUrlPrefix = '<s:url action="downloadExportFile" namespace="/workingDb"/>'; + $(importFiles).each(function () { + var exportFile = this; + var importFileId = exportFile['topiaId']; + var filename = 'check-' + exportFile['name']; + var importUrl = encodeURI($.prepareUrl(exportUrlPrefix, {importFileId: importFileId})); - function downloadImportFile(importFileId) { + exportResult += "<li><a href='" + importUrl + "' class='fontsize11'>" + filename + "</a></li>"; + }); + if (exportResult == "") { + exportResult = "<s:text name='echobase.message.noImportFilesFound'/>"; + } + $('#exportLogFiles').html(exportResult); + + } + }); + return false; } + function loadVoyageDetail(voyageId) { $.ajax( { @@ -265,3 +276,20 @@ </fieldset> + +<fieldset id="exportLogFilesFieldset"> + <legend><s:text name="echobase.title.exportLog.files"/></legend> + + <div class="noImportLogDetail"> + <pre> + <s:text name="echobase.message.noImportLogSelected"/> + </pre> + </div> + <div class="importLogDetail"> + + <ul id='exportLogFiles' style="font-weight: bold;"></ul> + + </div> + + +</fieldset> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.