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 828df0a90abc2e3717dfbe5f4d918e2f61c5af7f Author: Julien Ruchaud <julien.ruchaud@debux.org> Date: Tue Oct 4 11:49:15 2016 +0200 ref #8173, begin export to xml instead of csv --- .../echobase/services/csv/EchoBaseCsvUtil.java | 2 + .../service/atlantos/ExportAtlantosService.java | 35 +++ .../atlantos/row/DataProcessingExportRow.java | 1 - .../service/atlantos/xml/XmlAccousticExport.java | 249 +++++++++++++++++++++ .../services/service/atlantos/xml/XmlWriter.java | 91 ++++++++ .../atlantos/ExportAtlantosServiceTest.java | 15 +- 6 files changed, 389 insertions(+), 4 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 c7ea5ab..8034ec1 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,9 +67,11 @@ 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 ValueParserFormatter<Date> IMPORT_DAY_TIME_ECHOBASE = new DateValue(CELLULE_DATE_FORMAT); public static final ValueParserFormatter<Date> ISO8611_DATE_FORMATTER = new DateValue(ISO8611_DATE_FORMAT); + public static final ValueParserFormatter<Date> ISO8611_DATETIME_FORMATTER = new DateValue(ISO8611_DATETIME_FORMAT); // public static final ValueParser<Date> IMPORT_DAY_TIME_ECHOBASE2 = new DateValue("dd/MM/yyyy HH:mm:ss.SSSS"); 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 1993f14..1421404 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 @@ -47,12 +47,15 @@ import fr.ifremer.echobase.services.service.atlantos.row.DataExportRow; 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.XmlWriter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Export; import javax.inject.Inject; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -76,6 +79,38 @@ public class ExportAtlantosService extends EchoBaseServiceSupport { @Inject private UserDbPersistenceService persistenceService; + @Inject + private XmlAccousticExport xmlAccousticExport; + + public void doXmlExport(ExportAtlantosConfiguration model) throws IOException { + + Preconditions.checkNotNull(model); + Preconditions.checkNotNull(model.getVoyageId()); + + int nbSteps = 1; + model.setNbSteps(nbSteps); + + Voyage voyage = persistenceService.getVoyage(model.getVoyageId()); + Preconditions.checkNotNull(voyage); + + File tempDirectory = model.getWorkingDirectory(); + String basePath = tempDirectory.getAbsolutePath(); + + String name = voyage.getName(); + SimpleDateFormat formatter = new SimpleDateFormat("YYYY"); + String year = formatter.format(voyage.getStartDate()); + + 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(); + } + public void doExport(ExportAtlantosConfiguration model) throws IOException { Preconditions.checkNotNull(model); diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/row/DataProcessingExportRow.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/row/DataProcessingExportRow.java index e77ec34..320911a 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/row/DataProcessingExportRow.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/row/DataProcessingExportRow.java @@ -1,6 +1,5 @@ package fr.ifremer.echobase.services.service.atlantos.row; -import fr.ifremer.echobase.entities.data.DataAcquisition; import fr.ifremer.echobase.entities.data.DataProcessing; /* 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 new file mode 100644 index 0000000..980ba7d --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlAccousticExport.java @@ -0,0 +1,249 @@ +package fr.ifremer.echobase.services.service.atlantos.xml; + +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.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.services.EchoBaseService; +import fr.ifremer.echobase.services.csv.EchoBaseCsvUtil; +import java.io.IOException; +import java.util.Collection; + +/* + * #%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 XmlAccousticExport implements EchoBaseService { + + public void doExport(Voyage voyage, XmlWriter xml) throws IOException { + boolean exportCruiseDone = false; + + // EXPORT ACCOUSTIC + xml.open("Acoustic", + "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance", + "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); + + Collection<Transit> transits = voyage.getTransit(); + for (Transit transit : transits) { + + Collection<Transect> transects = transit.getTransect(); + for (Transect transect : transects) { + + Collection<DataAcquisition> dataAcquisitions = transect.getDataAcquisition(); + for (DataAcquisition dataAcquisition : dataAcquisitions) { + + // EXPORT INSTRUMENT + AcousticInstrument acousticInstrument = dataAcquisition.getAcousticInstrument(); + this.exportInstrument(acousticInstrument, xml); + + // EXPORT CALIBRATION + Collection<Calibration> calibrations = acousticInstrument.getCalibration(); + for (Calibration calibration : calibrations) { + this.exportCalibration(calibration, xml); + } + + // EXPORT DATA ACQUISITION + exportDataAcquisition(dataAcquisition, xml); + + Collection<DataProcessing> dataProcessings = dataAcquisition.getDataProcessing(); + for (DataProcessing dataProcessing : dataProcessings) { + + // EXPORT DATA PROCESSING + exportDataProcessing(dataProcessing, xml); + + // EXPORT CRUISE + if (!exportCruiseDone) { + exportCruise(voyage, xml); + exportCruiseDone = true; + } + + // EXPORT LOG + // EXPORT SAMPLE + + Collection<Cell> cells = dataProcessing.getCell(); + for (Cell cell : cells) { + + Collection<Data> datas = cell.getData(); + for (Data data : datas) { + + // EXPORT DATA + } + } + } + } + } + } + + if (exportCruiseDone) { + xml.close("Cruise"); + } + + xml.close("Acoustic"); + } + + public void exportInstrument(AcousticInstrument instrument, XmlWriter xml) throws IOException { + xml.open("Instrument", + "ID", instrument.getTopiaId()); + + xml.create("Frequency", + instrument.getTransducerFrequency()); + xml.create("TransducerLocation", + "IDREF", instrument.getTransducerLocation()); + xml.create("TransducerManufacturer", + instrument.getTransducerBeamManufactuer()); + xml.create("TransducerModel", + instrument.getTransducerModel()); + xml.create("TransducerSerial", + instrument.getTransducerSerial()); + xml.create("TransducerBeamType", + "IDREF", instrument.getTransducerBeams()); + xml.create("TransducerDepth", + instrument.getTransducerDepth()); + xml.create("TransducerOrientation", + "azimuth " + instrument.getTransducerAzimuth()); + xml.create("TransducerPSI", + instrument.getTransducerPsi()); + xml.create("TransducerBeamAngleMajor", + instrument.getTransducerBeamAngleMajor()); + xml.create("TransducerBeamAngleMinor", + instrument.getTransducerBeamAngleMinor()); + xml.create("TransceiverManufacturer", + instrument.getTransceiverManufacturer()); + xml.create("TransceiverModel", + instrument.getTransceiverModel()); + xml.create("TransceiverSerial", + instrument.getTransceiverSerial()); + xml.create("TransceiverFirmware", + instrument.getTransceiverFirmware()); + xml.create("Comments", + instrument.getComments()); + + xml.close("Instrument"); + } + + public void exportCalibration(Calibration calibration, XmlWriter xml) throws IOException { + xml.open("Calibration", + "ID", calibration.getTopiaId()); + + xml.create("Date", + EchoBaseCsvUtil.ISO8611_DATE_FORMATTER.format(calibration.getDate())); + xml.create("AcquisitionMethod", + "IDREF", calibration.getAquisitionMethod()); + xml.create("ProcessingMethod", + "IDREF", calibration.getProcessingMethod()); + xml.create("AccuracyEstimate", + calibration.getAccuracyEstimate()); + xml.create("Report", + calibration.getReport()); + xml.create("Comments", + calibration.getComments()); + + xml.close("Calibration"); + } + + public void exportDataAcquisition(DataAcquisition dataAcquisition, XmlWriter xml) throws IOException { + xml.open("DataAcquisition", + "ID", dataAcquisition.getTopiaId()); + + xml.create("SoftwareName", + "IDREF", dataAcquisition.getSoftwareName()); + xml.create("SoftwareVersion", + dataAcquisition.getAcquisitionSoftwareVersion()); + xml.create("StoredDataFormat", + "IDREF", dataAcquisition.getStoredDataFormat()); + xml.create("PingDutyCycle", + dataAcquisition.getPingDutyCycle()); + xml.create("Comments", + dataAcquisition.getComments()); + + xml.close("DataAcquisition"); + } + + public void exportDataProcessing(DataProcessing dataProcessing, XmlWriter xml) throws IOException { + xml.open("DataProcessing", + "ID", dataProcessing.getTopiaId()); + + xml.create("SoftwareName", "IDREF", + dataProcessing.getSoftwareName()); + xml.create("SoftwareVersion", + dataProcessing.getProcessingSoftwareVersion()); + xml.create("TriwaveCorrection", "IDREF", + dataProcessing.getDigitThreshold()); + xml.create("ChannelID", + dataProcessing.getChannelId()); + xml.create("Bandwidth", + dataProcessing.getBandWith()); + xml.create("Frequency", + dataProcessing.getFrequency()); + xml.create("TransceiverPower", + dataProcessing.getTransceiverPower()); + xml.create("TransmitPulseLength", + dataProcessing.getTransmitPulseLength()); + xml.create("OnAxisGain", + dataProcessing.getTransceiverProcessingGain()); + xml.create("OnAxisGainUnit", "IDREF", + dataProcessing.getTransceiverGainUnits()); + xml.create("SaCorrection", + dataProcessing.getTransceiverProcessingSacorrection()); + xml.create("Absorption", + dataProcessing.getTransceiverProcessingAbsorption()); + xml.create("AbsorptionDescription", + dataProcessing.getTransceiverProcessingAbsorptionDescription()); + xml.create("SoundSpeed", + dataProcessing.getEchosounderSoundSpeed()); + xml.create("SoundSpeedDescription", + dataProcessing.getSoundSpeedCalculations()); + xml.create("TransducerPSI", + dataProcessing.getTransducerProcessingPsi()); + xml.create("Comments", + dataProcessing.getComments()); + + xml.close("DataProcessing"); + } + + 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()); + } + +} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlWriter.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlWriter.java new file mode 100644 index 0000000..b368b0d --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/xml/XmlWriter.java @@ -0,0 +1,91 @@ +package fr.ifremer.echobase.services.service.atlantos.xml; + +import java.io.IOException; +import java.io.Writer; +import org.apache.commons.lang.StringUtils; + +/* + * #%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 XmlWriter { + + protected Writer writer; + protected String tab; + + public XmlWriter(Writer writer) throws IOException { + this.writer = writer; + this.writer.append("<?xml version=\"1.0\"?>\n"); + this.tab = ""; + } + + public Writer open(String tag, String ... attributes) throws IOException { + this.writer.append(this.tab + "<" + tag); + this.addAttributes(attributes); + this.writer.append(">\n"); + + this.tab += "\t"; + return this.writer; + } + + public Writer close(String tag) throws IOException { + this.tab = StringUtils.substring(this.tab, 0, -1); + this.writer.append(this.tab + "</" + tag + ">\n"); + return this.writer; + } + + public Writer create(String tag, Object ... attributes) throws IOException { + this.writer.append(this.tab + "<" + tag); + this.addAttributes(attributes); + + if (attributes.length % 2 != 0) { + Object innerValue = attributes[attributes.length - 1]; + if (innerValue != null) { + this.writer.append(">" + innerValue); + } + this.writer.append("</" + tag + ">\n"); + } else { + this.writer.append("/>\n"); + } + + return this.writer; + } + + protected void addAttributes(Object[] attributes) throws IOException { + if (attributes.length == 1) { + return; + } + + for (int index = 0; index < attributes.length; index+=2) { + Object key = attributes[index]; + Object value = attributes[index + 1]; + + if (value != null) { + this.writer.append(" " + key + "=\"" + value + "\""); + } else { + this.writer.append(" " + key + "=\"\""); + } + } + } +} 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 ef5e189..2fb90f1 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 @@ -21,7 +21,6 @@ package fr.ifremer.echobase.services.service.atlantos; * #L% */ -import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.EchoBaseTestServiceSupport; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import fr.ifremer.echobase.services.ImportDataFixtures; @@ -48,9 +47,19 @@ public class ExportAtlantosServiceTest extends EchoBaseTestServiceSupport { @Inject private ExportAtlantosService exportService; - @Inject - private UserDbPersistenceService persistenceService; + @Test + public void testXmlExport() throws Exception { + + File workingDirectory = new File(getTestDir(), "testAtlantos"); + FileUtil.createDirectoryIfNecessary(workingDirectory); + ExportAtlantosConfiguration model = new ExportAtlantosConfiguration(); + model.setVoyageId(getVoyageId()); + model.setWorkingDirectory(workingDirectory); + + exportService.doXmlExport(model); + } + @Test public void testExport() throws Exception { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.