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

Commits:

17 changed files:

Changes:

  • client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIHandler.java
    ... ... @@ -6,15 +6,15 @@
    6 6
      * %%
    
    7 7
      * This program is free software: you can redistribute it and/or modify
    
    8 8
      * it under the terms of the GNU General Public License as
    
    9
    - * published by the Free Software Foundation, either version 3 of the 
    
    9
    + * published by the Free Software Foundation, either version 3 of the
    
    10 10
      * License, or (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    17
    - * You should have received a copy of the GNU General Public 
    
    16
    + *
    
    17
    + * You should have received a copy of the GNU General Public
    
    18 18
      * License along with this program.  If not, see
    
    19 19
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    20 20
      * #L%
    
    ... ... @@ -47,6 +47,8 @@ import fr.ird.observe.dto.form.Form;
    47 47
     import fr.ird.observe.dto.referential.seine.ObjectMaterialDto;
    
    48 48
     import fr.ird.observe.dto.referential.seine.ObjectOperationReference;
    
    49 49
     import fr.ird.observe.dto.result.SaveResultDto;
    
    50
    +import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloatingObjectRequest;
    
    51
    +import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloatingObjectResult;
    
    50 52
     import fr.ird.observe.spi.DtoModelHelper;
    
    51 53
     import org.apache.commons.logging.Log;
    
    52 54
     import org.apache.commons.logging.LogFactory;
    
    ... ... @@ -85,7 +87,8 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto,
    85 87
     
    
    86 88
         /** Logger */
    
    87 89
         private static final Log log = LogFactory.getLog(FloatingObjectUIHandler.class);
    
    88
    -
    
    90
    +    private static final Icon ICON_NOT_A_REFERENCE = SwingUtil.createImageIcon("star-empty.png");
    
    91
    +    private static final Icon ICON_IS_A_REFERENCE = SwingUtil.createImageIcon("star.png");
    
    89 92
         // Compute valid state of tab from the error table
    
    90 93
         protected final TableModelListener computeTabValidStateListener;
    
    91 94
     
    
    ... ... @@ -235,14 +238,14 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto,
    235 238
             getUi().getValidator().setContext(contextName);
    
    236 239
             if (create) {
    
    237 240
                 addMessage(getUi(),
    
    238
    -                       NuitonValidatorScope.INFO,
    
    239
    -                       getTypeI18nKey(FloatingObjectDto.class),
    
    240
    -                       t("observe.common.FloatingObjectDto.message.creating"));
    
    241
    +                    NuitonValidatorScope.INFO,
    
    242
    +                    getTypeI18nKey(FloatingObjectDto.class),
    
    243
    +                    t("observe.common.FloatingObjectDto.message.creating"));
    
    241 244
             } else {
    
    242 245
                 addMessage(getUi(),
    
    243
    -                       NuitonValidatorScope.INFO,
    
    244
    -                       getTypeI18nKey(FloatingObjectDto.class),
    
    245
    -                       t("observe.common.FloatingObjectDto.message.updating"));
    
    246
    +                    NuitonValidatorScope.INFO,
    
    247
    +                    getTypeI18nKey(FloatingObjectDto.class),
    
    248
    +                    t("observe.common.FloatingObjectDto.message.updating"));
    
    246 249
             }
    
    247 250
             super.startEditUI(FloatingObjectUI.BINDING_COMMENT_MODEL);
    
    248 251
             contentUIModel.setModified(create);
    
    ... ... @@ -253,6 +256,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto,
    253 256
     
    
    254 257
             String activityId = getSelectedParentId();
    
    255 258
     
    
    259
    +        recomputeComputedValues();
    
    256 260
             SaveResultDto saveResult = getFloatingObjectService().save(activityId, bean);
    
    257 261
             saveResult.toDto(bean);
    
    258 262
     
    
    ... ... @@ -323,12 +327,13 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto,
    323 327
             Map<String, ObjectMaterialDto> allMap = new TreeMap<>();
    
    324 328
             detailedForm.stream().flatMap(o -> o.getAllDtos().stream()).forEach(s -> allMap.putIfAbsent(s.getId(), s));
    
    325 329
     
    
    326
    -        getModel().setReferentialMap(allMap);
    
    330
    +        FloatingObjectUIModel model = getModel();
    
    331
    +        model.setReferentialMap(allMap);
    
    327 332
     
    
    328 333
             initTable(detailedForm, ui.getTable());
    
    329 334
     
    
    330
    -        getModel().addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_REFERENCE, e -> {
    
    331
    -            if (!getModel().isUpdatingMode()) {
    
    335
    +        model.addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_REFERENCE, e -> {
    
    336
    +            if (!model.isUpdatingMode()) {
    
    332 337
                     return;
    
    333 338
                 }
    
    334 339
                 FloatingObjectPreset newValue = (FloatingObjectPreset) e.getNewValue();
    
    ... ... @@ -349,12 +354,26 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto,
    349 354
                 }
    
    350 355
             });
    
    351 356
     
    
    352
    -        getModel().addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_PARTS_MODIFIED, e -> getModel().recomputeComputedValues());
    
    357
    +        model.addPropertyChangeListener(FloatingObjectUIModel.PROPERTY_PARTS_MODIFIED, e -> {
    
    358
    +            if (Objects.equals(e.getNewValue(), Boolean.TRUE)) {
    
    359
    +                recomputeComputedValues();
    
    360
    +            }
    
    361
    +        });
    
    353 362
     
    
    354 363
             getBean().addPropertyChangeListener(FloatingObjectDto.PROPERTY_OBJECT_OPERATION, e -> updateMaterials((ObjectOperationReference) e.getNewValue()));
    
    355 364
     
    
    356 365
         }
    
    357 366
     
    
    367
    +    private void recomputeComputedValues() {
    
    368
    +
    
    369
    +        ConsolidateFloatingObjectResult result = getConsolidateDataService().consolidateFloatingObject(new ConsolidateFloatingObjectRequest(getBean(), getModel().toParts()));
    
    370
    +        if (result != null) {
    
    371
    +            log.info("Flush consolidate dcp changes...");
    
    372
    +            result.flushToDto(getBean());
    
    373
    +            getModel().fireComputedValuesChanged();
    
    374
    +        }
    
    375
    +    }
    
    376
    +
    
    358 377
         private void updateMaterials(ObjectOperationReference operation) {
    
    359 378
             if (operation == null) {
    
    360 379
                 getModel().setArriving(false);
    
    ... ... @@ -367,9 +386,6 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObjectDto,
    367 386
             treeModel.reset();
    
    368 387
         }
    
    369 388
     
    
    370
    -    private static final Icon ICON_NOT_A_REFERENCE = SwingUtil.createImageIcon("star-empty.png");
    
    371
    -    private static final Icon ICON_IS_A_REFERENCE = SwingUtil.createImageIcon("star.png");
    
    372
    -
    
    373 389
         private void initTable(List<ObjectMaterialHierarchyDto> materials, JXTreeTable table) {
    
    374 390
     
    
    375 391
             FloatingObjectPartsTreeTableModel treeModel = (FloatingObjectPartsTreeTableModel) table.getTreeTableModel();
    

  • client/src/main/java/fr/ird/observe/client/ui/content/data/seine/FloatingObjectUIModel.java
    ... ... @@ -144,7 +144,7 @@ public class FloatingObjectUIModel extends ContentUIModel<FloatingObjectDto> {
    144 144
             fireComputedValuesChanged();
    
    145 145
         }
    
    146 146
     
    
    147
    -    private void fireComputedValuesChanged() {
    
    147
    +    public void fireComputedValuesChanged() {
    
    148 148
             firePropertyChange("computedWhenArrivingBiodegradableValue", getComputedWhenArrivingBiodegradableValue());
    
    149 149
             firePropertyChange("computedWhenArrivingNonEntanglingValue", getComputedWhenArrivingNonEntanglingValue());
    
    150 150
             firePropertyChange("computedWhenArrivingSimplifiedObjectTypeValue", getComputedWhenArrivingSimplifiedObjectTypeValue());
    

  • persistence/src/main/resources/db/migration/7.2/01_update_objectMaterial-common.sql
    ... ... @@ -104,4 +104,8 @@ update observe_seine.objectmaterial set validation='x >= 5 && x <= 1000', topiav
    104 104
     -- Mise à jour label 4-8
    
    105 105
     update observe_seine.objectmaterial set label2='Number of tangled FOBs', label3='Numero de FADs enmallados', topiaversion=topiaversion+1 WHERE topiaid='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#0.76';
    
    106 106
     -- Mise à jour formule de validation len
    
    107
    -update observe_seine.objectmaterial set validation='x.length() >= 3 && x.length() <= 64', topiaversion=topiaversion+1 WHERE topiaid='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#0.75';
    \ No newline at end of file
    107
    +update observe_seine.objectmaterial set validation='x.length() >= 3 && x.length() <= 64', topiaversion=topiaversion+1 WHERE topiaid='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#0.75';
    
    108
    +-- Re-add entry for FOB with '' code
    
    109
    +INSERT INTO observe_seine.objectMaterial (topiaid, topiaversion, topiacreatedate, lastupdatedate, needComment, status, legacyCode, standardCode, code, parent, label1, label2, label3, selectable, childrenMultiSelectable, childSelectionMandatory, objectMaterialType, validation, biodegradable, nonEntangling) values ('fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#1.3', 0, CURRENT_DATE, CURRENT_TIMESTAMP, false,  1, NULL, 'FOB', ''        , null , 'FOB', 'FOB', 'FOB', false, true , true, NULL, NULL, false, false);
    
    110
    +UPDATE observe_seine.objectmaterial SET parent='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#1.3' WHERE parent IS NULL;
    
    111
    +UPDATE observe_seine.objectmaterial SET parent= NULL WHERE topiaid='fr.ird.observe.entities.referentiel.seine.ObjectMaterial#0#1.3';

  • server/src/main/filtered-resources/mapping
    ... ... @@ -67,6 +67,7 @@ POST /api/v1/LastUpdateDateService/updateDataLastUpdateDates
    67 67
     POST   /api/v1/LastUpdateDateService/updateReferentialLastUpdateDates                                                                v1.LastUpdateDateServiceRestApi.updateReferentialLastUpdateDates
    
    68 68
     GET    /api/v1/PingService/getModelVersion                                                                                           v1.PingServiceRestApi.getModelVersion
    
    69 69
     GET    /api/v1/PingService/getServerVersion                                                                                          v1.PingServiceRestApi.getServerVersion
    
    70
    +POST   /api/v1/actions/consolidate/ConsolidateDataService/consolidateFloatingObject                                                  v1.actions.consolidate.ConsolidateDataServiceRestApi.consolidateFloatingObject
    
    70 71
     POST   /api/v1/actions/consolidate/ConsolidateDataService/consolidateTripSeine                                                       v1.actions.consolidate.ConsolidateDataServiceRestApi.consolidateTripSeine
    
    71 72
     GET    /api/v1/actions/consolidate/ConsolidateDataService/newSimplifiedObjectTypeManager                                             v1.actions.consolidate.ConsolidateDataServiceRestApi.newSimplifiedObjectTypeManager
    
    72 73
     POST   /api/v1/actions/report/ReportService/executeReport                                                                            v1.actions.report.ReportServiceRestApi.executeReport
    

  • services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java
    ... ... @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service.actions.consolidate;
    10 10
      * it under the terms of the GNU General Public License as
    
    11 11
      * published by the Free Software Foundation, either version 3 of the
    
    12 12
      * License, or (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU General Public
    
    20 20
      * License along with this program.  If not, see
    
    21 21
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    ... ... @@ -25,11 +25,11 @@ package fr.ird.observe.services.local.service.actions.consolidate;
    25 25
     import com.google.common.collect.ImmutableMap;
    
    26 26
     import com.google.common.collect.ImmutableSet;
    
    27 27
     import fr.ird.observe.binder.data.DataEntityDtoBinderSupport;
    
    28
    +import fr.ird.observe.dto.data.seine.FloatingObjectDto;
    
    29
    +import fr.ird.observe.dto.data.seine.FloatingObjectPartDto;
    
    28 30
     import fr.ird.observe.dto.data.seine.NonTargetCatchComputedValueSource;
    
    29 31
     import fr.ird.observe.dto.data.seine.SchoolType;
    
    30 32
     import fr.ird.observe.dto.referential.ReferentialLocale;
    
    31
    -import fr.ird.observe.dto.data.seine.FloatingObjectDto;
    
    32
    -import fr.ird.observe.dto.data.seine.FloatingObjectPartDto;
    
    33 33
     import fr.ird.observe.entities.LengthWeightComputable;
    
    34 34
     import fr.ird.observe.entities.referentiel.LengthLengthParameter;
    
    35 35
     import fr.ird.observe.entities.referentiel.LengthLengthParameters;
    
    ... ... @@ -65,6 +65,11 @@ import fr.ird.observe.services.service.actions.consolidate.dcp.SimplifiedObjectT
    65 65
     import fr.ird.observe.services.service.actions.consolidate.dcp.SimplifiedObjectTypeNode;
    
    66 66
     import fr.ird.observe.services.service.actions.consolidate.set.ConsolidateActivitySeineDataResult;
    
    67 67
     import fr.ird.observe.spi.DbModelHelper;
    
    68
    +import org.apache.commons.collections4.CollectionUtils;
    
    69
    +import org.apache.commons.logging.Log;
    
    70
    +import org.apache.commons.logging.LogFactory;
    
    71
    +import org.nuiton.util.beans.BeanMonitor;
    
    72
    +
    
    68 73
     import java.util.Collection;
    
    69 74
     import java.util.LinkedHashSet;
    
    70 75
     import java.util.List;
    
    ... ... @@ -74,10 +79,6 @@ import java.util.Optional;
    74 79
     import java.util.Set;
    
    75 80
     import java.util.TreeMap;
    
    76 81
     import java.util.stream.Collectors;
    
    77
    -import org.apache.commons.collections4.CollectionUtils;
    
    78
    -import org.apache.commons.logging.Log;
    
    79
    -import org.apache.commons.logging.LogFactory;
    
    80
    -import org.nuiton.util.beans.BeanMonitor;
    
    81 82
     
    
    82 83
     /**
    
    83 84
      * Created on 28/08/15.
    
    ... ... @@ -89,15 +90,81 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements
    89 90
         /** Logger. */
    
    90 91
         private static final Log log = LogFactory.getLog(ConsolidateDataServiceLocal.class);
    
    91 92
     
    
    93
    +    private static ImmutableMap<String, SimplifiedObjectTypeNode> create(List<ObjectMaterial> materials) {
    
    94
    +        TreeMap<String, SimplifiedObjectTypeNode> mappingBuilder = new TreeMap<>();
    
    95
    +
    
    96
    +        Set<ObjectMaterial> materialsDone = new LinkedHashSet<>();
    
    97
    +        Set<ObjectMaterial> materialsTodo = new LinkedHashSet<>(materials);
    
    98
    +
    
    99
    +        while (!materialsTodo.isEmpty()) {
    
    100
    +
    
    101
    +            Set<ObjectMaterial> currentRoundMaterials;
    
    102
    +            if (materialsDone.isEmpty()) {
    
    103
    +
    
    104
    +                // first round
    
    105
    +                currentRoundMaterials = materialsTodo.stream().filter(f -> f.getParent() == null).collect(Collectors.toSet());
    
    106
    +
    
    107
    +            } else {
    
    108
    +                currentRoundMaterials = materialsTodo.stream().filter(f -> materialsDone.contains(f.getParent())).collect(Collectors.toSet());
    
    109
    +            }
    
    110
    +
    
    111
    +            materialsDone.addAll(currentRoundMaterials);
    
    112
    +            materialsTodo.removeAll(currentRoundMaterials);
    
    113
    +
    
    114
    +            for (ObjectMaterial currentRoundMaterial : currentRoundMaterials) {
    
    115
    +
    
    116
    +                ObjectMaterial simplifiedObjectMaterial = currentRoundMaterial.getSimplifiedObjectMaterial();
    
    117
    +
    
    118
    +                SimplifiedObjectTypeNode node;
    
    119
    +                if (Objects.equals(currentRoundMaterial, simplifiedObjectMaterial)) {
    
    120
    +
    
    121
    +                    // new node
    
    122
    +                    ObjectMaterial simplifiedParentObjectMaterial = currentRoundMaterial.getSimplifiedParentObjectMaterial();
    
    123
    +                    SimplifiedObjectTypeNode parentNode = simplifiedParentObjectMaterial == null ? null : mappingBuilder.get(simplifiedParentObjectMaterial.getTopiaId());
    
    124
    +                    node = new SimplifiedObjectTypeNode(currentRoundMaterial.getTopiaId(), currentRoundMaterial.getStandardCode(), parentNode);
    
    125
    +
    
    126
    +                } else {
    
    127
    +
    
    128
    +                    if (simplifiedObjectMaterial == null) {
    
    129
    +                        simplifiedObjectMaterial = currentRoundMaterial;
    
    130
    +                    }
    
    131
    +                    // simplified object material is a parent, so must have been process in previous round
    
    132
    +                    Objects.requireNonNull(simplifiedObjectMaterial);
    
    133
    +
    
    134
    +                    node = mappingBuilder.get(simplifiedObjectMaterial.getTopiaId());
    
    135
    +                    if (node == null) {
    
    136
    +                        node = new SimplifiedObjectTypeNode(currentRoundMaterial.getTopiaId(), currentRoundMaterial.getStandardCode(), null);
    
    137
    +                    }
    
    138
    +                    Objects.requireNonNull(node);
    
    139
    +
    
    140
    +                }
    
    141
    +
    
    142
    +                mappingBuilder.put(currentRoundMaterial.getTopiaId(), node);
    
    143
    +
    
    144
    +            }
    
    145
    +        }
    
    146
    +        return ImmutableMap.copyOf(mappingBuilder);
    
    147
    +    }
    
    148
    +
    
    92 149
         @Override
    
    93
    -    public ConsolidateTripSeineDataResult consolidateTripSeine(ConsolidateTripSeineDataRequest consolidateTripSeineDataRequest) {
    
    150
    +    public ConsolidateTripSeineDataResult consolidateTripSeine(ConsolidateTripSeineDataRequest request) {
    
    94 151
             ReferentialLocale referenceLocale = serviceContext.getReferentialLocale();
    
    95
    -        boolean failIfLenghtWeightParameterNotFound = consolidateTripSeineDataRequest.isFailIfLengthWeightParameterNotFound();
    
    96
    -        Optional<ConsolidateTripSeineDataResult> consolidateTripSeineDataResult = consolidateTripSeine(referenceLocale, consolidateTripSeineDataRequest.getTripSeineId(), failIfLenghtWeightParameterNotFound);
    
    152
    +        boolean failIfLenghtWeightParameterNotFound = request.isFailIfLengthWeightParameterNotFound();
    
    153
    +        Optional<ConsolidateTripSeineDataResult> consolidateTripSeineDataResult = consolidateTripSeine(referenceLocale, request.getTripSeineId(), failIfLenghtWeightParameterNotFound);
    
    97 154
             return consolidateTripSeineDataResult.orElse(null);
    
    98 155
         }
    
    99 156
     
    
    100 157
         @Override
    
    158
    +    public ConsolidateFloatingObjectResult consolidateFloatingObject(ConsolidateFloatingObjectRequest request) {
    
    159
    +
    
    160
    +        SimplifiedObjectTypeManager simplifiedObjectTypeManager = newSimplifiedObjectTypeManager();
    
    161
    +
    
    162
    +        FloatingObjectConsolidateEngine floatingObjectConsolidateEngine = new FloatingObjectConsolidateEngine(simplifiedObjectTypeManager);
    
    163
    +        Optional<ConsolidateFloatingObjectResult> result = floatingObjectConsolidateEngine.consolidate(request);
    
    164
    +        return result.orElse(null);
    
    165
    +    }
    
    166
    +
    
    167
    +    @Override
    
    101 168
         public SimplifiedObjectTypeManager newSimplifiedObjectTypeManager() {
    
    102 169
             ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext();
    
    103 170
             ImmutableMap<String, SimplifiedObjectTypeNode> materialMapping = create(persistenceContext.getObjectMaterialDao().findAll());
    
    ... ... @@ -251,9 +318,9 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements
    251 318
                             activityContext.watchTargetLength(targetLength);
    
    252 319
     
    
    253 320
                             updateLengthWeightAble(activityContext,
    
    254
    -                                               targetLength.getSpecies(),
    
    255
    -                                               null, /* pas de sexe precise */
    
    256
    -                                               targetLength);
    
    321
    +                                targetLength.getSpecies(),
    
    322
    +                                null, /* pas de sexe precise */
    
    323
    +                                targetLength);
    
    257 324
     
    
    258 325
                             activityContext.flushTargetLength();
    
    259 326
     
    
    ... ... @@ -273,9 +340,9 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements
    273 340
                             activityContext.watchNonTargetLenght(nonTargetLength);
    
    274 341
     
    
    275 342
                             updateLengthWeightAble(activityContext,
    
    276
    -                                               nonTargetLength.getSpecies(),
    
    277
    -                                               nonTargetLength.getSex(),
    
    278
    -                                               nonTargetLength);
    
    343
    +                                nonTargetLength.getSpecies(),
    
    344
    +                                nonTargetLength.getSex(),
    
    345
    +                                nonTargetLength);
    
    279 346
     
    
    280 347
                             activityContext.flushNonTargetLength();
    
    281 348
     
    
    ... ... @@ -697,60 +764,4 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements
    697 764
             }
    
    698 765
         }
    
    699 766
     
    
    700
    -    static ImmutableMap<String, SimplifiedObjectTypeNode> create(List<ObjectMaterial> materials) {
    
    701
    -        TreeMap<String, SimplifiedObjectTypeNode> mappingBuilder = new TreeMap<>();
    
    702
    -
    
    703
    -        Set<ObjectMaterial> materialsDone = new LinkedHashSet<>();
    
    704
    -        Set<ObjectMaterial> materialsTodo = new LinkedHashSet<>(materials);
    
    705
    -
    
    706
    -        while (!materialsTodo.isEmpty()) {
    
    707
    -
    
    708
    -            Set<ObjectMaterial> currentRoundMaterials;
    
    709
    -            if (materialsDone.isEmpty()) {
    
    710
    -
    
    711
    -                // first round
    
    712
    -                currentRoundMaterials = materialsTodo.stream().filter(f -> f.getParent() == null).collect(Collectors.toSet());
    
    713
    -
    
    714
    -            } else {
    
    715
    -                currentRoundMaterials = materialsTodo.stream().filter(f -> materialsDone.contains(f.getParent())).collect(Collectors.toSet());
    
    716
    -            }
    
    717
    -
    
    718
    -            materialsDone.addAll(currentRoundMaterials);
    
    719
    -            materialsTodo.removeAll(currentRoundMaterials);
    
    720
    -
    
    721
    -            for (ObjectMaterial currentRoundMaterial : currentRoundMaterials) {
    
    722
    -
    
    723
    -                ObjectMaterial simplifiedObjectMaterial = currentRoundMaterial.getSimplifiedObjectMaterial();
    
    724
    -
    
    725
    -                SimplifiedObjectTypeNode node;
    
    726
    -                if (Objects.equals(currentRoundMaterial, simplifiedObjectMaterial)) {
    
    727
    -
    
    728
    -                    // new node
    
    729
    -                    ObjectMaterial simplifiedParentObjectMaterial = currentRoundMaterial.getSimplifiedParentObjectMaterial();
    
    730
    -                    SimplifiedObjectTypeNode parentNode = simplifiedParentObjectMaterial == null ? null : mappingBuilder.get(simplifiedParentObjectMaterial.getTopiaId());
    
    731
    -                    node = new SimplifiedObjectTypeNode(currentRoundMaterial.getTopiaId(), currentRoundMaterial.getStandardCode(), parentNode);
    
    732
    -
    
    733
    -                } else {
    
    734
    -
    
    735
    -                    if (simplifiedObjectMaterial==null) {
    
    736
    -                        simplifiedObjectMaterial = currentRoundMaterial;
    
    737
    -                    }
    
    738
    -                    // simplified object material is a parent, so must have been process in previous round
    
    739
    -                    Objects.requireNonNull(simplifiedObjectMaterial);
    
    740
    -
    
    741
    -                    node = mappingBuilder.get(simplifiedObjectMaterial.getTopiaId());
    
    742
    -                    if (node==null) {
    
    743
    -                        node = new SimplifiedObjectTypeNode(currentRoundMaterial.getTopiaId(), currentRoundMaterial.getStandardCode(), null);
    
    744
    -                    }
    
    745
    -                    Objects.requireNonNull(node);
    
    746
    -
    
    747
    -                }
    
    748
    -
    
    749
    -                mappingBuilder.put(currentRoundMaterial.getTopiaId(), node);
    
    750
    -
    
    751
    -            }
    
    752
    -        }
    
    753
    -        return ImmutableMap.copyOf(mappingBuilder);
    
    754
    -    }
    
    755
    -
    
    756 767
     }

  • services-local/src/main/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocal.java
    ... ... @@ -238,8 +238,8 @@ public class FloatingObjectServiceLocal extends ObserveServiceLocal implements F
    238 238
     
    
    239 239
         private List<ObjectMaterialHierarchyDto> getObjectMaterialHierarchyDtos(List<ObjectMaterial> objectMaterials) {
    
    240 240
             Multimap<String, ObjectMaterial> childrenByParent = ArrayListMultimap.create();
    
    241
    -        objectMaterials.forEach(o -> childrenByParent.put(Optional.ofNullable(o.getParent()).map(ObjectMaterial::getTopiaId).orElse(null), o));
    
    242
    -        Collection<ObjectMaterial> topLevelMaterials = childrenByParent.get(null);
    
    241
    +        objectMaterials.forEach(o -> childrenByParent.put(Optional.ofNullable(o.getParent()).map(ObjectMaterial::getTopiaId).orElse("Yo"), o));
    
    242
    +        Collection<ObjectMaterial> topLevelMaterials = childrenByParent.get("Yo");
    
    243 243
             ReferentialEntityDtoBinderSupport<ObjectMaterialDto, ObserveReferentialEntity> referentialBinder = OBJECT_MATERIAL_SPI.toEntityBinder();
    
    244 244
             ReferentialLocale referentialLocale = getReferentialLocale();
    
    245 245
             List<ObjectMaterialHierarchyDto> result = new LinkedList<>();
    

  • services-local/src/test/java/fr/ird/observe/services/local/service/actions/consolidate/dcp/SimplifiedObjectTypeManagerTest.java
    ... ... @@ -55,7 +55,7 @@ public class SimplifiedObjectTypeManagerTest extends ServiceLocalTestSupport {
    55 55
         @Test
    
    56 56
         public void getStandardCode() {
    
    57 57
     
    
    58
    -//        SimplifiedObjectTypeNode fob = simplifiedObjectTypeManager.getNodeForStandardCode("FOB");
    
    58
    +        SimplifiedObjectTypeNode fob = simplifiedObjectTypeManager.getNodeForStandardCode("FOB");
    
    59 59
             SimplifiedObjectTypeNode fad = simplifiedObjectTypeManager.getNodeForStandardCode("FAD");
    
    60 60
             SimplifiedObjectTypeNode dfad = simplifiedObjectTypeManager.getNodeForStandardCode("DFAD");
    
    61 61
             SimplifiedObjectTypeNode log = simplifiedObjectTypeManager.getNodeForStandardCode("LOG");
    
    ... ... @@ -65,11 +65,11 @@ public class SimplifiedObjectTypeManagerTest extends ServiceLocalTestSupport {
    65 65
             SimplifiedObjectTypeNode falog = simplifiedObjectTypeManager.getNodeForStandardCode("FALOG");
    
    66 66
             SimplifiedObjectTypeNode halog = simplifiedObjectTypeManager.getNodeForStandardCode("HALOG");
    
    67 67
     
    
    68
    -//        assertStandardCode(fob, fob);
    
    69
    -        assertStandardCode(fad, /*fob,*/ fad);
    
    68
    +        assertStandardCode(fob, fob);
    
    69
    +        assertStandardCode(fad, fob, fad);
    
    70 70
             assertStandardCode(dfad, fad, dfad, dfad);
    
    71 71
             assertStandardCode(falog, log, alog, falog);
    
    72
    -        assertStandardCode(null, dfad, log, nlog);
    
    72
    +        assertStandardCode(fob, dfad, log, nlog);
    
    73 73
             assertStandardCode(falog, alog, falog, falog);
    
    74 74
             assertStandardCode(alog, alog, falog, halog);
    
    75 75
             assertStandardCode(log, falog, vnlog);
    
    ... ... @@ -78,7 +78,7 @@ public class SimplifiedObjectTypeManagerTest extends ServiceLocalTestSupport {
    78 78
     
    
    79 79
         private void assertStandardCode(SimplifiedObjectTypeNode expectedStandardCode, SimplifiedObjectTypeNode... objectMaterialIds) {
    
    80 80
             String actualStandardCode = simplifiedObjectTypeManager.getStandardCode(ImmutableSet.copyOf(objectMaterialIds).stream().map(SimplifiedObjectTypeNode::getId).collect(Collectors.toSet()));
    
    81
    -        Assert.assertEquals(expectedStandardCode == null ? SimplifiedObjectTypeManager.FOB : expectedStandardCode.getStandardCode(), actualStandardCode);
    
    81
    +        Assert.assertEquals(expectedStandardCode.getStandardCode(), actualStandardCode);
    
    82 82
         }
    
    83 83
     
    
    84 84
     }

  • services-local/src/test/java/fr/ird/observe/services/local/service/data/seine/FloatingObjectServiceLocalTest.java
    ... ... @@ -52,7 +52,7 @@ public class FloatingObjectServiceLocalTest extends ServiceLocalTestSupport {
    52 52
     
    
    53 53
             List<ObjectMaterialHierarchyDto> form = service.getObjectMaterialHierarchy();
    
    54 54
             Assert.assertNotNull(form);
    
    55
    -        Assert.assertEquals(4, form.size());
    
    55
    +        Assert.assertEquals(1, form.size());
    
    56 56
     
    
    57 57
         }
    
    58 58
     
    

  • services/src/main/java/fr/ird/observe/services/service/actions/consolidate/ConsolidateDataService.java
    ... ... @@ -23,6 +23,8 @@ package fr.ird.observe.services.service.actions.consolidate;
    23 23
      */
    
    24 24
     
    
    25 25
     import fr.ird.observe.services.service.ObserveService;
    
    26
    +import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloatingObjectRequest;
    
    27
    +import fr.ird.observe.services.service.actions.consolidate.dcp.ConsolidateFloatingObjectResult;
    
    26 28
     import fr.ird.observe.services.service.actions.consolidate.dcp.SimplifiedObjectTypeManager;
    
    27 29
     import fr.ird.observe.services.spi.ReadDataPermission;
    
    28 30
     import fr.ird.observe.services.spi.ReadReferentialPermission;
    
    ... ... @@ -44,16 +46,26 @@ public interface ConsolidateDataService extends ObserveService {
    44 46
         SimplifiedObjectTypeManager newSimplifiedObjectTypeManager();
    
    45 47
     
    
    46 48
         /**
    
    47
    -     * Effectue la consolitation à partir de la demande passé en paramètre et retourne les résultats pour les marées
    
    48
    -     * modifiées.
    
    49
    +     * Consolidate trip data using given {@code request} and produce a result.
    
    49 50
          *
    
    50
    -     * @param consolidateTripSeineDataRequest la demande de consolidation
    
    51
    +     * @param request la demande de consolidation
    
    51 52
          * @return le résultat de la consolidation de données pour chaque marée qui a été modifée.
    
    52 53
          */
    
    53 54
         @ReadDataPermission
    
    54 55
         @WriteDataPermission
    
    55 56
         @Post
    
    56 57
         @Write
    
    57
    -    ConsolidateTripSeineDataResult consolidateTripSeine(ConsolidateTripSeineDataRequest consolidateTripSeineDataRequest);
    
    58
    +    ConsolidateTripSeineDataResult consolidateTripSeine(ConsolidateTripSeineDataRequest request);
    
    59
    +
    
    60
    +    /**
    
    61
    +     * Effectue la consolitation à partir de la demande passé en paramètre et retourne les résultats pour les marées
    
    62
    +     * modifiées.
    
    63
    +     *
    
    64
    +     * @param request request
    
    65
    +     * @return {@code null} if no modification done, or {@code result} of operation.
    
    66
    +     */
    
    67
    +    @ReadDataPermission
    
    68
    +    @Post
    
    69
    +    ConsolidateFloatingObjectResult consolidateFloatingObject(ConsolidateFloatingObjectRequest request);
    
    58 70
     
    
    59 71
     }

  • services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/ConsolidateFloatingObjectResult.java
    ... ... @@ -10,12 +10,12 @@ package fr.ird.observe.services.service.actions.consolidate.dcp;
    10 10
      * it under the terms of the GNU General Public License as
    
    11 11
      * published by the Free Software Foundation, either version 3 of the
    
    12 12
      * License, or (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU General Public
    
    20 20
      * License along with this program.  If not, see
    
    21 21
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    ... ... @@ -24,6 +24,9 @@ package fr.ird.observe.services.service.actions.consolidate.dcp;
    24 24
     
    
    25 25
     import com.google.common.collect.ImmutableSet;
    
    26 26
     import fr.ird.observe.dto.ObserveDto;
    
    27
    +import fr.ird.observe.dto.data.seine.DcpComputedValue;
    
    28
    +import fr.ird.observe.dto.data.seine.FloatingObjectDto;
    
    29
    +
    
    27 30
     import java.io.Serializable;
    
    28 31
     
    
    29 32
     /**
    
    ... ... @@ -52,4 +55,38 @@ public class ConsolidateFloatingObjectResult implements Serializable, ObserveDto
    52 55
             return floatingObjectModifications;
    
    53 56
         }
    
    54 57
     
    
    58
    +    public void flushToDto(FloatingObjectDto dto) {
    
    59
    +        for (FloatingObjectModification floatingObjectModification : floatingObjectModifications) {
    
    60
    +            Serializable newValue = floatingObjectModification.getNewValue();
    
    61
    +            switch (floatingObjectModification.getPropertyName()) {
    
    62
    +                case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_ARRIVING_BIODEGRADABLE: {
    
    63
    +                    dto.setComputedWhenArrivingBiodegradable((DcpComputedValue) newValue);
    
    64
    +                    break;
    
    65
    +                }
    
    66
    +                case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_ARRIVING_NON_ENTANGLING: {
    
    67
    +                    dto.setComputedWhenArrivingNonEntangling((DcpComputedValue) newValue);
    
    68
    +
    
    69
    +                    break;
    
    70
    +                }
    
    71
    +                case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_ARRIVING_SIMPLIFIED_OBJECT_TYPE: {
    
    72
    +                    dto.setComputedWhenArrivingSimplifiedObjectType((String) newValue);
    
    73
    +                    break;
    
    74
    +                }
    
    75
    +                case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_LEAVING_BIODEGRADABLE: {
    
    76
    +                    dto.setComputedWhenLeavingBiodegradable((DcpComputedValue) newValue);
    
    77
    +                    break;
    
    78
    +                }
    
    79
    +                case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_LEAVING_NON_ENTANGLING: {
    
    80
    +                    dto.setComputedWhenLeavingNonEntangling((DcpComputedValue) newValue);
    
    81
    +
    
    82
    +                    break;
    
    83
    +                }
    
    84
    +                case FloatingObjectDto.PROPERTY_COMPUTED_WHEN_LEAVING_SIMPLIFIED_OBJECT_TYPE: {
    
    85
    +                    dto.setComputedWhenLeavingSimplifiedObjectType((String) newValue);
    
    86
    +                    break;
    
    87
    +                }
    
    88
    +            }
    
    89
    +        }
    
    90
    +    }
    
    55 91
     }
    
    92
    +

  • services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/FloatingObjectConsolidateEngine.java
    ... ... @@ -136,6 +136,9 @@ public class FloatingObjectConsolidateEngine {
    136 136
         }
    
    137 137
     
    
    138 138
         private String computeDcpSimplifiedObjectType0(Set<FloatingObjectPartDto> FloatingObjectPartDtos) {
    
    139
    +        if (FloatingObjectPartDtos.isEmpty()) {
    
    140
    +            return null;
    
    141
    +        }
    
    139 142
             Set<String> objectMaterialIds = FloatingObjectPartDtos.stream().map(p -> p.getObjectMaterial().getId()).collect(Collectors.toSet());
    
    140 143
             return simplifiedObjectTypeManager.getStandardCode(objectMaterialIds);
    
    141 144
         }
    

  • services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeManager.java
    ... ... @@ -39,7 +39,6 @@ import java.util.Set;
    39 39
      */
    
    40 40
     public class SimplifiedObjectTypeManager implements ObserveDto {
    
    41 41
     
    
    42
    -    public static final String FOB = "FOB";
    
    43 42
         // For each object material, get his simplified object type node
    
    44 43
         private final ImmutableMap<String, SimplifiedObjectTypeNode> mapping;
    
    45 44
     
    
    ... ... @@ -48,7 +47,7 @@ public class SimplifiedObjectTypeManager implements ObserveDto {
    48 47
         }
    
    49 48
     
    
    50 49
         public SimplifiedObjectTypeNode getNodeForStandardCode(String standardCode) {
    
    51
    -        return mapping.values().stream().filter(n -> n.getStandardCode().equals(standardCode)).findFirst().orElseThrow(IllegalArgumentException::new);
    
    50
    +        return mapping.values().stream().filter(n -> Objects.equals(n.getStandardCode(), standardCode)).findFirst().orElseThrow(IllegalArgumentException::new);
    
    52 51
         }
    
    53 52
     
    
    54 53
         public String getStandardCode(Set<String> objectMaterialIds) {
    
    ... ... @@ -59,10 +58,6 @@ public class SimplifiedObjectTypeManager implements ObserveDto {
    59 58
             // get highest level first
    
    60 59
             availableNodes.sort(Comparator.comparing(SimplifiedObjectTypeNode::getLevel).reversed());
    
    61 60
     
    
    62
    -        if (availableNodes.isEmpty()) {
    
    63
    -            return FOB;
    
    64
    -        }
    
    65
    -
    
    66 61
             // remove from available nodes, all nodes in the path of other ones
    
    67 62
             List<SimplifiedObjectTypeNode> mainNodes = new LinkedList<>(availableNodes);
    
    68 63
     
    
    ... ... @@ -78,9 +73,6 @@ public class SimplifiedObjectTypeManager implements ObserveDto {
    78 73
             while (iterator.hasNext()) {
    
    79 74
                 result = result.getSharedAncestor(iterator.next());
    
    80 75
             }
    
    81
    -        if (result==null) {
    
    82
    -            return FOB;
    
    83
    -        }
    
    84 76
             Objects.requireNonNull(result);
    
    85 77
             return result.getStandardCode();
    
    86 78
         }
    

  • services/src/main/java/fr/ird/observe/services/service/actions/consolidate/dcp/SimplifiedObjectTypeNode.java
    ... ... @@ -10,12 +10,12 @@ package fr.ird.observe.services.service.actions.consolidate.dcp;
    10 10
      * it under the terms of the GNU General Public License as
    
    11 11
      * published by the Free Software Foundation, either version 3 of the
    
    12 12
      * License, or (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU General Public
    
    20 20
      * License along with this program.  If not, see
    
    21 21
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    ... ... @@ -70,7 +70,7 @@ public class SimplifiedObjectTypeNode {
    70 70
             result.retainAll(otherPathsToRoot);
    
    71 71
     
    
    72 72
             // get the most precise on common paths (if it exists)
    
    73
    -        return result.isEmpty() ? null : result.get(0);
    
    73
    +        return result.isEmpty() ? pathsToRoot.get(pathsToRoot.size() - 1) : result.get(0);
    
    74 74
         }
    
    75 75
     
    
    76 76
         @Override
    

  • test/src/main/java/fr/ird/observe/test/ObserveFixtures.java
    ... ... @@ -117,7 +117,7 @@ public class ObserveFixtures {
    117 117
                 .put("observe_seine.nontargetcatchreleasestatus", 5L)
    
    118 118
                 .put("observe_seine.nontargetcatchreleasingtime", 4L)
    
    119 119
                 .put("observe_seine.objectoperation", 10L)
    
    120
    -            .put("observe_seine.objectmaterial", 77L)
    
    120
    +            .put("observe_seine.objectmaterial", 78L)
    
    121 121
                 .put("observe_seine.objectmaterialtype", 4L)
    
    122 122
                 .put("observe_seine.observedsystem", 21L)
    
    123 123
                 .put("observe_seine.reasonfordiscard", 5L)
    

  • test/src/main/resources/db/7.2/dataForTestLongline.sql.gz
    No preview for this file type
  • test/src/main/resources/db/7.2/dataForTestSeine.sql.gz
    No preview for this file type
  • test/src/main/resources/db/7.2/referentiel.sql.gz
    No preview for this file type