Tony CHEMIT pushed to branch develop-9.0.x at ultreiaio / ird-observe

Commits:

8 changed files:

Changes:

  • core/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_0.java
    ... ... @@ -32,14 +32,10 @@ import org.apache.logging.log4j.Logger;
    32 32
     import org.nuiton.topia.service.migration.resources.MigrationVersionResource;
    
    33 33
     import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor;
    
    34 34
     
    
    35
    -import java.sql.PreparedStatement;
    
    36
    -import java.sql.ResultSet;
    
    37 35
     import java.util.LinkedHashSet;
    
    38 36
     import java.util.List;
    
    39 37
     import java.util.Map;
    
    40 38
     import java.util.Set;
    
    41
    -import java.util.TreeMap;
    
    42
    -import java.util.function.Function;
    
    43 39
     import java.util.stream.Stream;
    
    44 40
     
    
    45 41
     /**
    
    ... ... @@ -57,6 +53,7 @@ public class DataSourceMigrationForVersion_9_0 extends ByMajorMigrationVersionRe
    57 53
         public static final String INFORMATION_SOURCE_U = "fr.ird.referential.ps.observation.InformationSource#1464000000000#03";
    
    58 54
         public static final String SPECIES_FATE_5 = "fr.ird.referential.ps.common.SpeciesFate#1239832683619#0.6250731662108877";
    
    59 55
         public static final String SPECIES_FATE_6 = "fr.ird.referential.ps.common.SpeciesFate#1239832683619#0.5722739932065866";
    
    56
    +    public static final String DEFAULT_WEIGHT_MEASURE_METHOD = "fr.ird.referential.common.WeightMeasureMethod#666#03";
    
    60 57
         public static final Set<String> SMALL_SPECIES_TO_SPECIES_FATE_6 =
    
    61 58
                 Set.of("fr.ird.referential.common.Species#1239832685476#0.5618871286604711", //ALB
    
    62 59
                        "fr.ird.referential.common.Species#1239832685475#0.13349466123905152", //BET
    
    ... ... @@ -158,14 +155,14 @@ public class DataSourceMigrationForVersion_9_0 extends ByMajorMigrationVersionRe
    158 155
                 executor.addScript("03_1", "migrate-table-ps_observation_nonTargetCatch");
    
    159 156
     
    
    160 157
                 // migrate TargetCatch
    
    161
    -            migrateCatches(executor);
    
    158
    +            TargetCatchRecord.processTargetCatches(executor);
    
    162 159
     
    
    163 160
                 // To fix well
    
    164 161
                 executor.addScript("03_2", "migrate-table-ps_observation_catch_well");
    
    165 162
     
    
    166 163
                 // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2436
    
    167 164
                 // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2539
    
    168
    -            migrateSample(executor);
    
    165
    +            SampleRecord.processSample(executor);
    
    169 166
             }
    
    170 167
     
    
    171 168
             executor.addScript("04_0", "adapt_table-ps_observation_activity");
    
    ... ... @@ -258,60 +255,6 @@ public class DataSourceMigrationForVersion_9_0 extends ByMajorMigrationVersionRe
    258 255
             }
    
    259 256
         }
    
    260 257
     
    
    261
    -    private void migrateCatches(MigrationVersionResourceExecutor executor) {
    
    262
    -
    
    263
    -        Function<String, String> commentFormat = executor.commentFormat();
    
    264
    -        Map<String, WeightCategoryRecord> weightCategoryRecordById = WeightCategoryRecord.loadWeightCategoriesMap(executor);
    
    265
    -
    
    266
    -        executor.doSqlWork(connection -> {
    
    267
    -            // process discarded values
    
    268
    -            try (PreparedStatement statement = DiscardedTargetCatchRecord.prepareStatement(connection)) {
    
    269
    -                try (ResultSet resultSet = statement.executeQuery()) {
    
    270
    -                    while (resultSet.next()) {
    
    271
    -                        DiscardedTargetCatchRecord record = new DiscardedTargetCatchRecord(resultSet);
    
    272
    -                        executor.writeSql(record.toCatchSql(weightCategoryRecordById, commentFormat));
    
    273
    -                    }
    
    274
    -                }
    
    275
    -            }
    
    276
    -            // process not discarded values
    
    277
    -            try (PreparedStatement statement = NotDiscardedTargetCatchRecord.prepareStatement(connection)) {
    
    278
    -                try (ResultSet resultSet = statement.executeQuery()) {
    
    279
    -                    while (resultSet.next()) {
    
    280
    -                        NotDiscardedTargetCatchRecord record = new NotDiscardedTargetCatchRecord(resultSet);
    
    281
    -                        executor.writeSql(record.toCatchSql(weightCategoryRecordById, commentFormat));
    
    282
    -                    }
    
    283
    -                }
    
    284
    -            }
    
    285
    -        });
    
    286
    -    }
    
    287
    -
    
    288
    -
    
    289
    -    private void migrateSample(MigrationVersionResourceExecutor executor) {
    
    290
    -
    
    291
    -        Map<String, SampleRecord> setToSampleMap = new TreeMap<>();
    
    292
    -        Map<String, String> sampleMapping = new TreeMap<>();
    
    293
    -
    
    294
    -        executor.doSqlWork(connection -> {
    
    295
    -            SampleRecord.addNonTargetSample(connection, setToSampleMap, sampleMapping);
    
    296
    -            SampleRecord.addTargetSample(connection, setToSampleMap, sampleMapping);
    
    297
    -        });
    
    298
    -
    
    299
    -        Function<String, String> stringFormat = executor.commentFormat();
    
    300
    -        for (SampleRecord sample : setToSampleMap.values()) {
    
    301
    -            executor.writeSql(sample.toSampleSql(stringFormat));
    
    302
    -        }
    
    303
    -
    
    304
    -        migrateSampleMeasure(executor, sampleMapping);
    
    305
    -    }
    
    306
    -
    
    307
    -    private void migrateSampleMeasure(MigrationVersionResourceExecutor executor, Map<String, String> sampleMapping) {
    
    308
    -        executor.doSqlWork(connection -> {
    
    309
    -            SampleMeasureRecord.addNonTargetSampleMeasure(connection, executor, sampleMapping);
    
    310
    -            SampleMeasureRecord.addDiscardedTargetSampleMeasure(connection, executor, sampleMapping);
    
    311
    -            SampleMeasureRecord.addNotDiscardedTargetSampleMeasure(connection, executor, sampleMapping);
    
    312
    -        });
    
    313
    -    }
    
    314
    -
    
    315 258
         @Override
    
    316 259
         public void generateFinalizeSqlScript(MigrationVersionResourceExecutor executor) {
    
    317 260
             long stringFixedCount = new FixStringHelper(executor).execute();
    

  • core/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/DiscardedTargetCatchRecord.java deleted
    1
    -package fr.ird.observe.spi.migration.v9;
    
    2
    -
    
    3
    -/*-
    
    4
    - * #%L
    
    5
    - * ObServe Core :: Persistence :: Resources
    
    6
    - * %%
    
    7
    - * Copyright (C) 2008 - 2022 IRD, 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 fr.ird.observe.dto.StringCleaner;
    
    26
    -import fr.ird.observe.persistence.SqlHelper;
    
    27
    -import fr.ird.observe.spi.context.DataDtoEntityContext;
    
    28
    -
    
    29
    -import java.sql.Connection;
    
    30
    -import java.sql.PreparedStatement;
    
    31
    -import java.sql.ResultSet;
    
    32
    -import java.sql.SQLException;
    
    33
    -import java.sql.Timestamp;
    
    34
    -import java.util.Map;
    
    35
    -import java.util.function.Function;
    
    36
    -
    
    37
    -/**
    
    38
    - * Created on 06/11/2022.
    
    39
    - *
    
    40
    - * @author Tony Chemit - dev@tchemit.fr
    
    41
    - * @since 9.0.17
    
    42
    - */
    
    43
    -public class DiscardedTargetCatchRecord {
    
    44
    -
    
    45
    -    private final String id;
    
    46
    -    private final long topiaVersion;
    
    47
    -    private final Timestamp topiaCreateDate;
    
    48
    -    private final String homeId;
    
    49
    -    private final Float catchWeight;
    
    50
    -    private final String weightCategoryId;
    
    51
    -    private final String comment;
    
    52
    -    private final String reasonForDiscardId;
    
    53
    -    private final String setId;
    
    54
    -    private final Timestamp lastUpdateDate;
    
    55
    -    private final String well;
    
    56
    -    private final long setIdx;
    
    57
    -    private final String weightMeasureMethodId;
    
    58
    -
    
    59
    -    public static PreparedStatement prepareStatement(Connection connection) throws SQLException {
    
    60
    -        return connection.prepareStatement("SELECT" +
    
    61
    -                                                   /* 01 */      " REPLACE(tc.topiaId, '.TargetCatch', '.Catch')," +
    
    62
    -                                                   /* 02 */      " tc.topiaVersion + 1," +
    
    63
    -                                                   /* 03 */      " tc.topiaCreateDate," +
    
    64
    -                                                   /* 04 */      " tc.homeId," +
    
    65
    -                                                   /* 05 */      " tc.catchWeight," +
    
    66
    -                                                   /* 06 */      " tc.weightCategory," +
    
    67
    -                                                   /* 07 */      " tc.comment," +
    
    68
    -                                                   /* 08 */      " tc.reasonForDiscard," +
    
    69
    -                                                   /* 09 */      " tc.set," +
    
    70
    -                                                   /* 10 */      " tc.lastUpdateDate," +
    
    71
    -                                                   /* 11 */      " tc.well," +
    
    72
    -                                                   /* 12 */      " -tc.set_idx," +
    
    73
    -                                                   /* 13 */      " tc.weightMeasureMethod" +
    
    74
    -                                                   " FROM ps_observation.TargetCatch tc" +
    
    75
    -                                                   " WHERE tc.discarded");
    
    76
    -    }
    
    77
    -
    
    78
    -    public DiscardedTargetCatchRecord(ResultSet resultSet) throws SQLException {
    
    79
    -        this.id = resultSet.getString(1);
    
    80
    -        this.topiaVersion = resultSet.getLong(2);
    
    81
    -        this.topiaCreateDate = resultSet.getTimestamp(3);
    
    82
    -        this.homeId = resultSet.getString(4);
    
    83
    -        this.catchWeight = resultSet.getFloat(5);
    
    84
    -        this.weightCategoryId = resultSet.getString(6);
    
    85
    -        this.comment = resultSet.getString(7);
    
    86
    -        this.reasonForDiscardId = resultSet.getString(8);
    
    87
    -        this.setId = resultSet.getString(9);
    
    88
    -        this.lastUpdateDate = resultSet.getTimestamp(10);
    
    89
    -        this.well = resultSet.getString(11);
    
    90
    -        this.setIdx = resultSet.getLong(12);
    
    91
    -        this.weightMeasureMethodId = resultSet.getString(13);
    
    92
    -    }
    
    93
    -
    
    94
    -    public String toCatchSql(Map<String, WeightCategoryRecord> weightCategoryRecordById, Function<String, String> commentFormat) {
    
    95
    -        WeightCategoryRecord weightCategoryRecord = weightCategoryRecordById.get(weightCategoryId);
    
    96
    -        if (weightCategoryRecord == null) {
    
    97
    -            throw new IllegalStateException(String.format("Could not find weightCategory with id: %s", weightCategoryId));
    
    98
    -        }
    
    99
    -        return String.format("INSERT INTO ps_observation.Catch(" +
    
    100
    -                                     /*1*/                       "topiaId, " +
    
    101
    -                                     /*2*/                       "topiaVersion, " +
    
    102
    -                                     /*3*/                       "topiaCreateDate, " +
    
    103
    -                                     /*4*/                       "homeId, " +
    
    104
    -                                     /*5*/                       "catchWeight, " +
    
    105
    -                                     /*6*/                       "minWeight, " +
    
    106
    -                                     /*7*/                       "maxWeight, " +
    
    107
    -                                     /*8*/                       "meanWeight, " +
    
    108
    -                                     /*9*/                       "comment, " +
    
    109
    -                                     /*10*/                      "reasonForDiscard, " +
    
    110
    -                                     /*11*/                      "species, " +
    
    111
    -                                     /*12*/                      "speciesFate, " +
    
    112
    -                                     /*13*/                      "set, " +
    
    113
    -                                     /*14*/                      "lastUpdateDate, " +
    
    114
    -                                     /*15*/                      "well, " +
    
    115
    -                                     /*16*/                      "set_idx, " +
    
    116
    -                                     /*17*/                      "weightMeasureMethod, " +
    
    117
    -                                     /*18*/                      "informationSource) VALUES ( " +
    
    118
    -                                     "%1$s, " +
    
    119
    -                                     "%2$s, " +
    
    120
    -                                     "'%3$s'::timestamp, " +
    
    121
    -                                     "%4$s, " +
    
    122
    -                                     "%5$s, " +
    
    123
    -                                     "%6$s, " +
    
    124
    -                                     "%7$s, " +
    
    125
    -                                     "%8$s, " +
    
    126
    -                                     "%9$s, " +
    
    127
    -                                     "%10$s, " +
    
    128
    -                                     "%11$s, " +
    
    129
    -                                     "%12$s, " +
    
    130
    -                                     "%13$s, " +
    
    131
    -                                     "'%14$s'::timestamp, " +
    
    132
    -                                     "%15$s, " +
    
    133
    -                                     "%16$s, " +
    
    134
    -                                     "%17$s, " +
    
    135
    -                                     "%18$s" +
    
    136
    -                                     ");",
    
    137
    -                /*1*/                SqlHelper.escapeString(id),
    
    138
    -                /*2*/                topiaVersion,
    
    139
    -                /*3*/                DataDtoEntityContext.timestamp(topiaCreateDate),
    
    140
    -                /*4*/                SqlHelper.escapeString(StringCleaner.ALL.apply(homeId)),
    
    141
    -                /*5*/                catchWeight,
    
    142
    -                /*6*/                weightCategoryRecord.getMinWeight(),
    
    143
    -                /*7*/                weightCategoryRecord.getMaxWeight(),
    
    144
    -                /*8*/                null,
    
    145
    -                /*9*/                getComment(weightCategoryRecord, commentFormat),
    
    146
    -                /*10*/               SqlHelper.escapeString(reasonForDiscardId),
    
    147
    -                /*11*/               SqlHelper.escapeString(weightCategoryRecord.getSpeciesId()),
    
    148
    -                /*12*/               SqlHelper.escapeString(DataSourceMigrationForVersion_9_0.SPECIES_FATE_5),
    
    149
    -                /*13*/               SqlHelper.escapeString(setId),
    
    150
    -                /*14*/               DataDtoEntityContext.timestamp(lastUpdateDate),
    
    151
    -                /*15*/               SqlHelper.escapeString(StringCleaner.ALL.apply(well)),
    
    152
    -                /*16*/               setIdx,
    
    153
    -                /*17*/               SqlHelper.escapeString(weightMeasureMethodId == null ? "fr.ird.referential.common.WeightMeasureMethod#666#03" : weightCategoryId),
    
    154
    -                /*18*/               SqlHelper.escapeString(DataSourceMigrationForVersion_9_0.INFORMATION_SOURCE_O)
    
    155
    -        );
    
    156
    -    }
    
    157
    -
    
    158
    -    public String getComment(WeightCategoryRecord weightCategoryRecord, Function<String, String> stringFormat) {
    
    159
    -        if (comment == null) {
    
    160
    -            return stringFormat.apply(weightCategoryRecord.toComment());
    
    161
    -        }
    
    162
    -        return stringFormat.apply(comment + "\n" + weightCategoryRecord.toComment());
    
    163
    -    }
    
    164
    -
    
    165
    -}

  • core/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/SampleMeasureRecord.java
    ... ... @@ -22,7 +22,9 @@ package fr.ird.observe.spi.migration.v9;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    +import fr.ird.observe.dto.StringCleaner;
    
    25 26
     import fr.ird.observe.persistence.SqlHelper;
    
    27
    +import fr.ird.observe.spi.context.DataDtoEntityContext;
    
    26 28
     import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor;
    
    27 29
     
    
    28 30
     import java.sql.Connection;
    
    ... ... @@ -31,7 +33,7 @@ import java.sql.ResultSet;
    31 33
     import java.sql.SQLException;
    
    32 34
     import java.sql.Timestamp;
    
    33 35
     import java.util.Map;
    
    34
    -import java.util.function.Function;
    
    36
    +import java.util.function.BiFunction;
    
    35 37
     
    
    36 38
     /**
    
    37 39
      * Created on 20/11/2022.
    
    ... ... @@ -129,17 +131,16 @@ class SampleMeasureRecord {
    129 131
                              SampleMeasureRecord::toNotDiscardedTargetSpeciesFate);
    
    130 132
         }
    
    131 133
     
    
    132
    -    static void addSampleMeasure(Connection connection, MigrationVersionResourceExecutor executor, Map<String, String> sampleMapping, String query, Function<SampleMeasureRecord, String> speciesFateSupplier) throws SQLException {
    
    133
    -
    
    134
    +    static void addSampleMeasure(Connection connection,
    
    135
    +                                 MigrationVersionResourceExecutor executor,
    
    136
    +                                 Map<String, String> sampleMapping,
    
    137
    +                                 String query,
    
    138
    +                                 BiFunction<SampleMeasureRecord, String, String> speciesFateSupplier) throws SQLException {
    
    134 139
             try (PreparedStatement statement = connection.prepareStatement(query)) {
    
    135 140
                 try (ResultSet resultSet = statement.executeQuery()) {
    
    136 141
                     while (resultSet.next()) {
    
    137
    -                    SampleMeasureRecord sampleMeasure = new SampleMeasureRecord(resultSet);
    
    138
    -                    String sampleId = sampleMapping.get(sampleMeasure.sample);
    
    139
    -                    if (sampleId == null) {
    
    140
    -                        sampleId = sampleMeasure.sample;
    
    141
    -                    }
    
    142
    -                    executor.writeSql(sampleMeasure.toSampleMeasureSql(sampleId, speciesFateSupplier));
    
    142
    +                    SampleMeasureRecord sampleMeasure = new SampleMeasureRecord(resultSet, sampleMapping, speciesFateSupplier);
    
    143
    +                    executor.writeSql(sampleMeasure.toSql());
    
    143 144
                     }
    
    144 145
                 }
    
    145 146
             }
    
    ... ... @@ -158,7 +159,7 @@ class SampleMeasureRecord {
    158 159
         int count;
    
    159 160
         int acquisitionMode;
    
    160 161
         String species;
    
    161
    -    String sample;
    
    162
    +    String sampleId;
    
    162 163
         String sex;
    
    163 164
         String sizeMeasureType;
    
    164 165
         String weightMeasureType;
    
    ... ... @@ -168,35 +169,9 @@ class SampleMeasureRecord {
    168 169
         String lengthMeasureMethod;
    
    169 170
         String weightMeasureMethod;
    
    170 171
     
    
    171
    -
    
    172
    -    private String toNonTargetSpeciesFate() {
    
    173
    -        if (speciesFate == null) {
    
    174
    -            return null;
    
    175
    -        }
    
    176
    -        if (DataSourceMigrationForVersion_9_0.SPECIES_FATE_6.equals(speciesFate)) {
    
    177
    -            // like for non target catches always change from speciesFate 6 to 15
    
    178
    -            speciesFate = DataSourceMigrationForVersion_9_0.SPECIES_FATE_15;
    
    179
    -        }
    
    180
    -        return speciesFate;
    
    181
    -    }
    
    182
    -
    
    183
    -    private String toDiscardedTargetSpeciesFate() {
    
    184
    -        // Discarded target species use always speciesFate 5 (and we have it from the sql query)
    
    185
    -        return speciesFate;
    
    186
    -
    
    187
    -    }
    
    188
    -
    
    189
    -    private String toNotDiscardedTargetSpeciesFate() {
    
    190
    -        // by default we use in sql query speciesFate = 6
    
    191
    -        // for small species, they are always with speciesFate = 15
    
    192
    -
    
    193
    -        if (!DataSourceMigrationForVersion_9_0.SMALL_SPECIES_TO_SPECIES_FATE_6.contains(species)) {
    
    194
    -            speciesFate = DataSourceMigrationForVersion_9_0.SPECIES_FATE_15;
    
    195
    -        }
    
    196
    -        return speciesFate;
    
    197
    -    }
    
    198
    -
    
    199
    -    public SampleMeasureRecord(ResultSet resultSet) throws SQLException {
    
    172
    +    public SampleMeasureRecord(ResultSet resultSet,
    
    173
    +                               Map<String, String> sampleMapping,
    
    174
    +                               BiFunction<SampleMeasureRecord, String, String> speciesFateSupplier) throws SQLException {
    
    200 175
             this.topiaId = resultSet.getString(1);
    
    201 176
             this.topiaVersion = resultSet.getLong(2);
    
    202 177
             this.topiaCreateDate = resultSet.getTimestamp(3);
    
    ... ... @@ -209,13 +184,16 @@ class SampleMeasureRecord {
    209 184
             this.count = resultSet.getInt(10);
    
    210 185
             this.acquisitionMode = resultSet.getInt(11);
    
    211 186
             this.species = resultSet.getString(12);
    
    212
    -        this.sample = resultSet.getString(13);
    
    187
    +        String originalSampleId = resultSet.getString(13);
    
    188
    +        String replaceSampleId = sampleMapping.get(originalSampleId);
    
    189
    +        this.sampleId = replaceSampleId == null ? originalSampleId : replaceSampleId;
    
    213 190
             this.sex = resultSet.getString(14);
    
    214 191
             this.lastUpdateDate = resultSet.getTimestamp(15);
    
    215 192
             this.sizeMeasureType = resultSet.getString(16);
    
    216 193
             this.weightMeasureType = resultSet.getString(17);
    
    217 194
             this.tagNumber = resultSet.getString(18);
    
    218
    -        this.speciesFate = resultSet.getString(19);
    
    195
    +        String originalSpeciesFate = resultSet.getString(19);
    
    196
    +        this.speciesFate = speciesFateSupplier.apply(this, originalSpeciesFate);
    
    219 197
             this.sample_idx = resultSet.getInt(20);
    
    220 198
             this.lengthMeasureMethod = resultSet.getString(21);
    
    221 199
             this.weightMeasureMethod = resultSet.getString(22);
    
    ... ... @@ -225,7 +203,7 @@ class SampleMeasureRecord {
    225 203
             }
    
    226 204
         }
    
    227 205
     
    
    228
    -    String toSampleMeasureSql(String sampleId, Function<SampleMeasureRecord, String> speciesFateSupplier) {
    
    206
    +    String toSql() {
    
    229 207
             return String.format("INSERT INTO ps_observation.SampleMeasure(" +
    
    230 208
                                          " topiaId," +
    
    231 209
                                          " topiaVersion," +
    
    ... ... @@ -250,9 +228,7 @@ class SampleMeasureRecord {
    250 228
                                          " lengthMeasureMethod," +
    
    251 229
                                          " weightMeasureMethod)" +
    
    252 230
                                          " VALUES(" +
    
    253
    -                                     "'%s', " +
    
    254 231
                                          "%s, " +
    
    255
    -                                     "'%s'::timestamp, " +
    
    256 232
                                          "%s, " +
    
    257 233
                                          "%s, " +
    
    258 234
                                          "%s, " +
    
    ... ... @@ -262,9 +238,11 @@ class SampleMeasureRecord {
    262 238
                                          "%s, " +
    
    263 239
                                          "%s, " +
    
    264 240
                                          "%s, " +
    
    265
    -                                     "'%s', " +
    
    266 241
                                          "%s, " +
    
    267
    -                                     "'%s'::timestamp, " +
    
    242
    +                                     "%s, " +
    
    243
    +                                     "%s, " +
    
    244
    +                                     "%s, " +
    
    245
    +                                     "%s, " +
    
    268 246
                                          "%s, " +
    
    269 247
                                          "%s, " +
    
    270 248
                                          "%s, " +
    
    ... ... @@ -273,29 +251,53 @@ class SampleMeasureRecord {
    273 251
                                          "%s, " +
    
    274 252
                                          "%s " +
    
    275 253
                                          ");",
    
    276
    -                             topiaId,
    
    254
    +                             SqlHelper.escapeString(topiaId),
    
    277 255
                                  topiaVersion,
    
    278
    -                             topiaCreateDate,
    
    279
    -                             SqlHelper.escapeString(homeId == null ? null : homeId.replaceAll("'", "")),
    
    256
    +                             DataDtoEntityContext.toTimeStamp(topiaCreateDate),
    
    257
    +                             SqlHelper.escapeString(StringCleaner.ALL.apply(homeId)),
    
    280 258
                                  length,
    
    281 259
                                  isLengthComputed,
    
    282
    -                             SqlHelper.escapeString(picturesReferences == null ? null : picturesReferences.replaceAll("'", "")),
    
    260
    +                             SqlHelper.escapeString(StringCleaner.ALL.apply(picturesReferences)),
    
    283 261
                                  weight,
    
    284 262
                                  isWeightComputed,
    
    285 263
                                  count,
    
    286 264
                                  acquisitionMode,
    
    287 265
                                  SqlHelper.escapeString(species),
    
    288
    -                             sampleId,
    
    266
    +                             SqlHelper.escapeString(sampleId),
    
    289 267
                                  SqlHelper.escapeString(sex),
    
    290
    -                             lastUpdateDate,
    
    268
    +                             DataDtoEntityContext.toTimeStamp(lastUpdateDate),
    
    291 269
                                  SqlHelper.escapeString(sizeMeasureType),
    
    292 270
                                  SqlHelper.escapeString(weightMeasureType),
    
    293 271
                                  SqlHelper.escapeString(tagNumber),
    
    294
    -                             SqlHelper.escapeString(speciesFateSupplier.apply(this)),
    
    272
    +                             SqlHelper.escapeString(speciesFate),
    
    295 273
                                  sample_idx,
    
    296 274
                                  SqlHelper.escapeString(lengthMeasureMethod),
    
    297
    -                             SqlHelper.escapeString(weightMeasureMethod)
    
    298
    -        );
    
    275
    +                             SqlHelper.escapeString(weightMeasureMethod));
    
    276
    +    }
    
    277
    +
    
    278
    +    private String toNonTargetSpeciesFate(String speciesFate) {
    
    279
    +        if (speciesFate == null) {
    
    280
    +            // keep null value from NonTargetCatch
    
    281
    +            return null;
    
    282
    +        }
    
    283
    +        if (DataSourceMigrationForVersion_9_0.SPECIES_FATE_6.equals(speciesFate)) {
    
    284
    +            // like for non target catches always change from speciesFate 6 to 15
    
    285
    +            speciesFate = DataSourceMigrationForVersion_9_0.SPECIES_FATE_15;
    
    286
    +        }
    
    287
    +        return speciesFate;
    
    288
    +    }
    
    289
    +
    
    290
    +    private String toDiscardedTargetSpeciesFate(String speciesFate) {
    
    291
    +        // Discarded target species use always speciesFate 5 (and we have it from the sql query)
    
    292
    +        return speciesFate;
    
    299 293
         }
    
    300 294
     
    
    295
    +    private String toNotDiscardedTargetSpeciesFate(String speciesFate) {
    
    296
    +        // by default we use in sql query speciesFate = 6
    
    297
    +        if (!DataSourceMigrationForVersion_9_0.SMALL_SPECIES_TO_SPECIES_FATE_6.contains(species)) {
    
    298
    +            // for small species, they are always with speciesFate = 15
    
    299
    +            speciesFate = DataSourceMigrationForVersion_9_0.SPECIES_FATE_15;
    
    300
    +        }
    
    301
    +        return speciesFate;
    
    302
    +    }
    
    301 303
     }

  • core/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/SampleRecord.java
    ... ... @@ -24,6 +24,8 @@ package fr.ird.observe.spi.migration.v9;
    24 24
     
    
    25 25
     import fr.ird.observe.dto.StringCleaner;
    
    26 26
     import fr.ird.observe.persistence.SqlHelper;
    
    27
    +import fr.ird.observe.spi.context.DataDtoEntityContext;
    
    28
    +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor;
    
    27 29
     
    
    28 30
     import java.sql.Connection;
    
    29 31
     import java.sql.PreparedStatement;
    
    ... ... @@ -31,6 +33,7 @@ import java.sql.ResultSet;
    31 33
     import java.sql.SQLException;
    
    32 34
     import java.sql.Timestamp;
    
    33 35
     import java.util.Map;
    
    36
    +import java.util.TreeMap;
    
    34 37
     import java.util.function.Function;
    
    35 38
     
    
    36 39
     /**
    
    ... ... @@ -44,11 +47,26 @@ class SampleRecord {
    44 47
         final long topiaVersion;
    
    45 48
         final Timestamp topiaCreateDate;
    
    46 49
         final Timestamp lastUpdateDate;
    
    47
    -    final boolean nonTarget;
    
    48 50
         String homeId;
    
    49 51
         String comment;
    
    50 52
         String set;
    
    51 53
     
    
    54
    +    static void processSample(MigrationVersionResourceExecutor executor) {
    
    55
    +        executor.doSqlWork(connection -> {
    
    56
    +            Function<String, String> commentFormat = executor.commentFormat();
    
    57
    +            Map<String, String> sampleMapping = new TreeMap<>();
    
    58
    +            Map<String, SampleRecord> setToSampleMap = new TreeMap<>();
    
    59
    +            SampleRecord.addNonTargetSample(connection, setToSampleMap, sampleMapping);
    
    60
    +            SampleRecord.addTargetSample(connection, setToSampleMap, sampleMapping);
    
    61
    +            for (SampleRecord sample : setToSampleMap.values()) {
    
    62
    +                executor.writeSql(sample.toSql(commentFormat));
    
    63
    +            }
    
    64
    +            SampleMeasureRecord.addNonTargetSampleMeasure(connection, executor, sampleMapping);
    
    65
    +            SampleMeasureRecord.addDiscardedTargetSampleMeasure(connection, executor, sampleMapping);
    
    66
    +            SampleMeasureRecord.addNotDiscardedTargetSampleMeasure(connection, executor, sampleMapping);
    
    67
    +        });
    
    68
    +    }
    
    69
    +
    
    52 70
         static void addNonTargetSample(Connection connection, Map<String, SampleRecord> setToSampleMap, Map<String, String> sampleMapping) throws SQLException {
    
    53 71
     
    
    54 72
             try (PreparedStatement statement = connection.prepareStatement(
    
    ... ... @@ -62,7 +80,7 @@ class SampleRecord {
    62 80
                             "lastUpdateDate " +
    
    63 81
                             "FROM ps_observation.nontargetsample " +
    
    64 82
                             "ORDER BY set, topiaId")) {
    
    65
    -            addSample(statement, setToSampleMap, sampleMapping, true);
    
    83
    +            addSample(statement, setToSampleMap, sampleMapping);
    
    66 84
             }
    
    67 85
         }
    
    68 86
     
    
    ... ... @@ -79,14 +97,14 @@ class SampleRecord {
    79 97
                             "lastUpdateDate " +
    
    80 98
                             "FROM ps_observation.targetsample " +
    
    81 99
                             "ORDER BY set, topiaId")) {
    
    82
    -            addSample(statement, setToSampleMap, sampleMapping, false);
    
    100
    +            addSample(statement, setToSampleMap, sampleMapping);
    
    83 101
             }
    
    84 102
         }
    
    85 103
     
    
    86
    -    static void addSample(PreparedStatement statement, Map<String, SampleRecord> setToSampleMap, Map<String, String> sampleMapping, boolean nonTarget) throws SQLException {
    
    104
    +    static void addSample(PreparedStatement statement, Map<String, SampleRecord> setToSampleMap, Map<String, String> sampleMapping) throws SQLException {
    
    87 105
             try (ResultSet resultSet = statement.executeQuery()) {
    
    88 106
                 while (resultSet.next()) {
    
    89
    -                SampleRecord sample = new SampleRecord(resultSet, nonTarget);
    
    107
    +                SampleRecord sample = new SampleRecord(resultSet);
    
    90 108
                     SampleRecord existingSample = setToSampleMap.get(sample.set);
    
    91 109
                     if (existingSample == null) {
    
    92 110
                         // new sample
    
    ... ... @@ -103,7 +121,7 @@ class SampleRecord {
    103 121
             }
    
    104 122
         }
    
    105 123
     
    
    106
    -    public SampleRecord(ResultSet resultSet, boolean nonTarget) throws SQLException {
    
    124
    +    SampleRecord(ResultSet resultSet) throws SQLException {
    
    107 125
             this.topiaId = resultSet.getString(1);
    
    108 126
             this.topiaVersion = resultSet.getLong(2);
    
    109 127
             this.topiaCreateDate = resultSet.getTimestamp(3);
    
    ... ... @@ -111,18 +129,17 @@ class SampleRecord {
    111 129
             this.comment = resultSet.getString(5);
    
    112 130
             this.set = resultSet.getString(6);
    
    113 131
             this.lastUpdateDate = resultSet.getTimestamp(7);
    
    114
    -        this.nonTarget = nonTarget;
    
    115 132
         }
    
    116 133
     
    
    117
    -    public String toSampleSql(Function<String, String> commentFormat) {
    
    118
    -        return String.format("INSERT INTO ps_observation.Sample(topiaId, topiaVersion, topiaCreateDate, homeId, comment, set, lastUpdateDate) VALUES('%s', %s, '%s'::timestamp, %s, %s, '%s', '%s'::timestamp);",
    
    119
    -                             topiaId,
    
    134
    +    public String toSql(Function<String, String> commentFormat) {
    
    135
    +        return String.format("INSERT INTO ps_observation.Sample(topiaId, topiaVersion, topiaCreateDate, homeId, comment, set, lastUpdateDate) VALUES(%s, %s, %s, %s, %s, %s, %s);",
    
    136
    +                             SqlHelper.escapeString(topiaId),
    
    120 137
                                  topiaVersion,
    
    121
    -                             topiaCreateDate,
    
    138
    +                             DataDtoEntityContext.toTimeStamp(topiaCreateDate),
    
    122 139
                                  SqlHelper.escapeString(StringCleaner.ALL.apply(homeId)),
    
    123 140
                                  commentFormat.apply(comment),
    
    124
    -                             set,
    
    125
    -                             lastUpdateDate);
    
    141
    +                             SqlHelper.escapeString(set),
    
    142
    +                             DataDtoEntityContext.toTimeStamp(lastUpdateDate));
    
    126 143
         }
    
    127 144
     
    
    128 145
         public void addHomeId(String homeId) {
    

  • core/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/NotDiscardedTargetCatchRecord.javacore/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/TargetCatchRecord.java
    ... ... @@ -25,6 +25,7 @@ package fr.ird.observe.spi.migration.v9;
    25 25
     import fr.ird.observe.dto.StringCleaner;
    
    26 26
     import fr.ird.observe.persistence.SqlHelper;
    
    27 27
     import fr.ird.observe.spi.context.DataDtoEntityContext;
    
    28
    +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor;
    
    28 29
     
    
    29 30
     import java.sql.Connection;
    
    30 31
     import java.sql.PreparedStatement;
    
    ... ... @@ -32,6 +33,8 @@ import java.sql.ResultSet;
    32 33
     import java.sql.SQLException;
    
    33 34
     import java.sql.Timestamp;
    
    34 35
     import java.util.Map;
    
    36
    +import java.util.Set;
    
    37
    +import java.util.TreeSet;
    
    35 38
     import java.util.function.Function;
    
    36 39
     
    
    37 40
     /**
    
    ... ... @@ -40,25 +43,92 @@ import java.util.function.Function;
    40 43
      * @author Tony Chemit - dev@tchemit.fr
    
    41 44
      * @since 9.0.17
    
    42 45
      */
    
    43
    -class NotDiscardedTargetCatchRecord {
    
    46
    +public class TargetCatchRecord {
    
    44 47
     
    
    45
    -    public static PreparedStatement prepareStatement(Connection connection) throws SQLException {
    
    46
    -        return connection.prepareStatement("SELECT" +
    
    47
    -                                                   /* 01 */    " REPLACE(tc.topiaId, '.TargetCatch', '.Catch')," +
    
    48
    -                                                   /* 02 */    " tc.topiaVersion + 1," +
    
    49
    -                                                   /* 03 */    " tc.topiaCreateDate," +
    
    50
    -                                                   /* 04 */    " tc.homeId," +
    
    51
    -                                                   /* 05 */    " tc.catchWeight," +
    
    52
    -                                                   /* 06 */    " tc.weightCategory," +
    
    53
    -                                                   /* 07 */    " tc.comment," +
    
    54
    -                                                   /* 08 */    " tc.set," +
    
    55
    -                                                   /* 09 */    " tc.lastUpdateDate," +
    
    56
    -                                                   /* 10 */    " tc.well," +
    
    57
    -                                                   /* 11 */    " -tc.set_idx," +
    
    58
    -                                                   /* 12 */    " tc.weightMeasureMethod," +
    
    59
    -                                                   /* 13 */    " s.targetcatchcompositionestimatedbyobserver " +
    
    60
    -                                                   " FROM ps_observation.TargetCatch tc INNER JOIN ps_observation.set s on s.topiaId = tc.set" +
    
    61
    -                                                   " WHERE NOT tc.discarded AND NOT ( weightCategory IS NULL AND catchweight IS NULL AND well IS NULL AND broughtondeck IS NULL AND reasonfordiscard IS NULL )");
    
    48
    +    static final String DISCARDED_SQL = "SELECT" +
    
    49
    +            /* 01 */    " REPLACE(tc.topiaId, '.TargetCatch', '.Catch')," +
    
    50
    +            /* 02 */    " tc.topiaVersion + 1," +
    
    51
    +            /* 03 */    " tc.topiaCreateDate," +
    
    52
    +            /* 04 */    " tc.homeId," +
    
    53
    +            /* 05 */    " tc.catchWeight," +
    
    54
    +            /* 06 */    " tc.weightCategory," +
    
    55
    +            /* 07 */    " tc.comment," +
    
    56
    +            /* 08 */    " tc.set," +
    
    57
    +            /* 09 */    " tc.lastUpdateDate," +
    
    58
    +            /* 10 */    " tc.well," +
    
    59
    +            /* 11 */    " -tc.set_idx," +
    
    60
    +            /* 12 */    " tc.weightMeasureMethod," +
    
    61
    +            /* 13 */    " tc.reasonForDiscard" +
    
    62
    +            " FROM ps_observation.TargetCatch tc" +
    
    63
    +            " WHERE tc.discarded AND NOT ( tc.weightCategory IS NULL AND tc.catchWeight IS NULL AND tc.well IS NULL AND tc.broughtOnDeck IS NULL AND tc.reasonForDiscard IS NULL )";
    
    64
    +
    
    65
    +    static final String NOT_DISCARDED_SQL = "SELECT" +
    
    66
    +            /* 01 */    " REPLACE(tc.topiaId, '.TargetCatch', '.Catch')," +
    
    67
    +            /* 02 */    " tc.topiaVersion + 1," +
    
    68
    +            /* 03 */    " tc.topiaCreateDate," +
    
    69
    +            /* 04 */    " tc.homeId," +
    
    70
    +            /* 05 */    " tc.catchWeight," +
    
    71
    +            /* 06 */    " tc.weightCategory," +
    
    72
    +            /* 07 */    " tc.comment," +
    
    73
    +            /* 08 */    " tc.set," +
    
    74
    +            /* 09 */    " tc.lastUpdateDate," +
    
    75
    +            /* 10 */    " tc.well," +
    
    76
    +            /* 11 */    " -tc.set_idx," +
    
    77
    +            /* 12 */    " tc.weightMeasureMethod," +
    
    78
    +            /* 13 */    " s.targetCatchCompositionEstimatedByObserver " +
    
    79
    +            " FROM ps_observation.TargetCatch tc INNER JOIN ps_observation.set s on s.topiaId = tc.set" +
    
    80
    +            " WHERE NOT tc.discarded AND NOT ( tc.weightCategory IS NULL AND tc.catchWeight IS NULL AND tc.well IS NULL AND tc.broughtOnDeck IS NULL AND tc.reasonForDiscard IS NULL )";
    
    81
    +
    
    82
    +    public static void processTargetCatches(MigrationVersionResourceExecutor executor) {
    
    83
    +        // Load weight category records indexed by their id
    
    84
    +        Map<String, WeightCategoryRecord> weightCategoryRecordById = WeightCategoryRecord.loadWeightCategoriesMap(executor);
    
    85
    +        // To track target catches with no weight category
    
    86
    +        Set<String> catchesWithNullWeightCategory = new TreeSet<>();
    
    87
    +        executor.doSqlWork(connection -> {
    
    88
    +            // process discarded values
    
    89
    +            processTargetCatches(connection, executor, weightCategoryRecordById, catchesWithNullWeightCategory, true);
    
    90
    +            // process not discarded values
    
    91
    +            processTargetCatches(connection, executor, weightCategoryRecordById, catchesWithNullWeightCategory, false);
    
    92
    +        });
    
    93
    +        // can't perform migration, we found some target catches with no weight category
    
    94
    +        if (!catchesWithNullWeightCategory.isEmpty()) {
    
    95
    +            StringBuilder error = new StringBuilder();
    
    96
    +            error.append(String.format("\nFound %d target catches with null category:", catchesWithNullWeightCategory.size()));
    
    97
    +            for (String id : catchesWithNullWeightCategory) {
    
    98
    +                error.append("\n\t").append(id);
    
    99
    +            }
    
    100
    +            throw new IllegalStateException(error.toString());
    
    101
    +        }
    
    102
    +    }
    
    103
    +
    
    104
    +    static void processTargetCatches(Connection connection,
    
    105
    +                                     MigrationVersionResourceExecutor executor,
    
    106
    +                                     Map<String, WeightCategoryRecord> weightCategoryRecordById,
    
    107
    +                                     Set<String> catchesWithNullWeightCategory,
    
    108
    +                                     boolean discarded) throws SQLException {
    
    109
    +        Function<String, String> commentFormat = executor.commentFormat();
    
    110
    +        // to skip writing sql to executor as soon as a record was found with no weight category
    
    111
    +        // since this case will stop migration
    
    112
    +        boolean skipWriteSql = !catchesWithNullWeightCategory.isEmpty();
    
    113
    +        try (PreparedStatement statement = connection.prepareStatement(discarded ? DISCARDED_SQL : NOT_DISCARDED_SQL)) {
    
    114
    +            try (ResultSet resultSet = statement.executeQuery()) {
    
    115
    +                while (resultSet.next()) {
    
    116
    +                    TargetCatchRecord record = new TargetCatchRecord(resultSet, weightCategoryRecordById, discarded);
    
    117
    +                    if (record.isWeightCategoryNull()) {
    
    118
    +                        // can't process a such record,
    
    119
    +                        // just keep id of target catch for migration failure exception message
    
    120
    +                        catchesWithNullWeightCategory.add(record.getId());
    
    121
    +                        // no more need to add sql to executor
    
    122
    +                        skipWriteSql = true;
    
    123
    +                        continue;
    
    124
    +                    }
    
    125
    +                    if (skipWriteSql) {
    
    126
    +                        continue;
    
    127
    +                    }
    
    128
    +                    executor.writeSql(record.toSql(commentFormat));
    
    129
    +                }
    
    130
    +            }
    
    131
    +        }
    
    62 132
         }
    
    63 133
     
    
    64 134
         private final String id;
    
    ... ... @@ -66,36 +136,45 @@ class NotDiscardedTargetCatchRecord {
    66 136
         private final Timestamp topiaCreateDate;
    
    67 137
         private final String homeId;
    
    68 138
         private final Float catchWeight;
    
    69
    -    private final String weightCategoryId;
    
    139
    +    private final WeightCategoryRecord weightCategory;
    
    70 140
         private final String comment;
    
    141
    +    private final String reasonForDiscardId;
    
    71 142
         private final String setId;
    
    72 143
         private final Timestamp lastUpdateDate;
    
    73 144
         private final String well;
    
    74 145
         private final long setIdx;
    
    75 146
         private final String weightMeasureMethodId;
    
    76
    -    private final boolean targetCatchCompositionEstimatedByObserver;
    
    147
    +    private final String speciesFateId;
    
    148
    +    private final String informationSourceId;
    
    77 149
     
    
    78
    -    public NotDiscardedTargetCatchRecord(ResultSet resultSet) throws SQLException {
    
    150
    +    public TargetCatchRecord(ResultSet resultSet, Map<String, WeightCategoryRecord> weightCategoryRecordById, boolean discarded) throws SQLException {
    
    79 151
             this.id = resultSet.getString(1);
    
    80 152
             this.topiaVersion = resultSet.getLong(2);
    
    81 153
             this.topiaCreateDate = resultSet.getTimestamp(3);
    
    82 154
             this.homeId = resultSet.getString(4);
    
    83 155
             this.catchWeight = resultSet.getFloat(5);
    
    84
    -        this.weightCategoryId = resultSet.getString(6);
    
    156
    +        String weightCategoryId = resultSet.getString(6);
    
    157
    +        this.weightCategory = weightCategoryId == null ? null : weightCategoryRecordById.get(weightCategoryId);
    
    85 158
             this.comment = resultSet.getString(7);
    
    86 159
             this.setId = resultSet.getString(8);
    
    87 160
             this.lastUpdateDate = resultSet.getTimestamp(9);
    
    88 161
             this.well = resultSet.getString(10);
    
    89 162
             this.setIdx = resultSet.getLong(11);
    
    90
    -        this.weightMeasureMethodId = resultSet.getString(12);
    
    91
    -        this.targetCatchCompositionEstimatedByObserver = resultSet.getBoolean(13);
    
    163
    +        String weightMeasureMethodId = resultSet.getString(12);
    
    164
    +        this.weightMeasureMethodId = weightMeasureMethodId == null ? DataSourceMigrationForVersion_9_0.DEFAULT_WEIGHT_MEASURE_METHOD : weightMeasureMethodId;
    
    165
    +        if (discarded) {
    
    166
    +            this.reasonForDiscardId = resultSet.getString(13);
    
    167
    +            this.speciesFateId = DataSourceMigrationForVersion_9_0.SPECIES_FATE_5;
    
    168
    +            this.informationSourceId = DataSourceMigrationForVersion_9_0.INFORMATION_SOURCE_O;
    
    169
    +        } else {
    
    170
    +            this.reasonForDiscardId = null;
    
    171
    +            this.speciesFateId = weightCategory != null && "10".equals(weightCategory.getCode()) ? DataSourceMigrationForVersion_9_0.SPECIES_FATE_15 : DataSourceMigrationForVersion_9_0.SPECIES_FATE_6;
    
    172
    +            boolean targetCatchCompositionEstimatedByObserver = resultSet.getBoolean(13);
    
    173
    +            this.informationSourceId = targetCatchCompositionEstimatedByObserver ? DataSourceMigrationForVersion_9_0.INFORMATION_SOURCE_P : DataSourceMigrationForVersion_9_0.INFORMATION_SOURCE_U;
    
    174
    +        }
    
    92 175
         }
    
    93 176
     
    
    94
    -    public String toCatchSql(Map<String, WeightCategoryRecord> weightCategoryRecordById, Function<String, String> commentFormat) {
    
    95
    -        WeightCategoryRecord weightCategoryRecord = weightCategoryRecordById.get(weightCategoryId);
    
    96
    -        if (weightCategoryRecord == null) {
    
    97
    -            throw new IllegalStateException(String.format("Could not find weightCategory with id: %s", weightCategoryId));
    
    98
    -        }
    
    177
    +    public String toSql(Function<String, String> commentFormat) {
    
    99 178
             return String.format("INSERT INTO ps_observation.Catch(" +
    
    100 179
                                          /*1*/                  "topiaId, " +
    
    101 180
                                          /*2*/                  "topiaVersion, " +
    
    ... ... @@ -117,7 +196,7 @@ class NotDiscardedTargetCatchRecord {
    117 196
                                          /*18*/                 "informationSource) VALUES ( " +
    
    118 197
                                          "%1$s, " +
    
    119 198
                                          "%2$s, " +
    
    120
    -                                     "'%3$s'::timestamp, " +
    
    199
    +                                     "%3$s, " +
    
    121 200
                                          "%4$s, " +
    
    122 201
                                          "%5$s, " +
    
    123 202
                                          "%6$s, " +
    
    ... ... @@ -128,29 +207,29 @@ class NotDiscardedTargetCatchRecord {
    128 207
                                          "%11$s, " +
    
    129 208
                                          "%12$s, " +
    
    130 209
                                          "%13$s, " +
    
    131
    -                                     "'%14$s'::timestamp, " +
    
    210
    +                                     "%14$s, " +
    
    132 211
                                          "%15$s, " +
    
    133 212
                                          "%16$s, " +
    
    134 213
                                          "%17$s, " +
    
    135 214
                                          "%18$s);",
    
    136 215
                     /*1*/          SqlHelper.escapeString(id),
    
    137 216
                     /*2*/          topiaVersion,
    
    138
    -                /*3*/          DataDtoEntityContext.timestamp(topiaCreateDate),
    
    217
    +                /*3*/          DataDtoEntityContext.toTimeStamp(topiaCreateDate),
    
    139 218
                     /*4*/          SqlHelper.escapeString(StringCleaner.ALL.apply(homeId)),
    
    140 219
                     /*5*/          catchWeight,
    
    141
    -                /*6*/          weightCategoryRecord.getMinWeight(),
    
    142
    -                /*7*/          weightCategoryRecord.getMaxWeight(),
    
    220
    +                /*6*/          weightCategory.getMinWeight(),
    
    221
    +                /*7*/          weightCategory.getMaxWeight(),
    
    143 222
                     /*8*/          null,
    
    144
    -                /*9*/          getComment(weightCategoryRecord, commentFormat),
    
    145
    -                /*10*/         null,
    
    146
    -                /*11*/         SqlHelper.escapeString(weightCategoryRecord.getSpeciesId()),
    
    147
    -                /*12*/         SqlHelper.escapeString("10".equals(weightCategoryRecord.getCode()) ? DataSourceMigrationForVersion_9_0.SPECIES_FATE_15 : DataSourceMigrationForVersion_9_0.SPECIES_FATE_6),
    
    223
    +                /*9*/          getComment(weightCategory, commentFormat),
    
    224
    +                /*10*/         SqlHelper.escapeString(reasonForDiscardId),
    
    225
    +                /*11*/         SqlHelper.escapeString(weightCategory.getSpeciesId()),
    
    226
    +                /*12*/         SqlHelper.escapeString(speciesFateId),
    
    148 227
                     /*13*/         SqlHelper.escapeString(setId),
    
    149
    -                /*14*/         DataDtoEntityContext.timestamp(lastUpdateDate),
    
    228
    +                /*14*/         DataDtoEntityContext.toTimeStamp(lastUpdateDate),
    
    150 229
                     /*15*/         SqlHelper.escapeString(StringCleaner.ALL.apply(well)),
    
    151 230
                     /*16*/         setIdx,
    
    152
    -                /*17*/         SqlHelper.escapeString(weightMeasureMethodId == null ? "fr.ird.referential.common.WeightMeasureMethod#666#03" : weightCategoryId),
    
    153
    -                /*18*/         SqlHelper.escapeString(targetCatchCompositionEstimatedByObserver ? DataSourceMigrationForVersion_9_0.INFORMATION_SOURCE_P : DataSourceMigrationForVersion_9_0.INFORMATION_SOURCE_U)
    
    231
    +                /*17*/         SqlHelper.escapeString(weightMeasureMethodId),
    
    232
    +                /*18*/         SqlHelper.escapeString(informationSourceId)
    
    154 233
             );
    
    155 234
         }
    
    156 235
     
    
    ... ... @@ -160,4 +239,12 @@ class NotDiscardedTargetCatchRecord {
    160 239
             }
    
    161 240
             return stringFormat.apply(comment + "\n" + weightCategoryRecord.toComment());
    
    162 241
         }
    
    242
    +
    
    243
    +    public String getId() {
    
    244
    +        return id;
    
    245
    +    }
    
    246
    +
    
    247
    +    public boolean isWeightCategoryNull() {
    
    248
    +        return weightCategory == null;
    
    249
    +    }
    
    163 250
     }

  • core/persistence/resources/src/main/java/fr/ird/observe/spi/migration/v9/WeightCategoryRecord.java
    ... ... @@ -30,6 +30,8 @@ import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExec
    30 30
     
    
    31 31
     import java.util.Map;
    
    32 32
     import java.util.Set;
    
    33
    +import java.util.TreeMap;
    
    34
    +import java.util.TreeSet;
    
    33 35
     
    
    34 36
     /**
    
    35 37
      * Created on 06/11/2022.
    
    ... ... @@ -43,162 +45,208 @@ public class WeightCategoryRecord {
    43 45
         private final String code;
    
    44 46
         private final String speciesId;
    
    45 47
         private final String label1;
    
    48
    +    private final String speciesFaoCode;
    
    49
    +    private final String speciesLabel1;
    
    46 50
         private Float minWeight;
    
    47 51
         private Float maxWeight;
    
    48 52
     
    
    49 53
         public static Map<String, WeightCategoryRecord> loadWeightCategoriesMap(MigrationVersionResourceExecutor executor) {
    
    50
    -        Set<WeightCategoryRecord> weightCategories = executor.findMultipleResultAstSet(SqlQuery.wrap("SELECT topiaId, code, species, label1 FROM ps_observation.WeightCategory", resultSet -> new WeightCategoryRecord(
    
    51
    -                resultSet.getString(1),
    
    52
    -                resultSet.getString(2),
    
    53
    -                resultSet.getString(3),
    
    54
    -                resultSet.getString(4))));
    
    55
    -        Map<String, WeightCategoryRecord> map = Maps.uniqueIndex(weightCategories, WeightCategoryRecord::getId);
    
    54
    +        Set<WeightCategoryRecord> weightCategories = executor.findMultipleResultAstSet(SqlQuery.wrap(
    
    55
    +                "SELECT wc.topiaId, wc.code, wc.species, wc.label1, s.faoCode, s.label1" +
    
    56
    +                        " FROM ps_observation.WeightCategory wc" +
    
    57
    +                        " INNER JOIN common.species s on wc.species = s.topiaId", resultSet -> new WeightCategoryRecord(
    
    58
    +                        resultSet.getString(1),
    
    59
    +                        resultSet.getString(2),
    
    60
    +                        resultSet.getString(3),
    
    61
    +                        resultSet.getString(4),
    
    62
    +                        resultSet.getString(5),
    
    63
    +                        resultSet.getString(6)
    
    64
    +                )));
    
    65
    +        // all weight categories found in database
    
    66
    +        // while building safe map, this map will be reduced to weight categories that are not in the safe list
    
    67
    +        Map<String, WeightCategoryRecord> toFixMap = new TreeMap<>(Maps.uniqueIndex(weightCategories, WeightCategoryRecord::getId));
    
    68
    +        // safe weight categories we can use in migration (we need to get all of them, otherwise let's throw an error)
    
    69
    +        Map<String, WeightCategoryRecord> safeMap = new TreeMap<>();
    
    70
    +        // missing weight categories (from the safe list)
    
    71
    +        Set<String> missingIds = new TreeSet<>();
    
    56 72
     
    
    57 73
             // load weight categories extra fields (minWeight-maxWeight)
    
    58
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685804#0.034641865339321565", 0f, 3f);
    
    59
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685810#0.9054833697032716", 3f, 10f);
    
    60
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685818#0.5146901232402814", 11f, 30f);
    
    61
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685824#0.30572839692068965", 3f, 30f);
    
    62
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685830#0.3505424853460628", 31f, 50f);
    
    63
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685837#0.9977145363359975", 11f, 50f);
    
    64
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265900731495#0.02540873055336068", 50f, null);
    
    65
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685843#0.5227248075951917", 10f, null);
    
    66
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685849#0.25030425638120324", null, null);
    
    67
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336721513613#0.1603994688043372", null, null);
    
    68
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1389775941412#0.15834335814453693", 30f, null);
    
    69
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1389776343228#0.7378693597245063", 30f, null);
    
    70
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1424937125831#0.9928551215821171", 0f, 10f);
    
    71
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685747#0.8903018444376307", 0f, 3f);
    
    72
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685754#0.10338259022397256", 3f, 10f);
    
    73
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685760#0.5190060347627616", 11f, 30f);
    
    74
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685767#0.17985459818605176", 3f, 30f);
    
    75
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685773#0.36018870624305044", 31f, 50f);
    
    76
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685779#0.6459697632929102", 11f, 50f);
    
    77
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685785#0.017557737970281928", 50f, null);
    
    78
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685791#0.96882088900269", 10f, null);
    
    79
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685798#0.8205778575049493", null, null);
    
    80
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336721546508#0.9537814356455492", null, null);
    
    81
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1389776259896#0.07638719997162424", 30f, null);
    
    82
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1424937065301#0.2847458239357389", 0f, 10f);
    
    83
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1447659295872#0.5394619880622312", 0f, 3.5f);
    
    84
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1447659325662#0.768248108810874", 3.5f, 10f);
    
    85
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336722270972#0.37652846873357493", null, null);
    
    86
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1285247232470#0.6003570416302645", null, null);
    
    87
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336722322572#0.3938987624410807", null, null);
    
    88
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685856#0.37681463866680454", 0f, 1.8f);
    
    89
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685862#0.3577261083569382", 1.8f, null);
    
    90
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685869#0.1577912646543379", 1.8f, 4f);
    
    91
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685876#0.571764466269097", 1.8f, 6f);
    
    92
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685882#0.6060344598115799", 4f, 6f);
    
    93
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685888#0.04548287749163349", 4f, 8f);
    
    94
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685894#0.7596812507048669", 6f, 8f);
    
    95
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685901#0.9401665182005969", 8f, null);
    
    96
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685907#0.703864325385401", null, null);
    
    97
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336740964786#0.9038903638109549", null, null);
    
    98
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602771681957#0.9874591590552072", 0f, 1.8f);
    
    99
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602771701326#0.4010839902789137", 1.8f, null);
    
    100
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602771715715#0.7853847204136084", 1.8f, 4f);
    
    101
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602771729301#0.4884568851061948", 1.8f, 6f);
    
    102
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602771742931#0.7051564476067321", 4f, 6f);
    
    103
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602771756464#0.45050535009150927", 4f, 8f);
    
    104
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602771767261#0.6841254148640502", 6f, 8f);
    
    105
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602771778122#0.16162153365230103", 8f, null);
    
    106
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602770129319#0.19516930145898193", null, null);
    
    107
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1602770254324#0.846496629553337", null, null);
    
    108
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685913#0.6908151762213386", 0f, 1.8f);
    
    109
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685919#0.32661937164161003", 1.8f, null);
    
    110
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685926#0.26263537384431435", 1.8f, 4f);
    
    111
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685932#0.05603149764956994", 1.8f, 6f);
    
    112
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685938#0.1289482411270122", 4f, 6f);
    
    113
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685944#0.6386905101076812", 4f, 8f);
    
    114
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685950#0.5552574879416816", 6f, 8f);
    
    115
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685956#0.8040582347597208", 8f, null);
    
    116
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685962#0.5585432399656218", null, null);
    
    117
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741018010#0.03331113748771242", null, null);
    
    118
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303922010990#0.3754603442395006", 0f, 1.8f);
    
    119
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303922245707#0.40050172552023944", 1.8f, null);
    
    120
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303922280084#0.6622140480197926", 1.8f, 4f);
    
    121
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303922599555#0.7704492147942078", 1.8f, 6f);
    
    122
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303922687314#0.6979902619400133", 4f, 6f);
    
    123
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303922752777#0.47792415661458676", 4f, 8f);
    
    124
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303922804724#0.4624943876905273", 6f, 8f);
    
    125
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303922867136#0.4287768516967707", 8f, null);
    
    126
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1285247232470#0.2988865794350679", null, null);
    
    127
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741045619#0.26215173370303935", null, null);
    
    128
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303925079863#0.4512897233754356", 0f, 1.8f);
    
    129
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303925079863#0.5772066302124889", 1.8f, null);
    
    130
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303925079863#0.5076973842921164", 1.8f, 4f);
    
    131
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303925079864#0.15355738476896108", 1.8f, 6f);
    
    132
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303925590606#0.2425119417078675", 4f, 6f);
    
    133
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303925590606#0.8917988680730413", 4f, 8f);
    
    134
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303925716959#0.9994063870345968", 6f, 8f);
    
    135
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303925716959#0.07903343358670578", 8f, null);
    
    136
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1285247232470#0.6346372733268454", null, null);
    
    137
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741085150#0.8502977815118109", null, null);
    
    138
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1285247232470#0.6536295925217674", null, null);
    
    139
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741106738#0.8017167831584734", null, null);
    
    140
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685968#0.8743676757879854", 0f, 1.8f);
    
    141
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685975#0.9269185705341096", 1.8f, null);
    
    142
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685981#0.20973946035734992", 1.8f, 4f);
    
    143
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685987#0.8124900788304172", 1.8f, 6f);
    
    144
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685993#0.7110149379733451", 4f, 6f);
    
    145
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685999#0.35760983661297885", 4f, 8f);
    
    146
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832686006#0.27918502949209356", 6f, 8f);
    
    147
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832686012#0.3678254910247588", 8f, null);
    
    148
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685610#0.04119062512809801", null, null);
    
    149
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741128034#0.08367392559943787", null, null);
    
    150
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265900836849#0.18015633272140852", 0f, 1.8f);
    
    151
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265900836849#0.9036635253340434", 1.8f, null);
    
    152
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685673#0.3163596616269717", 1.8f, 4f);
    
    153
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685679#0.019733673419385367", 1.8f, 6f);
    
    154
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685685#0.7315998797178913", 4f, 6f);
    
    155
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685692#0.5940916998227946", 4f, 8f);
    
    156
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685722#0.9714869893887224", 6f, 8f);
    
    157
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685729#0.0015801959709714763", 8f, null);
    
    158
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685741#0.9084571608340902", null, null);
    
    159
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741168338#0.14273986795446758", null, null);
    
    160
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1447659383213#0.4400294468298005", 0f, 3.5f);
    
    161
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1447659418223#0.8121977439460182", 3.5f, null);
    
    162
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1555434122029#0.33046872986365916", null, null);
    
    163
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1555434233562#0.6221497586001838", null, null);
    
    164
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1563970176195#0.042949635286452015", null, null);
    
    165
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1563970198102#0.5406480296062075", null, null);
    
    166
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685499#0.45137386216494235", 0f, 3f);
    
    167
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1239832685505#0.6893474228813191", 3f, 10f);
    
    168
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265900972942#0.14809205088390143", 11f, 30f);
    
    169
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265900972963#0.6915765595336695", 3f, 30f);
    
    170
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265901072470#0.48282507736865", 31f, 50f);
    
    171
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265901072470#0.049555168356280266", 11f, 50f);
    
    172
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265901072470#0.3502049636413197", 50f, null);
    
    173
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265901225547#0.7474093737982056", 10f, null);
    
    174
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1265901225548#0.3886087214402537", null, null);
    
    175
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741209227#0.14815475082140694", null, null);
    
    176
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1424936892080#0.3071247026973247", 0f, 10f);
    
    177
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1447659237402#0.5659786750175115", 0f, 3.5f);
    
    178
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1447658978491#0.015566209814640963", 3.5f, 10f);
    
    179
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741235125#0.9596181329735903", null, null);
    
    180
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1303924814809#0.6964774216650054", null, null);
    
    181
    -        addWeightCategoryMinMaxWeight(map, "fr.ird.referential.ps.observation.WeightCategory#1336741257450#0.021228233536910834", null, null);
    
    182
    -        return map;
    
    74
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685804#0.034641865339321565", 0f, 3f);
    
    75
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685810#0.9054833697032716", 3f, 10f);
    
    76
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685818#0.5146901232402814", 11f, 30f);
    
    77
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685824#0.30572839692068965", 3f, 30f);
    
    78
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685830#0.3505424853460628", 31f, 50f);
    
    79
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685837#0.9977145363359975", 11f, 50f);
    
    80
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265900731495#0.02540873055336068", 50f, null);
    
    81
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685843#0.5227248075951917", 10f, null);
    
    82
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685849#0.25030425638120324", null, null);
    
    83
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336721513613#0.1603994688043372", null, null);
    
    84
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1389775941412#0.15834335814453693", 30f, null);
    
    85
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1389776343228#0.7378693597245063", 30f, null);
    
    86
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1424937125831#0.9928551215821171", 0f, 10f);
    
    87
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685747#0.8903018444376307", 0f, 3f);
    
    88
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685754#0.10338259022397256", 3f, 10f);
    
    89
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685760#0.5190060347627616", 11f, 30f);
    
    90
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685767#0.17985459818605176", 3f, 30f);
    
    91
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685773#0.36018870624305044", 31f, 50f);
    
    92
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685779#0.6459697632929102", 11f, 50f);
    
    93
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685785#0.017557737970281928", 50f, null);
    
    94
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685791#0.96882088900269", 10f, null);
    
    95
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685798#0.8205778575049493", null, null);
    
    96
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336721546508#0.9537814356455492", null, null);
    
    97
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1389776259896#0.07638719997162424", 30f, null);
    
    98
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1424937065301#0.2847458239357389", 0f, 10f);
    
    99
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1447659295872#0.5394619880622312", 0f, 3.5f);
    
    100
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1447659325662#0.768248108810874", 3.5f, 10f);
    
    101
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336722270972#0.37652846873357493", null, null);
    
    102
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1285247232470#0.6003570416302645", null, null);
    
    103
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336722322572#0.3938987624410807", null, null);
    
    104
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685856#0.37681463866680454", 0f, 1.8f);
    
    105
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685862#0.3577261083569382", 1.8f, null);
    
    106
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685869#0.1577912646543379", 1.8f, 4f);
    
    107
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685876#0.571764466269097", 1.8f, 6f);
    
    108
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685882#0.6060344598115799", 4f, 6f);
    
    109
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685888#0.04548287749163349", 4f, 8f);
    
    110
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685894#0.7596812507048669", 6f, 8f);
    
    111
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685901#0.9401665182005969", 8f, null);
    
    112
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685907#0.703864325385401", null, null);
    
    113
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336740964786#0.9038903638109549", null, null);
    
    114
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602771681957#0.9874591590552072", 0f, 1.8f);
    
    115
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602771701326#0.4010839902789137", 1.8f, null);
    
    116
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602771715715#0.7853847204136084", 1.8f, 4f);
    
    117
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602771729301#0.4884568851061948", 1.8f, 6f);
    
    118
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602771742931#0.7051564476067321", 4f, 6f);
    
    119
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602771756464#0.45050535009150927", 4f, 8f);
    
    120
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602771767261#0.6841254148640502", 6f, 8f);
    
    121
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602771778122#0.16162153365230103", 8f, null);
    
    122
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602770129319#0.19516930145898193", null, null);
    
    123
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1602770254324#0.846496629553337", null, null);
    
    124
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685913#0.6908151762213386", 0f, 1.8f);
    
    125
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685919#0.32661937164161003", 1.8f, null);
    
    126
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685926#0.26263537384431435", 1.8f, 4f);
    
    127
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685932#0.05603149764956994", 1.8f, 6f);
    
    128
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685938#0.1289482411270122", 4f, 6f);
    
    129
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685944#0.6386905101076812", 4f, 8f);
    
    130
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685950#0.5552574879416816", 6f, 8f);
    
    131
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685956#0.8040582347597208", 8f, null);
    
    132
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685962#0.5585432399656218", null, null);
    
    133
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741018010#0.03331113748771242", null, null);
    
    134
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303922010990#0.3754603442395006", 0f, 1.8f);
    
    135
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303922245707#0.40050172552023944", 1.8f, null);
    
    136
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303922280084#0.6622140480197926", 1.8f, 4f);
    
    137
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303922599555#0.7704492147942078", 1.8f, 6f);
    
    138
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303922687314#0.6979902619400133", 4f, 6f);
    
    139
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303922752777#0.47792415661458676", 4f, 8f);
    
    140
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303922804724#0.4624943876905273", 6f, 8f);
    
    141
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303922867136#0.4287768516967707", 8f, null);
    
    142
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1285247232470#0.2988865794350679", null, null);
    
    143
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741045619#0.26215173370303935", null, null);
    
    144
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303925079863#0.4512897233754356", 0f, 1.8f);
    
    145
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303925079863#0.5772066302124889", 1.8f, null);
    
    146
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303925079863#0.5076973842921164", 1.8f, 4f);
    
    147
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303925079864#0.15355738476896108", 1.8f, 6f);
    
    148
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303925590606#0.2425119417078675", 4f, 6f);
    
    149
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303925590606#0.8917988680730413", 4f, 8f);
    
    150
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303925716959#0.9994063870345968", 6f, 8f);
    
    151
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303925716959#0.07903343358670578", 8f, null);
    
    152
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1285247232470#0.6346372733268454", null, null);
    
    153
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741085150#0.8502977815118109", null, null);
    
    154
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1285247232470#0.6536295925217674", null, null);
    
    155
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741106738#0.8017167831584734", null, null);
    
    156
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685968#0.8743676757879854", 0f, 1.8f);
    
    157
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685975#0.9269185705341096", 1.8f, null);
    
    158
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685981#0.20973946035734992", 1.8f, 4f);
    
    159
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685987#0.8124900788304172", 1.8f, 6f);
    
    160
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685993#0.7110149379733451", 4f, 6f);
    
    161
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685999#0.35760983661297885", 4f, 8f);
    
    162
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832686006#0.27918502949209356", 6f, 8f);
    
    163
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832686012#0.3678254910247588", 8f, null);
    
    164
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685610#0.04119062512809801", null, null);
    
    165
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741128034#0.08367392559943787", null, null);
    
    166
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265900836849#0.18015633272140852", 0f, 1.8f);
    
    167
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265900836849#0.9036635253340434", 1.8f, null);
    
    168
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685673#0.3163596616269717", 1.8f, 4f);
    
    169
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685679#0.019733673419385367", 1.8f, 6f);
    
    170
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685685#0.7315998797178913", 4f, 6f);
    
    171
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685692#0.5940916998227946", 4f, 8f);
    
    172
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685722#0.9714869893887224", 6f, 8f);
    
    173
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685729#0.0015801959709714763", 8f, null);
    
    174
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685741#0.9084571608340902", null, null);
    
    175
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741168338#0.14273986795446758", null, null);
    
    176
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1447659383213#0.4400294468298005", 0f, 3.5f);
    
    177
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1447659418223#0.8121977439460182", 3.5f, null);
    
    178
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1555434122029#0.33046872986365916", null, null);
    
    179
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1555434233562#0.6221497586001838", null, null);
    
    180
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1563970176195#0.042949635286452015", null, null);
    
    181
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1563970198102#0.5406480296062075", null, null);
    
    182
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685499#0.45137386216494235", 0f, 3f);
    
    183
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1239832685505#0.6893474228813191", 3f, 10f);
    
    184
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265900972942#0.14809205088390143", 11f, 30f);
    
    185
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265900972963#0.6915765595336695", 3f, 30f);
    
    186
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265901072470#0.48282507736865", 31f, 50f);
    
    187
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265901072470#0.049555168356280266", 11f, 50f);
    
    188
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265901072470#0.3502049636413197", 50f, null);
    
    189
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265901225547#0.7474093737982056", 10f, null);
    
    190
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1265901225548#0.3886087214402537", null, null);
    
    191
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741209227#0.14815475082140694", null, null);
    
    192
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1424936892080#0.3071247026973247", 0f, 10f);
    
    193
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1447659237402#0.5659786750175115", 0f, 3.5f);
    
    194
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1447658978491#0.015566209814640963", 3.5f, 10f);
    
    195
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741235125#0.9596181329735903", null, null);
    
    196
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1303924814809#0.6964774216650054", null, null);
    
    197
    +        addWeightCategoryMinMaxWeight(toFixMap, safeMap, missingIds, "fr.ird.referential.ps.observation.WeightCategory#1336741257450#0.021228233536910834", null, null);
    
    198
    +        if (!missingIds.isEmpty()) {
    
    199
    +            StringBuilder error = new StringBuilder();
    
    200
    +            error.append(String.format("\nDetects %d official weight categories not found in current database:\n\t", missingIds.size()));
    
    201
    +            error.append(String.join("\n\t", missingIds));
    
    202
    +            log.warn(error);
    
    203
    +        }
    
    204
    +        if (toFixMap.isEmpty()) {
    
    205
    +            // everything is ok, we can use the safe map
    
    206
    +            return safeMap;
    
    207
    +        }
    
    208
    +        StringBuilder error = new StringBuilder(String.format("\nDetects %d weight categories in current database, that should be replaced by official one:", toFixMap.size()));
    
    209
    +        for (WeightCategoryRecord value : toFixMap.values()) {
    
    210
    +            error.append("\n").append(value.toString());
    
    211
    +        }
    
    212
    +        throw new IllegalStateException(error.toString());
    
    183 213
         }
    
    184 214
     
    
    185 215
         private static final Logger log = LogManager.getLogger(WeightCategoryRecord.class);
    
    186 216
     
    
    187
    -    private static void addWeightCategoryMinMaxWeight(Map<String, WeightCategoryRecord> map, String id, Float minWeight, Float maxWeight) {
    
    188
    -        WeightCategoryRecord weightCategoryRecord = map.get(id);
    
    217
    +    private static void addWeightCategoryMinMaxWeight(Map<String, WeightCategoryRecord> existingMap,
    
    218
    +                                                      Map<String, WeightCategoryRecord> safeMap,
    
    219
    +                                                      Set<String> missingIds,
    
    220
    +                                                      String id,
    
    221
    +                                                      Float minWeight,
    
    222
    +                                                      Float maxWeight) {
    
    223
    +        WeightCategoryRecord weightCategoryRecord = existingMap.get(id);
    
    189 224
             if (weightCategoryRecord == null) {
    
    190
    -            log.error(String.format("Could not find in database weightCategory: %s", id));
    
    225
    +            missingIds.add(id);
    
    191 226
                 return;
    
    192 227
             }
    
    228
    +        // remove it from existing map (since this weight category is ok)
    
    229
    +        existingMap.remove(id);
    
    230
    +        // add it to safe map
    
    231
    +        safeMap.put(id, weightCategoryRecord);
    
    232
    +        // add min weight
    
    193 233
             weightCategoryRecord.setMinWeight(minWeight);
    
    234
    +        // add max weight
    
    194 235
             weightCategoryRecord.setMaxWeight(maxWeight);
    
    195 236
         }
    
    196 237
     
    
    197
    -    WeightCategoryRecord(String id, String code, String speciesId, String label1) {
    
    238
    +    WeightCategoryRecord(String id,
    
    239
    +                         String code,
    
    240
    +                         String speciesId,
    
    241
    +                         String label1,
    
    242
    +                         String speciesFaoCode,
    
    243
    +                         String speciesLabel1) {
    
    198 244
             this.id = id;
    
    199 245
             this.code = code;
    
    200 246
             this.speciesId = speciesId;
    
    201 247
             this.label1 = label1;
    
    248
    +        this.speciesFaoCode = speciesFaoCode;
    
    249
    +        this.speciesLabel1 = speciesLabel1;
    
    202 250
         }
    
    203 251
     
    
    204 252
         public void setMinWeight(Float minWeight) {
    
    ... ... @@ -237,6 +285,11 @@ public class WeightCategoryRecord {
    237 285
             return String.format(COMMENT_PATTERN, getCode(), getLabel1());
    
    238 286
         }
    
    239 287
     
    
    288
    +    @Override
    
    289
    +    public String toString() {
    
    290
    +        return String.format("{id='%s', code='%s', label1='%s', speciesId='%s', speciesFaoCode='%s', speciesLabel1='%s'}", id, code, label1, speciesId, speciesFaoCode, speciesLabel1);
    
    291
    +    }
    
    292
    +
    
    240 293
         public static final String COMMENT_PATTERN = "<weightcategory>\n" +
    
    241 294
                 "   <code>%1$s</code>\n" +
    
    242 295
                 "   <label1>%2$s</label1>\n" +
    

  • core/persistence/resources/src/main/resources/db/migration/v8/8.1/99_fix_not_null_constraints-common.sql
    ... ... @@ -44,6 +44,11 @@ DELETE FROM ps_observation.ObjectObservedSpecies WHERE species IS NULL AND count
    44 44
     DELETE FROM ps_observation.ObjectSchoolEstimate WHERE species IS NULL AND totalWeight IS NULL;
    
    45 45
     DELETE FROM ll_observation.BranchlinesComposition WHERE topType IS NULL AND tracelineType IS NULL AND length IS NULL;
    
    46 46
     DELETE FROM ll_observation.SizeMeasure WHERE size IS NULL;
    
    47
    +DELETE FROM ps_observation.nonTargetCatch WHERE species IS NULL AND catchweight IS NULL AND meanWeight IS NULL AND totalCount IS NULL AND reasonfordiscard IS NULL AND well IS NULL;
    
    48
    +DELETE FROM ps_common.GearUseFeatures WHERE gear IS NULL AND number IS NULL AND usedintrip IS NULL;
    
    49
    +DELETE FROM ps_common.GearUseFeaturesMeasurement WHERE measurementvalue IS NULL;
    
    50
    +DELETE FROM ll_common.GearUseFeatures WHERE gear IS NULL AND number IS NULL AND usedintrip IS NULL;
    
    51
    +DELETE FROM ll_common.GearUseFeaturesMeasurement WHERE measurementvalue IS NULL;
    
    47 52
     
    
    48 53
     UPDATE ps_observation.NonTargetLength SET lastUpdateDate = ${CURRENT_TIMESTAMP}, topiaVersion = topiaVersion + 1, species = 'fr.ird.referential.common.Species#1433499266610#0.696541526820511' WHERE species IS NULL;
    
    49 54
     UPDATE ps_observation.NonTargetLength SET lastUpdateDate = ${CURRENT_TIMESTAMP}, topiaVersion = topiaVersion + 1, count = 1 WHERE count IS NULL AND species IS NOT NULL;
    

  • toolkit/persistence/src/main/java/fr/ird/observe/spi/context/DataDtoEntityContext.java
    ... ... @@ -78,6 +78,10 @@ public abstract class DataDtoEntityContext<
    78 78
             return String.format("%1$tF %1$tT", date);
    
    79 79
         }
    
    80 80
     
    
    81
    +    public static String toTimeStamp(Date time) {
    
    82
    +        return time == null ? null : SqlHelper.escapeString(DataDtoEntityContext.timestamp(time)) + "::timestamp";
    
    83
    +    }
    
    84
    +
    
    81 85
         public static String toId(Entity entity) {
    
    82 86
             return entity == null ? "NULL" : SqlHelper.escapeString(entity.getTopiaId());
    
    83 87
         }