mailman.cloud.codelutin.com
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

Observe-commits

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2021 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2020 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2019 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2018 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2017 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2016 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2015 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2014 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2013 -----
  • December
  • November
  • October
  • September
observe-commits@list.forge.codelutin.com

October 2022

  • 1 participants
  • 139 discussions
[Git][ultreiaio/ird-observe][develop-9.0.x] I can't afford to pay 10$ each week for some build that takes too much time to...
by Tony CHEMIT (@tchemit) 30 Oct '22

30 Oct '22
Tony CHEMIT pushed to branch develop-9.0.x at ultreiaio / ird-observe Commits: 0c6c5e20 by Tony Chemit at 2022-10-30T20:09:23+01:00 I can&#39;t afford to pay 10$ each week for some build that takes too much time to save cache or other things :( Gitlab -1 - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -97,25 +97,25 @@ trigger-make-release: ### AUTOMATIC JOBS ### ################################################################################################### -.automatic: &automatic - only: - - /^develop.*$/i - - /^feature/.+$/i - except: - - triggers - -build: - <<: *stage_build - <<: *automatic - script: - - ultreiaio-maven-execute 'clean install -U -DskipITs' - -build-for-release: - <<: *stage_test - <<: *automatic - <<: *build-for-release - before_script: - - export BUILD_FOR_RELEASE=true +#.automatic: &automatic +# only: +# - /^develop.*$/i +# - /^feature/.+$/i +# except: +# - triggers +# +#build: +# <<: *stage_build +# <<: *automatic +# script: +# - ultreiaio-maven-execute 'clean install -U -DskipITs' +# +#build-for-release: +# <<: *stage_test +# <<: *automatic +# <<: *build-for-release +# before_script: +# - export BUILD_FOR_RELEASE=true ################################################################################################### ### AUTOMATIC RELEASE JOBS ### View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/0c6c5e20e8979820e5404f007… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/0c6c5e20e8979820e5404f007… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop] I can't afford to pay 10$ each week for some build that takes too much time to...
by Tony CHEMIT (@tchemit) 30 Oct '22

30 Oct '22
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: d1fafc3e by Tony Chemit at 2022-10-30T20:09:37+01:00 I can&#39;t afford to pay 10$ each week for some build that takes too much time to save cache or other things :( Gitlab -1 - - - - - 1 changed file: - .gitlab-ci.yml Changes: ===================================== .gitlab-ci.yml ===================================== @@ -97,25 +97,25 @@ trigger-make-release: ### AUTOMATIC JOBS ### ################################################################################################### -.automatic: &automatic - only: - - /^develop.*$/i - - /^feature/.+$/i - except: - - triggers - -build: - <<: *stage_build - <<: *automatic - script: - - ultreiaio-maven-execute 'clean install -U -DskipITs' - -build-for-release: - <<: *stage_test - <<: *automatic - <<: *build-for-release - before_script: - - export BUILD_FOR_RELEASE=true +#.automatic: &automatic +# only: +# - /^develop.*$/i +# - /^feature/.+$/i +# except: +# - triggers +# +#build: +# <<: *stage_build +# <<: *automatic +# script: +# - ultreiaio-maven-execute 'clean install -U -DskipITs' +# +#build-for-release: +# <<: *stage_test +# <<: *automatic +# <<: *build-for-release +# before_script: +# - export BUILD_FOR_RELEASE=true ################################################################################################### ### AUTOMATIC RELEASE JOBS ### View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/d1fafc3e25bb3d291f7b0b2a5… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/d1fafc3e25bb3d291f7b0b2a5… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop] 3 commits: Générer les validateurs sur l'unicité des clef métier de collections - Closes #2505
by Tony CHEMIT (@tchemit) 30 Oct '22

30 Oct '22
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 2ad3e543 by Tony Chemit at 2022-10-30T17:04:30+01:00 Générer les validateurs sur l&#39;unicité des clef métier de collections - Closes #2505 - - - - - c1b1f96d by Tony Chemit at 2022-10-30T17:16:38+01:00 Générer les validateurs sur l&#39;unicité des clef métier de collections - Closes #2505 (update for well plan) - - - - - 84acf625 by Tony Chemit at 2022-10-30T17:16:38+01:00 Souci d&#39;unicité sur le formPS observations / captures - Closes #2504 - - - - - 30 changed files: - core/api/services/.mvn/i18n → core/api/services/.mvn/i18n/parse-java - + core/api/services/.mvn/models-dto - core/api/services/pom.xml - + core/api/services/src/main/i18n/getters/java.getter - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDtoBaitsCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDtoBranchlinesCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDtoFloatlinesCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDtoHooksCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDtoBaitsCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDtoBranchlinesCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDtoFloatlinesCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDtoHooksCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/localmarket/SampleSampleSpeciesDtoSampleSpeciesCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/localmarket/SampleSpeciesDtoSampleSpeciesMeasureCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/localmarket/SurveyDtoSurveyPartCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/logbook/SampleSampleSpeciesDtoSampleSpeciesCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/logbook/SampleSpeciesDtoSampleSpeciesMeasureCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/logbook/WellActivityDtoWellActivitySpeciesCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/observation/SetCatchDtoCatchesCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/observation/SetSchoolEstimateDtoSchoolEstimateCollectionUniqueKeyValidator.java - core/api/validation/src/main/filtered-resources/validators.xml → core/api/services/src/main/resources/validators.xml - core/api/validation/src/main/filtered-resources/META-INF/validators/validation.json - core/api/validation/src/main/i18n/getters/validation-messages.getter - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDto-create-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDto-update-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDto-create-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDto-update-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ps/localmarket/SampleSampleSpeciesDto-create-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ps/localmarket/SampleSampleSpeciesDto-update-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ps/localmarket/SampleSpeciesDto-create-error-validation.xml The diff was not included because it is too large. View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/9f27b93b8b44a72a1405273c… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/9f27b93b8b44a72a1405273c… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop-9.0.x] 2 commits: Générer les validateurs sur l'unicité des clef métier de collections - Closes #2505
by Tony CHEMIT (@tchemit) 30 Oct '22

30 Oct '22
Tony CHEMIT pushed to branch develop-9.0.x at ultreiaio / ird-observe Commits: f4127bc3 by Tony Chemit at 2022-10-30T17:02:23+01:00 Générer les validateurs sur l&#39;unicité des clef métier de collections - Closes #2505 - - - - - dc9bac3b by Tony Chemit at 2022-10-30T17:02:23+01:00 Souci d&#39;unicité sur le formPS observations / captures - Closes #2504 - - - - - 30 changed files: - core/api/services/.mvn/i18n → core/api/services/.mvn/i18n/parse-java - + core/api/services/.mvn/models-dto - core/api/services/pom.xml - + core/api/services/src/main/i18n/getters/java.getter - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDtoBaitsCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDtoBranchlinesCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDtoFloatlinesCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDtoHooksCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDtoBaitsCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDtoBranchlinesCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDtoFloatlinesCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDtoHooksCompositionCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/localmarket/SampleSampleSpeciesDtoSampleSpeciesCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/localmarket/SampleSpeciesDtoSampleSpeciesMeasureCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/localmarket/SurveyDtoSurveyPartCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/logbook/SampleSampleSpeciesDtoSampleSpeciesCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/logbook/SampleSpeciesDtoSampleSpeciesMeasureCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/observation/SetCatchDtoCatchesCollectionUniqueKeyValidator.java - + core/api/services/src/main/java/fr/ird/observe/dto/data/ps/observation/SetSchoolEstimateDtoSchoolEstimateCollectionUniqueKeyValidator.java - core/api/validation/src/main/filtered-resources/validators.xml → core/api/services/src/main/resources/validators.xml - core/api/validation/src/main/filtered-resources/META-INF/validators/validation.json - core/api/validation/src/main/i18n/getters/validation-messages.getter - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDto-create-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ll/logbook/SetGlobalCompositionDto-update-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDto-create-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ll/observation/SetGlobalCompositionDto-update-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ps/localmarket/SampleSampleSpeciesDto-create-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ps/localmarket/SampleSampleSpeciesDto-update-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ps/localmarket/SampleSpeciesDto-create-error-validation.xml - core/api/validation/src/main/resources/fr/ird/observe/dto/data/ps/localmarket/SampleSpeciesDto-update-error-validation.xml The diff was not included because it is too large. View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/d7c8956fe444adbe5b8c9335… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/d7c8956fe444adbe5b8c9335… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop] tms_version va-t-elle rester dans le schéma public ? - Closes #2218
by Tony CHEMIT (@tchemit) 27 Oct '22

27 Oct '22
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 9f27b93b by Tony Chemit at 2022-10-27T19:35:37+02:00 tms_version va-t-elle rester dans le schéma public ? - Closes #2218 - - - - - 12 changed files: - core/persistence/test/src/test/java/org/nuiton/topia/persistence/jdbc/JdbcHelperH2Test.java - core/persistence/test/src/test/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperH2Test.java - core/persistence/test/src/test/java/org/nuiton/topia/persistence/security/SecurityScriptHelperTest.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcHelper.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelper.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperH2.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperPostgres.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceContext.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceImpl.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/version/MigrationServiceSqlHelper.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/version/TMSVersion.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/sql/internal/consumer/AddVersionTableConsumer.java Changes: ===================================== core/persistence/test/src/test/java/org/nuiton/topia/persistence/jdbc/JdbcHelperH2Test.java ===================================== @@ -30,6 +30,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.nuiton.topia.service.migration.version.MigrationServiceSqlHelper; import java.sql.SQLException; @@ -54,20 +55,17 @@ public class JdbcHelperH2Test extends PersistenceTestSupportWrite { @Test public void isTableExist() throws SQLException { - boolean actual = jdbcHelper.isTableExist("Public", "Tms_version"); - Assert.assertTrue(actual); + Assert.assertTrue(jdbcHelper.isTableExist(MigrationServiceSqlHelper.CURRENT.schemaName(), MigrationServiceSqlHelper.CURRENT.tableName())); + Assert.assertTrue(jdbcHelper.isTableExist(MigrationServiceSqlHelper.CURRENT.schemaName().toUpperCase(), MigrationServiceSqlHelper.CURRENT.tableName())); + Assert.assertTrue(jdbcHelper.isTableExist(MigrationServiceSqlHelper.CURRENT.schemaName().toUpperCase(), MigrationServiceSqlHelper.CURRENT.tableName().toUpperCase())); - actual = jdbcHelper.isTableExist("PUBLIC", "tms_version-fake"); - Assert.assertFalse(actual); + Assert.assertFalse(jdbcHelper.isTableExist(MigrationServiceSqlHelper.CURRENT.schemaName(), MigrationServiceSqlHelper.CURRENT.tableName()+"-Fake")); } @Test public void isSchemaExist() throws SQLException { - boolean actual = jdbcHelper.isSchemaExist("Public"); - Assert.assertTrue(actual); - - actual = jdbcHelper.isSchemaExist("PUBLIC-fake"); - Assert.assertFalse(actual); + Assert.assertTrue(jdbcHelper.isSchemaExist("Public")); + Assert.assertFalse(jdbcHelper.isSchemaExist("PUBLIC-fake")); } } ===================================== core/persistence/test/src/test/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperH2Test.java ===================================== @@ -31,6 +31,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.nuiton.topia.service.migration.version.MigrationServiceSqlHelper; import java.util.List; import java.util.Set; @@ -62,10 +63,9 @@ public class JdbcSecurityHelperH2Test extends PersistenceTestSupportWrite { Assert.assertNotNull(actual); Assert.assertEquals(0, actual.size()); - actual = securityHelper.getTables(Set.of("PUbLIC"), Set.of()); + actual = securityHelper.getTables(Set.of(MigrationServiceSqlHelper.CURRENT.schemaName()), Set.of()); Assert.assertNotNull(actual); - Assert.assertEquals(1, actual.size()); - Assert.assertEquals(List.of(Pair.of("PUBLIC", "TMS_VERSION")), actual); + Assert.assertTrue(actual.contains(Pair.of(MigrationServiceSqlHelper.CURRENT.schemaName().toUpperCase(), MigrationServiceSqlHelper.CURRENT.tableName().toUpperCase()))); } @Test @@ -90,7 +90,7 @@ public class JdbcSecurityHelperH2Test extends PersistenceTestSupportWrite { @Test public void getTablePrivileges() { - Set<String> actual = securityHelper.getTablePrivileges("PUbLIC", "Tms_VERSION"); + Set<String> actual = securityHelper.getTablePrivileges(MigrationServiceSqlHelper.CURRENT.schemaName(), MigrationServiceSqlHelper.CURRENT.tableName()); Assert.assertNotNull(actual); Assert.assertEquals(0, actual.size()); } ===================================== core/persistence/test/src/test/java/org/nuiton/topia/persistence/security/SecurityScriptHelperTest.java ===================================== @@ -37,6 +37,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.nuiton.topia.persistence.jdbc.JdbcHelper; import org.nuiton.topia.persistence.jdbc.JdbcSecurityHelper; +import org.nuiton.topia.service.migration.version.MigrationServiceSqlHelper; import java.sql.SQLException; import java.util.Map; @@ -92,7 +93,7 @@ public class SecurityScriptHelperTest extends PersistenceTestSupportWrite { SecurityScriptHelper securityScriptHelper = localTestMethodResource.getTopiaApplicationContext().newSecurityScriptHelper(); securityScriptHelper.applySecurity(users); - Set<String> actual = securityHelper.getTablePrivileges("PUBLIC", "TMS_VERSION"); + Set<String> actual = securityHelper.getTablePrivileges(MigrationServiceSqlHelper.CURRENT.schemaName().toUpperCase(), MigrationServiceSqlHelper.CURRENT.tableName().toUpperCase()); Assert.assertNotNull(actual); Assert.assertEquals(4, actual.size()); Assert.assertEquals(Set.of("DELETE", "INSERT", "UPDATE", "SELECT"), actual); ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcHelper.java ===================================== @@ -34,6 +34,8 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.LinkedList; +import java.util.List; import java.util.Objects; /** @@ -116,17 +118,38 @@ public abstract class JdbcHelper { } public String runSelectOnString(String sql) throws SQLException { - return runSelect(sql, resultSet -> resultSet.next() ? resultSet.getString(1) : null); + return runSelect(sql, resultSet -> resultSet.getString(1)); } public <T> T runSelect(String sql, SqlFunction<ResultSet, T> function) throws SQLException { try (Connection connection = openConnection()) { try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { try (ResultSet resultSet = preparedStatement.executeQuery()) { - return function.apply(resultSet); + if (resultSet.next()) { + return function.apply(resultSet); + } + return null; + } + } + } + } + + public <T> List<T> runMultipleSelect(String sql, SqlFunction<ResultSet, T> function) throws SQLException { + List<T> result = new LinkedList<>(); + try (Connection connection = openConnection()) { + try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + try (ResultSet resultSet = preparedStatement.executeQuery()) { + while (resultSet.next()) { + + T row = function.apply(resultSet); + if (row != null) { + result.add(row); + } + } } } } + return result; } public <T> T runOnMetadata(SqlFunction<DatabaseMetaData, T> function) throws SQLException { ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelper.java ===================================== @@ -161,14 +161,14 @@ public interface JdbcSecurityHelper { return getLegacyVersion(); } try { - return MigrationServiceSqlHelper.DEFAULT.getVersion(jdbcHelper()).map(TMSVersion::toVersion).orElse(Version.VZERO); + return MigrationServiceSqlHelper.DEFAULT.getVersion(jdbcHelper()).map(TMSVersion::getVersion).orElse(Version.VZERO); } catch (Exception e) { - // try on legacy + // try on legacy (migration may not been applied) return getLegacyVersion(); } } private Version getLegacyVersion() { - return MigrationServiceSqlHelper.LEGACY.getVersion(jdbcHelper()).map(TMSVersion::toVersion).orElse(Version.VZERO); + return MigrationServiceSqlHelper.LEGACY.getVersion(jdbcHelper()).map(TMSVersion::getVersion).orElse(Version.VZERO); } } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperH2.java ===================================== @@ -31,7 +31,6 @@ import org.nuiton.topia.persistence.security.SecurityScriptHelper; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -162,24 +161,21 @@ public class JdbcSecurityHelperH2 implements JdbcSecurityHelper { Set<String> safeExtraTables = extraTables.stream().map(String::toLowerCase).collect(Collectors.toSet()); try { - return jdbcHelper.runSelect("SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'", resultSet -> { - List<Pair<String, String>> result = new ArrayList<>(); - while (resultSet.next()) { - String schemaName = resultSet.getString(1); - String tableName = resultSet.getString(2); - if (!safeExtraTables.contains(tableName.toLowerCase())) { - // if (POSTGIS_TABLES.contains(tableName)) { - // continue; - // } - if (schemaName == null || !safeSchemas.contains(schemaName.toLowerCase())) { - continue; - } + List<Pair<String, String>> pairs = jdbcHelper.runMultipleSelect("SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'", resultSet -> { + String schemaName = resultSet.getString(1); + String tableName = resultSet.getString(2); + if (!safeExtraTables.contains(tableName.toLowerCase())) { + // if (POSTGIS_TABLES.contains(tableName)) { + // continue; + // } + if (schemaName == null || !safeSchemas.contains(schemaName.toLowerCase())) { + return null; } - result.add(Pair.of(schemaName, tableName)); } - Collections.sort(result); - return result; + return Pair.of(schemaName, tableName); }); + Collections.sort(pairs); + return pairs; } catch (Exception e) { throw new TopiaException(e); } @@ -188,14 +184,8 @@ public class JdbcSecurityHelperH2 implements JdbcSecurityHelper { @Override public Set<String> getRoles() { try { - return jdbcHelper.runSelect("SELECT name FROM INFORMATION_SCHEMA.USERS;", resultSet -> { - Set<String> users = new LinkedHashSet<>(); - while (resultSet.next()) { - String name = resultSet.getString(1); - users.add(name); - } - return users; - }); + List<String> roles = jdbcHelper.runMultipleSelect("SELECT name FROM INFORMATION_SCHEMA.USERS;", resultSet -> resultSet.getString(1)); + return Set.copyOf(roles); } catch (SQLException e) { throw new TopiaException(e); } @@ -204,7 +194,7 @@ public class JdbcSecurityHelperH2 implements JdbcSecurityHelper { @Override public boolean isOwner() { try { - return jdbcHelper.runSelect("SELECT t.* FROM INFORMATION_SCHEMA.SCHEMATA t WHERE SCHEMA_NAME = 'PUBLIC' AND SCHEMA_OWNER = CURRENT_USER", ResultSet::next); + return jdbcHelper.runSelect("SELECT t.* FROM INFORMATION_SCHEMA.SCHEMATA t WHERE SCHEMA_NAME = 'PUBLIC' AND SCHEMA_OWNER = CURRENT_USER", r-> true); } catch (SQLException e) { throw new TopiaException(e); } @@ -213,7 +203,7 @@ public class JdbcSecurityHelperH2 implements JdbcSecurityHelper { @Override public boolean isSuperUser() { try { - return jdbcHelper.runSelect("SELECT admin FROM INFORMATION_SCHEMA.USERS WHERE name = CURRENT_USER", resultSet -> resultSet.next() && resultSet.getBoolean(1)); + return jdbcHelper.runSelect("SELECT admin FROM INFORMATION_SCHEMA.USERS WHERE name = CURRENT_USER", resultSet -> resultSet.getBoolean(1)); } catch (SQLException e) { throw new TopiaException(e); } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperPostgres.java ===================================== @@ -253,7 +253,7 @@ public class JdbcSecurityHelperPostgres implements JdbcSecurityHelper { @Override public boolean isOwner() { try { - return jdbcHelper.runSelect("SELECT pg_catalog.pg_get_userbyid(d.datdba) FROM pg_catalog.pg_database d WHERE d.datname = (SELECT current_database())", resultSet -> resultSet.next() && Objects.equals(jdbcHelper.getJdbcConnectionUser(), resultSet.getString(1))); + return jdbcHelper.runSelect("SELECT pg_catalog.pg_get_userbyid(d.datdba) FROM pg_catalog.pg_database d WHERE d.datname = (SELECT current_database())", resultSet -> Objects.equals(jdbcHelper.getJdbcConnectionUser(), resultSet.getString(1))); } catch (SQLException e) { throw new TopiaException(e); } @@ -262,7 +262,7 @@ public class JdbcSecurityHelperPostgres implements JdbcSecurityHelper { @Override public boolean isSuperUser() { try { - return jdbcHelper.runSelect("SELECT usesuper FROM pg_user WHERE usename = CURRENT_USER", resultSet -> resultSet.next() && resultSet.getBoolean(1)); + return jdbcHelper.runSelect("SELECT usesuper FROM pg_user WHERE usename = CURRENT_USER", resultSet -> resultSet.getBoolean(1)); } catch (SQLException e) { throw new TopiaException(e); } @@ -275,14 +275,8 @@ public class JdbcSecurityHelperPostgres implements JdbcSecurityHelper { " FROM pg_proc p INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)" + " WHERE ns.nspname = 'public' AND p.proname ILIKE '%s%%';", functionPattern); try { - return jdbcHelper.runSelect(sql, resultSet -> { - Set<String> result = new LinkedHashSet<>(); - while (resultSet.next()) { - String functionPrototype = resultSet.getString(1); - result.add(functionPrototype); - } - return result; - }); + List<String> result = jdbcHelper.runMultipleSelect(sql, resultSet -> resultSet.getString(1)); + return Set.copyOf(result); } catch (SQLException e) { throw new TopiaException(e); } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceContext.java ===================================== @@ -38,6 +38,9 @@ import org.nuiton.topia.service.migration.version.TMSVersion; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Date; +import java.util.List; +import java.util.Objects; import java.util.Optional; /** @@ -56,11 +59,10 @@ public class TopiaMigrationServiceContext { * Service configuration. */ protected final TopiaMigrationServiceConfiguration configuration; - protected final MigrationServiceSqlHelper sqlHelper; /** - * Jdbc helper used to perform some sql code. + * Migration sql helper (could be legacy or default). */ - private final JdbcHelper jdbcHelper; + protected final MigrationServiceSqlHelper sqlHelper; /** * Available migration resources found in class-path. */ @@ -74,17 +76,25 @@ public class TopiaMigrationServiceContext { */ protected final boolean dbNotVersioned; /** - * Is legacy TMSVersion table exists? + * Is legacy migration table exists? (only used with default mode) */ protected final boolean legacyVersionTableExist; /** - * Is TMSVersion schema exists? + * Is default migration schema exists? + */ + protected final boolean versionSchemaExist; + /** + * Is default migration table exists? */ - protected boolean versionSchemaExist; + protected final boolean versionTableExist; /** - * Is TMSVersion table exists? + * Can we apply migration versions? */ - protected boolean versionTableExist; + protected final boolean canApplyMigrationVersions; + /** + * Migration versions to apply. + */ + protected final List<Version> versionsToApply; /** * Current database version. */ @@ -114,10 +124,11 @@ public class TopiaMigrationServiceContext { try { versionTableExist = sqlHelper.isTableExist(jdbcHelper); if (versionTableExist) { + log.info("Detected standard migration table {}.", sqlHelper.gav()); versionSchemaExist = true; Optional<TMSVersion> tmsVersion = sqlHelper.getVersion(jdbcHelper); if (tmsVersion.isPresent()) { - v = tmsVersion.get().toVersion(); + v = tmsVersion.get().getVersion(); } if (v == null) { log.warn(String.format("Version not found on table %s", sqlHelper.gav())); @@ -126,9 +137,10 @@ public class TopiaMigrationServiceContext { versionSchemaExist = sqlHelper.isSchemaExist(jdbcHelper); legacyVersionTableExist = legacySqlHelper.isTableExist(jdbcHelper); if (legacyVersionTableExist) { + log.info("Detected legacy migration table {}.", sqlHelper.gav()); Optional<TMSVersion> tmsVersion = legacySqlHelper.getVersion(jdbcHelper); if (tmsVersion.isPresent()) { - v = tmsVersion.get().toVersion(); + v = tmsVersion.get().getVersion(); } if (v == null) { log.warn(String.format("Version not found on legacy table %s", legacySqlHelper.gav())); @@ -137,6 +149,7 @@ public class TopiaMigrationServiceContext { } } finally { if (v == null) { + //FIXME Is this can really happen? // la base dans ce cas n'est pas versionee. // On dit que la version de la base est 0 // et les schema de cette version 0 doivent @@ -151,7 +164,6 @@ public class TopiaMigrationServiceContext { } return new TopiaMigrationServiceContext(configuration, sqlHelper, - jdbcHelper, legacyVersionTableExist, versionSchemaExist, versionTableExist, @@ -175,9 +187,10 @@ public class TopiaMigrationServiceContext { try { versionTableExist = sqlHelper.isTableExist(jdbcHelper); if (versionTableExist) { + log.info("Detected legacy migration table {}.", sqlHelper.gav()); Optional<TMSVersion> tmsVersion = sqlHelper.getVersion(jdbcHelper); if (tmsVersion.isPresent()) { - v = tmsVersion.get().toVersion(); + v = tmsVersion.get().getVersion(); } if (v == null) { log.warn(String.format("Version not found on table %s", sqlHelper.gav())); @@ -199,7 +212,6 @@ public class TopiaMigrationServiceContext { } return new TopiaMigrationServiceContext(configuration, sqlHelper, - jdbcHelper, false, true, versionTableExist, @@ -211,15 +223,14 @@ public class TopiaMigrationServiceContext { protected TopiaMigrationServiceContext(TopiaMigrationServiceConfiguration configuration, MigrationServiceSqlHelper sqlHelper, - JdbcHelper jdbcHelper, - boolean legacyVersionTableExist, boolean versionSchemaExist, + boolean legacyVersionTableExist, + boolean versionSchemaExist, boolean versionTableExist, boolean dbNotVersioned, Version dbVersion, MigrationVersionResourceProvider resources) { this.configuration = configuration; this.sqlHelper = sqlHelper; - this.jdbcHelper = jdbcHelper; this.versionSchemaExist = versionSchemaExist; this.versionTableExist = versionTableExist; this.dbNotVersioned = dbNotVersioned; @@ -231,26 +242,24 @@ public class TopiaMigrationServiceContext { } catch (IOException e) { throw new IllegalStateException("Can't create scripts path", e); } - } - public Path getScriptPath() { - return scriptPath; - } + List<Version> allVersions = getResources().getAvailableVersions(); + log.info(String.format("Detected available versions: %1$s", allVersions)); - public boolean isVersionSchemaExist() { - return versionSchemaExist; - } + versionsToApply = getResources().getVersionsAfter(dbVersion); + log.info(String.format("Detected versions to apply: %1$s", versionsToApply)); - public boolean isVersionTableExist() { - return versionTableExist; - } + Optional<TopiaMigrationServiceAskUserToMigrate> askUserToMigrate = Optional.ofNullable(configuration.getCallback()); - public boolean isLegacyVersionTableExist() { - return legacyVersionTableExist; + // ask to perform the migration + canApplyMigrationVersions = askUserToMigrate.map(c -> c.canIMigrate(getDbVersion(), versionsToApply)).orElse(true); + if (!canApplyMigrationVersions) { + log.warn("Detected that we can not migrate versions (maybe version of database is too old?)."); + } } - public boolean isDbNotVersioned() { - return dbNotVersioned; + public Path getScriptPath() { + return scriptPath; } public Version getModelVersion() { @@ -265,35 +274,65 @@ public class TopiaMigrationServiceContext { return resources; } - public void createSchemaIfNotExist() { + public boolean adaptVersionTable(TopiaSqlSupport sqlSupport) { + + Version modelVersion = getModelVersion(); + boolean dbVersionEqualsModelVersion = Objects.equals(dbVersion, modelVersion); + if (!versionSchemaExist) { - sqlHelper.createSchema(jdbcHelper); - versionSchemaExist = true; + log.info("Create default migration schema."); + sqlHelper.createSchema(sqlSupport); } - } - - public void createTableIfNotExist() { if (!versionTableExist) { - sqlHelper.createTable(jdbcHelper); - versionTableExist = true; + log.info("Create default migration table."); + sqlHelper.createTable(sqlSupport); + } else { + if (dbVersionEqualsModelVersion) { + log.info("Database is up to date, no migration needed."); + return false; + } + } + if (legacyVersionTableExist) { + log.info("Drop legacy migration table."); + MigrationServiceSqlHelper.LEGACY.dropTable(sqlSupport); + if (dbVersionEqualsModelVersion) { + log.info("Database is up to date (version: {}), but was coming from legacy migration table, fill new migration table.", modelVersion); + saveVersion(sqlSupport, modelVersion, null); + return false; + } + log.info("Fill version table {} from legacy table.", dbVersion); + saveVersion(sqlSupport, dbVersion, null); + } else if (dbNotVersioned) { + log.info("Database is empty, no migration needed, set "); + saveVersion(sqlSupport, modelVersion, new Date()); + return false; } + // In all other cases, we can try to perform migration + return true; } - public void saveModelVersion() { - saveVersion(null, getModelVersion()); - } + public List<Version> getVersionsToApply() { - public Optional<TopiaMigrationServiceAskUserToMigrate> getAskUserToMigrate() { - return Optional.ofNullable(configuration.getCallback()); - } + if (versionsToApply.isEmpty()) { + log.info("No version to apply, no migration needed."); + // No migration, so nothing to save +// context.saveModelVersion(); + return null; + } - protected void saveVersion(TopiaSqlSupport sqlSupport, Version version) { - log.info(String.format("[ Version %s ] Saving new database version.", version)); - if (sqlSupport != null) { - sqlHelper.save(sqlSupport, version.getVersion()); - } else { - sqlHelper.save(jdbcHelper, version.getVersion()); + // ask to perform the migration + + if (!canApplyMigrationVersions) { + // user cancel migration + log.warn("Migration was cancelled by migration callback (maybe version of database is too old?)."); + return null; } + return versionsToApply; + } + + protected void saveVersion(TopiaSqlSupport sqlSupport, Version version, Date date) { + log.info(String.format("[ Version %s ] Saving new database version (date: %s).", version, date)); + sqlHelper.save(sqlSupport, version.getVersion(), date); dbVersion = version; } @@ -309,8 +348,4 @@ public class TopiaMigrationServiceContext { return new MigrationVersionResourceExecutor(migrationVersionResource, sqlSupport, configuration.getClassifier(), getScriptPath(), migrationVersionResource.getScriptVariables()); } - public void dropLegacyTable() { - MigrationServiceSqlHelper.LEGACY.dropTable(jdbcHelper); - } - } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceImpl.java ===================================== @@ -34,10 +34,10 @@ import org.nuiton.topia.service.migration.resources.MigrationVersionResource; import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor; import java.io.IOException; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; /** * Topia migration service default implementation. @@ -68,81 +68,38 @@ public class TopiaMigrationServiceImpl implements TopiaMigrationService { @Override public void runSchemaMigration() throws TopiaMigrationServiceException { + log.info("Migration - Prepare internal states."); TopiaMigrationServiceContext context = TopiaMigrationServiceContext.create(configuration); - Version modelVersion = context.getModelVersion(); - Version dbVersion = context.getDbVersion(); - boolean dbNotVersioned = context.isDbNotVersioned(); - boolean legacyVersionTableExist = context.isLegacyVersionTableExist(); - boolean versionSchemaExist = context.isVersionSchemaExist(); - boolean versionTableExist = context.isVersionTableExist(); - - log.info(String.format("Starting Topia Migration Service - Model version : %s, Database version : %s", modelVersion, dbVersion)); - - if (!versionSchemaExist) { - log.info("Create migration schema."); - context.createSchemaIfNotExist(); - } - if (!versionTableExist) { - log.info("Create migration table."); - context.createTableIfNotExist(); - } - if (legacyVersionTableExist) { - log.info("Drop legacy migration table."); - context.dropLegacyTable(); - if (dbVersion.equals(modelVersion)) { - log.info("Database is up to date, but was coming from legacy migration table, fill new migration table."); - context.saveModelVersion(); + log.info("Migration - Prepare internal states done."); + + try (TopiaPersistenceContext persistenceContext = context.newPersistenceContext()) { + log.info("Migration - Adapting migration table."); + boolean canContinue = adaptVersionTable(persistenceContext, context); + log.info("Migration - Adapting migration table done."); + if (!canContinue) { + log.info(String.format("Migration - End - db version: %s (nothing more to do).", context.getDbVersion())); + return; + } + log.info("Migration - Getting migration versions to apply."); + List<Version> versionsToApply = context.getVersionsToApply(); + log.info("Migration - Getting migration versions to apply done."); + if (versionsToApply == null) { + log.info(String.format("Migration - End - db version: %s (nothing more to do).", context.getDbVersion())); return; } - } - - if (versionTableExist && dbVersion.equals(modelVersion)) { - log.info("Database is up to date, no migration needed."); - return; - } - - if (versionTableExist && dbNotVersioned) { - log.info("Database is empty, no migration needed."); - context.saveModelVersion(); - return; - } - - List<Version> allVersions = context.getResources().getAvailableVersions(); - log.info(String.format("Available versions: %1$s", allVersions)); - - List<Version> versionsToApply = context.getResources().getVersionsAfter(dbVersion); - - if (versionsToApply.isEmpty()) { - log.info("No version to apply, no migration needed."); - context.saveModelVersion(); - return; - } - - log.info(String.format("Versions to apply: %1$s", versionsToApply)); - - Optional<TopiaMigrationServiceAskUserToMigrate> askUserToMigrate = context.getAskUserToMigrate(); - - // ask to perform the migration - boolean performMigration = askUserToMigrate.map(c -> c.canIMigrate(dbVersion, versionsToApply)).orElse(true); - - log.debug("Handler choose : " + performMigration); - if (!performMigration) { - // user cancel migration - return; - } + log.info(String.format("Migration - Will apply versions: %1$s.", versionsToApply)); - long statementCount = 0; - try (TopiaPersistenceContext persistenceContext = context.newPersistenceContext()) { + long statementCount = 0; for (Version version : versionsToApply) { long t0 = TimeLog.getTime(); long versionCount = migrateVersion(persistenceContext, version, context); statementCount += versionCount; TIME_LOG.log(t0, "migrationVersion", version.toString() + " - " + versionCount + " sql statements"); } + log.info(String.format("Migration - End - db version: %s - consume %d sql statement(s)", context.getDbVersion(), statementCount)); } - log.info(String.format("Ends migration - db version: %s - consume %d sql statement(s)", context.getDbVersion(), statementCount)); } @Override @@ -150,6 +107,17 @@ public class TopiaMigrationServiceImpl implements TopiaMigrationService { configuration = null; } + protected boolean adaptVersionTable(TopiaPersistenceContext persistenceContext, TopiaMigrationServiceContext context) { + try { + boolean canContinue = context.adaptVersionTable(persistenceContext.getSqlSupport()); + persistenceContext.commit(); + return canContinue; + } catch (Exception e) { + persistenceContext.rollback(); + throw new TopiaMigrationServiceException("Exception during adapting migration table", e); + } + } + protected long migrateVersion(TopiaPersistenceContext persistenceContext, Version version, TopiaMigrationServiceContext context) { MigrationVersionResource resource = context.getResource(version); @@ -174,14 +142,15 @@ public class TopiaMigrationServiceImpl implements TopiaMigrationService { } } // here we use the sqlSupport to save version, to stay on the very same transaction - context.saveVersion(sqlSupport, version); + context.saveVersion(sqlSupport, version, new Date()); + // do commit, this migration version is now completed + persistenceContext.commit(); } catch (Exception e) { // Exception, rollback transaction persistenceContext.rollback(); throw new TopiaMigrationServiceException("Exception during schema migration on version: " + version, e); } - persistenceContext.commit(); return outStatementCount; } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/version/MigrationServiceSqlHelper.java ===================================== @@ -27,6 +27,10 @@ import org.nuiton.topia.persistence.jdbc.JdbcHelper; import org.nuiton.topia.persistence.support.TopiaSqlSupport; import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.Comparator; +import java.util.Date; +import java.util.List; import java.util.Optional; /** @@ -38,12 +42,8 @@ import java.util.Optional; * @since 9.0.7 */ public interface MigrationServiceSqlHelper { - String GET_VERSION_TABLE_STATEMENT = "SELECT version FROM %s;"; - String CREATE_VERSION_SCHEMA_STATEMENT = "CREATE SCHEMA %s;"; - String CREATE_VERSION_TABLE_STATEMENT = "CREATE TABLE %s(version VARCHAR(255) NOT NULL, PRIMARY KEY (version));"; - String DELETE_VERSION_TABLE_STATEMENT = "DELETE FROM %s;"; + String CREATE_VERSION_SCHEMA_STATEMENT = "CREATE SCHEMA IF NOT EXISTS %s;"; String DROP_VERSION_TABLE_STATEMENT = "DROP TABLE %s;"; - String FILL_VERSION_TABLE_STATEMENT = "INSERT INTO %s(version) VALUES('%s');"; /** * Legacy layout. @@ -51,6 +51,10 @@ public interface MigrationServiceSqlHelper { MigrationServiceSqlHelper LEGACY = new MigrationServiceSqlHelper() { public static final String SCHEMA_NAME = "public"; public static final String TABLE_NAME = "tms_version"; + public static final String CREATE_VERSION_TABLE_STATEMENT = "CREATE TABLE %s(version VARCHAR(255) NOT NULL, PRIMARY KEY(version));"; + public static final String FILL_VERSION_TABLE_STATEMENT = "INSERT INTO %s(version) VALUES('%s');"; + public static final String GET_VERSION_TABLE_STATEMENT = "SELECT version FROM %s;"; + public static final String DELETE_VERSION_TABLE_STATEMENT = "DELETE FROM %s;"; @Override public String schemaName() { @@ -61,15 +65,46 @@ public interface MigrationServiceSqlHelper { public String tableName() { return TABLE_NAME; } + + @Override + public String createTableSql() { + return String.format(CREATE_VERSION_TABLE_STATEMENT, gav()); + } + + @Override + public String getVersionSql() { + return String.format(GET_VERSION_TABLE_STATEMENT, gav()); + } + + @Override + public Optional<TMSVersion> getVersion(JdbcHelper jdbcHelper) { + try { + try { + TMSVersion result = jdbcHelper.runSelect(getVersionSql(), r -> new TMSVersion(r.getString(1), null)); + return Optional.ofNullable(result); + } catch (Exception e) { + throw new TopiaException("Could not obtain version", e); + } + } catch (Exception e) { + throw new TopiaException("Could not obtain version", e); + } + } + + @Override + public String saveTableSql(String version, Date date) { + return String.format(DELETE_VERSION_TABLE_STATEMENT, gav()) + String.format(FILL_VERSION_TABLE_STATEMENT, gav(), version); + } }; /** * Default layout. */ MigrationServiceSqlHelper DEFAULT = new MigrationServiceSqlHelper() { - //FIXME Find a better name public static final String SCHEMA_NAME = "common"; //FIXME Find a better name - public static final String TABLE_NAME = "tms_version"; + public static final String TABLE_NAME = "database_version"; + public static final String CREATE_VERSION_TABLE_STATEMENT = "CREATE TABLE %s(version VARCHAR(255) NOT NULL, date TIMESTAMP, PRIMARY KEY(version));"; + public static final String FILL_VERSION_TABLE_STATEMENT = "INSERT INTO %s(version, date) VALUES('%s', %s);"; + public static final String GET_VERSION_TABLE_STATEMENT = "SELECT version, date FROM %s;"; @Override public String schemaName() { @@ -80,6 +115,35 @@ public interface MigrationServiceSqlHelper { public String tableName() { return TABLE_NAME; } + + @Override + public String createTableSql() { + return String.format(CREATE_VERSION_TABLE_STATEMENT, gav()); + } + + @Override + public String getVersionSql() { + return String.format(GET_VERSION_TABLE_STATEMENT, gav()); + } + + @Override + public Optional<TMSVersion> getVersion(JdbcHelper jdbcHelper) { + try { + List<TMSVersion> result = jdbcHelper.runMultipleSelect(getVersionSql(), r -> new TMSVersion(r.getString(1), r.getTimestamp(2))); + if (result.isEmpty()) { + return Optional.empty(); + } + result.sort(Comparator.comparing(TMSVersion::getVersion).reversed()); + return Optional.of(result.get(0)); + } catch (Exception e) { + throw new TopiaException("Could not obtain version", e); + } + } + + @Override + public String saveTableSql(String version, Date date) { + return String.format(FILL_VERSION_TABLE_STATEMENT, gav(), version, date == null ? "NULL" : ("'" + new Timestamp(date.getTime()) + "'::timestamp")); + } }; /** @@ -89,7 +153,7 @@ public interface MigrationServiceSqlHelper { * <p> * We will need even after that to keep the legacy definition, to be able to migration older database using it. */ - MigrationServiceSqlHelper CURRENT = LEGACY; + MigrationServiceSqlHelper CURRENT = DEFAULT; static boolean isLegacy() { return CURRENT.equals(LEGACY); @@ -112,59 +176,22 @@ public interface MigrationServiceSqlHelper { return schemaName() + "." + tableName(); } - default Optional<TMSVersion> getVersion(JdbcHelper jdbcHelper) { - try { - String version = jdbcHelper.runSelectOnString(getVersionSql()); - return Optional.ofNullable(version == null ? null : new TMSVersion(version)); - } catch (Exception e) { - throw new TopiaException("Could not obtain version", e); - } - } - - default String getVersionSql() { - return String.format(GET_VERSION_TABLE_STATEMENT, gav()); - } + Optional<TMSVersion> getVersion(JdbcHelper jdbcHelper); - default String createSchemaSql() { - return String.format(CREATE_VERSION_SCHEMA_STATEMENT, gav()); - } + String getVersionSql(); - default String createTableSql() { - return String.format(CREATE_VERSION_TABLE_STATEMENT, gav()); - } + String createTableSql(); - default String deleteTableSql() { - return String.format(DELETE_VERSION_TABLE_STATEMENT, gav()); - } + String saveTableSql(String version, Date date); - default String fillVersionSql(String version) { - return String.format(FILL_VERSION_TABLE_STATEMENT, gav(), version); + default String createSchemaSql() { + return String.format(CREATE_VERSION_SCHEMA_STATEMENT, schemaName()); } default String dropTableSql() { return String.format(DROP_VERSION_TABLE_STATEMENT, gav()); } - default String saveTableSql(String version) { - return deleteTableSql() + fillVersionSql(version); - } - - default void save(JdbcHelper jdbcHelper, String version) { - try { - jdbcHelper.runUpdate(saveTableSql(version)); - } catch (Exception e) { - throw new TopiaException(String.format("Could not save version %s", version), e); - } - } - - default void save(TopiaSqlSupport sqlSupport, String version) { - try { - sqlSupport.executeSql(saveTableSql(version)); - } catch (Exception e) { - throw new TopiaException(String.format("Could not save version %s", version), e); - } - } - default boolean isTableExist(JdbcHelper jdbcHelper) { try { return jdbcHelper.isTableExist(schemaName(), tableName()); @@ -181,27 +208,35 @@ public interface MigrationServiceSqlHelper { } } - default void createSchema(JdbcHelper jdbcHelper) { + default void createSchema(TopiaSqlSupport sqlSupport) { try { - jdbcHelper.runUpdate(createSchemaSql()); + sqlSupport.executeSql(createSchemaSql()); } catch (Exception e) { - throw new TopiaException(String.format("Could not create version table %s", gav()), e); + throw new TopiaException(String.format("Could not create version schema %s", gav()), e); } } - default void createTable(JdbcHelper jdbcHelper) { + default void createTable(TopiaSqlSupport sqlSupport) { try { - jdbcHelper.runUpdate(createTableSql()); + sqlSupport.executeSql(createTableSql()); } catch (Exception e) { throw new TopiaException(String.format("Could not create version table %s", gav()), e); } } - default void dropTable(JdbcHelper jdbcHelper) { + default void dropTable(TopiaSqlSupport sqlSupport) { try { - jdbcHelper.runUpdate(dropTableSql()); + sqlSupport.executeSql(dropTableSql()); } catch (Exception e) { throw new TopiaException(String.format("Could not drop version table %s", gav()), e); } } + + default void save(TopiaSqlSupport sqlSupport, String version, Date date) { + try { + sqlSupport.executeSql(saveTableSql(version, date)); + } catch (Exception e) { + throw new TopiaException(String.format("Could not save version %s", version), e); + } + } } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/version/TMSVersion.java ===================================== @@ -25,6 +25,7 @@ package org.nuiton.topia.service.migration.version; import io.ultreia.java4all.util.Version; import java.io.Serializable; +import java.util.Date; /** * @author Tony Chemit - dev(a)tchemit.fr @@ -33,27 +34,23 @@ public class TMSVersion implements Serializable { private static final long serialVersionUID = 1L; - private String version; + private final Version version; + private final Date date; - public TMSVersion() { - } - - public TMSVersion(String version) { + public TMSVersion(String version, Date date) { if (version == null || version.isEmpty()) { throw new IllegalArgumentException("version parameter can not be null nor empty."); } - this.version = version; + this.version = Version.valueOf(version); + this.date = date; } - public String getVersion() { + public Version getVersion() { return version; } - public void setVersion(String version) { - this.version = version; + public Date getDate() { + return date; } - public Version toVersion() { - return version == null || version.isEmpty() ? null : Version.valueOf(version); - } } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/sql/internal/consumer/AddVersionTableConsumer.java ===================================== @@ -29,6 +29,8 @@ import org.nuiton.topia.service.sql.internal.SqlRequestConsumer; import org.nuiton.topia.service.sql.internal.SqlRequestSetConsumerContext; import org.nuiton.topia.service.sql.internal.request.AddVersionTableRequest; +import java.util.Date; + /** * Created on 21/02/2021. * @@ -41,8 +43,9 @@ public class AddVersionTableConsumer implements SqlRequestConsumer<AddVersionTab public void consume(AddVersionTableRequest request, SqlRequestSetConsumerContext context) { try { SqlScriptWriter writer = context.getWriter(); + writer.writeSql(MigrationServiceSqlHelper.CURRENT.createSchemaSql()); writer.writeSql(MigrationServiceSqlHelper.CURRENT.createTableSql()); - writer.writeSql(MigrationServiceSqlHelper.CURRENT.fillVersionSql(request.getDbVersion().getVersion())); + writer.writeSql(MigrationServiceSqlHelper.CURRENT.saveTableSql(request.getDbVersion().getVersion(), new Date())); } catch (Exception e) { throw new TopiaException(String.format("Could not add version table for reason: %s", e.getMessage()), e); } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/9f27b93b8b44a72a1405273cc… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/9f27b93b8b44a72a1405273cc… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop] tms_version va-t-elle rester dans le schéma public ? - Closes #2218
by Tony CHEMIT (@tchemit) 27 Oct '22

