Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
41491680
by Tony CHEMIT at 2018-05-04T16:01:00Z
-
7e0ce9c0
by Tony CHEMIT at 2018-05-08T21:41:43Z
-
d10e76f5
by Tony CHEMIT at 2018-05-08T22:15:12Z
-
89ef1058
by Tony CHEMIT at 2018-05-08T22:15:36Z
-
b6b9bc62
by Tony CHEMIT at 2018-05-08T22:15:36Z
-
cc085c2d
by Tony CHEMIT at 2018-05-08T22:15:37Z
2 changed files:
- persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_6_0.java
- + persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_7_0_RC_4.java
Changes:
| ... | ... | @@ -316,6 +316,74 @@ public class DataSourceMigrationForVersion_6_0 extends MigrationVersionResource |
| 316 | 316 |
}
|
| 317 | 317 |
}
|
| 318 | 318 |
|
| 319 |
+ @Override
|
|
| 320 |
+ protected void prepareMigrationScript(TopiaSqlSupport topiaSqlSupport, List<String> queries, boolean showSql, boolean showProgression) {
|
|
| 321 |
+ Boolean withTriggers = topiaSqlSupport.findSingleResult(new TopiaSqlQuery<Boolean>() {
|
|
| 322 |
+ @Override
|
|
| 323 |
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 324 |
+ return connection.prepareStatement("select exists(select * from pg_proc where proname = 'sync_activity_the_geom');");
|
|
| 325 |
+ }
|
|
| 326 |
+ |
|
| 327 |
+ @Override
|
|
| 328 |
+ public Boolean prepareResult(ResultSet resultSet) throws SQLException {
|
|
| 329 |
+ return resultSet.getBoolean(1);
|
|
| 330 |
+ }
|
|
| 331 |
+ });
|
|
| 332 |
+ |
|
| 333 |
+ if (withTriggers) {
|
|
| 334 |
+ queries.add("CREATE OR REPLACE function sync_activity_the_geom () returns trigger as '\n" +
|
|
| 335 |
+ "BEGIN\n" +
|
|
| 336 |
+ " IF (TG_OP = ''DELETE'') THEN\n" +
|
|
| 337 |
+ " RETURN OLD;\n" +
|
|
| 338 |
+ " END IF;\n" +
|
|
| 339 |
+ " IF (NEW.latitude IS NULL OR NEW.longitude IS NULL) THEN\n" +
|
|
| 340 |
+ " -- on ne calcule pas le point postgis si au moins une des -- coordonnees n est pas renseignee\n" +
|
|
| 341 |
+ " RAISE NOTICE ''No latitude or longitude, can not compute postgis field for id % '', NEW.topiaId;\n" +
|
|
| 342 |
+ " NEW.the_geom := NULL;\n" +
|
|
| 343 |
+ " return NEW;\n" +
|
|
| 344 |
+ " END IF;\n" +
|
|
| 345 |
+ " IF (TG_OP = ''UPDATE'' AND NEW.latitude = OLD.latitude AND NEW.longitude = OLD.longitude)\n" +
|
|
| 346 |
+ " THEN\n" +
|
|
| 347 |
+ " -- on ne calcule pas le point postgis si les coordonnées n''ont pas changées\n" +
|
|
| 348 |
+ " return NEW;\n" +
|
|
| 349 |
+ " END IF;\n" +
|
|
| 350 |
+ " RAISE NOTICE ''Will compute the_geom for activite % - latitude % and longitude %'', NEW.topiaId, NEW.latitude, NEW.longitude;\n" +
|
|
| 351 |
+ " -- affectation du point\n" +
|
|
| 352 |
+ " NEW.the_geom := ST_SetSRID(ST_MakePoint(NEW.longitude,NEW.latitude), 4326);\n" +
|
|
| 353 |
+ " RAISE NOTICE ''Computed for activity % latitude % and longitude %, the_geom %'', NEW.topiaId, NEW.latitude, NEW.longitude, NEW.the_geom;\n" +
|
|
| 354 |
+ "\n" +
|
|
| 355 |
+ " RETURN NEW;\n" +
|
|
| 356 |
+ "END\n" +
|
|
| 357 |
+ "'\n" +
|
|
| 358 |
+ "LANGUAGE 'plpgsql';\n");
|
|
| 359 |
+ queries.add("CREATE OR REPLACE function sync_harbour_the_geom () returns trigger as '\n" +
|
|
| 360 |
+ "BEGIN\n" +
|
|
| 361 |
+ " IF (TG_OP = ''DELETE'') THEN\n" +
|
|
| 362 |
+ " RETURN OLD;\n" +
|
|
| 363 |
+ " END IF;\n" +
|
|
| 364 |
+ " IF (NEW.latitude IS NULL OR NEW.longitude IS NULL) THEN\n" +
|
|
| 365 |
+ " -- on ne calcule pas le point postgis si au moins une des -- coordonnees n est pas renseignee\n" +
|
|
| 366 |
+ " RAISE NOTICE ''No latitude or longitude, can not compute postgis field for id % '', NEW.topiaId;\n" +
|
|
| 367 |
+ " NEW.the_geom := NULL;\n" +
|
|
| 368 |
+ " return NEW;\n" +
|
|
| 369 |
+ " END IF;\n" +
|
|
| 370 |
+ " IF (TG_OP = ''UPDATE'' AND NEW.latitude = OLD.latitude AND NEW.longitude = OLD.longitude)\n" +
|
|
| 371 |
+ " THEN\n" +
|
|
| 372 |
+ " -- on ne calcule pas le point postgis si les coordonnées n''ont pas changées\n" +
|
|
| 373 |
+ " return NEW;\n" +
|
|
| 374 |
+ " END IF;\n" +
|
|
| 375 |
+ " RAISE NOTICE ''Will compute the_geom for harbour % - latitude % and longitude %'', NEW.topiaId, NEW.latitude, NEW.longitude;\n" +
|
|
| 376 |
+ " -- affectation du point\n" +
|
|
| 377 |
+ " NEW.the_geom := ST_SetSRID(ST_MakePoint(NEW.longitude,NEW.latitude), 4326);\n" +
|
|
| 378 |
+ " RAISE NOTICE ''Computed for harbour % latitude % and longitude %, the_geom %'', NEW.topiaId, NEW.latitude, NEW.longitude, NEW.the_geom;\n" +
|
|
| 379 |
+ " RETURN NEW;\n" +
|
|
| 380 |
+ "END\n" +
|
|
| 381 |
+ "'\n" +
|
|
| 382 |
+ "LANGUAGE 'plpgsql';");
|
|
| 383 |
+ addScript("00", "fix_trigger", queries);
|
|
| 384 |
+ }
|
|
| 385 |
+ super.prepareMigrationScript(topiaSqlSupport, queries, showSql, showProgression);
|
|
| 386 |
+ }
|
|
| 319 | 387 |
}
|
| 320 | 388 |
|
| 321 | 389 |
}
|
| 1 |
+package fr.ird.observe.persistence.migration;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Persistence
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import org.nuiton.topia.persistence.support.TopiaSqlSupport;
|
|
| 26 |
+ |
|
| 27 |
+import java.util.List;
|
|
| 28 |
+import java.util.Map;
|
|
| 29 |
+import java.util.Set;
|
|
| 30 |
+import java.util.TreeMap;
|
|
| 31 |
+ |
|
| 32 |
+/**
|
|
| 33 |
+ * Created on 27/10/16.
|
|
| 34 |
+ *
|
|
| 35 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 36 |
+ * @since 6.0
|
|
| 37 |
+ */
|
|
| 38 |
+@MigrationVersion(version = "6.1")
|
|
| 39 |
+public class DataSourceMigrationForVersion_7_0_RC_4 extends AbstractObserveMigrationCallBack {
|
|
| 40 |
+ |
|
| 41 |
+ DataSourceMigrationForVersion_7_0_RC_4(AbstractDataSourceMigration callBack, String scriptSuffix) {
|
|
| 42 |
+ super(DataSourceMigrationForVersion_7_0_RC_4.class, callBack, scriptSuffix);
|
|
| 43 |
+ }
|
|
| 44 |
+ |
|
| 45 |
+ @Override
|
|
| 46 |
+ protected void prepareMigrationScript(TopiaSqlSupport topiaSqlSupport, List<String> queries, boolean showSql, boolean showProgression) {
|
|
| 47 |
+ |
|
| 48 |
+ addScript("01", "add_object_operation", queries);
|
|
| 49 |
+ addScript("02", "add_object_material", queries);
|
|
| 50 |
+ addScript("03", "add_floating_object_part", queries);
|
|
| 51 |
+ addScript("04", "remove_dcp_fields", queries);
|
|
| 52 |
+ |
|
| 53 |
+ Map<String, String> speciesGroupIdMapping = new TreeMap<>();
|
|
| 54 |
+ speciesGroupIdMapping.put("fr.ird.observe.entities.referentiel.SpeciesGroup#1445863056144#0.9820877553253712", "INSERT INTO OBSERVE_COMMON.SPECIESGROUP (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, LASTUPDATEDATE, CODE, URI, NEEDCOMMENT, STATUS, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7, LABEL8) VALUES ('fr.ird.observe.entities.referentiel.SpeciesGroup#1445863056144#0.9820877553253712', 1, '2015-10-26 16:37:36.144000000', '2016-12-06 15:54:27.727005000', '11', null, false, 1, 'Rays', 'Raies', 'Rayas', null, null, null, null, null);");
|
|
| 55 |
+ speciesGroupIdMapping.put("fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683690#0.24333033683679461", "INSERT INTO OBSERVE_COMMON.SPECIESGROUP (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, LASTUPDATEDATE, CODE, URI, NEEDCOMMENT, STATUS, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7, LABEL8) VALUES ('fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683690#0.24333033683679461', 14, '2009-04-15 00:00:00.003000000', '2016-12-06 15:54:27.727005000', '4', null, false, 1, 'Turtles', 'Tortues', 'Tortugas', null, null, null, null, null);");
|
|
| 56 |
+ speciesGroupIdMapping.put("fr.ird.observe.entities.referentiel.SpeciesGroup#1446014286433#0.6480183366605247", "INSERT INTO OBSERVE_COMMON.SPECIESGROUP (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, LASTUPDATEDATE, CODE, URI, NEEDCOMMENT, STATUS, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7, LABEL8) VALUES ('fr.ird.observe.entities.referentiel.SpeciesGroup#1446014286433#0.6480183366605247', 1, '2015-10-28 10:38:06.432000000', '2016-12-06 15:54:27.727005000', '12', null, false, 1, 'Whale shark', 'Requin-baleine', 'Tiburón ballena', null, null, null, null, null);");
|
|
| 57 |
+ speciesGroupIdMapping.put("fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683689#0.7120116158620075", "INSERT INTO OBSERVE_COMMON.SPECIESGROUP (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, LASTUPDATEDATE, CODE, URI, NEEDCOMMENT, STATUS, LABEL1, LABEL2, LABEL3, LABEL4, LABEL5, LABEL6, LABEL7, LABEL8) VALUES ('fr.ird.observe.entities.referentiel.SpeciesGroup#1239832683689#0.7120116158620075', 17, '2009-04-15 00:00:00.001000000', '2017-02-28 15:04:55.370000000', '2', null, false, 1, 'Sharks', 'Requins', 'Tiburones', null, null, null, null, null);");
|
|
| 58 |
+ |
|
| 59 |
+ Set<String> existingSpeciesGroupIds = getTopiaIds(topiaSqlSupport, "OBSERVE_COMMON.SPECIESGROUP");
|
|
| 60 |
+ for (Map.Entry<String, String> entry : speciesGroupIdMapping.entrySet()) {
|
|
| 61 |
+ if (!existingSpeciesGroupIds.contains(entry.getKey())) {
|
|
| 62 |
+ queries.add(entry.getValue());
|
|
| 63 |
+ }
|
|
| 64 |
+ }
|
|
| 65 |
+ addScript("05", "add_species_group_release_mode", queries);
|
|
| 66 |
+ addScript("06", "add_non_target_catch_release", queries);
|
|
| 67 |
+ addScript("07", "drop_table_sizemeasuretype", queries);
|
|
| 68 |
+ addScript("08", "add_floating_object_fields", queries);
|
|
| 69 |
+ addScript("09", "fill_object_material", queries);
|
|
| 70 |
+ |
|
| 71 |
+ }
|
|
| 72 |
+ |
|
| 73 |
+ public static class H2DataSourceMigrationForVersion extends DataSourceMigrationForVersion_7_0_RC_4 {
|
|
| 74 |
+ |
|
| 75 |
+ public H2DataSourceMigrationForVersion(AbstractDataSourceMigration callBack) {
|
|
| 76 |
+ super(callBack, H2DataSourceMigration.TYPE);
|
|
| 77 |
+ }
|
|
| 78 |
+ |
|
| 79 |
+ }
|
|
| 80 |
+ |
|
| 81 |
+ public static class PGDataSourceMigrationForVersion extends DataSourceMigrationForVersion_7_0_RC_4 {
|
|
| 82 |
+ |
|
| 83 |
+ public PGDataSourceMigrationForVersion(AbstractDataSourceMigration callBack) {
|
|
| 84 |
+ super(callBack, PGDataSourceMigration.TYPE);
|
|
| 85 |
+ }
|
|
| 86 |
+ |
|
| 87 |
+ }
|
|
| 88 |
+ |
|
| 89 |
+}
|
|
| 90 |
+ |