Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: b6e9c668 by Tony Chemit at 2020-05-13T17:09:08+02:00 update pom - - - - - 00924f75 by Tony Chemit at 2020-05-13T17:09:10+02:00 Report form v8 - Closes #1472 * Dans le gestionnaire de connexions, un bouton 'dupliquer le profil' serait pratique - Closes #1477 * Quelques améliorations dans le gestionnaire de connexion - Closes #1479 * L'écran de gestion des connexions pourrait être présenté en partage horizontal - Closes #1480 - - - - - b7dc0bc2 by Tony Chemit at 2020-05-13T17:09:10+02:00 Comportement sidérant d'H2 - Closes #1463 - - - - - 28 changed files: - client-core/src/main/i18n/getters/java.getter - client-core/src/main/java/fr/ird/observe/client/ui/ObserveKeyStrokes.java - client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/CancelRemoteUIAction.java - client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/CancelServerUIAction.java - client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/DeleteRemoteUIAction.java - client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/DeleteServerUIAction.java - + client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/DuplicateRemoteUIAction.java - + client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/DuplicateServerUIAction.java - client-core/src/main/java/fr/ird/observe/client/ui/storage/presets/RemotePresetsUI.jaxx - client-core/src/main/java/fr/ird/observe/client/ui/storage/presets/RemotePresetsUI.jcss - client-core/src/main/java/fr/ird/observe/client/ui/storage/presets/RemotePresetsUIHandler.java - dto/src/main/java/fr/ird/observe/dto/decoration/DecoratorService.java - observe-i18n/src/main/i18n/translations/observe_en_GB.properties - observe-i18n/src/main/i18n/translations/observe_es_ES.properties - observe-i18n/src/main/i18n/translations/observe_fr_FR.properties - + persistence/.mvn/i18n/parse-java - persistence/pom.xml - + persistence/src/main/i18n/getters/java.getter - persistence/src/main/java/fr/ird/observe/entities/referentiel/DuplicateLengthLengthParameterException.java - persistence/src/main/java/fr/ird/observe/entities/referentiel/DuplicateLengthWeightParameterException.java - persistence/src/main/java/fr/ird/observe/entities/referentiel/LengthLengthParameterNotFoundException.java - persistence/src/main/java/fr/ird/observe/entities/referentiel/LengthLengthParameters.java - persistence/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterNotFoundException.java - persistence/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameters.java - pom.xml - services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java - services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidationActivitySeineDataContext.java - services-local/src/test/java/fr/ird/observe/services/local/entity/LengthWeightParemetersTest.java Changes: ===================================== client-core/src/main/i18n/getters/java.getter ===================================== @@ -44,6 +44,9 @@ observe.action.delete.remote.tip observe.action.delete.server.tip observe.action.delete.tip observe.action.detail +observe.action.duplicate +observe.action.duplicate.remote.tip +observe.action.duplicate.server.tip observe.action.exit observe.action.exit.tip observe.action.floatingObjectPresets ===================================== client-core/src/main/java/fr/ird/observe/client/ui/ObserveKeyStrokes.java ===================================== @@ -86,6 +86,7 @@ public abstract class ObserveKeyStrokes { public static final KeyStroke KEY_STROKE_RESET_DATA = KeyStroke.getKeyStroke("pressed F7"); public static final KeyStroke KEY_STROKE_NEW_NEXT_DATA = KeyStroke.getKeyStroke("pressed F4"); public static final KeyStroke KEY_STROKE_DELETE_DATA_GLOBAL = KeyStroke.getKeyStroke("pressed F6"); + public static final KeyStroke KEY_STROKE_DUPLICATE = KeyStroke.getKeyStroke("pressed F2"); public static final KeyStroke KEY_STROKE_OPEN_DATA = KeyStroke.getKeyStroke("pressed F2"); public static final KeyStroke KEY_STROKE_CLOSE_DATA = KeyStroke.getKeyStroke("pressed F3"); public static final KeyStroke KEY_STROKE_SAVE_DATA = KeyStroke.getKeyStroke("pressed F5"); ===================================== client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/CancelRemoteUIAction.java ===================================== @@ -57,6 +57,8 @@ public class CancelRemoteUIAction extends PresetsUIActionSupport { ObserveSwingApplicationContext.get().getConfig().removeRemoteDataSourceConfiguration(configuration); ui.getModel().setRemoteDataSourceConfiguration(null); ui.getModel().setRemoteCreateMode(false); + int newConfiguration = configurations.isEmpty() ? -1 : 0; + ui.getRemoteConfigurations().setSelectedIndex(newConfiguration); } } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/CancelServerUIAction.java ===================================== @@ -57,6 +57,8 @@ public class CancelServerUIAction extends PresetsUIActionSupport { ObserveSwingApplicationContext.get().getConfig().removeServerDataSourceConfiguration(configuration); ui.getModel().setServerDataSourceConfiguration(null); ui.getModel().setServerCreateMode(false); + int newConfiguration = configurations.isEmpty() ? -1 : 0; + ui.getServerConfigurations().setSelectedIndex(newConfiguration); } } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/DeleteRemoteUIAction.java ===================================== @@ -69,6 +69,8 @@ public class DeleteRemoteUIAction extends PresetsUIActionSupport { ui.getModel().setRemoteDataSourceConfigurations(configurations); ObserveSwingApplicationContext.get().getConfig().removeRemoteDataSourceConfiguration(configuration); ui.getModel().setRemoteDataSourceConfiguration(null); + int newConfiguration = configurations.isEmpty() ? -1 : 0; + ui.getRemoteConfigurations().setSelectedIndex(newConfiguration); } } } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/DeleteServerUIAction.java ===================================== @@ -71,6 +71,8 @@ public class DeleteServerUIAction extends PresetsUIActionSupport { ui.getModel().setServerDataSourceConfigurations(configurations); ObserveSwingApplicationContext.get().getConfig().removeServerDataSourceConfiguration(configuration); ui.getModel().setServerDataSourceConfiguration(null); + int newConfiguration = configurations.isEmpty() ? -1 : 0; + ui.getServerConfigurations().setSelectedIndex(newConfiguration); } } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/DuplicateRemoteUIAction.java ===================================== @@ -0,0 +1,61 @@ +package fr.ird.observe.client.ui.actions.storage.presets; + +/*- + * #%L + * ObServe :: Client core + * %% + * Copyright (C) 2008 - 2020 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.ui.ObserveKeyStrokes; +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.storage.presets.RemotePresetsUI; +import fr.ird.observe.dto.presets.RemoteDataSourceConfiguration; + +import java.util.ArrayList; +import java.util.List; + +import static io.ultreia.java4all.i18n.I18n.n; + +public class DuplicateRemoteUIAction extends PresetsUIActionSupport { + + public static final String ACTION_NAME = DuplicateRemoteUIAction.class.getName(); + + public DuplicateRemoteUIAction(ObserveMainUI mainUI) { + super(mainUI, ACTION_NAME, n("observe.action.duplicate"), n("observe.action.duplicate.remote.tip"), "mode-create", ObserveKeyStrokes.KEY_STROKE_DUPLICATE); + } + + @Override + protected void doActionPerformed(RemotePresetsUI ui) { + + RemoteDataSourceConfiguration incomingConfiguration = ui.getModel().getRemoteDataSourceConfiguration(); + + RemoteDataSourceConfiguration configuration = new RemoteDataSourceConfiguration(); + + configuration.setLogin(incomingConfiguration.getLogin()); + configuration.setPassword(incomingConfiguration.getPassword()); + configuration.setName(incomingConfiguration.getName() + " (Copie)"); + configuration.setUrl(incomingConfiguration.getUrl()); + + List<RemoteDataSourceConfiguration> configurations = new ArrayList<>(ui.getModel().getRemoteDataSourceConfigurations()); + configurations.add(configuration); + ui.getModel().setRemoteDataSourceConfigurations(configurations); + ui.getModel().setRemoteCreateMode(true); + ui.getRemoteConfigurations().setSelectedValue(configuration, true); + } +} ===================================== client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/DuplicateServerUIAction.java ===================================== @@ -0,0 +1,62 @@ +package fr.ird.observe.client.ui.actions.storage.presets; + +/*- + * #%L + * ObServe :: Client core + * %% + * Copyright (C) 2008 - 2020 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.ui.ObserveKeyStrokes; +import fr.ird.observe.client.ui.ObserveMainUI; +import fr.ird.observe.client.ui.storage.presets.RemotePresetsUI; +import fr.ird.observe.dto.presets.ServerDataSourceConfiguration; + +import java.util.ArrayList; +import java.util.List; + +import static io.ultreia.java4all.i18n.I18n.n; + +public class DuplicateServerUIAction extends PresetsUIActionSupport { + + public static final String ACTION_NAME = DuplicateServerUIAction.class.getName(); + + public DuplicateServerUIAction(ObserveMainUI mainUI) { + super(mainUI, ACTION_NAME, n("observe.action.duplicate"), n("observe.action.duplicate.server.tip"), "mode-create", ObserveKeyStrokes.KEY_STROKE_DUPLICATE); + } + + @Override + protected void doActionPerformed(RemotePresetsUI ui) { + + ServerDataSourceConfiguration incomingConfiguration = ui.getModel().getServerDataSourceConfiguration(); + ServerDataSourceConfiguration configuration = new ServerDataSourceConfiguration(); + + configuration.setDatabaseName(incomingConfiguration.getDatabaseName()); + configuration.setLogin(incomingConfiguration.getLogin()); + configuration.setPassword(incomingConfiguration.getPassword()); + configuration.setName(incomingConfiguration.getName() + " (Copie)"); + configuration.setUrl(incomingConfiguration.getUrl()); + + List<ServerDataSourceConfiguration> configurations = new ArrayList<>(ui.getModel().getServerDataSourceConfigurations()); + configurations.add(configuration); + ui.getModel().setServerDataSourceConfigurations(configurations); + ui.getModel().setServerCreateMode(true); + ui.getServerConfigurations().setSelectedValue(configuration, true); + + } +} ===================================== client-core/src/main/java/fr/ird/observe/client/ui/storage/presets/RemotePresetsUI.jaxx ===================================== @@ -19,7 +19,7 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<JPanel layout="{new BorderLayout()}"> +<org.jdesktop.swingx.JXTitledPanel id="dataSourcePresets"> <import> fr.ird.observe.dto.presets.RemoteDataSourceConfiguration @@ -28,6 +28,8 @@ fr.ird.observe.client.ui.actions.storage.presets.CreatePresetUIAction fr.ird.observe.client.ui.actions.storage.presets.DeleteRemoteUIAction fr.ird.observe.client.ui.actions.storage.presets.DeleteServerUIAction + fr.ird.observe.client.ui.actions.storage.presets.DuplicateRemoteUIAction + fr.ird.observe.client.ui.actions.storage.presets.DuplicateServerUIAction fr.ird.observe.client.ui.actions.storage.presets.QuitPresetsUIAction fr.ird.observe.client.ui.actions.storage.presets.CancelRemoteUIAction fr.ird.observe.client.ui.actions.storage.presets.ResetRemoteUIAction @@ -39,24 +41,26 @@ fr.ird.observe.client.ui.actions.storage.presets.TestServerUIAction org.nuiton.jaxx.widgets.select.BeanComboBox - + java.awt.CardLayout </import> <RemotePresetsUIModel id="model" initializer="getContextValue(RemotePresetsUIModel.class)"/> <JTabbedPane id='tabs' constraints='BorderLayout.CENTER'> <tab id='remoteTab' title="observe.storage.remote.presets.title"> - <JSplitPane id="remotePanel"> - <JList id='remoteConfigurations' genericType="RemoteDataSourceConfiguration"/> - <JPanel id="remoteContentPanel" layout="{new BorderLayout()}"> - <JLabel id="noRemoteSelected" constraints='BorderLayout.CENTER'/> - <Table id="remoteForm" constraints='BorderLayout.SOUTH' fill="both"> + <JPanel id="remotePanel" layout="{new BorderLayout()}"> + <JScrollPane id='remoteConfigurationsPane' constraints='BorderLayout.CENTER'> + <JList id='remoteConfigurations' genericType="RemoteDataSourceConfiguration"/> + </JScrollPane> + <JPanel id="remoteContentPanel" layout="{new CardLayout()}" constraints='BorderLayout.SOUTH' border='{new TitledBorder("")}'> + <JLabel id="noRemoteSelected" constraints='"empty"'/> + <Table id="remoteForm" constraints='"form"' fill="both"> <row> <cell anchor='west'> <JLabel text='observe.storage.remote.name'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="remoteName" onKeyReleased="model.setRemoteModified(true);"/> + <JTextField id="remoteName" onKeyReleased="handler.setRemoteModified(event);"/> </cell> </row> <row> @@ -64,7 +68,7 @@ <JLabel text='observe.storage.remote.url'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="remoteUrl" onKeyReleased="model.setRemoteModified(true);"/> + <JTextField id="remoteUrl" onKeyReleased="handler.setRemoteModified(event);"/> </cell> </row> <row> @@ -72,7 +76,7 @@ <JLabel text='observe.storage.remote.login'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="remoteLogin" onKeyReleased="model.setRemoteModified(true);"/> + <JTextField id="remoteLogin" onKeyReleased="handler.setRemoteModified(event);"/> </cell> </row> <row> @@ -80,7 +84,7 @@ <JLabel text='observe.storage.remote.password'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="remotePassword" onKeyReleased="model.setRemoteModified(true);"/> + <JTextField id="remotePassword" onKeyReleased="handler.setRemoteModified(event);"/> </cell> </row> <row> @@ -97,26 +101,29 @@ <JButton id="saveRemoteAction"/> <JButton id="deleteRemoteAction"/> <JButton id="testRemoteAction"/> + <JButton id="duplicateRemoteAction"/> </JPanel> </cell> </row> </Table> </JPanel> - </JSplitPane> + </JPanel> </tab> <tab id='serverTab' title="observe.storage.server.presets.title"> - <JSplitPane id="serverPanel"> - <JList id='serverConfigurations' genericType="ServerDataSourceConfiguration"/> - <JPanel id="serverContentPanel" layout="{new BorderLayout()}"> - <JLabel id="noServerSelected" constraints='BorderLayout.CENTER'/> - <Table id="serverForm" constraints='BorderLayout.SOUTH' fill="both"> + <JPanel id="serverPanel" layout="{new BorderLayout()}" > + <JScrollPane id='serverConfigurationsPane' constraints='BorderLayout.CENTER'> + <JList id='serverConfigurations' genericType="ServerDataSourceConfiguration"/> + </JScrollPane> + <JPanel id="serverContentPanel" layout="{new CardLayout()}" constraints='BorderLayout.SOUTH' border='{new TitledBorder("")}'> + <JLabel id="noServerSelected" constraints='"empty"'/> + <Table id="serverForm" constraints='"form"' fill="both"> <row> <cell anchor='west'> <JLabel text='observe.storage.remote.name'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="serverName" onKeyReleased="model.setServerModified(true);"/> + <JTextField id="serverName" onKeyReleased="handler.setServerModified(event);"/> </cell> </row> <row> @@ -124,7 +131,7 @@ <JLabel text='observe.storage.remote.url'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="serverUrl" onKeyReleased="model.setServerModified(true);"/> + <JTextField id="serverUrl" onKeyReleased="handler.setServerModified(event);"/> </cell> </row> <row> @@ -132,7 +139,7 @@ <JLabel text='observe.storage.remote.login'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="serverLogin" onKeyReleased="model.setServerModified(true);"/> + <JTextField id="serverLogin" onKeyReleased="handler.setServerModified(event);"/> </cell> </row> <row> @@ -140,7 +147,7 @@ <JLabel text='observe.storage.remote.password'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="serverPassword" onKeyReleased="model.setServerModified(true);"/> + <JTextField id="serverPassword" onKeyReleased="handler.setServerModified(event);"/> </cell> </row> <row> @@ -148,7 +155,7 @@ <JLabel id="serverDataBaseLabel" text='observe.storage.server.dataBase'/> </cell> <cell weightx='1' fill="both" anchor='east'> - <JTextField id="serverDataBase" onKeyReleased="model.setServerModified(true);"/> + <JTextField id="serverDataBase" onKeyReleased="handler.setServerModified(event);"/> </cell> </row> @@ -160,12 +167,13 @@ <JButton id="saveServerAction"/> <JButton id="deleteServerAction"/> <JButton id="testServerAction"/> + <JButton id="duplicateServerAction"/> </JPanel> </cell> </row> </Table> </JPanel> - </JSplitPane> + </JPanel> </tab> </JTabbedPane> @@ -174,4 +182,4 @@ <JButton id="quitAction"/> </JPanel> -</JPanel> +</org.jdesktop.swingx.JXTitledPanel> ===================================== client-core/src/main/java/fr/ird/observe/client/ui/storage/presets/RemotePresetsUI.jcss ===================================== @@ -21,15 +21,10 @@ */ #noRemoteSelected { - visible: true; text:"observe.storage.presets.no.selected"; horizontalAlignment: center; } -#remoteForm { - visible: false; -} - #remoteName { text:{SwingUtil.getStringValue(model.getRemoteDataSourceConfiguration().getName())}; } @@ -52,15 +47,10 @@ } #noServerSelected { - visible: true; text:"observe.storage.presets.no.selected"; horizontalAlignment: center; } -#serverForm { - visible: false; -} - #serverName { text:{SwingUtil.getStringValue(model.getServerDataSourceConfiguration().getName())}; } @@ -87,6 +77,7 @@ #resetRemoteAction { _observeAction:{ResetRemoteUIAction.ACTION_NAME}; + enabled:{model.isRemoteModified()}; } #saveRemoteAction { @@ -98,6 +89,10 @@ _observeAction:{DeleteRemoteUIAction.ACTION_NAME}; } +#duplicateRemoteAction { + _observeAction:{DuplicateRemoteUIAction.ACTION_NAME}; +} + #testRemoteAction { _observeAction:{TestRemoteUIAction.ACTION_NAME}; } @@ -120,6 +115,10 @@ _observeAction:{DeleteServerUIAction.ACTION_NAME}; } +#duplicateServerAction { + _observeAction:{DuplicateServerUIAction.ACTION_NAME}; +} + #testServerAction { _observeAction:{TestServerUIAction.ACTION_NAME}; } ===================================== client-core/src/main/java/fr/ird/observe/client/ui/storage/presets/RemotePresetsUIHandler.java ===================================== @@ -44,7 +44,7 @@ import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; -import java.awt.BorderLayout; +import java.awt.CardLayout; import java.awt.event.KeyEvent; import java.util.List; import java.util.Objects; @@ -105,6 +105,7 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { ui.getModel().setRemoteModified(false); } else { ui.getModel().setRemoteDataSourceConfiguration(ui.getRemoteConfigurations().getSelectedValue()); + ui.getRemoteName().requestFocusInWindow(); } }); @@ -124,17 +125,12 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { ui.getModel().addPropertyChangeListener("remoteDataSourceConfiguration", evt -> { RemoteDataSourceConfiguration oldValue = (RemoteDataSourceConfiguration) evt.getOldValue(); - if (ui.getModel().getRemoteDataSourceConfiguration() == null) { - ui.getRemoteContentPanel().remove(ui.getRemoteForm()); - ui.getRemoteContentPanel().add(ui.getNoRemoteSelected(), BorderLayout.CENTER); - UIHelper.askFocus(ui.getCreateAction()); + ((CardLayout) ui.getRemoteContentPanel().getLayout()).show(ui.getRemoteContentPanel(), "empty"); + ui.getCreateAction().requestFocusInWindow(); } else { if (oldValue == null) { - ui.getRemoteForm().setVisible(true); - ui.getRemoteContentPanel().remove(ui.getNoRemoteSelected()); - ui.getRemoteContentPanel().add(ui.getRemoteForm(), BorderLayout.CENTER); - UIHelper.askFocus(ui.getRemoteName()); + ((CardLayout) ui.getRemoteContentPanel().getLayout()).show(ui.getRemoteContentPanel(), "form"); } ui.getModel().setRemoteModified(false); } @@ -146,10 +142,12 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { if ((Boolean) evt.getNewValue()) { remoteActions.remove(ui.getResetRemoteAction()); remoteActions.remove(ui.getDeleteRemoteAction()); + remoteActions.remove(ui.getDuplicateRemoteAction()); remoteActions.add(ui.getCancelRemoteAction(), 0); } else { remoteActions.add(ui.getResetRemoteAction(), 0); remoteActions.add(ui.getDeleteRemoteAction(), 2); + remoteActions.add(ui.getDuplicateRemoteAction()); remoteActions.remove(ui.getCancelRemoteAction()); } }); @@ -169,6 +167,7 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { ui.getModel().setServerModified(false); } else { ui.getModel().setServerDataSourceConfiguration(ui.getServerConfigurations().getSelectedValue()); + ui.getServerName().requestFocusInWindow(); } }); @@ -190,15 +189,11 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { ServerDataSourceConfiguration oldValue = (ServerDataSourceConfiguration) evt.getOldValue(); if (ui.getModel().getServerDataSourceConfiguration() == null) { - ui.getServerContentPanel().remove(ui.getServerForm()); - ui.getServerContentPanel().add(ui.getNoServerSelected(), BorderLayout.CENTER); - UIHelper.askFocus(ui.getCreateAction()); + ((CardLayout) ui.getServerContentPanel().getLayout()).show(ui.getServerContentPanel(), "empty"); + ui.getCreateAction().requestFocusInWindow(); } else { if (oldValue == null) { - ui.getServerForm().setVisible(true); - ui.getServerContentPanel().remove(ui.getNoServerSelected()); - ui.getServerContentPanel().add(ui.getServerForm(), BorderLayout.CENTER); - UIHelper.askFocus(ui.getServerName()); + ((CardLayout) ui.getServerContentPanel().getLayout()).show(ui.getServerContentPanel(), "form"); } ui.getModel().setServerModified(false); } @@ -210,11 +205,13 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { if ((Boolean) evt.getNewValue()) { serverActions.remove(ui.getResetServerAction()); serverActions.remove(ui.getDeleteServerAction()); + serverActions.remove(ui.getDuplicateServerAction()); serverActions.add(ui.getCancelServerAction(), 0); } else { serverActions.add(ui.getResetServerAction(), 0); serverActions.add(ui.getDeleteServerAction(), 2); + serverActions.add(ui.getDuplicateServerAction()); serverActions.remove(ui.getCancelServerAction()); } }); @@ -222,6 +219,13 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { ui.getServerActions().remove(0); UIHelper.askFocus(ui.getCreateAction()); + if (ui.getRemoteConfigurations().getModel().getSize()>0) { + ui.getRemoteConfigurations().setSelectedIndex(0); + } + + if (ui.getServerConfigurations().getModel().getSize()>0) { + ui.getServerConfigurations().setSelectedIndex(0); + } } protected void init(JSplitPane editor) { @@ -243,8 +247,33 @@ public class RemotePresetsUIHandler implements UIHandler<RemotePresetsUI> { log.debug("init common action " + actionId); } + if (actionId.contains("Remote")) { + inputMap = ui.getRemoteContentPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + actionMap = ui.getRemoteContentPanel().getActionMap(); + } else if (actionId.contains("Server")) { + inputMap = ui.getServerContentPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + actionMap = ui.getServerContentPanel().getActionMap(); + } else { + inputMap = ui.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); + actionMap = ui.getActionMap(); + } action.initForMainUi(editor, inputMap, actionMap); editor.putClientProperty(UIActionSupport.CLIENT_PROPERTY_UI, ui); } + + protected void setServerModified(KeyEvent event) { + if (event.isActionKey()) { + return; + } + ui.getModel().setServerModified(true); + } + + protected void setRemoteModified(KeyEvent event) { + if (event.isActionKey()) { + return; + } + ui.getModel().setRemoteModified(true); + } + } ===================================== dto/src/main/java/fr/ird/observe/dto/decoration/DecoratorService.java ===================================== @@ -1084,4 +1084,17 @@ public class DecoratorService extends DecoratorProvider { } }; + + public String toString(Object o) { + if (o==null) { + return null; + } + if (o instanceof ReferentialDtoReference) { + return getReferentialReferenceDecorator(((ReferentialDtoReference<?,?>) o).getReferenceType()).toString(o); + } + if (o instanceof DataDtoReference) { + return getDataReferenceDecorator(((DataDtoReference<?,?>) o).getReferenceType()).toString(o); + } + return getDecoratorByType(o.getClass()).toString(o); + } } ===================================== observe-i18n/src/main/i18n/translations/observe_en_GB.properties ===================================== @@ -72,6 +72,9 @@ observe.action.delete.tip=Delete observe.action.detail=Details observe.action.do.backup=Backup local database observe.action.do.backup.tip=Make a backup of local database before applying modifications. +observe.action.duplicate=Duplicate +observe.action.duplicate.remote.tip=Duplicate remote +observe.action.duplicate.server.tip=Duplicate server observe.action.exit=Quit observe.action.exit.tip=quit Observe observe.action.floatingObjectPresets=Floating Object references @@ -1948,6 +1951,10 @@ observe.converter.error.float.format=Decimal format not correct for value %s observe.converter.error.no.convertor=could not convert decimal %s using convertor %s observe.converter.error.noValue=No value to convert using convertor %s observe.entity.message.updating=object '%1$s' is in editing mode. +observe.error.DuplicateLengthLengthParameterException=Found multiple length length relation for species\: %s, ocean\: %s, sex\: %s, date\: %s \:\n * %s +observe.error.DuplicateLengthWeightParameterException=Found multiple length weight paramters for species\: %s, ocean\: %s, sex\: %s, date\: %s \:\n * %s +observe.error.LengthLengthParameterNotFoundException=No length length relation found for species\: %s, ocean\: %s, sex\: %s, date\: %s \: %s +observe.error.LengthWeightParameterNotFoundException=No length weight relation found for species\: %s, ocean\: %s, sex\: %s, date\: %s \: %s observe.error.can.not.create.directory=Can't create directory %&$s\! observe.error.storage.could.not.backup.unsane.local.db=Can not save an borken database observe.error.storage.could.not.load.local.db=Could not open local database for reason\: %s ===================================== observe-i18n/src/main/i18n/translations/observe_es_ES.properties ===================================== @@ -72,6 +72,9 @@ observe.action.delete.tip=Eliminar observe.action.detail=Ver detalles observe.action.do.backup=Guardar la base local observe.action.do.backup.tip=Hacer copia de seguridad de la base local antes de aplicar los cambios +observe.action.duplicate=Duplicate \#TODO +observe.action.duplicate.remote.tip=Duplicate remote \#TODO +observe.action.duplicate.server.tip=Duplicate server \#TODO observe.action.exit=Salir observe.action.exit.tip=Salir de ObServe observe.action.floatingObjectPresets=Referencias de objetos flotantes @@ -1948,6 +1951,10 @@ observe.converter.error.float.format=Formato de decimal incorrecto para el valor observe.converter.error.no.convertor=Impossible de convertir el decimal %s con el convertidor %s observe.converter.error.noValue=Ningún valor necesita ser convertida con el convertidor %s observe.entity.message.updating=Se está modificando el objeto actual '%1$s'. +observe.error.DuplicateLengthLengthParameterException=Found multiple length length relation for species\: %s, ocean\: %s, sex\: %s, date\: %s \:\n * %s \#TODO +observe.error.DuplicateLengthWeightParameterException=Found multiple length weight relation for species\: %s, ocean\: %s, sex\: %s, date\: %s \:\n * %s \#TODO +observe.error.LengthLengthParameterNotFoundException=No length length relation found for species\: %s, ocean\: %s, sex\: %s, date\: %s \: %s \#TODO +observe.error.LengthWeightParameterNotFoundException=No length weight relation found for species\: %s, ocean\: %s, sex\: %s, date\: %s \: %s \#TODO observe.error.can.not.create.directory=¡Imposible crear el directorio %1$s\! observe.error.storage.could.not.backup.unsane.local.db=Impossible grabar una base dañada observe.error.storage.could.not.load.local.db=Impossible grabar la base local por la razón siguiente \: %s ===================================== observe-i18n/src/main/i18n/translations/observe_fr_FR.properties ===================================== @@ -72,6 +72,9 @@ observe.action.delete.tip=Supprimer observe.action.detail=Voir les détails observe.action.do.backup=Sauver la base locale observe.action.do.backup.tip=Effectuer une sauvegarde de la base locale avant d'appliquer les changements +observe.action.duplicate=Dupliquer +observe.action.duplicate.remote.tip=Duplicate la connexion distante +observe.action.duplicate.server.tip=Duplicate la connexion server observe.action.exit=Quitter observe.action.exit.tip=Quitter ObServe observe.action.floatingObjectPresets=Objets flottants de références @@ -1948,6 +1951,10 @@ observe.converter.error.float.format=Format de décimal incorrecte pour la valeu observe.converter.error.no.convertor=Impossible de convertir le décimal %s depuis le convertisseur %s observe.converter.error.noValue=Aucune valeur à convertir pour le convertisseur %s observe.entity.message.updating=L'objet '%1$s' est en cours de modification. +observe.error.DuplicateLengthLengthParameterException=Plusieurs relations taille-taille ont été trouvées pour l'espèce\: %s, l'ocean\: %s, le sexe\: %s et la date\: %s \:\n * %s +observe.error.DuplicateLengthWeightParameterException=Plusieurs relations taille-poids ont été trouvées pour l'espèce\: %s, l'ocean\: %s, le sexe\: %s et la date\: %s \:\n * %s +observe.error.LengthLengthParameterNotFoundException=Aucune relation taille-taille trouvée pour l'espèce\: %s, l'ocean\: %s, le sexe\: %s et la date\: %s +observe.error.LengthWeightParameterNotFoundException=Aucune relation taille-poids trouvée pour l'espèce\: %s, l'ocean\: %s, le sexe\: %s et la date\: %s observe.error.can.not.create.directory=Création du répertoire %1$s impossible\! observe.error.storage.could.not.backup.unsane.local.db=Impossible d'enregistrer une base non endommagée observe.error.storage.could.not.load.local.db=Impossible d'ouvrir la base locale pour la raison suivante \: %s ===================================== persistence/.mvn/i18n/parse-java ===================================== ===================================== persistence/pom.xml ===================================== @@ -86,7 +86,10 @@ <artifactId>nuiton-csv</artifactId> <scope>test</scope> </dependency> - + <dependency> + <groupId>io.ultreia.java4all.i18n</groupId> + <artifactId>i18n-runtime</artifactId> + </dependency> <dependency> <groupId>io.ultreia.java4all.http</groupId> <artifactId>http-api</artifactId> ===================================== persistence/src/main/i18n/getters/java.getter ===================================== @@ -0,0 +1,3 @@ +observe.error.DuplicateLengthWeightParameterException +observe.error.LengthLengthParameterNotFoundException +observe.error.LengthWeightParameterNotFoundException ===================================== persistence/src/main/java/fr/ird/observe/entities/referentiel/DuplicateLengthLengthParameterException.java ===================================== @@ -22,8 +22,20 @@ package fr.ird.observe.entities.referentiel; * #L% */ +import fr.ird.observe.binder.referential.ReferentialEntityReferenceBinderSupport; +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.referential.LengthLengthParameterDto; +import fr.ird.observe.dto.referential.LengthLengthParameterReference; +import fr.ird.observe.dto.referential.LengthWeightParameterDto; +import fr.ird.observe.dto.referential.LengthWeightParameterReference; +import fr.ird.observe.dto.referential.ReferentialLocale; +import fr.ird.observe.spi.DbModelHelper; + import java.util.Date; import java.util.List; +import java.util.stream.Collectors; + +import static io.ultreia.java4all.i18n.I18n.t; /** * Created on 28/08/15. @@ -44,7 +56,8 @@ public class DuplicateLengthLengthParameterException extends RuntimeException { protected final List<LengthLengthParameter> foundLengthLengthParameters; - public DuplicateLengthLengthParameterException(Species species, Ocean ocean, Sex sex, Date date, List<LengthLengthParameter> foundLengthLengthParameters) { + public DuplicateLengthLengthParameterException(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date, List<LengthLengthParameter> foundLengthLengthParameters) { + super(buildMessage(decoratorService, species, ocean, sex, date, foundLengthLengthParameters)); this.species = species; this.ocean = ocean; this.sex = sex; @@ -52,6 +65,18 @@ public class DuplicateLengthLengthParameterException extends RuntimeException { this.foundLengthLengthParameters = foundLengthLengthParameters; } + private static String buildMessage(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date, List<LengthLengthParameter> foundLengthLengthParameters) { + ReferentialEntityReferenceBinderSupport<LengthLengthParameterDto, LengthLengthParameterReference, LengthLengthParameter> entityContext = DbModelHelper.fromReferentialEntity(LengthLengthParameter.class).toEntityReferenceBinder(); + ReferentialLocale referentialLocale = decoratorService.getReferentialLocale(); + return t("observe.error.DuplicateLengthWeightParameterException", + LengthLengthParameterNotFoundException.toString(decoratorService, species), + LengthLengthParameterNotFoundException.toString(decoratorService, ocean), + LengthLengthParameterNotFoundException.toString(decoratorService, sex), + date, + foundLengthLengthParameters.stream().map(e -> entityContext.toReference(referentialLocale, e)).map(decoratorService::toString).collect(Collectors.joining("\n * ")) + ); + } + public Species getSpecies() { return species; } ===================================== persistence/src/main/java/fr/ird/observe/entities/referentiel/DuplicateLengthWeightParameterException.java ===================================== @@ -22,8 +22,20 @@ package fr.ird.observe.entities.referentiel; * #L% */ +import fr.ird.observe.binder.referential.ReferentialEntityReferenceBinderSupport; +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.referential.LengthWeightParameterDto; +import fr.ird.observe.dto.referential.LengthWeightParameterReference; +import fr.ird.observe.dto.referential.ReferentialDto; +import fr.ird.observe.dto.referential.ReferentialLocale; +import fr.ird.observe.spi.DbModelHelper; +import fr.ird.observe.spi.context.ReferentialEntityContext; + import java.util.Date; import java.util.List; +import java.util.stream.Collectors; + +import static io.ultreia.java4all.i18n.I18n.t; /** * Created on 28/08/15. @@ -44,7 +56,8 @@ public class DuplicateLengthWeightParameterException extends RuntimeException { protected final List<LengthWeightParameter> foundLengthWeightParameters; - public DuplicateLengthWeightParameterException(Species species, Ocean ocean, Sex sex, Date date, List<LengthWeightParameter> foundLengthWeightParameters) { + public DuplicateLengthWeightParameterException(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date, List<LengthWeightParameter> foundLengthWeightParameters) { + super(buildMessage(decoratorService, species, ocean, sex, date, foundLengthWeightParameters)); this.species = species; this.ocean = ocean; this.sex = sex; @@ -52,6 +65,18 @@ public class DuplicateLengthWeightParameterException extends RuntimeException { this.foundLengthWeightParameters = foundLengthWeightParameters; } + private static String buildMessage(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date, List<LengthWeightParameter> foundLengthWeightParameters) { + ReferentialEntityReferenceBinderSupport<LengthWeightParameterDto, LengthWeightParameterReference, LengthWeightParameter> entityContext = DbModelHelper.fromReferentialEntity(LengthWeightParameter.class).toEntityReferenceBinder(); + ReferentialLocale referentialLocale = decoratorService.getReferentialLocale(); + return t("observe.error.DuplicateLengthWeightParameterException", + LengthLengthParameterNotFoundException.toString(decoratorService, species), + LengthLengthParameterNotFoundException.toString(decoratorService, ocean), + LengthLengthParameterNotFoundException.toString(decoratorService, sex), + date, + foundLengthWeightParameters.stream().map(e -> entityContext.toReference(referentialLocale, e)).map(decoratorService::toString).collect(Collectors.joining("\n * ")) + ); + } + public Species getSpecies() { return species; } ===================================== persistence/src/main/java/fr/ird/observe/entities/referentiel/LengthLengthParameterNotFoundException.java ===================================== @@ -22,8 +22,15 @@ package fr.ird.observe.entities.referentiel; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.reference.ReferentialDtoReference; +import fr.ird.observe.dto.referential.ReferentialDto; +import fr.ird.observe.spi.DbModelHelper; + import java.util.Date; +import static io.ultreia.java4all.i18n.I18n.t; + /** * Created on 29/08/15. * @@ -41,13 +48,23 @@ public class LengthLengthParameterNotFoundException extends RuntimeException { protected final Date date; - public LengthLengthParameterNotFoundException(Species species, Ocean ocean, Sex sex, Date date) { + public LengthLengthParameterNotFoundException(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date) { + super(buildMessage(decoratorService, species, ocean, sex, date)); this.species = species; this.ocean = ocean; this.sex = sex; this.date = date; } + private static String buildMessage(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date) { + + return t("observe.error.LengthLengthParameterNotFoundException", + LengthLengthParameterNotFoundException.toString(decoratorService, species), + LengthLengthParameterNotFoundException.toString(decoratorService, ocean), + LengthLengthParameterNotFoundException.toString(decoratorService, sex), + date); + } + public Species getSpecies() { return species; } @@ -64,4 +81,10 @@ public class LengthLengthParameterNotFoundException extends RuntimeException { return date; } + static <E extends ObserveReferentialEntity> String toString(DecoratorService decoratorService, E entity) { + if (entity == null) { + return null; + } + return decoratorService.toString(DbModelHelper.fromReferentialEntity(entity).toEntityReferenceBinder().toReference(decoratorService.getReferentialLocale(), entity)); + } } ===================================== persistence/src/main/java/fr/ird/observe/entities/referentiel/LengthLengthParameters.java ===================================== @@ -22,6 +22,7 @@ package fr.ird.observe.entities.referentiel; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.persistence.ObserveTopiaDaoSupplier; import org.apache.commons.collections4.CollectionUtils; @@ -49,6 +50,7 @@ public class LengthLengthParameters { * <p> * Si non trouvé sur le sexe (et que le sexe n'est pas indéterminé) , alors on recherche avec le sexe indéterminé (sexe=0). * + * @param decoratorService decorator service * @param daoSupplier la transaction en cours d'utilisation * @param species l'espèce sur lequel on recherche le paramétrage * @param ocean l'ocean recherché (peut être null) @@ -59,7 +61,7 @@ public class LengthLengthParameters { * @return le paramétrage adéquate * @since 1.5 */ - public static Optional<LengthLengthParameter> findLengthLengthParameter(ObserveTopiaDaoSupplier daoSupplier, + public static Optional<LengthLengthParameter> findLengthLengthParameter(DecoratorService decoratorService, ObserveTopiaDaoSupplier daoSupplier, Species species, Ocean ocean, Sex sex, @@ -85,7 +87,7 @@ public class LengthLengthParameters { } if (CollectionUtils.isEmpty(list)) { - throw new LengthLengthParameterNotFoundException(species, ocean, sex, date); + throw new LengthLengthParameterNotFoundException(decoratorService, species, ocean, sex, date); } // if (inputSizeMeasureType != null) { @@ -116,193 +118,14 @@ public class LengthLengthParameters { // au final il ne devrait en rester qu'un if (list.size() > 1) { - throw new DuplicateLengthLengthParameterException(species, ocean, sex, date, list); + throw new DuplicateLengthLengthParameterException(decoratorService, species, ocean, sex, date, list); } return Optional.of(list.get(0)); - } -// -// /** -// * Recherche de la liste des {@link LengthLengthParameter} à partir des paramètres donnés. -// * <p> -// * La recherche peut ne peut être aussi exacte que les paramètres donnés : -// * <p> -// * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son -// * speciesGroup d'espèce. -// * <p> -// * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on -// * recherche avec un ocean vide. -// * -// * @param daoSupplier la transaction en cours d'utilisation -// * @param species l'espèce sur lequel on recherche le paramétrage -// * @param ocean l'ocean recherché (peut être null) -// * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) -// * @param date le jour recherché -// * @return le paramétrage adéquate -// * @since 1.5 -// */ -// public static List<LengthLengthParameter> findLengthLengthParameter0(ObserveTopiaDaoSupplier daoSupplier, -// Species species, -// Ocean ocean, -// Sex sex, -// Date date) { -// -// Objects.requireNonNull(daoSupplier, "daoSupplier parameter can't be null"); -// Objects.requireNonNull(species, "species parameter can't be null"); -// Objects.requireNonNull(sex, "sex parameter can't be null"); -// -// List<LengthLengthParameter> list = findBySpecies(daoSupplier, species); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // aucun parametrage pour le type donne -// return null; -// } -// -// // filtrage par ocean -// List<LengthLengthParameter> filterByOcean = filterByOcean(list, ocean); -// -// if (CollectionUtils.isEmpty(filterByOcean) && ocean != null) { -// -// // filtre par ocean null -// filterByOcean = filterByOcean(list, null); -// } -// list = filterByOcean; -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas d'ocean adequate -// return null; -// } -// -// // filtrage par sexe -// list = filterBySexe(list, sex); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de sexe adequate -// return null; -// } -// -// // filtrage par startDate de validite -// list = filterByDateDebutValidite(list, date); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de date de debut adequate -// return null; -// } -// -// // filtrage par endDate de validite -// list = filterByDateFinValidite(list, date); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de date de fin adequate -// return null; -// } -// -// return list; -// -// } private static Sex getUnknownSex(ObserveTopiaDaoSupplier daoSupplier) { return daoSupplier.getSexDao().forCodeEquals("0").findUnique(); } -// public static List<LengthLengthParameter> findBySpecies(ObserveTopiaDaoSupplier daoSupplier, Species species) { -// -// LengthLengthParameterTopiaDao dao = daoSupplier.getLengthLengthParameterDao(); -// -// List<LengthLengthParameter> list = dao.forSpeciesEquals(species).findAll(); -// -// // on supprime les paramétrages qui ont a=0 ou a=null ou b=0 ou b = null -// Iterator<LengthLengthParameter> itr = list.iterator(); -// while (itr.hasNext()) { -// LengthLengthParameter p = itr.next(); -// Double a = p.getCoefficientValue(FormulaHelper.COEFFICIENT_A); -// if (a == null || a == 0) { -// itr.remove(); -// continue; -// } -// -// Double b = p.getCoefficientValue(FormulaHelper.COEFFICIENT_B); -// // on autorise d'avoir b à 0 (mais cela ne permet plus de calculer la taille à partir du poids) -//// if (b == null || b == 0) { -// if (b == null) { -// itr.remove(); -// } -// } -// return list; -// -// } - -// public static List<LengthLengthParameter> filterByOcean(List<LengthLengthParameter> list, Ocean ocean) { -// List<LengthLengthParameter> result = new ArrayList<>(); -// if (ocean == null) { -// -// // on n'accepte que les parametrage sans ocean -// for (LengthLengthParameter parametrageLengthWeight : list) { -// if (parametrageLengthWeight.getOcean() == null) { -// result.add(parametrageLengthWeight); -// } -// } -// } else { -// for (LengthLengthParameter parametrageLengthWeight : list) { -// if (ocean.equals(parametrageLengthWeight.getOcean())) { -// result.add(parametrageLengthWeight); -// } -// } -// } -// return result; -// } -// -// public static List<LengthLengthParameter> filterBySexe(List<LengthLengthParameter> list, Sex sex) { -// return list.stream().filter(l -> l.getSex() == sex).collect(Collectors.toList()); -// } -// -// public static List<LengthLengthParameter> filterByInputSizeMeasureType(List<LengthLengthParameter> list, SizeMeasureType sizeMeasureType) { -// return list.stream().filter(l -> l.getInputSizeMeasureType() == sizeMeasureType).collect(Collectors.toList()); -// } -//public static List<LengthLengthParameter> filterByOutputSizeMeasureType(List<LengthLengthParameter> list, SizeMeasureType sizeMeasureType) { -// return list.stream().filter(l -> l.getOutputSizeMeasureType() == sizeMeasureType).collect(Collectors.toList()); -// } -// -// public static List<LengthLengthParameter> filterByDateDebutValidite(List<LengthLengthParameter> list, Date startDate) { -// return list.stream() -// .filter(l -> l.getStartDate() == null || l.getStartDate().before(startDate) || l.getStartDate().equals(startDate)) -// .collect(Collectors.toList()); -// } -// -// public static List<LengthLengthParameter> filterByDateFinValidite(List<LengthLengthParameter> list, Date endDate) { -// List<LengthLengthParameter> result = new ArrayList<>(); -// -// if (endDate == null) { -// // on n'accepte que les parametrages selon les critères suivants : -// // - sans date de fin (i.e en cours de validite) -// for (LengthLengthParameter parametrageLengthWeight : list) { -// -// Date date = parametrageLengthWeight.getEndDate(); -// if (date == null) { -// result.add(parametrageLengthWeight); -// } -// } -// } else { -// // on n'accepte que les parametrages selon les critères suivants : -// // - sans date de fin (i.e en cours de validite) -// // - ceux dont la date de fin est avant la date de fin donnée -// for (LengthLengthParameter parametrageLengthWeight : list) { -// -// Date date = parametrageLengthWeight.getEndDate(); -// if (date == null || -// date.after(endDate) || -// date.equals(endDate)) { -// result.add(parametrageLengthWeight); -// } -// } -// } -// return result; -// } - } ===================================== persistence/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterNotFoundException.java ===================================== @@ -22,7 +22,15 @@ package fr.ird.observe.entities.referentiel; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.referential.SpeciesDto; +import fr.ird.observe.spi.DbModelHelper; +import fr.ird.observe.spi.DtoModelHelper; + import java.util.Date; +import java.util.stream.Collectors; + +import static io.ultreia.java4all.i18n.I18n.t; /** * Created on 29/08/15. @@ -41,13 +49,23 @@ public class LengthWeightParameterNotFoundException extends RuntimeException { protected final Date date; - public LengthWeightParameterNotFoundException(Species species, Ocean ocean, Sex sex, Date date) { + public LengthWeightParameterNotFoundException(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date) { + super(buildMessage(decoratorService, species, ocean, sex, date)); this.species = species; this.ocean = ocean; this.sex = sex; this.date = date; } + private static String buildMessage(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date) { + + return t("observe.error.LengthWeightParameterNotFoundException", + LengthLengthParameterNotFoundException.toString(decoratorService, species), + LengthLengthParameterNotFoundException.toString(decoratorService, ocean), + LengthLengthParameterNotFoundException.toString(decoratorService, sex), + date); + } + public Species getSpecies() { return species; } ===================================== persistence/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameters.java ===================================== @@ -22,6 +22,7 @@ package fr.ird.observe.entities.referentiel; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.persistence.ObserveTopiaDaoSupplier; import org.apache.commons.collections4.CollectionUtils; @@ -47,16 +48,17 @@ public class LengthWeightParameters { * <p> * Si non trouvé sur le sexe (et que le sexe n'est pas indéterminé) , alors on recherche avec le sexe indéterminé (sexe=0). * - * @param daoSupplier la transaction en cours d'utilisation - * @param species l'espèce sur lequel on recherche le paramétrage - * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) - * @param ocean l'ocean recherché (peut être null) - * @param date le jour recherché - * @param sizeMeasureType le type de mensuration recherché + * @param decoratorService decorator service + * @param daoSupplier la transaction en cours d'utilisation + * @param species l'espèce sur lequel on recherche le paramétrage + * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) + * @param ocean l'ocean recherché (peut être null) + * @param date le jour recherché + * @param sizeMeasureType le type de mensuration recherché * @return le paramétrage adéquate * @since 1.5 */ - public static LengthWeightParameter findLengthWeightParameter(ObserveTopiaDaoSupplier daoSupplier, + public static LengthWeightParameter findLengthWeightParameter(DecoratorService decoratorService, ObserveTopiaDaoSupplier daoSupplier, Species species, Sex sex, Ocean ocean, Date date, SizeMeasureType sizeMeasureType) { // Sex unknownSex = getUnknownSex(daoSupplier); @@ -77,7 +79,7 @@ public class LengthWeightParameters { // } if (CollectionUtils.isEmpty(list)) { - throw new LengthWeightParameterNotFoundException(species, ocean, sex, date); + throw new LengthWeightParameterNotFoundException(decoratorService, species, ocean, sex, date); } // if (sizeMeasureType != null) { @@ -96,190 +98,11 @@ public class LengthWeightParameters { // au final il ne devrait en rester qu'un if (list.size() > 1) { - throw new DuplicateLengthWeightParameterException(species, ocean, sex, date, list); + throw new DuplicateLengthWeightParameterException(decoratorService, species, ocean, sex, date, list); } return Objects.requireNonNull(list.get(0)); } -// /** -// * Recherche de la liste des {@link LengthWeightParameter} à partir des paramètres donnés. -// * <p> -// * La recherche peut ne peut être aussi exacte que les paramètres donnés : -// * <p> -// * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son -// * speciesGroup d'espèce. -// * <p> -// * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on -// * recherche avec un ocean vide. -// * -// * @param daoSupplier la transaction en cours d'utilisation -// * @param species l'espèce sur lequel on recherche le paramétrage -// * @param ocean l'ocean recherché (peut être null) -// * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) -// * @param date le jour recherché -// * @return le paramétrage adéquate -// * @since 1.5 -// */ -// public static List<LengthWeightParameter> findLengthWeightParameter0(ObserveTopiaDaoSupplier daoSupplier, -// Species species, -// Ocean ocean, -// Sex sex, -// Date date) { -// -// Objects.requireNonNull(daoSupplier, "daoSupplier parameter can't be null"); -// Objects.requireNonNull(species, "species parameter can't be null"); -// Objects.requireNonNull(sex, "sex parameter can't be null"); -// -// List<LengthWeightParameter> list = findBySpecies(daoSupplier, species); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // aucun parametrage pour le type donne -// return null; -// } -// -// // filtrage par ocean -// List<LengthWeightParameter> filterByOcean = filterByOcean(list, ocean); -// -// if (CollectionUtils.isEmpty(filterByOcean) && ocean != null) { -// -// // filtre par ocean null -// filterByOcean = filterByOcean(list, null); -// } -// list = filterByOcean; -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas d'ocean adequate -// return null; -// } -// -// // filtrage par sexe -// list = filterBySexe(list, sex); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de sexe adequate -// return null; -// } -// -// // filtrage par startDate de validite -// list = filterByDateDebutValidite(list, date); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de date de debut adequate -// return null; -// } -// -// // filtrage par endDate de validite -// list = filterByDateFinValidite(list, date); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de date de fin adequate -// return null; -// } -// -// return list; -// -// } - -// private static Sex getUnknownSex(ObserveTopiaDaoSupplier daoSupplier) { -// return daoSupplier.getSexDao().forCodeEquals("0").findUnique(); -// } - -// public static List<LengthWeightParameter> findBySpecies(ObserveTopiaDaoSupplier daoSupplier, Species species) { -// -// LengthWeightParameterTopiaDao dao = daoSupplier.getLengthWeightParameterDao(); -// -// List<LengthWeightParameter> list = dao.forSpeciesEquals(species).findAll(); -// -// // on supprime les paramétrages qui ont a=0 ou a=null ou b=0 ou b = null -// Iterator<LengthWeightParameter> itr = list.iterator(); -// while (itr.hasNext()) { -// LengthWeightParameter p = itr.next(); -// Double a = p.getCoefficientValue(FormulaHelper.COEFFICIENT_A); -// if (a == null || a == 0) { -// itr.remove(); -// continue; -// } -// -// Double b = p.getCoefficientValue(FormulaHelper.COEFFICIENT_B); -// // on autorise d'avoir b à 0 (mais cela ne permet plus de calculer la taille à partir du poids) -//// if (b == null || b == 0) { -// if (b == null) { -// itr.remove(); -// } -// } -// return list; -// -// } -// -// public static List<LengthWeightParameter> filterByOcean(List<LengthWeightParameter> list, Ocean ocean) { -// List<LengthWeightParameter> result = new ArrayList<>(); -// if (ocean == null) { -// -// // on n'accepte que les parametrage sans ocean -// for (LengthWeightParameter parametrageLengthWeight : list) { -// if (parametrageLengthWeight.getOcean() == null) { -// result.add(parametrageLengthWeight); -// } -// } -// } else { -// for (LengthWeightParameter parametrageLengthWeight : list) { -// if (ocean.equals(parametrageLengthWeight.getOcean())) { -// result.add(parametrageLengthWeight); -// } -// } -// } -// return result; -// } -// -// public static List<LengthWeightParameter> filterBySexe(List<LengthWeightParameter> list, Sex sex) { -// return list.stream().filter(l -> l.getSex() == sex).collect(Collectors.toList()); -// } -// -// public static List<LengthWeightParameter> filterBySizeMeasureType(List<LengthWeightParameter> list, SizeMeasureType sizeMeasureType) { -// return list.stream().filter(l -> l.getSizeMeasureType() == sizeMeasureType).collect(Collectors.toList()); -// } -// -// public static List<LengthWeightParameter> filterByDateDebutValidite(List<LengthWeightParameter> list, Date startDate) { -// return list.stream() -// .filter(l -> l.getStartDate() == null || l.getStartDate().before(startDate) || l.getStartDate().equals(startDate)) -// .collect(Collectors.toList()); -// } -// -// public static List<LengthWeightParameter> filterByDateFinValidite(List<LengthWeightParameter> list, Date endDate) { -// List<LengthWeightParameter> result = new ArrayList<>(); -// -// if (endDate == null) { -// // on n'accepte que les parametrages selon les critères suivants : -// // - sans date de fin (i.e en cours de validite) -// for (LengthWeightParameter parametrageLengthWeight : list) { -// -// Date date = parametrageLengthWeight.getEndDate(); -// if (date == null) { -// result.add(parametrageLengthWeight); -// } -// } -// } else { -// // on n'accepte que les parametrages selon les critères suivants : -// // - sans date de fin (i.e en cours de validite) -// // - ceux dont la date de fin est avant la date de fin donnée -// for (LengthWeightParameter parametrageLengthWeight : list) { -// -// Date date = parametrageLengthWeight.getEndDate(); -// if (date == null || -// date.after(endDate) || -// date.equals(endDate)) { -// result.add(parametrageLengthWeight); -// } -// } -// } -// return result; -// } - } ===================================== pom.xml ===================================== @@ -26,7 +26,7 @@ <parent> <groupId>io.ultreia.maven</groupId> <artifactId>pom</artifactId> - <version>2020.21</version> + <version>2020.25</version> </parent> <groupId>fr.ird.observe</groupId> @@ -163,7 +163,7 @@ <!--can't use 1.4.197 (date has changed + blob also--> <lib.version.h2>1.4.196</lib.version.h2> <lib.version.java4all.eugene>3.0-alpha-26</lib.version.java4all.eugene> - <lib.version.java4all.jaxx>3.0-alpha-68-SNAPSHOT</lib.version.java4all.jaxx> + <!--<lib.version.java4all.jaxx>3.0-alpha-68-SNAPSHOT</lib.version.java4all.jaxx>--> <!--<lib.version.java4all.i18n>4.0-beta-8-SNAPSHOT</lib.version.java4all.i18n>--> <lib.version.java4all.topia>1.1.17</lib.version.java4all.topia> <lib.version.nuiton.utils>3.0</lib.version.nuiton.utils> ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java ===================================== @@ -29,6 +29,7 @@ import fr.ird.observe.dto.data.seine.FloatingObjectDto; import fr.ird.observe.dto.data.seine.FloatingObjectPartDto; import fr.ird.observe.dto.data.seine.NonTargetCatchComputedValueSource; import fr.ird.observe.dto.data.seine.SchoolType; +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.dto.referential.ReferentialLocale; import fr.ird.observe.entities.LengthWeightComputable; import fr.ird.observe.entities.referentiel.LengthLengthParameter; @@ -157,7 +158,8 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements FloatingObjectConsolidateEngine floatingObjectConsolidateEngine = new FloatingObjectConsolidateEngine(simplifiedObjectTypeManager); - Optional<ConsolidateTripSeineDataResult> consolidateTripSeineDataResult = consolidateTripSeine(referenceLocale, floatingObjectConsolidateEngine, request.getTripSeineId(), failIfLengthWeightParameterNotFound, failIfLengthLengthParameterNotFound); + DecoratorService decoratorService = new DecoratorService(getReferentialLocale()); + Optional<ConsolidateTripSeineDataResult> consolidateTripSeineDataResult = consolidateTripSeine(decoratorService, referenceLocale, floatingObjectConsolidateEngine, request.getTripSeineId(), failIfLengthWeightParameterNotFound, failIfLengthLengthParameterNotFound); return consolidateTripSeineDataResult.orElse(null); } @@ -178,7 +180,7 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements return new SimplifiedObjectTypeManager(materialMapping, simplifiedObjectTypeSpecializedRules); } - private Optional<ConsolidateTripSeineDataResult> consolidateTripSeine(ReferentialLocale referenceLocale, FloatingObjectConsolidateEngine floatingObjectConsolidateEngine, String tripSeineId, boolean failIfLengthWeightParameterNotFound, boolean failIfLengthLengthParameterNotFound) { + private Optional<ConsolidateTripSeineDataResult> consolidateTripSeine(DecoratorService decoratorService, ReferentialLocale referenceLocale, FloatingObjectConsolidateEngine floatingObjectConsolidateEngine, String tripSeineId, boolean failIfLengthWeightParameterNotFound, boolean failIfLengthLengthParameterNotFound) { log.info(String.format("Start consolidate trip: %s", tripSeineId)); @@ -223,24 +225,25 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements int routeMax = tripSeine.sizeRoute(); for (Route route : tripSeine.getRoute()) { - String routePrefix =String.format("Route [%s/%s] ", ++routeIndex, routeMax); + String routePrefix = String.format("Route [%s/%s] ", ++routeIndex, routeMax); log.info(String.format("%s Start consolidate route: %s", routePrefix, route.getTopiaId())); int activityIndex = 0; int activityMax = route.sizeActivitySeine(); for (ActivitySeine activitySeine : route.getActivitySeine()) { - String activityPrefix =String.format("%s - Activity [%s/%s] ", routePrefix, ++activityIndex, activityMax); + String activityPrefix = String.format("%s - Activity [%s/%s] ", routePrefix, ++activityIndex, activityMax); boolean floatingObjectEmpty = activitySeine.isFloatingObjectEmpty(); if (!activitySeine.isSetOperation() && floatingObjectEmpty) { - log.info(String.format("%s Skip activity (No set nor dcp found): %s", activityPrefix, activitySeine.getTopiaId())); - continue; + log.info(String.format("%s Skip activity (No set nor dcp found): %s", activityPrefix, activitySeine.getTopiaId())); + continue; } ConsolidateActivitySeineDataResultBuilder resultBuilder = new ConsolidateActivitySeineDataResultBuilder(applicationLocale, referenceLocale, activitySeine.getTopiaId(), ActivitySeines.decorate(referenceLocale.ordinal(), activitySeine)); ConsolidationActivitySeineDataContext activityContext = new ConsolidationActivitySeineDataContext(); activityContext.locale = applicationLocale; + activityContext.decoratorService = decoratorService; activityContext.failIfLengthWeightParameterNotFound = failIfLengthWeightParameterNotFound; activityContext.failIfLengthLengthParameterNotFound = failIfLengthLengthParameterNotFound; activityContext.daoSupplier = persistenceContext; @@ -331,9 +334,9 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements activityContext.watchTargetLength(targetLength); updateLengthWeightAble(activityContext, - targetLength.getSpecies(), - null, /* pas de sexe precise */ - targetLength); + targetLength.getSpecies(), + null, /* pas de sexe precise */ + targetLength); activityContext.flushTargetLength(); @@ -353,9 +356,9 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements activityContext.watchNonTargetLenght(nonTargetLength); updateLengthWeightAble(activityContext, - nonTargetLength.getSpecies(), - nonTargetLength.getSex(), - nonTargetLength); + nonTargetLength.getSpecies(), + nonTargetLength.getSex(), + nonTargetLength); activityContext.flushNonTargetLength(); @@ -411,11 +414,11 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements boolean notWhenArriving = !dcp.getObjectOperation().isWhenArriving(); boolean notWhenLeaving = !dcp.getObjectOperation().isWhenLeaving(); for (FloatingObjectPart floatingObjectPart : dcp.getFloatingObjectPart()) { - if (floatingObjectPart.getWhenArriving()!=null && notWhenArriving) { + if (floatingObjectPart.getWhenArriving() != null && notWhenArriving) { log.info(String.format("Set whenArriving to null for part: %s", floatingObjectPart.getTopiaId())); floatingObjectPart.setWhenArriving(null); } - if (floatingObjectPart.getWhenLeaving()!=null && notWhenLeaving) { + if (floatingObjectPart.getWhenLeaving() != null && notWhenLeaving) { log.info(String.format("Set whenLeaving to null for part: %s", floatingObjectPart.getTopiaId())); floatingObjectPart.setWhenLeaving(null); } ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidationActivitySeineDataContext.java ===================================== @@ -27,6 +27,7 @@ import fr.ird.observe.dto.data.seine.DcpComputedValue; import fr.ird.observe.dto.data.seine.FloatingObjectDto; import fr.ird.observe.dto.data.seine.FloatingObjectPartDto; import fr.ird.observe.dto.data.seine.SchoolType; +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.entities.referentiel.LengthLengthParameter; import fr.ird.observe.entities.referentiel.LengthLengthParameterNotFoundException; import fr.ird.observe.entities.referentiel.LengthLengthParameters; @@ -72,6 +73,7 @@ class ConsolidationActivitySeineDataContext { boolean failIfLengthLengthParameterNotFound; BeanMonitor targetLengthMonitor; String activityPrefix; + DecoratorService decoratorService; BeanMonitor nonTargetLengthMonitor; @@ -99,7 +101,7 @@ class ConsolidationActivitySeineDataContext { Ocean ocean = getOcean(); Date routeDate = getRouteDate(); try { - return Optional.ofNullable(LengthWeightParameters.findLengthWeightParameter(daoSupplier, species, sex, ocean, routeDate, sizeMeasureType)); + return Optional.ofNullable(LengthWeightParameters.findLengthWeightParameter(decoratorService, daoSupplier, species, sex, ocean, routeDate, sizeMeasureType)); } catch (LengthWeightParameterNotFoundException e) { if (failIfLengthWeightParameterNotFound) { throw e; @@ -113,7 +115,7 @@ class ConsolidationActivitySeineDataContext { Ocean ocean = getOcean(); Date routeDate = getRouteDate(); try { - return LengthLengthParameters.findLengthLengthParameter(daoSupplier, species, ocean, sex, routeDate, inputSizeMeasureType, outputSizeMeasureType); + return LengthLengthParameters.findLengthLengthParameter(decoratorService, daoSupplier, species, ocean, sex, routeDate, inputSizeMeasureType, outputSizeMeasureType); } catch (LengthLengthParameterNotFoundException e) { if (failIfLengthLengthParameterNotFound) { throw e; ===================================== services-local/src/test/java/fr/ird/observe/services/local/entity/LengthWeightParemetersTest.java ===================================== @@ -22,7 +22,9 @@ package fr.ird.observe.services.local.entity; import com.opensymphony.xwork2.interceptor.annotations.After; +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.dto.referential.ReferenceStatus; +import fr.ird.observe.dto.referential.ReferentialLocale; import fr.ird.observe.entities.referentiel.LengthWeightParameter; import fr.ird.observe.entities.referentiel.LengthWeightParameterNotFoundException; import fr.ird.observe.entities.referentiel.LengthWeightParameterTopiaDao; @@ -61,6 +63,7 @@ public class LengthWeightParemetersTest extends ServiceLocalTestSupport { private static final Logger log = LogManager.getLogger(LengthWeightParemetersTest.class); private ObserveTopiaPersistenceContext persistenceContext; + private DecoratorService decoratorService; protected static void createLengthWeightParameter(LengthWeightParameterTopiaDao lengthWeightParameterDao, Species species, @@ -91,6 +94,7 @@ public class LengthWeightParemetersTest extends ServiceLocalTestSupport { @Before public void setUp() { + decoratorService =new DecoratorService(ReferentialLocale.FR); persistenceContext = localTestMethodResource.newPersistenceContext(); SpeciesTopiaDao speciesDAO = persistenceContext.getSpeciesDao(); @@ -239,7 +243,7 @@ public class LengthWeightParemetersTest extends ServiceLocalTestSupport { if (log.isInfoEnabled()) { log.info("Try to find length weith parameter for species " + species.getFaoCode() + " - ocean " + ocean.getLabel1() + " - sex " + (sex == null ? "null" : sex.getLabel1()) + " at " + date); } - LengthWeightParameter lengthWeightParameter = LengthWeightParameters.findLengthWeightParameter(supplier, species, sex, ocean, date, expectedSizeMeasureType); + LengthWeightParameter lengthWeightParameter = LengthWeightParameters.findLengthWeightParameter(decoratorService, supplier, species, sex, ocean, date, expectedSizeMeasureType); Assert.assertNotNull("length weith parameter not found for species " + species.getFaoCode() + " - ocean " + ocean.getLabel1() + " - sex " + (sex == null ? "null" : sex.getLabel1()) + " at " + date, lengthWeightParameter); Assert.assertEquals("Expected sex is " + expectedSex.getLabel1() + " but the one found was " + lengthWeightParameter.getSex().getLabel1(), expectedSex, lengthWeightParameter.getSex()); @@ -255,7 +259,7 @@ public class LengthWeightParemetersTest extends ServiceLocalTestSupport { log.info("Try to find length weith parameter for species " + species.getFaoCode() + " - ocean " + ocean.getLabel1() + " - sex " + (sex == null ? "null" : sex.getLabel1()) + " at " + date); } try { - LengthWeightParameters.findLengthWeightParameter(supplier, species, sex, ocean, date, expectedSizeMeasureType); + LengthWeightParameters.findLengthWeightParameter(decoratorService, supplier, species, sex, ocean, date, expectedSizeMeasureType); Assert.fail(); } catch (LengthWeightParameterNotFoundException e) { View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/36e112a1111ef927bbadf77dd... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/36e112a1111ef927bbadf77dd... You're receiving this email because of your account on gitlab.com.