27 Oct '22
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 68742cce by Tony Chemit at 2022-10-27T14:54:14+02:00 tms_version va-t-elle rester dans le schéma public ? - Closes #2218 - - - - - 12 changed files: - core/persistence/test/src/test/java/org/nuiton/topia/persistence/jdbc/JdbcHelperH2Test.java - core/persistence/test/src/test/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperH2Test.java - core/persistence/test/src/test/java/org/nuiton/topia/persistence/security/SecurityScriptHelperTest.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcHelper.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelper.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperH2.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperPostgres.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceContext.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceImpl.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/version/MigrationServiceSqlHelper.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/version/TMSVersion.java - toolkit/persistence/src/main/java/org/nuiton/topia/service/sql/internal/consumer/AddVersionTableConsumer.java Changes: ===================================== core/persistence/test/src/test/java/org/nuiton/topia/persistence/jdbc/JdbcHelperH2Test.java ===================================== @@ -30,6 +30,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.nuiton.topia.service.migration.version.MigrationServiceSqlHelper; import java.sql.SQLException; @@ -54,20 +55,17 @@ public class JdbcHelperH2Test extends PersistenceTestSupportWrite { @Test public void isTableExist() throws SQLException { - boolean actual = jdbcHelper.isTableExist("Public", "Tms_version"); - Assert.assertTrue(actual); + Assert.assertTrue(jdbcHelper.isTableExist(MigrationServiceSqlHelper.CURRENT.schemaName(), MigrationServiceSqlHelper.CURRENT.tableName())); + Assert.assertTrue(jdbcHelper.isTableExist(MigrationServiceSqlHelper.CURRENT.schemaName().toUpperCase(), MigrationServiceSqlHelper.CURRENT.tableName())); + Assert.assertTrue(jdbcHelper.isTableExist(MigrationServiceSqlHelper.CURRENT.schemaName().toUpperCase(), MigrationServiceSqlHelper.CURRENT.tableName().toUpperCase())); - actual = jdbcHelper.isTableExist("PUBLIC", "tms_version-fake"); - Assert.assertFalse(actual); + Assert.assertFalse(jdbcHelper.isTableExist(MigrationServiceSqlHelper.CURRENT.schemaName(), MigrationServiceSqlHelper.CURRENT.tableName()+"-Fake")); } @Test public void isSchemaExist() throws SQLException { - boolean actual = jdbcHelper.isSchemaExist("Public"); - Assert.assertTrue(actual); - - actual = jdbcHelper.isSchemaExist("PUBLIC-fake"); - Assert.assertFalse(actual); + Assert.assertTrue(jdbcHelper.isSchemaExist("Public")); + Assert.assertFalse(jdbcHelper.isSchemaExist("PUBLIC-fake")); } } ===================================== core/persistence/test/src/test/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperH2Test.java ===================================== @@ -31,6 +31,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.nuiton.topia.service.migration.version.MigrationServiceSqlHelper; import java.util.List; import java.util.Set; @@ -62,10 +63,9 @@ public class JdbcSecurityHelperH2Test extends PersistenceTestSupportWrite { Assert.assertNotNull(actual); Assert.assertEquals(0, actual.size()); - actual = securityHelper.getTables(Set.of("PUbLIC"), Set.of()); + actual = securityHelper.getTables(Set.of(MigrationServiceSqlHelper.CURRENT.schemaName()), Set.of()); Assert.assertNotNull(actual); - Assert.assertEquals(1, actual.size()); - Assert.assertEquals(List.of(Pair.of("PUBLIC", "TMS_VERSION")), actual); + Assert.assertTrue(actual.contains(Pair.of(MigrationServiceSqlHelper.CURRENT.schemaName().toUpperCase(), MigrationServiceSqlHelper.CURRENT.tableName().toUpperCase()))); } @Test @@ -90,7 +90,7 @@ public class JdbcSecurityHelperH2Test extends PersistenceTestSupportWrite { @Test public void getTablePrivileges() { - Set<String> actual = securityHelper.getTablePrivileges("PUbLIC", "Tms_VERSION"); + Set<String> actual = securityHelper.getTablePrivileges(MigrationServiceSqlHelper.CURRENT.schemaName(), MigrationServiceSqlHelper.CURRENT.tableName()); Assert.assertNotNull(actual); Assert.assertEquals(0, actual.size()); } ===================================== core/persistence/test/src/test/java/org/nuiton/topia/persistence/security/SecurityScriptHelperTest.java ===================================== @@ -37,6 +37,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.nuiton.topia.persistence.jdbc.JdbcHelper; import org.nuiton.topia.persistence.jdbc.JdbcSecurityHelper; +import org.nuiton.topia.service.migration.version.MigrationServiceSqlHelper; import java.sql.SQLException; import java.util.Map; @@ -92,7 +93,7 @@ public class SecurityScriptHelperTest extends PersistenceTestSupportWrite { SecurityScriptHelper securityScriptHelper = localTestMethodResource.getTopiaApplicationContext().newSecurityScriptHelper(); securityScriptHelper.applySecurity(users); - Set<String> actual = securityHelper.getTablePrivileges("PUBLIC", "TMS_VERSION"); + Set<String> actual = securityHelper.getTablePrivileges(MigrationServiceSqlHelper.CURRENT.schemaName().toUpperCase(), MigrationServiceSqlHelper.CURRENT.tableName().toUpperCase()); Assert.assertNotNull(actual); Assert.assertEquals(4, actual.size()); Assert.assertEquals(Set.of("DELETE", "INSERT", "UPDATE", "SELECT"), actual); ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcHelper.java ===================================== @@ -34,6 +34,8 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.LinkedList; +import java.util.List; import java.util.Objects; /** @@ -116,17 +118,38 @@ public abstract class JdbcHelper { } public String runSelectOnString(String sql) throws SQLException { - return runSelect(sql, resultSet -> resultSet.next() ? resultSet.getString(1) : null); + return runSelect(sql, resultSet -> resultSet.getString(1)); } public <T> T runSelect(String sql, SqlFunction<ResultSet, T> function) throws SQLException { try (Connection connection = openConnection()) { try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { try (ResultSet resultSet = preparedStatement.executeQuery()) { - return function.apply(resultSet); + if (resultSet.next()) { + return function.apply(resultSet); + } + return null; + } + } + } + } + + public <T> List<T> runMultipleSelect(String sql, SqlFunction<ResultSet, T> function) throws SQLException { + List<T> result = new LinkedList<>(); + try (Connection connection = openConnection()) { + try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + try (ResultSet resultSet = preparedStatement.executeQuery()) { + while (resultSet.next()) { + + T row = function.apply(resultSet); + if (row != null) { + result.add(row); + } + } } } } + return result; } public <T> T runOnMetadata(SqlFunction<DatabaseMetaData, T> function) throws SQLException { ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelper.java ===================================== @@ -161,14 +161,14 @@ public interface JdbcSecurityHelper { return getLegacyVersion(); } try { - return MigrationServiceSqlHelper.DEFAULT.getVersion(jdbcHelper()).map(TMSVersion::toVersion).orElse(Version.VZERO); + return MigrationServiceSqlHelper.DEFAULT.getVersion(jdbcHelper()).map(TMSVersion::getVersion).orElse(Version.VZERO); } catch (Exception e) { - // try on legacy + // try on legacy (migration may not been applied) return getLegacyVersion(); } } private Version getLegacyVersion() { - return MigrationServiceSqlHelper.LEGACY.getVersion(jdbcHelper()).map(TMSVersion::toVersion).orElse(Version.VZERO); + return MigrationServiceSqlHelper.LEGACY.getVersion(jdbcHelper()).map(TMSVersion::getVersion).orElse(Version.VZERO); } } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperH2.java ===================================== @@ -31,7 +31,6 @@ import org.nuiton.topia.persistence.security.SecurityScriptHelper; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -162,24 +161,21 @@ public class JdbcSecurityHelperH2 implements JdbcSecurityHelper { Set<String> safeExtraTables = extraTables.stream().map(String::toLowerCase).collect(Collectors.toSet()); try { - return jdbcHelper.runSelect("SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'", resultSet -> { - List<Pair<String, String>> result = new ArrayList<>(); - while (resultSet.next()) { - String schemaName = resultSet.getString(1); - String tableName = resultSet.getString(2); - if (!safeExtraTables.contains(tableName.toLowerCase())) { - // if (POSTGIS_TABLES.contains(tableName)) { - // continue; - // } - if (schemaName == null || !safeSchemas.contains(schemaName.toLowerCase())) { - continue; - } + List<Pair<String, String>> pairs = jdbcHelper.runMultipleSelect("SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'TABLE'", resultSet -> { + String schemaName = resultSet.getString(1); + String tableName = resultSet.getString(2); + if (!safeExtraTables.contains(tableName.toLowerCase())) { + // if (POSTGIS_TABLES.contains(tableName)) { + // continue; + // } + if (schemaName == null || !safeSchemas.contains(schemaName.toLowerCase())) { + return null; } - result.add(Pair.of(schemaName, tableName)); } - Collections.sort(result); - return result; + return Pair.of(schemaName, tableName); }); + Collections.sort(pairs); + return pairs; } catch (Exception e) { throw new TopiaException(e); } @@ -188,14 +184,8 @@ public class JdbcSecurityHelperH2 implements JdbcSecurityHelper { @Override public Set<String> getRoles() { try { - return jdbcHelper.runSelect("SELECT name FROM INFORMATION_SCHEMA.USERS;", resultSet -> { - Set<String> users = new LinkedHashSet<>(); - while (resultSet.next()) { - String name = resultSet.getString(1); - users.add(name); - } - return users; - }); + List<String> roles = jdbcHelper.runMultipleSelect("SELECT name FROM INFORMATION_SCHEMA.USERS;", resultSet -> resultSet.getString(1)); + return Set.copyOf(roles); } catch (SQLException e) { throw new TopiaException(e); } @@ -204,7 +194,7 @@ public class JdbcSecurityHelperH2 implements JdbcSecurityHelper { @Override public boolean isOwner() { try { - return jdbcHelper.runSelect("SELECT t.* FROM INFORMATION_SCHEMA.SCHEMATA t WHERE SCHEMA_NAME = 'PUBLIC' AND SCHEMA_OWNER = CURRENT_USER", ResultSet::next); + return jdbcHelper.runSelect("SELECT t.* FROM INFORMATION_SCHEMA.SCHEMATA t WHERE SCHEMA_NAME = 'PUBLIC' AND SCHEMA_OWNER = CURRENT_USER", r-> true); } catch (SQLException e) { throw new TopiaException(e); } @@ -213,7 +203,7 @@ public class JdbcSecurityHelperH2 implements JdbcSecurityHelper { @Override public boolean isSuperUser() { try { - return jdbcHelper.runSelect("SELECT admin FROM INFORMATION_SCHEMA.USERS WHERE name = CURRENT_USER", resultSet -> resultSet.next() && resultSet.getBoolean(1)); + return jdbcHelper.runSelect("SELECT admin FROM INFORMATION_SCHEMA.USERS WHERE name = CURRENT_USER", resultSet -> resultSet.getBoolean(1)); } catch (SQLException e) { throw new TopiaException(e); } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/jdbc/JdbcSecurityHelperPostgres.java ===================================== @@ -253,7 +253,7 @@ public class JdbcSecurityHelperPostgres implements JdbcSecurityHelper { @Override public boolean isOwner() { try { - return jdbcHelper.runSelect("SELECT pg_catalog.pg_get_userbyid(d.datdba) FROM pg_catalog.pg_database d WHERE d.datname = (SELECT current_database())", resultSet -> resultSet.next() && Objects.equals(jdbcHelper.getJdbcConnectionUser(), resultSet.getString(1))); + return jdbcHelper.runSelect("SELECT pg_catalog.pg_get_userbyid(d.datdba) FROM pg_catalog.pg_database d WHERE d.datname = (SELECT current_database())", resultSet -> Objects.equals(jdbcHelper.getJdbcConnectionUser(), resultSet.getString(1))); } catch (SQLException e) { throw new TopiaException(e); } @@ -262,7 +262,7 @@ public class JdbcSecurityHelperPostgres implements JdbcSecurityHelper { @Override public boolean isSuperUser() { try { - return jdbcHelper.runSelect("SELECT usesuper FROM pg_user WHERE usename = CURRENT_USER", resultSet -> resultSet.next() && resultSet.getBoolean(1)); + return jdbcHelper.runSelect("SELECT usesuper FROM pg_user WHERE usename = CURRENT_USER", resultSet -> resultSet.getBoolean(1)); } catch (SQLException e) { throw new TopiaException(e); } @@ -275,14 +275,8 @@ public class JdbcSecurityHelperPostgres implements JdbcSecurityHelper { " FROM pg_proc p INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)" + " WHERE ns.nspname = 'public' AND p.proname ILIKE '%s%%';", functionPattern); try { - return jdbcHelper.runSelect(sql, resultSet -> { - Set<String> result = new LinkedHashSet<>(); - while (resultSet.next()) { - String functionPrototype = resultSet.getString(1); - result.add(functionPrototype); - } - return result; - }); + List<String> result = jdbcHelper.runMultipleSelect(sql, resultSet -> resultSet.getString(1)); + return Set.copyOf(result); } catch (SQLException e) { throw new TopiaException(e); } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceContext.java ===================================== @@ -38,6 +38,9 @@ import org.nuiton.topia.service.migration.version.TMSVersion; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Date; +import java.util.List; +import java.util.Objects; import java.util.Optional; /** @@ -56,11 +59,10 @@ public class TopiaMigrationServiceContext { * Service configuration. */ protected final TopiaMigrationServiceConfiguration configuration; - protected final MigrationServiceSqlHelper sqlHelper; /** - * Jdbc helper used to perform some sql code. + * Migration sql helper (could be legacy or default). */ - private final JdbcHelper jdbcHelper; + protected final MigrationServiceSqlHelper sqlHelper; /** * Available migration resources found in class-path. */ @@ -74,17 +76,25 @@ public class TopiaMigrationServiceContext { */ protected final boolean dbNotVersioned; /** - * Is legacy TMSVersion table exists? + * Is legacy migration table exists? (only used with default mode) */ protected final boolean legacyVersionTableExist; /** - * Is TMSVersion schema exists? + * Is default migration schema exists? + */ + protected final boolean versionSchemaExist; + /** + * Is default migration table exists? */ - protected boolean versionSchemaExist; + protected final boolean versionTableExist; /** - * Is TMSVersion table exists? + * Can we apply migration versions? */ - protected boolean versionTableExist; + protected final boolean canApplyMigrationVersions; + /** + * Migration versions to apply. + */ + protected final List<Version> versionsToApply; /** * Current database version. */ @@ -114,10 +124,11 @@ public class TopiaMigrationServiceContext { try { versionTableExist = sqlHelper.isTableExist(jdbcHelper); if (versionTableExist) { + log.info("Detected standard migration table {}.", sqlHelper.gav()); versionSchemaExist = true; Optional<TMSVersion> tmsVersion = sqlHelper.getVersion(jdbcHelper); if (tmsVersion.isPresent()) { - v = tmsVersion.get().toVersion(); + v = tmsVersion.get().getVersion(); } if (v == null) { log.warn(String.format("Version not found on table %s", sqlHelper.gav())); @@ -126,9 +137,10 @@ public class TopiaMigrationServiceContext { versionSchemaExist = sqlHelper.isSchemaExist(jdbcHelper); legacyVersionTableExist = legacySqlHelper.isTableExist(jdbcHelper); if (legacyVersionTableExist) { + log.info("Detected legacy migration table {}.", sqlHelper.gav()); Optional<TMSVersion> tmsVersion = legacySqlHelper.getVersion(jdbcHelper); if (tmsVersion.isPresent()) { - v = tmsVersion.get().toVersion(); + v = tmsVersion.get().getVersion(); } if (v == null) { log.warn(String.format("Version not found on legacy table %s", legacySqlHelper.gav())); @@ -137,6 +149,7 @@ public class TopiaMigrationServiceContext { } } finally { if (v == null) { + //FIXME Is this can really happen? // la base dans ce cas n'est pas versionee. // On dit que la version de la base est 0 // et les schema de cette version 0 doivent @@ -151,7 +164,6 @@ public class TopiaMigrationServiceContext { } return new TopiaMigrationServiceContext(configuration, sqlHelper, - jdbcHelper, legacyVersionTableExist, versionSchemaExist, versionTableExist, @@ -175,9 +187,10 @@ public class TopiaMigrationServiceContext { try { versionTableExist = sqlHelper.isTableExist(jdbcHelper); if (versionTableExist) { + log.info("Detected legacy migration table {}.", sqlHelper.gav()); Optional<TMSVersion> tmsVersion = sqlHelper.getVersion(jdbcHelper); if (tmsVersion.isPresent()) { - v = tmsVersion.get().toVersion(); + v = tmsVersion.get().getVersion(); } if (v == null) { log.warn(String.format("Version not found on table %s", sqlHelper.gav())); @@ -199,7 +212,6 @@ public class TopiaMigrationServiceContext { } return new TopiaMigrationServiceContext(configuration, sqlHelper, - jdbcHelper, false, true, versionTableExist, @@ -211,15 +223,14 @@ public class TopiaMigrationServiceContext { protected TopiaMigrationServiceContext(TopiaMigrationServiceConfiguration configuration, MigrationServiceSqlHelper sqlHelper, - JdbcHelper jdbcHelper, - boolean legacyVersionTableExist, boolean versionSchemaExist, + boolean legacyVersionTableExist, + boolean versionSchemaExist, boolean versionTableExist, boolean dbNotVersioned, Version dbVersion, MigrationVersionResourceProvider resources) { this.configuration = configuration; this.sqlHelper = sqlHelper; - this.jdbcHelper = jdbcHelper; this.versionSchemaExist = versionSchemaExist; this.versionTableExist = versionTableExist; this.dbNotVersioned = dbNotVersioned; @@ -231,26 +242,24 @@ public class TopiaMigrationServiceContext { } catch (IOException e) { throw new IllegalStateException("Can't create scripts path", e); } - } - public Path getScriptPath() { - return scriptPath; - } + List<Version> allVersions = getResources().getAvailableVersions(); + log.info(String.format("Detected available versions: %1$s", allVersions)); - public boolean isVersionSchemaExist() { - return versionSchemaExist; - } + versionsToApply = getResources().getVersionsAfter(dbVersion); + log.info(String.format("Detected versions to apply: %1$s", versionsToApply)); - public boolean isVersionTableExist() { - return versionTableExist; - } + Optional<TopiaMigrationServiceAskUserToMigrate> askUserToMigrate = Optional.ofNullable(configuration.getCallback()); - public boolean isLegacyVersionTableExist() { - return legacyVersionTableExist; + // ask to perform the migration + canApplyMigrationVersions = askUserToMigrate.map(c -> c.canIMigrate(getDbVersion(), versionsToApply)).orElse(true); + if (!canApplyMigrationVersions) { + log.warn("Detected that we can not migrate versions (maybe version of database is too old?)."); + } } - public boolean isDbNotVersioned() { - return dbNotVersioned; + public Path getScriptPath() { + return scriptPath; } public Version getModelVersion() { @@ -265,35 +274,65 @@ public class TopiaMigrationServiceContext { return resources; } - public void createSchemaIfNotExist() { + public boolean adaptVersionTable(TopiaSqlSupport sqlSupport) { + + Version modelVersion = getModelVersion(); + boolean dbVersionEqualsModelVersion = Objects.equals(dbVersion, modelVersion); + if (!versionSchemaExist) { - sqlHelper.createSchema(jdbcHelper); - versionSchemaExist = true; + log.info("Create default migration schema."); + sqlHelper.createSchema(sqlSupport); } - } - - public void createTableIfNotExist() { if (!versionTableExist) { - sqlHelper.createTable(jdbcHelper); - versionTableExist = true; + log.info("Create default migration table."); + sqlHelper.createTable(sqlSupport); + } else { + if (dbVersionEqualsModelVersion) { + log.info("Database is up to date, no migration needed."); + return false; + } + } + if (legacyVersionTableExist) { + log.info("Drop legacy migration table."); + MigrationServiceSqlHelper.LEGACY.dropTable(sqlSupport); + if (dbVersionEqualsModelVersion) { + log.info("Database is up to date (version: {}), but was coming from legacy migration table, fill new migration table.", modelVersion); + saveVersion(sqlSupport, modelVersion, null); + return false; + } + log.info("Fill version table {} from legacy table.", dbVersion); + saveVersion(sqlSupport, dbVersion, null); + } else if (dbNotVersioned) { + log.info("Database is empty, no migration needed, set "); + saveVersion(sqlSupport, modelVersion, new Date()); + return false; } + // In all other cases, we can try to perform migration + return true; } - public void saveModelVersion() { - saveVersion(null, getModelVersion()); - } + public List<Version> getVersionsToApply() { - public Optional<TopiaMigrationServiceAskUserToMigrate> getAskUserToMigrate() { - return Optional.ofNullable(configuration.getCallback()); - } + if (versionsToApply.isEmpty()) { + log.info("No version to apply, no migration needed."); + // No migration, so nothing to save +// context.saveModelVersion(); + return null; + } - protected void saveVersion(TopiaSqlSupport sqlSupport, Version version) { - log.info(String.format("[ Version %s ] Saving new database version.", version)); - if (sqlSupport != null) { - sqlHelper.save(sqlSupport, version.getVersion()); - } else { - sqlHelper.save(jdbcHelper, version.getVersion()); + // ask to perform the migration + + if (!canApplyMigrationVersions) { + // user cancel migration + log.warn("Migration was cancelled by migration callback (maybe version of database is too old?)."); + return null; } + return versionsToApply; + } + + protected void saveVersion(TopiaSqlSupport sqlSupport, Version version, Date date) { + log.info(String.format("[ Version %s ] Saving new database version (date: %s).", version, date)); + sqlHelper.save(sqlSupport, version.getVersion(), date); dbVersion = version; } @@ -309,8 +348,4 @@ public class TopiaMigrationServiceContext { return new MigrationVersionResourceExecutor(migrationVersionResource, sqlSupport, configuration.getClassifier(), getScriptPath(), migrationVersionResource.getScriptVariables()); } - public void dropLegacyTable() { - MigrationServiceSqlHelper.LEGACY.dropTable(jdbcHelper); - } - } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/TopiaMigrationServiceImpl.java ===================================== @@ -34,10 +34,10 @@ import org.nuiton.topia.service.migration.resources.MigrationVersionResource; import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor; import java.io.IOException; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; /** * Topia migration service default implementation. @@ -68,81 +68,38 @@ public class TopiaMigrationServiceImpl implements TopiaMigrationService { @Override public void runSchemaMigration() throws TopiaMigrationServiceException { + log.info("Migration - Prepare internal states."); TopiaMigrationServiceContext context = TopiaMigrationServiceContext.create(configuration); - Version modelVersion = context.getModelVersion(); - Version dbVersion = context.getDbVersion(); - boolean dbNotVersioned = context.isDbNotVersioned(); - boolean legacyVersionTableExist = context.isLegacyVersionTableExist(); - boolean versionSchemaExist = context.isVersionSchemaExist(); - boolean versionTableExist = context.isVersionTableExist(); - - log.info(String.format("Starting Topia Migration Service - Model version : %s, Database version : %s", modelVersion, dbVersion)); - - if (!versionSchemaExist) { - log.info("Create migration schema."); - context.createSchemaIfNotExist(); - } - if (!versionTableExist) { - log.info("Create migration table."); - context.createTableIfNotExist(); - } - if (legacyVersionTableExist) { - log.info("Drop legacy migration table."); - context.dropLegacyTable(); - if (dbVersion.equals(modelVersion)) { - log.info("Database is up to date, but was coming from legacy migration table, fill new migration table."); - context.saveModelVersion(); + log.info("Migration - Prepare internal states done."); + + try (TopiaPersistenceContext persistenceContext = context.newPersistenceContext()) { + log.info("Migration - Adapting migration table."); + boolean canContinue = adaptVersionTable(persistenceContext, context); + log.info("Migration - Adapting migration table done."); + if (!canContinue) { + log.info(String.format("Migration - End - db version: %s (nothing more to do).", context.getDbVersion())); + return; + } + log.info("Migration - Getting migration versions to apply."); + List<Version> versionsToApply = context.getVersionsToApply(); + log.info("Migration - Getting migration versions to apply done."); + if (versionsToApply == null) { + log.info(String.format("Migration - End - db version: %s (nothing more to do).", context.getDbVersion())); return; } - } - - if (versionTableExist && dbVersion.equals(modelVersion)) { - log.info("Database is up to date, no migration needed."); - return; - } - - if (versionTableExist && dbNotVersioned) { - log.info("Database is empty, no migration needed."); - context.saveModelVersion(); - return; - } - - List<Version> allVersions = context.getResources().getAvailableVersions(); - log.info(String.format("Available versions: %1$s", allVersions)); - - List<Version> versionsToApply = context.getResources().getVersionsAfter(dbVersion); - - if (versionsToApply.isEmpty()) { - log.info("No version to apply, no migration needed."); - context.saveModelVersion(); - return; - } - - log.info(String.format("Versions to apply: %1$s", versionsToApply)); - - Optional<TopiaMigrationServiceAskUserToMigrate> askUserToMigrate = context.getAskUserToMigrate(); - - // ask to perform the migration - boolean performMigration = askUserToMigrate.map(c -> c.canIMigrate(dbVersion, versionsToApply)).orElse(true); - - log.debug("Handler choose : " + performMigration); - if (!performMigration) { - // user cancel migration - return; - } + log.info(String.format("Migration - Will apply versions: %1$s.", versionsToApply)); - long statementCount = 0; - try (TopiaPersistenceContext persistenceContext = context.newPersistenceContext()) { + long statementCount = 0; for (Version version : versionsToApply) { long t0 = TimeLog.getTime(); long versionCount = migrateVersion(persistenceContext, version, context); statementCount += versionCount; TIME_LOG.log(t0, "migrationVersion", version.toString() + " - " + versionCount + " sql statements"); } + log.info(String.format("Migration - End - db version: %s - consume %d sql statement(s)", context.getDbVersion(), statementCount)); } - log.info(String.format("Ends migration - db version: %s - consume %d sql statement(s)", context.getDbVersion(), statementCount)); } @Override @@ -150,6 +107,17 @@ public class TopiaMigrationServiceImpl implements TopiaMigrationService { configuration = null; } + protected boolean adaptVersionTable(TopiaPersistenceContext persistenceContext, TopiaMigrationServiceContext context) { + try { + boolean canContinue = context.adaptVersionTable(persistenceContext.getSqlSupport()); + persistenceContext.commit(); + return canContinue; + } catch (Exception e) { + persistenceContext.rollback(); + throw new TopiaMigrationServiceException("Exception during adapting migration table", e); + } + } + protected long migrateVersion(TopiaPersistenceContext persistenceContext, Version version, TopiaMigrationServiceContext context) { MigrationVersionResource resource = context.getResource(version); @@ -174,14 +142,15 @@ public class TopiaMigrationServiceImpl implements TopiaMigrationService { } } // here we use the sqlSupport to save version, to stay on the very same transaction - context.saveVersion(sqlSupport, version); + context.saveVersion(sqlSupport, version, new Date()); + // do commit, this migration version is now completed + persistenceContext.commit(); } catch (Exception e) { // Exception, rollback transaction persistenceContext.rollback(); throw new TopiaMigrationServiceException("Exception during schema migration on version: " + version, e); } - persistenceContext.commit(); return outStatementCount; } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/version/MigrationServiceSqlHelper.java ===================================== @@ -27,6 +27,10 @@ import org.nuiton.topia.persistence.jdbc.JdbcHelper; import org.nuiton.topia.persistence.support.TopiaSqlSupport; import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.Comparator; +import java.util.Date; +import java.util.List; import java.util.Optional; /** @@ -38,12 +42,8 @@ import java.util.Optional; * @since 9.0.7 */ public interface MigrationServiceSqlHelper { - String GET_VERSION_TABLE_STATEMENT = "SELECT version FROM %s;"; String CREATE_VERSION_SCHEMA_STATEMENT = "CREATE SCHEMA %s;"; - String CREATE_VERSION_TABLE_STATEMENT = "CREATE TABLE %s(version VARCHAR(255) NOT NULL, PRIMARY KEY (version));"; - String DELETE_VERSION_TABLE_STATEMENT = "DELETE FROM %s;"; String DROP_VERSION_TABLE_STATEMENT = "DROP TABLE %s;"; - String FILL_VERSION_TABLE_STATEMENT = "INSERT INTO %s(version) VALUES('%s');"; /** * Legacy layout. @@ -51,6 +51,10 @@ public interface MigrationServiceSqlHelper { MigrationServiceSqlHelper LEGACY = new MigrationServiceSqlHelper() { public static final String SCHEMA_NAME = "public"; public static final String TABLE_NAME = "tms_version"; + public static final String CREATE_VERSION_TABLE_STATEMENT = "CREATE TABLE %s(version VARCHAR(255) NOT NULL, PRIMARY KEY(version));"; + public static final String FILL_VERSION_TABLE_STATEMENT = "INSERT INTO %s(version) VALUES('%s');"; + public static final String GET_VERSION_TABLE_STATEMENT = "SELECT version FROM %s;"; + public static final String DELETE_VERSION_TABLE_STATEMENT = "DELETE FROM %s;"; @Override public String schemaName() { @@ -61,15 +65,46 @@ public interface MigrationServiceSqlHelper { public String tableName() { return TABLE_NAME; } + + @Override + public String createTableSql() { + return String.format(CREATE_VERSION_TABLE_STATEMENT, gav()); + } + + @Override + public String getVersionSql() { + return String.format(GET_VERSION_TABLE_STATEMENT, gav()); + } + + @Override + public Optional<TMSVersion> getVersion(JdbcHelper jdbcHelper) { + try { + try { + TMSVersion result = jdbcHelper.runSelect(getVersionSql(), r -> new TMSVersion(r.getString(1), null)); + return Optional.ofNullable(result); + } catch (Exception e) { + throw new TopiaException("Could not obtain version", e); + } + } catch (Exception e) { + throw new TopiaException("Could not obtain version", e); + } + } + + @Override + public String saveTableSql(String version, Date date) { + return String.format(DELETE_VERSION_TABLE_STATEMENT, gav()) + String.format(FILL_VERSION_TABLE_STATEMENT, gav(), version); + } }; /** * Default layout. */ MigrationServiceSqlHelper DEFAULT = new MigrationServiceSqlHelper() { - //FIXME Find a better name public static final String SCHEMA_NAME = "common"; //FIXME Find a better name - public static final String TABLE_NAME = "tms_version"; + public static final String TABLE_NAME = "database_version"; + public static final String CREATE_VERSION_TABLE_STATEMENT = "CREATE TABLE %s(version VARCHAR(255) NOT NULL, date TIMESTAMP, PRIMARY KEY(version));"; + public static final String FILL_VERSION_TABLE_STATEMENT = "INSERT INTO %s(version, date) VALUES('%s', %s);"; + public static final String GET_VERSION_TABLE_STATEMENT = "SELECT version, date FROM %s;"; @Override public String schemaName() { @@ -80,6 +115,35 @@ public interface MigrationServiceSqlHelper { public String tableName() { return TABLE_NAME; } + + @Override + public String createTableSql() { + return String.format(CREATE_VERSION_TABLE_STATEMENT, gav()); + } + + @Override + public String getVersionSql() { + return String.format(GET_VERSION_TABLE_STATEMENT, gav()); + } + + @Override + public Optional<TMSVersion> getVersion(JdbcHelper jdbcHelper) { + try { + List<TMSVersion> result = jdbcHelper.runMultipleSelect(getVersionSql(), r -> new TMSVersion(r.getString(1), r.getTimestamp(2))); + if (result.isEmpty()) { + return Optional.empty(); + } + result.sort(Comparator.comparing(TMSVersion::getVersion).reversed()); + return Optional.of(result.get(0)); + } catch (Exception e) { + throw new TopiaException("Could not obtain version", e); + } + } + + @Override + public String saveTableSql(String version, Date date) { + return String.format(FILL_VERSION_TABLE_STATEMENT, gav(), version, date == null ? "NULL" : ("'" + new Timestamp(date.getTime()) + "'::timestamp")); + } }; /** @@ -89,7 +153,7 @@ public interface MigrationServiceSqlHelper { * <p> * We will need even after that to keep the legacy definition, to be able to migration older database using it. */ - MigrationServiceSqlHelper CURRENT = LEGACY; + MigrationServiceSqlHelper CURRENT = DEFAULT; static boolean isLegacy() { return CURRENT.equals(LEGACY); @@ -112,59 +176,22 @@ public interface MigrationServiceSqlHelper { return schemaName() + "." + tableName(); } - default Optional<TMSVersion> getVersion(JdbcHelper jdbcHelper) { - try { - String version = jdbcHelper.runSelectOnString(getVersionSql()); - return Optional.ofNullable(version == null ? null : new TMSVersion(version)); - } catch (Exception e) { - throw new TopiaException("Could not obtain version", e); - } - } - - default String getVersionSql() { - return String.format(GET_VERSION_TABLE_STATEMENT, gav()); - } + Optional<TMSVersion> getVersion(JdbcHelper jdbcHelper); - default String createSchemaSql() { - return String.format(CREATE_VERSION_SCHEMA_STATEMENT, gav()); - } + String getVersionSql(); - default String createTableSql() { - return String.format(CREATE_VERSION_TABLE_STATEMENT, gav()); - } + String createTableSql(); - default String deleteTableSql() { - return String.format(DELETE_VERSION_TABLE_STATEMENT, gav()); - } + String saveTableSql(String version, Date date); - default String fillVersionSql(String version) { - return String.format(FILL_VERSION_TABLE_STATEMENT, gav(), version); + default String createSchemaSql() { + return String.format(CREATE_VERSION_SCHEMA_STATEMENT, gav()); } default String dropTableSql() { return String.format(DROP_VERSION_TABLE_STATEMENT, gav()); } - default String saveTableSql(String version) { - return deleteTableSql() + fillVersionSql(version); - } - - default void save(JdbcHelper jdbcHelper, String version) { - try { - jdbcHelper.runUpdate(saveTableSql(version)); - } catch (Exception e) { - throw new TopiaException(String.format("Could not save version %s", version), e); - } - } - - default void save(TopiaSqlSupport sqlSupport, String version) { - try { - sqlSupport.executeSql(saveTableSql(version)); - } catch (Exception e) { - throw new TopiaException(String.format("Could not save version %s", version), e); - } - } - default boolean isTableExist(JdbcHelper jdbcHelper) { try { return jdbcHelper.isTableExist(schemaName(), tableName()); @@ -181,27 +208,35 @@ public interface MigrationServiceSqlHelper { } } - default void createSchema(JdbcHelper jdbcHelper) { + default void createSchema(TopiaSqlSupport sqlSupport) { try { - jdbcHelper.runUpdate(createSchemaSql()); + sqlSupport.executeSql(createSchemaSql()); } catch (Exception e) { - throw new TopiaException(String.format("Could not create version table %s", gav()), e); + throw new TopiaException(String.format("Could not create version schema %s", gav()), e); } } - default void createTable(JdbcHelper jdbcHelper) { + default void createTable(TopiaSqlSupport sqlSupport) { try { - jdbcHelper.runUpdate(createTableSql()); + sqlSupport.executeSql(createTableSql()); } catch (Exception e) { throw new TopiaException(String.format("Could not create version table %s", gav()), e); } } - default void dropTable(JdbcHelper jdbcHelper) { + default void dropTable(TopiaSqlSupport sqlSupport) { try { - jdbcHelper.runUpdate(dropTableSql()); + sqlSupport.executeSql(dropTableSql()); } catch (Exception e) { throw new TopiaException(String.format("Could not drop version table %s", gav()), e); } } + + default void save(TopiaSqlSupport sqlSupport, String version, Date date) { + try { + sqlSupport.executeSql(saveTableSql(version, date)); + } catch (Exception e) { + throw new TopiaException(String.format("Could not save version %s", version), e); + } + } } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/migration/version/TMSVersion.java ===================================== @@ -25,6 +25,7 @@ package org.nuiton.topia.service.migration.version; import io.ultreia.java4all.util.Version; import java.io.Serializable; +import java.util.Date; /** * @author Tony Chemit - dev(a)tchemit.fr @@ -33,27 +34,23 @@ public class TMSVersion implements Serializable { private static final long serialVersionUID = 1L; - private String version; + private final Version version; + private final Date date; - public TMSVersion() { - } - - public TMSVersion(String version) { + public TMSVersion(String version, Date date) { if (version == null || version.isEmpty()) { throw new IllegalArgumentException("version parameter can not be null nor empty."); } - this.version = version; + this.version = Version.valueOf(version); + this.date = date; } - public String getVersion() { + public Version getVersion() { return version; } - public void setVersion(String version) { - this.version = version; + public Date getDate() { + return date; } - public Version toVersion() { - return version == null || version.isEmpty() ? null : Version.valueOf(version); - } } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/service/sql/internal/consumer/AddVersionTableConsumer.java ===================================== @@ -29,6 +29,8 @@ import org.nuiton.topia.service.sql.internal.SqlRequestConsumer; import org.nuiton.topia.service.sql.internal.SqlRequestSetConsumerContext; import org.nuiton.topia.service.sql.internal.request.AddVersionTableRequest; +import java.util.Date; + /** * Created on 21/02/2021. * @@ -42,7 +44,7 @@ public class AddVersionTableConsumer implements SqlRequestConsumer<AddVersionTab try { SqlScriptWriter writer = context.getWriter(); writer.writeSql(MigrationServiceSqlHelper.CURRENT.createTableSql()); - writer.writeSql(MigrationServiceSqlHelper.CURRENT.fillVersionSql(request.getDbVersion().getVersion())); + writer.writeSql(MigrationServiceSqlHelper.CURRENT.saveTableSql(request.getDbVersion().getVersion(), new Date())); } catch (Exception e) { throw new TopiaException(String.format("Could not add version table for reason: %s", e.getMessage()), e); } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/68742cce33a8d9674a1750656… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/68742cce33a8d9674a1750656… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop] Sur l'UI de gestion des listes d'affichage d'espèces, un contrôle récalcitrant...
by Tony CHEMIT (@tchemit) 25 Oct '22

