r228 - in trunk/echobase-ui/src/main: java/fr/ifremer/echobase/ui/actions java/fr/ifremer/echobase/ui/actions/exportDb java/fr/ifremer/echobase/ui/actions/importDb webapp/WEB-INF/jsp/exportDb
Author: tchemit Date: 2011-12-27 20:42:16 +0100 (Tue, 27 Dec 2011) New Revision: 228 Url: http://forge.codelutin.com/repositories/revision/echobase/228 Log: -add abstract exec and wait action -improve export result (auto download export file) Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/LaunchImport.java trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java 2011-12-27 19:42:16 UTC (rev 228) @@ -0,0 +1,111 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 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% + */ +package fr.ifremer.echobase.ui.actions; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.echobase.services.AbstractEchobaseActionConfiguration; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.framework.TopiaContextImplementor; + +/** + * Abstract long action using the exec and wait interceptor. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public abstract class AbstractWaitAndExecAction<M extends AbstractEchobaseActionConfiguration> extends EchoBaseActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + /** Configuration of the export action. */ + private M model; + + /** Shared actionContext to reuse all invocation of this same action. */ + private ActionContext actionContext; + + public final M getModel() { + return model; + } + + @Override + public void prepare() throws Exception { + + if (actionContext == null) { + + // keep it since exec and wait then use another thread + actionContext = ActionContext.getContext(); + } else { + + // having the action context here means we already came here, + // now we need to propagate it + ActionContext.setContext(actionContext); + } + model = initModel(); + } + + protected abstract M initModel(); + + protected abstract void startAction(M model) throws Exception; + + @Override + public final String execute() throws Exception { + + model.beginAction(); + + // having the action context here means we already came here, + // now we need to propagate it + ActionContext.setContext(actionContext); + + // we must use a standalone transaction since it will pass through + // in more than one request + + TopiaContextImplementor tx = + (TopiaContextImplementor) serviceContext.getTransaction(); + TopiaContextImplementor rootContext = tx.getRootContext(); + TopiaContext topiaContext = rootContext.beginTransaction(); + serviceContext.setTransaction(topiaContext); + try { + + startAction(model); + + model.endAction(); + + return SUCCESS; + } finally { + + try { + topiaContext.closeContext(); + } finally { + closeAction(model); + } + + + } + } + + protected void closeAction(M model) throws Exception { + // by default do nothing + } +} \ No newline at end of file Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java 2011-12-27 19:41:32 UTC (rev 227) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java 2011-12-27 19:42:16 UTC (rev 228) @@ -23,16 +23,11 @@ */ package fr.ifremer.echobase.ui.actions.exportDb; -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.echobase.services.CsvImportResult; import fr.ifremer.echobase.services.DbExportService; import fr.ifremer.echobase.services.ExportDbConfiguration; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import fr.ifremer.echobase.ui.actions.AbstractWaitAndExecAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.framework.TopiaContextImplementor; /** * Launch the complete db export. @@ -40,84 +35,34 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class LaunchExport extends EchoBaseActionSupport implements Preparable { +public class LaunchExport extends AbstractWaitAndExecAction<ExportDbConfiguration> { private static final long serialVersionUID = 1L; /** Logger. */ private static final Log log = LogFactory.getLog(LaunchExport.class); - /** Configuration of the export action. */ - protected ExportDbConfiguration model; - - /** Result of import. */ - protected CsvImportResult importResult; - /** service to execute the export. */ protected transient DbExportService service; - /** Shared actionContext to reuse all invocation of this same action. */ - protected ActionContext actionContext; - - public ExportDbConfiguration getModel() { - return model; + @Override + protected ExportDbConfiguration initModel() { + return getEchoBaseSession().getExportDbConfiguration(); } @Override public void prepare() throws Exception { - - if (actionContext == null) { - - // keep it since exec and wait then use another thread - actionContext = ActionContext.getContext(); - } else { - - // having the action context here means we already came here, - // now we need to propagate it - ActionContext.setContext(actionContext); - } - model = getEchoBaseSession().getExportDbConfiguration(); - + super.prepare(); service = newService(DbExportService.class); } @Override - public String execute() throws Exception { - - model.beginAction(); - - // having the action context here means we already came here, - // now we need to propagate it - ActionContext.setContext(actionContext); - - // we must use a standalone transaction since it will pass through - // in more than one request - - TopiaContextImplementor tx = - (TopiaContextImplementor) serviceContext.getTransaction(); - TopiaContextImplementor rootContext = tx.getRootContext(); - TopiaContext topiaContext = rootContext.beginTransaction(); - serviceContext.setTransaction(topiaContext); - try { - - if (log.isInfoEnabled()) { - log.info("Start export to file " + model.getFileName()); - } - - service.exportDb(model); - model.endAction(); - - return SUCCESS; - } finally { - - topiaContext.closeContext(); - -// // clean configuration -// model.destroy(); - - // remove configuration from session -// getEchoBaseSession().setExportDbConfiguration(null); + protected void startAction(ExportDbConfiguration model) throws Exception { + if (log.isInfoEnabled()) { + log.info("Start export to file " + model.getFileName()); } + + service.exportDb(model); } } \ No newline at end of file Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/LaunchImport.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/LaunchImport.java 2011-12-27 19:41:32 UTC (rev 227) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/LaunchImport.java 2011-12-27 19:42:16 UTC (rev 228) @@ -23,16 +23,11 @@ */ package fr.ifremer.echobase.ui.actions.importDb; -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.echobase.services.CsvImportResult; import fr.ifremer.echobase.services.DbImportService; import fr.ifremer.echobase.services.ImportDbConfiguration; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import fr.ifremer.echobase.ui.actions.AbstractWaitAndExecAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.framework.TopiaContextImplementor; /** * Start the import db. @@ -40,82 +35,48 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class LaunchImport extends EchoBaseActionSupport implements Preparable { +public class LaunchImport extends AbstractWaitAndExecAction<ImportDbConfiguration> { private static final long serialVersionUID = 1L; /** Logger. */ private static final Log log = LogFactory.getLog(LaunchImport.class); - /** Configuration of the historical import. */ - protected ImportDbConfiguration model; - - /** Result of import. */ - protected CsvImportResult importResult; - /** service to execute the import. */ protected transient DbImportService service; - protected ActionContext actionContext; - - public ImportDbConfiguration getModel() { - return model; + @Override + protected ImportDbConfiguration initModel() { + return getEchoBaseSession().getImportDbConfiguration(); } @Override public void prepare() throws Exception { - if (actionContext == null) { + super.prepare(); - // keep it since exec and wait then use another thread - actionContext = ActionContext.getContext(); - } else { + service = newService(DbImportService.class); + } - // having the action context here means we already came here, - // now we need to propagate it - ActionContext.setContext(actionContext); + @Override + protected void startAction(ImportDbConfiguration model) throws Exception { + if (log.isInfoEnabled()) { + log.info("Start imports with file " + + model.getInput().getFileName()); } - model = getEchoBaseSession().getImportDbConfiguration(); - service = newService(DbImportService.class); + service.importDb(model, getEchoBaseSession().getEchoBaseUser()); } @Override - public String execute() throws Exception { + protected void closeAction(ImportDbConfiguration model) throws Exception { - model.beginAction(); + // clean configuration + model.destroy(); - // having the action context here means we already came here, - // now we need to propagate it - ActionContext.setContext(actionContext); - - // we must use a standalone transaction since it will pass through - // in more than one request - - TopiaContextImplementor tx = - (TopiaContextImplementor) serviceContext.getTransaction(); - TopiaContextImplementor rootContext = tx.getRootContext(); - TopiaContext topiaContext = rootContext.beginTransaction(); - serviceContext.setTransaction(topiaContext); - try { - - if (log.isInfoEnabled()) { - log.info("Start imports with file " + - model.getInput().getFileName()); - } - - service.importDb(model, getEchoBaseSession().getEchoBaseUser()); - model.endAction(); - return SUCCESS; - } finally { - topiaContext.closeContext(); - - // clean configuration - model.destroy(); - - // remove configuration from session - getEchoBaseSession().setImportDbConfiguration(null); - } + // remove configuration from session + getEchoBaseSession().setImportDbConfiguration(null); } + } \ No newline at end of file Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp 2011-12-27 19:41:32 UTC (rev 227) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp 2011-12-27 19:42:16 UTC (rev 228) @@ -24,16 +24,30 @@ <%@page contentType="text/html" pageEncoding="UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> +<s:url id="downloadUrl" namespace="/exportDb" action="downloadExport"/> + +<script type="text/javascript"> + + jQuery(document).ready(function () { + + // start to download by it-self the result of import + window.open("${downloadUrl}"); + }); + +</script> <title><s:text name="echobase.title.exportDbResult"/></title> <div> - L'export de la base complête a réussi en <s:property value="model.actionTime"/>. - Vous pouvez désormais télécharger l'archive le contenant. + L'export de la base complête a réussi en <s:property + value="model.actionTime"/>. </div> <br/> -<s:a namespace="/exportDb" action="downloadExport"> - <s:text name="echobase.action.downloadExportDbFile"/> -</s:a> +<div> + Si le téléchargement n'a pas démarré automatiquement, suivez ce lien : + <a href="${downloadUrl}" target="download"> + <s:text name="echobase.action.downloadExportDbFile"/> + </a> +</div>
participants (1)
-
tchemit@users.forge.codelutin.com