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 3fd8d225552409a69e2c178d07a331175ff4e7f5 Author: Julien Ruchaud <julien.ruchaud@debux.org> Date: Tue Nov 8 19:10:31 2016 +0100 #8756 Setup spicies handling --- .../services/service/UserDbPersistenceService.java | 7 ++ .../VoyageResultsMapFishCellImportAction.java | 117 +++++++++++---------- .../csv/VoyageResultsMapFishCellImportRow.java | 7 +- .../import-data/result/map/mapsFish.csv.gz | Bin 3387 -> 3377 bytes 4 files changed, 74 insertions(+), 57 deletions(-) diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java index 4d66229..bb4c11d 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java @@ -259,6 +259,13 @@ public class UserDbPersistenceService extends EchoBaseServiceSupport { return persistenceContext.getCellDao().forTopiaIdEquals(id).findUnique(); } + public Cell getCellByNameAndType(String cellName, CellType cellType) { + return persistenceContext.getCellDao() + .forNameEquals(cellName) + .addEquals(Cell.PROPERTY_CELL_TYPE, cellType) + .findUniqueOrNull(); + } + public Optional<Cell> getOptionalCell(String id) { return persistenceContext.getCellDao().forTopiaIdEquals(id).tryFindUnique(); } 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 d2fab8a..0fbfc36 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 @@ -29,16 +29,17 @@ 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.CellType; 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.DuplicatedMapCellException; import fr.ifremer.echobase.services.service.importdata.ImportDataFileResult; import fr.ifremer.echobase.services.service.importdata.MismatchProviderException; 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.VoyageResultsMapFishCellImportExportModel; import fr.ifremer.echobase.services.service.importdata.csv.VoyageResultsMapFishCellImportRow; +import java.util.ArrayList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Import; @@ -65,7 +66,7 @@ public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDat private final DataMetadata dataLongitudeLagMeta; private final DataMetadata dataLatitudeLagMeta; private final DataMetadata dataDepthLagMeta; - private final Map<String, String> cellIdToCategoryId = new TreeMap<>(); + private final Map<String, List<String>> cellIdToCategoryId = new TreeMap<>(); public VoyageResultsMapFishCellImportAction(VoyageResultsImportDataContext importDataContext) { super(importDataContext, importDataContext.getConfiguration().getMapsFile()); @@ -114,15 +115,16 @@ public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDat throw new MismatchProviderException(getLocale(), rowNumber, voyage.getName()); } - String cellName = row.getCell().getName(); - boolean exists = persistenceService.containsPostVoyageCellByName(expectedVoyage, cellName); - if (exists) { - throw new DuplicatedMapCellException(getLocale(), rowNumber, cellName, voyage.getName()); + Cell rowCell = row.getCell(); + String cellName = rowCell.getName(); + CellType cellType = rowCell.getCellType(); + + Cell cell = persistenceService.getCellByNameAndType(cellName, cellType); + if (cell == null) { + cell = persistenceService.createCell(rowCell); + voyage.addPostCell(cell); } - - Cell cell = persistenceService.createCell(row.getCell()); - voyage.addPostCell(cell); - + // collect ids addId(result, EchoBaseUserEntityEnum.Cell, cell, rowNumber); @@ -185,7 +187,13 @@ public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDat row.getAgeCategory(), result); - cellIdToCategoryId.put(cell.getTopiaId(), category.getTopiaId()); + String topiaId = cell.getTopiaId(); + List<String> categories = cellIdToCategoryId.get(topiaId); + if (categories == null) { + categories = new ArrayList<>(); + cellIdToCategoryId.put(topiaId, categories); + } + categories.add(category.getTopiaId()); addResults(row, cell, category, resultLabel, result, false, true, rowNumber); @@ -209,58 +217,57 @@ public class VoyageResultsMapFishCellImportAction extends VoyageResultsImportDat if (log.isInfoEnabled()) { log.info("Cell has changed, flushing cell: " + cell); } + + List<String> categories = cellIdToCategoryId.remove(cellId); + if (categories != null) { + + for (String categoryId : categories) { - String categoryId = cellIdToCategoryId.get(cellId); - Preconditions.checkNotNull(categoryId); - Category category = persistenceService.getCategory(categoryId); - Preconditions.checkNotNull(category); + 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); - } - } + List<Result> results = new ArrayList<Result>(); + if (cell.isResultNotEmpty()) { - } + // check category is matching + for (Result cellResult : cell.getResult()) { + if (category.equals(cellResult.getCategory())) { + results.add(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); - } + } - } + VoyageResultsMapFishCellImportRow row = VoyageResultsMapFishCellImportRow.of(voyage, cell, category, results); + + for (Data data : cell.getData()) { + + Float dataValue = Float.valueOf(data.getDataValue()); + DataMetadata dataMetadata = data.getDataMetadata(); + + if (dataLatitudeMeta.equals(dataMetadata)) { + row.setGridCellLatitude(dataValue); + } else if (dataLongitudeMeta.equals(dataMetadata)) { + row.setGridCellLongitude(dataValue); + } else if (dataDepthMeta.equals(dataMetadata)) { + row.setGridCellDepth(dataValue); + } else if (dataLatitudeLagMeta.equals(dataMetadata)) { + row.setGridLatitudeLag(dataValue); + } else if (dataLongitudeLagMeta.equals(dataMetadata)) { + row.setGridLongitudeLag(dataValue); + } else if (dataDepthLagMeta.equals(dataMetadata)) { + row.setGridDepthLag(dataValue); + } else { + throw new IllegalStateException("Cant deal with data of metadata: " + dataMetadata); + } - addImportedRow(result, row); + } + addImportedRow(result, row); + } + } } - } - } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportRow.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportRow.java index b805215..02ce8b9 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportRow.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageResultsMapFishCellImportRow.java @@ -31,6 +31,7 @@ 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.Collection; import java.util.LinkedList; import java.util.List; @@ -95,10 +96,12 @@ public class VoyageResultsMapFishCellImportRow implements ResultAble { protected float gridDepthLag; - public static VoyageResultsMapFishCellImportRow of(Voyage voyage, Cell cell, Category category) { + public static VoyageResultsMapFishCellImportRow of(Voyage voyage, Cell cell, Category category, List<Result> results) { VoyageResultsMapFishCellImportRow row = new VoyageResultsMapFishCellImportRow(cell); row.setVoyage(voyage); - row.result.addAll(cell.getResult()); + row.result.addAll(results); + row.setDataQuality(results.get(0).getDataQuality()); + row.setSpecies(category.getSpeciesCategory().getSpecies()); row.setAgeCategory(category.getSpeciesCategory().getAgeCategory()); row.setSizeCategory(category.getSpeciesCategory().getSizeCategory()); diff --git a/echobase-services/src/test/resources/import-data/result/map/mapsFish.csv.gz b/echobase-services/src/test/resources/import-data/result/map/mapsFish.csv.gz index 9083d89..8daab06 100644 Binary files a/echobase-services/src/test/resources/import-data/result/map/mapsFish.csv.gz and b/echobase-services/src/test/resources/import-data/result/map/mapsFish.csv.gz differ -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.