25 Oct '22
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: d4d57c0f by Tony Chemit at 2022-10-25T21:24:30+02:00 Sur l&#39;UI de gestion des listes d&#39;affichage d&#39;espèces, un contrôle récalcitrant sur espèces désactivées - Closes #2496 - - - - - 6 changed files: - core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-dataResult.json - core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-referentialResult.json - toolkit/api/src/main/i18n/translations/toolkit_en_GB.properties - toolkit/api/src/main/i18n/translations/toolkit_es_ES.properties - toolkit/api/src/main/i18n/translations/toolkit_fr_FR.properties - toolkit/api/src/main/java/fr/ird/observe/spi/validation/validators/referential/IdDtoReferentialDisabledFieldValidationSupport.java Changes: ===================================== core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-dataResult.json ===================================== @@ -39495,7 +39495,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 2) est désactivé." } ] }, @@ -39569,7 +39569,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39602,7 +39602,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39635,7 +39635,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39668,7 +39668,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39701,7 +39701,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39734,7 +39734,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39899,7 +39899,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39932,7 +39932,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40419,7 +40419,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40452,7 +40452,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40683,7 +40683,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40716,7 +40716,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40782,7 +40782,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40815,7 +40815,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40914,7 +40914,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." }, { "fieldName": "observedSystemDistance", @@ -40985,7 +40985,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41018,7 +41018,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41084,7 +41084,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41117,7 +41117,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41150,7 +41150,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41216,7 +41216,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41249,7 +41249,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41282,7 +41282,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41315,7 +41315,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41348,7 +41348,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41381,7 +41381,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41447,7 +41447,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41480,7 +41480,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41513,7 +41513,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41546,7 +41546,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41612,7 +41612,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41645,7 +41645,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41678,7 +41678,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41711,7 +41711,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41744,7 +41744,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41777,7 +41777,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41810,7 +41810,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41843,7 +41843,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41876,7 +41876,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41909,7 +41909,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41942,7 +41942,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41975,7 +41975,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42041,7 +42041,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42074,7 +42074,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42107,7 +42107,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42140,7 +42140,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42173,7 +42173,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42206,7 +42206,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42239,7 +42239,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42305,7 +42305,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 2) est désactivé." } ] }, @@ -42338,7 +42338,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 2) est désactivé." } ] }, @@ -42503,7 +42503,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42536,7 +42536,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42569,7 +42569,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42602,7 +42602,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42635,7 +42635,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42668,7 +42668,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42701,7 +42701,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42866,7 +42866,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42899,7 +42899,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, ===================================== core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-referentialResult.json ===================================== @@ -60596,7 +60596,17 @@ { "fieldName": "species", "scope": "ERROR", - "message": "L\u0027un des référentiels de type \u0027Espèce\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «LKY - Lepidochelys kempii - Tortue de Kemp» (à la position 120) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «SPY - Sphyrnidae - Famille Sphyrnidae» (à la position 24) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «1BUM - Makaira mazara - Makaire bleu indo-pacifique » (à la position 191) est désactivé." } ] }, @@ -60763,7 +60773,7 @@ { "fieldName": "species", "scope": "ERROR", - "message": "L\u0027un des référentiels de type \u0027Espèce\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «RAV* - Ravil - Ravil» (à la position 12) est désactivé." } ] }, @@ -60795,7 +60805,22 @@ { "fieldName": "species", "scope": "ERROR", - "message": "L\u0027un des référentiels de type \u0027Espèce\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «1BUM - Makaira mazara - Makaire bleu indo-pacifique » (à la position 208) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «LKY - Lepidochelys kempii - Tortue de Kemp» (à la position 120) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «SPY - Sphyrnidae - Famille Sphyrnidae» (à la position 24) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «RAV* - Ravil - Ravil» (à la position 193) est désactivé." } ] }, ===================================== toolkit/api/src/main/i18n/translations/toolkit_en_GB.properties ===================================== @@ -60,7 +60,7 @@ observe.Common.validation.comment.needed.for.single=A comment is required for se observe.Common.validation.endDate.after.startDate=End date (%2$s) must be after start date (%1$s). observe.Common.validation.field.mandatory=Mandatory field. observe.Common.validation.field.not.filled=Field not filled. -observe.Common.validation.multiple.referential.disabled=On of the selected referential of type '%s' is disabled. +observe.Common.validation.multiple.referential.disabled=Selected referential «%1$s» (at position\: %2$s) is disabled. observe.Common.validation.number.bound=Value must be between %s and %s, but was %s. observe.Common.validation.number.positive=Number must be positive. observe.Common.validation.proportion.total=Sum of proportions must equals 100. ===================================== toolkit/api/src/main/i18n/translations/toolkit_es_ES.properties ===================================== @@ -60,7 +60,7 @@ observe.Common.validation.comment.needed.for.single=Se requiere un comentario pa observe.Common.validation.endDate.after.startDate=End date (%2$s) must be after start date (%1$s). \#TODO observe.Common.validation.field.mandatory=Campo obligatorio. observe.Common.validation.field.not.filled=Campo no registrado. -observe.Common.validation.multiple.referential.disabled=Uno de los referenciales de tipo seleccionados '%s' está desactivado. +observe.Common.validation.multiple.referential.disabled=El referencial seleccionados «%1$s» (position\: %2$s) está desactivado. observe.Common.validation.number.bound=El valor debe estar entre %s y %s, pero es %s. observe.Common.validation.number.positive=El número debe ser positivo. observe.Common.validation.proportion.total=La suma de las proporciónes debe ser de 100. ===================================== toolkit/api/src/main/i18n/translations/toolkit_fr_FR.properties ===================================== @@ -60,7 +60,7 @@ observe.Common.validation.comment.needed.for.single=Un commentaire est requis po observe.Common.validation.endDate.after.startDate=La date de fin (%2$s) doit être ultérieure à celle de début (%1$s). observe.Common.validation.field.mandatory=Le champ est obligatoire. observe.Common.validation.field.not.filled=Le champ n'est pas renseigné. -observe.Common.validation.multiple.referential.disabled=L'un des référentiels de type '%s' sélectionné est désactivé.. +observe.Common.validation.multiple.referential.disabled=Le référentiel sélectionné «%1$s» (à la position %2$s) est désactivé. observe.Common.validation.number.bound=La valeur doit être comprise entre %s et %s, mais vaut %s. observe.Common.validation.number.positive=Le nombre doit être positif. observe.Common.validation.proportion.total=La somme des proportions doit valoir 100. ===================================== toolkit/api/src/main/java/fr/ird/observe/spi/validation/validators/referential/IdDtoReferentialDisabledFieldValidationSupport.java ===================================== @@ -24,6 +24,7 @@ package fr.ird.observe.spi.validation.validators.referential; import com.opensymphony.xwork2.validator.ValidationException; import fr.ird.observe.dto.reference.ReferentialDtoReference; +import fr.ird.observe.spi.decoration.DecoratorService; import fr.ird.observe.spi.decoration.I18nDecoratorHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -46,8 +47,11 @@ public abstract class IdDtoReferentialDisabledFieldValidationSupport extends Nui private final NuitonValidatorScope scope; private String referenceType; + private String referenceValue; private String message; + private int referencePosition; + IdDtoReferentialDisabledFieldValidationSupport(NuitonValidatorScope scope) { this.scope = scope; super.setSkip("configuration.validationDisabledReferentialScope != \"" + Objects.requireNonNull(scope).name() + "\""); @@ -67,11 +71,16 @@ public abstract class IdDtoReferentialDisabledFieldValidationSupport extends Nui } if (fieldValue instanceof Collection) { if (message == null) { - super.setDefaultMessage(message = n("observe.Common.validation.multiple.referential.disabled") + "##${referenceType}"); - + super.setDefaultMessage(message = n("observe.Common.validation.multiple.referential.disabled") + "##${referenceValue}##${referencePosition}"); } - for (Object o : (Collection<?>) fieldValue) { - validateOne(object, fieldName, o); + referencePosition = 1; + try { + for (Object o : (Collection<?>) fieldValue) { + validateOne(object, fieldName, o); + referencePosition++; + } + } finally { + referencePosition = 0; } } else { if (message == null) { @@ -89,17 +98,37 @@ public abstract class IdDtoReferentialDisabledFieldValidationSupport extends Nui if (referentialDtoReference.isEnabled()) { return; } - if (referenceType == null) { - referenceType = I18nDecoratorHelper.getType(referentialDtoReference.getReferenceType()); + if (referencePosition > 0) { + if (referentialDtoReference.decorator().isEmpty()) { + DecoratorService decoratorService = (DecoratorService) stack.findValue("decoratorService"); + decoratorService.installDecorator(referentialDtoReference); + } + referenceValue = referentialDtoReference.toString(); + } else { + if (referenceType == null) { + referenceType = I18nDecoratorHelper.getType(referentialDtoReference.getReferenceType()); + } + } + try { + log.debug(String.format("[%s] Found a referential (%s) disabled.", scope, referenceValue)); + addFieldError(fieldName, object); + } finally { + referenceValue = null; } - log.debug(String.format("[%s] Found a referential (%s) disabled.", scope, referentialDtoReference)); - addFieldError(fieldName, object); } public String getReferenceType() { return referenceType; } + public String getReferenceValue() { + return referenceValue; + } + + public int getReferencePosition() { + return referencePosition; + } + @Override public String getValidatorType() { return "idDtoReferentialDisabledFieldValidation"; View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/d4d57c0f467f7c5918db54dbf… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/d4d57c0f467f7c5918db54dbf… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop-9.0.x] Sur l'UI de gestion des listes d'affichage d'espèces, un contrôle récalcitrant...
by Tony CHEMIT (@tchemit) 25 Oct '22

25 Oct '22
Tony CHEMIT pushed to branch develop-9.0.x at ultreiaio / ird-observe Commits: d7c8956f by Tony Chemit at 2022-10-25T21:24:49+02:00 Sur l&#39;UI de gestion des listes d&#39;affichage d&#39;espèces, un contrôle récalcitrant sur espèces désactivées - Closes #2496 - - - - - 6 changed files: - core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-dataResult.json - core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-referentialResult.json - toolkit/api/src/main/i18n/translations/toolkit_en_GB.properties - toolkit/api/src/main/i18n/translations/toolkit_es_ES.properties - toolkit/api/src/main/i18n/translations/toolkit_fr_FR.properties - toolkit/api/src/main/java/fr/ird/observe/spi/validation/validators/referential/IdDtoReferentialDisabledFieldValidationSupport.java Changes: ===================================== core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-dataResult.json ===================================== @@ -39495,7 +39495,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 2) est désactivé." } ] }, @@ -39569,7 +39569,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39602,7 +39602,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39635,7 +39635,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39668,7 +39668,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39701,7 +39701,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39734,7 +39734,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39899,7 +39899,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -39932,7 +39932,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40419,7 +40419,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40452,7 +40452,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40683,7 +40683,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40716,7 +40716,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40782,7 +40782,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40815,7 +40815,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -40914,7 +40914,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." }, { "fieldName": "observedSystemDistance", @@ -40985,7 +40985,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41018,7 +41018,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41084,7 +41084,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41117,7 +41117,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41150,7 +41150,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41216,7 +41216,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41249,7 +41249,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41282,7 +41282,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41315,7 +41315,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41348,7 +41348,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41381,7 +41381,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41447,7 +41447,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41480,7 +41480,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41513,7 +41513,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41546,7 +41546,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41612,7 +41612,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41645,7 +41645,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41678,7 +41678,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41711,7 +41711,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41744,7 +41744,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41777,7 +41777,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41810,7 +41810,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41843,7 +41843,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41876,7 +41876,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41909,7 +41909,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41942,7 +41942,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -41975,7 +41975,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42041,7 +42041,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42074,7 +42074,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42107,7 +42107,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42140,7 +42140,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42173,7 +42173,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42206,7 +42206,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42239,7 +42239,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42305,7 +42305,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 2) est désactivé." } ] }, @@ -42338,7 +42338,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 2) est désactivé." } ] }, @@ -42503,7 +42503,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42536,7 +42536,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42569,7 +42569,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42602,7 +42602,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42635,7 +42635,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42668,7 +42668,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42701,7 +42701,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42866,7 +42866,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, @@ -42899,7 +42899,7 @@ { "fieldName": "observedSystem", "scope": "WARNING", - "message": "L\u0027un des référentiels de type \u0027Système observé\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «6 - Epave balisée» (à la position 1) est désactivé." } ] }, ===================================== core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-referentialResult.json ===================================== @@ -60596,7 +60596,17 @@ { "fieldName": "species", "scope": "ERROR", - "message": "L\u0027un des référentiels de type \u0027Espèce\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «LKY - Lepidochelys kempii - Tortue de Kemp» (à la position 120) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «SPY - Sphyrnidae - Famille Sphyrnidae» (à la position 24) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «1BUM - Makaira mazara - Makaire bleu indo-pacifique » (à la position 191) est désactivé." } ] }, @@ -60763,7 +60773,7 @@ { "fieldName": "species", "scope": "ERROR", - "message": "L\u0027un des référentiels de type \u0027Espèce\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «RAV* - Ravil - Ravil» (à la position 12) est désactivé." } ] }, @@ -60795,7 +60805,22 @@ { "fieldName": "species", "scope": "ERROR", - "message": "L\u0027un des référentiels de type \u0027Espèce\u0027 sélectionné est désactivé." + "message": "Le référentiel sélectionné «1BUM - Makaira mazara - Makaire bleu indo-pacifique » (à la position 208) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «LKY - Lepidochelys kempii - Tortue de Kemp» (à la position 120) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «SPY - Sphyrnidae - Famille Sphyrnidae» (à la position 24) est désactivé." + }, + { + "fieldName": "species", + "scope": "ERROR", + "message": "Le référentiel sélectionné «RAV* - Ravil - Ravil» (à la position 193) est désactivé." } ] }, ===================================== toolkit/api/src/main/i18n/translations/toolkit_en_GB.properties ===================================== @@ -60,7 +60,7 @@ observe.Common.validation.comment.needed.for.single=A comment is required for se observe.Common.validation.endDate.after.startDate=End date (%2$s) must be after start date (%1$s). observe.Common.validation.field.mandatory=Mandatory field. observe.Common.validation.field.not.filled=Field not filled. -observe.Common.validation.multiple.referential.disabled=On of the selected referential of type '%s' is disabled. +observe.Common.validation.multiple.referential.disabled=Selected referential «%1$s» (at position\: %2$s) is disabled. observe.Common.validation.number.bound=Value must be between %s and %s, but was %s. observe.Common.validation.number.positive=Number must be positive. observe.Common.validation.proportion.total=Sum of proportions must equals 100. ===================================== toolkit/api/src/main/i18n/translations/toolkit_es_ES.properties ===================================== @@ -60,7 +60,7 @@ observe.Common.validation.comment.needed.for.single=Se requiere un comentario pa observe.Common.validation.endDate.after.startDate=End date (%2$s) must be after start date (%1$s). \#TODO observe.Common.validation.field.mandatory=Campo obligatorio. observe.Common.validation.field.not.filled=Campo no registrado. -observe.Common.validation.multiple.referential.disabled=Uno de los referenciales de tipo seleccionados '%s' está desactivado. +observe.Common.validation.multiple.referential.disabled=El referencial seleccionados «%1$s» (position\: %2$s) está desactivado. observe.Common.validation.number.bound=El valor debe estar entre %s y %s, pero es %s. observe.Common.validation.number.positive=El número debe ser positivo. observe.Common.validation.proportion.total=La suma de las proporciónes debe ser de 100. ===================================== toolkit/api/src/main/i18n/translations/toolkit_fr_FR.properties ===================================== @@ -60,7 +60,7 @@ observe.Common.validation.comment.needed.for.single=Un commentaire est requis po observe.Common.validation.endDate.after.startDate=La date de fin (%2$s) doit être ultérieure à celle de début (%1$s). observe.Common.validation.field.mandatory=Le champ est obligatoire. observe.Common.validation.field.not.filled=Le champ n'est pas renseigné. -observe.Common.validation.multiple.referential.disabled=L'un des référentiels de type '%s' sélectionné est désactivé.. +observe.Common.validation.multiple.referential.disabled=Le référentiel sélectionné «%1$s» (à la position %2$s) est désactivé. observe.Common.validation.number.bound=La valeur doit être comprise entre %s et %s, mais vaut %s. observe.Common.validation.number.positive=Le nombre doit être positif. observe.Common.validation.proportion.total=La somme des proportions doit valoir 100. ===================================== toolkit/api/src/main/java/fr/ird/observe/spi/validation/validators/referential/IdDtoReferentialDisabledFieldValidationSupport.java ===================================== @@ -24,6 +24,7 @@ package fr.ird.observe.spi.validation.validators.referential; import com.opensymphony.xwork2.validator.ValidationException; import fr.ird.observe.dto.reference.ReferentialDtoReference; +import fr.ird.observe.spi.decoration.DecoratorService; import fr.ird.observe.spi.decoration.I18nDecoratorHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -46,8 +47,11 @@ public abstract class IdDtoReferentialDisabledFieldValidationSupport extends Nui private final NuitonValidatorScope scope; private String referenceType; + private String referenceValue; private String message; + private int referencePosition; + IdDtoReferentialDisabledFieldValidationSupport(NuitonValidatorScope scope) { this.scope = scope; super.setSkip("configuration.validationDisabledReferentialScope != \"" + Objects.requireNonNull(scope).name() + "\""); @@ -67,11 +71,16 @@ public abstract class IdDtoReferentialDisabledFieldValidationSupport extends Nui } if (fieldValue instanceof Collection) { if (message == null) { - super.setDefaultMessage(message = n("observe.Common.validation.multiple.referential.disabled") + "##${referenceType}"); - + super.setDefaultMessage(message = n("observe.Common.validation.multiple.referential.disabled") + "##${referenceValue}##${referencePosition}"); } - for (Object o : (Collection<?>) fieldValue) { - validateOne(object, fieldName, o); + referencePosition = 1; + try { + for (Object o : (Collection<?>) fieldValue) { + validateOne(object, fieldName, o); + referencePosition++; + } + } finally { + referencePosition = 0; } } else { if (message == null) { @@ -89,17 +98,37 @@ public abstract class IdDtoReferentialDisabledFieldValidationSupport extends Nui if (referentialDtoReference.isEnabled()) { return; } - if (referenceType == null) { - referenceType = I18nDecoratorHelper.getType(referentialDtoReference.getReferenceType()); + if (referencePosition > 0) { + if (referentialDtoReference.decorator().isEmpty()) { + DecoratorService decoratorService = (DecoratorService) stack.findValue("decoratorService"); + decoratorService.installDecorator(referentialDtoReference); + } + referenceValue = referentialDtoReference.toString(); + } else { + if (referenceType == null) { + referenceType = I18nDecoratorHelper.getType(referentialDtoReference.getReferenceType()); + } + } + try { + log.debug(String.format("[%s] Found a referential (%s) disabled.", scope, referenceValue)); + addFieldError(fieldName, object); + } finally { + referenceValue = null; } - log.debug(String.format("[%s] Found a referential (%s) disabled.", scope, referentialDtoReference)); - addFieldError(fieldName, object); } public String getReferenceType() { return referenceType; } + public String getReferenceValue() { + return referenceValue; + } + + public int getReferencePosition() { + return referencePosition; + } + @Override public String getValidatorType() { return "idDtoReferentialDisabledFieldValidation"; View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/d7c8956fe444adbe5b8c9335f… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/d7c8956fe444adbe5b8c9335f… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop] 3 commits: Add ps_logbook Well new model (fix persistence migration (using IdFactoryBulk...
by Tony CHEMIT (@tchemit) 25 Oct '22

