r613 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti tutti-service/src/main/java/fr/ifremer/tutti/service tutti-ui-swing/src/main/filtered-resources tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action tutti-ui-swing/src/main/resources/i18n tutti-ui-swing/src/main/resources/icons
Author: tchemit Date: 2013-03-14 10:41:03 +0100 (Thu, 14 Mar 2013) New Revision: 613 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/613 Log: fixes #2116: [IMP/EXP] Pouvoir importer une base de donn?\195?\169es pr?\195?\169c?\195?\169demment export?\195?\169e Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportAndCleanDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ImportDbAction.java trunk/tutti-ui-swing/src/main/resources/icons/action-import-db.png Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/TuttiIOUtil.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/TuttiIOUtil.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/TuttiIOUtil.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/TuttiIOUtil.java 2013-03-14 09:41:03 UTC (rev 613) @@ -26,6 +26,10 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSelector; +import org.apache.commons.vfs2.FileSystemManager; +import org.apache.commons.vfs2.VFS; import org.nuiton.util.ZipUtil; import java.io.Closeable; @@ -62,6 +66,44 @@ } } + public static FileObject resolveFile(String file, String errorMessage) { + try { + FileSystemManager manager = VFS.getManager(); + FileObject targetObject = manager.resolveFile(file); + return targetObject; + } catch (IOException e) { + throw new TuttiTechnicalException(errorMessage, e); + } + } + + public static FileObject[] getChildren(FileObject objectFile, String errorMessage) { + try { + return objectFile.getChildren(); + } catch (IOException e) { + throw new TuttiTechnicalException(errorMessage, e); + } + } + + public static FileObject getChild(FileObject objectFile, String name, String errorMessage) { + try { + return objectFile.getChild(name); + } catch (IOException e) { + throw new TuttiTechnicalException(errorMessage, e); + } + } + + public static void explode(FileObject archiveFile, + File target, + FileSelector fileSelector, String errorMessage) { + try { + FileSystemManager manager = VFS.getManager(); + FileObject targetObject = manager.toFileObject(target); + targetObject.copyFrom(archiveFile, fileSelector); + } catch (IOException e) { + throw new TuttiTechnicalException(errorMessage, e); + } + } + public static void forceMkdir(File dir, String errorMessage) { try { FileUtils.forceMkdir(dir); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-03-14 09:41:03 UTC (rev 613) @@ -25,6 +25,7 @@ */ import com.google.common.base.Preconditions; +import fr.ifremer.tutti.TuttiBusinessException; import fr.ifremer.tutti.TuttiIOUtil; import fr.ifremer.tutti.persistence.InvalidBatchModelException; import fr.ifremer.tutti.persistence.TuttiPersistence; @@ -58,6 +59,8 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.commons.vfs2.AllFileSelector; +import org.apache.commons.vfs2.FileObject; import java.io.File; import java.io.IOException; @@ -104,33 +107,32 @@ public static final String EXPORT_DIRECTORY_FORMAT = "tutti-%s-%s"; /** - * Export db as an zip archive (including the attachments). + * Export db as a zip archive (including the attachments and protocols). * * @param file archive file where to store * @since 1.0.2 */ public void exportDb(File file) { - Preconditions.checkState(isDbLoaded()); + // can not do this operation on a opnened bd + Preconditions.checkState(!isDbLoaded()); + + // need a file to export Preconditions.checkNotNull(file); - // Make sure db is shutdown + // create zip structure - TuttiIOUtil.close(driver, "Could not close driver " + driver); + TuttiServiceConfig config = context.getConfig(); - try { - // create zip structure + String directoryName = String.format( + EXPORT_DIRECTORY_FORMAT, + config.getVersion(), + EXPORT_DATE_FORMAT.format(context.currentDate())); - TuttiServiceConfig config = context.getConfig(); + File structureDirectory = new File(config.newTempFile("exportdb"), + directoryName); - String directoryName = String.format( - EXPORT_DIRECTORY_FORMAT, - config.getVersion(), - EXPORT_DATE_FORMAT.format(context.currentDate())); - - File structureDirectory = new File(config.newTempFile("exportdb"), - directoryName); - + try { TuttiIOUtil.forceMkdir(structureDirectory, "Could not create directory"); @@ -151,17 +153,86 @@ new File(structureDirectory, "meas_files"), "Could not copy db attachment directory"); - //create zip + // create zip TuttiIOUtil.zip(structureDirectory, file, "Could not create archive at " + file); } finally { - // reload driver - driver = TuttiPersistenceServiceLocator.getPersistenceService(); + // delete temp files + TuttiIOUtil.forceDeleteOnExit( + structureDirectory, + "could not delete on exit temporary file " + structureDirectory); } } + + public void checkImportStructure(File file) { + + if (!file.exists()) { + throw new TuttiBusinessException("Db archive " + file + " does not exists"); + } + + // check zip structure + FileObject fileObject = TuttiIOUtil.resolveFile( + "zip:" + file.getAbsolutePath(), "could not obtain archive"); + + + FileObject[] children = TuttiIOUtil.getChildren(fileObject, "Could not open archive"); + + if (children.length != 1) { + throw new TuttiBusinessException("Db archive " + file + " should have only one children"); + } + fileObject = children[0]; + checkArchiveDb(file, fileObject, "db"); + checkArchiveDb(file, fileObject, "meas_files"); + checkArchiveDb(file, fileObject, "protocol"); + } + + protected void checkArchiveDb(File file, + FileObject fileObject, + String dir) { + FileObject directory = TuttiIOUtil.getChild(fileObject, dir, " could not obtain child " + dir); + if (directory == null) { + throw new TuttiBusinessException( + "Db archive " + file + " does not contains a " + + dir + " directory."); + } + } + + /** + * Import a db from a zip archive (including the attachments and protocols). + * + * @param file archive file where to store + * @since 1.0.2 + */ + public void importDb(File file) { + + // can not do this operation on a opnened bd + Preconditions.checkState(!isDbLoaded()); + + // need a file to export + Preconditions.checkNotNull(file); + + TuttiServiceConfig config = context.getConfig(); + + File target = config.getDataDirectory(); + + if (log.isInfoEnabled()) { + log.info("Import db to " + target); + } + FileObject fileObject = TuttiIOUtil.resolveFile("zip:" + file.getAbsolutePath(), "could not obtain archive"); + + FileObject[] children = TuttiIOUtil.getChildren(fileObject, "Could not open archive"); + + fileObject = children[0]; + + TuttiIOUtil.explode(fileObject, + target, + new AllFileSelector(), + "Could not decompress archive " + file); + } + public boolean isDbLoaded() { return !(driver instanceof TuttiPersistenceNoDbImpl); } Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties 2013-03-14 09:41:03 UTC (rev 613) @@ -1,12 +1,37 @@ +### +# #%L +# Tutti :: UI +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 - 2013 Ifremer +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Thu Mar 14 07:41:37 CET 2013 +#Thu Mar 14 09:01:00 CET 2013 tuttihelp.createSpeciesBatch.action.addSpecies.help= tuttihelp.createSpeciesBatch.field.batchWeightField.help= tuttihelp.createSpeciesBatch.field.sortedUnsortedCategoryComboBox.help= tuttihelp.createSpeciesBatch.field.speciesComboBox.help= tuttihelp.createSpeciesBatch.help= tuttihelp.dbManager.action.closeDb.help= +tuttihelp.dbManager.action.exportAndCleanDb.help= tuttihelp.dbManager.action.exportDb.help= +tuttihelp.dbManager.action.importDb.help= tuttihelp.dbManager.action.installDb.help= tuttihelp.dbManager.action.openDb.help= tuttihelp.dbManager.action.upgradeDb.help= Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2013-03-14 09:41:03 UTC (rev 613) @@ -8,28 +8,30 @@ # %% # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the +# 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 General Public +# +# You should have received a copy of the GNU General Public # License along with this program. If not, see # <http://www.gnu.org/licenses/gpl-3.0.html>. # #L% ### #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Tue Mar 12 09:29:29 CET 2013 +#Thu Mar 14 09:01:00 CET 2013 tuttihelp.createSpeciesBatch.action.addSpecies.help=createSpeciesBatch.html\#actions tuttihelp.createSpeciesBatch.field.batchWeightField.help=createSpeciesBatch.html\#fields tuttihelp.createSpeciesBatch.field.sortedUnsortedCategoryComboBox.help=createSpeciesBatch.html\#fields tuttihelp.createSpeciesBatch.field.speciesComboBox.help=createSpeciesBatch.html\#fields tuttihelp.createSpeciesBatch.help=createSpeciesBatch.html tuttihelp.dbManager.action.closeDb.help=dbManager.html\#actions +tuttihelp.dbManager.action.exportAndCleanDb.help= tuttihelp.dbManager.action.exportDb.help=dbManager.html\#actions +tuttihelp.dbManager.action.importDb.help= tuttihelp.dbManager.action.installDb.help=dbManager.html\#actions tuttihelp.dbManager.action.openDb.help=dbManager.html\#actions tuttihelp.dbManager.action.upgradeDb.help=dbManager.html\#actions Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/MainUIHandler.java 2013-03-14 09:41:03 UTC (rev 613) @@ -192,7 +192,6 @@ TuttiUIAction<OpenDbAction> uiAction = createUIAction(null, OpenDbAction.class); OpenDbAction logicAction = uiAction.getLogicAction(); logicAction.setSkipCheckCurrentScreen(true); - logicAction.setActionDescription(_("tuttihelp.dbManager.action.openDb.tip")); uiAction.actionPerformed(null); } else { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/CloseDbAction.java 2013-03-14 09:41:03 UTC (rev 613) @@ -24,6 +24,7 @@ * #L% */ +import fr.ifremer.tutti.TuttiIOUtil; import fr.ifremer.tutti.persistence.config.TuttiPersistenceConfig; import fr.ifremer.tutti.ui.swing.TuttiScreen; import fr.ifremer.tutti.ui.swing.content.AbstractChangeScreenAction; @@ -70,6 +71,10 @@ // clean db context getContext().clearDbContext(); + + TuttiIOUtil.deleteDirectory( + getConfig().getServiceConfig().getPersistenceConfig().getCacheDirectory(), + "Could not delete cache directory"); } @Override Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.css 2013-03-14 09:41:03 UTC (rev 613) @@ -39,12 +39,21 @@ #installDbButton { actionIcon: install-db; text: "tutti.action.installDb"; - mnemonic: I; + mnemonic: n; _tuttiAction: {InstallDbAction.class}; toolTipText: "tuttihelp.dbManager.action.installDb.tip"; _help: {"tuttihelp.dbManager.action.installDb.help"}; } +#importDbButton { + actionIcon: import-db; + text: "tutti.action.importDb"; + mnemonic: I; + _tuttiAction: {ImportDbAction.class}; + toolTipText: "tuttihelp.dbManager.action.importDb.tip"; + _help: {"tuttihelp.dbManager.action.importDb.help"}; +} + #withDbActions { visible: {model.isDbExist()}; } @@ -72,7 +81,7 @@ #closeDbButton { actionIcon: close-db; text: "tutti.action.closeDb"; - mnemonic: C; + mnemonic: F; enabled: {model.isDbLoaded()}; _tuttiAction: {CloseDbAction.class}; toolTipText: "tuttihelp.dbManager.action.closeDb.tip"; @@ -88,3 +97,13 @@ toolTipText: "tuttihelp.dbManager.action.exportDb.tip"; _help: {"tuttihelp.dbManager.action.exportDb.help"}; } + +#exportAndCleanDbButton { + actionIcon: export-db; + text: "tutti.action.exportAndCleanDb"; + mnemonic: E; + enabled: {model.isDbLoaded()}; + _tuttiAction: {ExportAndCleanDbAction.class}; + toolTipText: "tuttihelp.dbManager.action.exportAndCleanDb.tip"; + _help: {"tuttihelp.dbManager.action.exportAndCleanDb.help"}; +} \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUI.jaxx 2013-03-14 09:41:03 UTC (rev 613) @@ -62,12 +62,14 @@ <JPanel id='noDbActions' constraints='BorderLayout.CENTER' layout='{new GridLayout(0, 1)}'> <JButton id='installDbButton'/> + <JButton id='importDbButton'/> </JPanel> <JPanel id='withDbActions' constraints='BorderLayout.SOUTH' layout='{new GridLayout(0, 1)}'> <JButton id='openDbButton'/> <JButton id='upgradeDbButton'/> <JButton id='exportDbButton'/> + <JButton id='exportAndCleanDbButton'/> <JButton id='closeDbButton'/> </JPanel> </JPanel> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/DbManagerUIHandler.java 2013-03-14 09:41:03 UTC (rev 613) @@ -58,8 +58,10 @@ if (dbExist) { if (dbLoaded) { + String jdbcUrl = getConfig().getServiceConfig().getPersistenceConfig().getJdbcUrl(); + // db loaded - message = _("tutti.information.db.loaded"); + message = _("tutti.information.db.loaded", jdbcUrl); } else { @@ -81,8 +83,10 @@ initUI(ui); ui.applyDataBinding(DbManagerUI.BINDING_OPEN_DB_BUTTON_ENABLED); +// ui.applyDataBinding(DbManagerUI.BINDING_USE_EXTERNAL_DB_BUTTON_ENABLED); ui.applyDataBinding(DbManagerUI.BINDING_UPGRADE_DB_BUTTON_ENABLED); ui.applyDataBinding(DbManagerUI.BINDING_EXPORT_DB_BUTTON_ENABLED); + ui.applyDataBinding(DbManagerUI.BINDING_EXPORT_AND_CLEAN_DB_BUTTON_ENABLED); SwingUtilities.invokeLater( new Runnable() { Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportAndCleanDbAction.java (from rev 610, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportAndCleanDbAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportAndCleanDbAction.java 2013-03-14 09:41:03 UTC (rev 613) @@ -0,0 +1,148 @@ +package fr.ifremer.tutti.ui.swing.content.db; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.TuttiIOUtil; +import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.persistence.config.TuttiPersistenceConfig; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.ui.swing.content.AbstractMainUITuttiAction; +import fr.ifremer.tutti.ui.swing.content.MainUIHandler; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; + +import static org.nuiton.i18n.I18n._; + +/** + * To export a db attached to Tutti. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class ExportAndCleanDbAction extends AbstractMainUITuttiAction { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ExportAndCleanDbAction.class); + + protected File file; + + public ExportAndCleanDbAction(MainUIHandler handler) { + super(handler, true); + } + + @Override + protected boolean prepareAction() throws Exception { + file = null; + boolean doAction = super.prepareAction(); + + if (doAction) { + + // ask user file where to export db + + // choose file to import + file = TuttiUIUtil.chooseFile( + getContext().getMainUI(), + _("tutti.title.choose.dbExportFile"), + _("tutti.action.chooseDbExportFile"), + "^.*\\.zip", _("tutti.file.zip") + ); + if (file == null) { + + // user cancel + doAction = false; + } else { + + // add extension if missing + file = TuttiIOUtil.addExtensionIfMissing(file, ".zip"); + + // ask user to confirm overwrite. + doAction = getHandler().askOverwriteFile(file); + } + } + return doAction; + } + + @Override + protected void doAction() { + Preconditions.checkNotNull(file); + if (log.isInfoEnabled()) { + log.info("Will export db to " + file); + } + + ProgressionModel progressionModel = new ProgressionModel(); + setProgressionModel(progressionModel); + progressionModel.setTotal(3); + + // close db + + progressionModel.setMessage("Fermeture de la base courante"); + + runAction(getHandler().createLogicAction(CloseDbAction.class)); + + PersistenceService persistenceService = + getContext().getPersistenceService(); + + // export db + + progressionModel.increments(1); + progressionModel.setMessage("Création de l'archive " + file); + + persistenceService.exportDb(file); + + // clean files + + progressionModel.increments(1); + progressionModel.setMessage("Suppression des fichiers dans Tutti"); + + TuttiPersistenceConfig persistenceConfig = + getConfig().getServiceConfig().getPersistenceConfig(); + + File dbDirectory = persistenceConfig.getDbDirectory(); + TuttiIOUtil.cleanDirectory(dbDirectory, "Could not delete directory " + dbDirectory); + + File attachmentDirectory = persistenceConfig.getDbAttachmentDirectory(); + TuttiIOUtil.cleanDirectory(attachmentDirectory, "Could not delete directory " + attachmentDirectory); + + File protocolDirectory = persistenceConfig.getProtocolDirectory(); + TuttiIOUtil.cleanDirectory(protocolDirectory, "Could not delete directory " + protocolDirectory); + + getModel().setDbExist(false); + } + + @Override + public void postSuccessAction() { + super.postSuccessAction(); + + sendMessage(_("tutti.flash.information.db.exported.and.clean", file)); + + // make sure title is reloaded + getUI().getHandler().changeTitle(); + } + +} \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ExportDbAction.java 2013-03-14 09:41:03 UTC (rev 613) @@ -26,6 +26,7 @@ import com.google.common.base.Preconditions; import fr.ifremer.tutti.TuttiIOUtil; +import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.ui.swing.content.AbstractMainUITuttiAction; import fr.ifremer.tutti.ui.swing.content.MainUIHandler; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; @@ -92,14 +93,39 @@ log.info("Will export db to " + file); } + ProgressionModel progressionModel = new ProgressionModel(); + setProgressionModel(progressionModel); + progressionModel.setTotal(3); + + // close db + + progressionModel.setMessage("Fermuture de la base courante"); + + getContext().setDbLoaded(false); + getHandler().reloadPersistenceService(); + + // export + + progressionModel.increments(1); + progressionModel.setMessage("Création de l'archive " + file); + getContext().getPersistenceService().exportDb(file); + // reopen db + progressionModel.increments(1); + progressionModel.setMessage("Réouverture de la base courante"); + + getContext().setDbLoaded(true); + getHandler().reloadPersistenceService(); } @Override public void postSuccessAction() { super.postSuccessAction(); sendMessage(_("tutti.flash.information.db.exported", file)); + + // make sure title is reloaded + getUI().getHandler().changeTitle(); } } \ No newline at end of file Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ImportDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ImportDbAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ImportDbAction.java 2013-03-14 09:41:03 UTC (rev 613) @@ -0,0 +1,121 @@ +package fr.ifremer.tutti.ui.swing.content.db; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.persistence.config.TuttiPersistenceConfig; +import fr.ifremer.tutti.ui.swing.content.AbstractMainUITuttiAction; +import fr.ifremer.tutti.ui.swing.content.MainUIHandler; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; + +import static org.nuiton.i18n.I18n._; + +/** + * To import a db and use it. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public class ImportDbAction extends AbstractMainUITuttiAction { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ImportDbAction.class); + + protected File file; + + public ImportDbAction(MainUIHandler handler) { + super(handler, true); + } + + @Override + protected boolean prepareAction() throws Exception { + + boolean doAction = super.prepareAction(); + + if (doAction) { + + // choose file to import + file = TuttiUIUtil.chooseFile( + getContext().getMainUI(), + _("tutti.title.choose.dbImportFile"), + _("tutti.action.chooseDbFile"), + "^.*\\.zip", _("tutti.file.zip") + ); + + doAction = file != null; + + if (doAction) { + + getContext().getPersistenceService().checkImportStructure(file); + } + } + return doAction; + } + + @Override + protected void releaseAction() { + file = null; + super.releaseAction(); + } + + @Override + protected void doAction() throws Exception { + Preconditions.checkNotNull(file); + + if (log.isInfoEnabled()) { + log.info("Will import db: " + file); + } + + ProgressionModel progressionModel = new ProgressionModel(); + progressionModel.setTotal(3); + setProgressionModel(progressionModel); + + // import db + + progressionModel.setMessage("Décompression de l'archive"); + + getContext().getPersistenceService().importDb(file); + getContext().setDbExist(true); + + // open db + + progressionModel.increments(1); + progressionModel.setMessage("Ouverture de la base de données"); + runAction(getHandler().createLogicAction(OpenDbAction.class)); + } + + @Override + public void postSuccessAction() { + super.postSuccessAction(); + String jdbcUrl = TuttiPersistenceConfig.getInstance().getJdbcUrl(); + + sendMessage(_("tutti.flash.information.db.imported", jdbcUrl)); + } +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/ImportDbAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/InstallDbAction.java 2013-03-14 09:41:03 UTC (rev 613) @@ -47,8 +47,7 @@ public class InstallDbAction extends AbstractMainUITuttiAction { /** Logger. */ - private static final Log log = - LogFactory.getLog(InstallDbAction.class); + private static final Log log = LogFactory.getLog(InstallDbAction.class); public InstallDbAction(MainUIHandler handler) { super(handler, true); @@ -69,7 +68,7 @@ File dest = new File(config.getTuttiBasedir(), "NEW"); ProgressionModel progressionModel = new ProgressionModel(); up.setDownloadMonitor(progressionModel); - getContext().getActionUI().getModel().setProgressionModel(progressionModel); + setProgressionModel(progressionModel); progressionModel.setMessage("Recherche de mises à jour de base"); TuttiApplicationUpdaterCallBack callback = @@ -92,5 +91,8 @@ String jdbcUrl = TuttiPersistenceConfig.getInstance().getJdbcUrl(); sendMessage(_("tutti.flash.information.db.installed", jdbcUrl)); + + // make sure title is reloaded + getUI().getHandler().changeTitle(); } } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/db/OpenDbAction.java 2013-03-14 09:41:03 UTC (rev 613) @@ -46,6 +46,7 @@ public OpenDbAction(MainUIHandler handler) { super(handler, true, TuttiScreen.SELECT_CRUISE); + setActionDescription(_("tuttihelp.dbManager.action.openDb.tip")); } @Override Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/AbstractTuttiAction.java 2013-03-14 09:41:03 UTC (rev 613) @@ -25,6 +25,7 @@ */ import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.ui.swing.TuttiDataContext; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.config.TuttiApplicationConfig; @@ -123,6 +124,14 @@ this.actionDescription = actionDescription; } + protected void setProgressionModel(ProgressionModel progressionModel) { + getContext().getActionUI().getModel().setProgressionModel(progressionModel); + } + + protected ProgressionModel getProgressionModel() { + return getContext().getActionUI().getModel().getProgressionModel(); + } + public boolean isHideBody() { return hideBody; } Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-03-14 09:41:03 UTC (rev 613) @@ -16,6 +16,7 @@ tutti.action.changeLocaleFR= tutti.action.changeLocaleUK= tutti.action.chooseDbExportFile= +tutti.action.chooseDbFile= tutti.action.chooseProtocolCaracteristicFile= tutti.action.chooseProtocolFile= tutti.action.chooseProtocolSpeciesFile= @@ -55,6 +56,7 @@ tutti.action.editSelectedProgram= tutti.action.editSelectedProtocol= tutti.action.exit= +tutti.action.exportAndCleanDb= tutti.action.exportDb= tutti.action.exportProtocol= tutti.action.exportProtocolAllCaracteristic= @@ -67,6 +69,7 @@ tutti.action.generate= tutti.action.generateCampaignName= tutti.action.importCasino= +tutti.action.importDb= tutti.action.importProtocol= tutti.action.importProtocolCaracteristic= tutti.action.importProtocolSpecies= @@ -170,6 +173,8 @@ tutti.flash.information.cruiseSaved= tutti.flash.information.db.closed= tutti.flash.information.db.exported= +tutti.flash.information.db.exported.and.clean= +tutti.flash.information.db.imported= tutti.flash.information.db.installed= tutti.flash.information.db.installed.= tutti.flash.information.db.opened= @@ -441,6 +446,7 @@ tutti.title.about.translate=Translate Tutti tutti.title.attachment= tutti.title.choose.dbExportFile= +tutti.title.choose.dbImportFile= tutti.title.choose.exportTemporaryGearExampleFile= tutti.title.choose.exportTemporaryPersonExampleFile= tutti.title.choose.exportTemporarySpeciesExampleFile= @@ -556,7 +562,9 @@ tuttihelp.createSpeciesBatch.field.sortedUnsortedCategoryComboBox.tip= tuttihelp.createSpeciesBatch.field.speciesComboBox.tip= tuttihelp.dbManager.action.closeDb.tip= +tuttihelp.dbManager.action.exportAndCleanDb.tip= tuttihelp.dbManager.action.exportDb.tip= +tuttihelp.dbManager.action.importDb.tip= tuttihelp.dbManager.action.installDb.tip= tuttihelp.dbManager.action.openDb.tip= tuttihelp.dbManager.action.upgradeDb.tip= Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-03-14 06:46:28 UTC (rev 612) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-03-14 09:41:03 UTC (rev 613) @@ -16,6 +16,7 @@ tutti.action.changeLocaleFR=Français tutti.action.changeLocaleUK=Anglais tutti.action.chooseDbExportFile=Exporter la base de données +tutti.action.chooseDbFile=Choisir la base à importer tutti.action.chooseProtocolCaracteristicFile=Choisir le fichier des caractéristiques tutti.action.chooseProtocolFile=Choisir le fichier de protocole tutti.action.chooseProtocolSpeciesFile=Choisir le fichier des espèces @@ -25,7 +26,7 @@ tutti.action.chooseReferentialVesselFile=Choisir le fichier de référentiel navire tutti.action.cloneProtocol=Cloner tutti.action.close=Fermer -tutti.action.closeAttachment.tip=Fermer la fenêtre des picèes-jointes +tutti.action.closeAttachment.tip=Fermer la fenêtre des pièces-jointes tutti.action.closeCommentEditor.tip=Fermer la fenêtre des commentaires tutti.action.closeDb=Fermer tutti.action.comment.tip=Commentaire @@ -62,6 +63,7 @@ tutti.action.editSelectedProgram.tip=Éditer la série de campagne sélectionnée tutti.action.editSelectedProtocol=Protocole tutti.action.exit=Quitter +tutti.action.exportAndCleanDb=Exporter et supprimer tutti.action.exportDb=Exporter tutti.action.exportProtocol=Exporter tutti.action.exportProtocolAllCaracteristic=Exporter toutes les caractéristiques @@ -74,6 +76,7 @@ tutti.action.generate=Générer tutti.action.generateCampaignName=Générer le nom tutti.action.importCasino=Import Casino +tutti.action.importDb=Importer une base tutti.action.importProtocol=Importer tutti.action.importProtocolCaracteristic=Importer les caractéristiques tutti.action.importProtocolSpecies=Importer les espèces @@ -176,6 +179,8 @@ tutti.flash.information.cruiseSaved=La campagne <strong>%s</strong> a été enregistrée. tutti.flash.information.db.closed=La base de données <strong>%s</strong> est fermée. tutti.flash.information.db.exported=Base exportée dans l'archive <strong>%s</strong>. +tutti.flash.information.db.exported.and.clean=Base exportée dans l'archive <strong>%s</strong>. +tutti.flash.information.db.imported=La base de données <strong>%s</strong> est importée. tutti.flash.information.db.installed=La base de données <strong>%s</strong> est installée. tutti.flash.information.db.opened=La base de données <strong>%s</strong> est ouverte. tutti.flash.information.programCreated=La série de campagne <strong>%s</strong> a été créée. @@ -189,9 +194,9 @@ tutti.flash.information.species.imported.in.protocol.severalReplaced=Espèces importées dans le protocole depuis le fichier <strong>%s</strong>. %s remplacées par leur référent. tutti.flash.information.species.remove.from.protocol=L'espèce <strong>%s</strong> a été retirée du protocole. tutti.flash.information.species.replaced=L'espèce <strong>%s</strong> a été remplacée par son référent <strong>%s</strong>. -tutti.information.db.loaded=Tutti est connecté à une base de données -tutti.information.no.db.exist=Aucune base détectée, vous pouvez installer la dernière disponible sur le réseau. -tutti.information.no.db.loaded=Tutti a détecté une base mais elle n'est pas actuellement ouverte. +tutti.information.db.loaded=<html>Tutti est connecté à une base de données<hr/>Url de connexion \: <strong>%s</strong></html> +tutti.information.no.db.exist=Aucune base détectée, vous pouvez installer la dernière disponible sur le réseau ou bien en importer une. +tutti.information.no.db.loaded=Tutti possède une base mais elle n'est pas actuellement ouverte. tutti.label.attachmentEditor.file=Fichier tutti.label.attachmentEditor.fileComment=Commentaire tutti.label.attachmentEditor.fileName=Nom @@ -460,6 +465,7 @@ tutti.title.about.translate=Traduire Tutti tutti.title.attachment=Pièces jointes tutti.title.choose.dbExportFile=Exporter la base de données +tutti.title.choose.dbImportFile=Importer la base de données tutti.title.choose.exportTemporaryGearExampleFile=Exporter un exemple de référentiel Engin tutti.title.choose.exportTemporaryPersonExampleFile=Exporter un exemple de référentiel Personne tutti.title.choose.exportTemporarySpeciesExampleFile=Exporter un exemple de référentiel Espèce @@ -566,7 +572,7 @@ tutti.validator.warning.longitude.outOfBounds=La Latitude doit être comprise entre -180.0 et 180.0 tutti.validator.warning.longitude.second.outOfBounds=La seconde de la longitude doit être comprise entre 0 et 60 tutti.warn.invalid.batch.model=L'arbre d'échantillonage n'est pas compatible. Les captures ne seront pas visibles. -tutti.warn.invalid.program=Le programme sélectionné ne possède pas de zone, il ne peut pas être édité. +tutti.warn.invalid.program=La série de campagne sélectionnée ne possède pas de zone, ses captures ne peuvent pas être éditées. tuttihelp.createSpeciesBatch.action.addSpecies.tip=Sélectionner une autre espèce tuttihelp.createSpeciesBatch.action.cancel.tip= tuttihelp.createSpeciesBatch.action.save.tip= @@ -574,9 +580,11 @@ tuttihelp.createSpeciesBatch.field.sortedUnsortedCategoryComboBox.tip= tuttihelp.createSpeciesBatch.field.speciesComboBox.tip= tuttihelp.dbManager.action.closeDb.tip=Fermer la base de données en cours d'utilisation +tuttihelp.dbManager.action.exportAndCleanDb.tip=Exporter la base de données au format zip puis supprimer les fichiers de Tutti tuttihelp.dbManager.action.exportDb.tip=Exporter la base de données au format zip +tuttihelp.dbManager.action.importDb.tip=Importer la base de données au format zip tuttihelp.dbManager.action.installDb.tip=Télécharger puis installer la base de données -tuttihelp.dbManager.action.openDb.tip=Ouvrir la base de données détectée par Tutti +tuttihelp.dbManager.action.openDb.tip=Ouvrir la base de données tuttihelp.dbManager.action.upgradeDb.tip=Mettre à jour les référentiels si nécessaire tuttihelp.editCatchBatch.action.cancelEditCatchBatch.tip=Réinitialiser l'édition de la capture tuttihelp.editCatchBatch.action.computeWeights.tip=Elever les poids Copied: trunk/tutti-ui-swing/src/main/resources/icons/action-import-db.png (from rev 610, trunk/tutti-ui-swing/src/main/resources/icons/action-install-db.png) =================================================================== (Binary files differ)
participants (1)
-
tchemit@users.forge.codelutin.com