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 c886450c999a72becadbfe918c6c227c0200e731 Author: Julien Ruchaud <julien.ruchaud@debux.org> Date: Thu Nov 10 15:26:47 2016 +0100 #8173 Corrections --- .../echobase/services/csv/EchoBaseCsvUtil.java | 2 +- .../service/atlantos/xml/VocabularyExport.java | 66 +++++++++++----------- .../service/atlantos/xml/XmlAccousticExport.java | 15 +++-- .../service/atlantos/xml/XmlBioticExport.java | 32 ++++++----- 4 files changed, 57 insertions(+), 58 deletions(-) diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/EchoBaseCsvUtil.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/EchoBaseCsvUtil.java index 8034ec1..0954ba5 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/EchoBaseCsvUtil.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/EchoBaseCsvUtil.java @@ -67,7 +67,7 @@ public class EchoBaseCsvUtil extends TopiaCsvCommons { public static final String CELLULE_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSSS"; public static final String ISO8611_DATE_FORMAT = "YYYY-MM-dd"; - public static final String ISO8611_DATETIME_FORMAT = "YYYY-MM-dd"; + public static final String ISO8611_DATETIME_FORMAT = "YYYY-MM-dd HH:mm"; public static final ValueParserFormatter<Date> IMPORT_DAY_TIME_ECHOBASE = new DateValue(CELLULE_DATE_FORMAT); public static final ValueParserFormatter<Date> ISO8611_DATE_FORMATTER = new DateValue(ISO8611_DATE_FORMAT); diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/VocabularyExport.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/VocabularyExport.java index ae9eb22..70a85e8 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/VocabularyExport.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/VocabularyExport.java @@ -25,7 +25,9 @@ import fr.ifremer.echobase.services.EchoBaseService; import fr.ifremer.echobase.services.service.UserDbPersistenceService; import java.io.IOException; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.Map; +import java.util.Set; import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; @@ -40,6 +42,7 @@ public class VocabularyExport implements EchoBaseService { protected Map<String, String> vocabularyTags; protected Map<String, String> vocabulary; + protected Map<String, Set<String>> cache; protected XmlWriter writer; @@ -47,6 +50,7 @@ public class VocabularyExport implements EchoBaseService { this.writer = writer; this.vocabularyTags = new HashMap<String, String>(); + this.cache = new HashMap<>(); this.vocabularyTags.put("AC_Survey", "Survey"); this.vocabularyTags.put("ISO_3166", "Country"); @@ -94,11 +98,28 @@ public class VocabularyExport implements EchoBaseService { this.vocabulary = persistenceService.getVocabulary(); } - public void begin() throws IOException { + public void generate() throws IOException { this.writer.open("Vocabulary"); - } - - public void end() throws IOException { + + for (Map.Entry<String, Set<String>> entry : this.cache.entrySet()) { + String tag = entry.getKey(); + Set<String> codes = entry.getValue(); + + this.writer.open(tag); + + for (String code : codes) { + String prefix = StringUtils.substringBeforeLast(code, "_"); + String value = StringUtils.substringAfterLast(code, "_"); + + this.writer.create("Code", + "ID", code, + "CodeType", "http://acoustic.ices.dk/Services/Schema/XML/" + prefix + ".xml", + value); + } + + this.writer.close(tag); + } + this.writer.close("Vocabulary"); } @@ -125,38 +146,15 @@ public class VocabularyExport implements EchoBaseService { protected void addVocabulary(String code) throws IOException { String prefix = StringUtils.substringBeforeLast(code, "_"); - String value = StringUtils.substringAfterLast(code, "_"); + String tag = this.vocabularyTags.get(prefix); - String tag = this.vocabularyTags.remove(prefix); - if (tag != null) { - - // Only WeightUnit contains two values - if (tag.equals("WeightUnit")) { - this.writer.open(tag); - - this.writer.create("Code", - "ID", "AC_WeightUnit_kg", - "CodeType", "http://acoustic.ices.dk/Services/Schema/XML/" + prefix + ".xml", - "kg"); - this.writer.create("Code", - "ID", "AC_WeightUnit_gr", - "CodeType", "http://acoustic.ices.dk/Services/Schema/XML/" + prefix + ".xml", - "gr"); - - this.writer.close(tag); - - } else { - - this.writer.open(tag); - - this.writer.create("Code", - "ID", code, - "CodeType", "http://acoustic.ices.dk/Services/Schema/XML/" + prefix + ".xml", - value); - - this.writer.close(tag); - } + Set<String> codes = this.cache.get(tag); + if (codes == null) { + codes = new LinkedHashSet<>(); + this.cache.put(tag, codes); } + + codes.add(code); } } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlAccousticExport.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlAccousticExport.java index 1d73ab6..2df86b2 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlAccousticExport.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlAccousticExport.java @@ -58,7 +58,6 @@ public class XmlAccousticExport implements EchoBaseService { public void doExport(Voyage voyage, XmlWriter xmlHead, XmlWriter xmlVoca, XmlWriter xmlCruise) throws IOException { boolean exportCruiseDone = false; vocabulary.init(xmlVoca); - vocabulary.begin(); // EXPORT ACCOUSTIC xmlHead.append("<?xml version=\"1.0\"?>\n"); @@ -147,7 +146,7 @@ public class XmlAccousticExport implements EchoBaseService { } xmlCruise.close("Acoustic"); - vocabulary.end(); + vocabulary.generate(); } public void exportInstrument(AcousticInstrument instrument, XmlWriter xml) throws IOException { @@ -307,7 +306,7 @@ public class XmlAccousticExport implements EchoBaseService { }); String prefix = "Start"; - if (!dataValues.containsKey("TimeStart")) { + if (!dataValues.containsKey("LatitudeStart")) { prefix = "End"; } @@ -356,15 +355,15 @@ public class XmlAccousticExport implements EchoBaseService { depthRefSurfaceMeta = "DepthRefSurfaceEnd"; } - Float upperDepth = 10f; + Float lowerDepth = 10f; Data depthRefSurfaceData = dataValues.get(depthRefSurfaceMeta); - Float lowerDepth = depthRefSurfaceData != null ? Float.parseFloat(depthRefSurfaceData.getDataValue()) : 0f; - if (lowerDepth >= 50) { + Float upperDepth = depthRefSurfaceData != null ? Float.parseFloat(depthRefSurfaceData.getDataValue()) : 0f; + if (upperDepth >= 50) { if (result.getCategory().getEchotypeLabel().equals("D4")) { - lowerDepth = 30f; - } else { upperDepth = 30f; + } else { + lowerDepth = 30f; } } 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 50c2457..0d910f0 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 @@ -59,7 +59,6 @@ public class XmlBioticExport implements EchoBaseService { xmlVoca.open("Biotic", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); - vocabulary.begin(); exportCruise(voyage, vessel, xmlCruise); @@ -167,7 +166,7 @@ public class XmlBioticExport implements EchoBaseService { xmlCruise.close("Cruise"); xmlCruise.close("Biotic"); - vocabulary.end(); + vocabulary.generate(); } public void exportCruise(Voyage voyage, Vessel vessel, XmlWriter xml) throws IOException { @@ -180,9 +179,9 @@ public class XmlBioticExport implements EchoBaseService { xml.create("Platform", "IDREF", vocabulary.getVocabularyCode(vessel.getCode(), "SHIPC_35HT")); xml.create("StartDate", - EchoBaseCsvUtil.ISO8611_DATE_FORMATTER.format(voyage.getStartDate())); + EchoBaseCsvUtil.ISO8611_DATETIME_FORMATTER.format(voyage.getStartDate())); xml.create("EndDate", - EchoBaseCsvUtil.ISO8611_DATE_FORMATTER.format(voyage.getEndDate())); + EchoBaseCsvUtil.ISO8611_DATETIME_FORMATTER.format(voyage.getEndDate())); xml.create("Organisation", "IDREF", vocabulary.getVocabularyCode(voyage.getMission().getInstitution(), "EDMO_541")); xml.create("LocalID", @@ -202,10 +201,10 @@ public class XmlBioticExport implements EchoBaseService { String gearCode = operation.getGear().getGearCode(); OperationMetadataValue meanWaterDepthMeta = operationMetadatas.get("MeanWaterDepth"); - float meanWaterDepth = Float.parseFloat(meanWaterDepthMeta.getDataValue()); + Float meanWaterDepth = Float.parseFloat(meanWaterDepthMeta.getDataValue()); - float minTrawlDepth; - float maxTrawlDepth; + int minTrawlDepth; + int maxTrawlDepth; String depthStratum = operation.getDepthStratum().getId(); if (depthStratum.equals("SURF")) { @@ -213,7 +212,7 @@ public class XmlBioticExport implements EchoBaseService { maxTrawlDepth = 30; } else { - minTrawlDepth = meanWaterDepth; + minTrawlDepth = meanWaterDepth.intValue(); maxTrawlDepth = minTrawlDepth; switch (gearCode) { @@ -271,7 +270,7 @@ public class XmlBioticExport implements EchoBaseService { xml.create("MaxTrawlDepth", maxTrawlDepth); xml.create("BottomDepth", - meanWaterDepth); + meanWaterDepth.intValue()); xml.create("Distance", distance); xml.create("Netopening", @@ -336,10 +335,13 @@ public class XmlBioticExport implements EchoBaseService { lengthClassValue = Float.parseFloat(lengthClass) * 10; } + String numberAtLength = sampleDataValues.get(SampleDataTypeImpl.NUMBER_AT_LENGTH); + String weightAtLength = sampleDataValues.get(SampleDataTypeImpl.WEIGHT_AT_LENGTHKG); + xml.create("DataType", "IDREF", vocabulary.getVocabularyCode("AC_CatchDataType_R")); xml.create("SpeciesCode", - "IDREF", "SpecWoRMS_" + category.getSpecies().getWormsCode()); + "IDREF", vocabulary.getVocabularyCode("SpecWoRMS_" + category.getSpecies().getWormsCode())); xml.create("SpeciesValidity", "IDREF", vocabulary.getVocabularyCode("AC_SpeciesValidity_1")); xml.create("SpeciesTotalNumber", @@ -363,13 +365,13 @@ public class XmlBioticExport implements EchoBaseService { xml.create("LengthCode", "IDREF", vocabulary.getVocabularyCode("AC_LengthCode_mm")); xml.create("LengthClass", - lengthClassValue); + lengthClassValue.intValue()); xml.create("LengthType", "IDREF", vocabulary.getVocabularyCode("AC_LengthMeasurementType_1")); - xml.create("NumberAtLength", - sampleDataValues.get(SampleDataTypeImpl.NUMBER_AT_LENGTH)); - xml.create("WeightAtLength", - sampleDataValues.get(SampleDataTypeImpl.WEIGHT_AT_LENGTHKG)); + xml.create("NumberAtLength", + numberAtLength != null ? numberAtLength : 0); + xml.create("WeightAtLength", + weightAtLength != null ? weightAtLength : 0); } public void exportBiology(Sample individualSample, XmlWriter xml) throws IOException { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.