25 Oct '22
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: d329bdb7 by Tony Chemit at 2022-10-25T14:33:48+02:00 Add ps_logbook Well new model (fix persistence migration (using IdFactoryBulk again) and rename drop scripts) - - - - - 04a707fe by Tony Chemit at 2022-10-25T18:46:05+02:00 Ajout une contrainte de non nullité sur PS_OBS_Catch.speciesFate - Closes #2492 - - - - - 60aabbe9 by Tony Chemit at 2022-10-25T18:46:05+02:00 Le schooltype devrait être obligatoire en cas d&#39;activité PS logbook de type 6 - Pêche - Update public API Doc (See #2484) - - - - - 18 changed files: - core/persistence/java/src/main/resources/META-INF/persistence/Observe/TopiaEntitySqlUsageModel.json - core/persistence/java/src/main/resources/fr/ird/observe/entities/data/ps/observation/CatchImpl.hbm.xml - core/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_1.java - core/persistence/resources/src/main/resources/db/migration/v9/9.1/03_drop-table-wellPlan-H2.sql → core/persistence/resources/src/main/resources/db/migration/v9/9.1/02_drop-table-wellPlan-H2.sql - core/persistence/resources/src/main/resources/db/migration/v9/9.1/03_drop-table-wellPlan-PG.sql → core/persistence/resources/src/main/resources/db/migration/v9/9.1/02_drop-table-wellPlan-PG.sql - + core/persistence/resources/src/main/resources/db/migration/v9/9.1/03_adapt-table-ps_observation_catch_speciesFate_notnull-H2.sql - + core/persistence/resources/src/main/resources/db/migration/v9/9.1/03_adapt-table-ps_observation_catch_speciesFate_notnull-PG.sql - core/persistence/resources/src/main/resources/db/migration/v9/9.1/empty-schema-H2.sql - core/persistence/resources/src/main/resources/db/migration/v9/9.1/empty-schema-PG.sql - model/src/main/models/Observe/persistence/attribute/notNull.properties - server/runner/src/main/webResources/doc/api/public/data/ps/logbook/Activity/validation-create-error.xml - server/runner/src/main/webResources/doc/api/public/data/ps/logbook/Activity/validation-create.json - server/runner/src/main/webResources/doc/api/public/data/ps/logbook/Activity/validation-update-error.xml - server/runner/src/main/webResources/doc/api/public/data/ps/logbook/Activity/validation-update.json - server/runner/src/main/webResources/doc/api/public/data/ps/observation/Catch/validation-create-error.xml - server/runner/src/main/webResources/doc/api/public/data/ps/observation/Catch/validation-create.json - server/runner/src/main/webResources/doc/api/public/data/ps/observation/Catch/validation-update-error.xml - server/runner/src/main/webResources/doc/api/public/data/ps/observation/Catch/validation-update.json Changes: ===================================== core/persistence/java/src/main/resources/META-INF/persistence/Observe/TopiaEntitySqlUsageModel.json ===================================== @@ -846,10 +846,10 @@ }, "fr.ird.observe.entities.referential.ps.common.SpeciesFate": { "reverseCompositions": [ - "fr.ird.observe.entities.data.ps.observation.Catch~speciesFate", "fr.ird.observe.entities.data.ps.observation.SampleMeasure~speciesFate" ], "reverseMandatoryCompositions": [ + "fr.ird.observe.entities.data.ps.observation.Catch~speciesFate", "fr.ird.observe.entities.data.ps.logbook.Catch~speciesFate" ] }, ===================================== core/persistence/java/src/main/resources/fr/ird/observe/entities/data/ps/observation/CatchImpl.hbm.xml ===================================== @@ -72,7 +72,7 @@ <many-to-one name="species" class="fr.ird.observe.entities.referential.common.SpeciesImpl" column="species" foreign-key="fk_ps_observation_catch_species" not-null="true" /> <many-to-one name="weightMeasureMethod" class="fr.ird.observe.entities.referential.common.WeightMeasureMethodImpl" column="weightMeasureMethod" foreign-key="fk_ps_observation_catch_weightmeasuremethod" /> <many-to-one name="lengthMeasureMethod" class="fr.ird.observe.entities.referential.common.LengthMeasureMethodImpl" column="lengthMeasureMethod" foreign-key="fk_ps_observation_catch_lengthmeasuremethod" /> - <many-to-one name="speciesFate" class="fr.ird.observe.entities.referential.ps.common.SpeciesFateImpl" column="speciesFate" foreign-key="fk_ps_observation_catch_speciesfate" /> + <many-to-one name="speciesFate" class="fr.ird.observe.entities.referential.ps.common.SpeciesFateImpl" column="speciesFate" foreign-key="fk_ps_observation_catch_speciesfate" not-null="true" /> </class> <query name="fr.ird.observe.entities.data.ps.observation.Catch::id::all" read-only="true"><![CDATA[ select new fr.ird.observe.dto.ToolkitIdBean(id, lastUpdateDate) ===================================== core/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_1.java ===================================== @@ -23,15 +23,17 @@ package fr.ird.observe.spi.migration.v9; */ import com.google.auto.service.AutoService; -import fr.ird.observe.entities.ObserveIdFactory; import fr.ird.observe.spi.migration.ByMajorMigrationVersionResource; import io.ultreia.java4all.util.Version; import io.ultreia.java4all.util.sql.SqlQuery; import org.nuiton.topia.persistence.TopiaIdFactory; +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport; import org.nuiton.topia.service.migration.resources.MigrationVersionResource; import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor; import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.Date; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -84,7 +86,7 @@ public class DataSourceMigrationForVersion_9_1 extends ByMajorMigrationVersionRe public DataSourceMigrationForVersion_9_1() { super(Version.valueOf("9.1"), true); ByMajorMigrationVersionResource.createResourceScriptVariables(this, "2022-09-14", "2022-09-14 00:00:00.000000"); - idFactory = new ObserveIdFactory(); + idFactory = new TopiaIdFactoryForBulkSupport(LocalDateTime.of(2022, 9, 14,0,0).toInstant(ZoneOffset.UTC).toEpochMilli()); } static class WellPlanStructure { @@ -264,7 +266,10 @@ public class DataSourceMigrationForVersion_9_1 extends ByMajorMigrationVersionRe flushWell(executor, wellStructure); } } - executor.addScript("03", "drop-table-wellPlan"); + executor.addScript("02", "drop-table-wellPlan"); + + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2492 + executor.addScript("03", "adapt-table-ps_observation_catch_speciesFate_notnull"); } private Map<String, List<WellPlanStructure>> splitByTrip(List<WellPlanStructure> existingWellPlan) { ===================================== core/persistence/resources/src/main/resources/db/migration/v9/9.1/03_drop-table-wellPlan-H2.sql → core/persistence/resources/src/main/resources/db/migration/v9/9.1/02_drop-table-wellPlan-H2.sql ===================================== ===================================== core/persistence/resources/src/main/resources/db/migration/v9/9.1/03_drop-table-wellPlan-PG.sql → core/persistence/resources/src/main/resources/db/migration/v9/9.1/02_drop-table-wellPlan-PG.sql ===================================== ===================================== core/persistence/resources/src/main/resources/db/migration/v9/9.1/03_adapt-table-ps_observation_catch_speciesFate_notnull-H2.sql ===================================== @@ -0,0 +1,24 @@ +--- +-- #%L +-- ObServe Core :: Persistence :: Resources +-- %% +-- Copyright (C) 2008 - 2022 IRD, 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% +--- +UPDATE ps_observation.Catch SET speciesFate = 'fr.ird.referential.ps.common.SpeciesFate#1239832683621#0.9099804284263154', comment = 'Devenir passé de null à ''Autres'' par la migration 9.1' WHERE speciesFate IS NULL AND comment IS NULL; +UPDATE ps_observation.Catch SET speciesFate = 'fr.ird.referential.ps.common.SpeciesFate#1239832683621#0.9099804284263154', comment = CONCAT(comment, STRINGDECODE('\nDevenir passé de null à ''Autres'' par la migration 9.1')) WHERE speciesFate IS NULL; +ALTER TABLE ps_observation.Catch ALTER COLUMN speciesFate SET NOT NULL; ===================================== core/persistence/resources/src/main/resources/db/migration/v9/9.1/03_adapt-table-ps_observation_catch_speciesFate_notnull-PG.sql ===================================== @@ -0,0 +1,24 @@ +--- +-- #%L +-- ObServe Core :: Persistence :: Resources +-- %% +-- Copyright (C) 2008 - 2022 IRD, 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% +--- +UPDATE ps_observation.Catch SET speciesFate = 'fr.ird.referential.ps.common.SpeciesFate#1239832683621#0.9099804284263154', comment = 'Devenir passé de null à ''Autres'' par la migration 9.1' WHERE speciesFate IS NULL AND comment IS NULL; +UPDATE ps_observation.Catch SET speciesFate = 'fr.ird.referential.ps.common.SpeciesFate#1239832683621#0.9099804284263154', comment = CONCAT(comment, E'\nDevenir passé de null à ''Autres'' par la migration 9.1') WHERE speciesFate IS NULL; +ALTER TABLE ps_observation.Catch ALTER COLUMN speciesFate SET NOT NULL; ===================================== core/persistence/resources/src/main/resources/db/migration/v9/9.1/empty-schema-H2.sql ===================================== @@ -180,7 +180,7 @@ create table ps_logbook.wellSamplingConformity (topiaId varchar(255) not null, t create table ps_logbook.wellSamplingStatus (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, code varchar(255) not null, uri varchar(255), homeId varchar(255), needComment boolean default false not null, status integer not null, label1 varchar(255) not null, label2 varchar(255) not null, label3 varchar(255) not null, label4 varchar(255), label5 varchar(255), label6 varchar(255), label7 varchar(255), label8 varchar(255), primary key (topiaId)); create table ps_observation.activity (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), comment varchar(8192), time time not null, latitude numeric, longitude numeric, vesselSpeed numeric, seaSurfaceTemperature numeric, observedSystemDistance numeric, ersId varchar(255), vesselActivity varchar(255) not null, surroundingActivity varchar(255), wind varchar(255), detectionMode varchar(255), reasonForNoFishing varchar(255), currentFpaZone varchar(255), previousFpaZone varchar(255), nextFpaZone varchar(255), dataQuality varchar(255), route varchar(255) not null, primary key (topiaId)); create table ps_observation.activity_observedSystem (activity varchar(255) not null, observedSystem varchar(255) not null, primary key (activity, observedSystem)); -create table ps_observation.catch (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), comment varchar(8192), catchWeight numeric, catchWeightComputedSource integer, meanWeight numeric, meanWeightComputedSource integer, meanLength numeric, meanLengthComputedSource integer, totalCount integer, totalCountComputedSource integer, well varchar(255), reasonForDiscard varchar(255), informationSource varchar(255) not null, species varchar(255) not null, weightMeasureMethod varchar(255), lengthMeasureMethod varchar(255), speciesFate varchar(255), set varchar(255) not null, set_idx integer, primary key (topiaId)); +create table ps_observation.catch (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), comment varchar(8192), catchWeight numeric, catchWeightComputedSource integer, meanWeight numeric, meanWeightComputedSource integer, meanLength numeric, meanLengthComputedSource integer, totalCount integer, totalCountComputedSource integer, well varchar(255), reasonForDiscard varchar(255), informationSource varchar(255) not null, species varchar(255) not null, weightMeasureMethod varchar(255), lengthMeasureMethod varchar(255), speciesFate varchar(255) not null, set varchar(255) not null, set_idx integer, primary key (topiaId)); create table ps_observation.detectionMode (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, code varchar(255) not null, uri varchar(255), homeId varchar(255), needComment boolean default false not null, status integer not null, label1 varchar(255) not null, label2 varchar(255) not null, label3 varchar(255) not null, label4 varchar(255), label5 varchar(255), label6 varchar(255), label7 varchar(255), label8 varchar(255), primary key (topiaId)); create table ps_observation.floatingObject (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), comment varchar(8192), objectOperation varchar(255), supportVesselName varchar(32), computedWhenArrivingBiodegradable varchar(255), computedWhenArrivingNonEntangling varchar(255), computedWhenArrivingSimplifiedObjectType varchar(255), computedWhenLeavingBiodegradable varchar(255), computedWhenLeavingNonEntangling varchar(255), computedWhenLeavingSimplifiedObjectType varchar(255), activity varchar(255) not null, primary key (topiaId)); create table ps_observation.floatingObjectPart (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), whenArriving varchar(255), whenLeaving varchar(255), objectMaterial varchar(255) not null, floatingObject varchar(255) not null, primary key (topiaId)); ===================================== core/persistence/resources/src/main/resources/db/migration/v9/9.1/empty-schema-PG.sql ===================================== @@ -180,7 +180,7 @@ create table ps_logbook.wellSamplingConformity (topiaId varchar(255) not null, t create table ps_logbook.wellSamplingStatus (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, code varchar(255) not null, uri varchar(255), homeId varchar(255), needComment boolean default false not null, status integer not null, label1 varchar(255) not null, label2 varchar(255) not null, label3 varchar(255) not null, label4 varchar(255), label5 varchar(255), label6 varchar(255), label7 varchar(255), label8 varchar(255), primary key (topiaId)); create table ps_observation.activity (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), comment varchar(8192), time time not null, latitude numeric, longitude numeric, vesselSpeed numeric, seaSurfaceTemperature numeric, observedSystemDistance numeric, ersId varchar(255), vesselActivity varchar(255) not null, surroundingActivity varchar(255), wind varchar(255), detectionMode varchar(255), reasonForNoFishing varchar(255), currentFpaZone varchar(255), previousFpaZone varchar(255), nextFpaZone varchar(255), dataQuality varchar(255), route varchar(255) not null, primary key (topiaId)); create table ps_observation.activity_observedSystem (activity varchar(255) not null, observedSystem varchar(255) not null, primary key (activity, observedSystem)); -create table ps_observation.catch (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), comment varchar(8192), catchWeight numeric, catchWeightComputedSource integer, meanWeight numeric, meanWeightComputedSource integer, meanLength numeric, meanLengthComputedSource integer, totalCount integer, totalCountComputedSource integer, well varchar(255), reasonForDiscard varchar(255), informationSource varchar(255) not null, species varchar(255) not null, weightMeasureMethod varchar(255), lengthMeasureMethod varchar(255), speciesFate varchar(255), set varchar(255) not null, set_idx integer, primary key (topiaId)); +create table ps_observation.catch (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), comment varchar(8192), catchWeight numeric, catchWeightComputedSource integer, meanWeight numeric, meanWeightComputedSource integer, meanLength numeric, meanLengthComputedSource integer, totalCount integer, totalCountComputedSource integer, well varchar(255), reasonForDiscard varchar(255), informationSource varchar(255) not null, species varchar(255) not null, weightMeasureMethod varchar(255), lengthMeasureMethod varchar(255), speciesFate varchar(255) not null, set varchar(255) not null, set_idx integer, primary key (topiaId)); create table ps_observation.detectionMode (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, code varchar(255) not null, uri varchar(255), homeId varchar(255), needComment boolean default false not null, status integer not null, label1 varchar(255) not null, label2 varchar(255) not null, label3 varchar(255) not null, label4 varchar(255), label5 varchar(255), label6 varchar(255), label7 varchar(255), label8 varchar(255), primary key (topiaId)); create table ps_observation.floatingObject (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), comment varchar(8192), objectOperation varchar(255), supportVesselName varchar(32), computedWhenArrivingBiodegradable varchar(255), computedWhenArrivingNonEntangling varchar(255), computedWhenArrivingSimplifiedObjectType varchar(255), computedWhenLeavingBiodegradable varchar(255), computedWhenLeavingNonEntangling varchar(255), computedWhenLeavingSimplifiedObjectType varchar(255), activity varchar(255) not null, primary key (topiaId)); create table ps_observation.floatingObjectPart (topiaId varchar(255) not null, topiaVersion bigint not null, topiaCreateDate timestamp not null, lastUpdateDate timestamp default CURRENT_TIMESTAMP not null, homeId varchar(255), whenArriving varchar(255), whenLeaving varchar(255), objectMaterial varchar(255) not null, floatingObject varchar(255) not null, primary key (topiaId)); ===================================== model/src/main/models/Observe/persistence/attribute/notNull.properties ===================================== @@ -169,6 +169,7 @@ data.ps.observation.Activity.attribute.time=true data.ps.observation.Activity.attribute.vesselActivity=true data.ps.observation.Catch.attribute.informationSource=true data.ps.observation.Catch.attribute.species=true +data.ps.observation.Catch.attribute.speciesFate=true data.ps.observation.FloatingObjectPart.attribute.objectMaterial=true data.ps.observation.NonTargetCatchRelease.attribute.count=true data.ps.observation.NonTargetCatchRelease.attribute.sex=true ===================================== server/runner/src/main/webResources/doc/api/public/data/ps/logbook/Activity/validation-create-error.xml ===================================== @@ -231,6 +231,12 @@ </field> <field name="schoolType"> + <!-- schoolType is mandatory except if !setEnabled --> + <field-validator type="mandatory" short-circuit="true"> + <param name="skip"><![CDATA[ !setEnabled ]]></param> + <message>observe.data.ps.logbook.Activity.schoolType.validation.required</message> + </field-validator> + <!-- check if referential schoolType is disabled (only if validation is strong) --> <field-validator type="checkDisabledReferentialOnErrorScope"> <message/> ===================================== server/runner/src/main/webResources/doc/api/public/data/ps/logbook/Activity/validation-create.json ===================================== @@ -122,7 +122,8 @@ }, "schoolType": { "errors": [ - "check if referential schoolType is disabled (only if validation is strong)" + "check if referential schoolType is disabled (only if validation is strong)", + "schoolType is mandatory except if !setEnabled" ], "warnings": [ "check if referential schoolType is disabled (only if validation is not strong)" ===================================== server/runner/src/main/webResources/doc/api/public/data/ps/logbook/Activity/validation-update-error.xml ===================================== @@ -231,6 +231,12 @@ </field> <field name="schoolType"> + <!-- schoolType is mandatory except if !setEnabled --> + <field-validator type="mandatory" short-circuit="true"> + <param name="skip"><![CDATA[ !setEnabled ]]></param> + <message>observe.data.ps.logbook.Activity.schoolType.validation.required</message> + </field-validator> + <!-- check if referential schoolType is disabled (only if validation is strong) --> <field-validator type="checkDisabledReferentialOnErrorScope"> <message/> ===================================== server/runner/src/main/webResources/doc/api/public/data/ps/logbook/Activity/validation-update.json ===================================== @@ -122,7 +122,8 @@ }, "schoolType": { "errors": [ - "check if referential schoolType is disabled (only if validation is strong)" + "check if referential schoolType is disabled (only if validation is strong)", + "schoolType is mandatory except if !setEnabled" ], "warnings": [ "check if referential schoolType is disabled (only if validation is not strong)" ===================================== server/runner/src/main/webResources/doc/api/public/data/ps/observation/Catch/validation-create-error.xml ===================================== @@ -118,6 +118,11 @@ </field> <field name="speciesFate"> + <!-- speciesFate is mandatory --> + <field-validator type="mandatory" short-circuit="true"> + <message/> + </field-validator> + <!-- check if referential speciesFate is disabled (only if validation is strong) --> <field-validator type="checkDisabledReferentialOnErrorScope"> <message/> ===================================== server/runner/src/main/webResources/doc/api/public/data/ps/observation/Catch/validation-create.json ===================================== @@ -68,7 +68,8 @@ }, "speciesFate": { "errors": [ - "check if referential speciesFate is disabled (only if validation is strong)" + "check if referential speciesFate is disabled (only if validation is strong)", + "speciesFate is mandatory" ], "warnings": [ "check if referential speciesFate is disabled (only if validation is not strong)" ===================================== server/runner/src/main/webResources/doc/api/public/data/ps/observation/Catch/validation-update-error.xml ===================================== @@ -123,6 +123,11 @@ </field> <field name="speciesFate"> + <!-- speciesFate is mandatory --> + <field-validator type="mandatory" short-circuit="true"> + <message/> + </field-validator> + <!-- check if referential speciesFate is disabled (only if validation is strong) --> <field-validator type="checkDisabledReferentialOnErrorScope"> <message/> ===================================== server/runner/src/main/webResources/doc/api/public/data/ps/observation/Catch/validation-update.json ===================================== @@ -68,7 +68,8 @@ }, "speciesFate": { "errors": [ - "check if referential speciesFate is disabled (only if validation is strong)" + "check if referential speciesFate is disabled (only if validation is strong)", + "speciesFate is mandatory" ], "warnings": [ "check if referential speciesFate is disabled (only if validation is not strong)" View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/ddda2036ede355ce9c9c47d6… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/ddda2036ede355ce9c9c47d6… You're receiving this email because of your account on gitlab.com.
1 0
0 0
[Git][ultreiaio/ird-observe][develop] 2 commits: Persistence (IdFactory) - En insertion de marée par le service web, les...
by Tony CHEMIT (@tchemit) 25 Oct '22

