Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 58b30886 by Tony Chemit at 2021-03-12T13:16:40+01:00 Réusinage de la configuration d'une source de données et des templates associées - Closes #1797 - - - - - b564c86a by Tony Chemit at 2021-03-12T13:16:40+01:00 Bloquer l'import d'une marée si elle contient des identifiants déjà utilisés dans la base cible - Closes #1799 - - - - - 384b1d11 by Tony Chemit at 2021-03-12T13:16:40+01:00 Update jaxx - - - - - a5cef205 by Tony Chemit at 2021-03-12T13:16:40+01:00 Fix LL Paring admin action - - - - - 9d65cd9d by Tony Chemit at 2021-03-12T13:16:40+01:00 Simplify admin actions menu: no more any generated menu ui, just declare them while installing the body content - - - - - 27 changed files: - client/core/src/main/java/fr/ird/observe/client/util/treetable/JaxxComboBoxCellEditor.java - client/datasource/actions/src/main/i18n/getters/java.getter - client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/AdminUIBodyContent.java - client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchAdminActionSupport.java → client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/actions/LaunchAdminAction.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/AdminUIMenu.jaxx - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/AdminUIMenu.jcss - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/AdminUIMenuActionSupport.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchActivityLlPairingAction.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchConsolidateAction.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchDataSynchronizeAction.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchExportDataAction.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchReferentialSynchronizeAction.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchReportAction.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchSynchronizeAction.java - − client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchValidateAction.java - client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/pairing/ll/tree/ActivityLlPairingTreeTable.java - client/datasource/api/src/main/i18n/templates/InitStorageModel_en_GB.ftl - client/datasource/api/src/main/i18n/templates/InitStorageModel_es_ES.ftl - client/datasource/api/src/main/i18n/templates/InitStorageModel_fr_FR.ftl - client/datasource/api/src/main/java/fr/ird/observe/client/datasource/h2/backup/InitStorageModel.java → client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/h2/backup/InitStorageModel.java - client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/h2/server/H2ServerUI.jaxx - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/DataSourceEditorHelper.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/menu/DataSourceEditorMenu.jcss - models/dto/java/pom.xml - models/dto/java/src/main/java/fr/ird/observe/dto/data/ll/pairing/ActivityPairingResultItem.java - pom.xml - services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/TripManagementServiceLocalSupport.java Changes: ===================================== client/core/src/main/java/fr/ird/observe/client/util/treetable/JaxxComboBoxCellEditor.java ===================================== @@ -22,17 +22,16 @@ package fr.ird.observe.client.util.treetable; * #L% */ -import fr.ird.observe.client.util.UIHelper; +import fr.ird.observe.dto.decoration.ObserveI18nDecoratorHelper; import io.ultreia.java4all.jaxx.widgets.combobox.JaxxComboBox; import org.nuiton.decorator.MultiJXPathDecorator; import javax.swing.DefaultCellEditor; import javax.swing.JComboBox; import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.MouseEvent; import java.util.Collections; -import java.util.EventObject; + +import static io.ultreia.java4all.i18n.I18n.t; /** * Created by tchemit on 20/11/2018. @@ -41,12 +40,24 @@ import java.util.EventObject; */ public class JaxxComboBoxCellEditor extends DefaultCellEditor { + public static <B> JaxxComboBoxCellEditor newEditor(Class<B> dataType, MultiJXPathDecorator<B> decorator) { + JaxxComboBox<B> editor = new JaxxComboBox<>(); + editor.setI18nPrefix("observe.common."); + String entityLabel = ObserveI18nDecoratorHelper.getType(dataType); + editor.setPopupTitleText(t("observe.data.Data.type", entityLabel)); + editor.setBeanType(dataType); + editor.setMinimumSize(new Dimension(0, 24)); + editor.getConfig().setFilterable(false); + editor.getConfig().setTabToSelect(false); + editor.init(decorator, Collections.emptyList()); + return new JaxxComboBoxCellEditor(editor); + } + @SuppressWarnings("rawtypes") public JaxxComboBoxCellEditor(JaxxComboBox editor) { super(editor.getCombobox()); this.editorComponent = editor; JComboBox comboBox = editor.getCombobox(); - comboBox.setFocusable(false); editorComponent.setOpaque(false); comboBox.removeActionListener(this.delegate); @@ -55,6 +66,7 @@ public class JaxxComboBoxCellEditor extends DefaultCellEditor { @Override public void setValue(Object value) { editor.setSelectedItem(value); + super.setValue(value); } @Override @@ -62,39 +74,22 @@ public class JaxxComboBoxCellEditor extends DefaultCellEditor { return editor.getModel().getSelectedItem(); } - @Override - public boolean shouldSelectCell(EventObject anEvent) { - if (anEvent instanceof MouseEvent) { - MouseEvent e = (MouseEvent) anEvent; - return e.getID() != MouseEvent.MOUSE_DRAGGED; - } - return true; - } - + @SuppressWarnings("unchecked") @Override public boolean stopCellEditing() { if (comboBox.isEditable()) { - // Commit edited value. - comboBox.actionPerformed(new ActionEvent(JaxxComboBoxCellEditor.this, 0, "")); + Object cellEditorValue = getCellEditorValue(); + if (cellEditorValue != null && !editor.getConfig().getBeanType().isAssignableFrom(cellEditorValue.getClass())) { + setValue(null); + } } return super.stopCellEditing(); } - - @Override - public void actionPerformed(ActionEvent e) { - JaxxComboBoxCellEditor.this.stopCellEditing(); - } }; comboBox.addActionListener(this.delegate); } - public static <B> JaxxComboBoxCellEditor newEditor(Class<B> dataType, MultiJXPathDecorator<B> decorator) { - JaxxComboBox<B> editor = UIHelper.newJaxxComboBox(dataType, decorator, Collections.emptyList()); - editor.setMinimumSize(new Dimension(0, 24)); - return new JaxxComboBoxCellEditor(editor); - } - @Override public JaxxComboBox<?> getComponent() { return (JaxxComboBox<?>) super.getComponent(); ===================================== client/datasource/actions/src/main/i18n/getters/java.getter ===================================== @@ -186,6 +186,7 @@ observe.ui.datasource.storage.config.referentiel.storage observe.ui.datasource.storage.config.right.storage observe.ui.datasource.storage.config.source.storage observe.ui.datasource.storage.step.label +observe.ui.menu.actions observe.ui.message.no.report.selected observe.ui.message.select.report observe.ui.title.choose.db.dump.directory ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/AdminUIBodyContent.java ===================================== @@ -24,7 +24,7 @@ package fr.ird.observe.client.datasource.actions; import com.google.auto.service.AutoService; import fr.ird.observe.client.WithClientUIContext; -import fr.ird.observe.client.datasource.actions.menu.AdminUIMenu; +import fr.ird.observe.client.datasource.actions.actions.LaunchAdminAction; import fr.ird.observe.client.datasource.api.ObserveSwingDataSource; import fr.ird.observe.client.datasource.editor.api.DataSourceEditor; import fr.ird.observe.client.datasource.editor.api.DataSourceEditorBodyContent; @@ -35,6 +35,7 @@ import fr.ird.observe.client.main.body.NoBodyContentComponent; import fr.ird.observe.client.util.UIHelper; import fr.ird.observe.dto.ObserveUtil; import fr.ird.observe.dto.db.configuration.ObserveDataSourceConfiguration; +import io.ultreia.java4all.i18n.I18n; import io.ultreia.java4all.util.SingletonSupplier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -42,7 +43,9 @@ import org.nuiton.jaxx.runtime.JAXXUtil; import org.nuiton.jaxx.runtime.context.JAXXContextEntryDef; import org.nuiton.jaxx.runtime.context.JAXXInitialContext; +import javax.swing.JMenu; import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.SwingUtilities; import java.util.Objects; import java.util.function.Supplier; @@ -72,11 +75,29 @@ public class AdminUIBodyContent extends MainUIBodyContent<AdminUI> implements Wi @Override public void install(ObserveMainUI mainUI) { super.install(mainUI); - AdminUIMenu menu = new AdminUIMenu(UIHelper.initialContext(mainUI, mainUI.getModel())); + JMenu menu = new JMenu(I18n.t("observe.ui.menu.actions")); + menu.setMnemonic('A'); + addMenuAction(mainUI, menu, AdminStep.SYNCHRONIZE); + addMenuAction(mainUI, menu, AdminStep.REFERENTIAL_SYNCHRONIZE); + menu.addSeparator(); + addMenuAction(mainUI, menu, AdminStep.EXPORT_DATA); + addMenuAction(mainUI, menu, AdminStep.DATA_SYNCHRONIZE); + menu.addSeparator(); + addMenuAction(mainUI, menu, AdminStep.CONSOLIDATE); + addMenuAction(mainUI, menu, AdminStep.ACTIVITY_LL_PAIRING); + addMenuAction(mainUI, menu, AdminStep.VALIDATE); + addMenuAction(mainUI, menu, AdminStep.REPORT); JMenuBar menuBar = mainUI.getMenu(); menuBar.add(menu, 2); } + protected void addMenuAction(ObserveMainUI mainUI, JMenu menu, AdminStep step) { + LaunchAdminAction action = new LaunchAdminAction(step); + JMenuItem menuItem = new JMenuItem(); + LaunchAdminAction.init(mainUI, menuItem, action); + menu.add(menuItem); + } + @Override public void show(ObserveMainUI mainUI) { super.show(mainUI); @@ -102,12 +123,7 @@ public class AdminUIBodyContent extends MainUIBodyContent<AdminUI> implements Wi AdminUI ui = get(); AdminUIModel model = ui.getModel(); - -// ConfigModel.doCloseSource(model.getConfigModel().getRightSourceModel().getSource()); -// ConfigModel.doCloseSource(model.getConfigModel().getLeftSourceModel().getSource()); - model.destroy(); - ui.destroy(); ui.dispose(); @@ -135,7 +151,6 @@ public class AdminUIBodyContent extends MainUIBodyContent<AdminUI> implements Wi AdminStep adminStep = mainUI.getContextValue(AdminStep.class); AdminUIModel model = new AdminUIModel(Objects.requireNonNull(adminStep)); JAXXInitialContext uiContext = UIHelper.initialContext(mainUI, model); - //FIXME:BodyContent Review jaxx to remove this... // apply action uiContext.add(APPLY_DEF, () -> { @@ -150,30 +165,23 @@ public class AdminUIBodyContent extends MainUIBodyContent<AdminUI> implements Wi } private void doClose(boolean wasCanceled) { - log.info(this + ", was canceled ? " + wasCanceled); - + log.info(String.format("%s, was canceled ? %s", this, wasCanceled)); AdminUI ui = get(); AdminUIModel model = ui.getModel(); - ObserveSwingDataSource.doCloseSource(model.getConfigModel().getRightSourceModel().getSource()); ObserveSwingDataSource.doCloseSource(model.getConfigModel().getLeftSourceModel().getSource()); - ObserveMainUI mainUI = getClientUIContext().getMainUI(); - ObserveDataSourceConfiguration sourceConfiguration = model.getConfigModel().getPreviousSourceConfiguration(); if (sourceConfiguration == null) { // no previous data source mainUI.changeBodyContent(NoBodyContentComponent.class); return; } - // reopen data source ObserveSwingDataSource source = getClientUIContext().getDataSourcesManager().newDataSource(sourceConfiguration); // attach it to ui DataSourceEditorBodyContent dataSourceEditorBodyContent = mainUI.getMainUIBodyContentManager().getBodyTyped(DataSourceEditor.class, DataSourceEditorBodyContent.class); // load it dataSourceEditorBodyContent.loadStorage(mainUI, source); - } - } ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchAdminActionSupport.java → client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/actions/LaunchAdminAction.java ===================================== @@ -1,4 +1,4 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; +package fr.ird.observe.client.datasource.actions.actions; /* * #%L @@ -24,8 +24,8 @@ package fr.ird.observe.client.datasource.actions.menu.actions; import fr.ird.observe.client.datasource.actions.AdminStep; import fr.ird.observe.client.datasource.actions.AdminUI; -import fr.ird.observe.client.datasource.actions.menu.AdminUIMenu; import fr.ird.observe.client.main.ObserveMainUI; +import fr.ird.observe.client.main.actions.MainUIActionSupport; import fr.ird.observe.dto.I18nEnumHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -41,13 +41,13 @@ import static io.ultreia.java4all.i18n.I18n.t; * @author Tony Chemit - dev@tchemit.fr * @since 3.13 */ -public abstract class LaunchAdminActionSupport extends AdminUIMenuActionSupport { +public class LaunchAdminAction extends MainUIActionSupport { - private static final Logger log = LogManager.getLogger(LaunchAdminActionSupport.class); + private static final Logger log = LogManager.getLogger(LaunchAdminAction.class); private final AdminStep action; - LaunchAdminActionSupport(AdminStep action) { + public LaunchAdminAction(AdminStep action) { super(t(Objects.requireNonNull(action).getOperationLabel()), t(action.getOperationDescription()), action.getIconName(), action.getMnemonic()); this.action = action; } @@ -63,15 +63,13 @@ public abstract class LaunchAdminActionSupport extends AdminUIMenuActionSupport // } @Override - protected void doActionPerformed(ActionEvent e, AdminUIMenu ui) { + protected void doActionPerformed(ActionEvent e, ObserveMainUI ui) { log.info(String.format("Will start admin action: %s", I18nEnumHelper.getLabel(action))); - ObserveMainUI mainUI = getClientUIContext().getMainUI(); - mainUI.setContextValue(action); + ui.setContextValue(action); try { - mainUI.changeBodyContent(AdminUI.class); + ui.changeBodyContent(AdminUI.class); } finally { - mainUI.removeContextValue(AdminStep.class); + ui.removeContextValue(AdminStep.class); } } - } ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/AdminUIMenu.jaxx deleted ===================================== @@ -1,38 +0,0 @@ -<!-- - #%L - ObServe Client :: DataSource :: Actions - %% - Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - %% - 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% - --> -<JMenu id='menuActions'> - - <import> - fr.ird.observe.client.main.MainUIModel - </import> - - <MainUIModel id="uiModel" initializer="getContextValue(MainUIModel.class)"/> - - <JMenuItem id='launchSynchronizeAction'/> - <JMenuItem id='launchReferentialSynchronizeAction'/> - <JSeparator/> - <JMenuItem id='launchExportDataAction'/> - <JMenuItem id='launchDataSynchronizeAction'/> - <JSeparator/> - <JMenuItem id='launchConsolidateAction'/> - <JMenuItem id='launchActivityLonglinePairingAction'/> - <JMenuItem id='launchValidateAction'/> - <JMenuItem id='launchReportAction'/> -</JMenu> ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/AdminUIMenu.jcss deleted ===================================== @@ -1,26 +0,0 @@ -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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% - */ -#menuActions { - text: "observe.ui.menu.actions"; - mnemonic: A; - enabled: {uiModel.isActionsEnabled()}; -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/AdminUIMenuActionSupport.java deleted ===================================== @@ -1,52 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.WithClientUIContext; -import fr.ird.observe.client.datasource.actions.menu.AdminUIMenu; -import org.nuiton.jaxx.runtime.swing.action.JComponentActionSupport; - -import javax.swing.KeyStroke; - -/** - * @author Tony Chemit - dev@tchemit.fr - * @since ? - */ -public abstract class AdminUIMenuActionSupport extends JComponentActionSupport<AdminUIMenu> implements WithClientUIContext { - - protected AdminUIMenuActionSupport(String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) { - super(label, shortDescription, actionIcon, acceleratorKey); - } - - protected AdminUIMenuActionSupport(String actionCommandKey, String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) { - super(actionCommandKey, label, shortDescription, actionIcon, acceleratorKey); - } - - protected AdminUIMenuActionSupport(String label, String shortDescription, String actionIcon, char acceleratorKey) { - super(label, shortDescription, actionIcon, acceleratorKey); - } - - protected AdminUIMenuActionSupport(String actionCommandKey, String label, String shortDescription, String actionIcon, char acceleratorKey) { - super(actionCommandKey, label, shortDescription, actionIcon, acceleratorKey); - } -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchActivityLlPairingAction.java deleted ===================================== @@ -1,38 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.datasource.actions.AdminStep; - -/** - * Created by tchemit on 20/11/2018. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class LaunchActivityLlPairingAction extends LaunchAdminActionSupport { - - public LaunchActivityLlPairingAction() { - super(AdminStep.ACTIVITY_LL_PAIRING); - } - -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchConsolidateAction.java deleted ===================================== @@ -1,39 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.datasource.actions.AdminStep; - -/** - * Created on 05/12/16. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 6.0 - */ -public class LaunchConsolidateAction extends LaunchAdminActionSupport { - - public LaunchConsolidateAction() { - super(AdminStep.CONSOLIDATE); - } - -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchDataSynchronizeAction.java deleted ===================================== @@ -1,39 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.datasource.actions.AdminStep; - -/** - * Created on 05/12/16. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 6.0 - */ -public class LaunchDataSynchronizeAction extends LaunchAdminActionSupport { - - public LaunchDataSynchronizeAction() { - super(AdminStep.DATA_SYNCHRONIZE); - } - -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchExportDataAction.java deleted ===================================== @@ -1,39 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.datasource.actions.AdminStep; - -/** - * Created on 05/12/16. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 6.0 - */ -public class LaunchExportDataAction extends LaunchAdminActionSupport { - - public LaunchExportDataAction() { - super(AdminStep.EXPORT_DATA); - } - -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchReferentialSynchronizeAction.java deleted ===================================== @@ -1,39 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.datasource.actions.AdminStep; - -/** - * Created on 05/12/16. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 6.0 - */ -public class LaunchReferentialSynchronizeAction extends LaunchAdminActionSupport { - - public LaunchReferentialSynchronizeAction() { - super(AdminStep.REFERENTIAL_SYNCHRONIZE); - } - -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchReportAction.java deleted ===================================== @@ -1,39 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.datasource.actions.AdminStep; - -/** - * Created on 05/12/16. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 6.0 - */ -public class LaunchReportAction extends LaunchAdminActionSupport { - - public LaunchReportAction() { - super(AdminStep.REPORT); - } - -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchSynchronizeAction.java deleted ===================================== @@ -1,39 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.datasource.actions.AdminStep; - -/** - * Created on 05/12/16. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 6.0 - */ -public class LaunchSynchronizeAction extends LaunchAdminActionSupport { - - public LaunchSynchronizeAction() { - super(AdminStep.SYNCHRONIZE); - } - -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/menu/actions/LaunchValidateAction.java deleted ===================================== @@ -1,39 +0,0 @@ -package fr.ird.observe.client.datasource.actions.menu.actions; - -/*- - * #%L - * ObServe Client :: DataSource :: Actions - * %% - * Copyright (C) 2008 - 2021 IRD, Code Lutin, Ultreia.io - * %% - * 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 fr.ird.observe.client.datasource.actions.AdminStep; - -/** - * Created on 05/12/16. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 6.0 - */ -public class LaunchValidateAction extends LaunchAdminActionSupport { - - public LaunchValidateAction() { - super(AdminStep.VALIDATE); - } - -} ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/pairing/ll/tree/ActivityLlPairingTreeTable.java ===================================== @@ -34,7 +34,6 @@ import fr.ird.observe.client.datasource.actions.pairing.ll.tree.node.ActivityLlP import fr.ird.observe.client.datasource.actions.pairing.tree.node.ActivityPairingNodeSupport; import fr.ird.observe.client.datasource.actions.pairing.tree.node.ActivityPairingProgramNode; import fr.ird.observe.client.util.DtoIconHelper; -import fr.ird.observe.client.util.UIHelper; import fr.ird.observe.client.util.treetable.JaxxComboBoxCellEditor; import fr.ird.observe.dto.data.ll.common.TripDto; import fr.ird.observe.dto.data.ll.common.TripReference; @@ -76,92 +75,6 @@ import java.util.function.Supplier; */ public class ActivityLlPairingTreeTable extends JXTreeTable implements WithClientConfig, WithClientUIContext { - public ActivityLlPairingTreeTable(ActivityLlPairingTreeTableModel treeModel) { - super(treeModel); - setTreeCellRenderer(new ActivityLlPairingTreeTableTreeCellRenderer(getClientUIContext().getDecoratorService())); - setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - setCellSelectionEnabled(true); - setRootVisible(false); - setRowHeight(26); - getTableHeader().setReorderingAllowed(false); - } - - @Override - public ActivityLlPairingTreeTableModel getTreeTableModel() { - return (ActivityLlPairingTreeTableModel) super.getTreeTableModel(); - } - - public void openTable(ActivityLlPairingRootNode rootNode) { - - getTreeTableModel().setRoot(rootNode); - - expandAll(); - - // auto expand nodes when selected - addTreeSelectionListener(e -> { - int selectedRow = getSelectedRow(); - if (selectedRow != -1) { - if (!isExpanded(selectedRow)) { - SwingUtilities.invokeLater(() -> expandRow(selectedRow)); - } - } - }); - } - - public void initTable(ActivityLlPairingModel model, Supplier<Integer> width) { - - setColumnFactory(new ColumnFactory() { - - @Override - public void configureColumnWidths(JXTable table, TableColumnExt columnExt) { - if (table.getColumn(0).equals(columnExt)) { - columnExt.setPreferredWidth(width.get()); - columnExt.setMinWidth(columnExt.getPreferredWidth()); - return; - } - if (table.getColumn(1).equals(columnExt)) { - columnExt.setPreferredWidth(width.get()); - columnExt.setMinWidth(columnExt.getPreferredWidth()); - return; - } - if (table.getColumn(2).equals(columnExt)) { - columnExt.setPreferredWidth(50); - columnExt.setMinWidth(50); - return; - } - super.configureColumnWidths(table, columnExt); - columnExt.setMinWidth(columnExt.getPreferredWidth()); - } - }); - getTreeTableModel().addTreeModelListener(new TreeModelListener() { - @Override - public void treeNodesChanged(TreeModelEvent e) { - - model.recomputeSelectedValues(); - } - - @Override - public void treeNodesInserted(TreeModelEvent e) { - - } - - @Override - public void treeNodesRemoved(TreeModelEvent e) { - - } - - @Override - public void treeStructureChanged(TreeModelEvent e) { - - } - - }); - DecoratorService decoratorService = getClientUIContext().getDecoratorService(); - setDefaultRenderer(Object.class, new ActivityLlPairingTreeTableCellRenderer(this, getClientConfig(), decoratorService)); - setDefaultEditor(Object.class, new ActivityLlPairingTreeTableCellEditor(this, getClientConfig(), decoratorService)); - - } - static class ActivityLlPairingTreeTableCellRenderer implements TableCellRenderer { // Render booleans (inclusive) @@ -251,6 +164,91 @@ public class ActivityLlPairingTreeTable extends JXTreeTable implements WithClien } } + public ActivityLlPairingTreeTable(ActivityLlPairingTreeTableModel treeModel) { + super(treeModel); + setTreeCellRenderer(new ActivityLlPairingTreeTableTreeCellRenderer(getClientUIContext().getDecoratorService())); + setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + setCellSelectionEnabled(true); + setRootVisible(false); + setRowHeight(26); + getTableHeader().setReorderingAllowed(false); + } + + @Override + public ActivityLlPairingTreeTableModel getTreeTableModel() { + return (ActivityLlPairingTreeTableModel) super.getTreeTableModel(); + } + + public void openTable(ActivityLlPairingRootNode rootNode) { + + getTreeTableModel().setRoot(rootNode); + + expandAll(); + + // auto expand nodes when selected + addTreeSelectionListener(e -> { + int selectedRow = getSelectedRow(); + if (selectedRow != -1) { + if (!isExpanded(selectedRow)) { + SwingUtilities.invokeLater(() -> expandRow(selectedRow)); + } + } + }); + } + + public void initTable(ActivityLlPairingModel model, Supplier<Integer> width) { + + setColumnFactory(new ColumnFactory() { + + @Override + public void configureColumnWidths(JXTable table, TableColumnExt columnExt) { + if (table.getColumn(0).equals(columnExt)) { + columnExt.setPreferredWidth(width.get()); + columnExt.setMinWidth(columnExt.getPreferredWidth()); + return; + } + if (table.getColumn(1).equals(columnExt)) { + columnExt.setPreferredWidth(width.get()); + columnExt.setMinWidth(columnExt.getPreferredWidth()); + return; + } + if (table.getColumn(2).equals(columnExt)) { + columnExt.setPreferredWidth(50); + columnExt.setMinWidth(50); + return; + } + super.configureColumnWidths(table, columnExt); + columnExt.setMinWidth(columnExt.getPreferredWidth()); + } + }); + getTreeTableModel().addTreeModelListener(new TreeModelListener() { + @Override + public void treeNodesChanged(TreeModelEvent e) { + + model.recomputeSelectedValues(); + } + + @Override + public void treeNodesInserted(TreeModelEvent e) { + + } + + @Override + public void treeNodesRemoved(TreeModelEvent e) { + + } + + @Override + public void treeStructureChanged(TreeModelEvent e) { + + } + + }); + DecoratorService decoratorService = getClientUIContext().getDecoratorService(); + setDefaultRenderer(Object.class, new ActivityLlPairingTreeTableCellRenderer(this, getClientConfig(), decoratorService)); + setDefaultEditor(Object.class, new ActivityLlPairingTreeTableCellEditor(this, getClientConfig(), decoratorService)); + } + class ActivityLlPairingTreeTableCellEditor implements TableCellEditor { private final TableCellEditor booleanEditor; @@ -276,14 +274,15 @@ public class ActivityLlPairingTreeTable extends JXTreeTable implements WithClien Objects.requireNonNull(node); if (column == 1) { if (node instanceof ActivityLlPairingActivityNode) { - JaxxComboBox<?> component = pairingEditor.getComponent(); + @SuppressWarnings("unchecked") JaxxComboBox<ActivityPairingResultItem> component = (JaxxComboBox<ActivityPairingResultItem>) pairingEditor.getComponent(); ActivityLlPairingActivityNode activityLlPairingActivityNode = (ActivityLlPairingActivityNode) node; ImmutableList<ActivityPairingResultItem> availableActivities = getTreeTableModel().getAvailableActivities(activityLlPairingActivityNode); ActivityPairingResultItem selectedValue = activityLlPairingActivityNode.getSelectedValue(); if (!availableActivities.contains(selectedValue)) { selectedValue = null; } - UIHelper.fillComboBox(component.getCombobox(), availableActivities, selectedValue); + component.setData(availableActivities); + component.setSelectedItem(selectedValue); editor = pairingEditor; } } else if (column == 2) { ===================================== client/datasource/api/src/main/i18n/templates/InitStorageModel_en_GB.ftl ===================================== @@ -1,4 +1,4 @@ -<#-- @ftlvariable name=".data_model" type="fr.ird.observe.client.datasource.h2.backup.InitStorageModel" --> +<#-- @ftlvariable name=".data_model" type="fr.ird.observe.client.datasource.api.h2.backup.InitStorageModel" --> <#-- #%L ObServe Client :: Core ===================================== client/datasource/api/src/main/i18n/templates/InitStorageModel_es_ES.ftl ===================================== @@ -1,4 +1,4 @@ -<#-- @ftlvariable name=".data_model" type="fr.ird.observe.client.datasource.h2.backup.InitStorageModel" --> +<#-- @ftlvariable name=".data_model" type="fr.ird.observe.client.datasource.api.h2.backup.InitStorageModel" --> <#-- #%L ObServe Client :: Core ===================================== client/datasource/api/src/main/i18n/templates/InitStorageModel_fr_FR.ftl ===================================== @@ -1,4 +1,4 @@ -<#-- @ftlvariable name=".data_model" type="fr.ird.observe.client.datasource.h2.backup.InitStorageModel" --> +<#-- @ftlvariable name=".data_model" type="fr.ird.observe.client.datasource.api.h2.backup.InitStorageModel" --> <#-- #%L ObServe Client :: Core ===================================== client/datasource/api/src/main/java/fr/ird/observe/client/datasource/h2/backup/InitStorageModel.java → client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/h2/backup/InitStorageModel.java ===================================== @@ -1,4 +1,4 @@ -package fr.ird.observe.client.datasource.h2.backup; +package fr.ird.observe.client.datasource.api.h2.backup; /*- * #%L @@ -22,6 +22,7 @@ package fr.ird.observe.client.datasource.h2.backup; * #L% */ +import fr.ird.observe.client.datasource.h2.backup.BackupStorage; import io.ultreia.java4all.application.template.spi.GenerateTemplate; import java.io.File; ===================================== client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/h2/server/H2ServerUI.jaxx ===================================== @@ -58,10 +58,8 @@ <JPanel constraints='BorderLayout.CENTER' layout='{new GridLayout(0,1)}'> <JButton id="stopServerMode"/> - <JSeparator/> <JButton id="startH2WebServer"/> <JButton id="stopH2WebServer"/> - </JPanel> </JPanel> ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/DataSourceEditorHelper.java ===================================== @@ -28,8 +28,8 @@ import fr.ird.observe.client.datasource.api.ObserveDataSourcesManager; import fr.ird.observe.client.datasource.api.ObserveSwingDataSource; import fr.ird.observe.client.datasource.h2.backup.BackupStorage; import fr.ird.observe.client.datasource.h2.backup.BackupsManager; -import fr.ird.observe.client.datasource.h2.backup.InitStorageModel; -import fr.ird.observe.client.datasource.h2.backup.InitStorageModelTemplate; +import fr.ird.observe.client.datasource.api.h2.backup.InitStorageModel; +import fr.ird.observe.client.datasource.api.h2.backup.InitStorageModelTemplate; import fr.ird.observe.client.main.ObserveMainUI; import fr.ird.observe.client.util.ObserveSwingTechnicalException; import fr.ird.observe.dto.db.configuration.DataSourceConnectMode; ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/menu/DataSourceEditorMenu.jcss ===================================== @@ -36,6 +36,10 @@ JToolBar { enabled: {uiModel.isStorageReloadEnabled()}; } +#showStorageInfo { + enabled: {uiModel.isStorageCloseEnabled()}; +} + #closeStorage { enabled: {uiModel.isStorageCloseEnabled()}; } ===================================== models/dto/java/pom.xml ===================================== @@ -81,6 +81,11 @@ <artifactId>http-api</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>io.ultreia.java4all.jaxx</groupId> + <artifactId>jaxx-runtime-spi</artifactId> + <scope>provided</scope> + </dependency> <dependency> <groupId>io.ultreia.java4all.i18n</groupId> <artifactId>i18n-runtime</artifactId> ===================================== models/dto/java/src/main/java/fr/ird/observe/dto/data/ll/pairing/ActivityPairingResultItem.java ===================================== @@ -26,6 +26,8 @@ import fr.ird.observe.dto.SimpleDto; import fr.ird.observe.dto.data.ActivityAware; import fr.ird.observe.dto.data.ll.observation.ActivityReference; import io.ultreia.java4all.lang.Numbers; +import org.nuiton.decorator.Decorator; +import org.nuiton.jaxx.runtime.bean.BeanDecoratorAware; import java.util.Date; import java.util.Objects; @@ -38,11 +40,12 @@ import static io.ultreia.java4all.i18n.I18n.t; * * @author Tony Chemit - dev@tchemit.fr */ -public class ActivityPairingResultItem implements SimpleDto { +public class ActivityPairingResultItem implements SimpleDto, BeanDecoratorAware { private final ActivityReference observationActivity; private final long computedTime; private final float computedDistance; + protected transient Decorator<?> decorator; private String computedTimeStr; public static ActivityPairingResultItem create(ActivityAware activityLogbook, ActivityReference activityObsReference) { @@ -59,6 +62,16 @@ public class ActivityPairingResultItem implements SimpleDto { this.computedDistance = Numbers.roundTwoDigits((float) computedDistance); } + @Override + public Decorator<?> decorator() { + return decorator; + } + + @Override + public void registerDecorator(Decorator<?> decorator) { + this.decorator = Objects.requireNonNull(decorator); + } + public ActivityReference getObservationActivity() { return observationActivity; } @@ -102,4 +115,14 @@ public class ActivityPairingResultItem implements SimpleDto { public int hashCode() { return Objects.hash(observationActivity); } + + @Override + public String toString() { + if (decorator == null) { + return super.toString(); + } + return decorate(); + } + + } ===================================== pom.xml ===================================== @@ -161,7 +161,7 @@ <!-- <lib.version.java4all.topia>1.43</lib.version.java4all.topia>--> <!-- <lib.version.java4all.eugene>3.0-alpha-38</lib.version.java4all.eugene>--> - <lib.version.java4all.jaxx>3.0.0-RC-3-SNAPSHOT</lib.version.java4all.jaxx> + <lib.version.java4all.jaxx>3.0.0-RC-3</lib.version.java4all.jaxx> <!--<lib.version.java4all.application-context>1.0.3-SNAPSHOT</lib.version.java4all.application-context>--> <!--<lib.version.java4all.application-template>1.0.2-SNAPSHOT</lib.version.java4all.application-template>--> <!--<lib.version.java4all.i18n>4.0-beta-3-SNAPSHOT</lib.version.java4all.i18n>--> ===================================== services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/TripManagementServiceLocalSupport.java ===================================== @@ -42,8 +42,10 @@ import org.apache.logging.log4j.Logger; import org.nuiton.topia.persistence.script.SqlScriptConsumer; import org.nuiton.topia.persistence.script.TopiaBlobsContainer; import org.nuiton.topia.persistence.script.TopiaSqlScript; +import org.nuiton.util.TimeLog; import org.nuiton.version.Version; +import java.util.Collections; import java.util.Set; import java.util.TreeSet; @@ -74,7 +76,7 @@ public class TripManagementServiceLocalSupport extends ObserveServiceLocal imple String tripId = exportRequest.getTripId(); - log.info("Start export of trip: " + tripId); + log.info(String.format("Start export of trip: %s", tripId)); Version dbVersion = serviceContext.getServiceInitializer().optionalConnection().orElseThrow().getDataSourceInformation().getVersion(); AddSqlScriptProducerRequest request = (exportRequest.isForPG() ? AddSqlScriptProducerRequest.forPostgres(dbVersion) : AddSqlScriptProducerRequest.forH2(dbVersion)) @@ -89,17 +91,14 @@ public class TripManagementServiceLocalSupport extends ObserveServiceLocal imple ObserveTopiaPersistenceContext persistenceContext = serviceContext.getTopiaPersistenceContext(); - Set<String> tripSeineIds = new TreeSet<>(persistenceContext.getPsCommonTripDao().findAllIds()); - Set<String> tripLonglineIds = new TreeSet<>(persistenceContext.getLlCommonTripDao().findAllIds()); - String tripId = request.getTripId(); long t0 = System.nanoTime(); - boolean deleted = deleteTrip(persistenceContext, tripId, tripSeineIds, tripLonglineIds); + boolean deleted = deleteTrip(persistenceContext, tripId, Collections.emptySet()); if (deleted) { long time = System.nanoTime() - t0; - log.info("Delete of trip: " + tripId + " done in " + Strings.convertTime(time)); + log.info(String.format("Delete of trip: %s done in %s", tripId, Strings.convertTime(time))); return new DeleteTripResult(request, time); } return null; @@ -110,24 +109,33 @@ public class TripManagementServiceLocalSupport extends ObserveServiceLocal imple ObserveTopiaPersistenceContext persistenceContext = serviceContext.getTopiaPersistenceContext(); - Set<String> tripSeineIds = new TreeSet<>(persistenceContext.getPsCommonTripDao().findAllIds()); - Set<String> tripLonglineIds = new TreeSet<>(persistenceContext.getLlCommonTripDao().findAllIds()); - String tripId = request.getTripId(); - long t0 = System.nanoTime(); + long t1 = TimeLog.getTime(); + TopiaSqlScript sqlContent = request.getSqlContent(); + // detect ids in import script + Set<String> ids = new TreeSet<>(); + for (String sqlStatement : sqlContent.getLocation()) { + if (sqlStatement.toLowerCase().trim().startsWith("insert into")) { + String id = sqlStatement.substring(sqlStatement.indexOf("VALUES") + 6); + id = id.substring(id.indexOf("'") + 1); + id = id.substring(0, id.indexOf("'")); + ids.add(id); + } + } + log.info(String.format("Found in trip: %s, %d ids to import in %s.", tripId, ids.size(), Strings.convertTime(t1, System.nanoTime()))); + t1 = System.nanoTime(); - boolean deleted = deleteTrip(persistenceContext, tripId, tripSeineIds, tripLonglineIds); - long t1 = System.nanoTime(); + boolean deleted = deleteTrip(persistenceContext, tripId, ids); long deleteTime = 0; if (deleted) { - deleteTime = System.nanoTime() - t0; - log.info("Delete of trip: " + tripId + " done in " + Strings.convertTime(deleteTime)); + deleteTime = System.nanoTime() - t1; + log.info(String.format("Delete of trip: %s done in %s", tripId, Strings.convertTime(deleteTime))); } + t1 = System.nanoTime(); - log.info("Start import of trip: " + request.getTripId()); + log.info(String.format("Start import of trip: %s", request.getTripId())); - TopiaSqlScript sqlContent = request.getSqlContent(); Set<TopiaBlobsContainer> blobsContainers = sqlContent.getBlobsContainers(); SqlScriptConsumer.Builder consumerBuilder = SqlScriptConsumer.builder(sqlContent.getLocation()).batchSize(1000); @@ -135,38 +143,42 @@ public class TripManagementServiceLocalSupport extends ObserveServiceLocal imple consumerBuilder.blobs(blobsContainers); } persistenceContext.getSqlSupport().doSqlWork(consumerBuilder.build()); - - persistenceContext.commit(); + persistenceContext.flush(); long t2 = System.nanoTime(); - log.info("Import of trip: " + tripId + " done in " + Strings.convertTime(t1, t2)); + log.info(String.format("Import of trip: %s done in %s", tripId, Strings.convertTime(t1, t2))); return new ImportTripResult(request, true, t2 - t1, deleted, deleteTime); } - private boolean deleteTrip(ObserveTopiaPersistenceContext persistenceContext, String tripId, Set<String> tripSeineIds, Set<String> tripLonglineIds) { + private boolean deleteTrip(ObserveTopiaPersistenceContext persistenceContext, String tripId, Set<String> ids) { long t0 = System.nanoTime(); - boolean deleted = tripSeineIds.contains(tripId) || tripLonglineIds.contains(tripId); + boolean deleted = persistenceContext.exists(tripId); if (deleted) { - log.info("Start delete of trip: " + tripId); + log.info(String.format("Start delete of trip: %s", tripId)); DeleteSqlScriptProducerRequest sqlRequest = DeleteSqlScriptProducerRequest.of(tripId); TopiaSqlScript sqlScript = sqlScriptProducerService.produceDeleteSqlScript(sqlRequest); - //FIXME Make sure this always work!!! For the moment stay as before -// if (tripLonglineIds.contains(tripId) && serviceContext.getTopiaApplicationContext().getConfiguration().isH2Configuration()) { -// serviceContext.getTopiaApplicationContext().executeSqlStatementsWithH2AndRemoveIntegrity(persistenceContext, sqlScript); -// } else { -// persistenceContext.getSqlSupport().doSqlWork(SqlScriptConsumer.of(sqlScript)); -// } persistenceContext.getSqlSupport().doSqlWork(SqlScriptConsumer.of(sqlScript)); - log.info("Delete of trip: " + tripId + " done in " + Strings.convertTime(t0, System.nanoTime())); - persistenceContext.commit(); + log.info(String.format("Delete of trip: %s done in %s", tripId, Strings.convertTime(t0, System.nanoTime()))); + persistenceContext.flush(); + } + Set<String> existingIds = new TreeSet<>(); + if (!ids.isEmpty()) { + for (String id : ids) { + if (persistenceContext.exists(id)) { + log.error(String.format("Can't import trip %s, - found existing id in target database (%s)", tripId, id)); + existingIds.add(id); + } + } + } + if (!existingIds.isEmpty()) { + throw new IllegalStateException(String.format("Next %d id(s) are blocking the import of trip %s:\n%s", existingIds.size(), tripId, String.join("\n", existingIds))); } return deleted; } - } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/03a7237c020b47885877ea3f4... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/03a7237c020b47885877ea3f4... You're receiving this email because of your account on gitlab.com.