branch develop updated (eaffa46 -> c7d4927)
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 eaffa46 ref #8007, create double legend for pelagic trawl catch new c7d4927 ref #8173, create the first basic export for the cruise 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 c7d49278718f671e380fd90702230e3f6b8400ea Author: Julien Ruchaud <julien.ruchaud@debux.org> Date: Fri Sep 30 11:26:20 2016 +0200 ref #8173, create the first basic export for the cruise Summary of changes: .../echobase/services/csv/EchoBaseCsvUtil.java | 3 + .../ExportAtlantosConfiguration.java} | 68 +++++--------- .../service/atlantos/ExportAtlantosService.java | 102 +++++++++++++++++++++ .../service/atlantos/model/CruiseExportModel.java | 56 +++++++++++ .../service/atlantos/row/CruiseExportRow.java | 89 ++++++++++++++++++ .../atlantos/ExportAtlantosServiceTest.java | 71 ++++++++++++++ 6 files changed, 343 insertions(+), 46 deletions(-) copy echobase-services/src/main/java/fr/ifremer/echobase/services/service/{exportdb/ExportDbConfiguration.java => atlantos/ExportAtlantosConfiguration.java} (55%) create mode 100644 echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosService.java create mode 100644 echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/model/CruiseExportModel.java create mode 100644 echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/row/CruiseExportRow.java create mode 100644 echobase-services/src/test/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosServiceTest.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 c7d49278718f671e380fd90702230e3f6b8400ea Author: Julien Ruchaud <julien.ruchaud@debux.org> Date: Fri Sep 30 11:26:20 2016 +0200 ref #8173, create the first basic export for the cruise --- .../echobase/services/csv/EchoBaseCsvUtil.java | 3 + .../atlantos/ExportAtlantosConfiguration.java | 92 +++++++++++++++++++ .../service/atlantos/ExportAtlantosService.java | 102 +++++++++++++++++++++ .../service/atlantos/model/CruiseExportModel.java | 56 +++++++++++ .../service/atlantos/row/CruiseExportRow.java | 89 ++++++++++++++++++ .../atlantos/ExportAtlantosServiceTest.java | 71 ++++++++++++++ 6 files changed, 413 insertions(+) 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 96b7d4d..957c210 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 @@ -45,6 +45,7 @@ import fr.ifremer.echobase.entities.references.SizeCategory; import fr.ifremer.echobase.entities.references.Species; import fr.ifremer.echobase.entities.references.Strata; import fr.ifremer.echobase.entities.references.Vessel; +import java.text.SimpleDateFormat; import org.nuiton.csv.ValueFormatter; import org.nuiton.csv.ValueGetter; import org.nuiton.csv.ValueParser; @@ -66,8 +67,10 @@ import java.util.Set; 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 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 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/ExportAtlantosConfiguration.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosConfiguration.java new file mode 100644 index 0000000..edf8fa1 --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosConfiguration.java @@ -0,0 +1,92 @@ +package fr.ifremer.echobase.services.service.atlantos; + +/* + * #%L + * EchoBase :: Services + * %% + * Copyright (C) 2011 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import fr.ifremer.echobase.services.AbstractEchobaseActionConfiguration; +import fr.ifremer.echobase.services.ProgressModel; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * @author Julien Ruchaud - ruchaud@codelutin.com + * @since 4 + */ +public class ExportAtlantosConfiguration extends AbstractEchobaseActionConfiguration { + + private static final long serialVersionUID = 1L; + + /** + * Working directory. + */ + private File workingDirectory; + + /** + * Final export file. + */ + private File exportFile; + + /** + * Id of voyage to export. + */ + private String voyageId; + + + public ExportAtlantosConfiguration() { + } + + public ExportAtlantosConfiguration(ProgressModel progressModel) { + super(progressModel); + } + + public File getWorkingDirectory() { + return workingDirectory; + } + + public void setWorkingDirectory(File workingDirectory) { + this.workingDirectory = workingDirectory; + } + + public File getExportFile() { + return exportFile; + } + + public void setExportFile(File exportFile) { + this.exportFile = exportFile; + } + + public String getVoyageId() { + return voyageId; + } + + public void setVoyageId(String voyageId) { + this.voyageId = voyageId; + } + + @Override + public void destroy() throws IOException { + if (workingDirectory != null) { + FileUtils.deleteDirectory(workingDirectory); + } + } +} 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 new file mode 100644 index 0000000..4cf72f8 --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosService.java @@ -0,0 +1,102 @@ +package fr.ifremer.echobase.services.service.atlantos; + +/* + * #%L + * EchoBase :: Services + * %% + * Copyright (C) 2011 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.echobase.EchoBaseTechnicalException; +import fr.ifremer.echobase.entities.data.Voyage; +import fr.ifremer.echobase.io.EchoBaseIOUtil; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import fr.ifremer.echobase.services.service.UserDbPersistenceService; +import fr.ifremer.echobase.services.service.atlantos.model.CruiseExportModel; +import fr.ifremer.echobase.services.service.atlantos.row.CruiseExportRow; +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.IOException; +import java.util.List; + +/** + * @author Julien Ruchaud - ruchaud@codelutin.com + * @since 4 + */ +public class ExportAtlantosService extends EchoBaseServiceSupport { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ExportAtlantosService.class); + + @Inject + private UserDbPersistenceService persistenceService; + + public void doExport(ExportAtlantosConfiguration model) throws IOException { + + Preconditions.checkNotNull(model); + Preconditions.checkNotNull(model.getVoyageId()); + + int nbSteps = 3; + model.setNbSteps(nbSteps); + + Voyage voyage = persistenceService.getVoyage(model.getVoyageId()); + Preconditions.checkNotNull(voyage); + + File tempDirectory = model.getWorkingDirectory(); + + // Export data + exportData(tempDirectory, voyage, model); + + // Concat files + + model.incrementsProgress(); + } + + protected void exportData(File rawDataDirectory, + Voyage voyage, + ExportAtlantosConfiguration model) throws IOException { + + EchoBaseIOUtil.forceMkdir(rawDataDirectory); + + if (log.isInfoEnabled()) { + log.info("Extract raw data for mission: " + model.getVoyageId() + + " to : " + rawDataDirectory); + } + + { // create cruise file + File file = new File(rawDataDirectory, "Cruise.csv"); + if (log.isInfoEnabled()) { + log.info("generate " + file); + } + + CruiseExportModel exportModel = new CruiseExportModel(getCsvSeparator()); + List<CruiseExportRow> rows = exportModel.prepareRows(voyage); + try { + Export.exportToFile(exportModel, rows, file); + } catch (Exception e) { + throw new EchoBaseTechnicalException("Could not export cruise to " + file, e); + } + model.incrementsProgress(); + } + } + +} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/model/CruiseExportModel.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/model/CruiseExportModel.java new file mode 100644 index 0000000..a5a9e38 --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/model/CruiseExportModel.java @@ -0,0 +1,56 @@ +package fr.ifremer.echobase.services.service.atlantos.model; + +/* + * #%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% + */ + +import fr.ifremer.echobase.services.csv.EchoBaseCsvUtil; +import fr.ifremer.echobase.entities.data.Voyage; +import fr.ifremer.echobase.services.service.atlantos.row.CruiseExportRow; +import java.util.Arrays; +import java.util.List; +import org.nuiton.csv.ext.AbstractExportModel; + +/** + * @author Julien Ruchaud - ruchaud@codelutin.com + * @since 4 + */ +public class CruiseExportModel extends AbstractExportModel<CruiseExportRow> { + + public CruiseExportModel(char separator) { + super(separator); + newColumnForExport("Cruise", CruiseExportRow.PROPERTY_CRUISE); + newColumnForExport("Header", CruiseExportRow.PROPERTY_HEADER); + newColumnForExport("CruiseSurvey", CruiseExportRow.PROPERTY_SURVEY); + newColumnForExport("CruiseCountry", CruiseExportRow.PROPERTY_COUNTRY); + newColumnForExport("CruiseOrganisation", CruiseExportRow.PROPERTY_ORGANISATION); + newColumnForExport("CruisePlatform", CruiseExportRow.PROPERTY_PLATEFORM); + newColumnForExport("CruiseStartDate", CruiseExportRow.PROPERTY_START_DATE, EchoBaseCsvUtil.ISO8611_DATE_FORMATTER); + newColumnForExport("CruiseEndDate", CruiseExportRow.PROPERTY_END_DATE, EchoBaseCsvUtil.ISO8611_DATE_FORMATTER); + newColumnForExport("CruiseLocalID", CruiseExportRow.PROPERTY_LOCAL_ID); + } + + public List<CruiseExportRow> prepareRows(Voyage voyage) { + CruiseExportRow row = new CruiseExportRow(); + row.setVoyage(voyage); + return Arrays.asList(row); + } + +} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/row/CruiseExportRow.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/row/CruiseExportRow.java new file mode 100644 index 0000000..b4cd84b --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/atlantos/row/CruiseExportRow.java @@ -0,0 +1,89 @@ +package fr.ifremer.echobase.services.service.atlantos.row; + +import fr.ifremer.echobase.entities.data.Voyage; +import java.util.Date; + +/* + * #%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 CruiseExportRow { + + public static final String PROPERTY_CRUISE = "cruise"; + public static final String PROPERTY_HEADER = "header"; + public static final String PROPERTY_SURVEY = "survey"; + public static final String PROPERTY_COUNTRY = "country"; + public static final String PROPERTY_ORGANISATION = "organisation"; + public static final String PROPERTY_PLATEFORM = "plateform"; + public static final String PROPERTY_START_DATE = "startDate"; + public static final String PROPERTY_END_DATE = "endDate"; + public static final String PROPERTY_LOCAL_ID = "localId"; + + protected Voyage voyage; + + public Voyage getVoyage() { + return voyage; + } + + public void setVoyage(Voyage voyage) { + this.voyage = voyage; + } + + public String getCruise() { + return "Cruise"; + } + + public String getHeader() { + return "Record"; + } + + public String getSurvey() { + return ""; + } + + public String getCountry() { + return "FR"; + } + + public String getOrganisation() { + return ""; + } + + public String getPlateform() { + return ""; + } + + public Date getStartDate() { + return voyage.getStartDate(); + } + + public Date getEndDate() { + return voyage.getEndDate(); + } + + public String getLocalId() { + return voyage.getTopiaId(); + } + +} 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 new file mode 100644 index 0000000..44a511f --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/atlantos/ExportAtlantosServiceTest.java @@ -0,0 +1,71 @@ +package fr.ifremer.echobase.services.service.atlantos; + +/* + * #%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% + */ + +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; +import fr.ifremer.echobase.services.service.UserDbPersistenceService; +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.util.FileUtil; + +import javax.inject.Inject; +import java.io.File; + +/** + * @author Julien Ruchaud - ruchaud@codelutin.com + * @since 4 + */ +public class ExportAtlantosServiceTest extends EchoBaseTestServiceSupport { + + @Override + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext( + ImportDataFixtures.IMPORT_DATA_ECHOBASE_CATCHES_AND_VOYAGE_RESULT.getDbPath()); + } + + @Inject + private ExportAtlantosService exportService; + + @Inject + private UserDbPersistenceService persistenceService; + + @Test + public void testExport() throws Exception { + + File workingDirectory = new File(getTestDir(), "testAtlantos"); + FileUtil.createDirectoryIfNecessary(workingDirectory); + + ExportAtlantosConfiguration model = new ExportAtlantosConfiguration(); + model.setVoyageId(getVoyageId()); + + Assert.assertFalse(new File(workingDirectory, "Cruise.csv").exists()); + + Voyage voyage = persistenceService.getVoyage(getVoyageId()); + exportService.exportData(workingDirectory, voyage, model); + + Assert.assertTrue(new File(workingDirectory, "Cruise.csv").exists()); + } + +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm