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

Commits:

10 changed files:

Changes:

  • CHANGELOG.md
    1 1
     # ObServe changelog
    
    2 2
     
    
    3 3
      * Author [Tony Chemit](mailto:dev@tchemit.fr)
    
    4
    - * Last generated at 2023-02-14 12:38.
    
    4
    + * Last generated at 2023-03-08 09:00.
    
    5 5
     
    
    6 6
     ## Version [9.1.0-RC-1](https://gitlab.com/ultreiaio/ird-observe/-/milestones/243)
    
    7 7
     
    
    ... ... @@ -13,16 +13,32 @@
    13 13
     * [Serveur (observe-9.1.0-RC-1-server.zip)](https://repo1.maven.org/maven2/fr/ird/observe/observe/9.1.0-RC-1/observe-9.1.0-RC-1-server.zip)
    
    14 14
     
    
    15 15
     ### Issues
    
    16
    -  * [[Type::Anomalie 2546]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2546) **Quelques inexactitudes sur la persistence (découvert en voulant migrer vers Hibernate 6)** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    17
    -  * [[Type::Evolution 2218]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2218) **tms_version va-t-elle rester dans le schéma public ?** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
    
    18
    -  * [[Type::Evolution 2435]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2435) **Renommer l'entité  common.LengthMeasureMethod en common.SizeMeasureMethod** (Thanks to Pascal Cauquil) (Reported by Pascal Cauquil)
    
    19
    -  * [[Type::Evolution 2478]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2478) **Réusinage du plan de cuve** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    20
    -  * [[Type::Evolution 2600]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2600) **Nouvelle référence 'Refueling'** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
    
    21
    -  * [[Type::Evolution 2602]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2602) **Table ll_common.weightdeterminationmethod inutile ?** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
    
    22
    -  * [[Type::Evolution 2612]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2612) **Gestion des FAD sur OPERA AVDTH non mappées vers VesselActivity avec allowFad=TRUE** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
    
    23
    -  * [[Type::Evolution 2617]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2617) **Ajout de ps_common.TransmittingBuoyOperation 99** (Thanks to ) (Reported by Tony CHEMIT)
    
    24
    -  * [[Type::Evolution 2618]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2618) **Ajout de ps_landing.Destination 28 et 29** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    25
    -  * [[Type::Evolution 2620]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2620) **Nettoyage de la table LastUpdateDate** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    16
    +* [[Type::Anomalie 2546]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2546) **Quelques inexactitudes sur la persistence (découvert en voulant migrer vers Hibernate 6)** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    17
    +* [[Type::Evolution 2218]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2218) **tms_version va-t-elle rester dans le schéma public ?** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
    
    18
    +* [[Type::Evolution 2435]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2435) **Renommer l'entité  common.LengthMeasureMethod en common.SizeMeasureMethod** (Thanks to Pascal Cauquil) (Reported by Pascal Cauquil)
    
    19
    +* [[Type::Evolution 2478]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2478) **Réusinage du plan de cuve** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    20
    +* [[Type::Evolution 2600]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2600) **Nouvelle référence 'Refueling'** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
    
    21
    +* [[Type::Evolution 2602]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2602) **Table ll_common.weightdeterminationmethod inutile ?** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
    
    22
    +* [[Type::Evolution 2612]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2612) **Gestion des FAD sur OPERA AVDTH non mappées vers VesselActivity avec allowFad=TRUE** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
    
    23
    +* [[Type::Evolution 2617]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2617) **Ajout de ps_common.TransmittingBuoyOperation 99** (Thanks to ) (Reported by Tony CHEMIT)
    
    24
    +* [[Type::Evolution 2618]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2618) **Ajout de ps_landing.Destination 28 et 29** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    25
    +* [[Type::Evolution 2620]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2620) **Nettoyage de la table LastUpdateDate** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    26
    +
    
    27
    +## Version [9.0.26](https://gitlab.com/ultreiaio/ird-observe/-/milestones/256)
    
    28
    +
    
    29
    +**Closed at 2023-03-08.**
    
    30
    +
    
    31
    +### Download
    
    32
    +* [Client (observe-9.0.26-client.zip)](https://repo1.maven.org/maven2/fr/ird/observe/observe/9.0.26/observe-9.0.26-client.zip)
    
    33
    +* [Serveur (observe-9.0.26.war)](https://repo1.maven.org/maven2/fr/ird/observe/observe/9.0.26/observe-9.0.26.war)
    
    34
    +* [Serveur (observe-9.0.26-server.zip)](https://repo1.maven.org/maven2/fr/ird/observe/observe/9.0.26/observe-9.0.26-server.zip)
    
    35
    +
    
    36
    +### Issues
    
    37
    +  * [[Type::Anomalie 2629]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2629) **Revue de la précision lors des calcul de RTP et RTT** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    38
    +  * [[Type::Anomalie 2630]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2630) **Revue du code de l'action de consolidation et amélioration de la sortie de l'action** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    39
    +  * [[Type::Anomalie 2631]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2631) **Ajouter des options dans la configuration du client pour configurer l'action de consolidation** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    40
    +  * [[Type::Anomalie 2632]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2632) **Problème lors de la connexion à des bases distantes (la version du modèle de la première base testée est conservée ensuite comme version de modèle requis)** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    41
    +  * [[Type::Evolution 2633]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2633) **Supprimer de la génération des Dto de méthodes non utilisées (pour les propriétés à multiplicité n)** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
    
    26 42
     
    
    27 43
     ## Version [9.0.25](https://gitlab.com/ultreiaio/ird-observe/-/milestones/255)
    
    28 44
     
    

  • core/api/dto-consolidation/pom.xml
    ... ... @@ -56,6 +56,10 @@
    56 56
           <groupId>io.ultreia.java4all</groupId>
    
    57 57
           <artifactId>java-util</artifactId>
    
    58 58
         </dependency>
    
    59
    +    <dependency>
    
    60
    +      <groupId>io.ultreia.java4all.decorator</groupId>
    
    61
    +      <artifactId>decorator-api</artifactId>
    
    62
    +    </dependency>
    
    59 63
         <dependency>
    
    60 64
           <groupId>org.apache.logging.log4j</groupId>
    
    61 65
           <artifactId>log4j-api</artifactId>
    

  • core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/AtomicConsolidateAction.java
    ... ... @@ -53,18 +53,26 @@ public interface AtomicConsolidateAction<C extends ConsolidateContext<E>, E exte
    53 53
         default boolean execute(C context, E data) {
    
    54 54
             if (test(context, data)) {
    
    55 55
                 accept(context, data);
    
    56
    -            String fieldName = fieldName();
    
    57
    -            context.getModification(fieldName).ifPresent(modification -> log.info(String.format("%s [%s] property '%s.%s' was computed [old value: %s - new value: %s] (by action %s)",
    
    58
    -                                                                                                context.getLogPrefix(),
    
    59
    -                                                                                                data.getTopiaId(),
    
    60
    -                                                                                                context.dataType().getSimpleName(),
    
    61
    -                                                                                                fieldName,
    
    62
    -                                                                                                modification.getOldValue(),
    
    63
    -                                                                                                modification.getNewValue(),
    
    64
    -                                                                                                this)));
    
    56
    +            logModification(context, data);
    
    65 57
                 return true;
    
    66 58
             }
    
    67 59
             return false;
    
    68 60
         }
    
    69 61
     
    
    62
    +
    
    63
    +    default void logModification(C context, E data) {
    
    64
    +        String fieldName = fieldName();
    
    65
    +        logModification(context, data, fieldName);
    
    66
    +    }
    
    67
    +
    
    68
    +    default void logModification(C context, E data, String fieldName) {
    
    69
    +        context.getModification(fieldName).ifPresent(modification -> log.info(String.format("[%s] property '%s.%s' has changed [old value: %s - new value: %s] (by action %s)",
    
    70
    +                                                                                            data.getTopiaId(),
    
    71
    +                                                                                            context.dataType().getSimpleName(),
    
    72
    +                                                                                            fieldName,
    
    73
    +                                                                                            modification.getOldValue(),
    
    74
    +                                                                                            modification.getNewValue(),
    
    75
    +                                                                                            this)));
    
    76
    +    }
    
    77
    +
    
    70 78
     }

  • core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/ConsolidateContext.java
    ... ... @@ -36,8 +36,6 @@ import java.util.Optional;
    36 36
      */
    
    37 37
     public interface ConsolidateContext<E extends ToolkitId> {
    
    38 38
     
    
    39
    -    String getLogPrefix();
    
    40
    -
    
    41 39
         JavaBeanMonitor monitor();
    
    42 40
     
    
    43 41
         default Optional<JavaBeanPropertyModification> getModification(String fieldName) {
    

  • core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/localmarket/BatchConsolidateActions.java
    1
    +package fr.ird.observe.consolidation.data.ps.localmarket;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Core :: API :: Dto Consolidation
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2023 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.consolidation.AtomicConsolidateAction;
    
    26
    +import fr.ird.observe.dto.ProtectedIdsPs;
    
    27
    +import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
    
    28
    +import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
    
    29
    +import fr.ird.observe.dto.referential.common.SpeciesReference;
    
    30
    +import fr.ird.observe.dto.referential.ps.localmarket.BatchWeightTypeReference;
    
    31
    +import io.ultreia.java4all.lang.Numbers;
    
    32
    +
    
    33
    +import java.util.Date;
    
    34
    +import java.util.Optional;
    
    35
    +
    
    36
    +/**
    
    37
    + * Created on 24/02/2023.
    
    38
    + *
    
    39
    + * @author Tony Chemit - dev@tchemit.fr
    
    40
    + * @since 9.0.26
    
    41
    + */
    
    42
    +public enum BatchConsolidateActions implements AtomicConsolidateAction<BatchConsolidateContext, BatchDto> {
    
    43
    +
    
    44
    +
    
    45
    +    ComputeWeightFromSpeciesMeanWeight() {
    
    46
    +        @Override
    
    47
    +        public boolean test(BatchConsolidateContext context, BatchDto dto) {
    
    48
    +            if (dto.getCount() == null) {
    
    49
    +                // this method requires count
    
    50
    +                return false;
    
    51
    +            }
    
    52
    +            BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
    
    53
    +            return batchWeightType != null && ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_SINGLE_SPECIES_INDIVIDUAL.equals(batchWeightType.getId());
    
    54
    +        }
    
    55
    +
    
    56
    +        @Override
    
    57
    +        public void accept(BatchConsolidateContext context, BatchDto dto) {
    
    58
    +
    
    59
    +            // espèce unité
    
    60
    +            // P = poids moyen de l'espèce * batch.count / 1000
    
    61
    +            // ocean = océan de débarquement de la marée = ps_common.trip.ocean
    
    62
    +            //lengthweightparameter.startdate <= trip.enddate <= lengthweightparameter.enddate
    
    63
    +            //sex = 0 - indéterminé (fr.ird.referential.common.Sex#1239832686121#0.0)
    
    64
    +            //sizemeasuretype = type de mesure par défaut de l'espèce = common.species.sizemeasuretype
    
    65
    +            // Si aucun poids moyen n'est trouvé P = NULL.
    
    66
    +
    
    67
    +            SpeciesReference species = dto.getSpecies();
    
    68
    +            String sizeMeasureTypeId = species.getSizeMeasureTypeId();
    
    69
    +            BatchConsolidateRequest request = context.getRequest();
    
    70
    +            String oceanId = request.getOceanId();
    
    71
    +            Date date = request.getDate();
    
    72
    +            boolean failIfLengthWeightParameterNotFound = request.isFailIfLengthWeightParameterNotFound();
    
    73
    +            Optional<Float> optionalMeanWeight = context.getRtpMeanWeightFinder().get(species.getId(),
    
    74
    +                                                                                      "fr.ird.referential.common.Sex#1239832686121#0.0",
    
    75
    +                                                                                      oceanId,
    
    76
    +                                                                                      sizeMeasureTypeId,
    
    77
    +                                                                                      date,
    
    78
    +                                                                                      failIfLengthWeightParameterNotFound,
    
    79
    +                                                                                      context::registerLengthWeightParameterNotFound);
    
    80
    +            if (optionalMeanWeight.isPresent()) {
    
    81
    +                Float meanWeight = optionalMeanWeight.get();
    
    82
    +                dto.setWeight(Numbers.roundFourDigits(meanWeight * dto.getCount() / 1000));
    
    83
    +                dto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
    
    84
    +            } else {
    
    85
    +                dto.setWeight(null);
    
    86
    +                dto.setWeightComputedSource(null);
    
    87
    +            }
    
    88
    +        }
    
    89
    +
    
    90
    +    },
    
    91
    +    ComputeWeightFromPackagingMeanWeight() {
    
    92
    +        @Override
    
    93
    +        public boolean test(BatchConsolidateContext context, BatchDto dto) {
    
    94
    +            if (dto.getCount() == null) {
    
    95
    +                // this method requires count
    
    96
    +                return false;
    
    97
    +            }
    
    98
    +            BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
    
    99
    +            return batchWeightType != null && ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_PACKAGING_NOT_WEIGHTED.equals(batchWeightType.getId());
    
    100
    +        }
    
    101
    +
    
    102
    +        @Override
    
    103
    +        public void accept(BatchConsolidateContext context, BatchDto dto) {
    
    104
    +            //  Paquet/Conditionnement non pesé
    
    105
    +            //  P = batch.packaging.meanWeight * batch.count (ou null si pas de packaging.meanWeight)
    
    106
    +            Float meanWeight = dto.getPackaging().getMeanWeight();
    
    107
    +            if (meanWeight == null) {
    
    108
    +                dto.setWeight(null);
    
    109
    +                dto.setWeightComputedSource(null);
    
    110
    +            } else {
    
    111
    +                dto.setWeight(Numbers.roundFourDigits(dto.getCount() * meanWeight));
    
    112
    +                dto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
    
    113
    +            }
    
    114
    +        }
    
    115
    +    },
    
    116
    +    ResetWeightValues() {
    
    117
    +        @Override
    
    118
    +        public boolean test(BatchConsolidateContext context, BatchDto dto) {
    
    119
    +            return true;
    
    120
    +        }
    
    121
    +
    
    122
    +        @Override
    
    123
    +        public void accept(BatchConsolidateContext context, BatchDto dto) {
    
    124
    +            dto.setWeight(null);
    
    125
    +            dto.setWeightComputedSource(null);
    
    126
    +        }
    
    127
    +    };
    
    128
    +
    
    129
    +    @Override
    
    130
    +    public String fieldName() {
    
    131
    +        return BatchDto.PROPERTY_WEIGHT;
    
    132
    +    }
    
    133
    +
    
    134
    +
    
    135
    +    @Override
    
    136
    +    public void logModification(BatchConsolidateContext context, BatchDto data) {
    
    137
    +        AtomicConsolidateAction.super.logModification(context, data);
    
    138
    +        AtomicConsolidateAction.super.logModification(context, data, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
    
    139
    +    }
    
    140
    +}

  • core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/localmarket/BatchConsolidateContext.java
    ... ... @@ -22,10 +22,11 @@ package fr.ird.observe.consolidation.data.ps.localmarket;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    -import fr.ird.observe.decoration.DecoratorService;
    
    25
    +import fr.ird.observe.consolidation.ConsolidateContext;
    
    26 26
     import fr.ird.observe.dto.ToolkitIdModifications;
    
    27 27
     import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
    
    28 28
     import io.ultreia.java4all.bean.monitor.JavaBeanMonitor;
    
    29
    +import io.ultreia.java4all.decoration.Decorator;
    
    29 30
     import org.apache.logging.log4j.LogManager;
    
    30 31
     import org.apache.logging.log4j.Logger;
    
    31 32
     
    
    ... ... @@ -39,24 +40,36 @@ import java.util.Set;
    39 40
      * @author Tony Chemit - dev@tchemit.fr
    
    40 41
      * @since 9.0.26
    
    41 42
      */
    
    42
    -public class BatchConsolidateContext implements AutoCloseable {
    
    43
    +public class BatchConsolidateContext implements ConsolidateContext<BatchDto> {
    
    43 44
         private static final Logger log = LogManager.getLogger(BatchConsolidateContext.class);
    
    44 45
     
    
    46
    +    private final GetOptionalRtpMeanWeight rtpMeanWeightFinder;
    
    45 47
         private final JavaBeanMonitor monitor;
    
    48
    +    private final Decorator decorator;
    
    49
    +    private BatchConsolidateRequest request;
    
    50
    +    private BatchDto batch;
    
    46 51
         private String lengthWeightParameterNotFound;
    
    47 52
     
    
    48
    -    public BatchConsolidateContext(JavaBeanMonitor monitor, BatchDto bean) {
    
    53
    +    public BatchConsolidateContext(GetOptionalRtpMeanWeight rtpMeanWeightFinder, JavaBeanMonitor monitor, Decorator decorator) {
    
    54
    +        this.rtpMeanWeightFinder = rtpMeanWeightFinder;
    
    49 55
             this.monitor = Objects.requireNonNull(monitor);
    
    50
    -        this.monitor.setBean(Objects.requireNonNull(bean));
    
    56
    +        this.decorator = decorator;
    
    51 57
         }
    
    52 58
     
    
    53
    -    public Optional<ToolkitIdModifications> build(DecoratorService decoratorService) {
    
    54
    -        BatchDto bean = (BatchDto) monitor.getBean();
    
    59
    +    public void watch(BatchConsolidateRequest request) {
    
    60
    +        this.request = Objects.requireNonNull(request);
    
    61
    +        this.batch = Objects.requireNonNull(request.getBatch());
    
    62
    +        monitor.setBean(batch);
    
    63
    +    }
    
    64
    +
    
    65
    +    public Optional<ToolkitIdModifications> build() {
    
    55 66
             if (monitor.wasModified()) {
    
    56
    -            decoratorService.installDecorator(bean);
    
    57
    -            return monitor.toModifications(modifications -> new ToolkitIdModifications(bean, modifications, lengthWeightParameterNotFound == null ? null : Set.of(lengthWeightParameterNotFound)));
    
    67
    +            batch.registerDecorator(decorator);
    
    68
    +            Optional<ToolkitIdModifications> result = monitor.toModifications(modifications -> new ToolkitIdModifications(batch, modifications, lengthWeightParameterNotFound == null ? null : Set.of(lengthWeightParameterNotFound)));
    
    69
    +            result.ifPresent(m -> m.reset(batch));
    
    70
    +            return result;
    
    58 71
             } else if (lengthWeightParameterNotFound != null) {
    
    59
    -            return Optional.of(new ToolkitIdModifications(bean, Set.of(), Set.of(lengthWeightParameterNotFound)));
    
    72
    +            return Optional.of(new ToolkitIdModifications(batch, Set.of(), Set.of(lengthWeightParameterNotFound)));
    
    60 73
             }
    
    61 74
             return Optional.empty();
    
    62 75
         }
    
    ... ... @@ -68,8 +81,27 @@ public class BatchConsolidateContext implements AutoCloseable {
    68 81
             }
    
    69 82
         }
    
    70 83
     
    
    71
    -    @Override
    
    72
    -    public void close() {
    
    84
    +    public BatchConsolidateRequest getRequest() {
    
    85
    +        return request;
    
    86
    +    }
    
    87
    +
    
    88
    +    public GetOptionalRtpMeanWeight getRtpMeanWeightFinder() {
    
    89
    +        return rtpMeanWeightFinder;
    
    90
    +    }
    
    91
    +
    
    92
    +    public void clear() {
    
    93
    +        this.batch = null;
    
    94
    +        this.request = null;
    
    73 95
             monitor.setBean(null);
    
    74 96
         }
    
    97
    +
    
    98
    +    @Override
    
    99
    +    public JavaBeanMonitor monitor() {
    
    100
    +        return monitor;
    
    101
    +    }
    
    102
    +
    
    103
    +    @Override
    
    104
    +    public Class<BatchDto> dataType() {
    
    105
    +        return BatchDto.class;
    
    106
    +    }
    
    75 107
     }

  • core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/localmarket/BatchConsolidateEngine.java
    ... ... @@ -23,19 +23,12 @@ package fr.ird.observe.consolidation.data.ps.localmarket;
    23 23
      */
    
    24 24
     
    
    25 25
     import fr.ird.observe.decoration.DecoratorService;
    
    26
    -import fr.ird.observe.dto.ProtectedIdsPs;
    
    27 26
     import fr.ird.observe.dto.ToolkitIdModifications;
    
    28 27
     import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
    
    29
    -import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
    
    30
    -import fr.ird.observe.dto.referential.common.SpeciesReference;
    
    31
    -import fr.ird.observe.dto.referential.ps.localmarket.BatchWeightTypeReference;
    
    32 28
     import io.ultreia.java4all.bean.monitor.JavaBeanMonitor;
    
    33
    -import io.ultreia.java4all.lang.Numbers;
    
    34 29
     import org.apache.logging.log4j.LogManager;
    
    35 30
     import org.apache.logging.log4j.Logger;
    
    36 31
     
    
    37
    -import java.util.Date;
    
    38
    -import java.util.Objects;
    
    39 32
     import java.util.Optional;
    
    40 33
     
    
    41 34
     /**
    
    ... ... @@ -48,98 +41,41 @@ public class BatchConsolidateEngine {
    48 41
     
    
    49 42
         private static final Logger log = LogManager.getLogger(BatchConsolidateEngine.class);
    
    50 43
     
    
    51
    -    private final GetOptionalRtpMeanWeight rtpMeanWeightFinder;
    
    52
    -    private final DecoratorService decoratorService;
    
    53
    -    private final JavaBeanMonitor monitor;
    
    44
    +    private final BatchConsolidateContext context;
    
    54 45
     
    
    55 46
         public BatchConsolidateEngine(GetOptionalRtpMeanWeight rtpMeanWeightFinder, DecoratorService decoratorService) {
    
    56
    -        this.rtpMeanWeightFinder = Objects.requireNonNull(rtpMeanWeightFinder);
    
    57
    -        this.decoratorService = Objects.requireNonNull(decoratorService);
    
    58
    -        this.monitor = new JavaBeanMonitor(BatchDto.PROPERTY_WEIGHT, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
    
    47
    +        JavaBeanMonitor monitor = new JavaBeanMonitor(BatchDto.PROPERTY_WEIGHT, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
    
    48
    +        this.context = new BatchConsolidateContext(rtpMeanWeightFinder, monitor, decoratorService.getDecoratorByType(BatchDto.class));
    
    59 49
         }
    
    60 50
     
    
    61 51
         public Optional<ToolkitIdModifications> consolidate(BatchConsolidateRequest request) {
    
    62 52
             BatchDto dto = request.getBatch();
    
    63
    -        try (BatchConsolidateContext context = new BatchConsolidateContext(monitor, dto)) {
    
    64
    -            consolidateWeight(context,
    
    65
    -                              dto,
    
    66
    -                              request.getOceanId(),
    
    67
    -                              request.getDate(),
    
    68
    -                              request.isFailIfLengthWeightParameterNotFound());
    
    69
    -            Optional<ToolkitIdModifications> result = context.build(decoratorService);
    
    53
    +
    
    54
    +        // the only thing we can consolidate is the batch.weight
    
    55
    +        if (dto.getWeight() != null && dto.getWeightComputedSource() == null) {
    
    56
    +            // the value was set by user, do not change any thing
    
    57
    +            return Optional.empty();
    
    58
    +        }
    
    59
    +        context.watch(request);
    
    60
    +
    
    61
    +        try {
    
    62
    +            if (!BatchConsolidateActions.ComputeWeightFromSpeciesMeanWeight.execute(context, dto)) {
    
    63
    +                if (!BatchConsolidateActions.ComputeWeightFromPackagingMeanWeight.execute(context, dto)) {
    
    64
    +                    BatchConsolidateActions.ResetWeightValues.execute(context, dto);
    
    65
    +                }
    
    66
    +            }
    
    67
    +            Optional<ToolkitIdModifications> result = context.build();
    
    70 68
                 result.ifPresent(r -> {
    
    71 69
                     if (r.withModifications()) {
    
    72 70
                         log.info(String.format("Found some modifications on batch: %s", request.getBatch().getId()));
    
    73 71
                     }
    
    74 72
                     if (r.withWarnings()) {
    
    75
    -                    log.info(String.format("Found some warnings on batch: %s", request.getBatch().getId()));
    
    73
    +                    log.warn(String.format("Found some warnings on batch: %s", request.getBatch().getId()));
    
    76 74
                     }
    
    77 75
                 });
    
    78 76
                 return result;
    
    79
    -        }
    
    80
    -    }
    
    81
    -
    
    82
    -    private void consolidateWeight(BatchConsolidateContext context,
    
    83
    -                                   BatchDto dto,
    
    84
    -                                   String oceanId,
    
    85
    -                                   Date date,
    
    86
    -                                   boolean failIfLengthWeightParameterNotFound) {
    
    87
    -
    
    88
    -        Float weight = dto.getWeight();
    
    89
    -        if (weight != null && dto.getWeightComputedSource() == null) {
    
    90
    -            // the value was set by user, do not change any thing
    
    91
    -            return;
    
    92
    -        }
    
    93
    -        // always reset computed source state
    
    94
    -        dto.setWeightComputedSource(null);
    
    95
    -        // always reset weight since it was computed
    
    96
    -        dto.setWeight(null);
    
    97
    -        BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
    
    98
    -        Integer count = dto.getCount();
    
    99
    -        switch (batchWeightType.getId()) {
    
    100
    -            case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_WEIGHING:
    
    101
    -                // pesée poids direct
    
    102
    -                // P = batch.weight
    
    103
    -                // donc rien à faire
    
    104
    -                //FIXME Si il faut repousser le poids!
    
    105
    -                dto.setWeight(weight);
    
    106
    -                break;
    
    107
    -            case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_SINGLE_SPECIES_INDIVIDUAL:
    
    108
    -                // espèce unité
    
    109
    -                // P = poids moyen de l'espèce * batch.count / 1000
    
    110
    -                // ocean = océan de débarquement de la marée = ps_common.trip.ocean
    
    111
    -                //lengthweightparameter.startdate <= trip.enddate <= lengthweightparameter.enddate
    
    112
    -                //sex = 0 - indéterminé (fr.ird.referential.common.Sex#1239832686121#0.0)
    
    113
    -                //sizemeasuretype = type de mesure par défaut de l'espèce = common.species.sizemeasuretype
    
    114
    -                // Si aucun poids moyen n'est trouvé P = NULL.
    
    115
    -
    
    116
    -                if (count != null) {
    
    117
    -                    SpeciesReference species = dto.getSpecies();
    
    118
    -                    String sizeMeasureTypeId = species.getSizeMeasureTypeId();
    
    119
    -                    Optional<Float> optionalMeanWeight = rtpMeanWeightFinder.get(species.getId(),
    
    120
    -                                                                                 "fr.ird.referential.common.Sex#1239832686121#0.0",
    
    121
    -                                                                                 oceanId,
    
    122
    -                                                                                 sizeMeasureTypeId,
    
    123
    -                                                                                 date,
    
    124
    -                                                                                 failIfLengthWeightParameterNotFound,
    
    125
    -                                                                                 context::registerLengthWeightParameterNotFound);
    
    126
    -                    optionalMeanWeight.ifPresent(meanWeight -> {
    
    127
    -                        dto.setWeight(Numbers.roundFourDigits(meanWeight * count / 1000));
    
    128
    -                        dto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
    
    129
    -                    });
    
    130
    -                }
    
    131
    -                break;
    
    132
    -            case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_PACKAGING_NOT_WEIGHTED:
    
    133
    -                //  Paquet/Conditionnement non pesé
    
    134
    -                //  P = batch.packaging.meanWeight * batch.count (ou null si pas de packaging.meanWeight)
    
    135
    -                if (count != null) {
    
    136
    -                    Float meanWeight = dto.getPackaging().getMeanWeight();
    
    137
    -                    if (meanWeight != null) {
    
    138
    -                        dto.setWeight(Numbers.roundFourDigits(count * meanWeight));
    
    139
    -                        dto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
    
    140
    -                    }
    
    141
    -                }
    
    142
    -                break;
    
    77
    +        } finally {
    
    78
    +            context.clear();
    
    143 79
             }
    
    144 80
         }
    
    145 81
     }
    

  • core/persistence/consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/observation/SampleConsolidateContext.java
    ... ... @@ -118,7 +118,6 @@ public class SampleConsolidateContext implements ConsolidateContext<SampleMeasur
    118 118
             return getLengthLengthParameter() != null;
    
    119 119
         }
    
    120 120
     
    
    121
    -    @Override
    
    122 121
         public String getLogPrefix() {
    
    123 122
             return logPrefix;
    
    124 123
         }
    

  • core/services/test/src/main/java/fr/ird/observe/services/service/data/ps/ConsolidateDataServiceFixtures.java
    ... ... @@ -34,10 +34,14 @@ import fr.ird.observe.consolidation.data.ps.observation.FloatingObjectConsolidat
    34 34
     import fr.ird.observe.decoration.DecoratorService;
    
    35 35
     import fr.ird.observe.dto.ToolkitIdModifications;
    
    36 36
     import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
    
    37
    +import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
    
    37 38
     import fr.ird.observe.dto.data.ps.localmarket.TripBatchDto;
    
    38 39
     import fr.ird.observe.dto.form.Form;
    
    39 40
     import fr.ird.observe.dto.referential.ReferentialLocale;
    
    41
    +import fr.ird.observe.dto.referential.common.SpeciesReference;
    
    42
    +import fr.ird.observe.dto.referential.ps.localmarket.PackagingReference;
    
    40 43
     import fr.ird.observe.services.ObserveServicesProvider;
    
    44
    +import io.ultreia.java4all.util.Dates;
    
    41 45
     import org.junit.Assert;
    
    42 46
     
    
    43 47
     import java.net.URL;
    
    ... ... @@ -100,11 +104,75 @@ public class ConsolidateDataServiceFixtures extends GeneratedConsolidateDataServ
    100 104
             List<BatchDto> children = form.getObject().getChildren();
    
    101 105
             Assert.assertNotNull(children);
    
    102 106
             Assert.assertEquals(2, children.size());
    
    103
    -        request.setOceanId("fr.ird.referential.common.Ocean#1239832686151#0.17595105505051245");
    
    107
    +        request.setOceanId("fr.ird.referential.common.Ocean#1239832686152#0.8325731048817705");
    
    104 108
             request.setBatch(children.get(0));
    
    105 109
             ToolkitIdModifications actual = service.consolidateLocalmarketBatch(request);
    
    110
    +
    
    106 111
             //FIXME:Test Get a real dto
    
    107 112
             Assert.assertNull(actual);
    
    113
    +
    
    114
    +        {
    
    115
    +
    
    116
    +            BatchDto createDto = new BatchDto();
    
    117
    +            createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.1");
    
    118
    +            createDto.setCount(5);
    
    119
    +            createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#001"));
    
    120
    +            createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
    
    121
    +            createDto.setDate(Dates.createDate(30, 3, 2021));
    
    122
    +            request.setBatch(createDto);
    
    123
    +            request.setDate(createDto.getDate());
    
    124
    +
    
    125
    +            actual = service.consolidateLocalmarketBatch(request);
    
    126
    +
    
    127
    +            Assert.assertNotNull(actual);
    
    128
    +        }
    
    129
    +        {
    
    130
    +
    
    131
    +            BatchDto createDto = new BatchDto();
    
    132
    +            createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.2");
    
    133
    +            createDto.setCount(5);
    
    134
    +            createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#039"));
    
    135
    +            createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
    
    136
    +            createDto.setDate(Dates.createDate(30, 3, 2021));
    
    137
    +            request.setBatch(createDto);
    
    138
    +            request.setDate(createDto.getDate());
    
    139
    +
    
    140
    +            actual = service.consolidateLocalmarketBatch(request);
    
    141
    +
    
    142
    +            Assert.assertNotNull(actual);
    
    143
    +        }
    
    144
    +        {
    
    145
    +
    
    146
    +            BatchDto createDto = new BatchDto();
    
    147
    +            createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.3");
    
    148
    +            createDto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
    
    149
    +            createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#022"));
    
    150
    +            createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
    
    151
    +            createDto.setDate(Dates.createDate(30, 3, 2021));
    
    152
    +            request.setBatch(createDto);
    
    153
    +            request.setDate(createDto.getDate());
    
    154
    +
    
    155
    +            actual = service.consolidateLocalmarketBatch(request);
    
    156
    +
    
    157
    +            Assert.assertNotNull(actual);
    
    158
    +        }
    
    159
    +
    
    160
    +        {
    
    161
    +
    
    162
    +            BatchDto createDto = new BatchDto();
    
    163
    +            createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.4");
    
    164
    +            createDto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
    
    165
    +            createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#022"));
    
    166
    +            createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
    
    167
    +            createDto.setDate(Dates.createDate(30, 3, 2021));
    
    168
    +            createDto.setWeight(100.0f);
    
    169
    +            request.setBatch(createDto);
    
    170
    +            request.setDate(createDto.getDate());
    
    171
    +
    
    172
    +            actual = service.consolidateLocalmarketBatch(request);
    
    173
    +
    
    174
    +            Assert.assertNotNull(actual);
    
    175
    +        }
    
    108 176
         }
    
    109 177
     
    
    110 178
         @Override
    

  • pom.xml
    ... ... @@ -23,7 +23,7 @@
    23 23
       <parent>
    
    24 24
         <groupId>io.ultreia.maven</groupId>
    
    25 25
         <artifactId>pom</artifactId>
    
    26
    -    <version>2023.9</version>
    
    26
    +    <version>2023.10</version>
    
    27 27
       </parent>
    
    28 28
       <groupId>fr.ird.observe</groupId>
    
    29 29
       <artifactId>ird-observe</artifactId>