Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
f8d211b9
by Tony Chemit at 2024-06-25T17:28:55+02:00
-
cfa3abfb
by Tony Chemit at 2024-06-25T17:28:55+02:00
-
39784e11
by Tony Chemit at 2024-06-25T17:29:32+02:00
9 changed files:
- client/datasource/actions/src/main/i18n/getters/java.getter
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/data/tree/DataSelectionTreePaneHandler.java
- client/datasource/actions/src/main/java/fr/ird/observe/client/datasource/actions/synchronize/data/tree/DataSelectionTreePaneModel.java
- core/persistence/java/src/main/resources/META-INF/persistence/Observe/TopiaEntitySqlScriptModel.json
- core/persistence/test/src/test/java/fr/ird/observe/persistence/avdth/data/AvdthDataBuilderTestSupport.java
- core/persistence/test/src/test/java/fr/ird/observe/persistence/avdth/referential/AvdthReferentialBuilderTest.java
- core/persistence/test/src/test/java/fr/ird/observe/persistence/avdth/referential/AvdthWeightCategoryBuilderTest.java
- toolkit/templates/src/main/java/fr/ird/observe/toolkit/templates/entity/ReplaceReferentialScriptGenerator.java
- toolkit/test-api/src/main/java/fr/ird/observe/test/ObserveTestConfiguration.java
Changes:
| ... | ... | @@ -206,3 +206,4 @@ observe.ui.tree.action.collapseAll.tip |
| 206 | 206 | observe.ui.tree.action.expandAll.tip
|
| 207 | 207 | observe.ui.tree.action.selectAll.tip
|
| 208 | 208 | observe.ui.tree.action.unselectAll.tip
|
| 209 | +observe.ui.tree.reload |
| ... | ... | @@ -39,6 +39,7 @@ import fr.ird.observe.navigation.tree.selection.IdState; |
| 39 | 39 | import fr.ird.observe.navigation.tree.selection.SelectionTree;
|
| 40 | 40 | import fr.ird.observe.navigation.tree.selection.SelectionTreeModel;
|
| 41 | 41 | import fr.ird.observe.navigation.tree.selection.SelectionTreeNode;
|
| 42 | +import io.ultreia.java4all.i18n.I18n;
|
|
| 42 | 43 | import io.ultreia.java4all.util.TwoSideContext;
|
| 43 | 44 | import org.apache.logging.log4j.LogManager;
|
| 44 | 45 | import org.apache.logging.log4j.Logger;
|
| ... | ... | @@ -158,9 +159,11 @@ public class DataSelectionTreePaneHandler implements UIHandler<DataSelectionTree |
| 158 | 159 | }
|
| 159 | 160 | |
| 160 | 161 | public static void rebuildTree(DataSynchroModel stepModel, DataSelectionTreePane ui, boolean rebuildFlatModel) {
|
| 161 | - ui.getTree().getTree().clearSelection();
|
|
| 162 | - stepModel.rebuildSelectionModel(ui.getSide(), rebuildFlatModel);
|
|
| 163 | - finalizeTree(ui);
|
|
| 162 | + stepModel.getActionExecutor().addAction(I18n.t("observe.ui.tree.reload"), ()-> {
|
|
| 163 | + ui.getTree().getTree().clearSelection();
|
|
| 164 | + stepModel.rebuildSelectionModel(ui.getSide(), rebuildFlatModel);
|
|
| 165 | + finalizeTree(ui);
|
|
| 166 | + });
|
|
| 164 | 167 | }
|
| 165 | 168 | |
| 166 | 169 | public static void afterTreeBuild(DataSelectionTreePane ui) {
|
| ... | ... | @@ -98,6 +98,7 @@ public class DataSelectionTreePaneModel extends AbstractJavaBean { |
| 98 | 98 | * Can we delete from this side?
|
| 99 | 99 | */
|
| 100 | 100 | private boolean canDelete;
|
| 101 | + |
|
| 101 | 102 | public void dispose() {
|
| 102 | 103 | source = null;
|
| 103 | 104 | treeFlatModel = null;
|
| ... | ... | @@ -178,7 +179,9 @@ public class DataSelectionTreePaneModel extends AbstractJavaBean { |
| 178 | 179 | |
| 179 | 180 | public void rebuildSelectionModel(boolean rebuildFlatModel, List<IdAndLastUpdateDate> otherSideIds) {
|
| 180 | 181 | if (rebuildFlatModel) {
|
| 181 | - treeFlatModel = selectionDataModel.buildFlatModel(source.getNavigationService()::loadSelectionRoot);
|
|
| 182 | + try (ObserveSwingDataSource dataSource = ObserveSwingDataSource.doOpenSource(source)) {
|
|
| 183 | + treeFlatModel = selectionDataModel.buildFlatModel(dataSource.getNavigationService()::loadSelectionRoot);
|
|
| 184 | + }
|
|
| 182 | 185 | }
|
| 183 | 186 | selectionDataModel.populate(treeFlatModel, r -> {
|
| 184 | 187 | computeDataIds(r);
|
| ... | ... | @@ -1116,7 +1116,8 @@ |
| 1116 | 1116 | "UPDATE ps_common.trip SET captain = '%3$s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%1$s'::timestamp WHERE captain = '%2$s';",
|
| 1117 | 1117 | "UPDATE ps_common.trip SET observationsDataEntryOperator = '%3$s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%1$s'::timestamp WHERE observationsDataEntryOperator = '%2$s';",
|
| 1118 | 1118 | "UPDATE ps_common.trip SET logbookDataEntryOperator = '%3$s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%1$s'::timestamp WHERE logbookDataEntryOperator = '%2$s';",
|
| 1119 | - "UPDATE ps_logbook.sample_person SET person = '%3$s' WHERE person = '%2$s';"
|
|
| 1119 | + "UPDATE ps_logbook.sample_person SET person = '%3$s' WHERE person = '%2$s' AND (SELECT COUNT(s.person) FROM ps_logbook.sample_person s WHERE s.person = '%3$s') = 0;",
|
|
| 1120 | + "DELETE FROM ps_logbook.sample_person WHERE person = '%2$s';"
|
|
| 1120 | 1121 | ],
|
| 1121 | 1122 | "org.nuiton.topia.service.sql.script.DeleteReferentialScript": [
|
| 1122 | 1123 | "DELETE FROM common.person WHERE topiaId = '%1$s';"
|
| ... | ... | @@ -1239,10 +1240,14 @@ |
| 1239 | 1240 | "UPDATE ps_localmarket.batch SET species = '%3$s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%1$s'::timestamp WHERE species = '%2$s';",
|
| 1240 | 1241 | "UPDATE ps_localmarket.surveyPart SET species = '%3$s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%1$s'::timestamp WHERE species = '%2$s';",
|
| 1241 | 1242 | "UPDATE ps_localmarket.sampleSpecies SET species = '%3$s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%1$s'::timestamp WHERE species = '%2$s';",
|
| 1242 | - "UPDATE ll_common.trip_species SET species = '%3$s' WHERE species = '%2$s';",
|
|
| 1243 | - "UPDATE ll_observation.catch_predator SET species = '%3$s' WHERE species = '%2$s';",
|
|
| 1244 | - "UPDATE ll_observation.tdr_species SET species = '%3$s' WHERE species = '%2$s';",
|
|
| 1245 | - "UPDATE ll_logbook.catch_predator SET species = '%3$s' WHERE species = '%2$s';"
|
|
| 1243 | + "UPDATE ll_common.trip_species SET species = '%3$s' WHERE species = '%2$s' AND (SELECT COUNT(s.species) FROM ll_common.trip_species s WHERE s.species = '%3$s') = 0;",
|
|
| 1244 | + "DELETE FROM ll_common.trip_species WHERE species = '%2$s';",
|
|
| 1245 | + "UPDATE ll_observation.catch_predator SET species = '%3$s' WHERE species = '%2$s' AND (SELECT COUNT(s.species) FROM ll_observation.catch_predator s WHERE s.species = '%3$s') = 0;",
|
|
| 1246 | + "DELETE FROM ll_observation.catch_predator WHERE species = '%2$s';",
|
|
| 1247 | + "UPDATE ll_observation.tdr_species SET species = '%3$s' WHERE species = '%2$s' AND (SELECT COUNT(s.species) FROM ll_observation.tdr_species s WHERE s.species = '%3$s') = 0;",
|
|
| 1248 | + "DELETE FROM ll_observation.tdr_species WHERE species = '%2$s';",
|
|
| 1249 | + "UPDATE ll_logbook.catch_predator SET species = '%3$s' WHERE species = '%2$s' AND (SELECT COUNT(s.species) FROM ll_logbook.catch_predator s WHERE s.species = '%3$s') = 0;",
|
|
| 1250 | + "DELETE FROM ll_logbook.catch_predator WHERE species = '%2$s';"
|
|
| 1246 | 1251 | ],
|
| 1247 | 1252 | "org.nuiton.topia.service.sql.script.ReplaceReferentialInReferentialScript": [
|
| 1248 | 1253 | "UPDATE ps_common.weightCategory SET species = '%3$s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%1$s'::timestamp WHERE species = '%2$s';",
|
| ... | ... | @@ -1615,8 +1620,10 @@ |
| 1615 | 1620 | "UPDATE common.lastUpdateDate SET lastUpdateDate = '%1$s'::timestamp WHERE type ='fr.ird.observe.entities.referential.ll.common.MitigationType';"
|
| 1616 | 1621 | ],
|
| 1617 | 1622 | "org.nuiton.topia.service.sql.script.ReplaceReferentialInDataScript": [
|
| 1618 | - "UPDATE ll_observation.set_mitigationType SET mitigationType = '%3$s' WHERE mitigationType = '%2$s';",
|
|
| 1619 | - "UPDATE ll_logbook.set_mitigationType SET mitigationType = '%3$s' WHERE mitigationType = '%2$s';"
|
|
| 1623 | + "UPDATE ll_observation.set_mitigationType SET mitigationType = '%3$s' WHERE mitigationType = '%2$s' AND (SELECT COUNT(s.mitigationType) FROM ll_observation.set_mitigationType s WHERE s.mitigationType = '%3$s') = 0;",
|
|
| 1624 | + "DELETE FROM ll_observation.set_mitigationType WHERE mitigationType = '%2$s';",
|
|
| 1625 | + "UPDATE ll_logbook.set_mitigationType SET mitigationType = '%3$s' WHERE mitigationType = '%2$s' AND (SELECT COUNT(s.mitigationType) FROM ll_logbook.set_mitigationType s WHERE s.mitigationType = '%3$s') = 0;",
|
|
| 1626 | + "DELETE FROM ll_logbook.set_mitigationType WHERE mitigationType = '%2$s';"
|
|
| 1620 | 1627 | ],
|
| 1621 | 1628 | "org.nuiton.topia.service.sql.script.DeleteReferentialScript": [
|
| 1622 | 1629 | "DELETE FROM ll_common.mitigationType WHERE topiaId = '%1$s';"
|
| ... | ... | @@ -2043,8 +2050,10 @@ |
| 2043 | 2050 | "UPDATE common.lastUpdateDate SET lastUpdateDate = '%1$s'::timestamp WHERE type ='fr.ird.observe.entities.referential.ps.common.ObservedSystem';"
|
| 2044 | 2051 | ],
|
| 2045 | 2052 | "org.nuiton.topia.service.sql.script.ReplaceReferentialInDataScript": [
|
| 2046 | - "UPDATE ps_observation.activity_observedSystem SET observedSystem = '%3$s' WHERE observedSystem = '%2$s';",
|
|
| 2047 | - "UPDATE ps_logbook.activity_observedSystem SET observedSystem = '%3$s' WHERE observedSystem = '%2$s';"
|
|
| 2053 | + "UPDATE ps_observation.activity_observedSystem SET observedSystem = '%3$s' WHERE observedSystem = '%2$s' AND (SELECT COUNT(s.observedSystem) FROM ps_observation.activity_observedSystem s WHERE s.observedSystem = '%3$s') = 0;",
|
|
| 2054 | + "DELETE FROM ps_observation.activity_observedSystem WHERE observedSystem = '%2$s';",
|
|
| 2055 | + "UPDATE ps_logbook.activity_observedSystem SET observedSystem = '%3$s' WHERE observedSystem = '%2$s' AND (SELECT COUNT(s.observedSystem) FROM ps_logbook.activity_observedSystem s WHERE s.observedSystem = '%3$s') = 0;",
|
|
| 2056 | + "DELETE FROM ps_logbook.activity_observedSystem WHERE observedSystem = '%2$s';"
|
|
| 2048 | 2057 | ],
|
| 2049 | 2058 | "org.nuiton.topia.service.sql.script.DeleteReferentialScript": [
|
| 2050 | 2059 | "DELETE FROM ps_common.observedSystem WHERE topiaId = '%1$s';"
|
| ... | ... | @@ -127,6 +127,7 @@ public abstract class AvdthDataBuilderTestSupport extends PersistenceTestSupport |
| 127 | 127 | public void build() throws SQLException, IOException, MissingReferentialException {
|
| 128 | 128 | log.info(String.format("Start for database: %s", dbName));
|
| 129 | 129 | Path avdthFile = getRootPath().resolve(dbName);
|
| 130 | + Assume.assumeTrue("Skip, avdth file " + avdthFile + " not found", Files.exists(avdthFile));
|
|
| 130 | 131 | Path scriptPath = TOPIA_TEST_CLASS_RESOURCE.getTestDirectory().toPath().resolve("export-" + dbName.replace(".mdb", ".sql"));
|
| 131 | 132 | Path scriptTemporaryDirectory = scriptPath.getParent().resolve(scriptPath.toFile().getName().replace(".sql", "-tmp"));
|
| 132 | 133 |
| ... | ... | @@ -39,10 +39,12 @@ import fr.ird.observe.test.spi.DatabaseNameConfiguration; |
| 39 | 39 | import fr.ird.observe.test.spi.DatabasePasswordConfiguration;
|
| 40 | 40 | import fr.ird.observe.test.spi.DatabaseVersionConfiguration;
|
| 41 | 41 | import org.junit.Assert;
|
| 42 | +import org.junit.Assume;
|
|
| 42 | 43 | import org.junit.ClassRule;
|
| 43 | 44 | import org.junit.Test;
|
| 44 | 45 | |
| 45 | 46 | import java.io.IOException;
|
| 47 | +import java.nio.file.Files;
|
|
| 46 | 48 | import java.nio.file.Path;
|
| 47 | 49 | import java.sql.Connection;
|
| 48 | 50 | import java.sql.SQLException;
|
| ... | ... | @@ -74,6 +76,7 @@ public class AvdthReferentialBuilderTest extends TestSupportWithConfig { |
| 74 | 76 | Path avdthFile = AvdthFixtures.getAvdthCachePath()
|
| 75 | 77 | .resolve("OA")
|
| 76 | 78 | .resolve("OA_2020_V35.mdb");
|
| 79 | + Assume.assumeTrue("Skip, avdth file " + avdthFile + " not found", Files.exists(avdthFile));
|
|
| 77 | 80 | Path scriptPath = localTestMethodResource.getTestDirectory().toPath().resolve("export-" + avdthFile.toFile().getName().replace(".mdb", ".sql"));
|
| 78 | 81 | Path scriptTemporaryDirectory = scriptPath.getParent().resolve(scriptPath.toFile().getName().replace(".sql", "-tmp"));
|
| 79 | 82 |
| ... | ... | @@ -38,10 +38,12 @@ import fr.ird.observe.test.spi.DatabaseNameConfiguration; |
| 38 | 38 | import fr.ird.observe.test.spi.DatabasePasswordConfiguration;
|
| 39 | 39 | import fr.ird.observe.test.spi.DatabaseVersionConfiguration;
|
| 40 | 40 | import org.junit.Assert;
|
| 41 | +import org.junit.Assume;
|
|
| 41 | 42 | import org.junit.ClassRule;
|
| 42 | 43 | import org.junit.Test;
|
| 43 | 44 | |
| 44 | 45 | import java.io.IOException;
|
| 46 | +import java.nio.file.Files;
|
|
| 45 | 47 | import java.nio.file.Path;
|
| 46 | 48 | import java.sql.Connection;
|
| 47 | 49 | import java.sql.SQLException;
|
| ... | ... | @@ -70,6 +72,7 @@ public class AvdthWeightCategoryBuilderTest extends TestSupportWithConfig { |
| 70 | 72 | public void build() throws SQLException, IOException {
|
| 71 | 73 | Path avdthFile = AvdthFixtures.getAvdthCachePath()
|
| 72 | 74 | .resolve("avdth-gen-35_74.mdb");
|
| 75 | + Assume.assumeTrue("Skip, avdth file " + avdthFile + " not found", Files.exists(avdthFile));
|
|
| 73 | 76 | Path scriptPath = localTestMethodResource.getTestDirectory().toPath().resolve("export-" + avdthFile.toFile().getName().replace(".mdb", ".sql"));
|
| 74 | 77 | Path scriptTemporaryDirectory = scriptPath.getParent().resolve(scriptPath.toFile().getName().replace(".sql", "-tmp"));
|
| 75 | 78 |
| ... | ... | @@ -22,6 +22,7 @@ package fr.ird.observe.toolkit.templates.entity; |
| 22 | 22 | * #L%
|
| 23 | 23 | */
|
| 24 | 24 | |
| 25 | +import fr.ird.observe.spi.referential.SqlStatements;
|
|
| 25 | 26 | import org.nuiton.topia.service.sql.metadata.TopiaMetadataAssociation;
|
| 26 | 27 | import org.nuiton.topia.service.sql.metadata.TopiaMetadataComposition;
|
| 27 | 28 | import org.nuiton.topia.service.sql.metadata.TopiaMetadataEntity;
|
| ... | ... | @@ -55,11 +56,11 @@ public class ReplaceReferentialScriptGenerator { |
| 55 | 56 | /**
|
| 56 | 57 | * To update a reference of a composition relation.
|
| 57 | 58 | */
|
| 58 | - public static final String COMPOSITION_UPDATE_STATEMENT = "UPDATE %s.%s SET %s = '%s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%s'::timestamp WHERE %s = '%s';";
|
|
| 59 | + public static final String COMPOSITION_UPDATE_STATEMENT = "UPDATE %1$s.%2$s SET %3$s = '%4$s', topiaVersion = topiaVersion + 1, lastUpdateDate = '%5$s'::timestamp WHERE %3$s = '%6$s';";
|
|
| 59 | 60 | /**
|
| 60 | 61 | * To update a reference of an association relation.
|
| 61 | 62 | */
|
| 62 | - private static final String ASSOCIATION_UPDATE_STATEMENT = "UPDATE %s.%s SET %s = '%s' WHERE %s = '%s';";
|
|
| 63 | + private static final String ASSOCIATION_UPDATE_STATEMENT = "UPDATE %1$s.%2$s SET %3$s = '%4$s' WHERE %3$s = '%5$s' AND (SELECT COUNT(s.%3$s) FROM %1$s.%2$s s WHERE s.%3$s = '%4$s') = 0;";
|
|
| 63 | 64 | /**
|
| 64 | 65 | * All reverse relation many-to-one.
|
| 65 | 66 | */
|
| ... | ... | @@ -96,6 +97,8 @@ public class ReplaceReferentialScriptGenerator { |
| 96 | 97 | }
|
| 97 | 98 | String sql = generateAssociationUpdateStatement(replacementStruct, sourceId, replacementId);
|
| 98 | 99 | builder.add(sql);
|
| 100 | + sql = generateAssociationDeleteStatement(replacementStruct, sourceId);
|
|
| 101 | + builder.add(sql);
|
|
| 99 | 102 | }
|
| 100 | 103 | return builder;
|
| 101 | 104 | }
|
| ... | ... | @@ -107,7 +110,6 @@ public class ReplaceReferentialScriptGenerator { |
| 107 | 110 | composition.getTargetDbName(),
|
| 108 | 111 | replacementId,
|
| 109 | 112 | lastUpdateDate,
|
| 110 | - composition.getTargetDbName(),
|
|
| 111 | 113 | sourceId);
|
| 112 | 114 | }
|
| 113 | 115 | |
| ... | ... | @@ -117,7 +119,14 @@ public class ReplaceReferentialScriptGenerator { |
| 117 | 119 | association.getTableName(),
|
| 118 | 120 | association.getTargetDbName(),
|
| 119 | 121 | replacementId,
|
| 120 | - association.getTargetDbName(),
|
|
| 121 | 122 | sourceId);
|
| 122 | 123 | }
|
| 124 | + |
|
| 125 | + private String generateAssociationDeleteStatement(TopiaMetadataAssociation association, String sourceId) {
|
|
| 126 | + return String.format(SqlStatements.ASSOCIATION_DELETE_STATEMENT,
|
|
| 127 | + association.getOwner().getDbSchemaName(),
|
|
| 128 | + association.getTableName(),
|
|
| 129 | + association.getTargetDbName(),
|
|
| 130 | + sourceId).trim();
|
|
| 131 | + }
|
|
| 123 | 132 | } |
| ... | ... | @@ -33,10 +33,12 @@ import fr.ird.observe.test.spi.DatabaseVersionConfiguration; |
| 33 | 33 | import io.ultreia.java4all.util.Version;
|
| 34 | 34 | import io.ultreia.java4all.util.sql.conf.JdbcConfiguration;
|
| 35 | 35 | import io.ultreia.java4all.util.sql.conf.JdbcConfigurationBuilder;
|
| 36 | +import org.junit.Assume;
|
|
| 36 | 37 | |
| 37 | 38 | import java.lang.reflect.AnnotatedElement;
|
| 38 | 39 | import java.net.MalformedURLException;
|
| 39 | 40 | import java.net.URL;
|
| 41 | +import java.nio.file.Files;
|
|
| 40 | 42 | import java.nio.file.Path;
|
| 41 | 43 | |
| 42 | 44 | /**
|
| ... | ... | @@ -155,6 +157,7 @@ public class ObserveTestConfiguration { |
| 155 | 157 | public static void injectCredentials() {
|
| 156 | 158 | |
| 157 | 159 | Path credentialPath = Path.of(ObserveTestConfiguration.getTestPropertyAsString(ToolkitFixtures.TEST_CREDENTIALS_KEY));
|
| 160 | + Assume.assumeTrue("Skip, no credential file found", Files.exists(credentialPath));
|
|
| 158 | 161 | ToolkitFixtures.injectCredentials(credentialPath,
|
| 159 | 162 | ObserveTestConfiguration.PG_URL,
|
| 160 | 163 | ObserveTestConfiguration.PG_LOGIN,
|