Observe-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
March 2023
- 1 participants
- 64 discussions
[Git][ultreiaio/ird-observe][develop-9.0.x] [jgitflow-maven-plugin]updating poms for 9.0.27-SNAPSHOT development[skip ci]
by Tony CHEMIT (@tchemit) 08 Mar '23
by Tony CHEMIT (@tchemit) 08 Mar '23
08 Mar '23
Tony CHEMIT pushed to branch develop-9.0.x at ultreiaio / ird-observe
Commits:
a1939c2c by Tony Chemit at 2023-03-08T09:05:50+01:00
[jgitflow-maven-plugin]updating poms for 9.0.27-SNAPSHOT development[skip ci]
- - - - -
30 changed files:
- client/configuration/pom.xml
- client/core/pom.xml
- client/datasource/actions/pom.xml
- client/datasource/editor/api-test/pom.xml
- client/datasource/editor/api/pom.xml
- client/datasource/editor/common/pom.xml
- client/datasource/editor/ll/pom.xml
- client/datasource/editor/pom.xml
- client/datasource/editor/ps/pom.xml
- client/datasource/editor/spi/pom.xml
- client/datasource/pom.xml
- client/pom.xml
- client/runner/pom.xml
- core/api/dto-consolidation/pom.xml
- core/api/dto-decoration/pom.xml
- core/api/dto-validation/pom.xml
- core/api/dto/pom.xml
- core/api/pom.xml
- core/api/services/pom.xml
- core/api/tree/pom.xml
- core/api/validation/pom.xml
- core/persistence/avdth/pom.xml
- core/persistence/consolidation/pom.xml
- core/persistence/decoration/pom.xml
- core/persistence/java/pom.xml
- core/persistence/migration/pom.xml
- core/persistence/pom.xml
- core/persistence/report/pom.xml
- core/persistence/resources/pom.xml
- core/persistence/test/pom.xml
The diff was not included because it is too large.
View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/a1939c2ce9495d7eb6e7d0c37…
--
View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/a1939c2ce9495d7eb6e7d0c37…
You're receiving this email because of your account on gitlab.com.
1
0
08 Mar '23
Tony CHEMIT pushed new branch release/9.0.26 at ultreiaio / ird-observe
--
View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/tree/release/9.0.26
You're receiving this email because of your account on gitlab.com.
1
0
08 Mar '23
Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
c4581b4e by Tony Chemit at 2023-03-07T15:22:20+01:00
update pom
- - - - -
f97d24da by Tony Chemit at 2023-03-07T17:45:20+01:00
Revue du code de l'action de consolidation (Marché local)
- - - - -
b09dae21 by Tony Chemit at 2023-03-08T09:04:38+01:00
Update changelog for v.9.0.26 [skip CI]
- - - - -
10 changed files:
- CHANGELOG.md
- core/api/dto-consolidation/pom.xml
- core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/AtomicConsolidateAction.java
- core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/ConsolidateContext.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/persistence/consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/observation/SampleConsolidateContext.java
- core/services/test/src/main/java/fr/ird/observe/services/service/data/ps/ConsolidateDataServiceFixtures.java
- pom.xml
Changes:
=====================================
CHANGELOG.md
=====================================
@@ -1,7 +1,7 @@
# ObServe changelog
* Author [Tony Chemit](mailto:dev@tchemit.fr)
- * Last generated at 2023-02-14 12:38.
+ * Last generated at 2023-03-08 09:00.
## Version [9.1.0-RC-1](https://gitlab.com/ultreiaio/ird-observe/-/milestones/243)
@@ -13,16 +13,32 @@
* [Serveur (observe-9.1.0-RC-1-server.zip)](https://repo1.maven.org/maven2/fr/ird/obser…)
### Issues
- * [[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)
- * [[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)
- * [[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)
- * [[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)
- * [[Type::Evolution 2600]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2600) **Nouvelle référence 'Refueling'** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
- * [[Type::Evolution 2602]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2602) **Table ll_common.weightdeterminationmethod inutile ?** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
- * [[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)
- * [[Type::Evolution 2617]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2617) **Ajout de ps_common.TransmittingBuoyOperation 99** (Thanks to ) (Reported by Tony CHEMIT)
- * [[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)
- * [[Type::Evolution 2620]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2620) **Nettoyage de la table LastUpdateDate** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
+* [[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)
+* [[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)
+* [[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)
+* [[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)
+* [[Type::Evolution 2600]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2600) **Nouvelle référence 'Refueling'** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
+* [[Type::Evolution 2602]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2602) **Table ll_common.weightdeterminationmethod inutile ?** (Thanks to Tony CHEMIT) (Reported by Pascal Cauquil)
+* [[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)
+* [[Type::Evolution 2617]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2617) **Ajout de ps_common.TransmittingBuoyOperation 99** (Thanks to ) (Reported by Tony CHEMIT)
+* [[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)
+* [[Type::Evolution 2620]](https://gitlab.com/ultreiaio/ird-observe/-/issues/2620) **Nettoyage de la table LastUpdateDate** (Thanks to Tony CHEMIT) (Reported by Tony CHEMIT)
+
+## Version [9.0.26](https://gitlab.com/ultreiaio/ird-observe/-/milestones/256)
+
+**Closed at 2023-03-08.**
+
+### Download
+* [Client (observe-9.0.26-client.zip)](https://repo1.maven.org/maven2/fr/ird/observe/o…)
+* [Serveur (observe-9.0.26.war)](https://repo1.maven.org/maven2/fr/ird/observe/observe/…)
+* [Serveur (observe-9.0.26-server.zip)](https://repo1.maven.org/maven2/fr/ird/observe/o…)
+
+### Issues
+ * [[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)
+ * [[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)
+ * [[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)
+ * [[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)
+ * [[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)
## Version [9.0.25](https://gitlab.com/ultreiaio/ird-observe/-/milestones/255)
=====================================
core/api/dto-consolidation/pom.xml
=====================================
@@ -56,6 +56,10 @@
<groupId>io.ultreia.java4all</groupId>
<artifactId>java-util</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.ultreia.java4all.decorator</groupId>
+ <artifactId>decorator-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<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
default boolean execute(C context, E data) {
if (test(context, data)) {
accept(context, data);
- String fieldName = fieldName();
- 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)",
- context.getLogPrefix(),
- data.getTopiaId(),
- context.dataType().getSimpleName(),
- fieldName,
- modification.getOldValue(),
- modification.getNewValue(),
- this)));
+ logModification(context, data);
return true;
}
return false;
}
+
+ default void logModification(C context, E data) {
+ String fieldName = fieldName();
+ logModification(context, data, fieldName);
+ }
+
+ default void logModification(C context, E data, String fieldName) {
+ context.getModification(fieldName).ifPresent(modification -> log.info(String.format("[%s] property '%s.%s' has changed [old value: %s - new value: %s] (by action %s)",
+ data.getTopiaId(),
+ context.dataType().getSimpleName(),
+ fieldName,
+ modification.getOldValue(),
+ modification.getNewValue(),
+ this)));
+ }
+
}
=====================================
core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/ConsolidateContext.java
=====================================
@@ -36,8 +36,6 @@ import java.util.Optional;
*/
public interface ConsolidateContext<E extends ToolkitId> {
- String getLogPrefix();
-
JavaBeanMonitor monitor();
default Optional<JavaBeanPropertyModification> getModification(String fieldName) {
=====================================
core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/localmarket/BatchConsolidateActions.java
=====================================
@@ -0,0 +1,140 @@
+package fr.ird.observe.consolidation.data.ps.localmarket;
+
+/*-
+ * #%L
+ * ObServe Core :: API :: Dto Consolidation
+ * %%
+ * Copyright (C) 2008 - 2023 IRD, Ultreia.io
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+import fr.ird.observe.consolidation.AtomicConsolidateAction;
+import fr.ird.observe.dto.ProtectedIdsPs;
+import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
+import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
+import fr.ird.observe.dto.referential.common.SpeciesReference;
+import fr.ird.observe.dto.referential.ps.localmarket.BatchWeightTypeReference;
+import io.ultreia.java4all.lang.Numbers;
+
+import java.util.Date;
+import java.util.Optional;
+
+/**
+ * Created on 24/02/2023.
+ *
+ * @author Tony Chemit - dev(a)tchemit.fr
+ * @since 9.0.26
+ */
+public enum BatchConsolidateActions implements AtomicConsolidateAction<BatchConsolidateContext, BatchDto> {
+
+
+ ComputeWeightFromSpeciesMeanWeight() {
+ @Override
+ public boolean test(BatchConsolidateContext context, BatchDto dto) {
+ if (dto.getCount() == null) {
+ // this method requires count
+ return false;
+ }
+ BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
+ return batchWeightType != null && ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_SINGLE_SPECIES_INDIVIDUAL.equals(batchWeightType.getId());
+ }
+
+ @Override
+ public void accept(BatchConsolidateContext context, BatchDto dto) {
+
+ // espèce unité
+ // P = poids moyen de l'espèce * batch.count / 1000
+ // ocean = océan de débarquement de la marée = ps_common.trip.ocean
+ //lengthweightparameter.startdate <= trip.enddate <= lengthweightparameter.enddate
+ //sex = 0 - indéterminé (fr.ird.referential.common.Sex#1239832686121#0.0)
+ //sizemeasuretype = type de mesure par défaut de l'espèce = common.species.sizemeasuretype
+ // Si aucun poids moyen n'est trouvé P = NULL.
+
+ SpeciesReference species = dto.getSpecies();
+ String sizeMeasureTypeId = species.getSizeMeasureTypeId();
+ BatchConsolidateRequest request = context.getRequest();
+ String oceanId = request.getOceanId();
+ Date date = request.getDate();
+ boolean failIfLengthWeightParameterNotFound = request.isFailIfLengthWeightParameterNotFound();
+ Optional<Float> optionalMeanWeight = context.getRtpMeanWeightFinder().get(species.getId(),
+ "fr.ird.referential.common.Sex#1239832686121#0.0",
+ oceanId,
+ sizeMeasureTypeId,
+ date,
+ failIfLengthWeightParameterNotFound,
+ context::registerLengthWeightParameterNotFound);
+ if (optionalMeanWeight.isPresent()) {
+ Float meanWeight = optionalMeanWeight.get();
+ dto.setWeight(Numbers.roundFourDigits(meanWeight * dto.getCount() / 1000));
+ dto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
+ } else {
+ dto.setWeight(null);
+ dto.setWeightComputedSource(null);
+ }
+ }
+
+ },
+ ComputeWeightFromPackagingMeanWeight() {
+ @Override
+ public boolean test(BatchConsolidateContext context, BatchDto dto) {
+ if (dto.getCount() == null) {
+ // this method requires count
+ return false;
+ }
+ BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
+ return batchWeightType != null && ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_PACKAGING_NOT_WEIGHTED.equals(batchWeightType.getId());
+ }
+
+ @Override
+ public void accept(BatchConsolidateContext context, BatchDto dto) {
+ // Paquet/Conditionnement non pesé
+ // P = batch.packaging.meanWeight * batch.count (ou null si pas de packaging.meanWeight)
+ Float meanWeight = dto.getPackaging().getMeanWeight();
+ if (meanWeight == null) {
+ dto.setWeight(null);
+ dto.setWeightComputedSource(null);
+ } else {
+ dto.setWeight(Numbers.roundFourDigits(dto.getCount() * meanWeight));
+ dto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
+ }
+ }
+ },
+ ResetWeightValues() {
+ @Override
+ public boolean test(BatchConsolidateContext context, BatchDto dto) {
+ return true;
+ }
+
+ @Override
+ public void accept(BatchConsolidateContext context, BatchDto dto) {
+ dto.setWeight(null);
+ dto.setWeightComputedSource(null);
+ }
+ };
+
+ @Override
+ public String fieldName() {
+ return BatchDto.PROPERTY_WEIGHT;
+ }
+
+
+ @Override
+ public void logModification(BatchConsolidateContext context, BatchDto data) {
+ AtomicConsolidateAction.super.logModification(context, data);
+ AtomicConsolidateAction.super.logModification(context, data, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
+ }
+}
=====================================
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;
* #L%
*/
-import fr.ird.observe.decoration.DecoratorService;
+import fr.ird.observe.consolidation.ConsolidateContext;
import fr.ird.observe.dto.ToolkitIdModifications;
import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
import io.ultreia.java4all.bean.monitor.JavaBeanMonitor;
+import io.ultreia.java4all.decoration.Decorator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -39,24 +40,36 @@ import java.util.Set;
* @author Tony Chemit - dev(a)tchemit.fr
* @since 9.0.26
*/
-public class BatchConsolidateContext implements AutoCloseable {
+public class BatchConsolidateContext implements ConsolidateContext<BatchDto> {
private static final Logger log = LogManager.getLogger(BatchConsolidateContext.class);
+ private final GetOptionalRtpMeanWeight rtpMeanWeightFinder;
private final JavaBeanMonitor monitor;
+ private final Decorator decorator;
+ private BatchConsolidateRequest request;
+ private BatchDto batch;
private String lengthWeightParameterNotFound;
- public BatchConsolidateContext(JavaBeanMonitor monitor, BatchDto bean) {
+ public BatchConsolidateContext(GetOptionalRtpMeanWeight rtpMeanWeightFinder, JavaBeanMonitor monitor, Decorator decorator) {
+ this.rtpMeanWeightFinder = rtpMeanWeightFinder;
this.monitor = Objects.requireNonNull(monitor);
- this.monitor.setBean(Objects.requireNonNull(bean));
+ this.decorator = decorator;
}
- public Optional<ToolkitIdModifications> build(DecoratorService decoratorService) {
- BatchDto bean = (BatchDto) monitor.getBean();
+ public void watch(BatchConsolidateRequest request) {
+ this.request = Objects.requireNonNull(request);
+ this.batch = Objects.requireNonNull(request.getBatch());
+ monitor.setBean(batch);
+ }
+
+ public Optional<ToolkitIdModifications> build() {
if (monitor.wasModified()) {
- decoratorService.installDecorator(bean);
- return monitor.toModifications(modifications -> new ToolkitIdModifications(bean, modifications, lengthWeightParameterNotFound == null ? null : Set.of(lengthWeightParameterNotFound)));
+ batch.registerDecorator(decorator);
+ Optional<ToolkitIdModifications> result = monitor.toModifications(modifications -> new ToolkitIdModifications(batch, modifications, lengthWeightParameterNotFound == null ? null : Set.of(lengthWeightParameterNotFound)));
+ result.ifPresent(m -> m.reset(batch));
+ return result;
} else if (lengthWeightParameterNotFound != null) {
- return Optional.of(new ToolkitIdModifications(bean, Set.of(), Set.of(lengthWeightParameterNotFound)));
+ return Optional.of(new ToolkitIdModifications(batch, Set.of(), Set.of(lengthWeightParameterNotFound)));
}
return Optional.empty();
}
@@ -68,8 +81,27 @@ public class BatchConsolidateContext implements AutoCloseable {
}
}
- @Override
- public void close() {
+ public BatchConsolidateRequest getRequest() {
+ return request;
+ }
+
+ public GetOptionalRtpMeanWeight getRtpMeanWeightFinder() {
+ return rtpMeanWeightFinder;
+ }
+
+ public void clear() {
+ this.batch = null;
+ this.request = null;
monitor.setBean(null);
}
+
+ @Override
+ public JavaBeanMonitor monitor() {
+ return monitor;
+ }
+
+ @Override
+ public Class<BatchDto> dataType() {
+ return BatchDto.class;
+ }
}
=====================================
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;
*/
import fr.ird.observe.decoration.DecoratorService;
-import fr.ird.observe.dto.ProtectedIdsPs;
import fr.ird.observe.dto.ToolkitIdModifications;
import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
-import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
-import fr.ird.observe.dto.referential.common.SpeciesReference;
-import fr.ird.observe.dto.referential.ps.localmarket.BatchWeightTypeReference;
import io.ultreia.java4all.bean.monitor.JavaBeanMonitor;
-import io.ultreia.java4all.lang.Numbers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import java.util.Date;
-import java.util.Objects;
import java.util.Optional;
/**
@@ -48,98 +41,41 @@ public class BatchConsolidateEngine {
private static final Logger log = LogManager.getLogger(BatchConsolidateEngine.class);
- private final GetOptionalRtpMeanWeight rtpMeanWeightFinder;
- private final DecoratorService decoratorService;
- private final JavaBeanMonitor monitor;
+ private final BatchConsolidateContext context;
public BatchConsolidateEngine(GetOptionalRtpMeanWeight rtpMeanWeightFinder, DecoratorService decoratorService) {
- this.rtpMeanWeightFinder = Objects.requireNonNull(rtpMeanWeightFinder);
- this.decoratorService = Objects.requireNonNull(decoratorService);
- this.monitor = new JavaBeanMonitor(BatchDto.PROPERTY_WEIGHT, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
+ JavaBeanMonitor monitor = new JavaBeanMonitor(BatchDto.PROPERTY_WEIGHT, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
+ this.context = new BatchConsolidateContext(rtpMeanWeightFinder, monitor, decoratorService.getDecoratorByType(BatchDto.class));
}
public Optional<ToolkitIdModifications> consolidate(BatchConsolidateRequest request) {
BatchDto dto = request.getBatch();
- try (BatchConsolidateContext context = new BatchConsolidateContext(monitor, dto)) {
- consolidateWeight(context,
- dto,
- request.getOceanId(),
- request.getDate(),
- request.isFailIfLengthWeightParameterNotFound());
- Optional<ToolkitIdModifications> result = context.build(decoratorService);
+
+ // the only thing we can consolidate is the batch.weight
+ if (dto.getWeight() != null && dto.getWeightComputedSource() == null) {
+ // the value was set by user, do not change any thing
+ return Optional.empty();
+ }
+ context.watch(request);
+
+ try {
+ if (!BatchConsolidateActions.ComputeWeightFromSpeciesMeanWeight.execute(context, dto)) {
+ if (!BatchConsolidateActions.ComputeWeightFromPackagingMeanWeight.execute(context, dto)) {
+ BatchConsolidateActions.ResetWeightValues.execute(context, dto);
+ }
+ }
+ Optional<ToolkitIdModifications> result = context.build();
result.ifPresent(r -> {
if (r.withModifications()) {
log.info(String.format("Found some modifications on batch: %s", request.getBatch().getId()));
}
if (r.withWarnings()) {
- log.info(String.format("Found some warnings on batch: %s", request.getBatch().getId()));
+ log.warn(String.format("Found some warnings on batch: %s", request.getBatch().getId()));
}
});
return result;
- }
- }
-
- private void consolidateWeight(BatchConsolidateContext context,
- BatchDto dto,
- String oceanId,
- Date date,
- boolean failIfLengthWeightParameterNotFound) {
-
- Float weight = dto.getWeight();
- if (weight != null && dto.getWeightComputedSource() == null) {
- // the value was set by user, do not change any thing
- return;
- }
- // always reset computed source state
- dto.setWeightComputedSource(null);
- // always reset weight since it was computed
- dto.setWeight(null);
- BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
- Integer count = dto.getCount();
- switch (batchWeightType.getId()) {
- case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_WEIGHING:
- // pesée poids direct
- // P = batch.weight
- // donc rien à faire
- //FIXME Si il faut repousser le poids!
- dto.setWeight(weight);
- break;
- case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_SINGLE_SPECIES_INDIVIDUAL:
- // espèce unité
- // P = poids moyen de l'espèce * batch.count / 1000
- // ocean = océan de débarquement de la marée = ps_common.trip.ocean
- //lengthweightparameter.startdate <= trip.enddate <= lengthweightparameter.enddate
- //sex = 0 - indéterminé (fr.ird.referential.common.Sex#1239832686121#0.0)
- //sizemeasuretype = type de mesure par défaut de l'espèce = common.species.sizemeasuretype
- // Si aucun poids moyen n'est trouvé P = NULL.
-
- if (count != null) {
- SpeciesReference species = dto.getSpecies();
- String sizeMeasureTypeId = species.getSizeMeasureTypeId();
- Optional<Float> optionalMeanWeight = rtpMeanWeightFinder.get(species.getId(),
- "fr.ird.referential.common.Sex#1239832686121#0.0",
- oceanId,
- sizeMeasureTypeId,
- date,
- failIfLengthWeightParameterNotFound,
- context::registerLengthWeightParameterNotFound);
- optionalMeanWeight.ifPresent(meanWeight -> {
- dto.setWeight(Numbers.roundFourDigits(meanWeight * count / 1000));
- dto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
- });
- }
- break;
- case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_PACKAGING_NOT_WEIGHTED:
- // Paquet/Conditionnement non pesé
- // P = batch.packaging.meanWeight * batch.count (ou null si pas de packaging.meanWeight)
- if (count != null) {
- Float meanWeight = dto.getPackaging().getMeanWeight();
- if (meanWeight != null) {
- dto.setWeight(Numbers.roundFourDigits(count * meanWeight));
- dto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
- }
- }
- break;
+ } finally {
+ context.clear();
}
}
}
=====================================
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
return getLengthLengthParameter() != null;
}
- @Override
public String getLogPrefix() {
return logPrefix;
}
=====================================
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
import fr.ird.observe.decoration.DecoratorService;
import fr.ird.observe.dto.ToolkitIdModifications;
import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
+import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
import fr.ird.observe.dto.data.ps.localmarket.TripBatchDto;
import fr.ird.observe.dto.form.Form;
import fr.ird.observe.dto.referential.ReferentialLocale;
+import fr.ird.observe.dto.referential.common.SpeciesReference;
+import fr.ird.observe.dto.referential.ps.localmarket.PackagingReference;
import fr.ird.observe.services.ObserveServicesProvider;
+import io.ultreia.java4all.util.Dates;
import org.junit.Assert;
import java.net.URL;
@@ -100,11 +104,75 @@ public class ConsolidateDataServiceFixtures extends GeneratedConsolidateDataServ
List<BatchDto> children = form.getObject().getChildren();
Assert.assertNotNull(children);
Assert.assertEquals(2, children.size());
- request.setOceanId("fr.ird.referential.common.Ocean#1239832686151#0.17595105505051245");
+ request.setOceanId("fr.ird.referential.common.Ocean#1239832686152#0.8325731048817705");
request.setBatch(children.get(0));
ToolkitIdModifications actual = service.consolidateLocalmarketBatch(request);
+
//FIXME:Test Get a real dto
Assert.assertNull(actual);
+
+ {
+
+ BatchDto createDto = new BatchDto();
+ createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.1");
+ createDto.setCount(5);
+ createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#001"));
+ createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
+ createDto.setDate(Dates.createDate(30, 3, 2021));
+ request.setBatch(createDto);
+ request.setDate(createDto.getDate());
+
+ actual = service.consolidateLocalmarketBatch(request);
+
+ Assert.assertNotNull(actual);
+ }
+ {
+
+ BatchDto createDto = new BatchDto();
+ createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.2");
+ createDto.setCount(5);
+ createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#039"));
+ createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
+ createDto.setDate(Dates.createDate(30, 3, 2021));
+ request.setBatch(createDto);
+ request.setDate(createDto.getDate());
+
+ actual = service.consolidateLocalmarketBatch(request);
+
+ Assert.assertNotNull(actual);
+ }
+ {
+
+ BatchDto createDto = new BatchDto();
+ createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.3");
+ createDto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
+ createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#022"));
+ createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
+ createDto.setDate(Dates.createDate(30, 3, 2021));
+ request.setBatch(createDto);
+ request.setDate(createDto.getDate());
+
+ actual = service.consolidateLocalmarketBatch(request);
+
+ Assert.assertNotNull(actual);
+ }
+
+ {
+
+ BatchDto createDto = new BatchDto();
+ createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.4");
+ createDto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
+ createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#022"));
+ createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
+ createDto.setDate(Dates.createDate(30, 3, 2021));
+ createDto.setWeight(100.0f);
+ request.setBatch(createDto);
+ request.setDate(createDto.getDate());
+
+ actual = service.consolidateLocalmarketBatch(request);
+
+ Assert.assertNotNull(actual);
+ }
}
@Override
=====================================
pom.xml
=====================================
@@ -23,7 +23,7 @@
<parent>
<groupId>io.ultreia.maven</groupId>
<artifactId>pom</artifactId>
- <version>2023.9</version>
+ <version>2023.10</version>
</parent>
<groupId>fr.ird.observe</groupId>
<artifactId>ird-observe</artifactId>
View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/64cbc51dbb3d308e00c051ac…
--
View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/64cbc51dbb3d308e00c051ac…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-observe][develop-9.0.x] 2 commits: update pom
by Tony CHEMIT (@tchemit) 07 Mar '23
by Tony CHEMIT (@tchemit) 07 Mar '23
07 Mar '23
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
update pom
- - - - -
b18fcd29 by Tony Chemit at 2023-03-07T15:21:54+01:00
Revue du code de l'action de consolidation (Marché local)
- - - - -
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:
=====================================
core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/AtomicConsolidateAction.java
=====================================
@@ -53,17 +53,26 @@ public interface AtomicConsolidateAction<C extends ConsolidateContext<E>, E exte
default boolean execute(C context, E data) {
if (test(context, data)) {
accept(context, data);
- String fieldName = fieldName();
- context.getModification(fieldName).ifPresent(modification -> log.info(String.format("[%s] property '%s.%s' has changed [old value: %s - new value: %s] (by action %s)",
- data.getTopiaId(),
- context.dataType().getSimpleName(),
- fieldName,
- modification.getOldValue(),
- modification.getNewValue(),
- this)));
+ logModification(context, data);
return true;
}
return false;
}
+
+ default void logModification(C context, E data) {
+ String fieldName = fieldName();
+ logModification(context, data, fieldName);
+ }
+
+ default void logModification(C context, E data, String fieldName) {
+ context.getModification(fieldName).ifPresent(modification -> log.info(String.format("[%s] property '%s.%s' has changed [old value: %s - new value: %s] (by action %s)",
+ data.getTopiaId(),
+ context.dataType().getSimpleName(),
+ fieldName,
+ modification.getOldValue(),
+ modification.getNewValue(),
+ this)));
+ }
+
}
=====================================
core/api/dto-consolidation/src/main/java/fr/ird/observe/consolidation/data/ps/localmarket/BatchConsolidateActions.java
=====================================
@@ -0,0 +1,140 @@
+package fr.ird.observe.consolidation.data.ps.localmarket;
+
+/*-
+ * #%L
+ * ObServe Core :: API :: Dto Consolidation
+ * %%
+ * Copyright (C) 2008 - 2023 IRD, Ultreia.io
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+import fr.ird.observe.consolidation.AtomicConsolidateAction;
+import fr.ird.observe.dto.ProtectedIdsPs;
+import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
+import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
+import fr.ird.observe.dto.referential.common.SpeciesReference;
+import fr.ird.observe.dto.referential.ps.localmarket.BatchWeightTypeReference;
+import io.ultreia.java4all.lang.Numbers;
+
+import java.util.Date;
+import java.util.Optional;
+
+/**
+ * Created on 24/02/2023.
+ *
+ * @author Tony Chemit - dev(a)tchemit.fr
+ * @since 9.0.26
+ */
+public enum BatchConsolidateActions implements AtomicConsolidateAction<BatchConsolidateContext, BatchDto> {
+
+
+ ComputeWeightFromSpeciesMeanWeight() {
+ @Override
+ public boolean test(BatchConsolidateContext context, BatchDto dto) {
+ if (dto.getCount() == null) {
+ // this method requires count
+ return false;
+ }
+ BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
+ return batchWeightType != null && ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_SINGLE_SPECIES_INDIVIDUAL.equals(batchWeightType.getId());
+ }
+
+ @Override
+ public void accept(BatchConsolidateContext context, BatchDto dto) {
+
+ // espèce unité
+ // P = poids moyen de l'espèce * batch.count / 1000
+ // ocean = océan de débarquement de la marée = ps_common.trip.ocean
+ //lengthweightparameter.startdate <= trip.enddate <= lengthweightparameter.enddate
+ //sex = 0 - indéterminé (fr.ird.referential.common.Sex#1239832686121#0.0)
+ //sizemeasuretype = type de mesure par défaut de l'espèce = common.species.sizemeasuretype
+ // Si aucun poids moyen n'est trouvé P = NULL.
+
+ SpeciesReference species = dto.getSpecies();
+ String sizeMeasureTypeId = species.getSizeMeasureTypeId();
+ BatchConsolidateRequest request = context.getRequest();
+ String oceanId = request.getOceanId();
+ Date date = request.getDate();
+ boolean failIfLengthWeightParameterNotFound = request.isFailIfLengthWeightParameterNotFound();
+ Optional<Float> optionalMeanWeight = context.getRtpMeanWeightFinder().get(species.getId(),
+ "fr.ird.referential.common.Sex#1239832686121#0.0",
+ oceanId,
+ sizeMeasureTypeId,
+ date,
+ failIfLengthWeightParameterNotFound,
+ context::registerLengthWeightParameterNotFound);
+ if (optionalMeanWeight.isPresent()) {
+ Float meanWeight = optionalMeanWeight.get();
+ dto.setWeight(Numbers.roundFourDigits(meanWeight * dto.getCount() / 1000));
+ dto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
+ } else {
+ dto.setWeight(null);
+ dto.setWeightComputedSource(null);
+ }
+ }
+
+ },
+ ComputeWeightFromPackagingMeanWeight() {
+ @Override
+ public boolean test(BatchConsolidateContext context, BatchDto dto) {
+ if (dto.getCount() == null) {
+ // this method requires count
+ return false;
+ }
+ BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
+ return batchWeightType != null && ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_PACKAGING_NOT_WEIGHTED.equals(batchWeightType.getId());
+ }
+
+ @Override
+ public void accept(BatchConsolidateContext context, BatchDto dto) {
+ // Paquet/Conditionnement non pesé
+ // P = batch.packaging.meanWeight * batch.count (ou null si pas de packaging.meanWeight)
+ Float meanWeight = dto.getPackaging().getMeanWeight();
+ if (meanWeight == null) {
+ dto.setWeight(null);
+ dto.setWeightComputedSource(null);
+ } else {
+ dto.setWeight(Numbers.roundFourDigits(dto.getCount() * meanWeight));
+ dto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
+ }
+ }
+ },
+ ResetWeightValues() {
+ @Override
+ public boolean test(BatchConsolidateContext context, BatchDto dto) {
+ return true;
+ }
+
+ @Override
+ public void accept(BatchConsolidateContext context, BatchDto dto) {
+ dto.setWeight(null);
+ dto.setWeightComputedSource(null);
+ }
+ };
+
+ @Override
+ public String fieldName() {
+ return BatchDto.PROPERTY_WEIGHT;
+ }
+
+
+ @Override
+ public void logModification(BatchConsolidateContext context, BatchDto data) {
+ AtomicConsolidateAction.super.logModification(context, data);
+ AtomicConsolidateAction.super.logModification(context, data, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
+ }
+}
=====================================
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;
* #L%
*/
-import fr.ird.observe.decoration.DecoratorService;
+import fr.ird.observe.consolidation.ConsolidateContext;
import fr.ird.observe.dto.ToolkitIdModifications;
import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
import io.ultreia.java4all.bean.monitor.JavaBeanMonitor;
+import io.ultreia.java4all.decoration.Decorator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -39,24 +40,36 @@ import java.util.Set;
* @author Tony Chemit - dev(a)tchemit.fr
* @since 9.0.26
*/
-public class BatchConsolidateContext implements AutoCloseable {
+public class BatchConsolidateContext implements ConsolidateContext<BatchDto> {
private static final Logger log = LogManager.getLogger(BatchConsolidateContext.class);
+ private final GetOptionalRtpMeanWeight rtpMeanWeightFinder;
private final JavaBeanMonitor monitor;
+ private final Decorator decorator;
+ private BatchConsolidateRequest request;
+ private BatchDto batch;
private String lengthWeightParameterNotFound;
- public BatchConsolidateContext(JavaBeanMonitor monitor, BatchDto bean) {
+ public BatchConsolidateContext(GetOptionalRtpMeanWeight rtpMeanWeightFinder, JavaBeanMonitor monitor, Decorator decorator) {
+ this.rtpMeanWeightFinder = rtpMeanWeightFinder;
this.monitor = Objects.requireNonNull(monitor);
- this.monitor.setBean(Objects.requireNonNull(bean));
+ this.decorator = decorator;
}
- public Optional<ToolkitIdModifications> build(DecoratorService decoratorService) {
- BatchDto bean = (BatchDto) monitor.getBean();
+ public void watch(BatchConsolidateRequest request) {
+ this.request = Objects.requireNonNull(request);
+ this.batch = Objects.requireNonNull(request.getBatch());
+ monitor.setBean(batch);
+ }
+
+ public Optional<ToolkitIdModifications> build() {
if (monitor.wasModified()) {
- decoratorService.installDecorator(bean);
- return monitor.toModifications(modifications -> new ToolkitIdModifications(bean, modifications, lengthWeightParameterNotFound == null ? null : Set.of(lengthWeightParameterNotFound)));
+ batch.registerDecorator(decorator);
+ Optional<ToolkitIdModifications> result = monitor.toModifications(modifications -> new ToolkitIdModifications(batch, modifications, lengthWeightParameterNotFound == null ? null : Set.of(lengthWeightParameterNotFound)));
+ result.ifPresent(m -> m.reset(batch));
+ return result;
} else if (lengthWeightParameterNotFound != null) {
- return Optional.of(new ToolkitIdModifications(bean, Set.of(), Set.of(lengthWeightParameterNotFound)));
+ return Optional.of(new ToolkitIdModifications(batch, Set.of(), Set.of(lengthWeightParameterNotFound)));
}
return Optional.empty();
}
@@ -68,8 +81,27 @@ public class BatchConsolidateContext implements AutoCloseable {
}
}
- @Override
- public void close() {
+ public BatchConsolidateRequest getRequest() {
+ return request;
+ }
+
+ public GetOptionalRtpMeanWeight getRtpMeanWeightFinder() {
+ return rtpMeanWeightFinder;
+ }
+
+ public void clear() {
+ this.batch = null;
+ this.request = null;
monitor.setBean(null);
}
+
+ @Override
+ public JavaBeanMonitor monitor() {
+ return monitor;
+ }
+
+ @Override
+ public Class<BatchDto> dataType() {
+ return BatchDto.class;
+ }
}
=====================================
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;
*/
import fr.ird.observe.decoration.DecoratorService;
-import fr.ird.observe.dto.ProtectedIdsPs;
import fr.ird.observe.dto.ToolkitIdModifications;
import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
-import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
-import fr.ird.observe.dto.referential.common.SpeciesReference;
-import fr.ird.observe.dto.referential.ps.localmarket.BatchWeightTypeReference;
import io.ultreia.java4all.bean.monitor.JavaBeanMonitor;
-import io.ultreia.java4all.lang.Numbers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import java.util.Date;
-import java.util.Objects;
import java.util.Optional;
/**
@@ -48,98 +41,41 @@ public class BatchConsolidateEngine {
private static final Logger log = LogManager.getLogger(BatchConsolidateEngine.class);
- private final GetOptionalRtpMeanWeight rtpMeanWeightFinder;
- private final DecoratorService decoratorService;
- private final JavaBeanMonitor monitor;
+ private final BatchConsolidateContext context;
public BatchConsolidateEngine(GetOptionalRtpMeanWeight rtpMeanWeightFinder, DecoratorService decoratorService) {
- this.rtpMeanWeightFinder = Objects.requireNonNull(rtpMeanWeightFinder);
- this.decoratorService = Objects.requireNonNull(decoratorService);
- this.monitor = new JavaBeanMonitor(BatchDto.PROPERTY_WEIGHT, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
+ JavaBeanMonitor monitor = new JavaBeanMonitor(BatchDto.PROPERTY_WEIGHT, BatchDto.PROPERTY_WEIGHT_COMPUTED_SOURCE);
+ this.context = new BatchConsolidateContext(rtpMeanWeightFinder, monitor, decoratorService.getDecoratorByType(BatchDto.class));
}
public Optional<ToolkitIdModifications> consolidate(BatchConsolidateRequest request) {
BatchDto dto = request.getBatch();
- try (BatchConsolidateContext context = new BatchConsolidateContext(monitor, dto)) {
- consolidateWeight(context,
- dto,
- request.getOceanId(),
- request.getDate(),
- request.isFailIfLengthWeightParameterNotFound());
- Optional<ToolkitIdModifications> result = context.build(decoratorService);
+
+ // the only thing we can consolidate is the batch.weight
+ if (dto.getWeight() != null && dto.getWeightComputedSource() == null) {
+ // the value was set by user, do not change any thing
+ return Optional.empty();
+ }
+ context.watch(request);
+
+ try {
+ if (!BatchConsolidateActions.ComputeWeightFromSpeciesMeanWeight.execute(context, dto)) {
+ if (!BatchConsolidateActions.ComputeWeightFromPackagingMeanWeight.execute(context, dto)) {
+ BatchConsolidateActions.ResetWeightValues.execute(context, dto);
+ }
+ }
+ Optional<ToolkitIdModifications> result = context.build();
result.ifPresent(r -> {
if (r.withModifications()) {
log.info(String.format("Found some modifications on batch: %s", request.getBatch().getId()));
}
if (r.withWarnings()) {
- log.info(String.format("Found some warnings on batch: %s", request.getBatch().getId()));
+ log.warn(String.format("Found some warnings on batch: %s", request.getBatch().getId()));
}
});
return result;
- }
- }
-
- private void consolidateWeight(BatchConsolidateContext context,
- BatchDto dto,
- String oceanId,
- Date date,
- boolean failIfLengthWeightParameterNotFound) {
-
- Float weight = dto.getWeight();
- if (weight != null && dto.getWeightComputedSource() == null) {
- // the value was set by user, do not change any thing
- return;
- }
- // always reset computed source state
- dto.setWeightComputedSource(null);
- // always reset weight since it was computed
- dto.setWeight(null);
- BatchWeightTypeReference batchWeightType = dto.getPackaging().getBatchWeightType();
- Integer count = dto.getCount();
- switch (batchWeightType.getId()) {
- case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_WEIGHING:
- // pesée poids direct
- // P = batch.weight
- // donc rien à faire
- //FIXME Si il faut repousser le poids!
- dto.setWeight(weight);
- break;
- case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_SINGLE_SPECIES_INDIVIDUAL:
- // espèce unité
- // P = poids moyen de l'espèce * batch.count / 1000
- // ocean = océan de débarquement de la marée = ps_common.trip.ocean
- //lengthweightparameter.startdate <= trip.enddate <= lengthweightparameter.enddate
- //sex = 0 - indéterminé (fr.ird.referential.common.Sex#1239832686121#0.0)
- //sizemeasuretype = type de mesure par défaut de l'espèce = common.species.sizemeasuretype
- // Si aucun poids moyen n'est trouvé P = NULL.
-
- if (count != null) {
- SpeciesReference species = dto.getSpecies();
- String sizeMeasureTypeId = species.getSizeMeasureTypeId();
- Optional<Float> optionalMeanWeight = rtpMeanWeightFinder.get(species.getId(),
- "fr.ird.referential.common.Sex#1239832686121#0.0",
- oceanId,
- sizeMeasureTypeId,
- date,
- failIfLengthWeightParameterNotFound,
- context::registerLengthWeightParameterNotFound);
- optionalMeanWeight.ifPresent(meanWeight -> {
- dto.setWeight(Numbers.roundFourDigits(meanWeight * count / 1000));
- dto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
- });
- }
- break;
- case ProtectedIdsPs.PS_LOCAL_MARKET_BATCH_WEIGHT_TYPE_PACKAGING_NOT_WEIGHTED:
- // Paquet/Conditionnement non pesé
- // P = batch.packaging.meanWeight * batch.count (ou null si pas de packaging.meanWeight)
- if (count != null) {
- Float meanWeight = dto.getPackaging().getMeanWeight();
- if (meanWeight != null) {
- dto.setWeight(Numbers.roundFourDigits(count * meanWeight));
- dto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
- }
- }
- break;
+ } finally {
+ context.clear();
}
}
}
=====================================
core/services/test/src/main/java/fr/ird/observe/services/service/data/ps/ConsolidateDataServiceFixtures.java
=====================================
@@ -32,10 +32,14 @@ import fr.ird.observe.consolidation.data.ps.observation.ActivityConsolidateResul
import fr.ird.observe.decoration.DecoratorService;
import fr.ird.observe.dto.ToolkitIdModifications;
import fr.ird.observe.dto.data.ps.localmarket.BatchDto;
+import fr.ird.observe.dto.data.ps.localmarket.BatchWeightComputedValueSource;
import fr.ird.observe.dto.data.ps.localmarket.TripBatchDto;
import fr.ird.observe.dto.form.Form;
import fr.ird.observe.dto.referential.ReferentialLocale;
+import fr.ird.observe.dto.referential.common.SpeciesReference;
+import fr.ird.observe.dto.referential.ps.localmarket.PackagingReference;
import fr.ird.observe.services.ObserveServicesProvider;
+import io.ultreia.java4all.util.Dates;
import org.junit.Assert;
import java.net.URL;
@@ -126,11 +130,75 @@ public class ConsolidateDataServiceFixtures extends GeneratedConsolidateDataServ
List<BatchDto> children = form.getObject().getChildren();
Assert.assertNotNull(children);
Assert.assertEquals(2, children.size());
- request.setOceanId("fr.ird.referential.common.Ocean#1239832686151#0.17595105505051245");
+ request.setOceanId("fr.ird.referential.common.Ocean#1239832686152#0.8325731048817705");
request.setBatch(children.get(0));
ToolkitIdModifications actual = service.consolidateLocalmarketBatch(request);
+
//FIXME:Test Get a real dto
Assert.assertNull(actual);
+
+ {
+
+ BatchDto createDto = new BatchDto();
+ createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.1");
+ createDto.setCount(5);
+ createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#001"));
+ createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
+ createDto.setDate(Dates.createDate(30, 3, 2021));
+ request.setBatch(createDto);
+ request.setDate(createDto.getDate());
+
+ actual = service.consolidateLocalmarketBatch(request);
+
+ Assert.assertNotNull(actual);
+ }
+ {
+
+ BatchDto createDto = new BatchDto();
+ createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.2");
+ createDto.setCount(5);
+ createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#039"));
+ createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
+ createDto.setDate(Dates.createDate(30, 3, 2021));
+ request.setBatch(createDto);
+ request.setDate(createDto.getDate());
+
+ actual = service.consolidateLocalmarketBatch(request);
+
+ Assert.assertNotNull(actual);
+ }
+ {
+
+ BatchDto createDto = new BatchDto();
+ createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.3");
+ createDto.setWeightComputedSource(BatchWeightComputedValueSource.fromPackagingMeanWeight);
+ createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#022"));
+ createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
+ createDto.setDate(Dates.createDate(30, 3, 2021));
+ request.setBatch(createDto);
+ request.setDate(createDto.getDate());
+
+ actual = service.consolidateLocalmarketBatch(request);
+
+ Assert.assertNotNull(actual);
+ }
+
+ {
+
+ BatchDto createDto = new BatchDto();
+ createDto.setId("fr.ird.data.ps.localmarket.Batch#1617103690104#0.4");
+ createDto.setWeightComputedSource(BatchWeightComputedValueSource.fromSpeciesMeanWeight);
+ createDto.setPackaging(servicesProvider.getReferenceService().loadReferential(PackagingReference.class, "fr.ird.referential.ps.localmarket.Packaging#1464000000000#022"));
+ createDto.setSpecies(servicesProvider.getReferenceService().loadReferential(SpeciesReference.class, "fr.ird.referential.common.Species#1560863653582#0.22356459159799613"));
+ createDto.setDate(Dates.createDate(30, 3, 2021));
+ createDto.setWeight(100.0f);
+ request.setBatch(createDto);
+ request.setDate(createDto.getDate());
+
+ actual = service.consolidateLocalmarketBatch(request);
+
+ Assert.assertNotNull(actual);
+ }
}
@Override
=====================================
pom.xml
=====================================
@@ -23,7 +23,7 @@
<parent>
<groupId>io.ultreia.maven</groupId>
<artifactId>pom</artifactId>
- <version>2023.9</version>
+ <version>2023.10</version>
</parent>
<groupId>fr.ird.observe</groupId>
<artifactId>ird-observe</artifactId>
View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/17b40e5fbe56c2bedb1e8036…
--
View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/compare/17b40e5fbe56c2bedb1e8036…
You're receiving this email because of your account on gitlab.com.
1
0