This is an automated email from the git hooks/post-receive script. New commit to branch feature/8170 in repository echobase. See https://gitlab.nuiton.org/codelutin/echobase.git commit c93fc680d4be1b294e3458563d7059af06188bd9 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 5 08:50:33 2016 +0200 Voyage map import ok \o/ (See #8170) --- .../VoyageResultsMapFishCellImportAction.java | 113 +++++++++++++++---- .../VoyageResultsMapOtherCellImportAction.java | 91 ++++++++++++---- .../importdata/csv/MapCellImportExportModel.java | 108 ------------------- .../VoyageResultsMapFishCellImportExportModel.java | 119 +++++++++++++++++++++ ...java => VoyageResultsMapFishCellImportRow.java} | 70 ++++++++---- ...VoyageResultsMapOtherCellImportExportModel.java | 104 ++++++++++++++++++ ...ava => VoyageResultsMapOtherCellImportRow.java} | 92 +++++++--------- .../VoyageResultsMapFishCellImportServiceIT.java | 26 +++-- .../VoyageResultsMapOtherCellImportServiceIT.java | 21 ++-- 9 files changed, 506 insertions(+), 238 deletions(-) diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/VoyageResultsMapFishCellImportAction.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/VoyageResultsMapFishCellImportAction.java index caf1436..c02bfe3 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/VoyageResultsMapFishCellImportAction.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/VoyageResultsMapFishCellImportAction.java @@ -1,8 +1,11 @@ package fr.ifremer.echobase.services.service.importdata.actions; +import com.google.common.base.Preconditions; import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; import fr.ifremer.echobase.entities.data.Category; import fr.ifremer.echobase.entities.data.Cell; +import fr.ifremer.echobase.entities.data.Data; +import fr.ifremer.echobase.entities.data.Result; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.entities.references.DataMetadata; import fr.ifremer.echobase.entities.references.DataQuality; @@ -10,13 +13,15 @@ import fr.ifremer.echobase.io.InputFile; import fr.ifremer.echobase.services.service.importdata.ImportDataFileResult; import fr.ifremer.echobase.services.service.importdata.ResultCategoryCache; import fr.ifremer.echobase.services.service.importdata.contexts.VoyageResultsImportDataContext; -import fr.ifremer.echobase.services.service.importdata.csv.MapCellImportExportModel; -import fr.ifremer.echobase.services.service.importdata.csv.MapCellImportRow; +import fr.ifremer.echobase.services.service.importdata.csv.VoyageResultsMapFishCellImportExportModel; +import fr.ifremer.echobase.services.service.importdata.csv.VoyageResultsMapFishCellImportRow; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Import; import java.util.List; +import java.util.Map; +import java.util.TreeMap; /** * Created on 25/03/16. @@ -24,28 +29,42 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDataActionSupport<MapCellImportRow> { +public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDataActionSupport<VoyageResultsMapFishCellImportRow> { /** Logger. */ private static final Log log = LogFactory.getLog(VoyageResultsMapFishCellImportAction.class); private final List<DataMetadata> metas; + private final DataMetadata dataLongitudeMeta; + private final DataMetadata dataLatitudeMeta; + private final DataMetadata dataDepthMeta; + private final DataMetadata dataLongitudeLagMeta; + private final DataMetadata dataLatitudeLagMeta; + private final DataMetadata dataDepthLagMeta; public VoyageResultsMapFishCellImportAction(VoyageResultsImportDataContext importDataContext) { super(importDataContext, importDataContext.getConfiguration().getMapsFile()); - metas = importDataContext.getMetas(getInputFile(), MapCellImportExportModel.COLUMN_NAMES_TO_EXCLUDE); + metas = importDataContext.getMetas(getInputFile(), VoyageResultsMapFishCellImportExportModel.COLUMN_NAMES_TO_EXCLUDE); + dataLongitudeMeta = importDataContext.getGridCellLongitudeMeta(); + dataLatitudeMeta = importDataContext.getGridCellLatitudeMeta(); + dataDepthMeta = importDataContext.getGridCellDepthMeta(); + dataLongitudeLagMeta = importDataContext.getGridLongitudeLagMeta(); + dataLatitudeLagMeta = importDataContext.getGridLatitudeLagMeta(); + dataDepthLagMeta = importDataContext.getGridDepthLagMeta(); } @Override - protected MapCellImportExportModel createCsvImportModel(VoyageResultsImportDataContext importDataContext) { - return MapCellImportExportModel.forImport(importDataContext, metas); + protected VoyageResultsMapFishCellImportExportModel createCsvImportModel(VoyageResultsImportDataContext importDataContext) { + return VoyageResultsMapFishCellImportExportModel.forImport(importDataContext, metas); } @Override - protected MapCellImportExportModel createCsvExportModel(VoyageResultsImportDataContext importDataContext) { - return MapCellImportExportModel.forExport(importDataContext, metas); + protected VoyageResultsMapFishCellImportExportModel createCsvExportModel(VoyageResultsImportDataContext importDataContext) { + return VoyageResultsMapFishCellImportExportModel.forExport(importDataContext, metas); } + private final Map<String, String> cellIdToCategoryId = new TreeMap<>(); + @Override protected void performImport(VoyageResultsImportDataContext importDataContext, InputFile inputFile, ImportDataFileResult result) { @@ -58,19 +77,12 @@ public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDat String resultLabel = getConfiguration().getResultLabel(); - DataMetadata dataLongitudeMeta = importDataContext.getGridCellLongitudeMeta(); - DataMetadata dataLatitudeMeta = importDataContext.getGridCellLatitudeMeta(); - DataMetadata dataDepthMeta = importDataContext.getGridCellDepthMeta(); - DataMetadata dataLongitudeLagMeta = importDataContext.getGridLongitudeLagMeta(); - DataMetadata dataLatitudeLagMeta = importDataContext.getGridLatitudeLagMeta(); - DataMetadata dataDepthLagMeta = importDataContext.getGridDepthLagMeta(); - - try (Import<MapCellImportRow> importer = open()) { + try (Import<VoyageResultsMapFishCellImportRow> importer = open()) { incrementsProgress(); int rowNumber = 0; - for (MapCellImportRow row : importer) { + for (VoyageResultsMapFishCellImportRow row : importer) { doFlushTransaction(++rowNumber); @@ -80,6 +92,8 @@ public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDat // collect ids result.addId(EchoBaseUserEntityEnum.Cell, cell); + addProcessedRow(result, row); + DataQuality dataQuality = row.getDataQuality(); // add gridCellLongitude data @@ -136,6 +150,8 @@ public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDat row.getAgeCategory(), result); + cellIdToCategoryId.put(cell.getTopiaId(), category.getTopiaId()); + addResults(row, cell, category, resultLabel, result, false, true); } @@ -147,7 +163,68 @@ public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDat @Override protected void computeImportedExport(VoyageResultsImportDataContext importDataContext, ImportDataFileResult result) { - // TODO + String voyageId = importDataContext.getConfiguration().getVoyageId(); + Voyage voyage = persistenceService.getVoyage(voyageId); + + for (String cellId : result.getIds()) { + + Cell cell = persistenceService.getCell(cellId); + Preconditions.checkNotNull(cell); + + if (log.isInfoEnabled()) { + log.info("Cell has changed, flushing cell: " + cell); + } + + String categoryId = cellIdToCategoryId.get(cellId); + Preconditions.checkNotNull(categoryId); + Category category = persistenceService.getCategory(categoryId); + Preconditions.checkNotNull(category); + + if (cell.isResultNotEmpty()) { + + // check category is matching + for (Result cellResult : cell.getResult()) { + if (!category.equals(cellResult.getCategory())) { + throw new IllegalStateException("Category should be " + category + " but was " + cellResult.getCategory() + " on cell " + cell + " result: " + cellResult); + } + } + + } + + VoyageResultsMapFishCellImportRow row = VoyageResultsMapFishCellImportRow.of(voyage, cell, category); + + for (Data data : cell.getData()) { + + Float dataValue = Float.valueOf(data.getDataValue()); + DataMetadata dataMetadata = data.getDataMetadata(); + + if (dataLatitudeMeta.equals(dataMetadata)) { + row.setGridCellLatitude(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataLongitudeMeta.equals(dataMetadata)) { + row.setGridCellLongitude(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataDepthMeta.equals(dataMetadata)) { + row.setGridCellDepth(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataLatitudeLagMeta.equals(dataMetadata)) { + row.setGridLatitudeLag(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataLongitudeLagMeta.equals(dataMetadata)) { + row.setGridLongitudeLag(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataDepthLagMeta.equals(dataMetadata)) { + row.setGridDepthLag(dataValue); + row.setDataQuality(data.getDataQuality()); + } else { + throw new IllegalStateException("Cant deal with data of metadata: " + dataMetadata); + } + + } + + addImportedRow(result, row); + + } } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/VoyageResultsMapOtherCellImportAction.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/VoyageResultsMapOtherCellImportAction.java index cd5b26f..c15ebcb 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/VoyageResultsMapOtherCellImportAction.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/VoyageResultsMapOtherCellImportAction.java @@ -1,15 +1,17 @@ package fr.ifremer.echobase.services.service.importdata.actions; +import com.google.common.base.Preconditions; import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; import fr.ifremer.echobase.entities.data.Cell; +import fr.ifremer.echobase.entities.data.Data; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.entities.references.DataMetadata; import fr.ifremer.echobase.entities.references.DataQuality; import fr.ifremer.echobase.io.InputFile; import fr.ifremer.echobase.services.service.importdata.ImportDataFileResult; import fr.ifremer.echobase.services.service.importdata.contexts.VoyageResultsImportDataContext; -import fr.ifremer.echobase.services.service.importdata.csv.MapCellImportExportModel; -import fr.ifremer.echobase.services.service.importdata.csv.MapCellImportRow; +import fr.ifremer.echobase.services.service.importdata.csv.VoyageResultsMapOtherCellImportExportModel; +import fr.ifremer.echobase.services.service.importdata.csv.VoyageResultsMapOtherCellImportRow; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Import; @@ -22,26 +24,38 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 4.0 */ -public class VoyageResultsMapOtherCellImportAction extends VoyageResultsImportDataActionSupport<MapCellImportRow> { +public class VoyageResultsMapOtherCellImportAction extends VoyageResultsImportDataActionSupport<VoyageResultsMapOtherCellImportRow> { /** Logger. */ private static final Log log = LogFactory.getLog(VoyageResultsMapOtherCellImportAction.class); - protected final List<DataMetadata> metas; + private final List<DataMetadata> metas; + private final DataMetadata dataLongitudeMeta; + private final DataMetadata dataLatitudeMeta; + private final DataMetadata dataDepthMeta; + private final DataMetadata dataLongitudeLagMeta; + private final DataMetadata dataLatitudeLagMeta; + private final DataMetadata dataDepthLagMeta; public VoyageResultsMapOtherCellImportAction(VoyageResultsImportDataContext importDataContext) { super(importDataContext, importDataContext.getConfiguration().getMapsFile()); - metas = importDataContext.getMetas(getInputFile(), MapCellImportExportModel.COLUMN_NAMES_TO_EXCLUDE); + metas = importDataContext.getMetas(getInputFile(), VoyageResultsMapOtherCellImportExportModel.COLUMN_NAMES_TO_EXCLUDE); + dataLongitudeMeta = importDataContext.getGridCellLongitudeMeta(); + dataLatitudeMeta = importDataContext.getGridCellLatitudeMeta(); + dataDepthMeta = importDataContext.getGridCellDepthMeta(); + dataLongitudeLagMeta = importDataContext.getGridLongitudeLagMeta(); + dataLatitudeLagMeta = importDataContext.getGridLatitudeLagMeta(); + dataDepthLagMeta = importDataContext.getGridDepthLagMeta(); } @Override - protected MapCellImportExportModel createCsvImportModel(VoyageResultsImportDataContext importDataContext) { - return MapCellImportExportModel.forImport(importDataContext, metas); + protected VoyageResultsMapOtherCellImportExportModel createCsvImportModel(VoyageResultsImportDataContext importDataContext) { + return VoyageResultsMapOtherCellImportExportModel.forImport(importDataContext, metas); } @Override - protected MapCellImportExportModel createCsvExportModel(VoyageResultsImportDataContext importDataContext) { - return MapCellImportExportModel.forExport(importDataContext, metas); + protected VoyageResultsMapOtherCellImportExportModel createCsvExportModel(VoyageResultsImportDataContext importDataContext) { + return VoyageResultsMapOtherCellImportExportModel.forExport(importDataContext, metas); } @Override @@ -55,19 +69,12 @@ public class VoyageResultsMapOtherCellImportAction extends VoyageResultsImportDa String resultLabel = getConfiguration().getResultLabel(); - DataMetadata dataLongitudeMeta = importDataContext.getGridCellLongitudeMeta(); - DataMetadata dataLatitudeMeta = importDataContext.getGridCellLatitudeMeta(); - DataMetadata dataDepthMeta = importDataContext.getGridCellDepthMeta(); - DataMetadata dataLongitudeLagMeta = importDataContext.getGridLongitudeLagMeta(); - DataMetadata dataLatitudeLagMeta = importDataContext.getGridLatitudeLagMeta(); - DataMetadata dataDepthLagMeta = importDataContext.getGridDepthLagMeta(); - - try (Import<MapCellImportRow> importer = open()) { + try (Import<VoyageResultsMapOtherCellImportRow> importer = open()) { incrementsProgress(); int rowNumber = 0; - for (MapCellImportRow row : importer) { + for (VoyageResultsMapOtherCellImportRow row : importer) { doFlushTransaction(++rowNumber); @@ -76,6 +83,7 @@ public class VoyageResultsMapOtherCellImportAction extends VoyageResultsImportDa // collect ids result.addId(EchoBaseUserEntityEnum.Cell, cell); + addProcessedRow(result, row); DataQuality dataQuality = row.getDataQuality(); @@ -138,7 +146,52 @@ public class VoyageResultsMapOtherCellImportAction extends VoyageResultsImportDa @Override protected void computeImportedExport(VoyageResultsImportDataContext importDataContext, ImportDataFileResult result) { - // TODO + String voyageId = importDataContext.getConfiguration().getVoyageId(); + Voyage voyage = persistenceService.getVoyage(voyageId); + + for (String cellId : result.getIds()) { + + Cell cell = persistenceService.getCell(cellId); + Preconditions.checkNotNull(cell); + + if (log.isInfoEnabled()) { + log.info("Cell has changed, flushing cell: " + cell); + } + + VoyageResultsMapOtherCellImportRow row = VoyageResultsMapOtherCellImportRow.of(voyage, cell); + + for (Data data : cell.getData()) { + + Float dataValue = Float.valueOf(data.getDataValue()); + DataMetadata dataMetadata = data.getDataMetadata(); + + if (dataLatitudeMeta.equals(dataMetadata)) { + row.setGridCellLatitude(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataLongitudeMeta.equals(dataMetadata)) { + row.setGridCellLongitude(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataDepthMeta.equals(dataMetadata)) { + row.setGridCellDepth(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataLatitudeLagMeta.equals(dataMetadata)) { + row.setGridLatitudeLag(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataLongitudeLagMeta.equals(dataMetadata)) { + row.setGridLongitudeLag(dataValue); + row.setDataQuality(data.getDataQuality()); + } else if (dataDepthLagMeta.equals(dataMetadata)) { + row.setGridDepthLag(dataValue); + row.setDataQuality(data.getDataQuality()); + } else { + throw new IllegalStateException("Cant deal with data of metadata: " + dataMetadata); + } + + } + + addImportedRow(result, row); + + } } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportExportModel.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportExportModel.java deleted file mode 100644 index 0bfe27f..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportExportModel.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * %% - * Copyright (C) 2011 - 2012 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% - */ -package fr.ifremer.echobase.services.service.importdata.csv; - -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.references.CellType; -import fr.ifremer.echobase.entities.references.DataMetadata; -import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.entities.references.Species; -import fr.ifremer.echobase.services.csv.EchoBaseCsvUtil; -import fr.ifremer.echobase.services.service.importdata.contexts.VoyageResultsImportDataContext; - -import java.util.List; - -/** - * Model to import cells of type 'Map'. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class MapCellImportExportModel extends EchoBaseImportExportModelSupport<MapCellImportRow> { - - public static final String[] COLUMN_NAMES_TO_EXCLUDE = { - MapCellImportRow.PROPERTY_NAME, - Species.PROPERTY_BARACOUDA_CODE, - MapCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, - MapCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, - MapCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, - MapCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, - MapCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, - MapCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, - MapCellImportRow.PROPERTY_VOYAGE, - MapCellImportRow.PROPERTY_SIZE_CATEGORY, - MapCellImportRow.PROPERTY_AGE_CATEGORY, - MapCellImportRow.PROPERTY_DATA_QUALITY - }; - protected final CellType cellType; - - private MapCellImportExportModel(char separator, CellType cellType) { - super(separator); - this.cellType = cellType; - - } - - public static MapCellImportExportModel forImport(VoyageResultsImportDataContext importDataContext, List<DataMetadata> dataMetadatas) { - - MapCellImportExportModel model = new MapCellImportExportModel(importDataContext.getCsvSeparator(), importDataContext.getMapCellType()); - model.newForeignKeyColumn(MapCellImportRow.PROPERTY_VOYAGE, Voyage.class, Voyage.PROPERTY_NAME, importDataContext.getVoyagesByName()); - model.newMandatoryColumn(MapCellImportRow.PROPERTY_NAME); - model.newForeignKeyColumn(MapCellImportRow.PROPERTY_DATA_QUALITY, DataQuality.class, DataQuality.PROPERTY_QUALITY_DATA_FLAG_VALUES, importDataContext.getDataQualitiesByName()); - model.newMandatoryColumn(MapCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newMandatoryColumn(MapCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newMandatoryColumn(MapCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newMandatoryColumn(MapCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newMandatoryColumn(MapCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newMandatoryColumn(MapCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - - for (DataMetadata metadata : dataMetadatas) { - model.newMandatoryColumn( - metadata.getName(), - EchoBaseCsvUtil.newResultValueParser(metadata, false), - EchoBaseCsvUtil.<MapCellImportRow>newResultValueSetter()); - } - return model; - - } - - public static MapCellImportExportModel forExport(VoyageResultsImportDataContext importDataContext, List<DataMetadata> dataMetadatas) { - - MapCellImportExportModel model = new MapCellImportExportModel(importDataContext.getCsvSeparator(), importDataContext.getMapCellType()); - model.newColumnForExport(MapCellImportRow.PROPERTY_VOYAGE, EchoBaseCsvUtil.VOYAGE_FORMATTER); - model.newColumnForExport(MapCellImportRow.PROPERTY_NAME); - model.newColumnForExport(MapCellImportRow.PROPERTY_DATA_QUALITY, EchoBaseCsvUtil.DATA_QUALITY_FORMATTER); - model.newColumnForExport(MapCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newColumnForExport(MapCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newColumnForExport(MapCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newColumnForExport(MapCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newColumnForExport(MapCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - model.newColumnForExport(MapCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); - - addResultsColumns(model, dataMetadatas); - return model; - - } - - @Override - public MapCellImportRow newEmptyInstance() { - return new MapCellImportRow(cellType); - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportExportModel.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportExportModel.java new file mode 100644 index 0000000..d25b367 --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportExportModel.java @@ -0,0 +1,119 @@ +/* + * #%L + * EchoBase :: Services + * %% + * Copyright (C) 2011 - 2012 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% + */ +package fr.ifremer.echobase.services.service.importdata.csv; + +import fr.ifremer.echobase.entities.data.Voyage; +import fr.ifremer.echobase.entities.references.AgeCategory; +import fr.ifremer.echobase.entities.references.CellType; +import fr.ifremer.echobase.entities.references.DataMetadata; +import fr.ifremer.echobase.entities.references.DataQuality; +import fr.ifremer.echobase.entities.references.SizeCategory; +import fr.ifremer.echobase.entities.references.Species; +import fr.ifremer.echobase.services.csv.EchoBaseCsvUtil; +import fr.ifremer.echobase.services.service.importdata.contexts.VoyageResultsImportDataContext; + +import java.util.List; + +/** + * Model to import cells of type 'Map'. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 0.3 + */ +public class VoyageResultsMapFishCellImportExportModel extends EchoBaseImportExportModelSupport<VoyageResultsMapFishCellImportRow> { + + protected static final String HEADER_SPECIES = "baracoudaCode"; + + public static final String[] COLUMN_NAMES_TO_EXCLUDE = { + VoyageResultsMapFishCellImportRow.PROPERTY_NAME, + HEADER_SPECIES, + VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, + VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, + VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, + VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, + VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, + VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, + VoyageResultsMapFishCellImportRow.PROPERTY_VOYAGE, + VoyageResultsMapFishCellImportRow.PROPERTY_SIZE_CATEGORY, + VoyageResultsMapFishCellImportRow.PROPERTY_AGE_CATEGORY, + VoyageResultsMapFishCellImportRow.PROPERTY_DATA_QUALITY + }; + + protected final CellType cellType; + + private VoyageResultsMapFishCellImportExportModel(char separator, CellType cellType) { + super(separator); + this.cellType = cellType; + + } + + public static VoyageResultsMapFishCellImportExportModel forImport(VoyageResultsImportDataContext importDataContext, List<DataMetadata> dataMetadatas) { + + VoyageResultsMapFishCellImportExportModel model = new VoyageResultsMapFishCellImportExportModel(importDataContext.getCsvSeparator(), importDataContext.getMapCellType()); + model.newForeignKeyColumn(VoyageResultsMapFishCellImportRow.PROPERTY_VOYAGE, Voyage.class, Voyage.PROPERTY_NAME, importDataContext.getVoyagesByName()); + model.newMandatoryColumn(VoyageResultsMapFishCellImportRow.PROPERTY_NAME); + model.newForeignKeyColumn(HEADER_SPECIES, VoyageResultsMapFishCellImportRow.PROPERTY_SPECIES, Species.class, Species.PROPERTY_BARACOUDA_CODE, importDataContext.getSpeciesByBaracoudaCode()); + model.newForeignKeyColumn(VoyageResultsMapFishCellImportRow.PROPERTY_SIZE_CATEGORY, SizeCategory.class, SizeCategory.PROPERTY_NAME, importDataContext.getSizeCategoriesByName()); + model.newForeignKeyColumn(VoyageResultsMapFishCellImportRow.PROPERTY_AGE_CATEGORY, AgeCategory.class, AgeCategory.PROPERTY_NAME, importDataContext.getAgeCategoriesByName()); + model.newForeignKeyColumn(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_QUALITY, DataQuality.class, DataQuality.PROPERTY_QUALITY_DATA_FLAG_VALUES, importDataContext.getDataQualitiesByName()); + model.newMandatoryColumn(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + + for (DataMetadata metadata : dataMetadatas) { + model.newMandatoryColumn( + metadata.getName(), + EchoBaseCsvUtil.newResultValueParser(metadata, false), + EchoBaseCsvUtil.<VoyageResultsMapFishCellImportRow>newResultValueSetter()); + } + return model; + + } + + public static VoyageResultsMapFishCellImportExportModel forExport(VoyageResultsImportDataContext importDataContext, List<DataMetadata> dataMetadatas) { + + VoyageResultsMapFishCellImportExportModel model = new VoyageResultsMapFishCellImportExportModel(importDataContext.getCsvSeparator(), importDataContext.getMapCellType()); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_VOYAGE, EchoBaseCsvUtil.VOYAGE_FORMATTER); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_NAME); + model.newColumnForExport(HEADER_SPECIES, VoyageResultsMapFishCellImportRow.PROPERTY_SPECIES, EchoBaseCsvUtil.SPECIES_FORMATTER); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_SIZE_CATEGORY, EchoBaseCsvUtil.SIZE_CATEGORY_FORMATTER); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_AGE_CATEGORY, EchoBaseCsvUtil.AGE_CATEGORY_FORMATTER); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_QUALITY, EchoBaseCsvUtil.DATA_QUALITY_FORMATTER); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapFishCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + + addResultsColumns(model, dataMetadatas); + return model; + + } + + @Override + public VoyageResultsMapFishCellImportRow newEmptyInstance() { + return new VoyageResultsMapFishCellImportRow(cellType); + } +} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportRow.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportRow.java similarity index 81% copy from echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportRow.java copy to echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportRow.java index fc9d300..ecd13be 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportRow.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportRow.java @@ -20,7 +20,7 @@ */ package fr.ifremer.echobase.services.service.importdata.csv; -import com.google.common.collect.Lists; +import fr.ifremer.echobase.entities.data.Category; import fr.ifremer.echobase.entities.data.Cell; import fr.ifremer.echobase.entities.data.CellImpl; import fr.ifremer.echobase.entities.data.Result; @@ -32,15 +32,16 @@ import fr.ifremer.echobase.entities.references.SizeCategory; import fr.ifremer.echobase.entities.references.Species; import fr.ifremer.echobase.services.csv.ResultAble; +import java.util.ArrayList; import java.util.List; /** - * Bean used as a row for import of {@link MapCellImportExportModel}. + * Bean used as a row for import of {@link VoyageResultsMapFishCellImportExportModel}. * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ -public class MapCellImportRow implements ResultAble { +public class VoyageResultsMapFishCellImportRow implements ResultAble { public static final String PROPERTY_NAME = "name"; @@ -67,9 +68,12 @@ public class MapCellImportRow implements ResultAble { public static final String PROPERTY_DATA_GRID_DEPTH_LAG = "gridDepthLag"; public static final String PROPERTY_DATA_QUALITY = "dataQuality"; + protected final Cell cell; + protected Voyage voyage; - protected List<Result> result = Lists.newArrayList(); + + protected final List<Result> result = new ArrayList<>(); protected Species species; @@ -91,11 +95,46 @@ public class MapCellImportRow implements ResultAble { protected float gridDepthLag; - public MapCellImportRow(CellType cellType) { - this.cell = new CellImpl(); + public static VoyageResultsMapFishCellImportRow of(Voyage voyage, Cell cell, Category category) { + VoyageResultsMapFishCellImportRow row = new VoyageResultsMapFishCellImportRow(cell); + row.setVoyage(voyage); + row.result.addAll(cell.getResult()); + row.setSpecies(category.getSpeciesCategory().getSpecies()); + row.setAgeCategory(category.getSpeciesCategory().getAgeCategory()); + row.setSizeCategory(category.getSpeciesCategory().getSizeCategory()); + return row; + } + + public VoyageResultsMapFishCellImportRow(Cell cell) { + this.cell = cell; + } + + public VoyageResultsMapFishCellImportRow(CellType cellType) { + this(new CellImpl()); this.cell.setCellType(cellType); } + @Override + public List<Result> getResult() { + return result; + } + + @Override + public void addResult(Result result) { + this.result.add(result); + } + + @Override + public DataQuality getDataQuality() { + return dataQuality; + } + + @Override + public void setDataQuality(DataQuality dataQuality) { + this.dataQuality = dataQuality; + } + + public Cell getCell() { return cell; } @@ -132,10 +171,6 @@ public class MapCellImportRow implements ResultAble { this.ageCategory = ageCategory; } - public List<Result> getResult() { - return result; - } - public float getGridCellLongitude() { return gridCellLongitude; } @@ -184,20 +219,13 @@ public class MapCellImportRow implements ResultAble { this.gridDepthLag = GridDepthLag; } - public void setName(String name) { - getCell().setName(name); + public String getName() { + return cell.getName(); } - @Override - public void addResult(Result result) { - this.result.add(result); + public void setName(String name) { + cell.setName(name); } - public DataQuality getDataQuality() { - return dataQuality; - } - public void setDataQuality(DataQuality dataQuality) { - this.dataQuality = dataQuality; - } } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapOtherCellImportExportModel.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapOtherCellImportExportModel.java new file mode 100644 index 0000000..a5f4d67 --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapOtherCellImportExportModel.java @@ -0,0 +1,104 @@ +/* + * #%L + * EchoBase :: Services + * %% + * Copyright (C) 2011 - 2012 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% + */ +package fr.ifremer.echobase.services.service.importdata.csv; + +import fr.ifremer.echobase.entities.data.Voyage; +import fr.ifremer.echobase.entities.references.CellType; +import fr.ifremer.echobase.entities.references.DataMetadata; +import fr.ifremer.echobase.entities.references.DataQuality; +import fr.ifremer.echobase.services.csv.EchoBaseCsvUtil; +import fr.ifremer.echobase.services.service.importdata.contexts.VoyageResultsImportDataContext; + +import java.util.List; + +/** + * Model to import cells of type 'Map'. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 0.3 + */ +public class VoyageResultsMapOtherCellImportExportModel extends EchoBaseImportExportModelSupport<VoyageResultsMapOtherCellImportRow> { + + public static final String[] COLUMN_NAMES_TO_EXCLUDE = { + VoyageResultsMapOtherCellImportRow.PROPERTY_NAME, + VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, + VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, + VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, + VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, + VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, + VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, + VoyageResultsMapOtherCellImportRow.PROPERTY_VOYAGE, + VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_QUALITY + }; + protected final CellType cellType; + + private VoyageResultsMapOtherCellImportExportModel(char separator, CellType cellType) { + super(separator); + this.cellType = cellType; + + } + + public static VoyageResultsMapOtherCellImportExportModel forImport(VoyageResultsImportDataContext importDataContext, List<DataMetadata> dataMetadatas) { + + VoyageResultsMapOtherCellImportExportModel model = new VoyageResultsMapOtherCellImportExportModel(importDataContext.getCsvSeparator(), importDataContext.getMapCellType()); + model.newForeignKeyColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_VOYAGE, Voyage.class, Voyage.PROPERTY_NAME, importDataContext.getVoyagesByName()); + model.newMandatoryColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_NAME); + model.newForeignKeyColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_QUALITY, DataQuality.class, DataQuality.PROPERTY_QUALITY_DATA_FLAG_VALUES, importDataContext.getDataQualitiesByName()); + model.newMandatoryColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newMandatoryColumn(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + + for (DataMetadata metadata : dataMetadatas) { + model.newMandatoryColumn( + metadata.getName(), + EchoBaseCsvUtil.newResultValueParser(metadata, false), + EchoBaseCsvUtil.<VoyageResultsMapOtherCellImportRow>newResultValueSetter()); + } + return model; + + } + + public static VoyageResultsMapOtherCellImportExportModel forExport(VoyageResultsImportDataContext importDataContext, List<DataMetadata> dataMetadatas) { + + VoyageResultsMapOtherCellImportExportModel model = new VoyageResultsMapOtherCellImportExportModel(importDataContext.getCsvSeparator(), importDataContext.getMapCellType()); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_VOYAGE, EchoBaseCsvUtil.VOYAGE_FORMATTER); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_NAME); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_QUALITY, EchoBaseCsvUtil.DATA_QUALITY_FORMATTER); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_LONGITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_LATITUDE, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_CELL_DEPTH, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_LONGITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_LATITUDE_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + model.newColumnForExport(VoyageResultsMapOtherCellImportRow.PROPERTY_DATA_GRID_DEPTH_LAG, EchoBaseCsvUtil.PRIMITIVE_FLOAT); + + addResultsColumns(model, dataMetadatas); + return model; + + } + + @Override + public VoyageResultsMapOtherCellImportRow newEmptyInstance() { + return new VoyageResultsMapOtherCellImportRow(cellType); + } +} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportRow.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapOtherCellImportRow.java similarity index 75% rename from echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportRow.java rename to echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapOtherCellImportRow.java index fc9d300..6ed408d 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/MapCellImportRow.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapOtherCellImportRow.java @@ -20,27 +20,24 @@ */ package fr.ifremer.echobase.services.service.importdata.csv; -import com.google.common.collect.Lists; import fr.ifremer.echobase.entities.data.Cell; import fr.ifremer.echobase.entities.data.CellImpl; import fr.ifremer.echobase.entities.data.Result; import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.references.AgeCategory; import fr.ifremer.echobase.entities.references.CellType; import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.entities.references.SizeCategory; -import fr.ifremer.echobase.entities.references.Species; import fr.ifremer.echobase.services.csv.ResultAble; +import java.util.ArrayList; import java.util.List; /** - * Bean used as a row for import of {@link MapCellImportExportModel}. + * Bean used as a row for import of {@link VoyageResultsMapFishCellImportExportModel}. * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ -public class MapCellImportRow implements ResultAble { +public class VoyageResultsMapOtherCellImportRow implements ResultAble { public static final String PROPERTY_NAME = "name"; @@ -48,12 +45,6 @@ public class MapCellImportRow implements ResultAble { public static final String PROPERTY_CELL = "cell"; - public static final String PROPERTY_SPECIES = "species"; - - public static final String PROPERTY_SIZE_CATEGORY = "sizeCategory"; - - public static final String PROPERTY_AGE_CATEGORY = "ageCategory"; - public static final String PROPERTY_DATA_GRID_CELL_LONGITUDE = "gridCellLongitude"; public static final String PROPERTY_DATA_GRID_CELL_LATITUDE = "gridCellLatitude"; @@ -67,15 +58,12 @@ public class MapCellImportRow implements ResultAble { public static final String PROPERTY_DATA_GRID_DEPTH_LAG = "gridDepthLag"; public static final String PROPERTY_DATA_QUALITY = "dataQuality"; - protected final Cell cell; - protected Voyage voyage; - protected List<Result> result = Lists.newArrayList(); - protected Species species; + protected final Cell cell; - protected SizeCategory sizeCategory; + protected Voyage voyage; - protected AgeCategory ageCategory; + protected final List<Result> result = new ArrayList<>(); protected DataQuality dataQuality; @@ -91,49 +79,53 @@ public class MapCellImportRow implements ResultAble { protected float gridDepthLag; - public MapCellImportRow(CellType cellType) { - this.cell = new CellImpl(); - this.cell.setCellType(cellType); + public static VoyageResultsMapOtherCellImportRow of(Voyage voyage, Cell cell) { + VoyageResultsMapOtherCellImportRow row = new VoyageResultsMapOtherCellImportRow(cell); + row.setVoyage(voyage); + row.result.addAll(cell.getResult()); + return row; } - public Cell getCell() { - return cell; + public VoyageResultsMapOtherCellImportRow(Cell cell) { + this.cell = cell; } - public Voyage getVoyage() { - return voyage; + public VoyageResultsMapOtherCellImportRow(CellType cellType) { + this(new CellImpl()); + this.cell.setCellType(cellType); } - public void setVoyage(Voyage voyage) { - this.voyage = voyage; + @Override + public List<Result> getResult() { + return result; } - public Species getSpecies() { - return species; + @Override + public void addResult(Result result) { + this.result.add(result); } - public void setSpecies(Species species) { - this.species = species; + @Override + public DataQuality getDataQuality() { + return dataQuality; } - public SizeCategory getSizeCategory() { - return sizeCategory; + @Override + public void setDataQuality(DataQuality dataQuality) { + this.dataQuality = dataQuality; } - public void setSizeCategory(SizeCategory sizeCategory) { - this.sizeCategory = sizeCategory; - } - public AgeCategory getAgeCategory() { - return ageCategory; + public Cell getCell() { + return cell; } - public void setAgeCategory(AgeCategory ageCategory) { - this.ageCategory = ageCategory; + public Voyage getVoyage() { + return voyage; } - public List<Result> getResult() { - return result; + public void setVoyage(Voyage voyage) { + this.voyage = voyage; } public float getGridCellLongitude() { @@ -184,20 +176,12 @@ public class MapCellImportRow implements ResultAble { this.gridDepthLag = GridDepthLag; } - public void setName(String name) { - getCell().setName(name); - } - - @Override - public void addResult(Result result) { - this.result.add(result); + public String getName() { + return cell.getName(); } - public DataQuality getDataQuality() { - return dataQuality; + public void setName(String name) { + cell.setName(name); } - public void setDataQuality(DataQuality dataQuality) { - this.dataQuality = dataQuality; - } } diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/VoyageResultsMapFishCellImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/VoyageResultsMapFishCellImportServiceIT.java index 30c7068..af7fb75 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/VoyageResultsMapFishCellImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/VoyageResultsMapFishCellImportServiceIT.java @@ -20,6 +20,7 @@ */ package fr.ifremer.echobase.services.service.importdata; +import com.google.common.collect.Iterables; import fr.ifremer.echobase.entities.ImportType; import fr.ifremer.echobase.entities.data.Category; import fr.ifremer.echobase.entities.data.Cell; @@ -29,7 +30,6 @@ import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import fr.ifremer.echobase.services.service.importdata.configurations.VoyageResultsImportConfiguration; import java.io.IOException; -import java.util.Set; /** * @author Tony Chemit - chemit@codelutin.com @@ -72,13 +72,25 @@ public class VoyageResultsMapFishCellImportServiceIT extends VoyageResultsImport @Override protected void assertAfertImport(ImportDataResult<VoyageResultsImportConfiguration> result) throws IOException { - Set<ImportDataFileResult> importDataFileResults = result.getImportResults(); - assertNbIds(importDataFileResults, 0, 380); - assertCsvImportResult(importDataFileResults, 0, Cell.class, 380); - assertCsvImportResult(importDataFileResults, 0, Data.class, 2280); - assertCsvImportResult(importDataFileResults, 0, Result.class, 380); - assertCsvImportResult(importDataFileResults, 0, Category.class, 1); + int nbCategory = 1; + int nbCell = 380; + int nbCellData = 2280; + + ImportDataFileResult importDataFileResult = Iterables.get(result.getImportResults(), 0); + assertCsvImportResultPerEntity(importDataFileResult, Cell.class, nbCell, 0, nbCell); + assertCsvImportResultPerEntity(importDataFileResult, Data.class, nbCellData, 0, nbCellData); + assertCsvImportResultPerEntity(importDataFileResult, Result.class, nbCell, 0, nbCell); + assertCsvImportResultPerEntity(importDataFileResult, Category.class, nbCategory, 0, nbCategory); + assertCsvImportResult0(importDataFileResult, nbCell); + +// Set<ImportDataFileResult> importDataFileResults = result.getImportResults(); +// assertNbIds(importDataFileResults, 0, nbCell); +// +// assertCsvImportResult(importDataFileResults, 0, Cell.class, nbCell); +// assertCsvImportResult(importDataFileResults, 0, Data.class, 2280); +// assertCsvImportResult(importDataFileResults, 0, Result.class, nbCell); +// assertCsvImportResult(importDataFileResults, 0, Category.class, nbCategory); } } diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/VoyageResultsMapOtherCellImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/VoyageResultsMapOtherCellImportServiceIT.java index 573b64e..36e1ed2 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/VoyageResultsMapOtherCellImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/VoyageResultsMapOtherCellImportServiceIT.java @@ -21,8 +21,8 @@ package fr.ifremer.echobase.services.service.importdata; * #L% */ +import com.google.common.collect.Iterables; import fr.ifremer.echobase.entities.ImportType; -import fr.ifremer.echobase.entities.data.Category; import fr.ifremer.echobase.entities.data.Cell; import fr.ifremer.echobase.entities.data.Data; import fr.ifremer.echobase.entities.data.Result; @@ -30,7 +30,6 @@ import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import fr.ifremer.echobase.services.service.importdata.configurations.VoyageResultsImportConfiguration; import java.io.IOException; -import java.util.Set; /** * @author Tony Chemit - chemit@codelutin.com @@ -60,25 +59,25 @@ public class VoyageResultsMapOtherCellImportServiceIT extends VoyageResultsImpor @Override protected void assertBeforeImport() { - assertImportCommonData(); assertImportOperations(); assertImportSampleDatas(); assertImportVoyageResult(); - assertNoEntities(Result.class, Data.class); - } @Override protected void assertAfertImport(ImportDataResult<VoyageResultsImportConfiguration> result) throws IOException { - Set<ImportDataFileResult> importDataFileResults = result.getImportResults(); - assertNbIds(importDataFileResults, 0, 380); - assertCsvImportResult(importDataFileResults, 0, Cell.class, 380); - assertCsvImportResult(importDataFileResults, 0, Data.class, 2280); - assertCsvImportResult(importDataFileResults, 0, Result.class, 380); - assertCsvImportResult(importDataFileResults, 0, Category.class, 1); + int nbCell = 380; + int nbCellData = 2280; + + ImportDataFileResult importDataFileResult = Iterables.get(result.getImportResults(), 0); + assertCsvImportResultPerEntity(importDataFileResult, Cell.class, nbCell, 0, nbCell); + assertCsvImportResultPerEntity(importDataFileResult, Data.class, nbCellData, 0, nbCellData); + assertCsvImportResultPerEntity(importDataFileResult, Result.class, nbCell, 0, nbCell); + assertCsvImportResult0(importDataFileResult, nbCell); + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.