This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit d009b59733c95f144899fcdd27d1f92a2be55370 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 16:14:30 2016 +0200 Revue des arrondis et amélioration des messages d'erreur lors de l'élvation des poids --- .../catches/BenthosWeightComputingException.java | 109 ++++++++- .../catches/CatchWeightComputingException.java | 30 ++- .../MarineLitterWeightComputingException.java | 28 ++- .../catches/SpeciesWeightComputingException.java | 109 ++++++++- .../service/catches/WeightComputingService.java | 257 +++++++++++---------- .../data/SpeciesBatch-edit-error-validation.xml | 6 +- .../SpeciesBatch-validate-fatal-validation.xml | 2 +- .../resources/i18n/tutti-service_en_GB.properties | 5 + .../resources/i18n/tutti-service_fr_FR.properties | 35 +-- 9 files changed, 432 insertions(+), 149 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java index 3d85185..f869c3a 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java @@ -1,5 +1,10 @@ package fr.ifremer.tutti.service.catches; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.type.WeightUnit; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 13/04/16. * @@ -7,11 +12,111 @@ package fr.ifremer.tutti.service.catches; */ public class BenthosWeightComputingException extends TuttiWeightComputingException { - public BenthosWeightComputingException(String message) { + public static BenthosWeightComputingException forValidationMessage(WeightUnit weightUnit, + String message, + String species, + String categoryLabel, + String categoryValue, + Float weight, + Float sampleCategoryWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t(message, + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(weight) + unitShortLabel, + weightUnit.fromEntity(sampleCategoryWeight) + unitShortLabel + ); + throw new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + + } + + public static BenthosWeightComputingException forIncoherentTotalSorted(WeightUnit weightUnit, + Float speciesTotalSortedWeight, + Float speciesTotalComputedSortedWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted", + weightUnit.fromEntity(speciesTotalSortedWeight) + unitShortLabel, + weightUnit.fromEntity(speciesTotalComputedSortedWeight) + unitShortLabel); + return new BenthosWeightComputingException(errorMessage); + + } + + public static BenthosWeightComputingException forIncoherentParentCategoryWeight(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float categoryWeight, + Float sum, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(categoryWeight) + unitShortLabel, + weightUnit.fromEntity(sum) + unitShortLabel); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + public static BenthosWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float frequencyWeight, + Float rowWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(frequencyWeight) + unitShortLabel, + weightUnit.fromEntity(rowWeight) + unitShortLabel); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + } + + public static BenthosWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float frequencyWeight, + Float categoryWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(frequencyWeight) + unitShortLabel, + weightUnit.fromEntity(categoryWeight) + unitShortLabel); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + public static BenthosWeightComputingException forNoWeight(String species, + String categoryLabel, + String categoryValue, + int thisIndex) { + + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.noWeight", + species, + categoryLabel, + categoryValue); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + + private BenthosWeightComputingException(String message) { super(message); } - public BenthosWeightComputingException(String message, String property, int index) { + private BenthosWeightComputingException(String message, String property, int index) { super(message, property, index); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java index 997281a..01519cf 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java @@ -1,5 +1,9 @@ package fr.ifremer.tutti.service.catches; +import fr.ifremer.tutti.type.WeightUnit; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 13/04/16. * @@ -7,7 +11,31 @@ package fr.ifremer.tutti.service.catches; */ public class CatchWeightComputingException extends TuttiWeightComputingException { - public CatchWeightComputingException(String message) { + public static CatchWeightComputingException forIncoherentTotal(WeightUnit weightUnit, + Float totalWeight, + Float computedTotalWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.incoherentTotal", + weightUnit.fromEntity(totalWeight) + unitShortLabel, + weightUnit.fromEntity(computedTotalWeight) + unitShortLabel); + return new CatchWeightComputingException(errorMessage); + + } + + public static CatchWeightComputingException forIncoherentTotalWithRejected(WeightUnit weightUnit, + Float totalWeight, + Float computedTotalWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.incoherentTotalWithRejected", + weightUnit.fromEntity(totalWeight) + unitShortLabel, + weightUnit.fromEntity(computedTotalWeight) + unitShortLabel); + return new CatchWeightComputingException(errorMessage); + + } + + private CatchWeightComputingException(String message) { super(message); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java index 6c22618..a83a498 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java @@ -1,5 +1,10 @@ package fr.ifremer.tutti.service.catches; +import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; +import fr.ifremer.tutti.type.WeightUnit; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 13/04/16. * @@ -7,11 +12,30 @@ package fr.ifremer.tutti.service.catches; */ public class MarineLitterWeightComputingException extends TuttiWeightComputingException { - public MarineLitterWeightComputingException(String message) { + public static MarineLitterWeightComputingException forNoWeight(int index) { + + String errorMessage = t("tutti.validator.warning.marineLitter.weight.required"); + return new MarineLitterWeightComputingException(errorMessage, MarineLitterBatch.PROPERTY_WEIGHT, index); + + } + + public static MarineLitterWeightComputingException forIncoherentTotal(WeightUnit weightUnit, + Float marineLitterTotalWeight, + Float marineLitterTotalComputedWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal", + weightUnit.fromEntity(marineLitterTotalWeight) + unitShortLabel, + weightUnit.fromEntity(marineLitterTotalComputedWeight) + unitShortLabel); + return new MarineLitterWeightComputingException(errorMessage); + + } + + private MarineLitterWeightComputingException(String message) { super(message); } - public MarineLitterWeightComputingException(String message, String property, int index) { + private MarineLitterWeightComputingException(String message, String property, int index) { super(message, property, index); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java index 42ba734..4e734cd 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java @@ -1,5 +1,10 @@ package fr.ifremer.tutti.service.catches; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.type.WeightUnit; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 13/04/16. * @@ -7,11 +12,111 @@ package fr.ifremer.tutti.service.catches; */ public class SpeciesWeightComputingException extends TuttiWeightComputingException { - public SpeciesWeightComputingException(String message) { + public static SpeciesWeightComputingException forValidationMessage(WeightUnit weightUnit, + String message, + String species, + String categoryLabel, + String categoryValue, + Float weight, + Float sampleCategoryWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t(message, + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(weight) + unitShortLabel, + weightUnit.fromEntity(sampleCategoryWeight) + unitShortLabel + ); + throw new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + + } + + public static SpeciesWeightComputingException forIncoherentTotalSorted(WeightUnit weightUnit, + Float speciesTotalSortedWeight, + Float speciesTotalComputedSortedWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted", + weightUnit.fromEntity(speciesTotalSortedWeight) + unitShortLabel, + weightUnit.fromEntity(speciesTotalComputedSortedWeight) + unitShortLabel); + return new SpeciesWeightComputingException(errorMessage); + + } + + public static SpeciesWeightComputingException forIncoherentParentCategoryWeight(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float categoryWeight, + Float sum, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(categoryWeight) + unitShortLabel, + weightUnit.fromEntity(sum) + unitShortLabel); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + public static SpeciesWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float frequencyWeight, + Float rowWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(frequencyWeight) + unitShortLabel, + weightUnit.fromEntity(rowWeight) + unitShortLabel); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + } + + public static SpeciesWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float frequencyWeight, + Float categoryWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(frequencyWeight) + unitShortLabel, + weightUnit.fromEntity(categoryWeight) + unitShortLabel); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + public static SpeciesWeightComputingException forNoWeight(String species, + String categoryLabel, + String categoryValue, + int thisIndex) { + + String errorMessage = t("tutti.service.operations.computeWeights.error.species.noWeight", + species, + categoryLabel, + categoryValue); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + + private SpeciesWeightComputingException(String message) { super(message); } - public SpeciesWeightComputingException(String message, String property, int index) { + private SpeciesWeightComputingException(String message, String property, int index) { super(message, property, index); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java index 3896b7d..466cfc8 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java @@ -45,8 +45,6 @@ import org.nuiton.validator.NuitonValidatorResult; import java.io.Serializable; import java.util.List; -import static org.nuiton.i18n.I18n.t; - /** * @author Kevin Morin - kmorin@codelutin.com * @since 1.3 @@ -117,7 +115,11 @@ public class WeightComputingService extends AbstractTuttiService { catchBatch.setSpeciesTotalSortedComputedWeight(WeightUnit.KG.round(speciesTotalSortedWeight)); } else if (Weights.isSmallerWeight(speciesTotalSortedWeight, speciesTotalComputedSortedWeight)) { - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted")); + + throw SpeciesWeightComputingException.forIncoherentTotalSorted(getSpeciesWeightUnit(), + speciesTotalSortedWeight, + speciesTotalComputedSortedWeight); + } catchBatch.setSpeciesTotalUnsortedComputedWeight(WeightUnit.KG.round(speciesTotalComputedUnsortedWeight)); @@ -159,7 +161,12 @@ public class WeightComputingService extends AbstractTuttiService { catchBatch.setBenthosTotalSortedComputedWeight(WeightUnit.KG.round(benthosTotalSortedWeight)); } else if (Weights.isSmallerWeight(benthosTotalSortedWeight, benthosTotalComputedSortedWeight)) { - throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted")); + + throw BenthosWeightComputingException.forIncoherentTotalSorted( + getBenthosWeightUnit(), + benthosTotalSortedWeight, + benthosTotalComputedSortedWeight); + } catchBatch.setBenthosTotalUnsortedComputedWeight(WeightUnit.KG.round(benthosTotalComputedUnsortedWeight)); @@ -171,8 +178,8 @@ public class WeightComputingService extends AbstractTuttiService { Float marineLitterTotalComputedWeight = 0f; if (rootMarineLitterBatch != null) { - List<MarineLitterBatch> marineLitterBatches = rootMarineLitterBatch.getChildren(); - for (MarineLitterBatch row : marineLitterBatches) { + + for (MarineLitterBatch row : rootMarineLitterBatch.getChildren()) { Float rowWeight = row.getWeight(); if (rowWeight == null) { marineLitterTotalComputedWeight = null; @@ -180,17 +187,24 @@ public class WeightComputingService extends AbstractTuttiService { } marineLitterTotalComputedWeight += rowWeight; } + } if (marineLitterTotalComputedWeight != null) { - catchBatch.setMarineLitterTotalComputedWeight(WeightUnit.KG.round(marineLitterTotalComputedWeight)); + + marineLitterTotalComputedWeight = WeightUnit.KG.round(marineLitterTotalComputedWeight); + catchBatch.setMarineLitterTotalComputedWeight(marineLitterTotalComputedWeight); + } Float marineLitterTotalWeight = catchBatch.getMarineLitterTotalWeight(); - if (marineLitterTotalWeight == null) { - marineLitterTotalWeight = marineLitterTotalComputedWeight; + if (marineLitterTotalWeight != null + && marineLitterTotalComputedWeight != null + && Weights.isSmallerWeight(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { + + throw MarineLitterWeightComputingException.forIncoherentTotal(getMarineLitterWeightUnit(), + marineLitterTotalWeight, + marineLitterTotalComputedWeight); - } else if (marineLitterTotalComputedWeight != null && Weights.isSmallerWeight(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { - throw new MarineLitterWeightComputingException(t("tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal")); } // nothing to do with the marine litter weight, it is an isolated weight @@ -206,8 +220,14 @@ public class WeightComputingService extends AbstractTuttiService { Float rejectedWeight = catchBatch.getCatchTotalRejectedWeight(); if (rejectedWeight == null && totalWeight != null) { - if (Weights.isNotEqualWeight(totalWeight, totalUnsortedWeight + totalSortedSortedWeight)) { - throw new CatchWeightComputingException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); + + Float computedTotalWeight = WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight); + + if (Weights.isNotEqualWeight(totalWeight, computedTotalWeight)) { + + throw CatchWeightComputingException.forIncoherentTotal(getCatchWeightUnit(), + totalWeight, + computedTotalWeight); } @@ -221,8 +241,16 @@ public class WeightComputingService extends AbstractTuttiService { } catchBatch.setCatchTotalComputedWeight(WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight)); - } else if (Weights.isNotEqualWeight(totalWeight, totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight)) { - throw new CatchWeightComputingException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); + } else { + + Float computedTotalWeight = WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight); + if (Weights.isNotEqualWeight(totalWeight, computedTotalWeight)) { + + throw CatchWeightComputingException.forIncoherentTotalWithRejected(getCatchWeightUnit(), + totalWeight, + computedTotalWeight); + } + } Float totalSortedWeight = totalSortedSortedWeight; @@ -269,21 +297,20 @@ public class WeightComputingService extends AbstractTuttiService { int thisIndex = currentSpeciesRowIndex++; Float categoryWeight = batch.getSampleCategoryWeight(); Float rowWeight = batch.getWeight(); - String species = decorateSpecies(batch.getSpecies()); - String categoryValue = decorateCategoryValue(batch.getSampleCategoryValue()); NuitonValidatorResult validation = validationService.validateEditSpeciesBatch(batch); if (!validation.isValid()) { + List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new SpeciesWeightComputingException(t(messages.get(0), - species, - categoryLabel, - categoryValue, - batch.getWeight(), - batch.getSampleCategoryWeight()), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw SpeciesWeightComputingException.forValidationMessage( + getSpeciesWeightUnit(), + messages.get(0), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + batch.getWeight(), + batch.getSampleCategoryWeight(), + thisIndex); } List<SpeciesBatch> children = batch.getChildBatchs(); @@ -306,15 +333,15 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(sum); } else if (Weights.isSmallerWeight(categoryWeight, sum)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight", - species, - categoryLabel, - categoryValue, - categoryWeight, - sum), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + + throw SpeciesWeightComputingException.forIncoherentParentCategoryWeight( + getSpeciesWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + categoryWeight, + sum, + thisIndex); } else { sum = categoryWeight; @@ -337,16 +364,13 @@ public class WeightComputingService extends AbstractTuttiService { } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency", - species, - categoryLabel, - categoryValue, - frequencyWeight, - rowWeight), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw SpeciesWeightComputingException.forIncoherentRowWeightFrequency(getSpeciesWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + frequencyWeight, + rowWeight, + thisIndex); } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, @@ -360,16 +384,13 @@ public class WeightComputingService extends AbstractTuttiService { // weight, then set the weight of the sample if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight", - species, - categoryLabel, - categoryValue, - frequencyWeight, - categoryWeight), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw SpeciesWeightComputingException.forIncoherentCategoryWeight(getSpeciesWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + frequencyWeight, + categoryWeight, + thisIndex); } else if (rowWeight == null) { batch.setComputedWeight(frequencyWeight); @@ -391,14 +412,10 @@ public class WeightComputingService extends AbstractTuttiService { } if (Weights.isNullOrZero(result)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.noWeight", - species, - categoryLabel, - categoryValue), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw SpeciesWeightComputingException.forNoWeight(decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + thisIndex); } return WeightUnit.KG.round(result); @@ -423,26 +440,24 @@ public class WeightComputingService extends AbstractTuttiService { } public Float computeBenthosBatch(SpeciesBatch batch) { + Float result = null; int thisIndex = currentBenthosRowIndex++; Float categoryWeight = batch.getSampleCategoryWeight(); Float rowWeight = batch.getWeight(); - String species = decorateSpecies(batch.getSpecies()); - String categoryValue = decorateCategoryValue(batch.getSampleCategoryValue()); NuitonValidatorResult validation = validationService.validateEditBenthosBatch(batch); if (!validation.isValid()) { List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new BenthosWeightComputingException(t(messages.get(0), - species, - categoryLabel, - categoryValue, - batch.getWeight(), - batch.getSampleCategoryWeight()), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw BenthosWeightComputingException.forValidationMessage(getBenthosWeightUnit(), + messages.get(0), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + batch.getWeight(), + batch.getSampleCategoryWeight(), + thisIndex); } List<SpeciesBatch> children = batch.getChildBatchs(); @@ -465,16 +480,14 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(sum); } else if (Weights.isSmallerWeight(categoryWeight, sum)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight", - species, - categoryLabel, - categoryValue, - categoryWeight, - sum), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + + throw BenthosWeightComputingException.forIncoherentParentCategoryWeight(getBenthosWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + categoryWeight, + sum, + thisIndex); } else { sum = categoryWeight; @@ -498,17 +511,13 @@ public class WeightComputingService extends AbstractTuttiService { } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new BenthosWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency", - species, - categoryLabel, - categoryValue, - rowWeight, - categoryWeight), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw BenthosWeightComputingException.forIncoherentRowWeightFrequency(getBenthosWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + rowWeight, + categoryWeight, + thisIndex); } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, @@ -522,16 +531,13 @@ public class WeightComputingService extends AbstractTuttiService { // weight, then set the weight of the sample if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight", - species, - categoryLabel, - categoryValue, - frequencyWeight, - categoryWeight), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw BenthosWeightComputingException.forIncoherentCategoryWeight(getBenthosWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + frequencyWeight, + categoryWeight, + thisIndex); } else if (rowWeight == null) { batch.setComputedWeight(frequencyWeight); @@ -552,35 +558,29 @@ public class WeightComputingService extends AbstractTuttiService { } if (Weights.isNullOrZero(result)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.noWeight", - species, - categoryLabel, - categoryValue), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw BenthosWeightComputingException.forNoWeight(decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + thisIndex); } return WeightUnit.KG.round(result); } - public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(Integer fishingOperationId, Float marineLitterweight) { + public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(Integer fishingOperationId, Float marineLitterWeight) { BatchContainer<MarineLitterBatch> rootMarineLitterBatch = persistenceService.getRootMarineLitterBatch(fishingOperationId); if (rootMarineLitterBatch != null) { - boolean checkWeight = marineLitterweight == null; + boolean checkWeight = marineLitterWeight == null; List<MarineLitterBatch> children = rootMarineLitterBatch.getChildren(); for (int i = 0; i < children.size(); i++) { MarineLitterBatch batch = children.get(i); if (checkWeight && Weights.isNullOrZero(batch.getWeight())) { - throw new MarineLitterWeightComputingException(t("tutti.validator.warning.marineLitter.weight.required"), - MarineLitterBatch.PROPERTY_WEIGHT, - i); + throw MarineLitterWeightComputingException.forNoWeight(i); } } } @@ -595,9 +595,8 @@ public class WeightComputingService extends AbstractTuttiService { Float speciesTotalComputedUnsortedWeight = 0f; for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { - Float weight = Numbers.getValueOrComputedValue( - speciesBatch.getSampleCategoryWeight(), - speciesBatch.getSampleCategoryComputedWeight()); + Float weight = Numbers.getValueOrComputedValue(speciesBatch.getSampleCategoryWeight(), + speciesBatch.getSampleCategoryComputedWeight()); if (weight == null) { break; } @@ -659,4 +658,20 @@ public class WeightComputingService extends AbstractTuttiService { return decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue); } + private WeightUnit getSpeciesWeightUnit() { + return context.getConfig().getSpeciesWeightUnit(); + } + + private WeightUnit getBenthosWeightUnit() { + return context.getConfig().getBenthosWeightUnit(); + } + + private WeightUnit getMarineLitterWeightUnit() { + return context.getConfig().getMarineLitterWeightUnit(); + } + + private WeightUnit getCatchWeightUnit() { + return WeightUnit.KG; + } + } diff --git a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-edit-error-validation.xml b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-edit-error-validation.xml index 4d96b89..fdffdbe 100644 --- a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-edit-error-validation.xml +++ b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-edit-error-validation.xml @@ -30,7 +30,7 @@ <field name="species"> <field-validator type="required" short-circuit="true"> - <message>tutti.validator.error.speciesBatch.species.required</message> + <message>tutti.validator.error.speciesOrBenthosBatch.species.required</message> </field-validator> </field> @@ -39,14 +39,14 @@ <param name="expression"> <![CDATA[ !(sampleCategoryWeight == null && weight != null) ]]> </param> - <message>tutti.service.operations.computeWeights.error.species.incoherentRowWeightCategory</message> + <message>tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentRowWeightCategory</message> </field-validator> <field-validator type="fieldexpression" short-circuit="true"> <param name="expression"> <![CDATA[ weight == null || sampleCategoryWeight == null || weight <= sampleCategoryWeight ]]> </param> - <message>tutti.service.operations.computeWeights.error.species.incoherentSampleWeight</message> + <message>tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentSampleWeight</message> </field-validator> </field> diff --git a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-validate-fatal-validation.xml b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-validate-fatal-validation.xml index b955bc7..c6e014f 100644 --- a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-validate-fatal-validation.xml +++ b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-validate-fatal-validation.xml @@ -31,7 +31,7 @@ <field name="species"> <field-validator type="temporaryReferential" short-circuit="true"> - <message>tutti.validator.error.speciesBatch.species.temporary</message> + <message>tutti.validator.error.speciesOrBenthosBatch.species.temporary</message> </field-validator> </field> diff --git a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties index 67f5130..1f0e6be 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties @@ -308,6 +308,7 @@ tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted= tutti.service.operations.computeWeights.error.benthos.noWeight= tutti.service.operations.computeWeights.error.incoherentRowWeightCategory= tutti.service.operations.computeWeights.error.incoherentTotal= +tutti.service.operations.computeWeights.error.incoherentTotalWithRejected= tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal= tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight= tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight= @@ -316,6 +317,8 @@ tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequen tutti.service.operations.computeWeights.error.species.incoherentSampleWeight= tutti.service.operations.computeWeights.error.species.incoherentTotalSorted= tutti.service.operations.computeWeights.error.species.noWeight= +tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentRowWeightCategory= +tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentSampleWeight= tutti.service.operations.computeWeights.error.totalLessThanSortedAndUnsorted= tutti.service.operations.exportCatchesReport.error= tutti.service.operations.exportCatchesReport.specialRows.benthos.code= @@ -535,6 +538,8 @@ tutti.validator.error.protocol.name.required= tutti.validator.error.speciesBatch.species.required= tutti.validator.error.speciesBatch.species.temporary= tutti.validator.error.speciesBatch.vessel.temporary= +tutti.validator.error.speciesOrBenthosBatch.species.required= +tutti.validator.error.speciesOrBenthosBatch.species.temporary= tutti.validator.export.message.error= tutti.validator.export.message.warning= tutti.validator.export.operation= diff --git a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties index 379dddf..1009323 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties @@ -259,27 +259,28 @@ tutti.service.multipost.import.wrongOperation.error=Opération est impossible<hr tutti.service.multipost.import.wrongSpecies.error=Espèce impossible<hr/>Les lots que vous essayez d'importer proviennent d'un autre lot \:<br/>%s tutti.service.multipost.uncompress.error=Erreur lors de la décompression de l'archive %s tutti.service.operations.cleanWeights.benthos.batch=Lot benthos -tutti.service.operations.cleanWeights.error.redundant.frequencyWeight=Le poids (%s%s) du <strong>sous-échantillon</strong> vaut la somme des poids des <strong>échantillons mesurés</strong> -tutti.service.operations.cleanWeights.error.redundant.sampleCategoryWeight=Le poids (%s%s) de la catégorie <strong>%s</strong> vaut celui de la catégorie supérieure <strong>%s</strong> -tutti.service.operations.cleanWeights.error.redundant.weight=Le poids (%s%s) de <strong>sous-échantillon</strong> vaut celui de la plus fine catégorie <strong>%s</strong> +tutti.service.operations.cleanWeights.error.redundant.frequencyWeight=Le poids (%s) du <strong>sous-échantillon</strong> vaut la somme des poids des <strong>échantillons mesurés</strong> +tutti.service.operations.cleanWeights.error.redundant.sampleCategoryWeight=Le poids (%s) de la catégorie <strong>%s</strong> vaut celui de la catégorie supérieure <strong>%s</strong> +tutti.service.operations.cleanWeights.error.redundant.weight=Le poids (%s) de <strong>sous-échantillon</strong> vaut celui de la plus fine catégorie <strong>%s</strong> tutti.service.operations.cleanWeights.species.batch=Lot espèce -tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight=Benthos - Le poids total des mensurations du lot de %s/%s - %s (%skg) est supérieur au poids de la catégorie (%skg) -tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight=Benthos - Le poids du lot de %s/%s - %s (%skg) est inférieur à la somme des poids de ses sous-catégories (%skg) +tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight=Benthos - Le poids total des mensurations du lot de %s/%s - %s (%s) est supérieur au poids de la catégorie (%s) +tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight=Benthos - Le poids du lot de %s/%s - %s (%s) est inférieur à la somme des poids de ses sous-catégories (%s) tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightCategory=Le poids de sous-échantillon est renseigné alors que le lot n'a pas de poids. -tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency=Benthos - Le poids total des mensurations du lot de %s/%s - %s (%skg) est différent du poids du sous-échantillon (%skg) +tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency=Benthos - Le poids total des mensurations du lot de %s/%s - %s (%s) est différent du poids du sous-échantillon (%s) tutti.service.operations.computeWeights.error.benthos.incoherentSampleWeight=Benthos - Le poids de sous-échantillon du lot %s/%s - %s (%skg) est supérieur au poids du lot (%skg) -tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted=Le poids total Vrac du benthos est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié +tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted=Le poids total Vrac du benthos (%s) est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié (%s) tutti.service.operations.computeWeights.error.benthos.noWeight=Benthos - Le lot de %s/%s - %s n'a pas de poids ou un poids de 0 tutti.service.operations.computeWeights.error.incoherentRowWeightCategory=Le poids de sous-échantillon est renseigné alors que le lot n'a pas de poids. -tutti.service.operations.computeWeights.error.incoherentTotal=Le poids total de la capture ne correspond pas à la somme des poids totaux Vrac et Hors Vrac -tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal=Le poids total des macro-déchets est inférieur à la somme des poids des macro-déchets saisis -tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight=Espèces - Le poids total des mensurations du lot de %s/%s - %s (%skg) est supérieur au poids de la catégorie (%skg) -tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight=Espèces - Le poids du lot de %s/%s - %s (%skg) est inférieur à la somme des poids de ses sous-catégories (%skg) -tutti.service.operations.computeWeights.error.species.incoherentRowWeightCategory=Le poids de sous-échantillon est renseigné alors que le lot n'a pas de poids. -tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency=Espèces - Le poids total des mensurations du lot de %s/%s - %s (%skg) est différent du poids du sous-échantillon (%skg) -tutti.service.operations.computeWeights.error.species.incoherentSampleWeight=Espèces - Le poids de sous-échantillon du lot %s/%s - %s (%skg) est supérieur au poids du lot (%skg) -tutti.service.operations.computeWeights.error.species.incoherentTotalSorted=Le poids total Vrac des espèces est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié +tutti.service.operations.computeWeights.error.incoherentTotal=Le poids total de la capture (%s) ne correspond pas à la somme des poids totaux Vrac et Hors Vrac (%s) +tutti.service.operations.computeWeights.error.incoherentTotalWithRejected=Le poids total de la capture (%s) ne correspond pas à la somme des poids totaux Vrac et Hors Vrac et du rejeté (%s) +tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal=Le poids total des macro-déchets (%s) est inférieur à la somme des poids des macro-déchets saisis (%s) +tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight=Espèces - Le poids total des mensurations du lot de %s/%s - %s (%s) est supérieur au poids de la catégorie (%s) +tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight=Espèces - Le poids du lot de %s/%s - %s (%s) est inférieur à la somme des poids de ses sous-catégories (%s) +tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency=Espèces - Le poids total des mensurations du lot de %s/%s - %s (%s) est différent du poids du sous-échantillon (%s) +tutti.service.operations.computeWeights.error.species.incoherentTotalSorted=Le poids total Vrac des espèces (%s) est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié (%s) tutti.service.operations.computeWeights.error.species.noWeight=Espèces - Le lot de %s/%s/%s n'a pas de poids ou un poids de 0 +tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentRowWeightCategory=Le poids de sous-échantillon est renseigné alors que le lot n'a pas de poids. +tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentSampleWeight=Le poids de sous-échantillon du lot %s/%s - %s (%s) est supérieur au poids du lot (%s) tutti.service.operations.computeWeights.error.totalLessThanSortedAndUnsorted=Le poids total de la capture est inférieur à la somme des poids total Vrac et Hors Vrac. tutti.service.operations.exportCatchesReport.error=Erreur lors de la génération du rapport des captures tutti.service.operations.exportCatchesReport.specialRows.benthos.code=BENTHOS @@ -474,8 +475,8 @@ tutti.validator.error.program.name.required=Le nom de la série est obligatoire tutti.validator.error.program.zone.required=La zone de la série est obligatoire tutti.validator.error.protocol.name.alreadyUsed=Le nom du protocole est déjà utilisé tutti.validator.error.protocol.name.required=Le nom du protocole est obligatoire -tutti.validator.error.speciesBatch.species.required=L'espèce est obligatoire -tutti.validator.error.speciesBatch.species.temporary=La capture Espèce utilise une espèce temporaire +tutti.validator.error.speciesOrBenthosBatch.species.required=L'espèce est obligatoire +tutti.validator.error.speciesOrBenthosBatch.species.temporary=La capture utilise une espèce temporaire tutti.validator.export.message.error=\t- [ERREUR] %s tutti.validator.export.message.warning=\t- [WARNING] %s tutti.validator.export.operation=* %s \: -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.