Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: c1536213 by tchemit at 2019-07-16T15:51:56Z Consolidation des champs techniques en base - closes #1353 - - - - - 38f8daf4 by tchemit at 2019-07-16T16:32:33Z Problème synchro avancée référentiel - Closes #1352 - - - - - 11 changed files: - persistence/pom.xml - persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_7_1.java - + persistence/src/main/resources/db/migration/7.1/03_add_not_null_on_technical_fields-common.sql - pom.xml - services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/ng/ReferentialSynchronizeSqlsRequestBuilder.java - services/src/main/java/fr/ird/observe/services/service/actions/synchro/referential/ng/ReferentialSynchronizeRequest.java - test/src/main/resources/db/7.1/dataForTestLongline.sql.gz - test/src/main/resources/db/7.1/dataForTestSeine.sql.gz - test/src/main/resources/db/7.1/empty_h2.sql.gz - test/src/main/resources/db/7.1/empty_pg.sql.gz - test/src/main/resources/db/7.1/referentiel.sql.gz Changes: ===================================== persistence/pom.xml ===================================== @@ -274,6 +274,7 @@ </inputs> <templates> org.nuiton.topia.templates.TopiaEntityDaoTransformer, + org.nuiton.topia.templates.TopiaEntityHibernateMappingGenerator, org.nuiton.topia.templates.TopiaMetaTransformer, org.nuiton.topia.templates.TopiaMetadataModelGenerator </templates> ===================================== persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_7_1.java ===================================== @@ -44,6 +44,7 @@ public class DataSourceMigrationForVersion_7_1 extends MigrationVersionResource public void generateSqlScript(MigrationVersionResourceExecutor executor) { executor.addScript("01", "add_not_null_on_length_weight_parameters"); executor.addScript("02", "add_not_null_on_length_length_parameters"); + executor.addScript("03", "add_not_null_on_technical_fields"); } } ===================================== persistence/src/main/resources/db/migration/7.1/03_add_not_null_on_technical_fields-common.sql ===================================== @@ -0,0 +1,126 @@ +--- +-- #%L +-- ObServe :: Persistence +-- %% +-- Copyright (C) 2008 - 2019 IRD, Code Lutin, Ultreia.io +-- %% +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public +-- License along with this program. If not, see +-- <http://www.gnu.org/licenses/gpl-3.0.html>. +-- #L% +--- +ALTER TABLE observe_longline.Activity ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.BaitsComposition ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Basket ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Branchline ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.BranchlinesComposition ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Catch ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Encounter ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.FloatlinesComposition ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.GearUseFeatures ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.GearUseFeaturesMeasurement ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.HooksComposition ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Section ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.SensorUsed ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Set ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.SizeMeasure ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Tdr ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.TdrRecord ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Trip ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.WeightMeasure ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Country ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.DataQuality ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.FpaZone ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Gear ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.GearCaracteristic ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.GearCaracteristicType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Harbour ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.LastUpdateDate ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.LengthLengthParameter ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.LengthWeightParameter ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Ocean ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Organism ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Person ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Program ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Sex ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.ShipOwner ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.SizeMeasureType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Species ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.SpeciesGroup ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.SpeciesGroupReleaseMode ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.SpeciesList ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.Vessel ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.VesselSizeCategory ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.VesselType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_common.WeightMeasureType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.BaitHaulingStatus ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.BaitSettingStatus ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.BaitType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.CatchFate ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.EncounterType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.Healthness ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.HookPosition ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.HookSize ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.HookType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.ItemHorizontalPosition ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.ItemVerticalPosition ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.LightsticksColor ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.LightsticksType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.LineType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.MaturityStatus ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.MitigationType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.SensorBrand ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.SensorDataFormat ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.SensorType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.SettingShape ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.StomacFullness ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.TripType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_longline.VesselActivity ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.DetectionMode ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.NonTargetCatchReleaseConformity ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.NonTargetCatchReleaseStatus ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.NonTargetCatchReleasingTime ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ObjectMaterial ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ObjectMaterialType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ObjectOperation ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ObservedSystem ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ReasonForDiscard ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ReasonForNoFishing ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ReasonForNullSet ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.SpeciesFate ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.SpeciesStatus ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.SurroundingActivity ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.TransmittingBuoyOperation ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.TransmittingBuoyType ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.VesselActivity ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.WeightCategory ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.Wind ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.Activity ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.FloatingObject ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.FloatingObjectPart ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.GearUseFeaturesMeasurement ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.GearUseFeatures ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.NonTargetCatch ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.NonTargetCatchRelease ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.NonTargetLength ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.NonTargetSample ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ObjectObservedSpecies ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.ObjectSchoolEstimate ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.Route ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.SchoolEstimate ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.Set ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.TargetCatch ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.TargetLength ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.TargetSample ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.TransmittingBuoy ALTER COLUMN topiaCreateDate SET NOT NULL; +ALTER TABLE observe_seine.Trip ALTER COLUMN topiaCreateDate SET NOT NULL; ===================================== pom.xml ===================================== @@ -165,7 +165,7 @@ <lib.version.java4all.eugene>3.0-alpha-26</lib.version.java4all.eugene> <!--lib.version.java4all.jaxx>3.0-alpha-50</lib.version.java4all.jaxx--> <!--<lib.version.java4all.i18n>4.0-beta-8-SNAPSHOT</lib.version.java4all.i18n>--> - <lib.version.java4all.topia>1.1.15</lib.version.java4all.topia> + <lib.version.java4all.topia>1.1.16</lib.version.java4all.topia> <!--<lib.version.nuiton.topia>3.6-SNAPSHOT</lib.version.nuiton.topia>--> <!--<lib.version.java4all.eugene>3.0-alpha-21</lib.version.java4all.eugene>--> ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/synchro/referential/ng/ReferentialSynchronizeSqlsRequestBuilder.java ===================================== @@ -22,8 +22,10 @@ package fr.ird.observe.services.local.service.actions.synchro.referential.ng; * #L% */ +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; import fr.ird.observe.binder.referential.ReferentialEntityDtoBinderSupport; import fr.ird.observe.dto.reference.ReferentialDtoReference; import fr.ird.observe.dto.referential.ReferentialDto; @@ -90,14 +92,17 @@ public class ReferentialSynchronizeSqlsRequestBuilder { ImmutableSet<Class<? extends ReferentialDtoReference>> types = request.getTypes(); + + Multimap<Class<? extends ReferentialDtoReference>, String> newIds = request.getNewIds(); + for (Class<? extends ReferentialDto> dtoType : DtoModelClasses.REFERENTIAL_TYPES) { - build0(dtoType, types); + build0(dtoType, types, newIds); } return resultBuilder.build(); } - private <D extends ReferentialDto, R extends ReferentialDtoReference<D, R>, E extends ObserveReferentialEntity> void build0(Class<D> dtoType, ImmutableSet<Class<? extends ReferentialDtoReference>> types) { + private <D extends ReferentialDto, R extends ReferentialDtoReference<D, R>, E extends ObserveReferentialEntity> void build0(Class<D> dtoType, ImmutableSet<Class<? extends ReferentialDtoReference>> types, Multimap<Class<? extends ReferentialDtoReference>, String> newIds) { ReferentialDtoEntityContext<D, R, E> modelContext = DbModelHelper.fromReferentialDto(dtoType); Class<R> referenceType = modelContext.toReferenceType(); @@ -117,13 +122,13 @@ public class ReferentialSynchronizeSqlsRequestBuilder { if (log.isInfoEnabled()) { log.info("Add: " + addTasks.size()); } - onAdd(referentialName, referenceType, addTasks, binder); + onAdd(referentialName, referenceType, addTasks, binder, newIds); Set<ReferentialSynchronizeTask<R>> updateTasks = request.getUpdateTasks(referenceType); if (log.isInfoEnabled()) { log.info("Update: " + updateTasks.size()); } - onUpdate(referentialName, referenceType, updateTasks, binder); + onUpdate(referentialName, referenceType, updateTasks, binder, newIds); Set<ReferentialSynchronizeTask<R>> revertTasks = request.getRevertTasks(referenceType); if (log.isInfoEnabled()) { @@ -145,7 +150,7 @@ public class ReferentialSynchronizeSqlsRequestBuilder { } - private <D extends ReferentialDto, R extends ReferentialDtoReference<D, R>, E extends ObserveReferentialEntity> void onAdd(String referentialName, Class<R> referenceType, Set<ReferentialSynchronizeTask<R>> tasks, ReferentialEntityDtoBinderSupport<D, E> binder) { + private <D extends ReferentialDto, R extends ReferentialDtoReference<D, R>, E extends ObserveReferentialEntity> void onAdd(String referentialName, Class<R> referenceType, Set<ReferentialSynchronizeTask<R>> tasks, ReferentialEntityDtoBinderSupport<D, E> binder, Multimap<Class<? extends ReferentialDtoReference>, String> newIds) { Class<E> entityType = binder.getEntityType(); Class<D> dtoType = binder.getDtoType(); @@ -153,7 +158,9 @@ public class ReferentialSynchronizeSqlsRequestBuilder { List<E> insertEntities = loadEntities(entityType, tasks); if (metadata.withEntities()) { - InsertSqlWithCascadeStatementGenerator<D> insertGenerator = new InsertSqlWithCascadeStatementGenerator<D>(metadataModel, metadata, dtoType, request.getIdsOnlyExistingOnThisSide()) { + Multimap<Class<? extends ReferentialDtoReference>, String> allIds = ArrayListMultimap.create(request.getIdsOnlyExistingOnThisSide()); + allIds.putAll(newIds); + InsertSqlWithCascadeStatementGenerator<D> insertGenerator = new InsertSqlWithCascadeStatementGenerator<D>(metadataModel, metadata, dtoType, allIds) { @Override protected <DD extends ReferentialDto> ImmutableList<String> insertMissingReferential(Class<DD> referentialType, String id) { @@ -188,7 +195,7 @@ public class ReferentialSynchronizeSqlsRequestBuilder { } - private <D extends ReferentialDto, R extends ReferentialDtoReference<D, R>, E extends ObserveReferentialEntity> void onUpdate(String referentialName, Class<R> referenceType, Set<ReferentialSynchronizeTask<R>> tasks, ReferentialEntityDtoBinderSupport<D, E> binder) { + private <D extends ReferentialDto, R extends ReferentialDtoReference<D, R>, E extends ObserveReferentialEntity> void onUpdate(String referentialName, Class<R> referenceType, Set<ReferentialSynchronizeTask<R>> tasks, ReferentialEntityDtoBinderSupport<D, E> binder, Multimap<Class<? extends ReferentialDtoReference>, String> newIds) { Class<D> dtoType = binder.getDtoType(); TopiaMetadataEntity metadata = metadataModel.getEntity(referentialName); @@ -197,6 +204,10 @@ public class ReferentialSynchronizeSqlsRequestBuilder { if (metadata.withEntities()) { + + Multimap<Class<? extends ReferentialDtoReference>, String> allIds = ArrayListMultimap.create(request.getIdsOnlyExistingOnThisSide()); + allIds.putAll(newIds); + UpdateSqlWithCascadeStatementGenerator<D> updateGenerator = new UpdateSqlWithCascadeStatementGenerator<D>(metadataModel, metadata, dtoType, request.getIdsOnlyExistingOnThisSide()) { @Override ===================================== services/src/main/java/fr/ird/observe/services/service/actions/synchro/referential/ng/ReferentialSynchronizeRequest.java ===================================== @@ -71,6 +71,14 @@ public class ReferentialSynchronizeRequest implements ObserveDto { return idsOnlyExistingOnThisSide; } + public Multimap<Class<? extends ReferentialDtoReference>, String> getNewIds() { + Multimap<Class<? extends ReferentialDtoReference>, String> result = ArrayListMultimap.create(); + for (ReferentialSynchronizeTask<?> task : tasks.get(ReferentialSynchronizeTaskType.ADD)) { + result.put(task.getReferentialType(), task.getReferentialId()); + } + return result; + } + public ImmutableMultimap<ReferentialSynchronizeTaskType, ReferentialSynchronizeTask<?>> getTasks() { return tasks; } ===================================== test/src/main/resources/db/7.1/dataForTestLongline.sql.gz ===================================== Binary files a/test/src/main/resources/db/7.1/dataForTestLongline.sql.gz and b/test/src/main/resources/db/7.1/dataForTestLongline.sql.gz differ ===================================== test/src/main/resources/db/7.1/dataForTestSeine.sql.gz ===================================== Binary files a/test/src/main/resources/db/7.1/dataForTestSeine.sql.gz and b/test/src/main/resources/db/7.1/dataForTestSeine.sql.gz differ ===================================== test/src/main/resources/db/7.1/empty_h2.sql.gz ===================================== Binary files a/test/src/main/resources/db/7.1/empty_h2.sql.gz and b/test/src/main/resources/db/7.1/empty_h2.sql.gz differ ===================================== test/src/main/resources/db/7.1/empty_pg.sql.gz ===================================== Binary files a/test/src/main/resources/db/7.1/empty_pg.sql.gz and b/test/src/main/resources/db/7.1/empty_pg.sql.gz differ ===================================== test/src/main/resources/db/7.1/referentiel.sql.gz ===================================== Binary files a/test/src/main/resources/db/7.1/referentiel.sql.gz and b/test/src/main/resources/db/7.1/referentiel.sql.gz differ View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/35286e05f0d60e0e89bf4b10ae7... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/compare/35286e05f0d60e0e89bf4b10ae7... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT