Tony CHEMIT pushed to branch develop-9.0.x at ultreiaio / ird-observe
Commits:
-
4666462e
by Tony Chemit at 2023-03-07T14:25:26+01:00
-
b18fcd29
by Tony Chemit at 2023-03-07T15:21:54+01:00
6 changed files:
- core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/AtomicConsolidateAction.java
- + core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/localmarket/BatchConsolidateActions.java
- core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/localmarket/BatchConsolidateContext.java
- core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/localmarket/BatchConsolidateEngine.java
- core/services/test/src/main/java/fr/ird/observe/services/service/data/ps/ConsolidateDataServiceFixtures.java
- pom.xml
Changes:
| ... | ... | @@ -53,17 +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] property '%s.%s' has changed [old value: %s - new value: %s] (by action %s)",
|
|
| 58 | - data.getTopiaId(),
|
|
| 59 | - context.dataType().getSimpleName(),
|
|
| 60 | - fieldName,
|
|
| 61 | - modification.getOldValue(),
|
|
| 62 | - modification.getNewValue(),
|
|
| 63 | - this)));
|
|
| 56 | + logModification(context, data);
|
|
| 64 | 57 | return true;
|
| 65 | 58 | }
|
| 66 | 59 | return false;
|
| 67 | 60 | }
|
| 68 | 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 | + |
|
| 69 | 78 | } |
| 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 | +} |
| ... | ... | @@ -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 | } |
| ... | ... | @@ -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 | }
|
| ... | ... | @@ -32,10 +32,14 @@ import fr.ird.observe.consolidation.data.ps.observation.ActivityConsolidateResul |
| 32 | 32 | import fr.ird.observe.decoration.DecoratorService;
|
| 33 | 33 | import fr.ird.observe.dto.ToolkitIdModifications;
|
| 34 | 34 | import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
|
| 35 | +import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
|
|
| 35 | 36 | import fr.ird.observe.dto.data.ps.localmarket.TripBatchDto;
|
| 36 | 37 | import fr.ird.observe.dto.form.Form;
|
| 37 | 38 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 39 | +import fr.ird.observe.dto.referential.common.SpeciesReference;
|
|
| 40 | +import fr.ird.observe.dto.referential.ps.localmarket.PackagingReference;
|
|
| 38 | 41 | import fr.ird.observe.services.ObserveServicesProvider;
|
| 42 | +import io.ultreia.java4all.util.Dates;
|
|
| 39 | 43 | import org.junit.Assert;
|
| 40 | 44 | |
| 41 | 45 | import java.net.URL;
|
| ... | ... | @@ -126,11 +130,75 @@ public class ConsolidateDataServiceFixtures extends GeneratedConsolidateDataServ |
| 126 | 130 | List<BatchDto> children = form.getObject().getChildren();
|
| 127 | 131 | Assert.assertNotNull(children);
|
| 128 | 132 | Assert.assertEquals(2, children.size());
|
| 129 | - request.setOceanId("fr.ird.referential.common.Ocean#1239832686151#0.17595105505051245");
|
|
| 133 | + request.setOceanId("fr.ird.referential.common.Ocean#1239832686152#0.8325731048817705");
|
|
| 130 | 134 | request.setBatch(children.get(0));
|
| 131 | 135 | ToolkitIdModifications actual = service.consolidateLocalmarketBatch(request);
|
| 136 | + |
|
| 132 | 137 | //FIXME:Test Get a real dto
|
| 133 | 138 | Assert.assertNull(actual);
|
| 139 | + |
|
| 140 | + {
|
|
| 141 | + |
|
| 142 | + BatchDto createDto = new BatchDto();
|
|
| 143 | + createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.1");
|
|
| 144 | + createDto.setCount(5);
|
|
| 145 | + createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#001"));
|
|
| 146 | + createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
|
|
| 147 | + createDto.setDate(Dates.createDate(30, 3, 2021));
|
|
| 148 | + request.setBatch(createDto);
|
|
| 149 | + request.setDate(createDto.getDate());
|
|
| 150 | + |
|
| 151 | + actual = service.consolidateLocalmarketBatch(request);
|
|
| 152 | + |
|
| 153 | + Assert.assertNotNull(actual);
|
|
| 154 | + }
|
|
| 155 | + {
|
|
| 156 | + |
|
| 157 | + BatchDto createDto = new BatchDto();
|
|
| 158 | + createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.2");
|
|
| 159 | + createDto.setCount(5);
|
|
| 160 | + createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#039"));
|
|
| 161 | + createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
|
|
| 162 | + createDto.setDate(Dates.createDate(30, 3, 2021));
|
|
| 163 | + request.setBatch(createDto);
|
|
| 164 | + request.setDate(createDto.getDate());
|
|
| 165 | + |
|
| 166 | + actual = service.consolidateLocalmarketBatch(request);
|
|
| 167 | + |
|
| 168 | + Assert.assertNotNull(actual);
|
|
| 169 | + }
|
|
| 170 | + {
|
|
| 171 | + |
|
| 172 | + BatchDto createDto = new BatchDto();
|
|
| 173 | + createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.3");
|
|
| 174 | + createDto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
|
|
| 175 | + createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#022"));
|
|
| 176 | + createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
|
|
| 177 | + createDto.setDate(Dates.createDate(30, 3, 2021));
|
|
| 178 | + request.setBatch(createDto);
|
|
| 179 | + request.setDate(createDto.getDate());
|
|
| 180 | + |
|
| 181 | + actual = service.consolidateLocalmarketBatch(request);
|
|
| 182 | + |
|
| 183 | + Assert.assertNotNull(actual);
|
|
| 184 | + }
|
|
| 185 | + |
|
| 186 | + {
|
|
| 187 | + |
|
| 188 | + BatchDto createDto = new BatchDto();
|
|
| 189 | + createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.4");
|
|
| 190 | + createDto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
|
|
| 191 | + createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#022"));
|
|
| 192 | + createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
|
|
| 193 | + createDto.setDate(Dates.createDate(30, 3, 2021));
|
|
| 194 | + createDto.setWeight(100.0f);
|
|
| 195 | + request.setBatch(createDto);
|
|
| 196 | + request.setDate(createDto.getDate());
|
|
| 197 | + |
|
| 198 | + actual = service.consolidateLocalmarketBatch(request);
|
|
| 199 | + |
|
| 200 | + Assert.assertNotNull(actual);
|
|
| 201 | + }
|
|
| 134 | 202 | }
|
| 135 | 203 | |
| 136 | 204 | @Override
|
| ... | ... | @@ -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>
|