This is an automated email from the git hooks/post-receive script. New commit to branch feature/7537 in repository tutti. See http://git.codelutin.com/tutti.git commit 04e34ded47b1b1d0b34e44f9f50b2d34dcbdc06a Author: Kevin Morin <morin@codelutin.com> Date: Fri Sep 18 16:37:00 2015 +0200 fixes #7537 [IMPORT BIGFIN] gestion des poids --- .../service/util/BatchPersistenceHelper.java | 4 +- .../tutti/service/bigfin/BigfinImportService.java | 46 ++++++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java index e8d5e11..4be8565 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java @@ -352,8 +352,8 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { if (!sampleCategoryId.equals(PmfmId.SORTED_UNSORTED.getValue())) { throw new DataIntegrityViolationException(MessageFormat.format( "A species or benthos batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", - sampleCategoryId, - PmfmId.SORTED_UNSORTED.getValue())); + PmfmId.SORTED_UNSORTED.getValue(), + sampleCategoryId)); } Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(sampleCategoryValue); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/bigfin/BigfinImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/bigfin/BigfinImportService.java index 92c8e33..d45a932 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/bigfin/BigfinImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/bigfin/BigfinImportService.java @@ -27,7 +27,9 @@ package fr.ifremer.tutti.service.bigfin; import com.google.common.base.Charsets; import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Collections2; import com.google.common.collect.ListMultimap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; @@ -364,9 +366,13 @@ public class BigfinImportService extends AbstractTuttiService { category.getPmfmId(), caracteristic, parentBatch != null ? parentBatch.getId() : null); + // useful to be able to save the batch later in the frequency creation + batch.setParentBatch(parentBatch); } } else { + // useful to be able to save the batch later in the frequency creation + batch.setFishingOperation(commonParameter.getOperation()); List<SpeciesBatchFrequency> frequencies = persistenceService.getAllSpeciesBatchFrequency(batch.getId()); batchHasFrequencies = CollectionUtils.isNotEmpty(frequencies); } @@ -499,6 +505,29 @@ public class BigfinImportService extends AbstractTuttiService { weightsByLengthStep.put(lengthStep, weight); } + // tous les poids du batch + Collection<Float> weightValues = weightsByLengthStep.values(); + int weightValuesSize = weightValues.size(); + + // poids non nuls du batch + Collection<Float> notNullWeights = Collections2.filter(weightValues, new Predicate<Float>() { + @Override + public boolean apply(Float input) { + return input != null; + } + }); + int notNullWeightsSize = notNullWeights.size(); + + // si présence d'une seule valeur, mettre cette valeur dans le champ "Poids sous échantillon" + if (notNullWeightsSize == 1) { + float weight = CollectionUtils.get(notNullWeights, 0); + batch.setWeight(weight); + persistenceService.saveSpeciesBatch(batch); + } + + // si présence de plusieurs valeurs et aucune vide, renseigner les champs "Poids Observé" en face des classes de taille + boolean importWeights = weightValuesSize == notNullWeightsSize; + List<SpeciesBatchFrequency> frequencies = new ArrayList<>(); for (Float lengthStep : weightsByLengthStep.keySet()) { SpeciesBatchFrequency frequency = SpeciesBatchFrequencys.newSpeciesBatchFrequency(); @@ -511,16 +540,17 @@ public class BigfinImportService extends AbstractTuttiService { Collection<Float> weights = weightsByLengthStep.get(lengthStep); frequency.setNumber(weights.size()); - Float totalWeight = 0f; - for (Float weight : weights) { - if (weight != null) { + if (importWeights) { + // all the weights are not null + float totalWeight = 0f; + for (float weight : weights) { totalWeight += weight; } - } - if (totalWeight > 0f) { - // convert grams to kilograms - totalWeight = Weights.roundKiloGram(totalWeight / 1000); - frequency.setWeight(totalWeight); + if (totalWeight > 0f) { + // convert grams to kilograms + totalWeight = Weights.roundKiloGram(totalWeight / 1000); + frequency.setWeight(totalWeight); + } } } return frequencies; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.