This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository echobase. See https://gitlab.nuiton.org/codelutin/echobase.git commit 68d3b25b96ac6d181a0a7367fda319186e4f32b2 Author: Jean Couteau <jean.couteau@gmail.com> Date: Tue Mar 6 10:35:03 2018 +0100 refs #9685 : fixes biotic ICES export fixes #9735 fixes #9734 fixes #9714 --- .../service/atlantos/xml/XmlBioticExport.java | 253 ++++++++++++--------- 1 file changed, 148 insertions(+), 105 deletions(-) diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java index 1cb14ba2..1b711e16 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java @@ -66,9 +66,23 @@ public class XmlBioticExport implements EchoBaseService { int index = 1; Collection<Operation> operations = voyage.getOperations(vessel); for (Operation operation : operations) { + Collection<Sample> samples = operation.getSample(); - // EXPORT HAUL - exportHaul(operation, index++, xmlCruise); + Boolean exportHaul=false; + + //Export Haul only if it contains samples + for (Sample sample : samples) { + SpeciesCategory category = sample.getSpeciesCategory(); + //FIXME jcouteau : pour les tests. En prod, il faut que ça pète si null -> données non valides alors que export de données valides uniquement + //if (category != null) { + if (category.getSpecies().getIcesExport() != null && category.getSpecies().getIcesExport()) { + // EXPORT HAUL + exportHaul = true; + exportHaul(operation, index++, xmlCruise); + break; + } + //} + } //Map with all the totals with no subsamples - key : code#cat Map<String,Sample> totals = new HashMap<>(); @@ -91,7 +105,6 @@ public class XmlBioticExport implements EchoBaseService { //Map with all the subsampledWeight - key : code#cat Map<String,Float> subsampledWeights = new HashMap<>(); - Collection<Sample> samples = operation.getSample(); for (Sample sample : samples) { @@ -102,116 +115,119 @@ public class XmlBioticExport implements EchoBaseService { //FIXME jcouteau : pour les tests. En prod, il faut que ça pète si null -> données non valides alors que export de données valides uniquement //if (category != null) { - //Compute code#cat key - Species species = category.getSpecies(); - String code = species.getBaracoudaCode(); - String categoryName = ""; - if (category.getSizeCategory() != null) { - categoryName = category.getSizeCategory().getName(); - } - String codeCatKey = code + "#" + categoryName; - - if ("Total".equals(name)) { - //Add sample to totals list if no subsamples (yet) - if (subsamples.get(codeCatKey) == null) { - totals.put(codeCatKey, sample); - } - - //Add sample weight to speciesCategoryWeight - Float weight = speciesCategoryWeights.get(codeCatKey); - if (weight == null) { - weight = 0f; - } - - Float sampleWeight = sample.getSampleWeight(); - if (sampleWeight != null) { - weight += sampleWeight; - } - speciesCategoryWeights.put(codeCatKey, weight); - - //Add sample number to speciesCategoryNumber - Integer number = speciesCategoryNumbers.get(codeCatKey); - if (number == null) { - number = 0; - } - - Integer numberSampled = sample.getNumberSampled(); - if (numberSampled != null) { - number += numberSampled; - } - speciesCategoryNumbers.put(codeCatKey, number); - - } else if ("Subsample".equals(name)) { + if (category.getSpecies().getIcesExport() != null && category.getSpecies().getIcesExport()) { - //Get back sample datas - Map<String, String> sampleDataValues = getSampleDataValues(sample); - - // get back weight at length for this subsample - String weightAtLength = sampleDataValues.get(SampleDataTypeImpl.WEIGHT_AT_LENGTHKG); - Float sampleWeight = null; - if (weightAtLength != null) { - sampleWeight = Float.parseFloat(weightAtLength); - } - - //add weightAtLength to the sum for this category - Float weightBySize = subsampledWeights.get(codeCatKey); - if (weightBySize == null) { - weightBySize = 0f; - } - if (sampleWeight != null) { - weightBySize += sampleWeight; - } - subsampledWeights.put(codeCatKey, weightBySize); - - //get back number at length for this subsample - String numberAtLength = sampleDataValues.get(SampleDataTypeImpl.NUMBER_AT_LENGTH); - Float sampleNumber = null; - if (numberAtLength != null) { - sampleNumber = Float.parseFloat(numberAtLength); - } - - //add numberAtLength to the sum for this category - Integer sumNumberAtLength = subsampledNumbers.get(codeCatKey); - if (sumNumberAtLength == null) { - sumNumberAtLength = 0; + //Compute code#cat key + Species species = category.getSpecies(); + String code = species.getBaracoudaCode(); + String categoryName = ""; + if (category.getSizeCategory() != null) { + categoryName = category.getSizeCategory().getName(); } - if (sampleNumber != null) { - sumNumberAtLength += sampleNumber.intValue(); - } - subsampledNumbers.put(codeCatKey, sumNumberAtLength); - - //Add subsample to the list - List<Sample> speciesCategorySubsamples = subsamples.get(codeCatKey); - if (speciesCategorySubsamples == null) { - speciesCategorySubsamples = new ArrayList<>(); + String codeCatKey = code + "#" + categoryName; + + if ("Total".equals(name)) { + //Add sample to totals list if no subsamples (yet) + if (subsamples.get(codeCatKey) == null) { + totals.put(codeCatKey, sample); + } + + //Add sample weight to speciesCategoryWeight + Float weight = speciesCategoryWeights.get(codeCatKey); + if (weight == null) { + weight = 0f; + } + + Float sampleWeight = sample.getSampleWeight(); + if (sampleWeight != null) { + weight += sampleWeight; + } + speciesCategoryWeights.put(codeCatKey, weight); + + //Add sample number to speciesCategoryNumber + Integer number = speciesCategoryNumbers.get(codeCatKey); + if (number == null) { + number = 0; + } + + Integer numberSampled = sample.getNumberSampled(); + if (numberSampled != null) { + number += numberSampled; + } + speciesCategoryNumbers.put(codeCatKey, number); + + } else if ("Subsample".equals(name)) { + + //Get back sample datas + Map<String, String> sampleDataValues = getSampleDataValues(sample); + + // get back weight at length for this subsample + String weightAtLength = sampleDataValues.get(SampleDataTypeImpl.WEIGHT_AT_LENGTHKG); + Float sampleWeight = null; + if (weightAtLength != null) { + sampleWeight = Float.parseFloat(weightAtLength); + } + + //add weightAtLength to the sum for this category + Float weightBySize = subsampledWeights.get(codeCatKey); + if (weightBySize == null) { + weightBySize = 0f; + } + if (sampleWeight != null) { + weightBySize += sampleWeight; + } + subsampledWeights.put(codeCatKey, weightBySize); + + //get back number at length for this subsample + String numberAtLength = sampleDataValues.get(SampleDataTypeImpl.NUMBER_AT_LENGTH); + Float sampleNumber = null; + if (numberAtLength != null) { + sampleNumber = Float.parseFloat(numberAtLength); + } + + //add numberAtLength to the sum for this category + Integer sumNumberAtLength = subsampledNumbers.get(codeCatKey); + if (sumNumberAtLength == null) { + sumNumberAtLength = 0; + } + if (sampleNumber != null) { + sumNumberAtLength += sampleNumber.intValue(); + } + subsampledNumbers.put(codeCatKey, sumNumberAtLength); + + //Add subsample to the list + List<Sample> speciesCategorySubsamples = subsamples.get(codeCatKey); + if (speciesCategorySubsamples == null) { + speciesCategorySubsamples = new ArrayList<>(); + } + speciesCategorySubsamples.add(sample); subsamples.put(codeCatKey, speciesCategorySubsamples); - } - speciesCategorySubsamples.add(sample); - //check if total present, if so, removes it - if (subsamples.get(codeCatKey) != null) { - totals.remove(codeCatKey); - } + //check if total present, if so, removes it + if (subsamples.get(codeCatKey) != null) { + totals.remove(codeCatKey); + } - } else if ("Individual".equals(name)) { + } else if ("Individual".equals(name)) { - //Get back sample datas - Map<String, String> sampleDataValues = getSampleDataValues(sample); + //Get back sample datas + Map<String, String> sampleDataValues = getSampleDataValues(sample); - //Get back lengthclass for individual, remove trailing .0 - String lengthClass = sampleDataValues.get("LTmm1"); - lengthClass = lengthClass.substring(0,lengthClass.indexOf(".")); + //Get back lengthclass for individual, remove trailing .0 + String lengthClass = sampleDataValues.get("LTmm1"); + lengthClass = lengthClass.substring(0, lengthClass.indexOf(".")); - String codeCatLCkey = codeCatKey+"#"+lengthClass; + String codeCatLCkey = codeCatKey + "#" + lengthClass; - //add individual to the list - List<Sample> lengthClassIndividuals = individuals.get(codeCatLCkey); - if (lengthClassIndividuals == null) { - lengthClassIndividuals = new ArrayList<>(); - individuals.put(codeCatLCkey, lengthClassIndividuals); - } - lengthClassIndividuals.add(sample); + //add individual to the list + List<Sample> lengthClassIndividuals = individuals.get(codeCatLCkey); + if (lengthClassIndividuals == null) { + lengthClassIndividuals = new ArrayList<>(); + individuals.put(codeCatLCkey, lengthClassIndividuals); + } + lengthClassIndividuals.add(sample); + } } //} } @@ -287,7 +303,9 @@ public class XmlBioticExport implements EchoBaseService { } } - xmlCruise.close("Haul"); + if (exportHaul) { + xmlCruise.close("Haul"); + } } xmlCruise.close("Cruise"); @@ -469,6 +487,7 @@ public class XmlBioticExport implements EchoBaseService { xml.create("SpeciesSex"); if (subsampledNumber != null && subsampledNumber != 0) { + //case catch of type subsample xml.create("SubsampledNumber", subsampledNumber); if (weightAtLength != null && subsampledWeight != null) { @@ -478,8 +497,32 @@ public class XmlBioticExport implements EchoBaseService { xml.create("SubsamplingFactor", 0); } + String subsampledWeightString = subsampledWeight.toString(); + //keep only 3 digits in decimal value for speciesCategoryWeight to prevent from rounds in calculus + if (subsampledWeightString.contains(".")){ + int dotIndex = subsampledWeightString.indexOf("."); + if (subsampledWeightString.length()>((dotIndex+3)+1)) { + subsampledWeightString = subsampledWeightString.substring(0, dotIndex + 3); + } + } + xml.create("SubsampleWeight", + subsampledWeightString); + } else { + //Case catch of type total + xml.create("SubsampledNumber", + speciesCategoryNumber); + if (weightAtLength != null && subsampledWeight != null) { + xml.create("SubsamplingFactor", + Float.parseFloat(weightAtLength) / speciesCategoryNumber); + } else { + xml.create("SubsamplingFactor", + 0); + } + + xml.create("SubsampleWeight", - subsampledWeight); + speciesCategoryWeight); + } if (lengthClassValue!= 0) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.