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 0652ce95303ad072ad0cc2d9516385587f313aae Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:40:58 2016 +0200 Nettoyage sur le service de nettoyage de poids + dernière revue des exceptions du service d'élévation --- .../catches/BenthosWeightComputingException.java | 31 ++- .../catches/CatchWeightComputingException.java | 10 +- .../MarineLitterWeightComputingException.java | 5 +- .../catches/SpeciesWeightComputingException.java | 31 ++- .../service/catches/WeightCleaningService.java | 294 +++++++++------------ .../service/catches/WeightComputingService.java | 35 ++- 6 files changed, 175 insertions(+), 231 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 f869c3a..c964f21 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 @@ -21,15 +21,14 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti Float sampleCategoryWeight, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t(message, species, categoryLabel, categoryValue, - weightUnit.fromEntity(weight) + unitShortLabel, - weightUnit.fromEntity(sampleCategoryWeight) + unitShortLabel + weightUnit.renderFromEntityWithShortLabel(weight), + weightUnit.renderFromEntityWithShortLabel(sampleCategoryWeight) ); - throw new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); } @@ -37,10 +36,9 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti 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); + weightUnit.renderFromEntityWithShortLabel(speciesTotalSortedWeight), + weightUnit.renderFromEntityWithShortLabel(speciesTotalComputedSortedWeight)); return new BenthosWeightComputingException(errorMessage); } @@ -53,14 +51,14 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti 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); + weightUnit.renderFromEntityWithShortLabel(categoryWeight), + weightUnit.renderFromEntityWithShortLabel(sum)); return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } public static BenthosWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit, @@ -71,14 +69,14 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti 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); + weightUnit.renderFromEntityWithShortLabel(frequencyWeight), + weightUnit.renderFromEntityWithShortLabel(rowWeight)); return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + } public static BenthosWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit, @@ -89,14 +87,14 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti 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); + weightUnit.renderFromEntityWithShortLabel(frequencyWeight), + weightUnit.renderFromEntityWithShortLabel(categoryWeight)); return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } public static BenthosWeightComputingException forNoWeight(String species, @@ -109,6 +107,7 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti categoryLabel, categoryValue); return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } 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 01519cf..5fc498d 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 @@ -15,10 +15,9 @@ public class CatchWeightComputingException extends TuttiWeightComputingException 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); + weightUnit.renderFromEntityWithShortLabel(totalWeight), + weightUnit.renderFromEntityWithShortLabel(computedTotalWeight)); return new CatchWeightComputingException(errorMessage); } @@ -27,10 +26,9 @@ public class CatchWeightComputingException extends TuttiWeightComputingException 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); + weightUnit.renderFromEntityWithShortLabel(totalWeight), + weightUnit.renderFromEntityWithShortLabel(computedTotalWeight)); return new CatchWeightComputingException(errorMessage); } 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 a83a498..658cefb 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 @@ -23,10 +23,9 @@ public class MarineLitterWeightComputingException extends TuttiWeightComputingEx 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); + weightUnit.renderFromEntityWithShortLabel(marineLitterTotalWeight) , + weightUnit.renderFromEntityWithShortLabel(marineLitterTotalComputedWeight) ); return new MarineLitterWeightComputingException(errorMessage); } 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 4e734cd..c748824 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 @@ -21,15 +21,14 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti Float sampleCategoryWeight, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t(message, species, categoryLabel, categoryValue, - weightUnit.fromEntity(weight) + unitShortLabel, - weightUnit.fromEntity(sampleCategoryWeight) + unitShortLabel + weightUnit.renderFromEntityWithShortLabel(weight), + weightUnit.renderFromEntityWithShortLabel(sampleCategoryWeight) ); - throw new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); } @@ -37,10 +36,9 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti 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); + weightUnit.renderFromEntityWithShortLabel(speciesTotalSortedWeight), + weightUnit.renderFromEntityWithShortLabel(speciesTotalComputedSortedWeight)); return new SpeciesWeightComputingException(errorMessage); } @@ -53,14 +51,14 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti 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); + weightUnit.renderFromEntityWithShortLabel(categoryWeight), + weightUnit.renderFromEntityWithShortLabel(sum)); return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } public static SpeciesWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit, @@ -71,14 +69,14 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti 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); + weightUnit.renderFromEntityWithShortLabel(frequencyWeight), + weightUnit.renderFromEntityWithShortLabel(rowWeight)); return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + } public static SpeciesWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit, @@ -89,14 +87,14 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti 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); + weightUnit.renderFromEntityWithShortLabel(frequencyWeight), + weightUnit.renderFromEntityWithShortLabel(categoryWeight)); return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } public static SpeciesWeightComputingException forNoWeight(String species, @@ -109,6 +107,7 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti categoryLabel, categoryValue); return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java index 92f8ef4..9207121 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java @@ -24,10 +24,7 @@ package fr.ifremer.tutti.service.catches; import com.google.common.base.Preconditions; import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; @@ -40,13 +37,13 @@ import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.type.WeightUnit; -import fr.ifremer.tutti.util.Weights; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import static fr.ifremer.tutti.service.PersistenceService.FrequencyFunction; @@ -62,8 +59,7 @@ import static org.nuiton.i18n.I18n.t; */ public class WeightCleaningService extends AbstractTuttiService { - private static final Log log = - LogFactory.getLog(WeightCleaningService.class); + private static final Log log = LogFactory.getLog(WeightCleaningService.class); protected PersistenceService persistenceService; @@ -97,53 +93,52 @@ public class WeightCleaningService extends AbstractTuttiService { benthosBatchPrefix = t("tutti.service.operations.cleanWeights.benthos.batch"); } - /** - * Check if there is some redundant weights that could be cleaned. - * - * If no warning found, then return is a empty map, otherwise all errors - * for any bad fishing operation. - * - * Result keys are fishing operation id, values are all batches in error for - * the fishing operation. - * - * @param cruiseId id of the cruise to check. - * @return map of warnings, or empty map if no error found. - */ - public Map<Integer, String> checkCruise(Integer cruiseId) { - - if (log.isDebugEnabled()) { - log.debug("Will check cruise: " + cruiseId); - } - - Map<Integer, String> result = Maps.newLinkedHashMap(); - - List<FishingOperation> allFishingOperation = - persistenceService.getAllFishingOperation(cruiseId); - - for (FishingOperation fishingOperation : allFishingOperation) { - - Integer fishingOperationId = fishingOperation.getIdAsInt(); - - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); - - if (!withCatchBatch) { - if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperation + - " since no catchBatch associated."); - } - continue; - } - - Multimap<String, String> errors = checkFishingOperation(fishingOperationId); - - if (!errors.isEmpty()) { - result.put(fishingOperationId, errorsToString(errors)); - } - } - return result; - } +// /** +// * Check if there is some redundant weights that could be cleaned. +// * +// * If no warning found, then return is a empty map, otherwise all errors +// * for any bad fishing operation. +// * +// * Result keys are fishing operation id, values are all batches in error for +// * the fishing operation. +// * +// * @param cruiseId id of the cruise to check. +// * @return map of warnings, or empty map if no error found. +// */ +// public Map<Integer, String> checkCruise(Integer cruiseId) { +// +// if (log.isDebugEnabled()) { +// log.debug("Will check cruise: " + cruiseId); +// } +// +// Map<Integer, String> result = new LinkedHashMap<>(); +// +// List<FishingOperation> allFishingOperation = +// persistenceService.getAllFishingOperation(cruiseId); +// +// for (FishingOperation fishingOperation : allFishingOperation) { +// +// Integer fishingOperationId = fishingOperation.getIdAsInt(); +// +// boolean withCatchBatch = +// persistenceService.isFishingOperationWithCatchBatch( +// fishingOperationId); +// +// if (!withCatchBatch) { +// if (log.isWarnEnabled()) { +// log.warn("Skip fishing operation " + fishingOperation + " since no catchBatch associated."); +// } +// continue; +// } +// +// Multimap<String, String> errors = checkFishingOperation(fishingOperationId); +// +// if (!errors.isEmpty()) { +// result.put(fishingOperationId, errorsToString(errors)); +// } +// } +// return result; +// } public String errorsToString(Multimap<String, String> errors) { StringBuilder errorsStr = new StringBuilder("<ul style=\"font-size:11\">"); @@ -170,22 +165,21 @@ public class WeightCleaningService extends AbstractTuttiService { return errorsStr.toString(); } - /** - * Clean all redundant weights for the given cruise. - * - * @param cruiseId id of the cruise to clean. - */ - public void cleanCruise(Integer cruiseId) { - - if (log.isDebugEnabled()) { - log.debug("Will clean cruise: " + cruiseId); - } - - List<Integer> allFishingOperation = - persistenceService.getAllFishingOperationIds(cruiseId); - - allFishingOperation.forEach(this::cleanFishingOperation); - } +// /** +// * Clean all redundant weights for the given cruise. +// * +// * @param cruiseId id of the cruise to clean. +// */ +// public void cleanCruise(Integer cruiseId) { +// +// if (log.isDebugEnabled()) { +// log.debug("Will clean cruise: " + cruiseId); +// } +// +// List<Integer> allFishingOperation = persistenceService.getAllFishingOperationIds(cruiseId); +// +// allFishingOperation.forEach(this::cleanFishingOperation); +// } /** * Check for some redundant weights in species or benthos batches of @@ -201,33 +195,26 @@ public class WeightCleaningService extends AbstractTuttiService { } Multimap<String, String> result = LinkedHashMultimap.create(); - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); + boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId); if (withCatchBatch) { // check species batches - BatchContainer<SpeciesBatch> speciesBatch = - persistenceService.getRootSpeciesBatch( - fishingOperationId, true); + BatchContainer<SpeciesBatch> speciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, true); for (SpeciesBatch batch : speciesBatch.getChildren()) { - checkBatch( - speciesBatchPrefix, - speciesWeightUnit, - batch, - result, - speciesFrequencyFunction); + checkBatch(speciesBatchPrefix, + speciesWeightUnit, + batch, + result, + speciesFrequencyFunction); } // check benthos batches - BatchContainer<SpeciesBatch> benthosBatch = - persistenceService.getRootBenthosBatch( - fishingOperationId, true); + BatchContainer<SpeciesBatch> benthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, true); for (SpeciesBatch batch : benthosBatch.getChildren()) { @@ -237,13 +224,13 @@ public class WeightCleaningService extends AbstractTuttiService { result, benthosFrequencyFunction); } + } else { // no catch, no check if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); + log.warn("Skip fishing operation " + fishingOperationId + " since no catchBatch associated."); } } @@ -263,9 +250,7 @@ public class WeightCleaningService extends AbstractTuttiService { log.debug("Will clean fishingOperation: " + fishingOperationId); } - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); + boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId); boolean result = false; @@ -273,10 +258,8 @@ public class WeightCleaningService extends AbstractTuttiService { // clean species batches - Set<SpeciesBatch> speciesToSave = Sets.newHashSet(); - BatchContainer<SpeciesBatch> speciesBatch = - persistenceService.getRootSpeciesBatch( - fishingOperationId, true); + Set<SpeciesBatch> speciesToSave = new HashSet<>(); + BatchContainer<SpeciesBatch> speciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, true); for (SpeciesBatch batch : speciesBatch.getChildren()) { @@ -289,10 +272,8 @@ public class WeightCleaningService extends AbstractTuttiService { // clean benthos batches - Set<SpeciesBatch> benthosToSave = Sets.newHashSet(); - BatchContainer<SpeciesBatch> benthosBatch = - persistenceService.getRootBenthosBatch( - fishingOperationId, true); + Set<SpeciesBatch> benthosToSave = new HashSet<>(); + BatchContainer<SpeciesBatch> benthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, true); for (SpeciesBatch batch : benthosBatch.getChildren()) { @@ -309,8 +290,7 @@ public class WeightCleaningService extends AbstractTuttiService { result = true; - FishingOperation fishingOperation = - persistenceService.getFishingOperation(fishingOperationId); + FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); for (SpeciesBatch toSave : speciesToSave) { toSave.setFishingOperation(fishingOperation); @@ -328,8 +308,7 @@ public class WeightCleaningService extends AbstractTuttiService { // no catch, no clean if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); + log.warn("Skip fishing operation " + fishingOperationId + " since no catchBatch associated."); } } @@ -337,11 +316,7 @@ public class WeightCleaningService extends AbstractTuttiService { } - protected void checkBatch(String batchPrefix, - WeightUnit weightUnit, - SpeciesBatch batch, - Multimap<String, String> result, - FrequencyFunction frequencyFunction) { + protected void checkBatch(String batchPrefix, WeightUnit weightUnit, SpeciesBatch batch, Multimap<String, String> result, FrequencyFunction frequencyFunction) { if (!batch.isChildBatchsEmpty()) { @@ -350,17 +325,7 @@ public class WeightCleaningService extends AbstractTuttiService { // check batch sample category weight (before childs) String message = checkSampleCategoryWeightRedundant(weightUnit, batch, childBatch); - - if (message != null) { - - String label = getBatchLabel(batchPrefix, weightUnit, childBatch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } - if (!result.containsEntry(label, message)) { - result.put(label, message); - } - } + addMessageIfNotExist(message, batchPrefix, weightUnit, childBatch, result); // check childs checkBatch(batchPrefix, weightUnit, childBatch, result, frequencyFunction); @@ -369,30 +334,12 @@ public class WeightCleaningService extends AbstractTuttiService { { // check batch weight String message = checkWeightRedundant(weightUnit, batch); - - if (message != null) { - String label = getBatchLabel(batchPrefix, weightUnit, batch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } - if (!result.containsEntry(label, message)) { - result.put(label, message); - } - } + addMessageIfNotExist(message, batchPrefix, weightUnit, batch, result); } { // check batch frequencies weight String message = checkFrequencyWeightRedundant(weightUnit, batch, frequencyFunction); - - if (message != null) { - String label = getBatchLabel(batchPrefix, weightUnit, batch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } - if (!result.containsEntry(label, message)) { - result.put(label, message); - } - } + addMessageIfNotExist(message, batchPrefix, weightUnit, batch, result); } } } @@ -417,10 +364,7 @@ public class WeightCleaningService extends AbstractTuttiService { if (message != null) { // always clean batch after cleaning childs - String label = getBatchLabel(batchPrefix, weightUnit, childBatch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } + buildLabelAndLogMessage(message, batchPrefix, weightUnit, childBatch); batch.setSampleCategoryWeight(null); result.add(batch); } @@ -433,10 +377,7 @@ public class WeightCleaningService extends AbstractTuttiService { String message = checkFrequencyWeightRedundant(weightUnit, batch, frequencyFunction); if (message != null) { - String label = getBatchLabel(batchPrefix, weightUnit, batch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } + buildLabelAndLogMessage(message, batchPrefix, weightUnit, batch); removeWeight = true; } @@ -446,10 +387,7 @@ public class WeightCleaningService extends AbstractTuttiService { String message = checkWeightRedundant(weightUnit, batch); if (message != null) { - String label = getBatchLabel(batchPrefix, weightUnit, batch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } + buildLabelAndLogMessage(message, batchPrefix, weightUnit, batch); removeWeight = true; } } @@ -461,11 +399,10 @@ public class WeightCleaningService extends AbstractTuttiService { result.add(batch); } } + } - protected String checkSampleCategoryWeightRedundant(WeightUnit weightUnit, - SpeciesBatch parentBatch, - SpeciesBatch batch) { + protected String checkSampleCategoryWeightRedundant(WeightUnit weightUnit, SpeciesBatch parentBatch, SpeciesBatch batch) { Preconditions.checkNotNull(parentBatch); @@ -475,12 +412,10 @@ public class WeightCleaningService extends AbstractTuttiService { Float sampleCategoryWeight = batch.getSampleCategoryWeight(); Float parentSampleCategoryWeight = parentBatch.getSampleCategoryWeight(); - if (sampleCategoryWeight != null && parentSampleCategoryWeight != null && - Weights.isEqualWeight(parentSampleCategoryWeight, sampleCategoryWeight)) { + if (sampleCategoryWeight != null && parentSampleCategoryWeight != null && WeightUnit.KG.isEquals(parentSampleCategoryWeight, sampleCategoryWeight)) { result = t("tutti.service.operations.cleanWeights.error.redundant.sampleCategoryWeight", - weightUnit.fromEntity(sampleCategoryWeight), - weightUnit.getShortLabel(), + weightUnit.fromEntity(sampleCategoryWeight) + weightUnit.getShortLabel(), getCategoryLabel(batch), getCategoryLabel(parentBatch) ); @@ -503,13 +438,11 @@ public class WeightCleaningService extends AbstractTuttiService { // check if there is some frequencies List<SpeciesBatchFrequency> frequencies = frequencyFunction.apply(batch); - Float frequenciesWeigth = - persistenceService.countFrequenciesWeight(frequencies, true); + Float frequenciesWeigth = persistenceService.countFrequenciesWeight(frequencies, true); - if (frequenciesWeigth != null && Weights.isEqualWeight(weight, frequenciesWeigth)) { + if (frequenciesWeigth != null && WeightUnit.KG.isEquals(weight, frequenciesWeigth)) { result = t("tutti.service.operations.cleanWeights.error.redundant.frequencyWeight", - weightUnit.fromEntity(weight), - weightUnit.getShortLabel(), + weightUnit.fromEntity(weight) + weightUnit.getShortLabel(), getCategoryLabel(batch)); } } @@ -517,8 +450,7 @@ public class WeightCleaningService extends AbstractTuttiService { return result; } - protected String checkWeightRedundant(WeightUnit weightUnit, - SpeciesBatch batch) { + protected String checkWeightRedundant(WeightUnit weightUnit, SpeciesBatch batch) { Preconditions.checkState(batch.isChildBatchsEmpty()); @@ -527,25 +459,23 @@ public class WeightCleaningService extends AbstractTuttiService { // on a leaf, check if weight is not = to the finest category weight Float weight = batch.getWeight(); Float sampleCategoryWeight = batch.getSampleCategoryWeight(); - if (weight != null && sampleCategoryWeight != null && Weights.isEqualWeight(weight, sampleCategoryWeight)) { + if (weight != null && sampleCategoryWeight != null && WeightUnit.KG.isEquals(weight, sampleCategoryWeight)) { result = t("tutti.service.operations.cleanWeights.error.redundant.weight", - weightUnit.fromEntity(weight), - weightUnit.getShortLabel(), + weightUnit.fromEntity(weight) + weightUnit.getShortLabel(), getCategoryLabel(batch)); } return result; } - protected String getBatchLabel(String type, WeightUnit weightUnit, - SpeciesBatch batch) { + protected String getBatchLabel(String type, WeightUnit weightUnit, SpeciesBatch batch) { StringBuilder sb = new StringBuilder("[ " + type); String species = decoratorService.getDecoratorByType(Species.class).toString(batch.getSpecies()); sb.append(" ").append(species); - List<String> categories = Lists.newArrayList(); + List<String> categories = new ArrayList<>(); SpeciesBatch b = batch; while (b.getParentBatch() != null) { String categoryValue = decoratorService.getDecorator(b.getSampleCategoryValue()) @@ -562,9 +492,29 @@ public class WeightCleaningService extends AbstractTuttiService { } protected String getCategoryLabel(SpeciesBatch batch) { - SampleCategoryModelEntry category = - sampleCategoryModel.getCategoryById(batch.getSampleCategoryId()); + SampleCategoryModelEntry category = sampleCategoryModel.getCategoryById(batch.getSampleCategoryId()); return category.getLabel(); } + + protected String buildLabelAndLogMessage(String message, String batchPrefix, WeightUnit weightUnit, SpeciesBatch b) { + String label = getBatchLabel(batchPrefix, weightUnit, b); + if (log.isInfoEnabled()) { + log.info(label + " " + message); + } + return label; + } + + protected void addMessageIfNotExist(String message, String batchPrefix, WeightUnit weightUnit, SpeciesBatch b, Multimap<String, String> result) { + + if (message != null) { + + String label = buildLabelAndLogMessage(message, batchPrefix, weightUnit, b); + if (!result.containsEntry(label, message)) { + result.put(label, message); + } + } + + } + } 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 466cfc8..901add8 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 @@ -36,7 +36,6 @@ import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.ValidationService; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.util.Numbers; -import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.tuple.Pair; import org.nuiton.decorator.Decorator; @@ -114,7 +113,7 @@ public class WeightComputingService extends AbstractTuttiService { speciesTotalSortedWeight = speciesTotalComputedSortedWeight; catchBatch.setSpeciesTotalSortedComputedWeight(WeightUnit.KG.round(speciesTotalSortedWeight)); - } else if (Weights.isSmallerWeight(speciesTotalSortedWeight, speciesTotalComputedSortedWeight)) { + } else if (WeightUnit.KG.isSmallerThan(speciesTotalSortedWeight, speciesTotalComputedSortedWeight)) { throw SpeciesWeightComputingException.forIncoherentTotalSorted(getSpeciesWeightUnit(), speciesTotalSortedWeight, @@ -160,7 +159,7 @@ public class WeightComputingService extends AbstractTuttiService { benthosTotalSortedWeight = benthosTotalComputedSortedWeight; catchBatch.setBenthosTotalSortedComputedWeight(WeightUnit.KG.round(benthosTotalSortedWeight)); - } else if (Weights.isSmallerWeight(benthosTotalSortedWeight, benthosTotalComputedSortedWeight)) { + } else if (WeightUnit.KG.isSmallerThan(benthosTotalSortedWeight, benthosTotalComputedSortedWeight)) { throw BenthosWeightComputingException.forIncoherentTotalSorted( getBenthosWeightUnit(), @@ -199,7 +198,7 @@ public class WeightComputingService extends AbstractTuttiService { Float marineLitterTotalWeight = catchBatch.getMarineLitterTotalWeight(); if (marineLitterTotalWeight != null && marineLitterTotalComputedWeight != null - && Weights.isSmallerWeight(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { + && WeightUnit.KG.isSmallerThan(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { throw MarineLitterWeightComputingException.forIncoherentTotal(getMarineLitterWeightUnit(), marineLitterTotalWeight, @@ -223,7 +222,7 @@ public class WeightComputingService extends AbstractTuttiService { Float computedTotalWeight = WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight); - if (Weights.isNotEqualWeight(totalWeight, computedTotalWeight)) { + if (WeightUnit.KG.isNotEquals(totalWeight, computedTotalWeight)) { throw CatchWeightComputingException.forIncoherentTotal(getCatchWeightUnit(), totalWeight, @@ -244,7 +243,7 @@ public class WeightComputingService extends AbstractTuttiService { } else { Float computedTotalWeight = WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight); - if (Weights.isNotEqualWeight(totalWeight, computedTotalWeight)) { + if (WeightUnit.KG.isNotEquals(totalWeight, computedTotalWeight)) { throw CatchWeightComputingException.forIncoherentTotalWithRejected(getCatchWeightUnit(), totalWeight, @@ -261,7 +260,7 @@ public class WeightComputingService extends AbstractTuttiService { Float catchRate; - if (Weights.isEqualWeight(totalSortedSortedWeight, 0f)) { + if (WeightUnit.KG.isZero(totalSortedSortedWeight)) { catchRate = 0f; } else { catchRate = totalSortedWeight / totalSortedSortedWeight; @@ -332,7 +331,7 @@ public class WeightComputingService extends AbstractTuttiService { if (categoryWeight == null) { batch.setSampleCategoryComputedWeight(sum); - } else if (Weights.isSmallerWeight(categoryWeight, sum)) { + } else if (WeightUnit.KG.isSmallerThan(categoryWeight, sum)) { throw SpeciesWeightComputingException.forIncoherentParentCategoryWeight( getSpeciesWeightUnit(), @@ -362,7 +361,7 @@ public class WeightComputingService extends AbstractTuttiService { if (categoryWeight == null && rowWeight != null) { // throw new TuttiBusinessException(t("tutti.service.operations.computeWeights.error.incoherentRowWeightCategory")); - } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { + } else if (rowWeight != null && frequencyWeight != null && WeightUnit.KG.isNotEquals(rowWeight, frequencyWeight)) { throw SpeciesWeightComputingException.forIncoherentRowWeightFrequency(getSpeciesWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -378,11 +377,11 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(frequencyWeight); result = frequencyWeight; - } else if (frequencyWeight != null && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { + } else if (frequencyWeight != null && WeightUnit.KG.isNotEquals(frequencyWeight, categoryWeight)) { // if the weight of the frequencies is different from the category // weight, then set the weight of the sample - if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { + if (WeightUnit.KG.isGreaterThan(frequencyWeight, categoryWeight)) { throw SpeciesWeightComputingException.forIncoherentCategoryWeight(getSpeciesWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -410,7 +409,7 @@ public class WeightComputingService extends AbstractTuttiService { result = categoryWeight; } } - if (Weights.isNullOrZero(result)) { + if (WeightUnit.KG.isNullOrZero(result)) { throw SpeciesWeightComputingException.forNoWeight(decorateSpecies(batch.getSpecies()), getCategoryLabel(batch.getSampleCategoryId()), @@ -479,7 +478,7 @@ public class WeightComputingService extends AbstractTuttiService { if (categoryWeight == null) { batch.setSampleCategoryComputedWeight(sum); - } else if (Weights.isSmallerWeight(categoryWeight, sum)) { + } else if (WeightUnit.KG.isSmallerThan(categoryWeight, sum)) { throw BenthosWeightComputingException.forIncoherentParentCategoryWeight(getBenthosWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -509,7 +508,7 @@ public class WeightComputingService extends AbstractTuttiService { if (categoryWeight == null && rowWeight != null) { // throw new TuttiBusinessException(t("tutti.service.operations.computeWeights.error.incoherentRowWeightCategory")); - } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { + } else if (rowWeight != null && frequencyWeight != null && WeightUnit.KG.isNotEquals(rowWeight, frequencyWeight)) { throw BenthosWeightComputingException.forIncoherentRowWeightFrequency(getBenthosWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -525,11 +524,11 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(frequencyWeight); result = frequencyWeight; - } else if (frequencyWeight != null && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { + } else if (frequencyWeight != null && WeightUnit.KG.isNotEquals(frequencyWeight, categoryWeight)) { // if the weight of the frequencies is different from the category // weight, then set the weight of the sample - if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { + if (WeightUnit.KG.isGreaterThan(frequencyWeight, categoryWeight)) { throw BenthosWeightComputingException.forIncoherentCategoryWeight(getBenthosWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -556,7 +555,7 @@ public class WeightComputingService extends AbstractTuttiService { result = categoryWeight; } } - if (Weights.isNullOrZero(result)) { + if (WeightUnit.KG.isNullOrZero(result)) { throw BenthosWeightComputingException.forNoWeight(decorateSpecies(batch.getSpecies()), getCategoryLabel(batch.getSampleCategoryId()), @@ -579,7 +578,7 @@ public class WeightComputingService extends AbstractTuttiService { for (int i = 0; i < children.size(); i++) { MarineLitterBatch batch = children.get(i); - if (checkWeight && Weights.isNullOrZero(batch.getWeight())) { + if (checkWeight && WeightUnit.KG.isNullOrZero(batch.getWeight())) { throw MarineLitterWeightComputingException.forNoWeight(i); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.