25 Oct '22
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: a7855953 by Tony Chemit at 2022-10-25T12:16:26+02:00 Persistence (IdFactory) - En insertion de marée par le service web, les nouveaux topiaid générés ont un nouveau format. Est-il voulu et fiable ? - Closes #2459 - - - - - ddda2036 by Tony Chemit at 2022-10-25T12:33:49+02:00 Persistence (IdFactory) - Review his usage in Avdth import - See #2459 - - - - - 11 changed files: - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/avdth/ImportDialog.jcss - client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/avdth/ImportDialogModel.java - core/api/services/src/main/java/fr/ird/observe/services/service/data/ps/AvdthDataImportConfiguration.java - core/persistence/java/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java - core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/DataReader.java - core/persistence/test/src/test/java/fr/ird/observe/persistence/avdth/data/AvdthDataBuilderTestSupport.java - toolkit/persistence/src/main/java/fr/ird/observe/spi/io/EntityDeserializer.java - toolkit/persistence/src/main/java/fr/ird/observe/spi/io/EntityDeserializerContext.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactoryForBulkSupport.java - toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactorySupport.java Changes: ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/avdth/ImportDialog.jcss ===================================== @@ -57,7 +57,7 @@ } #idTimestamp { - text:{model.getIdTimestamp()}; + text:{model.getIdTimestamp() + ""}; enabled:false; } ===================================== client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/avdth/ImportDialogModel.java ===================================== @@ -289,8 +289,8 @@ public class ImportDialogModel extends AbstractJavaBean { return importFile == null ? "" : removeMsAccessExtension(importFile.getAbsolutePath()); } - public String getIdTimestamp() { - return now.getTime() + ""; + public long getIdTimestamp() { + return now.getTime() ; } public boolean isImportDone() { ===================================== core/api/services/src/main/java/fr/ird/observe/services/service/data/ps/AvdthDataImportConfiguration.java ===================================== @@ -43,7 +43,7 @@ public class AvdthDataImportConfiguration implements JsonAware { /** * Id prefix to use to create new data. */ - private final String idTimestamp; + private final long idTimestamp; /** * Program id where to attach imported trip. */ @@ -83,7 +83,7 @@ public class AvdthDataImportConfiguration implements JsonAware { private final ProgressionModel progressionModel; public AvdthDataImportConfiguration(Date now, - String idTimestamp, + long idTimestamp, String programId, String oceanId, ReferentialLocale referentialLocale, @@ -138,7 +138,7 @@ public class AvdthDataImportConfiguration implements JsonAware { return now; } - public String getIdTimestamp() { + public long getIdTimestamp() { return idTimestamp; } ===================================== core/persistence/java/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java ===================================== @@ -36,6 +36,7 @@ import io.ultreia.java4all.util.sql.SqlScript; import org.nuiton.topia.persistence.TagValues; import org.nuiton.topia.persistence.TopiaConfiguration; import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport; import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContextConstructorParameter; import org.nuiton.topia.service.sql.blob.TopiaEntitySqlBlobModel; import org.nuiton.topia.service.sql.model.TopiaEntitySqlModel; @@ -96,7 +97,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat } @Override - public ObserveIdFactoryForBulk newIdFactoryForBulk(long timestamp) { + public TopiaIdFactoryForBulkSupport newIdFactoryForBulk(long timestamp) { return new ObserveIdFactoryForBulk(timestamp); } ===================================== core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/DataReader.java ===================================== @@ -27,9 +27,8 @@ import fr.ird.observe.persistence.avdth.coordinate.CoordinateHelper; import fr.ird.observe.persistence.avdth.coordinate.IntToCoordinate; import fr.ird.observe.services.service.data.ps.AvdthDataImportConfiguration; import fr.ird.observe.spi.context.DtoEntityContext; -import io.ultreia.java4all.lang.Strings; import org.apache.commons.lang3.mutable.MutableInt; -import org.nuiton.topia.persistence.TopiaIdFactory; +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport; import java.sql.ResultSet; import java.sql.SQLException; @@ -46,28 +45,19 @@ public abstract class DataReader<E extends DataEntity> { * Configuration of import (with also import context). */ private final ImportEngine context; - /** - * Size of the random part. - */ - private final int randomPartSize; /** * Internal topia Id factory. */ - private final TopiaIdFactory topiaIdFactory; - /** - * Fixed id timestamp. - */ - private final String idTimestamp; + private final TopiaIdFactoryForBulkSupport topiaIdFactory; /** - * Internal counter to simulate id on none persisted entries. + * Internal counter of created entities of this type. */ private int count = 0; public DataReader(ImportEngine context) { this.context = Objects.requireNonNull(context); - this.topiaIdFactory = context.getPersistenceApplicationContext().getTopiaIdFactory(); - this.idTimestamp = context.getConfiguration().getIdTimestamp(); - this.randomPartSize = 8; + long idTimestamp = context.getConfiguration().getIdTimestamp(); + this.topiaIdFactory = context.getPersistenceApplicationContext().newIdFactoryForBulk(idTimestamp); } public ImportEngine context() { @@ -93,12 +83,14 @@ public abstract class DataReader<E extends DataEntity> { } protected final <EE extends DataEntity> EE newEntity(DtoEntityContext<?, ?, EE, ?> spi) { - String id = topiaIdFactory.newTopiaId(spi.toEntityType(), idTimestamp, Strings.leftPad("" + (count++), randomPartSize, '0')); + String id = topiaIdFactory.newTopiaId(spi.toEntityType()); + count++; return spi.newEntity(id); } protected final <EE extends DataEntity> EE newEntity(DtoEntityContext<?, ?, EE, ?> spi, MutableInt count) { - String id = topiaIdFactory.newTopiaId(spi.toEntityType(), idTimestamp, Strings.leftPad("" + count.incrementAndGet(), randomPartSize, '0')); + String id = topiaIdFactory.newTopiaId(spi.toEntityType()); + count.increment(); return spi.newEntity(id); } ===================================== core/persistence/test/src/test/java/fr/ird/observe/persistence/avdth/data/AvdthDataBuilderTestSupport.java ===================================== @@ -130,7 +130,7 @@ public abstract class AvdthDataBuilderTestSupport extends PersistenceTestSupport boolean doInlineImport = doInlineImport(); AvdthDataImportConfiguration configuration = new AvdthDataImportConfiguration( AvdthFixtures.DATE, - "20200601", + 20200601L, "fr.ird.referential.ps.common.Program#1239832686262#0.42751447061198444", getOceanId(), ReferentialLocale.FR, ===================================== toolkit/persistence/src/main/java/fr/ird/observe/spi/io/EntityDeserializer.java ===================================== @@ -24,8 +24,8 @@ package fr.ird.observe.spi.io; import com.google.gson.Gson; import fr.ird.observe.entities.Entity; -import fr.ird.observe.entities.ObserveIdFactoryForBulk; import fr.ird.observe.entities.ToolkitTopiaPersistenceContextSupport; +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport; import java.util.Date; import java.util.List; @@ -42,7 +42,7 @@ public class EntityDeserializer { private final EntityDeserializerContext context; - public EntityDeserializer(ToolkitTopiaPersistenceContextSupport persistenceContext, Supplier<Gson> gson, ObserveIdFactoryForBulk idFactory, Date now) { + public EntityDeserializer(ToolkitTopiaPersistenceContextSupport persistenceContext, Supplier<Gson> gson, TopiaIdFactoryForBulkSupport idFactory, Date now) { this.context = new EntityDeserializerContext(persistenceContext, gson,idFactory, now); } ===================================== toolkit/persistence/src/main/java/fr/ird/observe/spi/io/EntityDeserializerContext.java ===================================== @@ -24,13 +24,13 @@ package fr.ird.observe.spi.io; import com.google.gson.Gson; import fr.ird.observe.entities.Entity; -import fr.ird.observe.entities.ObserveIdFactoryForBulk; import fr.ird.observe.entities.ToolkitTopiaPersistenceContextSupport; import fr.ird.observe.entities.data.DataEntity; import fr.ird.observe.entities.referential.ReferentialEntity; import io.ultreia.java4all.util.json.adapters.DateAdapter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport; import org.nuiton.topia.persistence.TopiaNoResultException; import javax.sql.rowset.serial.SerialBlob; @@ -62,7 +62,7 @@ public class EntityDeserializerContext { private static final Logger log = LogManager.getLogger(EntityDeserializerContext.class); private final ToolkitTopiaPersistenceContextSupport persistenceContext; private final Gson gson; - private final ObserveIdFactoryForBulk idFactory; + private final TopiaIdFactoryForBulkSupport idFactory; private final Date now; private final DateAdapter dataAdapter; private final List<Entity> created; @@ -73,7 +73,7 @@ public class EntityDeserializerContext { return id != null && id.startsWith(ID_REFERENCE_PREFIX); } - public EntityDeserializerContext(ToolkitTopiaPersistenceContextSupport persistenceContext, Supplier<Gson> gson, ObserveIdFactoryForBulk idFactory, Date now) { + public EntityDeserializerContext(ToolkitTopiaPersistenceContextSupport persistenceContext, Supplier<Gson> gson, TopiaIdFactoryForBulkSupport idFactory, Date now) { this.persistenceContext = Objects.requireNonNull(persistenceContext); this.gson = Objects.requireNonNull(gson).get(); this.idFactory = idFactory; ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java ===================================== @@ -175,4 +175,16 @@ public interface TopiaIdFactory extends Serializable { return result; } + /** + * Generates a random decimal (between 0 and 1) used as random part in a id. + * + * @return generate random as a string + */ + default String generateRandom() { + double random = Math.random(); + while (Double.toString(random).contains("E-")) { + random = Math.random(); + } + return random + ""; + } } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactoryForBulkSupport.java ===================================== @@ -27,7 +27,7 @@ import java.util.TreeMap; import java.util.concurrent.atomic.AtomicLong; /** - * A special id factory where the timestamp part is fixed and the random part is performed by a sequence (by type). + * A special id factory where the timestamp part is fixed and the random part is performed by a sequence (by type) plus always a random part. * <p> * Created on 09/03/2022. * @@ -37,8 +37,6 @@ import java.util.concurrent.atomic.AtomicLong; public class TopiaIdFactoryForBulkSupport implements TopiaIdFactory { private static final long serialVersionUID = 1L; - private static final String ID_SUFFIX = "000000000000000000%d"; - private static final int SUFFIX_LENGTH = ID_SUFFIX.length() - 1; private final String timestampPart; private final Map<String, AtomicLong> count; @@ -52,13 +50,8 @@ public class TopiaIdFactoryForBulkSupport implements TopiaIdFactory { return newTopiaId(idPrefix, timestampPart, getRandom(idPrefix)); } - private String getRandom(String type) { - String result = String.format(ID_SUFFIX, count.computeIfAbsent(type, s -> new AtomicLong()).incrementAndGet()); - int length = result.length(); - if (length > SUFFIX_LENGTH) { - result = result.substring(length - SUFFIX_LENGTH); - } - return result; + protected String getRandom(String type) { + return count.computeIfAbsent(type, s -> new AtomicLong()).incrementAndGet() + generateRandom().substring(1); } } ===================================== toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactorySupport.java ===================================== @@ -34,15 +34,7 @@ public class TopiaIdFactorySupport implements TopiaIdFactory { @Override public String newTopiaIdFromIdPrefix(String idPrefix) { - return newTopiaId(idPrefix, System.currentTimeMillis() + "", getRandom()); - } - - private String getRandom() { - double random = Math.random(); - while (Double.toString(random).contains("E-")) { - random = Math.random(); - } - return random + ""; + return newTopiaId(idPrefix, System.currentTimeMillis() + "", generateRandom()); } } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/14a001e36ebd5e2a78e7d5f1… -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/14a001e36ebd5e2a78e7d5f1… You're receiving this email because of your account on gitlab.com.
1 0
0 0
  • ← Newer
  • 1
  • 2
  • 3
  • 4
  • ...
  • 14
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.