Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: af76b2dc by Tony Chemit at 2021-03-11T10:51:24+01:00 Réusinage de la configuration d'une source de données et des templates associées - Closes #1797 - - - - - d219d92e by Tony Chemit at 2021-03-11T10:51:24+01:00 Fix bad reports selection - - - - - c10c0313 by Tony Chemit at 2021-03-11T10:57:10+01:00 Réusinage de la configuration d'une source de données et des templates associées - Closes #1797 - - - - - f1be0811 by Tony Chemit at 2021-03-11T12:15:05+01:00 Bloquer l'import d'une marée si elle contient des identifiants déjà utilisés dans la base cible - Closes #1799 - - - - - 03a7237c by Tony Chemit at 2021-03-11T15:19:13+01:00 Update jaxx - - - - - 27 changed files: - client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportModel.java - client/datasource/api/src/main/i18n/templates/ObserveSwingDataSource_en_GB.ftl - client/datasource/api/src/main/i18n/templates/ObserveSwingDataSource_es_ES.ftl - client/datasource/api/src/main/i18n/templates/ObserveSwingDataSource_fr_FR.ftl - client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/config/ConfigSupport.jcss - client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/config/form/ConfigurationModel.java - client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/config/form/ServerConfigurationModel.java - client/datasource/api/src/test/java/fr/ird/observe/client/datasource/api/ObserveSwingDataSourceTest.java - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/menu/DataSourceEditorMenu.jcss - pom.xml - − server/core/.mvn/i18n/parse-java - server/core/pom.xml - − server/core/src/main/i18n/getters/java.getter - server/core/src/main/java/fr/ird/observe/server/request/ObserveWebRequestContext.java - − server/core/src/main/java/fr/ird/observe/server/security/AdminApiKeyNotFoundException.java - − server/core/src/main/java/fr/ird/observe/server/security/AuthenticationTokenNotFoundException.java - − server/core/src/main/java/fr/ird/observe/server/security/BadObserveWebUserPasswordException.java - − server/core/src/main/java/fr/ird/observe/server/security/InvalidAdminKeyApiException.java - server/core/src/main/java/fr/ird/observe/server/security/ObserveWebSecurityApplicationContext.java - − server/core/src/main/java/fr/ird/observe/server/security/UnknownObserveWebUserException.java - − server/core/src/main/java/fr/ird/observe/server/security/UnknownObserveWebUserForDatabaseException.java - − server/core/src/main/java/fr/ird/observe/server/security/UserLoginNotFoundException.java - − server/core/src/main/java/fr/ird/observe/server/security/UserPasswordNotFoundException.java - server/i18n/src/main/i18n/translations/observe_en_GB.properties - server/i18n/src/main/i18n/translations/observe_es_ES.properties - server/i18n/src/main/i18n/translations/observe_fr_FR.properties - services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/TripManagementServiceLocalSupport.java Changes: ===================================== client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/report/ReportModel.java ===================================== @@ -44,6 +44,7 @@ import java.nio.file.Files; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.TreeMap; import java.util.stream.Collectors; @@ -333,7 +334,7 @@ public class ReportModel extends AdminActionModel { if (reportFile == null) { return; } - reports = getAllReports().stream().filter(r -> modelType.toString() == r.getModelType()).collect(Collectors.toList()); + reports = getAllReports().stream().filter(r -> Objects.equals(modelType.toString(), r.getModelType())).collect(Collectors.toList()); firePropertyChange(REPORTS_PROPERTY_NAME, reports); log.info(String.format("Detects %d report(s).", reports.size() - 1)); } ===================================== client/datasource/api/src/main/i18n/templates/ObserveSwingDataSource_en_GB.ftl ===================================== @@ -20,11 +20,13 @@ --> <html> <body> -<#import "ObserveDataSourceConfiguration_en_GB.ftl" as configurationMacros> -<h3>${.data_model.label}</h3> -<@configurationMacros.dataSourceConfiguration .data_model.configuration /> -<#if .data_model.dataSourceInformation??> - <@configurationMacros.dataSourceInformationRights .data_model.dataSourceInformation /> +<#if .data_model?? && .data_model.label??> + <#import "ObserveDataSourceConfiguration_en_GB.ftl" as configurationMacros> + <h3>${.data_model.label}</h3> + <@configurationMacros.dataSourceConfiguration .data_model.configuration /> + <#if .data_model.dataSourceInformation??> + <@configurationMacros.dataSourceInformationRights .data_model.dataSourceInformation /> + </#if> <#else> No data source loaded </#if> ===================================== client/datasource/api/src/main/i18n/templates/ObserveSwingDataSource_es_ES.ftl ===================================== @@ -20,11 +20,13 @@ --> <html> <body> -<#import "ObserveDataSourceConfiguration_es_ES.ftl" as configurationMacros> -<h3>${.data_model.label}</h3> -<@configurationMacros.dataSourceConfiguration .data_model.configuration /> -<#if .data_model.dataSourceInformation??> - <@configurationMacros.dataSourceInformationRights .data_model.dataSourceInformation /> +<#if .data_model?? && .data_model.label??> + <#import "ObserveDataSourceConfiguration_es_ES.ftl" as configurationMacros> + <h3>${.data_model.label}</h3> + <@configurationMacros.dataSourceConfiguration .data_model.configuration /> + <#if .data_model.dataSourceInformation??> + <@configurationMacros.dataSourceInformationRights .data_model.dataSourceInformation /> + </#if> <#else> Ninguna fuente de datos cargada </#if> ===================================== client/datasource/api/src/main/i18n/templates/ObserveSwingDataSource_fr_FR.ftl ===================================== @@ -20,11 +20,13 @@ --> <html> <body> -<#import "ObserveDataSourceConfiguration_fr_FR.ftl" as configurationMacros> -<h3>${.data_model.label}</h3> -<@configurationMacros.dataSourceConfiguration .data_model.configuration /> -<#if .data_model.dataSourceInformation??> - <@configurationMacros.dataSourceInformationRights .data_model.dataSourceInformation /> +<#if .data_model?? && .data_model.label??> + <#import "ObserveDataSourceConfiguration_fr_FR.ftl" as configurationMacros> + <h3>${.data_model.label}</h3> + <@configurationMacros.dataSourceConfiguration .data_model.configuration /> + <#if .data_model.dataSourceInformation??> + <@configurationMacros.dataSourceInformationRights .data_model.dataSourceInformation /> + </#if> <#else> Aucune source de données chargée </#if> ===================================== client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/config/ConfigSupport.jcss ===================================== @@ -21,7 +21,7 @@ */ #testConnexion { - enabled:{!model.isConnexionSuccess()}; + enabled:{model.isSyntaxValid() && !model.isConnexionSuccess()}; } #saveConfiguration { ===================================== client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/config/form/ConfigurationModel.java ===================================== @@ -40,6 +40,8 @@ import org.nuiton.version.Versions; import javax.swing.Icon; import java.awt.Color; +import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.reflect.UndeclaredThrowableException; import java.util.Objects; import java.util.function.Function; @@ -70,7 +72,6 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit public static final String CONNEXION_STATUS_ICON_PROPERTY_NAME = "connexionStatusIcon"; public static final String CONNEXION_STATUS_COLOR_PROPERTY_NAME = "connexionStatusColor"; public static final String CAN_CREATE_DATABASE_PROPERTY_NAME = "canCreateDatabase"; - public static final String BUSY_PROPERTY_NAME = "busy"; public static final String SYNTAX_VALID_PROPERTY_NAME = "syntaxValid"; /** @@ -109,11 +110,6 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit * Is configuration syntax is valid? */ private boolean syntaxValid; - - /** - * Is model busy? - */ - private boolean busy; /** * FIXME Add this in DataSourceConnectMode * Cache of colors indexed by connexion status. @@ -124,6 +120,8 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit this.configuration = Objects.requireNonNull(configuration); } + protected abstract boolean testSyntax(); + public void fromConfig(ObserveDataSourceConfiguration config) { String oldLabel = getLabel(); getConfiguration().setLabel(config == null ? null : config.getLabel()); @@ -135,45 +133,28 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit return configuration.getDataSourceType(); } - /** - * Use this as soon as the configuration has been modified. - */ - protected void clearStatus() { - setDataSourceInformation(null); - setConnexionError(null); - setConnexionStatus(ConnexionStatus.UNTESTED); - setSyntaxValid(false); - } - /** * @param dataSourceFunction to get new data source * @return {@code true} if connexion was tested and is valid. */ public final boolean testConnexion(Function<ObserveDataSourceConfiguration, ObserveSwingDataSource> dataSourceFunction) { clearStatus(); - setBusy(true); - boolean syntaxValid = testSyntax(); - setSyntaxValid(syntaxValid); - if (isConnexionFailed()) { + if (!isSyntaxValid() || isConnexionFailed()) { return false; } + ObserveSwingDataSource dataSource = dataSourceFunction.apply(getConfiguration()); try { - ObserveSwingDataSource dataSource = dataSourceFunction.apply(getConfiguration()); - try { - ObserveDataSourceInformation dataSourceInformation = test(dataSource); - testDataSourceInformation(dataSourceInformation); - if (!isConnexionFailed()) { - setConnexionStatus(ConnexionStatus.SUCCESS); - } - } catch (Throwable e) { - onConnexionError(e); - } finally { - if (dataSource.isOpen()) { - dataSource.close(); - } + ObserveDataSourceInformation dataSourceInformation = test(dataSource); + testDataSourceInformation(dataSourceInformation); + if (!isConnexionFailed()) { + setConnexionStatus(ConnexionStatus.SUCCESS); } + } catch (Throwable e) { + onConnexionError(e); } finally { - setBusy(false); + if (dataSource.isOpen()) { + dataSource.close(); + } } return isConnexionSuccess(); } @@ -183,8 +164,9 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit } public void setSyntaxValid(boolean syntaxValid) { + boolean oldValue = isSyntaxValid(); this.syntaxValid = syntaxValid; - firePropertyChange(SYNTAX_VALID_PROPERTY_NAME, syntaxValid); + firePropertyChange(SYNTAX_VALID_PROPERTY_NAME, oldValue, syntaxValid); } public boolean isConnexionSuccess() { @@ -199,20 +181,6 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit return getConnexionStatus() == ConnexionStatus.UNTESTED; } - protected abstract boolean testSyntax(); - - protected void onConnexionError(Throwable e) { - if (e instanceof UndeclaredThrowableException) { - e = ((UndeclaredThrowableException) e).getUndeclaredThrowable(); - } - setConnexionError(e); - setConnexionStatus(ConnexionStatus.FAILED); - } - - public ObserveDataSourceConfiguration getConfiguration() { - return configuration; - } - public String getLabel() { return getConfiguration().getLabel(); } @@ -239,7 +207,16 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit public String getConnexionStatusText() { if (connexionStatusText == null) { - this.connexionStatusText = ConfigurationModelTemplate.generate(this); + try { + this.connexionStatusText = ConfigurationModelTemplate.generate(this); + } catch (Exception e) { + StringWriter out = new StringWriter(4048); + try (PrintWriter writer = new PrintWriter(out)) { + e.printStackTrace(writer); + out.flush(); + } + connexionStatusText = out.toString(); + } } return connexionStatusText; } @@ -292,7 +269,7 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit Throwable oldValue = getConnexionError(); this.connexionError = connexionError; firePropertyChange(CONNEXION_ERROR_PROPERTY_NAME, oldValue, connexionError); - setConnexionStatusError(connexionError == null ? null : connexionError.getMessage()); + setConnexionStatusError(connexionError == null ? null : connexionError.getMessage()==null?connexionError.toString():connexionError.getMessage()); } public ObserveDataSourceInformation getDataSourceInformation() { @@ -318,14 +295,26 @@ public abstract class ConfigurationModel extends AbstractJavaBean implements Wit firePropertyChange(CAN_MIGRATE_PROPERTY_NAME, oldValue, canMigrate); } - public boolean isBusy() { - return busy; + /** + * Use this as soon as the configuration has been modified. + */ + protected void clearStatus() { + setDataSourceInformation(null); + setConnexionError(null); + setConnexionStatus(ConnexionStatus.UNTESTED); + setSyntaxValid(testSyntax()); } - public void setBusy(boolean busy) { - boolean oldValue = isBusy(); - this.busy = busy; - firePropertyChange(BUSY_PROPERTY_NAME, oldValue, busy); + protected void onConnexionError(Throwable e) { + if (e instanceof UndeclaredThrowableException) { + e = ((UndeclaredThrowableException) e).getUndeclaredThrowable(); + } + setConnexionError(e); + setConnexionStatus(ConnexionStatus.FAILED); + } + + public ObserveDataSourceConfiguration getConfiguration() { + return configuration; } protected final ObserveDataSourceInformation test(ObserveSwingDataSource dataSource) throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException { ===================================== client/datasource/api/src/main/java/fr/ird/observe/client/datasource/api/config/form/ServerConfigurationModel.java ===================================== @@ -43,7 +43,7 @@ import java.net.URL; public class ServerConfigurationModel extends ConfigurationModel { public static final String LOGIN_PROPERTY_NAME = "login"; public static final String SERVER_URL_PROPERTY_NAME = "serverUrl"; - public static final String OPTIONAL_SERVER_DATABASE_NAME_PROPERTY_NAME = "optionalServerDatabaseName"; + public static final String OPTIONAL_DATABASE_NAME_PROPERTY_NAME = "optionalDatabaseName"; private static final Logger log = LogManager.getLogger(ServerConfigurationModel.class); public ServerConfigurationModel() { @@ -63,7 +63,7 @@ public class ServerConfigurationModel extends ConfigurationModel { firePropertyChange(SERVER_URL_PROPERTY_NAME, oldServerUrl, getServerUrl()); firePropertyChange(LOGIN_PROPERTY_NAME, oldLogin, getLogin()); firePropertyChange(PASSWORD_PROPERTY_NAME, oldPassword, getPassword()); - firePropertyChange(OPTIONAL_SERVER_DATABASE_NAME_PROPERTY_NAME, oldOptionalDatabaseName, getOptionalDatabaseName()); + firePropertyChange(OPTIONAL_DATABASE_NAME_PROPERTY_NAME, oldOptionalDatabaseName, getOptionalDatabaseName()); } public void fromPreset(ServerDataSourceConfiguration configuration) { @@ -79,7 +79,7 @@ public class ServerConfigurationModel extends ConfigurationModel { firePropertyChange(SERVER_URL_PROPERTY_NAME, oldServerUrl, getServerUrl()); firePropertyChange(LOGIN_PROPERTY_NAME, oldLogin, getLogin()); firePropertyChange(PASSWORD_PROPERTY_NAME, oldPassword, getPassword()); - firePropertyChange(OPTIONAL_SERVER_DATABASE_NAME_PROPERTY_NAME, oldOptionalDatabaseName, getOptionalDatabaseName()); + firePropertyChange(OPTIONAL_DATABASE_NAME_PROPERTY_NAME, oldOptionalDatabaseName, getOptionalDatabaseName()); clearStatus(); } @@ -100,9 +100,8 @@ public class ServerConfigurationModel extends ConfigurationModel { @Override protected boolean testSyntax() { - String serverUrl = getConfiguration().getServerUrl(); - if (getServerUrl() == null || getLogin() != null || getPassword() == null) { + if (getServerUrl() == null || getLogin() == null || getPassword() == null) { return false; } try { @@ -110,6 +109,7 @@ public class ServerConfigurationModel extends ConfigurationModel { } catch (MalformedURLException e) { setConnexionStatusError(I18n.t("observe.ui.datasource.storage.error.badUrl", serverUrl)); setConnexionStatus(ConnexionStatus.FAILED); + return false; } return true; } @@ -154,7 +154,7 @@ public class ServerConfigurationModel extends ConfigurationModel { public void setOptionalDatabaseName(String optionalDatabaseName) { String oldValue = getOptionalDatabaseName(); getConfiguration().setOptionalDatabaseName(optionalDatabaseName); - firePropertyChange(OPTIONAL_SERVER_DATABASE_NAME_PROPERTY_NAME, oldValue, optionalDatabaseName); + firePropertyChange(OPTIONAL_DATABASE_NAME_PROPERTY_NAME, oldValue, optionalDatabaseName); clearStatus(); } ===================================== client/datasource/api/src/test/java/fr/ird/observe/client/datasource/api/ObserveSwingDataSourceTest.java ===================================== @@ -145,7 +145,9 @@ public class ObserveSwingDataSourceTest { } private void assertGenerate(ObserveSwingDataSource dataSource) { - String expected = ObserveSwingDataSourceTemplate.generate(dataSource); + String expected = ObserveSwingDataSourceTemplate.generate(null); + Assert.assertNotNull(expected); + expected = ObserveSwingDataSourceTemplate.generate(dataSource); String actual = dataSource.getSummaryText(); Assert.assertNotNull(expected); Assert.assertNotNull(actual); ===================================== 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()}; } ===================================== pom.xml ===================================== @@ -151,7 +151,7 @@ <maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format> <buildDate>${maven.build.timestamp}</buildDate> - <toolkit.version>5.0.7</toolkit.version> + <toolkit.version>5.0.8</toolkit.version> <lib.version.ognl>3.1.28</lib.version.ognl> <!--can't use 1.4.197 (date has changed + blob also)--> @@ -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-2</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>--> ===================================== server/core/.mvn/i18n/parse-java deleted ===================================== ===================================== server/core/pom.xml ===================================== @@ -88,10 +88,6 @@ <groupId>io.ultreia.java4all.topia</groupId> <artifactId>persistence</artifactId> </dependency> - <dependency> - <groupId>io.ultreia.java4all.i18n</groupId> - <artifactId>i18n-runtime</artifactId> - </dependency> <dependency> <groupId>io.ultreia.java4all</groupId> <artifactId>class-mapping</artifactId> @@ -117,10 +113,10 @@ <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> - <dependency> - <groupId>com.google.auto.service</groupId> - <artifactId>auto-service-annotations</artifactId> - </dependency> +<!-- <dependency>--> +<!-- <groupId>com.google.auto.service</groupId>--> +<!-- <artifactId>auto-service-annotations</artifactId>--> +<!-- </dependency>--> <dependency> <groupId>org.nuiton</groupId> ===================================== server/core/src/main/i18n/getters/java.getter deleted ===================================== @@ -1,8 +0,0 @@ -observe.ui.datasource.storage.error.rest.adminApiKey.invalid -observe.ui.datasource.storage.error.rest.adminApiKey.required -observe.ui.datasource.storage.error.rest.authenticationToken.required -observe.ui.datasource.storage.error.rest.database.unknownForUser -observe.ui.datasource.storage.error.rest.password.bad -observe.ui.datasource.storage.error.rest.password.required -observe.ui.datasource.storage.error.rest.user.required -observe.ui.datasource.storage.error.rest.user.unknown ===================================== server/core/src/main/java/fr/ird/observe/server/request/ObserveWebRequestContext.java ===================================== @@ -26,9 +26,9 @@ import fr.ird.observe.dto.db.configuration.ObserveDataSourceConfiguration; import fr.ird.observe.dto.db.configuration.ObserveDataSourceConfigurationAndConnection; import fr.ird.observe.server.ObserveWebApplicationContext; import fr.ird.observe.server.configuration.ObserveServiceInitializerServerConfig; -import fr.ird.observe.server.security.AdminApiKeyNotFoundException; -import fr.ird.observe.server.security.AuthenticationTokenNotFoundException; -import fr.ird.observe.server.security.InvalidAdminKeyApiException; +import fr.ird.observe.services.service.security.AdminApiKeyNotFoundException; +import fr.ird.observe.services.service.security.AuthenticationTokenNotFoundException; +import fr.ird.observe.services.service.security.InvalidAdminKeyApiException; import fr.ird.observe.services.ObserveServiceInitializer; import fr.ird.observe.services.service.ObserveService; import org.debux.webmotion.server.call.HttpContext; ===================================== server/core/src/main/java/fr/ird/observe/server/security/AdminApiKeyNotFoundException.java deleted ===================================== @@ -1,42 +0,0 @@ -package fr.ird.observe.server.security; - -/* - * #%L - * ObServe Server :: Core - * %% - * 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.services.service.security.SecurityExceptionSupport; -import io.ultreia.java4all.i18n.I18n; - -import java.util.Locale; - -/** - * Created on 07/09/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class AdminApiKeyNotFoundException extends SecurityExceptionSupport { - - private static final long serialVersionUID = 1L; - - public AdminApiKeyNotFoundException(Locale locale) { - super(I18n.l(locale, "observe.ui.datasource.storage.error.rest.adminApiKey.required")); - } -} ===================================== server/core/src/main/java/fr/ird/observe/server/security/AuthenticationTokenNotFoundException.java deleted ===================================== @@ -1,42 +0,0 @@ -package fr.ird.observe.server.security; - -/* - * #%L - * ObServe Server :: Core - * %% - * 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.services.service.security.SecurityExceptionSupport; -import io.ultreia.java4all.i18n.I18n; - -import java.util.Locale; - -/** - * Created on 07/09/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class AuthenticationTokenNotFoundException extends SecurityExceptionSupport { - - private static final long serialVersionUID = 1L; - - public AuthenticationTokenNotFoundException(Locale locale) { - super(I18n.l(locale, "observe.ui.datasource.storage.error.rest.authenticationToken.required")); - } -} ===================================== server/core/src/main/java/fr/ird/observe/server/security/BadObserveWebUserPasswordException.java deleted ===================================== @@ -1,43 +0,0 @@ -package fr.ird.observe.server.security; - -/* - * #%L - * ObServe Server :: Core - * %% - * 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.services.service.security.SecurityExceptionSupport; -import io.ultreia.java4all.i18n.I18n; - -import java.util.Locale; - -/** - * Created on 30/08/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class BadObserveWebUserPasswordException extends SecurityExceptionSupport { - - private static final long serialVersionUID = 1L; - - public BadObserveWebUserPasswordException(Locale locale, String userLogin) { - super(I18n.l(locale, "observe.ui.datasource.storage.error.rest.password.bad", userLogin)); - } - -} ===================================== server/core/src/main/java/fr/ird/observe/server/security/InvalidAdminKeyApiException.java deleted ===================================== @@ -1,43 +0,0 @@ -package fr.ird.observe.server.security; - -/* - * #%L - * ObServe Server :: Core - * %% - * 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.services.service.security.SecurityExceptionSupport; -import io.ultreia.java4all.i18n.I18n; - -import java.util.Locale; - -/** - * Created on 02/09/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class InvalidAdminKeyApiException extends SecurityExceptionSupport { - - private static final long serialVersionUID = 1L; - - public InvalidAdminKeyApiException(Locale locale) { - super(I18n.l(locale, "observe.ui.datasource.storage.error.rest.adminApiKey.invalid")); - } - -} ===================================== server/core/src/main/java/fr/ird/observe/server/security/ObserveWebSecurityApplicationContext.java ===================================== @@ -35,7 +35,12 @@ import fr.ird.observe.server.configuration.user.ObserveWebUser; import fr.ird.observe.server.configuration.user.ObserveWebUserPermission; import fr.ird.observe.server.configuration.user.ObserveWebUsers; import fr.ird.observe.server.request.ObserveWebRequestContext; +import fr.ird.observe.services.service.security.BadObserveWebUserPasswordException; import fr.ird.observe.services.service.security.InvalidAuthenticationTokenException; +import fr.ird.observe.services.service.security.UnknownObserveWebUserException; +import fr.ird.observe.services.service.security.UnknownObserveWebUserForDatabaseException; +import fr.ird.observe.services.service.security.UserLoginNotFoundException; +import fr.ird.observe.services.service.security.UserPasswordNotFoundException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.nuiton.version.Version; ===================================== server/core/src/main/java/fr/ird/observe/server/security/UnknownObserveWebUserException.java deleted ===================================== @@ -1,43 +0,0 @@ -package fr.ird.observe.server.security; - -/* - * #%L - * ObServe Server :: Core - * %% - * 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.services.service.security.SecurityExceptionSupport; -import io.ultreia.java4all.i18n.I18n; - -import java.util.Locale; - -/** - * Created on 30/08/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class UnknownObserveWebUserException extends SecurityExceptionSupport { - - private static final long serialVersionUID = 1L; - - public UnknownObserveWebUserException(Locale locale, String userLogin) { - super(I18n.l(locale, "observe.ui.datasource.storage.error.rest.user.unknown", userLogin)); - } - -} ===================================== server/core/src/main/java/fr/ird/observe/server/security/UnknownObserveWebUserForDatabaseException.java deleted ===================================== @@ -1,42 +0,0 @@ -package fr.ird.observe.server.security; - -/* - * #%L - * ObServe Server :: Core - * %% - * 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.services.service.security.SecurityExceptionSupport; -import io.ultreia.java4all.i18n.I18n; - -import java.util.Locale; - -/** - * Created on 30/08/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class UnknownObserveWebUserForDatabaseException extends SecurityExceptionSupport { - - private static final long serialVersionUID = 1L; - - public UnknownObserveWebUserForDatabaseException(Locale locale, String databaseName, String role) { - super(I18n.l(locale, "observe.ui.datasource.storage.error.rest.database.unknownForUser", databaseName, role)); - } -} ===================================== server/core/src/main/java/fr/ird/observe/server/security/UserLoginNotFoundException.java deleted ===================================== @@ -1,42 +0,0 @@ -package fr.ird.observe.server.security; - -/* - * #%L - * ObServe Server :: Core - * %% - * 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.services.service.security.SecurityExceptionSupport; -import io.ultreia.java4all.i18n.I18n; - -import java.util.Locale; - -/** - * Created on 07/09/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class UserLoginNotFoundException extends SecurityExceptionSupport { - - private static final long serialVersionUID = 1L; - - public UserLoginNotFoundException(Locale locale) { - super(I18n.l(locale, "observe.ui.datasource.storage.error.rest.user.required")); - } -} ===================================== server/core/src/main/java/fr/ird/observe/server/security/UserPasswordNotFoundException.java deleted ===================================== @@ -1,42 +0,0 @@ -package fr.ird.observe.server.security; - -/* - * #%L - * ObServe Server :: Core - * %% - * 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.services.service.security.SecurityExceptionSupport; -import io.ultreia.java4all.i18n.I18n; - -import java.util.Locale; - -/** - * Created on 07/09/15. - * - * @author Tony Chemit - dev@tchemit.fr - */ -public class UserPasswordNotFoundException extends SecurityExceptionSupport { - - private static final long serialVersionUID = 1L; - - public UserPasswordNotFoundException(Locale locale) { - super(I18n.l(locale, "observe.ui.datasource.storage.error.rest.password.required")); - } -} ===================================== server/i18n/src/main/i18n/translations/observe_en_GB.properties ===================================== @@ -1,14 +1,6 @@ ObserveWebApplicationConfig.description=ObServe Web configuration observe.config.client.temporaryFiles.timeout.description=Temporary files delete (in hours) observe.model.version=Model version -observe.ui.datasource.storage.error.rest.adminApiKey.invalid=Admin key not valid -observe.ui.datasource.storage.error.rest.adminApiKey.required=Admin key not found -observe.ui.datasource.storage.error.rest.authenticationToken.required=Authentication token not found -observe.ui.datasource.storage.error.rest.database.unknownForUser=Database "%s" is not defined for user "%s" -observe.ui.datasource.storage.error.rest.password.bad=Password is not valid -observe.ui.datasource.storage.error.rest.password.required=Password is mandatory -observe.ui.datasource.storage.error.rest.user.required=User login is mandatory -observe.ui.datasource.storage.error.rest.user.unknown=User "%s" is not defined on server observeweb.adminApiKey.description=API Key to use the admin mode (You should change it). observeweb.baseDirectory.description=Base directory observeweb.build.date.description=Build date ===================================== server/i18n/src/main/i18n/translations/observe_es_ES.properties ===================================== @@ -1,14 +1,6 @@ ObserveWebApplicationConfig.description=Configuración de Observe web observe.config.client.temporaryFiles.timeout.description=Temporary files delete (in hours) \#TODO observe.model.version=Versión del modelo -observe.ui.datasource.storage.error.rest.adminApiKey.invalid=Admin key not valid \#TODO -observe.ui.datasource.storage.error.rest.adminApiKey.required=Admin key not found \#TODO -observe.ui.datasource.storage.error.rest.authenticationToken.required=Authentication token not found \#TODO -observe.ui.datasource.storage.error.rest.database.unknownForUser=La base de datos "%s" no está configurada para el usuario "%s" -observe.ui.datasource.storage.error.rest.password.bad=Le contraseña es invalida -observe.ui.datasource.storage.error.rest.password.required=Le contraseña es obligatoria -observe.ui.datasource.storage.error.rest.user.required=El usuario es obligatorio -observe.ui.datasource.storage.error.rest.user.unknown=El usuario "%s" no es conocido del servidor observeweb.adminApiKey.description=Llave API Admin (Cambiar). observeweb.baseDirectory.description=Directorio de la aplicación observeweb.build.date.description=Fecha de construcción ===================================== server/i18n/src/main/i18n/translations/observe_fr_FR.properties ===================================== @@ -1,14 +1,6 @@ ObserveWebApplicationConfig.description=Observe web Configuration observe.config.client.temporaryFiles.timeout.description=Nettoyage des fichiers temporaires (en heures) observe.model.version=Version du modèle -observe.ui.datasource.storage.error.rest.adminApiKey.invalid=Pas de clef admin trouvée -observe.ui.datasource.storage.error.rest.adminApiKey.required=Clef admin non valide -observe.ui.datasource.storage.error.rest.authenticationToken.required=Pas de jeton d'authentification trouvé -observe.ui.datasource.storage.error.rest.database.unknownForUser=La base de données "%s" n'est pas définie pour l'utilisateur "%s" -observe.ui.datasource.storage.error.rest.password.bad=Le mot de passe est invalide -observe.ui.datasource.storage.error.rest.password.required=Le mot de passe est obligatoire -observe.ui.datasource.storage.error.rest.user.required=L'utilisateur est obligatoire -observe.ui.datasource.storage.error.rest.user.unknown=L'utilisateur "%s" est inconnu sur le serveur observeweb.adminApiKey.description=Clé API Admin (À changer) observeweb.baseDirectory.description=Répertoire de l'application observeweb.build.date.description=Date de construction ===================================== 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/df05cdfde7d30588c510d76ba... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/df05cdfde7d30588c510d76ba... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT