branch develop updated (828df0a -> eddc84e)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository echobase. See https://gitlab.nuiton.org/codelutin/echobase.git from 828df0a ref #8173, begin export to xml instead of csv new eddc84e ref #8173, add export biotic The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit eddc84e050b997a4294e11f8be4858da5a341deb Author: Julien Ruchaud <julien.ruchaud@debux.org> Date: Tue Oct 4 16:31:29 2016 +0200 ref #8173, add export biotic Summary of changes: .../service/atlantos/ExportAtlantosService.java | 16 +- .../service/atlantos/xml/XmlAccousticExport.java | 88 ++++++- .../service/atlantos/xml/XmlBioticExport.java | 252 +++++++++++++++++++++ .../atlantos/ExportAtlantosServiceTest.java | 1 - 4 files changed, 351 insertions(+), 6 deletions(-) create mode 100644 echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 eddc84e050b997a4294e11f8be4858da5a341deb Author: Julien Ruchaud <julien.ruchaud@debux.org> Date: Tue Oct 4 16:31:29 2016 +0200 ref #8173, add export biotic --- .../service/atlantos/ExportAtlantosService.java | 16 +- .../service/atlantos/xml/XmlAccousticExport.java | 88 ++++++- .../service/atlantos/xml/XmlBioticExport.java | 252 +++++++++++++++++++++ .../atlantos/ExportAtlantosServiceTest.java | 1 - 4 files changed, 351 insertions(+), 6 deletions(-) diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosService.java index 1421404..8b3b7b4 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosService.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosService.java @@ -48,6 +48,7 @@ import fr.ifremer.echobase.services.service.atlantos.row.DataProcessingExportRow import fr.ifremer.echobase.services.service.atlantos.row.HaulExportRow; import fr.ifremer.echobase.services.service.atlantos.row.InstrumentExportRow; import fr.ifremer.echobase.services.service.atlantos.xml.XmlAccousticExport; +import fr.ifremer.echobase.services.service.atlantos.xml.XmlBioticExport; import fr.ifremer.echobase.services.service.atlantos.xml.XmlWriter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -82,12 +83,15 @@ public class ExportAtlantosService extends EchoBaseServiceSupport { @Inject private XmlAccousticExport xmlAccousticExport; + @Inject + private XmlBioticExport xmlBioticExport; + public void doXmlExport(ExportAtlantosConfiguration model) throws IOException { Preconditions.checkNotNull(model); Preconditions.checkNotNull(model.getVoyageId()); - int nbSteps = 1; + int nbSteps = 2; model.setNbSteps(nbSteps); Voyage voyage = persistenceService.getVoyage(model.getVoyageId()); @@ -100,12 +104,22 @@ public class ExportAtlantosService extends EchoBaseServiceSupport { SimpleDateFormat formatter = new SimpleDateFormat("YYYY"); String year = formatter.format(voyage.getStartDate()); + // Export Accoustic Path output = Paths.get(basePath, "Acoustic_" + year + name + ".xml"); FileWriter file = new FileWriter(output.toFile()); XmlWriter xml = new XmlWriter(file); xmlAccousticExport.doExport(voyage, xml); + file.flush(); + + model.incrementsProgress(); + + // Export Biotic + output = Paths.get(basePath, "Biotic_" + year + name + ".xml"); + file = new FileWriter(output.toFile()); + xml = new XmlWriter(file); + xmlBioticExport.doExport(voyage, xml); file.flush(); model.incrementsProgress(); 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 980ba7d..996afc2 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 @@ -1,18 +1,26 @@ package fr.ifremer.echobase.services.service.atlantos.xml; +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; import fr.ifremer.echobase.entities.data.Cell; import fr.ifremer.echobase.entities.data.Data; import fr.ifremer.echobase.entities.data.DataAcquisition; import fr.ifremer.echobase.entities.data.DataProcessing; +import fr.ifremer.echobase.entities.data.GearMetadataValue; import fr.ifremer.echobase.entities.data.Transect; import fr.ifremer.echobase.entities.data.Transit; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.entities.references.AcousticInstrument; import fr.ifremer.echobase.entities.references.Calibration; +import fr.ifremer.echobase.entities.references.DataMetadata; +import fr.ifremer.echobase.entities.references.DataMetadatas; import fr.ifremer.echobase.services.EchoBaseService; import fr.ifremer.echobase.services.csv.EchoBaseCsvUtil; import java.io.IOException; import java.util.Collection; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; /* * #%L @@ -83,17 +91,23 @@ public class XmlAccousticExport implements EchoBaseService { exportCruiseDone = true; } - // EXPORT LOG - // EXPORT SAMPLE - Collection<Cell> cells = dataProcessing.getCell(); for (Cell cell : cells) { + // EXPORT LOG + exportLog(cell, xml); Collection<Data> datas = cell.getData(); for (Data data : datas) { + // EXPORT SAMPLE + exportSample(cell, xml); - // EXPORT DATA + // EXPORT DATA + exportData(data, xml); + + xml.close("Sample"); } + + xml.close("Log"); } } } @@ -246,4 +260,70 @@ public class XmlAccousticExport implements EchoBaseService { voyage.getTopiaId()); } + public void exportLog(Cell cell, XmlWriter xml) throws IOException { + xml.open("Log"); + + Collection<Data> datas = cell.getData(); + ImmutableMap<String, Data> dataValues = Maps.uniqueIndex(datas, new Function<Data, String>() { + @Override + public String apply(Data value) { + return value.getDataMetadata().getName(); + } + }); + + String prefix = "Start"; + if (!dataValues.containsKey("TimeStart")) { + prefix = "End"; + } + + xml.create("Distance"); + xml.create("Time", + StringUtils.substring(dataValues.get("Time" + prefix).getDataValue(), 0, -8)); + xml.create("Latitude", + dataValues.get("Latitude" + prefix).getDataValue()); + xml.create("Longitude", + dataValues.get("Longitude" + prefix).getDataValue()); + xml.create("Origin", + "IDREF", "AC_LogOrigin_" + prefix); + } + + public void exportSample(Cell cell, XmlWriter xml) throws IOException { + xml.open("Sample"); + + Collection<Calibration> calibration = cell.getDataProcessing().getDataAcquisition().getAcousticInstrument().getCalibration(); + + xml.create("ChannelDepthUpper"); + xml.create("ChannelDepthLower"); + xml.create("PingAxisInterval"); + xml.create("PingAxisIntervalType", + "IDREF", "AC_PingAxisIntervalType_time"); + xml.create("PingAxisIntervalUnit", + "IDREF", "AC_PingAxisIntervalUnit_sec"); + xml.create("SvThreshhold"); + xml.create("Instrument", + "IDREF", cell.getDataProcessing().getDataAcquisition().getAcousticInstrument().getTopiaId()); + xml.create("Calibration", + "IDREF", ""); + xml.create("DataAcquisition", + "IDREF", cell.getDataProcessing().getDataAcquisition().getTopiaId()); + xml.create("DataProcessing", + "IDREF", cell.getDataProcessing().getTopiaId()); + xml.create("PingAxisIntervalOrigin", + "IDREF", "AC_PingAxisIntervalOrigin_start"); + } + + public void exportData(Data data, XmlWriter xml) throws IOException { + xml.open("Data"); + + xml.create("SaCategory", + "IDREF", ""); + xml.create("Type", + "IDREF", ""); + xml.create("Unit", + "IDREF", ""); + xml.create("Value", + data.getDataValue()); + + xml.close("Data"); + } } 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 new file mode 100644 index 0000000..e47329a --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlBioticExport.java @@ -0,0 +1,252 @@ +package fr.ifremer.echobase.services.service.atlantos.xml; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import fr.ifremer.echobase.entities.data.GearMetadataValue; +import fr.ifremer.echobase.entities.data.Operation; +import fr.ifremer.echobase.entities.data.OperationMetadataValue; +import fr.ifremer.echobase.entities.data.Sample; +import fr.ifremer.echobase.entities.data.SampleData; +import fr.ifremer.echobase.entities.data.Voyage; +import fr.ifremer.echobase.entities.references.Species; +import fr.ifremer.echobase.entities.references.SpeciesCategory; +import fr.ifremer.echobase.services.EchoBaseService; +import fr.ifremer.echobase.services.csv.EchoBaseCsvUtil; +import fr.ifremer.echobase.services.service.UserDbPersistenceService; +import java.io.IOException; +import java.util.Collection; +import javax.inject.Inject; + +/* + * #%L + * EchoBase :: Services + * %% + * Copyright (C) 2011 - 2014 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +/** + * @author Julien Ruchaud - ruchaud@codelutin.com + * @since 4 + */ +public class XmlBioticExport implements EchoBaseService { + + public void doExport(Voyage voyage, XmlWriter xml) throws IOException { + + // EXPORT BIOTIC + xml.open("Biotic", + "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", + "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); + + exportCruise(voyage, xml); + + Collection<Operation> operations = voyage.getAllOperations(); + for (Operation operation : operations) { + + // EXPORT HAUL + exportHaul(operation, xml); + + Collection<Sample> samples = operation.getSample(); + for (Sample sample : samples) { + + // EXPORT CATCH + exportCatch(sample, xml); + + Collection<SampleData> datas = sample.getSampleData(); + for (SampleData data : datas) { + + // EXPORT BIOLOGY + exportBiology(data, xml); + } + xml.close("Catch"); + } + xml.close("Haul"); + } + + xml.close("Cruise"); + xml.close("Biotic"); + } + + public void exportCruise(Voyage voyage, XmlWriter xml) throws IOException { + xml.open("Cruise"); + + xml.create("Survey", + "IDREF", "AC_Survey_HERAS"); + xml.create("Country", + "IDREF", "ISO_3166_DK"); + xml.create("Platform", + "IDREF", "SHIPC_26D4"); + xml.create("StartDate", + EchoBaseCsvUtil.ISO8611_DATE_FORMATTER.format(voyage.getStartDate())); + xml.create("EndDate", + EchoBaseCsvUtil.ISO8611_DATE_FORMATTER.format(voyage.getEndDate())); + xml.create("Organisation", + "IDREF", "EDMO_2195"); + xml.create("LocalID", + voyage.getTopiaId()); + } + + public void exportHaul(Operation operation, XmlWriter xml) throws IOException { + xml.open("Haul"); + + Collection<GearMetadataValue> gearMetadataValues = operation.getGearMetadataValue(); + ImmutableMap<String, GearMetadataValue> gearMetadatas = Maps.uniqueIndex(gearMetadataValues, new Function<GearMetadataValue, String>() { + @Override + public String apply(GearMetadataValue value) { + return value.getGearMetadata().getName(); + } + }); + + Collection<OperationMetadataValue> operationMetadataValues = operation.getOperationMetadataValue(); + ImmutableMap<String, OperationMetadataValue> operationMetadatas = Maps.uniqueIndex(operationMetadataValues, new Function<OperationMetadataValue, String>() { + @Override + public String apply(OperationMetadataValue value) { + return value.getOperationMetadata().getName(); + } + }); + + xml.create("Gear", + "IDREF", operation.getTopiaId()); + xml.create("Number"); + xml.create("StationName"); + xml.create("StartTime", + EchoBaseCsvUtil.ISO8611_DATE_FORMATTER.format(operation.getGearShootingStartTime())); + xml.create("Duration", + (int)((operation.getGearShootingEndTime().getTime() - operation.getGearShootingStartTime().getTime()) / (1000 * 60))); + xml.create("Validity", + "IDREF", ""); + xml.create("StartLatitude", + operation.getGearShootingStartLatitude()); + xml.create("StartLongitude", + operation.getGearShootingStartLongitude()); + xml.create("StopLatitude", + operation.getGearShootingEndLatitude()); + xml.create("StopLongitude", + operation.getGearShootingEndLongitude()); + xml.create("StatisticalRectangle"); + xml.create("MinTrawlDepth"); + xml.create("MaxTrawlDepth"); + xml.create("BottomDepth"); + xml.create("Distance"); + xml.create("Netopening"); + xml.create("CodendMesh"); + xml.create("SweepLength"); + xml.create("GearExceptions", + "IDREF", ""); + xml.create("DoorType", + "IDREF", ""); + xml.create("WarpLength"); + xml.create("WarpDiameter"); + xml.create("WarpDensity"); + xml.create("DoorSurface"); + xml.create("DoorWeight"); + xml.create("DoorSpread"); + xml.create("WingSpread"); + xml.create("Buoyancy"); + xml.create("KiteArea"); + xml.create("GroundRopeWeight"); + xml.create("Rigging"); + xml.create("Tickler"); + xml.create("HydrographicStationID"); + xml.create("TowDirection"); + xml.create("SpeedGround"); + xml.create("SpeedWater"); + xml.create("WindDirection"); + xml.create("WindSpeed"); + xml.create("SwellDirection"); + xml.create("SwellHeight"); + xml.create("LogDistance"); + } + + public void exportCatch(Sample sample, XmlWriter xml) throws IOException { + xml.open("Catch"); + + SpeciesCategory category = sample.getSpeciesCategory(); + boolean hasCategory = category != null; + + boolean hasSpecies = false; + Species species = null; + if (hasCategory) { + species = category.getSpecies(); + hasSpecies = species != null; + } + + xml.create("DataType", + "IDREF", "AC_CatchDataType_R"); + xml.create("SpeciesCode", + "IDREF", hasSpecies ? species.getBaracoudaCode() : null); + xml.create("SpeciesValidity", + "IDREF", ""); + xml.create("SpeciesTotalNumber", + sample.getNumberSampled()); + xml.create("WeightUnit", + "IDREF", "AC_WeightUnit_kg"); + xml.create("SpeciesTotalWeight", + sample.getSampleWeight()); + xml.create("SpeciesCategory", + "IDREF", hasSpecies ? species.getTaxonCode() : null); + xml.create("SpeciesSex", + "IDREF", hasCategory ? category.getSexCategoryLabel() : null); + xml.create("CategoryWeight"); + xml.create("SubsampledNumber"); + xml.create("SubsamplingFactor"); + xml.create("SubsampleWeight"); + xml.create("LengthCode", + "IDREF", "AC_LengthCode_mm"); + xml.create("LengthClass", + hasCategory ? category.getLengthClass() : null); + xml.create("LengthType", + "IDREF", "AC_LengthMeasurementType_1"); + xml.create("NumberAtLength"); + xml.create("WeightAtLength"); + } + + public void exportBiology(SampleData data, XmlWriter xml) throws IOException { + xml.open("Biology"); + + xml.create("StockCode", + "IDREF", ""); + xml.create("FishID"); + xml.create("LengthCode", + "IDREF", ""); + xml.create("IndividualLength"); + xml.create("WeightUnit", + "IDREF", ""); + xml.create("IndividualWeight"); + xml.create("IndividualSex", + "IDREF", ""); + xml.create("IndividualMaturity", + "IDREF", ""); + xml.create("MaturityScale", + "IDREF", ""); + xml.create("IndividualAge", + "IDREF", ""); + xml.create("AgePlusGroup", + "IDREF", ""); + xml.create("AgeSource", + "IDREF", ""); + xml.create("GeneticSamplingFlag", + "IDREF", ""); + xml.create("StomachSamplingFlag", + "IDREF", ""); + xml.create("ParasiteSamplingFlag", + "IDREF", ""); + xml.create("IndividualVertebraeCount"); + + xml.close("Biology"); + } +} diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosServiceTest.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosServiceTest.java index 2fb90f1..4061776 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosServiceTest.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosServiceTest.java @@ -24,7 +24,6 @@ package fr.ifremer.echobase.services.service.atlantos; import fr.ifremer.echobase.services.EchoBaseTestServiceSupport; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import fr.ifremer.echobase.services.ImportDataFixtures; -import fr.ifremer.echobase.services.service.UserDbPersistenceService; import org.junit.Assert; import org.junit.Test; import org.nuiton.util.FileUtil; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm