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 d4471e615ec77772397def30a1e36c0d005d801b Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Mar 26 14:43:44 2016 +0100 Suppression des anciens services et code d'import de données + ajout de nouveaux tests d'import --- .../services/service/UserDbPersistenceService.java | 44 ++ .../importdata/AbstractImportConfiguration.java | 18 - .../importdata/AbstractImportDataService.java | 409 ------------ .../service/importdata/AcousticImportResult.java | 57 -- .../service/importdata/AcousticImportService.java | 725 --------------------- .../service/importdata/CatchesImportService.java | 433 ------------ .../service/importdata/CommonAllImportService.java | 68 -- .../service/importdata/CommonImportService.java | 101 --- .../importdata/CommonTransectImportService.java | 137 ---- .../importdata/CommonTransitImportService.java | 113 ---- .../importdata/CommonVoyageImportService.java | 121 ---- .../importdata/EchoBaseCsvFileImportResult.java | 60 -- .../service/importdata/ImportDataResult.java | 8 +- .../service/importdata/ImportDataService.java | 99 +-- .../service/importdata/OperationImportService.java | 254 -------- .../importdata/ResultsEsduCellImportService.java | 433 ------------ .../service/importdata/ResultsImportService.java | 130 ---- .../ResultsMapFishCellImportService.java | 216 ------ .../ResultsMapOtherCellImportService.java | 188 ------ .../importdata/ResultsRegionCellImportService.java | 290 --------- .../importdata/ResultsVoyageImportService.java | 307 --------- .../importdata/actions/AbstractImportAction.java | 2 +- .../services/EchoBaseTestServiceSupport.java | 31 +- .../fr/ifremer/echobase/services/FixCellsIT.java | 15 +- .../importdata/AbstractImportDataServiceIT.java | 13 +- .../importdata/AcousticImportServiceIT.java | 10 +- .../service/importdata/CatchesImportServiceIT.java | 92 +-- .../CatchesImportServiceOnlyBiometrySampleIT.java | 64 ++ .../CatchesImportServiceOnlySubSampleIT.java | 64 ++ .../CatchesImportServiceOnlyTotalSampleIT.java | 64 ++ .../importdata/CommonAllImportServiceIT.java | 13 +- .../importdata/CommonTransectImportServiceIT.java | 13 +- .../importdata/CommonTransitImportServiceIT.java | 13 +- .../importdata/CommonVoyageImportServiceIT.java | 13 +- .../importdata/OperationImportServiceIT.java | 13 +- .../importdata/ResultsEsduCellImportServiceIT.java | 37 +- .../ResultsMapFishCellImportServiceIT.java | 13 +- .../ResultsMapOtherCellImportServiceIT.java | 13 +- .../ResultsRegionCellImportServiceIT.java | 13 +- .../importdata/ResultsVoyageImportServiceIT.java | 88 +-- .../ResultsVoyageImportServiceOnlyEchotypeIT.java | 66 ++ ...sultsVoyageImportServiceOnlyLengthAgeKeyIT.java | 67 ++ ...tsVoyageImportServiceOnlyLengthWeightKeyIT.java | 67 ++ .../actions/importData/AbstractLaunchImport.java | 7 +- .../importData/GetDataProcessingsForVoyage.java | 5 +- .../actions/importData/LaunchAcousticImport.java | 3 +- .../ui/actions/importData/LaunchCatchesImport.java | 3 +- .../ui/actions/importData/LaunchCommonImport.java | 3 +- .../actions/importData/LaunchOperationImport.java | 3 +- .../ui/actions/importData/LaunchResultsImport.java | 3 +- 50 files changed, 569 insertions(+), 4453 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 8858deb..a040188 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 @@ -73,6 +73,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.ValueParser; +import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaException; @@ -405,6 +406,49 @@ public class UserDbPersistenceService extends EchoBaseServiceSupport { return persistenceContext.getDataProcessingDao().forCellContains(cell).findAnyOrNull(); } + public Map<String, String> getDataProcessings(Voyage voyage) { + + Map<String, String> result = Maps.newLinkedHashMap(); + + Decorator<Transit> transitDecorator = decoratorService.getDecorator(Transit.class, null); + Decorator<Transect> transectDecorator = decoratorService.getDecorator(Transect.class, null); + Decorator<DataAcquisition> dataAcquisitionDecorator = decoratorService.getDecorator(DataAcquisition.class, null); + Decorator<DataProcessing> dataProcessingDecorator = decoratorService.getDecorator(DataProcessing.class, null); + + if (!voyage.isTransitEmpty()) { + + for (Transit transit : voyage.getTransit()) { + + String transitStr = transitDecorator.toString(transit); + + if (!transit.isTransectEmpty()) { + for (Transect transect : transit.getTransect()) { + + String transectStr = transitStr + " / " + transectDecorator.toString(transect); + + if (!transect.isDataAcquisitionEmpty()) { + + for (DataAcquisition dataAcquisition : transect.getDataAcquisition()) { + + String dataAcquisitionStr = transectStr + " / " + dataAcquisitionDecorator.toString(dataAcquisition); + + if (!dataAcquisition.isDataProcessingEmpty()) { + for (DataProcessing dataProcessing : dataAcquisition.getDataProcessing()) { + + String value = dataAcquisitionStr + dataProcessingDecorator.toString(dataProcessing); + result.put(dataProcessing.getTopiaId(), value); + } + } + } + } + } + } + } + } + return result; + + } + //------------------------------------------------------------------------// //--- Echotype -----------------------------------------------------------// //------------------------------------------------------------------------// diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportConfiguration.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportConfiguration.java index 7359866..bffeff6 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportConfiguration.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportConfiguration.java @@ -20,16 +20,12 @@ */ package fr.ifremer.echobase.services.service.importdata; -import com.google.common.collect.Lists; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; import fr.ifremer.echobase.entities.ImportType; import fr.ifremer.echobase.io.EchoBaseIOUtil; import fr.ifremer.echobase.io.InputFile; import fr.ifremer.echobase.services.AbstractEchobaseActionConfiguration; import java.io.File; -import java.util.List; -import java.util.Set; /** * Common import data configuration. @@ -59,10 +55,6 @@ public abstract class AbstractImportConfiguration extends AbstractEchobaseAction */ protected ImportType importType; - /** Result stats for each file imported. (mainly kept for testing purpose). */ - protected final List<EchoBaseCsvFileImportResult> importResults = - Lists.newArrayList(); - public final String getVoyageId() { return voyageId; } @@ -95,10 +87,6 @@ public abstract class AbstractImportConfiguration extends AbstractEchobaseAction this.importType = importType; } - public List<EchoBaseCsvFileImportResult> getImportResults() { - return importResults; - } - /** @return all the input files defined for the import (some can be empty). */ public abstract InputFile[] getInputFiles(); @@ -117,10 +105,4 @@ public abstract class AbstractImportConfiguration extends AbstractEchobaseAction return result; } - public void addResult(EchoBaseCsvFileImportResult fileResult) { - Set<EchoBaseUserEntityEnum> entityTypes = fileResult.getEntityTypes(); - if (!entityTypes.isEmpty()) { - importResults.add(fileResult); - } - } } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataService.java deleted file mode 100644 index 6c9be78..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataService.java +++ /dev/null @@ -1,409 +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; - -import com.google.common.base.Charsets; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import fr.ifremer.echobase.EchoBaseTechnicalException; -import fr.ifremer.echobase.csv.EchoBaseCsvUtil; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.ImportFile; -import fr.ifremer.echobase.entities.ImportLog; -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.Echotype; -import fr.ifremer.echobase.entities.data.Result; -import fr.ifremer.echobase.entities.references.AgeCategory; -import fr.ifremer.echobase.entities.references.DataMetadata; -import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.entities.references.SexCategory; -import fr.ifremer.echobase.entities.references.SizeCategory; -import fr.ifremer.echobase.entities.references.Species; -import fr.ifremer.echobase.entities.references.SpeciesCategory; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.EchoBaseServiceSupport; -import fr.ifremer.echobase.services.service.UserDbPersistenceService; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.TimeLog; - -import javax.inject.Inject; -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.sql.SQLException; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static org.nuiton.i18n.I18n.l; - -/** - * Abstract data import service. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public abstract class AbstractImportDataService<M extends AbstractImportConfiguration> extends EchoBaseServiceSupport { - - public static final Pattern REMOVE_DOUBLE_QUOTES_PATTERN = - Pattern.compile("\"(.+)\""); - - /** Logger. */ - private static final Log log = - LogFactory.getLog(AbstractImportDataService.class); - - public static final TimeLog TIME_LOG = - new TimeLog(AbstractImportDataService.class); - - @Inject - protected UserDbPersistenceService persistenceService; - - public final String doImport(M configuration, EchoBaseUser user) throws ImportException { - - long s0 = TimeLog.getTime(); - - long nbSteps = configuration.computeNbSteps(); - - if (log.isInfoEnabled()) { - log.info("Nb lines to import " + nbSteps); - } - - s0 = TIME_LOG.log(s0, "computeNbSteps"); - - try { - - startImport(configuration, user); - - s0 = TIME_LOG.log(s0, "importDone"); - - // add result in log book and compute resume to show in result - String result = computeResultAndLogBookEntry(configuration, user); - - // do commit - persistenceService.commit(); - - TIME_LOG.log(s0, "importCommited"); - - return result; - - } catch (EchoBaseTechnicalException e) { - throw new ImportException(e.getMessage(), e); - } - } - - protected EchoBaseCsvFileImportResult newImportResult(InputFile inputFile) { - return new EchoBaseCsvFileImportResult(inputFile.getFileName()); - } - - public ImportLog computeImportLogEntry(M configuration, EchoBaseUser user) { - - Date importDate = newDate(); - String importUser = user.getEmail(); - - StringBuilder buffer = new StringBuilder(); - - if (StringUtils.isNotEmpty(configuration.getImportNotes())) { - buffer.append("Notes :").append(configuration.getImportNotes()).append('\n'); - } - - List<String> importIds = Lists.newArrayList(); - - for (EchoBaseCsvFileImportResult importResult : configuration.getImportResults()) { - - importIds.addAll(importResult.getIds()); - - StringBuilder description = new StringBuilder(); - description.append("Depuis Fichier ").append(importResult.getImportFileName()); - - for (EchoBaseUserEntityEnum entityType : importResult.getEntityTypes()) { - int numberCreated = importResult.getNumberCreated(entityType); - int numberUpdated = importResult.getNumberUpdated(entityType); - description.append("\n\tEntité ").append(entityType); - if (numberCreated > 0) { - description.append(" [nombre de création : "); - description.append(numberCreated); - description.append("]"); - } - if (numberUpdated > 0) { - description.append(" [nombre de mises à jour : "); - description.append(numberUpdated); - description.append("]"); - } - } - buffer.append(description.toString()).append('\n'); - } - String importText = buffer.toString().trim(); - - ImportLog importLog = persistenceService.createImportLog(configuration.getVoyageId(), - configuration.getImportType(), - importUser, - importDate, - importText, - importIds); - - addImportFiles(importLog, configuration.getInputFiles()); - - return importLog; - - } - - protected void addImportFiles(ImportLog importLog, InputFile... inputFiles) { - - for (InputFile inputFile : inputFiles) { - - if (inputFile.hasFile()) { - - ImportFile importFile = persistenceService.createImportFile(inputFile); - - if (log.isInfoEnabled()) { - try { - log.info("Add ImportFile: " + importFile.getName() + " - size: " + importFile.getFile().length()); - } catch (SQLException e) { - throw new EchoBaseTechnicalException("Can't get length of importFile " + importFile.getName()); - } - } - importLog.addImportFile(importFile); - - } - - } - - } - - - protected String computeResultAndLogBookEntry(M configuration, EchoBaseUser user) { - - Date importDate = newDate(); - String importUser = user.getEmail(); - - ImportLog importLog = computeImportLogEntry(configuration, user); - - String importType = getImportLabel(configuration); - - String result = importLog.getImportText(); - - persistenceService.createEntityModificationLog("Import", importType, importUser, importDate, result); - return result; - - } - - protected final String getImportLabel(M configuration) { - return l(getLocale(), configuration.getImportType().getI18nKey()); - } - - protected abstract void startImport(M configuration, EchoBaseUser user) throws ImportException; - - protected Reader getInputFileReader(InputFile inputFile) throws EchoBaseTechnicalException { - try { - return new BufferedReader(new InputStreamReader(new FileInputStream(inputFile.getFile()), Charsets.UTF_8)); - } catch (FileNotFoundException e) { - throw new EchoBaseTechnicalException("Could not find import file " + inputFile.getFile(), e); - } - } - -// protected void closeReader(Reader reader, InputFile inputFile) { -// try { -// reader.close(); -// } catch (IOException e) { -// throw new EchoBaseTechnicalException( -// "Could not close reader on file " + -// inputFile.getFile(), e -// ); -// } -// } - - protected String getImportMessage(M configuration, InputFile inputFile) { - return l(getLocale(), "echobase.importLabel.withFile", getImportLabel(configuration), inputFile.getFileName()); - } - - protected final void doFlushTransaction(int rowNumber, InputFile inputFile, M configuration) { - configuration.incrementsProgress(); - if (rowNumber % 1000 == 0) { - // flush each 1000 imported rows - String message = getImportMessage(configuration, inputFile); - persistenceService.flush(); - } - } - - protected Map<String, SpeciesCategory> speciesCategories = Maps.newTreeMap(); - - protected SpeciesCategory getSpeciesCategory(Species species, - SizeCategory sizeCategory, - AgeCategory ageCategory, - SexCategory sexCategory, - EchoBaseCsvFileImportResult importResult) { - - String key = species == null ? "" : species.getBaracoudaCode(); - key += "#" + (ageCategory == null ? "" : ageCategory.getName()); - key += "#" + (sizeCategory == null ? "" : sizeCategory.getName()); - key += "#" + (sexCategory == null ? "" : sexCategory.getName()); - - SpeciesCategory category = speciesCategories.get(key); - - if (category == null) { - - // try to find it in db - - category = persistenceService.getSpeciesCategory(species, sizeCategory, ageCategory, sexCategory); - - if (category == null) { - - // not found in db, create it - - category = persistenceService.createSpeciesCategory(species, sizeCategory, ageCategory, sexCategory); - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.SpeciesCategory); - } - - speciesCategories.put(key, category); - } - return category; - } - - protected Map<String, Category> categories = Maps.newTreeMap(); - - protected Category getResultCategory(Echotype echotype, - Species species, - SizeCategory sizeCategory, - AgeCategory ageCategory, - EchoBaseCsvFileImportResult importResult) { - - // get species categorie first - - SpeciesCategory speciesCategory = getSpeciesCategory(species, sizeCategory, ageCategory, null, importResult); - - return getResultCategory(echotype, speciesCategory, importResult); - } - - protected Category getResultCategory(Echotype echotype, SpeciesCategory speciesCategory, EchoBaseCsvFileImportResult importResult) { - - String key = speciesCategory == null ? "" : speciesCategory.getTopiaId(); - key += "#" + (echotype == null ? "" : echotype.getName()); - - Category category = categories.get(key); - - if (category == null) { - - // try to find it in db - - category = persistenceService.getCategoryByEchotypeAndSpeciesCategory(echotype, speciesCategory); - - if (category == null) { - - // not found in db, create it - category = persistenceService.createCategory(echotype, speciesCategory); - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.Category); - } - - categories.put(key, category); - } - - return category; - } - - protected List<DataMetadata> getMetas(String[] columnNamesToExclude, Map<String, DataMetadata> dataMetadataMap, String... headers) { - - List<String> metadataNames = Lists.newArrayList(headers); - for (String columnToExclude : columnNamesToExclude) { - metadataNames.remove(columnToExclude); - metadataNames.remove("\"" + columnToExclude + "\""); - } - - List<DataMetadata> result = Lists.newArrayList(); - - Locale locale = getLocale(); - - for (String metadataName : metadataNames) { - - Matcher matcher = REMOVE_DOUBLE_QUOTES_PATTERN.matcher(metadataName); - if (matcher.matches()) { - metadataName = matcher.group(1); - } - DataMetadata dataMetadata = dataMetadataMap.get(metadataName); - if (dataMetadata == null) { - throw new DataMetadataNotFoundException(locale, metadataName, dataMetadataMap.keySet()); - } - result.add(dataMetadata); - } - return result; - - } - - protected void createCellData(Cell cell, - DataMetadata dataMetaData, - String dataValue, - DataQuality dataQuality, - EchoBaseCsvFileImportResult importResult) { - - Data data = persistenceService.createData(dataMetaData, dataValue); - cell.addData(data); - cell.setDataQuality(dataQuality); - - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.Data); - - } - - protected void addResults(EchoBaseCsvUtil.ResultAble row, - Cell cell, - Category category, - String resultLabel, - EchoBaseCsvFileImportResult importResult, - boolean collecIds, - boolean importNAResults) { - - List<Result> results = row.getResult(); - - for (Result result : results) { - - if (!importNAResults && EchoBaseCsvUtil.NA.equals(result.getResultValue())) { - - // Do not import NA results - continue; - } - result.setDataQuality(row.getDataQuality()); - result.setCategory(category); - result.setResultLabel(resultLabel); - - Result resultCreated = persistenceService.createResult(result); - cell.addResult(resultCreated); - - if (collecIds) { - - importResult.addId(EchoBaseUserEntityEnum.Result, resultCreated); - - } else { - - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.Result); - } - - } - - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportResult.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportResult.java deleted file mode 100644 index fe18cb6..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportResult.java +++ /dev/null @@ -1,57 +0,0 @@ -package fr.ifremer.echobase.services.service.importdata; - -/* - * #%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% - */ - -import com.google.common.collect.ImmutableSet; -import fr.ifremer.echobase.entities.ImportLog; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.service.csv.in.CsvFileImportResult; - -import java.util.HashSet; -import java.util.Set; - -/** - * {@link CsvFileImportResult} with support for ids to keep in the - * {@link ImportLog#getImportId()}. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.2 - */ -public class AcousticImportResult extends EchoBaseCsvFileImportResult { - - private static final long serialVersionUID = 1L; - - protected final Set<String> notImportedEsduCellIds = new HashSet<String>(); - - public AcousticImportResult(String importFileName) { - super(importFileName); - } - - public <E extends TopiaEntity> void addNotImportedEsduCellId(String id) { - notImportedEsduCellIds.add(id); - } - - public Set<String> getNotImportedEsduCellIds() { - return ImmutableSet.copyOf(notImportedEsduCellIds); - } - -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportService.java deleted file mode 100644 index 069c618..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportService.java +++ /dev/null @@ -1,725 +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; - -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import fr.ifremer.echobase.csv.EchoBaseCsvUtil; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.data.Cell; -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.AcousticInstruments; -import fr.ifremer.echobase.entities.references.CellType; -import fr.ifremer.echobase.entities.references.CellTypeImpl; -import fr.ifremer.echobase.entities.references.DataMetadata; -import fr.ifremer.echobase.entities.references.DataMetadatas; -import fr.ifremer.echobase.entities.references.DataQualities; -import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.entities.references.Vessel; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.AcousticImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.AcousticImportRow; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; - -import java.io.IOException; -import java.io.Reader; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import static org.nuiton.i18n.I18n.l; - -/** - * Service to launch a "acoustic data" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class AcousticImportService extends AbstractImportDataService<AcousticImportConfiguration> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(AcousticImportService.class); - - @Override - protected void startImport(AcousticImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - // get selected voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - // get selected vessel - Vessel vessel = persistenceService.getVessel(configuration.getVesselId()); - - CellType esduCellType = persistenceService.getCellTypeById(CellTypeImpl.ESDU); - - CellType elementaryCellType = persistenceService.getCellTypeById(CellTypeImpl.ELEMENTARY); - - EchoBaseCsvFileImportResult importResult = importMoviesFile(configuration, - voyage, - vessel, - esduCellType, - elementaryCellType); - configuration.addResult(importResult); - - } - - private final DateFormat cellDateFormat = new SimpleDateFormat(EchoBaseCsvUtil.CELLULE_DATE_FORMAT); - - private DataAcquisition getDataAcquisition(Transect transect, AcousticInstrument instrument, boolean addDataAcquisition) throws ImportException { - - DataAcquisition result = null; - if (!addDataAcquisition && !transect.isDataAcquisitionEmpty()) { - - // try to obtain an existing data acquisiton - - for (DataAcquisition acquisition : transect.getDataAcquisition()) { - - if (instrument.equals(acquisition.getAcousticInstrument())) { - - // found a matching dataAcquisition from his acoustic instrument - result = acquisition; - break; - } - } - } - return result; - } - - private String lastEsduId; - - private EchoBaseCsvFileImportResult importMoviesFile(AcousticImportConfiguration configuration, - Voyage voyage, - Vessel vessel, - CellType esduCellType, - CellType elementaryCellType) throws ImportException { - - InputFile inputFile = configuration.getMoviesFile(); - - if (log.isInfoEnabled()) { - log.info("Starts " + getImportMessage(configuration, inputFile)); - } - - AcousticImportResult importResult = newImportResult(inputFile); - - Map<String, AcousticInstrument> instrumentsById = persistenceService.getEntitiesMap(AcousticInstrument.class, AcousticInstruments.ACOUSTIC_INSTRUMENT_ID); - - Map<String, DataMetadata> dataMetadatasByName = persistenceService.getEntitiesMap(DataMetadata.class, DataMetadatas.DATA_METADATA_NAME); - - Map<String, DataQuality> dataQualityMap = persistenceService.getEntitiesMap(DataQuality.class, DataQualities.DATA_QUALITY_NAME); - - boolean addDataAcquisition = configuration.isAddDataAcquisition(); - - String suffix = configuration.getCellPositionReference().getMetadataNameSuffix(); - - List<Cell> elementaryCells = Lists.newArrayList(); - - Locale locale = getLocale(); - - try (Reader reader = getInputFileReader(inputFile)) { - - String dataProcessingId = null; - - AcousticImportModel csvModel = new AcousticImportModel(getCsvSeparator(), instrumentsById, dataQualityMap); - - try (Import<AcousticImportRow> importer = Import.newImport(csvModel, reader)) { - DataAcquisition dataAcquisition = null; - DataProcessing dataProcessing = null; - - Cell elementaryCell; - int rowNumber = 0; - - configuration.incrementsProgress(); - - Set<String> createdDataAcquisitions = Sets.newHashSet(); - - for (AcousticImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - if (dataProcessingId == null) { - - // compute once for all the common dataprocessing id used - // for hole the movies file - dataProcessingId = row.getEiLayer() + configuration.getProcessingTemplate(); - } - - Date startDate = row.getCellDateStart(); - Date endDate = row.getCellDateEnd(); - - // get transect to use - Transit transit = voyage.getTransit(startDate); - if (transit == null) { - - // can not find correct transit - throw new TransitNotFoundException(locale, voyage, startDate, rowNumber); - } - - Transect transect = transit.getTransect(vessel); - if (transect == null) { - - // can not find correct transect - throw new TransectNotFoundException(locale, voyage, vessel, startDate, rowNumber); - } - - AcousticInstrument instrument = row.getAcousticInstrument(); - boolean isME70 = AcousticInstruments.IS_ACOUSTIC_INSTRUMENT_ME70.apply(instrument); - - if (dataAcquisition == null || !instrument.equals(dataAcquisition.getAcousticInstrument())) { - - // need to use another data acquisition - - if (log.isDebugEnabled()) { - log.debug("[row " + rowNumber + "] New instrument to use (" + instrument.getId() + ")"); - } - - if (CollectionUtils.isNotEmpty(elementaryCells)) { - - // means miss a esdu cell - // can not find correct transect - throw new EsduCellNotFoundException(locale, voyage, vessel, instrument, rowNumber); - } - - String softwareVersion = getSoftwareVersion(configuration, isME70); - - String soundSpeedCalculations = getSoundSpeedCalculations(configuration, isME70); - - // try to get existing data acquisition - dataAcquisition = getDataAcquisition(transect, instrument, addDataAcquisition); - - if (dataAcquisition == null) { - - // need to create the data acquisition - dataAcquisition = createDataAcquisition(configuration, instrument, softwareVersion, soundSpeedCalculations, row); - - // collect id of the import - importResult.addId(EchoBaseUserEntityEnum.DataAcquisition, dataAcquisition); - createdDataAcquisitions.add(dataAcquisition.getTopiaId()); - - // add dataAcquisition to transect - transect.addDataAcquisition(dataAcquisition); - - if (log.isDebugEnabled()) { - log.debug("[row " + rowNumber + "] New dataAquisition to use (number: " + importResult.getNumberCreated(EchoBaseUserEntityEnum.DataAcquisition) + ")"); - } - - // create data processing - dataProcessing = createDataProcessing( - configuration, - dataProcessingId, - softwareVersion, - soundSpeedCalculations, - row); - - if (log.isDebugEnabled()) { - log.debug("[row " + rowNumber + - "] New dataProcessing to use (" + - dataProcessing.getId() + ")"); - } - - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.DataProcessing); - - // add it to data acquisition - dataAcquisition.addDataProcessing(dataProcessing); - } - } - - int cellType = row.getCellType(); - - String esduCellId = cellDateFormat.format(endDate); - - String previousLastEsduId = lastEsduId; - - if (lastEsduId == null || !lastEsduId.equals(esduCellId)) { - - lastEsduId = esduCellId; - // find a new esdu cell id - if (log.isDebugEnabled()) { - log.debug("row: " + rowNumber + " - detects new esduCellId:" + lastEsduId); - } - } - boolean isEsduCell = cellType == 4; - - if (isEsduCell) { - - if (!esduCellId.equals(previousLastEsduId)) { - - // This should not happen ? - if (log.isWarnEnabled()) { - log.warn("row: " + rowNumber + " A previous esduCellId was detected (" + previousLastEsduId + "); but the esdu id was never found."); - } - } - if (log.isDebugEnabled()) { - log.debug("row: " + rowNumber + " - found esdu cell:" + lastEsduId); - } - } - - if (!row.isCellToAdd()) { - - // dead cell not to be imported - - String id = rowNumber + " - " + cellType + " : " + esduCellId; - if (isEsduCell) { - - // keep this fact into import result - if (log.isWarnEnabled()) { - log.warn("Will not import esdu cell of row " + id); - } - importResult.addNotImportedEsduCellId(id); - } else { - - // just a debug log - if (log.isTraceEnabled()) { - log.trace("Will not import cell of row " + id); - } - } - - continue; - } - - DataQuality dataQuality = row.getDataQuality(); - - // collect Esdu cellIds only if dataAcquisitions was not created here - boolean collectCellIds = !createdDataAcquisitions.contains(dataAcquisition.getTopiaId()); - - - if (isEsduCell) { - - if (log.isDebugEnabled()) { - log.debug("[row " + rowNumber + "] Esdu cell (" + esduCellId + ")"); - } - - // this is a esdu cell row - - // create esdu cell - Cell esduCell = persistenceService.createCell(esduCellType, esduCellId); - - esduCell.setDataQuality(dataQuality); - - // add all found elementary cells - esduCell.addAllChilds(elementaryCells); - - // clear elementary cells - elementaryCells.clear(); - - if (collectCellIds) { - - // collect ids (dataProcessing already exists) - importResult.addId(EchoBaseUserEntityEnum.Cell, esduCell); - } else { - - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.Cell); - } - - // add it to data processing - dataProcessing.addCell(esduCell); - - // create esdu cell data - createEsduCellData(suffix, - esduCell, - dataMetadatasByName, - row, - dataQuality, - importResult); - } else { - - // this is a elementary cell row - - int cellNum = row.getCellNum(); - - boolean surface = cellType == 0; - - String elementaryCellId = cellNum + (surface ? "S" : "B"); - - if (log.isTraceEnabled()) { - log.trace("[row " + rowNumber + "] elementary cell (" + elementaryCellId + ")"); - } - - // create the elementary cell - elementaryCell = persistenceService.createCell( - elementaryCellType, elementaryCellId); - elementaryCell.setDataQuality(dataQuality); - - // keep (to attach them to esdu cell) - elementaryCells.add(elementaryCell); - - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.Cell); - - // create datas of the elementary cell - createElementaryCellData(suffix, - elementaryCell, - dataMetadatasByName, - surface, - row, - dataQuality, - importResult); - } - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(locale, inputFile, e); - } - - } - - @Override - protected String computeResultAndLogBookEntry(AcousticImportConfiguration configuration, - EchoBaseUser user) { - String resultText = super.computeResultAndLogBookEntry(configuration, user); - List<EchoBaseCsvFileImportResult> importResults = configuration.getImportResults(); - if (!importResults.isEmpty()) { - AcousticImportResult acousticImportResult = (AcousticImportResult) importResults.get(0); - Set<String> notImportedCellIds = acousticImportResult.getNotImportedEsduCellIds(); - if (!notImportedCellIds.isEmpty()) { - - // add a log of not imported cells - resultText += "\n\n" + l(getLocale(), "echobase.acousticImport.cellNotImported", Joiner.on("\n").join(notImportedCellIds)); - } - } - return resultText; - } - - protected void createEsduCellData(String suffix, - Cell cell, - Map<String, DataMetadata> dataMetadatas, - AcousticImportRow row, - DataQuality dataQuality, - EchoBaseCsvFileImportResult importResult) { - - String dataValue; - - // create Latitude data - dataValue = String.valueOf(row.getCellLatitude()); - createCellData(cell, dataMetadatas, "Latitude" + suffix, - dataValue, dataQuality, importResult); - - // create Longitude data - dataValue = String.valueOf(row.getCellLongitude()); - createCellData(cell, dataMetadatas, "Longitude" + suffix, - dataValue, dataQuality, importResult); - - // create Depth data - dataValue = row.getEsduCellDataDepth(); - createCellData(cell, dataMetadatas, "DepthRefSurface" + suffix, - dataValue, dataQuality, importResult); - - // create Time Start data - dataValue = cellDateFormat.format(row.getCellDateStart()); - createCellData(cell, dataMetadatas, "TimeStart", - dataValue, dataQuality, importResult); - - // create Time end data - dataValue = cellDateFormat.format(row.getCellDateEnd()); - createCellData(cell, dataMetadatas, "TimeEnd", - dataValue, dataQuality, importResult); - - // create NASC data - if (row.getCellNasc() != null) { - dataValue = String.valueOf(row.getCellNasc()); - createCellData(cell, dataMetadatas, "NASC", - dataValue, dataQuality, importResult); - } - - // create Volume data - if (row.getCellVolume() != null) { - dataValue = String.valueOf(row.getCellVolume()); - createCellData(cell, dataMetadatas, "Volume", - dataValue, dataQuality, importResult); - } - - // create Surface data - dataValue = String.valueOf(row.getCellSurface()); - createCellData(cell, dataMetadatas, "Surface", - dataValue, dataQuality, importResult); - - // create NumberOfSamplesRecorded data - if (row.getCellNumberOfSamplesRecorded() != null) { - dataValue = String.valueOf(row.getCellNumberOfSamplesRecorded()); - createCellData(cell, dataMetadatas, "NumberOfSamplesRecorded", - dataValue, dataQuality, importResult); - } - // create NumberOfSamplesEchoIntegrated data - if (row.getCellNumberOfSamplesEchoIntegrated() != null) { - dataValue = String.valueOf(row.getCellNumberOfSamplesEchoIntegrated()); - createCellData(cell, dataMetadatas, "NumberOfSamplesEchoIntegrated", - dataValue, dataQuality, importResult); - } - } - - private void createElementaryCellData(String suffix, - Cell cell, - Map<String, DataMetadata> dataMetadatas, - boolean surface, - AcousticImportRow row, - DataQuality dataQuality, - EchoBaseCsvFileImportResult importResult) { - - String dataValue; - String startMeta; - String endMeta; - - if (surface) { - - // surface - - startMeta = "DepthRefSurfaceStart"; - endMeta = "DepthRefSurfaceEnd"; - - } else { - - // bottom - - startMeta = "DepthRefBottomStart"; - endMeta = "DepthRefBottomEnd"; - } - - // create Latitude data - dataValue = String.valueOf(row.getCellLatitude()); - createCellData(cell, dataMetadatas, "Latitude" + suffix, - dataValue, dataQuality, importResult); - - // create Longitude data - dataValue = String.valueOf(row.getCellLongitude()); - createCellData(cell, dataMetadatas, "Longitude" + suffix, - dataValue, dataQuality, importResult); - - // create depth start data - dataValue = String.valueOf(row.getCellDepthStart()); - createCellData(cell, dataMetadatas, startMeta, dataValue, - dataQuality, importResult); - - // create depth end data - dataValue = String.valueOf(row.getCellDepthEnd()); - createCellData(cell, dataMetadatas, endMeta, dataValue, - dataQuality, importResult); - - - // create Time Start data - dataValue = cellDateFormat.format(row.getCellDateStart()); - createCellData(cell, dataMetadatas, "TimeStart", - dataValue, dataQuality, importResult); - - // create Time end data - dataValue = cellDateFormat.format(row.getCellDateEnd()); - createCellData(cell, dataMetadatas, "TimeEnd", - dataValue, dataQuality, importResult); - - // create acoustic density data - if (row.getCellNasc() != null) { - dataValue = String.valueOf(row.getCellNasc()); - createCellData(cell, dataMetadatas, "NASC", dataValue, - dataQuality, importResult); - } - // create Volume data - if (row.getCellVolume() != null) { - dataValue = String.valueOf(row.getCellVolume()); - createCellData(cell, dataMetadatas, "Volume", - dataValue, dataQuality, importResult); - } - // create Surface data - dataValue = String.valueOf(row.getCellSurface()); - createCellData(cell, dataMetadatas, "Surface", - dataValue, dataQuality, importResult); - - // create NumberOfSamplesRecorded data - if (row.getCellNumberOfSamplesRecorded() != null) { - dataValue = String.valueOf(row.getCellNumberOfSamplesRecorded()); - createCellData(cell, dataMetadatas, "NumberOfSamplesRecorded", - dataValue, dataQuality, importResult); - } - // create NumberOfSamplesEchoIntegrated data - if (row.getCellNumberOfSamplesEchoIntegrated() != null) { - dataValue = String.valueOf(row.getCellNumberOfSamplesEchoIntegrated()); - createCellData(cell, dataMetadatas, "NumberOfSamplesEchoIntegrated", - dataValue, dataQuality, importResult); - } - } - - private DataAcquisition createDataAcquisition(AcousticImportConfiguration configuration, - AcousticInstrument instrument, - String softwareVersion, - String soundSpeedCalculations, - AcousticImportRow row) { - - String transceiverAcquisitionAbsorptionDescription = - configuration.getTransceiverAcquisitionAbsorptionDescription(); - String loggedDataFormat = configuration.getLoggedDataFormat(); - String loggedDataDatatype = configuration.getLoggedDataDatatype(); - String pingDutyCycle = configuration.getPingDutyCycle(); - - DataAcquisition dataAcquisition = persistenceService.createDataAcquisition( - instrument); - - // fill from manual configuration - dataAcquisition.setTransceiverAcquisitionAbsorptionDescription(transceiverAcquisitionAbsorptionDescription); - dataAcquisition.setAcquisitionSoftwareVersion(softwareVersion); - dataAcquisition.setLoggedDataFormat(loggedDataFormat); - dataAcquisition.setLoggedDataDatatype(loggedDataDatatype); - dataAcquisition.setPingDutyCycle(pingDutyCycle); - dataAcquisition.setEchosounderSoundSpeed(row.getSoundCelerity()); - dataAcquisition.setSoundSpeedCalculations(soundSpeedCalculations); - - // fill from csv file - Float transceiverAcquisitionAbsorption = - row.getTransceiverAcquisitionAbsorption(); - Float transducerAcquisitionBeamAngleAthwartship = - row.getTransducerAcquisitionBeamAngleAthwartship(); - Float transducerAcquisitionBeamAngleAlongship = - row.getTransducerAcquisitionBeamAngleAlongship(); - Float transducerAcquisitionPsi = - row.getTransducerAcquisitionPsi(); - Float transceiverAcquisitionPower = - row.getTransceiverAcquisitionPower(); - Float transceiverAcquisitionPulseLength = - row.getTransceiverAcquisitionPulseLength(); - Float transceiverAcquisitionGain = - row.getTransceiverAcquisitionGain(); - Float transceiverAcquisitionSacorrection = - row.getTransceiverAcquisitionSacorrection(); - - dataAcquisition.setTransceiverAcquisitionAbsorption(transceiverAcquisitionAbsorption); - dataAcquisition.setTransducerAcquisitionBeamAngleAthwartship(transducerAcquisitionBeamAngleAthwartship); - dataAcquisition.setTransducerAcquisitionBeamAngleAlongship(transducerAcquisitionBeamAngleAlongship); - dataAcquisition.setTransducerAcquisitionPsi(transducerAcquisitionPsi); - dataAcquisition.setTransceiverAcquisitionPower(transceiverAcquisitionPower); - dataAcquisition.setTransceiverAcquisitionPulseLength(transceiverAcquisitionPulseLength); - dataAcquisition.setTransceiverAcquisitionGain(transceiverAcquisitionGain); - dataAcquisition.setTransceiverAcquisitionSacorrection(transceiverAcquisitionSacorrection); - - return dataAcquisition; - } - - private DataProcessing createDataProcessing(AcousticImportConfiguration configuration, - String id, - String softwareVersion, - String soundSpeedCalculations, - AcousticImportRow row) { - - String transceiverAcquisitionAbsorptionDescription = - configuration.getTransceiverAcquisitionAbsorptionDescription(); - String processingTemplate = configuration.getProcessingTemplate(); - String processingDescription = configuration.getProcessingDescription(); - String sounderConstant = configuration.getSounderConstant(); - float digitThreshold = configuration.getDigitThreshold(); - String acousticDensityUnit = configuration.getAcousticDensityUnit(); - String notes = configuration.getNotes(); - - DataProcessing dataProcessing = persistenceService.createDataProcessing( - id, processingTemplate); - - // fill from manual configuration - dataProcessing.setProcessingDescription(processingDescription); - dataProcessing.setSounderConstant(sounderConstant); - dataProcessing.setDigitThreshold(digitThreshold); - dataProcessing.setAcousticDensityUnit(acousticDensityUnit); - dataProcessing.setNotes(notes); - dataProcessing.setProcessingSoftwareVersion(softwareVersion); - dataProcessing.setTransceiverProcessingAbsorptionDescription(transceiverAcquisitionAbsorptionDescription); - dataProcessing.setEchosounderSoundSpeed(row.getSoundCelerity()); - dataProcessing.setSoundSpeedCalculations(soundSpeedCalculations); - - // fill from csv file - - Float transceiverAcquisitionAbsorption = - row.getTransceiverAcquisitionAbsorption(); - Float transducerAcquisitionBeamAngleAthwartship = - row.getTransducerAcquisitionBeamAngleAthwartship(); - Float transducerAcquisitionBeamAngleAlongship = - row.getTransducerAcquisitionBeamAngleAlongship(); - Float transducerAcquisitionPsi = - row.getTransducerAcquisitionPsi(); - Float transceiverAcquisitionGain = - row.getTransceiverAcquisitionGain(); - Float transceiverAcquisitionSacorrection = - row.getTransceiverAcquisitionSacorrection(); - int eIThresholdLow = row.geteIThresholdLow(); - int eIThresholdHigh = row.geteIThresholdHigh(); - - dataProcessing.seteIThresholdLow(eIThresholdLow); - dataProcessing.seteIThresholdHigh(eIThresholdHigh); - dataProcessing.setTransceiverProcessingSacorrection(transceiverAcquisitionSacorrection); - dataProcessing.setTransceiverProcessingAbsorption(transceiverAcquisitionAbsorption); - dataProcessing.setTransceiverProcessingGain(transceiverAcquisitionGain); - dataProcessing.setTransducerProcessingPsi(transducerAcquisitionPsi); - dataProcessing.setTransducerProcessingBeamAngleAthwartship(transducerAcquisitionBeamAngleAthwartship); - dataProcessing.setTransducerProcessingBeamAngleAlongship(transducerAcquisitionBeamAngleAlongship); - - return dataProcessing; - } - - private void createCellData(Cell cell, - Map<String, DataMetadata> dataMetadatasByName, - String metadataName, - String dataValue, - DataQuality dataQuality, - EchoBaseCsvFileImportResult importResult) { - createCellData( - cell, - dataMetadatasByName.get(metadataName), - dataValue, - dataQuality, - importResult); - } - - private String getSoftwareVersion(AcousticImportConfiguration configuration, - boolean isME70) { - String result; - if (isME70) { - result = configuration.getAcquisitionSoftwareVersionME70(); - } else { - result = configuration.getAcquisitionSoftwareVersionER60(); - } - return result; - } - - private String getSoundSpeedCalculations(AcousticImportConfiguration configuration, - boolean isME70) { - String result; - if (isME70) { - result = configuration.getSoundSpeedCalculationsME70(); - } else { - result = configuration.getSoundSpeedCalculationsER60(); - } - return result; - } - - @Override - protected AcousticImportResult newImportResult(InputFile inputFile) { - return new AcousticImportResult(inputFile.getFileName()); - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CatchesImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CatchesImportService.java deleted file mode 100644 index 97adccb..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CatchesImportService.java +++ /dev/null @@ -1,433 +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; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Collections2; -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.data.Operation; -import fr.ifremer.echobase.entities.data.Operations; -import fr.ifremer.echobase.entities.data.Sample; -import fr.ifremer.echobase.entities.data.SampleData; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.references.SampleDataType; -import fr.ifremer.echobase.entities.references.SampleDataTypeImpl; -import fr.ifremer.echobase.entities.references.SampleDataTypes; -import fr.ifremer.echobase.entities.references.SampleType; -import fr.ifremer.echobase.entities.references.SampleTypeImpl; -import fr.ifremer.echobase.entities.references.SexCategories; -import fr.ifremer.echobase.entities.references.SexCategory; -import fr.ifremer.echobase.entities.references.SizeCategories; -import fr.ifremer.echobase.entities.references.SizeCategory; -import fr.ifremer.echobase.entities.references.Species; -import fr.ifremer.echobase.entities.references.Species2; -import fr.ifremer.echobase.entities.references.SpeciesCategory; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.BiometrySampleImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.BiometrySampleImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.SubSampleImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.SubSampleImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.TotalSampleImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.TotalSampleImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collection; -import java.util.Locale; -import java.util.Map; - -import static org.nuiton.i18n.I18n.l; - -/** - * Service to launch a "catches sample data" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class CatchesImportService extends AbstractImportDataService<CatchesImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(CatchesImportService.class); - - @Override - protected void startImport(CatchesImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - // get all operation for this voyage and this vessel - Collection<Operation> operations = voyage.getAllOperations(); - - // split them by operation Id - Map<String, Operation> operationMap = Maps.uniqueIndex(operations, Operations.OPERATION_ID); - - Map<String, Species> speciesMap = persistenceService.getEntitiesMap(Species.class, Species2.SPECIES_BARACOUDA_CODE); - - Map<String, SizeCategory> sizeCategoryMap = persistenceService.getEntitiesMap(SizeCategory.class, SizeCategories.SIZE_CATEGORY_NAME); - - InputFile totalSampleFile = configuration.getTotalSampleFile(); - if (totalSampleFile.hasFile()) { - - EchoBaseCsvFileImportResult importResult = importTotalSampleFile(configuration, - totalSampleFile, - operationMap, - speciesMap, - sizeCategoryMap); - configuration.addResult(importResult); - - } - - // build for each operation the one with at least one sample typed *total* or *unsorted* - - Collection<Operation> operationWithTotalOrUnsortedSample = Collections2.filter(operations, Operations.OPERATION_WITH_TOTAL_OR_UNSORTED_SAMPLE); - - InputFile subSampleFile = configuration.getSubSampleFile(); - if (subSampleFile.hasFile()) { - - EchoBaseCsvFileImportResult importResult = importSubSampleFile(configuration, - subSampleFile, - operationMap, - operationWithTotalOrUnsortedSample, - speciesMap, - sizeCategoryMap); - configuration.addResult(importResult); - - } - - InputFile biometrySampleFile = configuration.getBiometrySampleFile(); - if (biometrySampleFile.hasFile()) { - - EchoBaseCsvFileImportResult importResult = importBiometrySampleFile(configuration, - biometrySampleFile, - operationMap, - operationWithTotalOrUnsortedSample, - speciesMap); - configuration.addResult(importResult); - - } - } - - private EchoBaseCsvFileImportResult importTotalSampleFile(CatchesImportConfiguration configuration, - InputFile inputFile, - Map<String, Operation> operationMap, - Map<String, Species> speciesMap, - Map<String, SizeCategory> sizeCategoryMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of totalSample from file " + inputFile.getFileName()); - } - - - SampleType sampleTypeTotal = persistenceService.getSampleTypeByName(SampleTypeImpl.TOTAL_SAMPLE_TYPE); - SampleType sampleTypeUnsorted = persistenceService.getSampleTypeByName(SampleTypeImpl.UNSORTED_SAMPLE_TYPE); - SampleType sampleTypeSorted = persistenceService.getSampleTypeByName(SampleTypeImpl.SORTED_SAMPLE_TYPE); - - SampleDataType sampleDataTypeMeanLength = persistenceService.getSampleDataTypeByName(SampleDataTypeImpl.MEAN_LENGTHCM); - SampleDataType sampleDataTypeMeanWeight = persistenceService.getSampleDataTypeByName(SampleDataTypeImpl.MEAN_WEIGHTG); - SampleDataType sampleDataTypeNoPerKg = persistenceService.getSampleDataTypeByName(SampleDataTypeImpl.NO_PER_KG); - - Locale locale = getLocale(); - - try (Reader reader = getInputFileReader(inputFile)) { - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - TotalSampleImportModel csvModel = new TotalSampleImportModel(getCsvSeparator(), operationMap, speciesMap, sizeCategoryMap); - - try (Import<TotalSampleImportRow> importer = Import.newImport(csvModel, reader)) { - - - int rowNumber = 0; - configuration.incrementsProgress(); - for (TotalSampleImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - Operation operation = row.getOperation(); - - Species species = row.getSpecies(); - SizeCategory sizeCategory = row.getSizeCategory(); - - SpeciesCategory category = getSpeciesCategory(species, sizeCategory, null, null, importResult); - - SampleType sampleType; - - if (SizeCategories.IS_HORS_VRAC.apply(sizeCategory)) { - - // hors vrac case - sampleType = sampleTypeUnsorted; - - } else { - // none hors vrac case - sampleType = sampleTypeTotal; - } - - Sample sample = operation.getSample(category, sampleType); - - if (sample != null) { - - // can not have twice same sample - throw new ImportException(l(locale, "echobase.importError.duplicate.sample", - operation.getId(), - sampleType.getName(), - species.getBaracoudaCode(), - sizeCategory.getName())); - } - - - // must create it - - sample = row.getSample(); - sample.setSpeciesCategory(category); - sample.setSampleType(sampleType); - sample = addSample(operation, sample, importResult); - - // create datas - - if (row.getMeanLength() != null) { - - //create meanLength data - addSampleData(sampleDataTypeMeanLength, null, row.getMeanLength(), sample, importResult); - } - - if (row.getMeanWeight() != null) { - - //create meanWeight data - addSampleData(sampleDataTypeMeanWeight, null, row.getMeanWeight(), sample, importResult); - } - - if (row.getNoPerKg() != null) { - - //create noPerKg data - addSampleData(sampleDataTypeNoPerKg, null, row.getNoPerKg(), sample, importResult); - } - - Sample createdSortedSample = persistenceService.newSample(); - createdSortedSample.setSampleType(sampleTypeSorted); - createdSortedSample.setSampleWeight(row.getSortedWeight()); - - // create sorted sample - createdSortedSample = addSample(operation, createdSortedSample, importResult); - } - } - - return importResult; - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(locale, inputFile, e); - } - - } - - private EchoBaseCsvFileImportResult importSubSampleFile(CatchesImportConfiguration configuration, - InputFile inputFile, - Map<String, Operation> operationMap, - Collection<Operation> operationWithTotalOrUnsortedSample, - Map<String, Species> speciesMap, - Map<String, SizeCategory> sizeCategoryMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of subSample from file " + inputFile.getFileName()); - } - - Map<String, SexCategory> sexCategoryMap = persistenceService.getEntitiesMap(SexCategory.class, SexCategories.SEX_CATEGORY_NAME); - SampleType sampleTypeSubsample = persistenceService.getSampleTypeByName(SampleTypeImpl.SUB_SAMPLE_TYPE); - SampleDataType sampleDataTypeNumberAtLength = persistenceService.getSampleDataTypeByName(SampleDataTypeImpl.NUMBER_AT_LENGTH); - SampleDataType sampleDataTypeNumberAtLength05cm = persistenceService.getSampleDataTypeByName(SampleDataTypeImpl.LTCM0_5); - SampleDataType sampleDataTypeNumberAtLength1cm = persistenceService.getSampleDataTypeByName(SampleDataTypeImpl.L_TCM_1); - SampleDataType sampleDataTypeWeightAtLength = persistenceService.getSampleDataTypeByName(SampleDataTypeImpl.WEIGHT_AT_LENGTHKG); - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - try (Reader reader = getInputFileReader(inputFile)) { - - SubSampleImportModel csvModel = new SubSampleImportModel(getCsvSeparator(), - operationMap, - speciesMap, - sizeCategoryMap, - sexCategoryMap); - - try (Import<SubSampleImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (SubSampleImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - Operation operation = row.getOperation(); - - checkOperationWithTotalOrUnsortedSample(rowNumber, operationWithTotalOrUnsortedSample, operation); - - Species species = row.getSpecies(); - SizeCategory sizeCategory = row.getSizeCategory(); - SexCategory sexCategory = row.getSexCategory(); - - SpeciesCategory category = getSpeciesCategory(species, sizeCategory, null, sexCategory, importResult); - - // find the sample with this category - Sample sample = operation.getSample(category, sampleTypeSubsample); - - if (sample == null) { - - // must create it - sample = row.getSample(); - - sample.setSpeciesCategory(category); - sample.setSampleType(sampleTypeSubsample); - - sample = addSample(operation, sample, importResult); - } - - Integer round = row.getRound(); - SampleDataType dataType = sampleDataTypeNumberAtLength; - - if (round == null) { - dataType = sampleDataTypeNumberAtLength; - } else if (round == 5) { - dataType = sampleDataTypeNumberAtLength05cm; - } else if (round == 1) { - dataType = sampleDataTypeNumberAtLength1cm; - } - - //create numberAtLength data - addSampleData(dataType, "" + row.getLengthClass(), row.getNumberAtLength(), sample, importResult); - - if (row.getWeightAtLength() != null) { - - //create weightAtLength data - addSampleData(sampleDataTypeWeightAtLength, "" + row.getLengthClass(), row.getWeightAtLength(), sample, importResult); - } - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - } - - private void checkOperationWithTotalOrUnsortedSample(int rowNumber, Collection<Operation> operationWithTotalOrUnsortedSample, Operation operation) throws ImportException { - if (!operationWithTotalOrUnsortedSample.contains(operation)) { - - // can not accept this import - throw new ImportException("At line " + rowNumber + ", wants to add a subsample sample but operation " + operation.getId() + " has no sample of type *Total*, nor *Unsorted*"); - } - } - - private EchoBaseCsvFileImportResult importBiometrySampleFile(CatchesImportConfiguration configuration, - InputFile inputFile, - Map<String, Operation> operationMap, - Collection<Operation> operationWithTotalOrUnsortedSample, Map<String, Species> speciesMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of biometrySample from file " + inputFile.getFileName()); - } - - try (Reader reader = getInputFileReader(inputFile)) { - - Map<String, SampleDataType> sampleDataTypeMap = persistenceService.getEntitiesMap(SampleDataType.class, SampleDataTypes.SAMPLE_DATA_TYPE_NAME); - SampleType sampleTypeIndividual = persistenceService.getSampleTypeByName(SampleTypeImpl.INDIVIDUAL_SAMPLE_TYPE); - Map<String, Sample> samples = Maps.newTreeMap(); - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - BiometrySampleImportModel csvModel = new BiometrySampleImportModel(getCsvSeparator(), - operationMap, - speciesMap, - sampleDataTypeMap); - - try (Import<BiometrySampleImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (BiometrySampleImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Operation operation = row.getOperation(); - - checkOperationWithTotalOrUnsortedSample(rowNumber, operationWithTotalOrUnsortedSample, operation); - - Species species = row.getSpecies(); - - int numFish = row.getNumFish(); - - String sampleKey = operation.getId() + "_" + species.getBaracoudaCode() + "_" + numFish; - - Sample sample = samples.get(sampleKey); - - if (sample == null) { - - // create a new sample - sample = persistenceService.newSample(); - - sample.setSampleType(sampleTypeIndividual); - - SpeciesCategory category = getSpeciesCategory(species, null, null, null, importResult); - - sample.setSpeciesCategory(category); - - sample = addSample(operation, sample, importResult); - - samples.put(sampleKey, sample); - } - - SampleData sampleData = row.getSampleData(); - - SampleData sampleDataCreated = persistenceService.createSampleData(sampleData); - sample.addSampleData(sampleDataCreated); - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.SampleData); - - } - } - - return importResult; - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - - } - } - - private Sample addSample(Operation operation, Sample sample, EchoBaseCsvFileImportResult importResult) { - - Preconditions.checkNotNull(operation); - Preconditions.checkNotNull(sample); - Sample result = persistenceService.createSample(sample); - operation.addSample(result); - importResult.addId(EchoBaseUserEntityEnum.Sample, sample); - return result; - - } - - private SampleData addSampleData(SampleDataType sampleDataType, String label, float value, Sample sample, EchoBaseCsvFileImportResult importResult) { - - SampleData sampleData = persistenceService.createSampleData(sampleDataType, label, value); - sample.addSampleData(sampleData); - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.SampleData); - return sampleData; - - } - -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonAllImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonAllImportService.java deleted file mode 100644 index 0bb4e3a..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonAllImportService.java +++ /dev/null @@ -1,68 +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; - -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.references.Vessel; -import fr.ifremer.echobase.entities.references.Vessels; - -import javax.inject.Inject; -import java.util.Map; - -/** - * Service to launch a "common all data" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class CommonAllImportService extends AbstractImportDataService<CommonImportConfiguration> { - - @Inject - CommonVoyageImportService commonVoyageImportService; - - @Inject - CommonTransitImportService commonTransitImportService; - - @Inject - CommonTransectImportService commonTransectImportService; - - @Override - protected void startImport(CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - // get usable vessels - Map<String, Vessel> vesselMap = persistenceService.getEntitiesMap(Vessel.class, Vessels.VESSEL_NAME); - - { - EchoBaseCsvFileImportResult result = commonVoyageImportService.importFile(configuration); - configuration.addResult(result); - } - { - EchoBaseCsvFileImportResult result = commonTransitImportService.importFile(configuration, false); - configuration.addResult(result); - } - { - EchoBaseCsvFileImportResult result = commonTransectImportService.importFile(vesselMap, configuration, false); - configuration.addResult(result); - } - - } - -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonImportService.java deleted file mode 100644 index 43b3055..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonImportService.java +++ /dev/null @@ -1,101 +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; - -import com.google.common.base.Preconditions; -import fr.ifremer.echobase.EchoBaseTechnicalException; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.ImportType; -import fr.ifremer.echobase.entities.references.Mission; -import org.nuiton.topia.persistence.TopiaException; - -import javax.inject.Inject; - -/** - * Service to launch a "common data" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class CommonImportService extends AbstractImportDataService<CommonImportConfiguration> { - - @Inject - CommonAllImportService commonAllImportService; - - @Inject - CommonVoyageImportService commonVoyageImportService; - - @Inject - CommonTransitImportService commonTransitImportService; - - @Inject - CommonTransectImportService commonTransectImportService; - - @Override - public void startImport(CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - ImportType importMode = configuration.getImportType(); - - AbstractImportDataService<CommonImportConfiguration> service; - - switch (importMode) { - - case COMMON_ALL: - service = commonAllImportService; - break; - - case COMMON_VOYAGE: - service = commonVoyageImportService; - break; - - case COMMON_TRANSIT: - service = commonTransitImportService; - break; - - case COMMON_TRANSECT: - service = commonTransectImportService; - break; - - default: - throw new EchoBaseTechnicalException("Can not treate import result of type " + importMode); - } - service.startImport(configuration, user); - } - - public Mission createMission(Mission mission) throws MissionNameAlreadyExistException { - - Preconditions.checkNotNull(mission); - - try { - // check mission name is unique - boolean exists = persistenceService.isMissionExistByName(mission.getName()); - - if (exists) { - throw new MissionNameAlreadyExistException(); - } - Mission result = persistenceService.createMission(mission); - persistenceService.commit(); - return result; - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException(eee); - } - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonTransectImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonTransectImportService.java deleted file mode 100644 index 1abe541..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonTransectImportService.java +++ /dev/null @@ -1,137 +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; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -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.data.Voyages; -import fr.ifremer.echobase.entities.references.Vessel; -import fr.ifremer.echobase.entities.references.Vessels; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.TransectImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.TransectImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collections; -import java.util.Date; -import java.util.Map; - -import static org.nuiton.i18n.I18n.l; - -/** - * Service to launch a "common transect data" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class CommonTransectImportService extends AbstractImportDataService<CommonImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(CommonTransectImportService.class); - - @Override - protected void startImport(CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - // get usable vessels - Map<String, Vessel> vesselMap = persistenceService.getEntitiesMap(Vessel.class, Vessels.VESSEL_NAME); - - EchoBaseCsvFileImportResult importResult; - - importResult = importFile(vesselMap, configuration, true); - configuration.addResult(importResult); - } - - protected EchoBaseCsvFileImportResult importFile(Map<String, Vessel> vesselMap, CommonImportConfiguration configuration, boolean collectIds) throws ImportException { - - InputFile inputFile = configuration.getTransectFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of transects from file " + inputFile.getFileName()); - } - - try (Reader reader = getInputFileReader(inputFile)) { - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - // get voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - // restrict voyage to use to this voyage - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - String datum = configuration.getDatum(); - String license = configuration.getTransectLicence(); - String geospatialVerticalPositive = configuration.getTransectGeospatialVerticalPositive(); - String binUnitsPingAxis = configuration.getTransectBinUnitsPingAxis(); - - TransectImportModel csvModel = new TransectImportModel(getCsvSeparator(), voyageMap, vesselMap); - try (Import<TransectImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - for (TransectImportRow row : importer) { - - configuration.incrementsProgress(); - Transect transect = row.getTransect(); - - Date timeCoverageStart = transect.getTimeCoverageStart(); - Date timeCoverageEnd = transect.getTimeCoverageEnd(); - - Transit transit = voyage.getTransit(timeCoverageStart, timeCoverageEnd); - if (transit == null) { - throw new ImportException(l(getLocale(), "echobase.importError.no.transit.between.date", voyage.getName(), timeCoverageStart, timeCoverageEnd)); - } - - transect.setDatum(datum); - transect.setLicence(license); - transect.setGeospatialVerticalPositive(geospatialVerticalPositive); - transect.setBinUnitsPingAxis(binUnitsPingAxis); - - Transect createdTransect = persistenceService.createTransect(transect); - - transit.addTransect(createdTransect); - - if (collectIds) { - - // collect id of the import - importResult.addId(EchoBaseUserEntityEnum.Transect, createdTransect); - } else { - - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.Transect); - } - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonTransitImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonTransitImportService.java deleted file mode 100644 index 1355995..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonTransitImportService.java +++ /dev/null @@ -1,113 +0,0 @@ -package fr.ifremer.echobase.services.service.importdata; - -/* - * #%L - * EchoBase :: Services - * %% - * Copyright (C) 2011 - 2013 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 com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.data.Transit; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.data.Voyages; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.TransitImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.TransitImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collections; -import java.util.Map; - -/** - * Service to launch a "common transit data" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.2 - */ -public class CommonTransitImportService extends AbstractImportDataService<CommonImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(CommonTransitImportService.class); - - @Override - protected void startImport(CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - EchoBaseCsvFileImportResult importResult = importFile(configuration, true); - configuration.addResult(importResult); - - } - - protected EchoBaseCsvFileImportResult importFile(CommonImportConfiguration configuration, boolean collectIds) throws ImportException { - - InputFile inputFile = configuration.getTransitFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of transits from file " + inputFile.getFileName()); - } - - try (Reader reader = getInputFileReader(inputFile)) { - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - // get voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - // restrict voyage to use to this voyage - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - String relatedActivity = configuration.getTransitRelatedActivity(); - - TransitImportModel csvModel = new TransitImportModel(getCsvSeparator(), voyageMap); - try (Import<TransitImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - for (TransitImportRow row : importer) { - - configuration.incrementsProgress(); - Transit transit = row.getTransit(); - - transit.setRelatedActivity(relatedActivity); - - Transit createdTransit = persistenceService.createTransit(transit); - - voyage.addTransit(createdTransit); - - if (collectIds) { - - // collect id of the import - importResult.addId(EchoBaseUserEntityEnum.Transit, createdTransit); - - } else { - - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.Transit); - } - } - } - return importResult; - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonVoyageImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonVoyageImportService.java deleted file mode 100644 index 15a80ef..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/CommonVoyageImportService.java +++ /dev/null @@ -1,121 +0,0 @@ -package fr.ifremer.echobase.services.service.importdata; - -/* - * #%L - * EchoBase :: Services - * %% - * Copyright (C) 2011 - 2013 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.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.references.AreaOfOperation; -import fr.ifremer.echobase.entities.references.Mission; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.VoyageImportModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportModel; -import org.nuiton.csv.ImportRuntimeException; - -import java.io.IOException; -import java.io.Reader; -import java.util.Locale; - -/** - * Service to launch a "common voyage data" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.2 - */ -public class CommonVoyageImportService extends AbstractImportDataService<CommonImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(CommonVoyageImportService.class); - - @Override - protected void startImport(CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - EchoBaseCsvFileImportResult importResult = importFile(configuration); - configuration.addResult(importResult); - - } - - protected EchoBaseCsvFileImportResult importFile(CommonImportConfiguration configuration) throws ImportException { - - InputFile inputFile = configuration.getVoyageFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of voyages from file " + inputFile.getFileName()); - } - - Mission mission = persistenceService.getMission(configuration.getMissionId()); - AreaOfOperation areaOfOperation = persistenceService.getAreaOfOperation(configuration.getAreaOfOperationId()); - String voyageDescription = configuration.getVoyageDescription(); - String datum = configuration.getDatum(); - Locale locale = getLocale(); - - try (Reader reader = getInputFileReader(inputFile)) { - - Voyage newVoyage = null; - - EchoBaseCsvFileImportResult result = newImportResult(inputFile); - ImportModel<Voyage> csvModel = new VoyageImportModel(getCsvSeparator()); - try (Import<Voyage> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - for (Voyage voyage : importer) { - - configuration.incrementsProgress(); - - voyage.setMission(mission); - voyage.setAreaOfOperation(areaOfOperation); - voyage.setDescription(voyageDescription); - voyage.setDatum(datum); - - Voyage createdVoyage = persistenceService.createVoyage(voyage); - if (newVoyage == null) { - newVoyage = createdVoyage; - } else { - // this means a voyage file with more than one row not possible... - - throw new MoreThanOnceVoyageToImportException(locale); - } - - // collect id of the import - result.addId(EchoBaseUserEntityEnum.Voyage, voyage); - - } - } - - if (newVoyage == null) { - throw new NoVoyageToImportException(locale); - } - - // push back to id of the voyage in configuration for next imports - configuration.setVoyageId(newVoyage.getTopiaId()); - - return result; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(locale, inputFile, e); - } - - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/EchoBaseCsvFileImportResult.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/EchoBaseCsvFileImportResult.java deleted file mode 100644 index a95c6d1..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/EchoBaseCsvFileImportResult.java +++ /dev/null @@ -1,60 +0,0 @@ -package fr.ifremer.echobase.services.service.importdata; - -/* - * #%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% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.ImportLog; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.service.csv.in.CsvFileImportResult; - -import java.util.List; - -/** - * {@link CsvFileImportResult} with support for ids to keep in the - * {@link ImportLog#getImportId()}. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.2 - */ -public class EchoBaseCsvFileImportResult extends CsvFileImportResult<EchoBaseUserEntityEnum> { - - private static final long serialVersionUID = 1L; - - protected final List<String> ids; - - public EchoBaseCsvFileImportResult(String importFileName) { - super(importFileName, EchoBaseUserEntityEnum.values()); - ids = Lists.newArrayList(); - } - - public <E extends TopiaEntity> void addId(EchoBaseUserEntityEnum entityEnum, E... entities) { - for (E entity : entities) { - this.ids.add(entity.getTopiaId()); - incrementsNumberCreated(entityEnum); - } - } - - public List<String> getIds() { - return ids; - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ImportDataResult.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ImportDataResult.java index 43365aa..98274e4 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ImportDataResult.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ImportDataResult.java @@ -15,12 +15,14 @@ public class ImportDataResult<C extends AbstractImportConfiguration> { private final C configuration; private final EchoBaseUser user; + private final String importSummary; private final Set<ImportDataFileResult> importResults; - public ImportDataResult(C configuration, EchoBaseUser user, Set<ImportDataFileResult> importResults) { + public ImportDataResult(C configuration, EchoBaseUser user, Set<ImportDataFileResult> importResults, String importSummary) { this.configuration = configuration; this.user = user; + this.importSummary = importSummary; this.importResults = Collections.unmodifiableSet(importResults); } @@ -35,4 +37,8 @@ public class ImportDataResult<C extends AbstractImportConfiguration> { public Set<ImportDataFileResult> getImportResults() { return importResults; } + + public String getImportSummary() { + return importSummary; + } } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ImportDataService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ImportDataService.java index 003ef6f..d16f1ba 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ImportDataService.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ImportDataService.java @@ -40,12 +40,14 @@ import org.nuiton.util.TimeLog; import javax.inject.Inject; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.regex.Pattern; import static org.nuiton.i18n.I18n.l; @@ -56,18 +58,18 @@ import static org.nuiton.i18n.I18n.l; */ public class ImportDataService extends EchoBaseServiceSupport { -// public static final Pattern REMOVE_DOUBLE_QUOTES_PATTERN = Pattern.compile("\"(.+)\""); + public static final Pattern REMOVE_DOUBLE_QUOTES_PATTERN = Pattern.compile("\"(.+)\""); /** Logger. */ - private static final Log log = LogFactory.getLog(AbstractImportDataService.class); + private static final Log log = LogFactory.getLog(ImportDataService.class); - public static final TimeLog TIME_LOG = new TimeLog(AbstractImportDataService.class); + public static final TimeLog TIME_LOG = new TimeLog(ImportDataService.class); @Inject protected UserDbPersistenceService persistenceService; - public String doImportCommons(CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<CommonImportConfiguration> doImportCommons(CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { Collection<AbstractImportAction> importActions = new LinkedHashSet<>(); ImportType importMode = configuration.getImportType(); @@ -114,7 +116,7 @@ public class ImportDataService extends EchoBaseServiceSupport { } - public String doImportOperations(OperationImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<OperationImportConfiguration> doImportOperations(OperationImportConfiguration configuration, EchoBaseUser user) throws ImportException { Collection<AbstractImportAction> importActions = new LinkedHashSet<>(); OperationImportAction operationImportAction = new OperationImportAction(getLocale(), getCsvSeparator(), persistenceService, configuration, user); @@ -130,7 +132,7 @@ public class ImportDataService extends EchoBaseServiceSupport { } - public String doImportCatches(CatchesImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<CatchesImportConfiguration> doImportCatches(CatchesImportConfiguration configuration, EchoBaseUser user) throws ImportException { Collection<AbstractImportAction> importActions = new LinkedHashSet<>(); @@ -159,7 +161,7 @@ public class ImportDataService extends EchoBaseServiceSupport { } - public String doImportAcoustics(AcousticImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<AcousticImportConfiguration> doImportAcoustics(AcousticImportConfiguration configuration, EchoBaseUser user) throws ImportException { AcousticImportAction acousticImportAction = new AcousticImportAction(getLocale(), getCsvSeparator(), persistenceService, configuration, user); Set<AcousticImportAction> importActions = Collections.singleton(acousticImportAction); @@ -167,7 +169,7 @@ public class ImportDataService extends EchoBaseServiceSupport { } - public String doImportResults(ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<ResultsImportConfiguration> doImportResults(ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { Collection<AbstractImportAction> importActions = new LinkedHashSet<>(); @@ -275,7 +277,7 @@ public class ImportDataService extends EchoBaseServiceSupport { } - protected <M extends AbstractImportConfiguration, A extends AbstractImportAction> String doImport(M configuration, EchoBaseUser user, Collection<A> importActions) throws ImportException { + protected <M extends AbstractImportConfiguration, A extends AbstractImportAction> ImportDataResult<M> doImport(M configuration, EchoBaseUser user, Collection<A> importActions) throws ImportException { long s0 = TimeLog.getTime(); @@ -296,29 +298,28 @@ public class ImportDataService extends EchoBaseServiceSupport { importDataFileResults.add(importDataFileResult); } - ImportDataResult<M> importDataResult = new ImportDataResult<>(configuration, user, importDataFileResults); s0 = TIME_LOG.log(s0, "importDone"); // add result in log book and compute resume to show in result - String result = computeResultAndLogBookEntry(importDataResult); + String importSummary = computeResultAndLogBookEntry(configuration, user, importDataFileResults); + + ImportDataResult<M> importDataResult = new ImportDataResult<>(configuration, user, importDataFileResults, importSummary); // do commit persistenceService.commit(); TIME_LOG.log(s0, "importCommited"); - return result; + return importDataResult; } catch (EchoBaseTechnicalException e) { throw new ImportException(e.getMessage(), e); } } - public <M extends AbstractImportConfiguration> ImportLog computeImportLogEntry(ImportDataResult<M> result) { + protected <M extends AbstractImportConfiguration> String computeResultAndLogBookEntry(M configuration, EchoBaseUser user, Set<ImportDataFileResult> importDataFileResults) { - EchoBaseUser user = result.getUser(); - M configuration = result.getConfiguration(); Date importDate = newDate(); String importUser = user.getEmail(); @@ -330,7 +331,7 @@ public class ImportDataService extends EchoBaseServiceSupport { List<String> importIds = Lists.newArrayList(); - for (ImportDataFileResult importResult : result.getImportResults()) { + for (ImportDataFileResult importResult : importDataFileResults) { InputFile importFile = importResult.getImportFile(); @@ -372,15 +373,19 @@ public class ImportDataService extends EchoBaseServiceSupport { importText, importIds); - for (ImportDataFileResult importDataFileResult : result.getImportResults()) { + for (ImportDataFileResult importDataFileResult : importDataFileResults) { ImportFile importFile = createImportFile(importDataFileResult.getImportFile(), importDataFileResult.getExportFile()); importLog.addImportFile(importFile); - } - return importLog; + String importType = getImportLabel(configuration); + + String result = importLog.getImportText(); + + persistenceService.createEntityModificationLog("Import", importType, importUser, importDate, result); + return result; } @@ -395,8 +400,6 @@ public class ImportDataService extends EchoBaseServiceSupport { buffer.append("Notes :").append(configuration.getImportNotes()).append('\n'); } - List<String> importIds = Lists.newArrayList(); - String importText = buffer.toString().trim(); return persistenceService.createImportLog(configuration.getVoyageId(), @@ -404,13 +407,13 @@ public class ImportDataService extends EchoBaseServiceSupport { importUser, importDate, importText, - importIds); + new ArrayList<>()); } - protected ImportFile createImportFile(InputFile importFile, InputFile checkFile) { + protected ImportFile createImportFile(InputFile importFile, InputFile checkFile) { - ImportFile result= persistenceService.createImportFile(importFile, checkFile); + ImportFile result = persistenceService.createImportFile(importFile, checkFile); if (log.isInfoEnabled()) { try { @@ -428,83 +431,49 @@ public class ImportDataService extends EchoBaseServiceSupport { } -// protected void addImportFiles(ImportLog importLog, InputFile... inputFiles) { -// -// for (InputFile inputFile : inputFiles) { -// -// ImportFile importFile = persistenceService.createImportFile(inputFile); -// -// if (log.isInfoEnabled()) { -// try { -// log.info("Add ImportFile: " + importFile.getName() + " - size: " + importFile.getFile().length()); -// } catch (SQLException e) { -// throw new EchoBaseTechnicalException("Can't get length of importFile " + importFile.getName()); -// } -// } -// importLog.addImportFile(importFile); -// -// } -// -// } - - protected <M extends AbstractImportConfiguration> String computeResultAndLogBookEntry(ImportDataResult<M> importDataResult) { - - Date importDate = newDate(); - String importUser = importDataResult.getUser().getEmail(); - - ImportLog importLog = computeImportLogEntry(importDataResult); - - String importType = getImportLabel(importDataResult.getConfiguration()); - - String result = importLog.getImportText(); - - persistenceService.createEntityModificationLog("Import", importType, importUser, importDate, result); - return result; - - } - protected <M extends AbstractImportConfiguration> String getImportLabel(M configuration) { return l(getLocale(), configuration.getImportType().getI18nKey()); } public interface ImportDataAction<M extends AbstractImportConfiguration> { - String doImport(ImportDataService service, M configuration, EchoBaseUser user) throws ImportException; + ImportDataResult<M> doImport(ImportDataService service, M configuration, EchoBaseUser user) throws ImportException; } public static class AcousticImportDataAction implements ImportDataAction<AcousticImportConfiguration> { @Override - public String doImport(ImportDataService service, AcousticImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<AcousticImportConfiguration> doImport(ImportDataService service, AcousticImportConfiguration configuration, EchoBaseUser user) throws ImportException { return service.doImportAcoustics(configuration, user); } } public static class CommonImportDataAction implements ImportDataAction<CommonImportConfiguration> { @Override - public String doImport(ImportDataService service, CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<CommonImportConfiguration> doImport(ImportDataService service, CommonImportConfiguration configuration, EchoBaseUser user) throws ImportException { return service.doImportCommons(configuration, user); } } public static class OperationsImportDataAction implements ImportDataAction<OperationImportConfiguration> { @Override - public String doImport(ImportDataService service, OperationImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<OperationImportConfiguration> doImport(ImportDataService service, OperationImportConfiguration configuration, EchoBaseUser user) throws ImportException { return service.doImportOperations(configuration, user); } } public static class ResultsImportDataAction implements ImportDataAction<ResultsImportConfiguration> { @Override - public String doImport(ImportDataService service, ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<ResultsImportConfiguration> doImport(ImportDataService service, ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { return service.doImportResults(configuration, user); } } public static class CatchesImportDataAction implements ImportDataAction<CatchesImportConfiguration> { @Override - public String doImport(ImportDataService service, CatchesImportConfiguration configuration, EchoBaseUser user) throws ImportException { + public ImportDataResult<CatchesImportConfiguration> doImport(ImportDataService service, CatchesImportConfiguration configuration, EchoBaseUser user) throws ImportException { return service.doImportCatches(configuration, user); } } + } diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/OperationImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/OperationImportService.java deleted file mode 100644 index a567868..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/OperationImportService.java +++ /dev/null @@ -1,254 +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; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.data.GearMetadataValue; -import fr.ifremer.echobase.entities.data.Operation; -import fr.ifremer.echobase.entities.data.OperationMetadataValue; -import fr.ifremer.echobase.entities.data.Operations; -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.DepthStratum; -import fr.ifremer.echobase.entities.references.DepthStratums; -import fr.ifremer.echobase.entities.references.Gear; -import fr.ifremer.echobase.entities.references.GearMetadata; -import fr.ifremer.echobase.entities.references.GearMetadatas; -import fr.ifremer.echobase.entities.references.Gears; -import fr.ifremer.echobase.entities.references.OperationMetadata; -import fr.ifremer.echobase.entities.references.OperationMetadatas; -import fr.ifremer.echobase.entities.references.Vessel; -import fr.ifremer.echobase.entities.references.Vessels; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.GearMetadataValueImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.GearMetadataValueImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.OperationImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.OperationImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.OperationMetadataValueImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.OperationMetadataValueImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collection; -import java.util.Date; -import java.util.Map; - -/** - * Service to launch a "operations" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class OperationImportService extends AbstractImportDataService<OperationImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(OperationImportService.class); - - @Override - protected void startImport(OperationImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - // get selected voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - // get usable vessels from the voyage by their name - Map<String, Vessel> vesselMap = Maps.uniqueIndex(voyage.getAllVessels(), Vessels.VESSEL_NAME); - - // get usable gears by their casino gear name - Map<String, Gear> gearMap = persistenceService.getEntitiesMap(Gear.class, Gears.GEAR_CASINO_GEAR_NAME); - - { - EchoBaseCsvFileImportResult result = importOperationFile(configuration, - voyage, - vesselMap, - gearMap); - configuration.addResult(result); - } - - // get all operation for this voyage and this vessel - Collection<Operation> operations = voyage.getAllOperations(); - - // split them by operation Id - Map<String, Operation> operationMap = Maps.uniqueIndex(operations, Operations.OPERATION_ID); - - { - EchoBaseCsvFileImportResult result = importOperationMetadataFile(configuration, - vesselMap, - operationMap); - configuration.addResult(result); - } - { - EchoBaseCsvFileImportResult result = importGearMetadataFile(configuration, - vesselMap, - gearMap, - operationMap); - configuration.addResult(result); - } - } - - protected EchoBaseCsvFileImportResult importOperationFile(OperationImportConfiguration configuration, - Voyage voyage, - Map<String, Vessel> vesselMap, - Map<String, Gear> gearMap) throws ImportException { - - InputFile inputFile = configuration.getOperationFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of operation from file " + inputFile.getFileName()); - } - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - Map<String, DepthStratum> depthStratumMap = persistenceService.getEntitiesMap(DepthStratum.class, DepthStratums.DEPTH_STRATUM_ID); - - try (Reader reader = getInputFileReader(inputFile)) { - - OperationImportModel csvModel = new OperationImportModel(getCsvSeparator(), vesselMap, gearMap, depthStratumMap); - try (Import<OperationImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (OperationImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - Vessel vessel = row.getVessel(); - - Operation operation = row.getOperation(); - - Date startTime = operation.getGearShootingStartTime(); - Date endTime = operation.getGearShootingEndTime(); - - Transit transit = voyage.getTransit(startTime, endTime); - - Transect transect = transit.getTransect(vessel); - - Operation createdOperation = persistenceService.createOperation(operation); - - // collect ids - importResult.addId(EchoBaseUserEntityEnum.Operation, createdOperation); - - transect.addOperation(createdOperation); - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - - } - } - - protected EchoBaseCsvFileImportResult importOperationMetadataFile(OperationImportConfiguration configuration, - Map<String, Vessel> vesselMap, - Map<String, Operation> operationMap) throws ImportException { - - InputFile inputFile = configuration.getOperationMetadataFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of operation metadata values from file " + inputFile.getFileName()); - } - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - Map<String, OperationMetadata> operationMetadatasByName = persistenceService.getEntitiesMap(OperationMetadata.class, OperationMetadatas.OPERATION_METADATA_NAME); - - try (Reader reader = getInputFileReader(inputFile)) { - - OperationMetadataValueImportModel csvModel = new OperationMetadataValueImportModel(getCsvSeparator(), vesselMap, operationMetadatasByName, operationMap); - try (Import<OperationMetadataValueImportRow> importer = Import.newImport(csvModel, reader)) { - - int rowNumber = 0; - configuration.incrementsProgress(); - for (OperationMetadataValueImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - Operation operation = row.getOperation(); - - OperationMetadataValue operationMetadataValueToCreate = row.getOperationMetadataValue(); - OperationMetadataValue operationMetadataValue = persistenceService.createOperationMetadataValue(operationMetadataValueToCreate); - - operation.addOperationMetadataValue(operationMetadataValue); - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.OperationMetadataValue); - - } - } - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - } - - protected EchoBaseCsvFileImportResult importGearMetadataFile(OperationImportConfiguration configuration, - Map<String, Vessel> vesselMap, - Map<String, Gear> gearMap, - Map<String, Operation> operationMap) throws ImportException { - - InputFile inputFile = configuration.getGearMetadataFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of gear metadata values from file " + inputFile.getFileName()); - } - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - Map<String, GearMetadata> gearMetadatasByType = persistenceService.getEntitiesMap(GearMetadata.class, GearMetadatas.GEAR_METADATA_NAME); - - try (Reader reader = getInputFileReader(inputFile)) { - - GearMetadataValueImportModel csvModel = new GearMetadataValueImportModel(getCsvSeparator(), - vesselMap, - gearMetadatasByType, - gearMap, - operationMap); - - try (Import<GearMetadataValueImportRow> importer = Import.newImport(csvModel, reader)) { - - int rowNumber = 0; - configuration.incrementsProgress(); - for (GearMetadataValueImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - Operation operation = row.getOperation(); - - GearMetadataValue gearMetadataValuetoCreate = row.getGearMetadataValue(); - GearMetadataValue gearMetadataValue = persistenceService.createGearMetadataValue(gearMetadataValuetoCreate); - - operation.addGearMetadataValue(gearMetadataValue); - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.GearMetadataValue); - - } - } - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsEsduCellImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsEsduCellImportService.java deleted file mode 100644 index b7074fa..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsEsduCellImportService.java +++ /dev/null @@ -1,433 +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; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -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.Cells; -import fr.ifremer.echobase.entities.data.DataProcessing; -import fr.ifremer.echobase.entities.data.Echotype; -import fr.ifremer.echobase.entities.data.Echotypes; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.data.Voyages; -import fr.ifremer.echobase.entities.references.AgeCategories; -import fr.ifremer.echobase.entities.references.AgeCategory; -import fr.ifremer.echobase.entities.references.DataMetadata; -import fr.ifremer.echobase.entities.references.DataMetadatas; -import fr.ifremer.echobase.entities.references.DataQualities; -import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.entities.references.SizeCategories; -import fr.ifremer.echobase.entities.references.SizeCategory; -import fr.ifremer.echobase.entities.references.Species; -import fr.ifremer.echobase.entities.references.Species2; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.EsduResultByEchotypeAndSpeciesCategoryImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.EsduResultByEchotypeAndSpeciesCategoryImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.EsduResultByEchotypeImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.EsduResultByEchotypeImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.EsduResultBySpeciesAndAgeCategoryImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.EsduResultBySpeciesAndAgeCategoryImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.EsduResultBySpeciesAndSizeCategoryImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.EsduResultBySpeciesAndSizeCategoryImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.csv.ext.CsvReaders; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * To import results attached to a voyage (but not cells). - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class ResultsEsduCellImportService extends AbstractImportDataService<ResultsImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ResultsEsduCellImportService.class); - - @Override - public void startImport(ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - Map<String, Species> speciesMap = persistenceService.getEntitiesMap(Species.class, Species2.SPECIES_BARACOUDA_CODE); - - Map<String, SizeCategory> sizeCategoryMap = Maps.newTreeMap(); - sizeCategoryMap.putAll(persistenceService.getEntitiesMap(SizeCategory.class, SizeCategories.SIZE_CATEGORY_NAME)); - - Map<String, AgeCategory> ageCategoryMap = Maps.newTreeMap(); - ageCategoryMap.putAll(persistenceService.getEntitiesMap(AgeCategory.class, AgeCategories.AGE_CATEGORY_NAME)); - - Map<String, DataMetadata> dataMetadataMap = persistenceService.getEntitiesMap(DataMetadata.class, DataMetadatas.DATA_METADATA_NAME); - - Map<String, DataQuality> dataQualityMap = persistenceService.getEntitiesMap(DataQuality.class, DataQualities.DATA_QUALITY_NAME); - - // get selected voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - // get selected dataProcessing - DataProcessing dataProcessing = persistenceService.getDataProcessing(configuration.getDataProcessingId()); - - // authorize only the selected voyage to be imported - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - // get esdu cells usables - Map<String, Cell> esduCellMap = Maps.uniqueIndex(dataProcessing.getCell(), Cells.CELL_BY_NAME); - - // index all echotypes of this voyage - Map<String, Echotype> echotypeMap = Maps.uniqueIndex(voyage.getEchotype(), Echotypes.ECHOTYPE_NAME); - - if (configuration.getEsduByEchotypeFile().hasFile()) { - - EchoBaseCsvFileImportResult result = importByEchotypeFile(configuration, - configuration.getEsduByEchotypeFile(), - voyage, - voyageMap, - echotypeMap, - dataMetadataMap, - esduCellMap, - dataQualityMap); - configuration.addResult(result); - - } - - if (configuration.getEsduByEchotypeAndSpeciesCategoryFile().hasFile()) { - - EchoBaseCsvFileImportResult result = importByEchotypeAndSpeciesCategoryFile(configuration, - configuration.getEsduByEchotypeAndSpeciesCategoryFile(), - voyage, - voyageMap, - echotypeMap, - dataMetadataMap, - speciesMap, - sizeCategoryMap, - esduCellMap, - dataQualityMap); - configuration.addResult(result); - - } - if (configuration.getEsduBySpeciesAndSizeCategoryFile().hasFile()) { - - EchoBaseCsvFileImportResult result = importBySpeciesAndSizeCategoryFile(configuration, - configuration.getEsduBySpeciesAndSizeCategoryFile(), - voyage, - voyageMap, - dataMetadataMap, - speciesMap, - sizeCategoryMap, - esduCellMap, - dataQualityMap); - configuration.addResult(result); - - } - - if (configuration.getEsduBySpeciesAndAgeCategoryFile().hasFile()) { - - EchoBaseCsvFileImportResult result = importBySpeciesAndAgeCategoryFile(configuration, - configuration.getEsduBySpeciesAndAgeCategoryFile(), - voyage, - voyageMap, - dataMetadataMap, - speciesMap, - ageCategoryMap, - esduCellMap, - dataQualityMap); - configuration.addResult(result); - - } - - } - - private EchoBaseCsvFileImportResult importByEchotypeFile(ResultsImportConfiguration configuration, - InputFile inputFile, - Voyage voyage, - Map<String, Voyage> voyageMap, - Map<String, Echotype> echotypeMap, - Map<String, DataMetadata> dataMetadataMap, - Map<String, Cell> esduCellMap, - Map<String, DataQuality> dataQualityMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of esdu result by echotype from file " + inputFile.getFileName()); - } - - // first get header of file to detect which results to import - String[] header = CsvReaders.getHeader(inputFile.getFile(), getCsvSeparator()); - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - List<DataMetadata> metas = getMetas(EsduResultByEchotypeImportModel.COLUMN_NAMES_TO_EXCLUDE, dataMetadataMap, header); - - String resultLabel = configuration.getResultLabel(); - - try (Reader reader = getInputFileReader(inputFile)) { - - EsduResultByEchotypeImportModel csvModel = new EsduResultByEchotypeImportModel(getCsvSeparator(), - voyageMap, - echotypeMap, - voyage, - esduCellMap, - metas, - dataQualityMap); - - try (Import<EsduResultByEchotypeImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - - for (EsduResultByEchotypeImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Cell cell = row.getCell(); - - Category category = getResultCategory(row.getEchotype(), null, importResult); - - addResults(row, cell, category, resultLabel, importResult, true, true); - } - } - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - - private EchoBaseCsvFileImportResult importByEchotypeAndSpeciesCategoryFile(ResultsImportConfiguration configuration, - InputFile inputFile, - Voyage voyage, - Map<String, Voyage> voyageMap, - Map<String, Echotype> echotypeMap, - Map<String, DataMetadata> dataMetadataMap, - Map<String, Species> speciesMap, - Map<String, SizeCategory> sizeCategoryMap, - Map<String, Cell> esduCellMap, - Map<String, DataQuality> dataQualityMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of acoustic result by echotype and species category from file " + inputFile.getFileName()); - } - - // first get header of file to detect which results to import - String[] header = CsvReaders.getHeader(inputFile.getFile(), getCsvSeparator()); - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - List<DataMetadata> metas = getMetas(EsduResultByEchotypeAndSpeciesCategoryImportModel.COLUMN_NAMES_TO_EXCLUDE, dataMetadataMap, header); - - String resultLabel = configuration.getResultLabel(); - - try (Reader reader = getInputFileReader(inputFile)) { - - EsduResultByEchotypeAndSpeciesCategoryImportModel csvModel = new EsduResultByEchotypeAndSpeciesCategoryImportModel(getCsvSeparator(), - voyageMap, - echotypeMap, - speciesMap, - sizeCategoryMap, - voyage, - esduCellMap, - metas, - dataQualityMap); - try (Import<EsduResultByEchotypeAndSpeciesCategoryImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (EsduResultByEchotypeAndSpeciesCategoryImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Cell cell = row.getCell(); - - Category category = getResultCategory(row.getEchotype(), - row.getSpecies(), - row.getSizeCategory(), - null, - importResult); - - addResults(row, cell, category, resultLabel, importResult, true, true); - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - - } - } - - private EchoBaseCsvFileImportResult importBySpeciesAndSizeCategoryFile(ResultsImportConfiguration configuration, InputFile inputFile, - Voyage voyage, - Map<String, Voyage> voyageMap, - Map<String, DataMetadata> dataMetadataMap, - Map<String, Species> speciesMap, - Map<String, SizeCategory> sizeCategoryMap, - Map<String, Cell> esduCellMap, - Map<String, DataQuality> dataQualityMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of acoustic result by speices and size category from file " + inputFile.getFileName()); - } - - // first get header of file to detect which results to import - String[] header = CsvReaders.getHeader(inputFile.getFile(), getCsvSeparator()); - - - List<DataMetadata> metas = getMetas(EsduResultBySpeciesAndSizeCategoryImportModel.COLUMN_NAMES_TO_EXCLUDE, dataMetadataMap, header); - - String resultLabel = configuration.getResultLabel(); - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - try (Reader reader = getInputFileReader(inputFile)) { - - EsduResultBySpeciesAndSizeCategoryImportModel csvModel = new EsduResultBySpeciesAndSizeCategoryImportModel(getCsvSeparator(), - voyageMap, - speciesMap, - voyage, - esduCellMap, - metas, - dataQualityMap); - - try (Import<EsduResultBySpeciesAndSizeCategoryImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (EsduResultBySpeciesAndSizeCategoryImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Cell cell = row.getCell(); - - String sizeCategoryName = row.getSizeCategory(); - - SizeCategory sizeCategory = sizeCategoryMap.get(sizeCategoryName); - - if (sizeCategory == null) { - - // create a new sizeCategory - sizeCategory = persistenceService.createSizeCategory(sizeCategoryName, row.getSizeCategoryMeaning()); - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.SizeCategory); - if (log.isInfoEnabled()) { - log.info("Creates a new SizeCategory " + sizeCategoryName); - } - sizeCategoryMap.put(sizeCategoryName, sizeCategory); - } - - Category category = getResultCategory(null, - row.getSpecies(), - sizeCategory, - null, - importResult); - - addResults(row, cell, category, resultLabel, importResult, true, true); - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - - private EchoBaseCsvFileImportResult importBySpeciesAndAgeCategoryFile(ResultsImportConfiguration configuration, - InputFile inputFile, - Voyage voyage, - Map<String, Voyage> voyageMap, - Map<String, DataMetadata> dataMetadataMap, - Map<String, Species> speciesMap, - Map<String, AgeCategory> ageCategoryMap, - Map<String, Cell> esduCellMap, - Map<String, DataQuality> dataQualityMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of acoustic result by species and age category from file " + inputFile.getFileName()); - } - - // first get header of file to detect which results to import - String[] header = CsvReaders.getHeader(inputFile.getFile(), getCsvSeparator()); - - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - List<DataMetadata> metas = getMetas(EsduResultBySpeciesAndAgeCategoryImportModel.COLUMN_NAMES_TO_EXCLUDE, dataMetadataMap, header); - - String resultLabel = configuration.getResultLabel(); - - try (Reader reader = getInputFileReader(inputFile)) { - - EsduResultBySpeciesAndAgeCategoryImportModel csvModel = new EsduResultBySpeciesAndAgeCategoryImportModel(getCsvSeparator(), - voyageMap, - speciesMap, - voyage, - esduCellMap, - metas, - dataQualityMap); - try (Import<EsduResultBySpeciesAndAgeCategoryImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (EsduResultBySpeciesAndAgeCategoryImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Cell cell = row.getCell(); - - String ageCategoryName = row.getAgeCategory(); - - AgeCategory ageCategory = ageCategoryMap.get(ageCategoryName); - - if (ageCategory == null) { - - // create a new sizeCategory - ageCategory = persistenceService.createAgeCategory(ageCategoryName, row.getAgeCategoryMeaning()); - importResult.incrementsNumberCreated(EchoBaseUserEntityEnum.AgeCategory); - if (log.isInfoEnabled()) { - log.info("Creates a new AgeCategory " + ageCategoryName); - } - ageCategoryMap.put(ageCategoryName, ageCategory); - } - - Category category = getResultCategory(null, row.getSpecies(), null, ageCategory, importResult); - - addResults(row, cell, category, resultLabel, importResult, true, true); - - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsImportService.java deleted file mode 100644 index add3e36..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsImportService.java +++ /dev/null @@ -1,130 +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; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.EchoBaseTechnicalException; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.ImportType; -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.services.service.DecoratorService; -import org.nuiton.decorator.Decorator; - -import javax.inject.Inject; -import java.util.Map; - -/** - * Service to launch a "results" import. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class ResultsImportService extends AbstractImportDataService<ResultsImportConfiguration> { - - @Inject - private DecoratorService decoratorService; - - @Override - public void startImport(ResultsImportConfiguration configuration, - EchoBaseUser user) throws ImportException { - - ImportType importMode = configuration.getImportType(); - - AbstractImportDataService<ResultsImportConfiguration> service; - - switch (importMode) { - - case RESULT_VOYAGE: - service = newService(ResultsVoyageImportService.class); - break; - - case RESULT_ESDU: - - service = newService(ResultsEsduCellImportService.class); - break; - - case RESULT_REGION: - - service = newService(ResultsRegionCellImportService.class); - break; - - case RESULT_MAP_FISH: - - service = newService(ResultsMapFishCellImportService.class); - break; - - case RESULT_MAP_OTHER: - - service = newService(ResultsMapOtherCellImportService.class); - break; - default: - throw new EchoBaseTechnicalException( - "Can not treate import result of type " + importMode); - } - service.startImport(configuration, user); - } - - public Map<String, String> getDataProcessings(Voyage voyage) { - - Map<String, String> result = Maps.newLinkedHashMap(); - - Decorator<Transit> transitDecorator = decoratorService.getDecorator(Transit.class, null); - Decorator<Transect> transectDecorator = decoratorService.getDecorator(Transect.class, null); - Decorator<DataAcquisition> dataAcquisitionDecorator = decoratorService.getDecorator(DataAcquisition.class, null); - Decorator<DataProcessing> dataProcessingDecorator = decoratorService.getDecorator(DataProcessing.class, null); - - if (!voyage.isTransitEmpty()) { - - for (Transit transit : voyage.getTransit()) { - - String transitStr = transitDecorator.toString(transit); - - if (!transit.isTransectEmpty()) { - for (Transect transect : transit.getTransect()) { - - String transectStr = transitStr + " / " + transectDecorator.toString(transect); - - if (!transect.isDataAcquisitionEmpty()) { - - for (DataAcquisition dataAcquisition : transect.getDataAcquisition()) { - - String dataAcquisitionStr = transectStr + " / " + dataAcquisitionDecorator.toString(dataAcquisition); - - if (!dataAcquisition.isDataProcessingEmpty()) { - for (DataProcessing dataProcessing : dataAcquisition.getDataProcessing()) { - - String value = dataAcquisitionStr + dataProcessingDecorator.toString(dataProcessing); - result.put(dataProcessing.getTopiaId(), value); - } - } - } - } - } - } - } - } - return result; - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsMapFishCellImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsMapFishCellImportService.java deleted file mode 100644 index 6efc78b..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsMapFishCellImportService.java +++ /dev/null @@ -1,216 +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; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -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.Voyage; -import fr.ifremer.echobase.entities.data.Voyages; -import fr.ifremer.echobase.entities.references.AgeCategories; -import fr.ifremer.echobase.entities.references.AgeCategory; -import fr.ifremer.echobase.entities.references.CellType; -import fr.ifremer.echobase.entities.references.CellTypeImpl; -import fr.ifremer.echobase.entities.references.DataMetadata; -import fr.ifremer.echobase.entities.references.DataMetadataImpl; -import fr.ifremer.echobase.entities.references.DataMetadatas; -import fr.ifremer.echobase.entities.references.DataQualities; -import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.entities.references.SizeCategories; -import fr.ifremer.echobase.entities.references.SizeCategory; -import fr.ifremer.echobase.entities.references.Species; -import fr.ifremer.echobase.entities.references.Species2; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.MapCellImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.MapCellImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.csv.ext.CsvReaders; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * To import map fish results attached to a voyage. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class ResultsMapFishCellImportService extends AbstractImportDataService<ResultsImportConfiguration> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ResultsMapFishCellImportService.class); - - @Override - public void startImport(ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - // get selected voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - EchoBaseCsvFileImportResult importResult = importMapFile(configuration, voyage); - configuration.addResult(importResult); - - } - - protected EchoBaseCsvFileImportResult importMapFile(ResultsImportConfiguration configuration, Voyage voyage) throws ImportException { - - InputFile inputFile = configuration.getMapsFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of Map cells from file " + inputFile.getFileName()); - } - - String resultLabel = configuration.getResultLabel(); - - CellType cellType = persistenceService.getCellTypeById(CellTypeImpl.MAP); - - DataMetadata dataLongitudeMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_CELL_LONGITUDE); - - DataMetadata dataLatitudeMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_CELL_LATITUDE); - - DataMetadata dataDepthMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_CELL_DEPTH); - - DataMetadata dataLongitudeLagMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_LONGITUDE_LAG); - - DataMetadata dataLatitudeLagMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_LATITUDE_LAG); - - DataMetadata dataDepthLagMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_DEPTH_LAG); - - // authorize only the selected voyage to be imported - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - Map<String, Species> speciesMap = persistenceService.getEntitiesMap(Species.class, Species2.SPECIES_BARACOUDA_CODE); - - Map<String, SizeCategory> sizeCategoryMap = Maps.newTreeMap(); - sizeCategoryMap.putAll(persistenceService.getEntitiesMap(SizeCategory.class, SizeCategories.SIZE_CATEGORY_NAME)); - - Map<String, AgeCategory> ageCategoryMap = Maps.newTreeMap(); - ageCategoryMap.putAll(persistenceService.getEntitiesMap(AgeCategory.class, AgeCategories.AGE_CATEGORY_NAME)); - - Map<String, DataMetadata> dataMetadataMap = persistenceService.getEntitiesMap(DataMetadata.class, DataMetadatas.DATA_METADATA_NAME); - - Map<String, DataQuality> dataQualityMap = persistenceService.getEntitiesMap(DataQuality.class, DataQualities.DATA_QUALITY_NAME); - - // first get header of file to detect which results to import - String[] header = CsvReaders.getHeader(inputFile.getFile(), getCsvSeparator()); - - List<DataMetadata> metas = getMetas(MapCellImportModel.COLUMN_NAMES_TO_EXCLUDE, dataMetadataMap, header); - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - try (Reader reader = getInputFileReader(inputFile)) { - - MapCellImportModel csvModel = new MapCellImportModel(getCsvSeparator(), - cellType, - voyageMap, - speciesMap, - sizeCategoryMap, - ageCategoryMap, - metas, - dataQualityMap); - - try (Import<MapCellImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - - int rowNumber = 0; - for (MapCellImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Cell cell = persistenceService.createCell(row.getCell()); - voyage.addPostCell(cell); - - // collect ids - importResult.addId(EchoBaseUserEntityEnum.Cell, cell); - - DataQuality dataQuality = row.getDataQuality(); - - // add gridCellLongitude data - createCellData(cell, - dataLongitudeMeta, - String.valueOf(row.getGridCellLongitude()), - dataQuality, - importResult); - - // add gridCellLatitude data - createCellData(cell, - dataLatitudeMeta, - String.valueOf(row.getGridCellLatitude()), - dataQuality, - importResult); - - // add gridCellDepth data - createCellData(cell, - dataDepthMeta, - String.valueOf(row.getGridCellDepth()), - dataQuality, - importResult); - - // add gridLongitudeLag data - createCellData(cell, - dataLongitudeLagMeta, - String.valueOf(row.getGridLongitudeLag()), - dataQuality, - importResult); - - // add gridLatitudeLag data - createCellData(cell, - dataLatitudeLagMeta, - String.valueOf(row.getGridLatitudeLag()), - dataQuality, - importResult); - - // add gridDepthLag data - createCellData(cell, - dataDepthLagMeta, - String.valueOf(row.getGridDepthLag()), - dataQuality, - importResult); - - Category category = getResultCategory(null, - row.getSpecies(), - row.getSizeCategory(), - row.getAgeCategory(), - importResult); - - addResults(row, cell, category, resultLabel, importResult, false, true); - - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsMapOtherCellImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsMapOtherCellImportService.java deleted file mode 100644 index 14ede15..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsMapOtherCellImportService.java +++ /dev/null @@ -1,188 +0,0 @@ -package fr.ifremer.echobase.services.service.importdata; - -/* - * #%L - * EchoBase :: Services - * %% - * Copyright (C) 2011 - 2013 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 com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.data.Cell; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.data.Voyages; -import fr.ifremer.echobase.entities.references.CellType; -import fr.ifremer.echobase.entities.references.CellTypeImpl; -import fr.ifremer.echobase.entities.references.DataMetadata; -import fr.ifremer.echobase.entities.references.DataMetadataImpl; -import fr.ifremer.echobase.entities.references.DataMetadatas; -import fr.ifremer.echobase.entities.references.DataQualities; -import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.MapCellImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.MapCellImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.csv.ext.CsvReaders; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * To import map other results attached to a voyage. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.2 - */ -public class ResultsMapOtherCellImportService extends AbstractImportDataService<ResultsImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ResultsMapOtherCellImportService.class); - - @Override - public void startImport(ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - // get selected voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - EchoBaseCsvFileImportResult importResult = importMapFile(configuration, voyage); - configuration.addResult(importResult); - - } - - protected EchoBaseCsvFileImportResult importMapFile(ResultsImportConfiguration configuration, Voyage voyage) throws ImportException { - - InputFile inputFile = configuration.getMapsFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of Map Other cells from file " + inputFile.getFileName()); - } - - String resultLabel = configuration.getResultLabel(); - - CellType cellType = persistenceService.getCellTypeById(CellTypeImpl.MAP); - - DataMetadata dataLongitudeMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_CELL_LONGITUDE); - - DataMetadata dataLatitudeMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_CELL_LATITUDE); - - DataMetadata dataDepthMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_CELL_DEPTH); - - DataMetadata dataLongitudeLagMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_LONGITUDE_LAG); - - DataMetadata dataLatitudeLagMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_LATITUDE_LAG); - - DataMetadata dataDepthLagMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.GRID_DEPTH_LAG); - - // authorize only the selected voyage to be imported - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - Map<String, DataMetadata> dataMetadataMap = persistenceService.getEntitiesMap(DataMetadata.class, DataMetadatas.DATA_METADATA_NAME); - - Map<String, DataQuality> dataQualityMap = persistenceService.getEntitiesMap(DataQuality.class, DataQualities.DATA_QUALITY_NAME); - - // first get header of file to detect which results to import - String[] header = CsvReaders.getHeader(inputFile.getFile(), getCsvSeparator()); - - List<DataMetadata> metas = getMetas(MapCellImportModel.COLUMN_NAMES_TO_EXCLUDE, dataMetadataMap, header); - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - try (Reader reader = getInputFileReader(inputFile)) { - - MapCellImportModel csvModel = new MapCellImportModel(getCsvSeparator(), cellType, voyageMap, metas, dataQualityMap); - - try (Import<MapCellImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - - int rowNumber = 0; - for (MapCellImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Cell cell = persistenceService.createCell(row.getCell()); - voyage.addPostCell(cell); - - // collect ids - importResult.addId(EchoBaseUserEntityEnum.Cell, cell); - - DataQuality dataQuality = row.getDataQuality(); - - // add gridCellLongitude data - createCellData(cell, - dataLongitudeMeta, - String.valueOf(row.getGridCellLongitude()), - dataQuality, - importResult); - - // add gridCellLatitude data - createCellData(cell, - dataLatitudeMeta, - String.valueOf(row.getGridCellLatitude()), - dataQuality, - importResult); - - // add gridCellDepth data - createCellData(cell, - dataDepthMeta, - String.valueOf(row.getGridCellDepth()), - dataQuality, - importResult); - - // add gridLongitudeLag data - createCellData(cell, - dataLongitudeLagMeta, - String.valueOf(row.getGridLongitudeLag()), - dataQuality, - importResult); - - // add gridLatitudeLag data - createCellData(cell, - dataLatitudeLagMeta, - String.valueOf(row.getGridLatitudeLag()), - dataQuality, - importResult); - - // add gridDepthLag data - createCellData(cell, - dataDepthLagMeta, - String.valueOf(row.getGridDepthLag()), - dataQuality, - importResult); - - addResults(row, cell, null, resultLabel, importResult, false, true); - - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportService.java deleted file mode 100644 index 18bfb28..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportService.java +++ /dev/null @@ -1,290 +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; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -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.Cells; -import fr.ifremer.echobase.entities.data.Echotype; -import fr.ifremer.echobase.entities.data.Echotypes; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.data.Voyages; -import fr.ifremer.echobase.entities.references.CellType; -import fr.ifremer.echobase.entities.references.CellTypes; -import fr.ifremer.echobase.entities.references.DataMetadata; -import fr.ifremer.echobase.entities.references.DataMetadataImpl; -import fr.ifremer.echobase.entities.references.DataMetadatas; -import fr.ifremer.echobase.entities.references.DataQualities; -import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.entities.references.SizeCategories; -import fr.ifremer.echobase.entities.references.SizeCategory; -import fr.ifremer.echobase.entities.references.Species; -import fr.ifremer.echobase.entities.references.Species2; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.RegionCellAssociationImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.RegionCellAssociationImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.RegionCellImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.RegionCellImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.RegionCellResultImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.RegionCellResultImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.csv.ext.CsvReaders; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * To import regions results attached to a voyage. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class ResultsRegionCellImportService extends AbstractImportDataService<ResultsImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ResultsRegionCellImportService.class); - - @Override - public void startImport(ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - // get selected voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - Map<String, DataQuality> dataQualityMap = persistenceService.getEntitiesMap(DataQuality.class, DataQualities.DATA_QUALITY_NAME); - - { - EchoBaseCsvFileImportResult importResult = importRegionFile(configuration, voyage, dataQualityMap); - configuration.addResult(importResult); - } - { - EchoBaseCsvFileImportResult importResult = importRegionAssociationFile(configuration, voyage); - configuration.addResult(importResult); - } - { - EchoBaseCsvFileImportResult importResult = importRegionResultFile(configuration, voyage, dataQualityMap); - configuration.addResult(importResult); - } - } - - protected EchoBaseCsvFileImportResult importRegionFile(ResultsImportConfiguration configuration, - Voyage voyage, - Map<String, DataQuality> dataQualityMap) throws ImportException { - - InputFile inputFile = configuration.getRegionsFile(); - - Set<CellType> allCellTypes = persistenceService.getRegionCellTypes(); - - DataMetadata dataCoordinateMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.REGION_ENV_COORDINATES); - - DataMetadata dataSurfaceMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.SURFACE); - - // authorize only the selected voyage to be imported - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - // authorize only to use region* cell types - Map<String, CellType> cellTypeMap = Maps.uniqueIndex(allCellTypes, CellTypes.CELL_TYPE_ID); - - if (log.isInfoEnabled()) { - log.info("Starts import of Region cells from file " + inputFile.getFileName()); - } - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - try (Reader reader = getInputFileReader(inputFile)) { - - RegionCellImportModel csvModel = new RegionCellImportModel(getCsvSeparator(), - voyageMap, - cellTypeMap, - dataQualityMap); - try (Import<RegionCellImportRow> importer = Import.newImport(csvModel, reader)) { - - Cell cell = null; - - configuration.incrementsProgress(); - int rowNumber = 0; - for (RegionCellImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - if (cell == null || !row.getName().equals(cell.getName())) { - - cell = persistenceService.createCell(row.getCellType(), row.getName()); - voyage.addPostCell(cell); - - // collect ids - importResult.addId(EchoBaseUserEntityEnum.Cell, cell); - - // add surface data - createCellData(cell, - dataSurfaceMeta, - String.valueOf(row.getDataSurface()), - row.getDataQuality(), - importResult); - } - - // add coordinate data - createCellData(cell, - dataCoordinateMeta, - row.getDataCoordinate(), - row.getDataQuality(), - importResult); - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - - protected EchoBaseCsvFileImportResult importRegionAssociationFile(ResultsImportConfiguration configuration, - Voyage voyage) throws ImportException { - - InputFile inputFile = configuration.getRegionAssociationFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of Region cells association from file " + inputFile.getFileName()); - } - - // authorize only the selected voyage to be imported - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - Map<String, Cell> regionsMap = Maps.uniqueIndex(voyage.getRegionCells(), Cells.CELL_BY_NAME); - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - try (Reader reader = getInputFileReader(inputFile)) { - - RegionCellAssociationImportModel csvModel = new RegionCellAssociationImportModel(getCsvSeparator(), - voyageMap, - regionsMap, - persistenceService.newCellValueParser(voyage)); - - try (Import<RegionCellAssociationImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (RegionCellAssociationImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Cell regionCell = row.getRegionCell(); - Cell esduCell = row.getEsduCell(); - regionCell.addChilds(esduCell); - importResult.incrementsNumberUpdated(EchoBaseUserEntityEnum.Cell); - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - - protected EchoBaseCsvFileImportResult importRegionResultFile(ResultsImportConfiguration configuration, - Voyage voyage, - Map<String, DataQuality> dataQualityMap) throws ImportException { - - InputFile inputFile = configuration.getRegionResultFile(); - - if (log.isInfoEnabled()) { - log.info("Starts import of Region cell results from file " + inputFile.getFileName()); - } - - // authorize only the selected voyage to be imported - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - // index regions of the voyage - Map<String, Cell> regionsMap = Maps.uniqueIndex(voyage.getRegionCells(), Cells.CELL_BY_NAME); - - // index all echotypes of thi voyage - Map<String, Echotype> echotypeMap = Maps.uniqueIndex(voyage.getEchotype(), Echotypes.ECHOTYPE_NAME); - - Map<String, Species> speciesMap = persistenceService.getEntitiesMap(Species.class, Species2.SPECIES_BARACOUDA_CODE); - - Map<String, SizeCategory> sizeCategoryMap = Maps.newTreeMap(); - sizeCategoryMap.putAll(persistenceService.getEntitiesMap(SizeCategory.class, SizeCategories.SIZE_CATEGORY_NAME)); - - Map<String, DataMetadata> dataMetadataMap = persistenceService.getEntitiesMap(DataMetadata.class, DataMetadatas.DATA_METADATA_NAME); - - // first get header of file to detect which results to import - String[] header = CsvReaders.getHeader(inputFile.getFile(), getCsvSeparator()); - - List<DataMetadata> metas = getMetas(RegionCellResultImportModel.COLUMN_NAMES_TO_EXCLUDE, dataMetadataMap, header); - - String resultLabel = configuration.getResultLabel(); - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - try (Reader reader = getInputFileReader(inputFile)) { - - RegionCellResultImportModel csvModel = new RegionCellResultImportModel(getCsvSeparator(), - voyageMap, - regionsMap, - echotypeMap, - speciesMap, - sizeCategoryMap, - metas, - dataQualityMap); - - try (Import<RegionCellResultImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (RegionCellResultImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Cell cell = row.getCell(); - - Category category = getResultCategory(row.getEchotype(), - row.getSpecies(), - row.getSizeCategory(), - null, - importResult); - - addResults(row, cell, category, resultLabel, importResult, false, false); - - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - - } - - } -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportService.java deleted file mode 100644 index 5916172..0000000 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportService.java +++ /dev/null @@ -1,307 +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; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; -import fr.ifremer.echobase.entities.data.Echotype; -import fr.ifremer.echobase.entities.data.Echotypes; -import fr.ifremer.echobase.entities.data.LengthAgeKey; -import fr.ifremer.echobase.entities.data.LengthWeightKey; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.data.Voyages; -import fr.ifremer.echobase.entities.references.DepthStratum; -import fr.ifremer.echobase.entities.references.DepthStratums; -import fr.ifremer.echobase.entities.references.SizeCategories; -import fr.ifremer.echobase.entities.references.SizeCategory; -import fr.ifremer.echobase.entities.references.Species; -import fr.ifremer.echobase.entities.references.Species2; -import fr.ifremer.echobase.entities.references.SpeciesCategory; -import fr.ifremer.echobase.entities.references.Strata; -import fr.ifremer.echobase.entities.references.Stratas; -import fr.ifremer.echobase.io.InputFile; -import fr.ifremer.echobase.services.service.importdata.csv.EchotypeImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.EchotypeImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.LengthAgeKeyImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.LengthAgeKeyImportRow; -import fr.ifremer.echobase.services.service.importdata.csv.LengthWeightKeyImportModel; -import fr.ifremer.echobase.services.service.importdata.csv.LengthWeightKeyImportRow; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; - -import java.io.IOException; -import java.io.Reader; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -/** - * To import results attached to a voyage (but not cells). - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class ResultsVoyageImportService extends AbstractImportDataService<ResultsImportConfiguration> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ResultsVoyageImportService.class); - - @Override - public void startImport(ResultsImportConfiguration configuration, EchoBaseUser user) throws ImportException { - - Map<String, Species> speciesMap = persistenceService.getEntitiesMap(Species.class, Species2.SPECIES_BARACOUDA_CODE); - - Map<String, Strata> strataMap = persistenceService.getEntitiesMap(Strata.class, Stratas.STRATA_BY_NAME); - - // get selected voyage - Voyage voyage = persistenceService.getVoyage(configuration.getVoyageId()); - - // check if there is a such same import on this voyage - boolean importExists = persistenceService.isImportLogForVoyageExists(configuration.getVoyageId()); - if (importExists) { - if (log.isWarnEnabled()) { - log.warn("there is already a voyage result import for this voyage, won't import."); - } - throw new ResultsVoyageImportAlreadyExistException(getLocale()); - } - - // authorize only the selected voyage to be imported - Map<String, Voyage> voyageMap = Maps.uniqueIndex(Collections.singletonList(voyage), Voyages.VOYAGE_NAME); - - if (configuration.getLengthAgeKeyFile().hasFile()) { - - EchoBaseCsvFileImportResult importResult = importLenthAgeKey(configuration, - configuration.getLengthAgeKeyFile(), - voyageMap, - strataMap, - speciesMap); - configuration.addResult(importResult); - - } - - if (configuration.getLengthWeightKeyFile().hasFile()) { - - EchoBaseCsvFileImportResult importResult = importLenghtWeightKey(configuration, - configuration.getLengthWeightKeyFile(), - voyageMap, - strataMap, - speciesMap); - configuration.addResult(importResult); - - } - - if (configuration.getEchotypeFile().hasFile()) { - - EchoBaseCsvFileImportResult importResult = importEchotypeFile(configuration, - configuration.getEchotypeFile(), - voyageMap, - speciesMap); - configuration.addResult(importResult); - - } - } - - protected EchoBaseCsvFileImportResult importLenghtWeightKey(ResultsImportConfiguration configuration, - InputFile inputFile, - Map<String, Voyage> voyageMap, - Map<String, Strata> strataMap, - Map<String, Species> speciesMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of lenthWeightKey from file " + inputFile.getFileName()); - } - - Map<String, SizeCategory> sizeCategoryMap = persistenceService.getEntitiesMap(SizeCategory.class, SizeCategories.SIZE_CATEGORY_NAME); - - try (Reader reader = getInputFileReader(inputFile)) { - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - LengthWeightKeyImportModel csvModel = new LengthWeightKeyImportModel(getCsvSeparator(), - voyageMap, - strataMap, - sizeCategoryMap, - speciesMap); - - try (Import<LengthWeightKeyImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - int rowNumber = 0; - for (LengthWeightKeyImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - Voyage voyage = row.getVoyage(); - - // find speciesCategory - SpeciesCategory speciesCategory = getSpeciesCategory(row.getSpecies(), row.getSizeCategory(), null, null, importResult); - - LengthWeightKey toCreate = row.getLengthWeightKey(); - toCreate.setSpeciesCategory(speciesCategory); - - LengthWeightKey lengthWeightKey = persistenceService.createLengthWeightKey(toCreate); - - //TODO should we import it ? - //lengthWeightKey.setMetadata(row.getMetadata()); - - // attach it to voyage - voyage.addLengthWeightKey(lengthWeightKey); - - // collect ids - importResult.addId(EchoBaseUserEntityEnum.LengthWeightKey, lengthWeightKey); - - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - - protected EchoBaseCsvFileImportResult importLenthAgeKey(ResultsImportConfiguration configuration, - InputFile inputFile, - Map<String, Voyage> voyageMap, - Map<String, Strata> strataMap, - Map<String, Species> speciesMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of lenthAgeKey from file " + inputFile.getFileName()); - } - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - try (Reader reader = getInputFileReader(inputFile)) { - - LengthAgeKeyImportModel csvModel = new LengthAgeKeyImportModel(getCsvSeparator(), voyageMap, strataMap, speciesMap); - try (Import<LengthAgeKeyImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - - int rowNumber = 0; - for (LengthAgeKeyImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Voyage voyage = row.getVoyage(); - - LengthAgeKey lengthAgeKeyToCreate = row.getLengthAgeKey(); - LengthAgeKey lengthAgeKey = persistenceService.createLengthAgeKey(lengthAgeKeyToCreate); - - // attach it to voyage - voyage.addLengthAgeKey(lengthAgeKey); - - // collect ids - importResult.addId(EchoBaseUserEntityEnum.LengthAgeKey, lengthAgeKey); - - } - } - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - - private EchoBaseCsvFileImportResult importEchotypeFile(ResultsImportConfiguration configuration, - InputFile inputFile, - Map<String, Voyage> voyageMap, - Map<String, Species> speciesMap) throws ImportException { - - if (log.isInfoEnabled()) { - log.info("Starts import of echotype from file " + inputFile.getFileName()); - } - - EchoBaseCsvFileImportResult importResult = newImportResult(inputFile); - - Map<String, DepthStratum> depthStratumMap = persistenceService.getEntitiesMap(DepthStratum.class, DepthStratums.DEPTH_STRATUM_ID); - - try (Reader reader = getInputFileReader(inputFile)) { - - EchotypeImportModel csvModel = new EchotypeImportModel(getCsvSeparator(), voyageMap, depthStratumMap, speciesMap); - - try (Import<EchotypeImportRow> importer = Import.newImport(csvModel, reader)) { - - configuration.incrementsProgress(); - - int rowNumber = 0; - for (EchotypeImportRow row : importer) { - - doFlushTransaction(++rowNumber, inputFile, configuration); - - Voyage voyage = row.getVoyage(); - - Echotype rowEchotype = row.getEchotype(); - - String echotypeName = rowEchotype.getName(); - - // check if there is a echotype for the voyage and this name - Echotype echotype = null; - - if (!voyage.isEchotypeEmpty()) { - - Collection<Echotype> echotypes = voyage.getEchotype(); - Predicate<Echotype> predicate = Echotypes.newEchotypeByNamePredicate(echotypeName); - echotype = Iterables.find(echotypes, predicate, null); - - } - - if (echotype == null) { - - // creates it - echotype = persistenceService.createEchotype(rowEchotype); - - // attach it to voyage - voyage.addEchotype(echotype); - - // collect ids - importResult.addId(EchoBaseUserEntityEnum.Echotype, echotype); - - } else { - - Species species = rowEchotype.getSpecies().iterator().next(); - Species existingSpecie = echotype.getSpeciesByTopiaId(species.getTopiaId()); - - if (existingSpecie == null) { - - // add this species - echotype.addSpecies(species); - } - } - } - } - - return importResult; - - } catch (ImportRuntimeException | IOException e) { - throw new ImportException(getLocale(), inputFile, e); - } - - } - -} diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/AbstractImportAction.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/AbstractImportAction.java index 1f390b1..832c51f 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/AbstractImportAction.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/actions/AbstractImportAction.java @@ -50,7 +50,7 @@ import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; -import static fr.ifremer.echobase.services.service.importdata.AbstractImportDataService.REMOVE_DOUBLE_QUOTES_PATTERN; +import static fr.ifremer.echobase.services.service.importdata.ImportDataService.REMOVE_DOUBLE_QUOTES_PATTERN; import static org.nuiton.i18n.I18n.l; /** diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/EchoBaseTestServiceSupport.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/EchoBaseTestServiceSupport.java index 37fdd2b..a963bd0 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/EchoBaseTestServiceSupport.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/EchoBaseTestServiceSupport.java @@ -21,6 +21,7 @@ package fr.ifremer.echobase.services; import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.entities.EchoBaseUserEntityEnum; import fr.ifremer.echobase.entities.EchoBaseUserImpl; @@ -31,7 +32,7 @@ import fr.ifremer.echobase.io.InputFile; import fr.ifremer.echobase.services.service.exportdb.ExportDbConfiguration; import fr.ifremer.echobase.services.service.exportdb.ExportDbMode; import fr.ifremer.echobase.services.service.exportdb.ExportDbService; -import fr.ifremer.echobase.services.service.importdata.EchoBaseCsvFileImportResult; +import fr.ifremer.echobase.services.service.importdata.ImportDataFileResult; import fr.ifremer.echobase.services.service.importdata.ImportException; import fr.ifremer.echobase.services.service.importdb.ImportDbConfiguration; import fr.ifremer.echobase.services.service.importdb.ImportDbMode; @@ -55,7 +56,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Collection; -import java.util.List; import java.util.Set; import java.util.zip.GZIPInputStream; @@ -87,7 +87,7 @@ public abstract class EchoBaseTestServiceSupport extends EchoBaseServiceSupport @Before public void setUp() throws Exception { this.serviceContext = fakeServiceContext; - if (fakeServiceContext!=null) { + if (fakeServiceContext != null) { fakeServiceContext.inject(this); } } @@ -155,23 +155,12 @@ public abstract class EchoBaseTestServiceSupport extends EchoBaseServiceSupport } } - protected <E extends TopiaEntity> void assertCsvImportResult(EchoBaseCsvFileImportResult actual, - Class<E> entityType, - int numberCreated) throws TopiaException { - assertCsvImportResult(actual, - entityType, - numberCreated, - 0, - numberCreated); - - } - - protected <E extends TopiaEntity> void assertCsvImportResult(List<EchoBaseCsvFileImportResult> actual, + protected <E extends TopiaEntity> void assertCsvImportResult(Set<ImportDataFileResult> actual, int pos, Class<E> entityType, int numberCreated) throws TopiaException { Assert.assertTrue(actual.size() >= pos); - assertCsvImportResult(actual.get(pos), + assertCsvImportResult(Iterables.get(actual, pos), entityType, numberCreated, 0, @@ -179,7 +168,7 @@ public abstract class EchoBaseTestServiceSupport extends EchoBaseServiceSupport } - protected <E extends TopiaEntity> void assertCsvImportResult(EchoBaseCsvFileImportResult actual, + protected <E extends TopiaEntity> void assertCsvImportResult(ImportDataFileResult actual, Class<E> entityType, int numberCreated, int numberUpdated, @@ -193,14 +182,14 @@ public abstract class EchoBaseTestServiceSupport extends EchoBaseServiceSupport assertNbEntities(entityType, nbCount); } - protected <E extends TopiaEntity> void assertCsvImportResult(List<EchoBaseCsvFileImportResult> results, + protected <E extends TopiaEntity> void assertCsvImportResult(Set<ImportDataFileResult> results, int pos, Class<E> entityType, int numberCreated, int numberUpdated, int nbCount) throws TopiaException { Assert.assertTrue(results.size() >= pos); - EchoBaseCsvFileImportResult actual = results.get(pos); + ImportDataFileResult actual = Iterables.get(results, pos); Assert.assertNotNull(actual); Set<EchoBaseUserEntityEnum> entityTypes = actual.getEntityTypes(); EchoBaseUserEntityEnum expectedEntityType = EchoBaseUserEntityEnum.valueOf(entityType); @@ -210,11 +199,11 @@ public abstract class EchoBaseTestServiceSupport extends EchoBaseServiceSupport assertNbEntities(entityType, nbCount); } - protected <E extends TopiaEntity> void assertNbIDs(List<EchoBaseCsvFileImportResult> results, + protected <E extends TopiaEntity> void assertNbIDs(Set<ImportDataFileResult> results, int pos, int nbIds) throws TopiaException { Assert.assertTrue(results.size() >= pos); - EchoBaseCsvFileImportResult actual = results.get(pos); + ImportDataFileResult actual = Iterables.get(results, pos); Assert.assertNotNull(actual); Assert.assertEquals(nbIds, actual.getIds().size()); } diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/FixCellsIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/FixCellsIT.java index dc818c3..51c1468 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/FixCellsIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/FixCellsIT.java @@ -28,14 +28,14 @@ import fr.ifremer.echobase.entities.data.Data; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.service.UserDbPersistenceService; import fr.ifremer.echobase.services.service.importdata.AcousticImportConfiguration; -import fr.ifremer.echobase.services.service.importdata.AcousticImportService; import fr.ifremer.echobase.services.service.importdata.CellPositionReference; +import fr.ifremer.echobase.services.service.importdata.ImportDataService; import fr.ifremer.echobase.services.service.importdata.ImportException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; -import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaDao; +import org.nuiton.topia.persistence.TopiaException; import java.io.IOException; import java.text.DateFormat; @@ -162,16 +162,9 @@ Seens years 2003 :: 26595 System.gc(); - AcousticImportService service = newService(AcousticImportService.class); - -// AcousticImportService.POSSIBLE_YEARS.clear(); -// -// for (int year : years) { -// -// AcousticImportService.POSSIBLE_YEARS.add(year); -// } + ImportDataService service = newService(ImportDataService.class); - service.doImport(conf, createFakeUser()); + service.doImportAcoustics(conf, createFakeUser()); System.gc(); } diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataServiceIT.java index e0f6d49..1846336 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataServiceIT.java @@ -64,7 +64,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; -import java.util.List; import java.util.Set; import java.util.regex.Matcher; @@ -111,7 +110,7 @@ public abstract class AbstractImportDataServiceIT extends EchoBaseTestServiceSup assertNbEntities(Echotype.class, fixtures.NB_ECHOTYPE()); } - protected <M extends AbstractImportConfiguration> List<EchoBaseCsvFileImportResult> doImport(M conf, ImportDataService.ImportDataAction<M> importDataAction, int nbResults) throws ImportException { + protected <M extends AbstractImportConfiguration> Set<ImportDataFileResult> doImport(M conf, ImportDataService.ImportDataAction<M> importDataAction, int nbResults) throws ImportException { ImportDataService service = newService(ImportDataService.class); @@ -119,11 +118,12 @@ public abstract class AbstractImportDataServiceIT extends EchoBaseTestServiceSup long s0 = TimeLog.getTime(); - String resume = importDataAction.doImport(service, conf, fakeUser); + ImportDataResult<M> importDataResult = importDataAction.doImport(service, conf, fakeUser); + String resume = importDataResult.getImportSummary(); TIME_LOG.log(s0, "doImport"); - List<EchoBaseCsvFileImportResult> result = conf.getImportResults(); + Set<ImportDataFileResult> result = importDataResult.getImportResults(); Assert.assertNotNull(result); Assert.assertEquals(nbResults, result.size()); @@ -135,7 +135,7 @@ public abstract class AbstractImportDataServiceIT extends EchoBaseTestServiceSup } } - return result; + return importDataResult.getImportResults(); } // protected <E extends TopiaEntity> E create(TopiaDao<E> dao, @@ -155,7 +155,6 @@ public abstract class AbstractImportDataServiceIT extends EchoBaseTestServiceSup UserDbPersistenceService persistenceService = serviceContext.newService(UserDbPersistenceService.class); - ResultsImportService service = newService(ResultsImportService.class); Voyage voyage = persistenceService.getVoyage(voyageId); Transit transit; Transect transect; @@ -275,7 +274,7 @@ public abstract class AbstractImportDataServiceIT extends EchoBaseTestServiceSup if (!esduColumnName.equals(columnHeader) && !("\"" + esduColumnName + "\"").equals(columnHeader)) { - Matcher matcher = AbstractImportDataService.REMOVE_DOUBLE_QUOTES_PATTERN.matcher(columnHeader); + Matcher matcher = ImportDataService.REMOVE_DOUBLE_QUOTES_PATTERN.matcher(columnHeader); if (matcher.matches()) { newIgnoredColumn(matcher.group(1)); } else { diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/AcousticImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/AcousticImportServiceIT.java index c79f0bc..1f5f463 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/AcousticImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/AcousticImportServiceIT.java @@ -27,11 +27,9 @@ import fr.ifremer.echobase.entities.data.DataProcessing; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * Tests {@link AcousticImportService}. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ @@ -55,8 +53,7 @@ public class AcousticImportServiceIT extends AbstractImportDataServiceIT { Cell.class, Data.class); - AcousticImportConfiguration conf = - new AcousticImportConfiguration(getLocale()); + AcousticImportConfiguration conf = new AcousticImportConfiguration(getLocale()); conf.setVoyageId(getVoyageId()); conf.setVesselId(fixtures.VESSEL_ID()); @@ -79,8 +76,7 @@ public class AcousticImportServiceIT extends AbstractImportDataServiceIT { prepareInputFile(conf.getMoviesFile(), getImportPath("movies.csv.gz")); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.AcousticImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.AcousticImportDataAction(), 1); assertNbIDs(result, 0, fixtures.NB_CELL()); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceIT.java index 102993b..197f0b1 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceIT.java @@ -24,14 +24,11 @@ import fr.ifremer.echobase.entities.data.Sample; import fr.ifremer.echobase.entities.data.SampleData; import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; -import org.junit.Ignore; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * Tests {@link CatchesImportService}. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ @@ -52,20 +49,15 @@ public class CatchesImportServiceIT extends AbstractImportDataServiceIT { assertImportOperations(); assertNoEntities(Sample.class, SampleData.class); - CatchesImportConfiguration conf = - new CatchesImportConfiguration(getLocale()); + CatchesImportConfiguration conf = new CatchesImportConfiguration(getLocale()); conf.setVoyageId(getVoyageId()); - prepareInputFile(conf.getTotalSampleFile(), - getImportPath("totalsample.csv.gz")); - prepareInputFile(conf.getSubSampleFile(), - getImportPath("subsample.csv.gz")); - prepareInputFile(conf.getBiometrySampleFile(), - getImportPath("biometrysample.csv.gz")); + prepareInputFile(conf.getTotalSampleFile(), getImportPath("totalsample.csv.gz")); + prepareInputFile(conf.getSubSampleFile(), getImportPath("subsample.csv.gz")); + prepareInputFile(conf.getBiometrySampleFile(), getImportPath("biometrysample.csv.gz")); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.CatchesImportDataAction(), 3); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.CatchesImportDataAction(), 3); assertNbIDs(result, 0, fixtures.NB_SAMPLE_TOTAL()); @@ -85,76 +77,4 @@ public class CatchesImportServiceIT extends AbstractImportDataServiceIT { assertImportSampleDatas(); } - @Ignore - @Test - public void doImportTotalSample() throws Exception { - - assertImportCommonData(); - assertImportOperations(); - assertNoEntities(Sample.class, SampleData.class); - - CatchesImportConfiguration conf = - new CatchesImportConfiguration(getLocale()); - - conf.setVoyageId(getVoyageId()); - - prepareInputFile(conf.getTotalSampleFile(), - getImportPath("totalsample.csv.gz")); - - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.CatchesImportDataAction(), 1); - - assertNbIDs(result, 0, fixtures.NB_SAMPLE_TOTAL()); - assertCsvImportResult(result, 0, Sample.class, fixtures.NB_SAMPLE_TOTAL()); - assertCsvImportResult(result, 0, SampleData.class, fixtures.NB_SAMPLE_DATA_TOTAL()); - } - - @Ignore - @Test - public void doImportSubSample() throws Exception { - - assertImportCommonData(); - assertImportOperations(); - assertNoEntities(Sample.class, SampleData.class); - - CatchesImportConfiguration conf = - new CatchesImportConfiguration(getLocale()); - - conf.setVoyageId(getVoyageId()); - - prepareInputFile(conf.getSubSampleFile(), - getImportPath("subsample.csv.gz")); - - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.CatchesImportDataAction(), 1); - - assertNbIDs(result, 0, fixtures.NB_SAMPLE_UNSORTED()); - assertCsvImportResult(result, 0, Sample.class, fixtures.NB_SAMPLE_UNSORTED()); - assertCsvImportResult(result, 0, SampleData.class, fixtures.NB_SAMPLE_DATA_UNSORTED()); - } - - @Ignore - @Test - public void doImportBiometrySample() throws Exception { - - assertImportCommonData(); - assertImportOperations(); - assertNoEntities(Sample.class, SampleData.class); - - CatchesImportConfiguration conf = - new CatchesImportConfiguration(getLocale()); - - conf.setVoyageId(getVoyageId()); - - prepareInputFile(conf.getBiometrySampleFile(), - getImportPath("biometrysample.csv.gz")); - - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.CatchesImportDataAction(), 1); - - assertNbIDs(result, 0, fixtures.NB_SAMPLE_BIOMETRY()); - assertCsvImportResult(result, 0, Sample.class, fixtures.NB_SAMPLE_BIOMETRY()); - assertCsvImportResult(result, 0, SampleData.class, fixtures.NB_SAMPLE_DATA_BIOMETRY()); - } - } diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlyBiometrySampleIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlyBiometrySampleIT.java new file mode 100644 index 0000000..794f248 --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlyBiometrySampleIT.java @@ -0,0 +1,64 @@ +/* + * #%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; + +import fr.ifremer.echobase.entities.data.Sample; +import fr.ifremer.echobase.entities.data.SampleData; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import org.junit.Test; + +import java.util.Set; + +/** + * @author Tony Chemit - chemit@codelutin.com + * @since 0.3 + */ +public class CatchesImportServiceOnlyBiometrySampleIT extends AbstractImportDataServiceIT { + + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_OPERATION()); + } + + protected String[] getImportPath(String filename) { + return new String[]{"/import-data", "catches", filename}; + } + + @Test + public void doImportBiometrySample() throws Exception { + + assertImportCommonData(); + assertImportOperations(); + assertNoEntities(Sample.class, SampleData.class); + + CatchesImportConfiguration conf = new CatchesImportConfiguration(getLocale()); + + conf.setVoyageId(getVoyageId()); + + prepareInputFile(conf.getBiometrySampleFile(), getImportPath("biometrysample.csv.gz")); + + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.CatchesImportDataAction(), 1); + + assertNbIDs(result, 0, fixtures.NB_SAMPLE_BIOMETRY()); + assertCsvImportResult(result, 0, Sample.class, fixtures.NB_SAMPLE_BIOMETRY()); + assertCsvImportResult(result, 0, SampleData.class, fixtures.NB_SAMPLE_DATA_BIOMETRY()); + } + +} diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlySubSampleIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlySubSampleIT.java new file mode 100644 index 0000000..2a8442c --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlySubSampleIT.java @@ -0,0 +1,64 @@ +/* + * #%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; + +import fr.ifremer.echobase.entities.data.Sample; +import fr.ifremer.echobase.entities.data.SampleData; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import org.junit.Test; + +import java.util.Set; + +/** + * @author Tony Chemit - chemit@codelutin.com + * @since 0.3 + */ +public class CatchesImportServiceOnlySubSampleIT extends AbstractImportDataServiceIT { + + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_OPERATION()); + } + + protected String[] getImportPath(String filename) { + return new String[]{"/import-data", "catches", filename}; + } + + @Test + public void doImportSubSample() throws Exception { + + assertImportCommonData(); + assertImportOperations(); + assertNoEntities(Sample.class, SampleData.class); + + CatchesImportConfiguration conf = new CatchesImportConfiguration(getLocale()); + + conf.setVoyageId(getVoyageId()); + + prepareInputFile(conf.getSubSampleFile(), getImportPath("subsample.csv.gz")); + + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.CatchesImportDataAction(), 1); + + assertNbIDs(result, 0, fixtures.NB_SAMPLE_UNSORTED()); + assertCsvImportResult(result, 0, Sample.class, fixtures.NB_SAMPLE_UNSORTED()); + assertCsvImportResult(result, 0, SampleData.class, fixtures.NB_SAMPLE_DATA_UNSORTED()); + } + +} diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlyTotalSampleIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlyTotalSampleIT.java new file mode 100644 index 0000000..28b4073 --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CatchesImportServiceOnlyTotalSampleIT.java @@ -0,0 +1,64 @@ +/* + * #%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; + +import fr.ifremer.echobase.entities.data.Sample; +import fr.ifremer.echobase.entities.data.SampleData; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import org.junit.Test; + +import java.util.Set; + +/** + * @author Tony Chemit - chemit@codelutin.com + * @since 0.3 + */ +public class CatchesImportServiceOnlyTotalSampleIT extends AbstractImportDataServiceIT { + + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_OPERATION()); + } + + protected String[] getImportPath(String filename) { + return new String[]{"/import-data", "catches", filename}; + } + + @Test + public void doImportTotalSample() throws Exception { + + assertImportCommonData(); + assertImportOperations(); + assertNoEntities(Sample.class, SampleData.class); + + CatchesImportConfiguration conf = new CatchesImportConfiguration(getLocale()); + + conf.setVoyageId(getVoyageId()); + + prepareInputFile(conf.getTotalSampleFile(), getImportPath("totalsample.csv.gz")); + + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.CatchesImportDataAction(), 1); + + assertNbIDs(result, 0, fixtures.NB_SAMPLE_TOTAL()); + assertCsvImportResult(result, 0, Sample.class, fixtures.NB_SAMPLE_TOTAL()); + assertCsvImportResult(result, 0, SampleData.class, fixtures.NB_SAMPLE_DATA_TOTAL()); + } + +} diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonAllImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonAllImportServiceIT.java index fca3f96..8e2118a 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonAllImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonAllImportServiceIT.java @@ -27,11 +27,9 @@ import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * Tests common imports with {@link ImportType#COMMON_ALL} mode. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ @@ -39,8 +37,7 @@ public class CommonAllImportServiceIT extends AbstractImportDataServiceIT { @Override protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext( - fixtures.IMPORT_DATA_ECHOBASE_NO_DATA()); + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_NO_DATA()); } protected String[] getImportPath(String filename) { @@ -56,8 +53,7 @@ public class CommonAllImportServiceIT extends AbstractImportDataServiceIT { // import with mode all (voyage / transit / transect) - CommonImportConfiguration conf = - new CommonImportConfiguration(getLocale()); + CommonImportConfiguration conf = new CommonImportConfiguration(getLocale()); conf.setAreaOfOperationId(fixtures.AREA_OF_OPERATION_ID()); conf.setDatum(fixtures.DATUM()); @@ -74,8 +70,7 @@ public class CommonAllImportServiceIT extends AbstractImportDataServiceIT { conf.setImportType(ImportType.COMMON_ALL); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.CommonImportDataAction(), 3); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.CommonImportDataAction(), 3); assertNbIDs(result, 0, fixtures.NB_VOYAGE()); assertCsvImportResult(result, 0, Voyage.class, fixtures.NB_VOYAGE()); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonTransectImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonTransectImportServiceIT.java index bbb88b9..b950161 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonTransectImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonTransectImportServiceIT.java @@ -26,19 +26,16 @@ import fr.ifremer.echobase.entities.data.Transit; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * Tests common imports with {@link ImportType#COMMON_TRANSECT} mode. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ public class CommonTransectImportServiceIT extends AbstractImportDataServiceIT { protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext( - fixtures.IMPORT_DATA_ECHOBASE_COMMON_DATA()); + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_COMMON_DATA()); } protected String[] getImportPath(String filename) { @@ -52,8 +49,7 @@ public class CommonTransectImportServiceIT extends AbstractImportDataServiceIT { assertImportCommonData(); - CommonImportConfiguration conf = - new CommonImportConfiguration(getLocale()); + CommonImportConfiguration conf = new CommonImportConfiguration(getLocale()); conf.setDatum(fixtures.DATUM()); conf.setVoyageId(getVoyageId()); @@ -70,8 +66,7 @@ public class CommonTransectImportServiceIT extends AbstractImportDataServiceIT { transit.clearTransect(); } - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.CommonImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.CommonImportDataAction(), 1); assertNbIDs(result, 0, fixtures.NB_TRANSECT()); assertCsvImportResult(result, 0, Transect.class, fixtures.NB_TRANSECT()); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonTransitImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonTransitImportServiceIT.java index 9c0aa4f..e9ad1ce 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonTransitImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonTransitImportServiceIT.java @@ -28,11 +28,9 @@ import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * Tests common imports with {@link ImportType#COMMON_TRANSIT} mode. - * * @author Tony Chemit - chemit@codelutin.com * @since 2.2 */ @@ -40,8 +38,7 @@ public class CommonTransitImportServiceIT extends AbstractImportDataServiceIT { @Override protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext( - fixtures.IMPORT_DATA_ECHOBASE_COMMON_DATA()); + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_COMMON_DATA()); } protected String[] getImportPath(String filename) { @@ -62,8 +59,7 @@ public class CommonTransitImportServiceIT extends AbstractImportDataServiceIT { // import common data with mode transit - CommonImportConfiguration conf = - new CommonImportConfiguration(getLocale()); + CommonImportConfiguration conf = new CommonImportConfiguration(getLocale()); conf.setVoyageId(getVoyageId()); conf.setTransitRelatedActivity(fixtures.TRANSIT_RELATED_ACTIVITY()); @@ -72,8 +68,7 @@ public class CommonTransitImportServiceIT extends AbstractImportDataServiceIT { conf.setImportType(ImportType.COMMON_TRANSIT); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.CommonImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.CommonImportDataAction(), 1); assertNbIDs(result, 0, fixtures.NB_TRANSIT()); assertCsvImportResult(result, 0, Transit.class, fixtures.NB_TRANSIT()); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonVoyageImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonVoyageImportServiceIT.java index 4adc0cc..9e473ad 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonVoyageImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/CommonVoyageImportServiceIT.java @@ -28,11 +28,9 @@ import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * Tests common imports with {@link ImportType#COMMON_VOYAGE} mode. - * * @author Tony Chemit - chemit@codelutin.com * @since 2.2 */ @@ -40,8 +38,7 @@ public class CommonVoyageImportServiceIT extends AbstractImportDataServiceIT { @Override protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext( - fixtures.IMPORT_DATA_ECHOBASE_NO_DATA()); + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_NO_DATA()); } protected String[] getImportPath(String filename) { @@ -57,8 +54,7 @@ public class CommonVoyageImportServiceIT extends AbstractImportDataServiceIT { // import with mode voyage - CommonImportConfiguration conf = - new CommonImportConfiguration(getLocale()); + CommonImportConfiguration conf = new CommonImportConfiguration(getLocale()); conf.setAreaOfOperationId(fixtures.AREA_OF_OPERATION_ID()); conf.setDatum(fixtures.DATUM()); @@ -69,8 +65,7 @@ public class CommonVoyageImportServiceIT extends AbstractImportDataServiceIT { conf.setImportType(ImportType.COMMON_VOYAGE); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.CommonImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.CommonImportDataAction(), 1); assertNbIDs(result, 0, fixtures.NB_VOYAGE()); assertCsvImportResult(result, 0, Voyage.class, fixtures.NB_VOYAGE()); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/OperationImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/OperationImportServiceIT.java index 520126b..e0cb551 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/OperationImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/OperationImportServiceIT.java @@ -26,19 +26,16 @@ import fr.ifremer.echobase.entities.data.OperationMetadataValue; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * Tests {@link OperationImportService}. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ public class OperationImportServiceIT extends AbstractImportDataServiceIT { protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext( - fixtures.IMPORT_DATA_ECHOBASE_COMMON_DATA()); + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_COMMON_DATA()); } protected String[] getImportPath(String filename) { @@ -54,8 +51,7 @@ public class OperationImportServiceIT extends AbstractImportDataServiceIT { OperationMetadataValue.class, GearMetadataValue.class); - OperationImportConfiguration conf = - new OperationImportConfiguration(getLocale()); + OperationImportConfiguration conf = new OperationImportConfiguration(getLocale()); conf.setVoyageId(getVoyageId()); @@ -66,8 +62,7 @@ public class OperationImportServiceIT extends AbstractImportDataServiceIT { prepareInputFile(conf.getGearMetadataFile(), getImportPath("gearmetadatavalue.csv.gz")); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.OperationsImportDataAction(), 3); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.OperationsImportDataAction(), 3); assertNbIDs(result, 0, fixtures.NB_OPERATION()); assertCsvImportResult(result, 0, Operation.class, fixtures.NB_OPERATION()); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsEsduCellImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsEsduCellImportServiceIT.java index bc36133..b15fac5 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsEsduCellImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsEsduCellImportServiceIT.java @@ -31,11 +31,9 @@ import fr.ifremer.echobase.io.InputFile; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * Test import of esdu results. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ @@ -60,8 +58,7 @@ public class ResultsEsduCellImportServiceIT extends AbstractImportDataServiceIT assertNoEntities(Result.class); - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); conf.setResultLabel("resultLabel"); conf.setVoyageId(getVoyageId()); @@ -74,8 +71,7 @@ public class ResultsEsduCellImportServiceIT extends AbstractImportDataServiceIT conf.setDataProcessingId(getDataProcessingId()); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); assertNbIDs(result, 0, 43533); @@ -93,23 +89,20 @@ public class ResultsEsduCellImportServiceIT extends AbstractImportDataServiceIT assertNoEntities(Result.class); - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); conf.setResultLabel("resultLabel"); conf.setVoyageId(getVoyageId()); conf.setImportType(ImportType.RESULT_ESDU); InputFile inputFile = conf.getEsduByEchotypeAndSpeciesCategoryFile(); - prepareInputFile(inputFile, - getImportPath("byEchotypeAndSpeciesCategory.csv.gz")); + prepareInputFile(inputFile, getImportPath("byEchotypeAndSpeciesCategory.csv.gz")); addMissingEsduCells(EchoBaseCsvUtil.CELL_NAME, conf.getVoyageId(), inputFile); conf.setDataProcessingId(getDataProcessingId()); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); assertNbIDs(result, 0, 357291); @@ -128,23 +121,20 @@ public class ResultsEsduCellImportServiceIT extends AbstractImportDataServiceIT assertNoEntities(Result.class); - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); conf.setResultLabel("resultLabel"); conf.setVoyageId(getVoyageId()); conf.setImportType(ImportType.RESULT_ESDU); InputFile intputFile = conf.getEsduBySpeciesAndSizeCategoryFile(); - prepareInputFile(intputFile, - getImportPath("bySpeciesAndSizeCategory.csv.gz")); + prepareInputFile(intputFile, getImportPath("bySpeciesAndSizeCategory.csv.gz")); addMissingEsduCells(EchoBaseCsvUtil.CELL_NAME, conf.getVoyageId(), intputFile); conf.setDataProcessingId(getDataProcessingId()); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); assertNbIDs(result, 0, 68108); assertCsvImportResult(result, 0, Result.class, 68108); @@ -163,23 +153,20 @@ public class ResultsEsduCellImportServiceIT extends AbstractImportDataServiceIT assertNoEntities(Result.class); - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); conf.setResultLabel("resultLabel"); conf.setVoyageId(getVoyageId()); conf.setImportType(ImportType.RESULT_ESDU); InputFile inputFile = conf.getEsduBySpeciesAndAgeCategoryFile(); - prepareInputFile(inputFile, - getImportPath("bySpeciesAndAgeCategory.csv.gz")); + prepareInputFile(inputFile, getImportPath("bySpeciesAndAgeCategory.csv.gz")); addMissingEsduCells(EchoBaseCsvUtil.CELL_NAME, conf.getVoyageId(), inputFile); conf.setDataProcessingId(getDataProcessingId()); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); assertNbIDs(result, 0, 10021); assertCsvImportResult(result, 0, Category.class, 14); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsMapFishCellImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsMapFishCellImportServiceIT.java index 965f984..2706777 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsMapFishCellImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsMapFishCellImportServiceIT.java @@ -28,19 +28,16 @@ import fr.ifremer.echobase.entities.data.Result; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * To test the {@link ResultsMapFishCellImportService} service. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ public class ResultsMapFishCellImportServiceIT extends AbstractImportDataServiceIT { protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext( - fixtures.IMPORT_DATA_ECHOBASE_CATCHES_AND_VOYAGE_RESULT()); + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_CATCHES_AND_VOYAGE_RESULT()); } protected String[] getImportPath(String filename) { @@ -57,8 +54,7 @@ public class ResultsMapFishCellImportServiceIT extends AbstractImportDataService assertNoEntities(Result.class, Data.class); - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); conf.setResultLabel("resultLabel"); conf.setVoyageId(getVoyageId()); @@ -66,8 +62,7 @@ public class ResultsMapFishCellImportServiceIT extends AbstractImportDataService prepareInputFile(conf.getMapsFile(), getImportPath("mapsFish.csv.gz")); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); assertNbIDs(result, 0, 380); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsMapOtherCellImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsMapOtherCellImportServiceIT.java index 46b52c2..dcb54db 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsMapOtherCellImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsMapOtherCellImportServiceIT.java @@ -28,19 +28,16 @@ import fr.ifremer.echobase.entities.data.Result; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * To test the {@link ResultsMapOtherCellImportService} service. - * * @author Tony Chemit - chemit@codelutin.com * @since 2.2 */ public class ResultsMapOtherCellImportServiceIT extends AbstractImportDataServiceIT { protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext( - fixtures.IMPORT_DATA_ECHOBASE_CATCHES_AND_VOYAGE_RESULT()); + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_CATCHES_AND_VOYAGE_RESULT()); } protected String[] getImportPath(String filename) { @@ -57,8 +54,7 @@ public class ResultsMapOtherCellImportServiceIT extends AbstractImportDataServic assertNoEntities(Result.class, Data.class); - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); conf.setResultLabel("resultLabel"); conf.setVoyageId(getVoyageId()); @@ -66,8 +62,7 @@ public class ResultsMapOtherCellImportServiceIT extends AbstractImportDataServic prepareInputFile(conf.getMapsFile(), getImportPath("mapsOther.csv.gz")); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); assertNbIDs(result, 0, 380); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportServiceIT.java index 216e921..504e32a 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportServiceIT.java @@ -29,19 +29,16 @@ import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * To test the {@link ResultsRegionCellImportService} service. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ public class ResultsRegionCellImportServiceIT extends AbstractImportDataServiceIT { protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext( - fixtures.IMPORT_DATA_ECHOBASE_CATCHES_AND_VOYAGE_RESULT()); + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_CATCHES_AND_VOYAGE_RESULT()); } protected String[] getImportPath(String filename) { @@ -58,8 +55,7 @@ public class ResultsRegionCellImportServiceIT extends AbstractImportDataServiceI assertNoEntities(Result.class); - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); conf.setResultLabel("resultLabel"); conf.setVoyageId(getVoyageId()); @@ -76,8 +72,7 @@ public class ResultsRegionCellImportServiceIT extends AbstractImportDataServiceI conf.getVoyageId(), conf.getRegionAssociationFile()); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 3); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 3); assertNbIDs(result, 0, 10); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceIT.java index 1d0758b..297e83a 100644 --- a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceIT.java +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceIT.java @@ -25,14 +25,11 @@ import fr.ifremer.echobase.entities.data.Echotype; import fr.ifremer.echobase.entities.data.LengthAgeKey; import fr.ifremer.echobase.entities.data.LengthWeightKey; import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; -import org.junit.Ignore; import org.junit.Test; -import java.util.List; +import java.util.Set; /** - * To test the {@link ResultsVoyageImportService} service. - * * @author Tony Chemit - chemit@codelutin.com * @since 0.3 */ @@ -57,8 +54,7 @@ public class ResultsVoyageImportServiceIT extends AbstractImportDataServiceIT { assertNoEntities(LengthWeightKey.class); assertNoEntities(Echotype.class); - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); conf.setVoyageId(getVoyageId()); conf.setImportType(ImportType.RESULT_VOYAGE); @@ -69,8 +65,7 @@ public class ResultsVoyageImportServiceIT extends AbstractImportDataServiceIT { getImportPath("lengthWeightKey.csv.gz")); prepareInputFile(conf.getEchotypeFile(), getImportPath("echotype.csv.gz")); - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 3); + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 3); assertNbIDs(result, 0, fixtures.NB_LENGTH_AGE_KEY()); assertCsvImportResult(result, 0, LengthAgeKey.class, fixtures.NB_LENGTH_AGE_KEY()); @@ -82,81 +77,4 @@ public class ResultsVoyageImportServiceIT extends AbstractImportDataServiceIT { assertCsvImportResult(result, 2, Echotype.class, fixtures.NB_ECHOTYPE()); } - @Ignore - @Test - public void doImportLengthAgeKey() throws Exception { - - assertImportCommonData(); - assertImportOperations(); - assertImportSampleDatas(); - - assertNoEntities(LengthAgeKey.class); - - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); - - conf.setVoyageId(getVoyageId()); - conf.setImportType(ImportType.RESULT_VOYAGE); - - prepareInputFile(conf.getLengthAgeKeyFile(), - getImportPath("lengthAgeKey.csv.gz")); - - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); - - assertNbIDs(result, 0, fixtures.NB_LENGTH_AGE_KEY()); - assertCsvImportResult(result, 0, LengthAgeKey.class, fixtures.NB_LENGTH_AGE_KEY()); - } - - @Ignore - @Test - public void doImportLengthWeightKey() throws Exception { - - assertImportCommonData(); - assertImportOperations(); - assertImportSampleDatas(); - - assertNoEntities(LengthWeightKey.class); - - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); - - conf.setVoyageId(getVoyageId()); - conf.setImportType(ImportType.RESULT_VOYAGE); - - prepareInputFile(conf.getLengthWeightKeyFile(), - getImportPath("lengthWeightKey.csv.gz")); - - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); - - assertNbIDs(result, 0, fixtures.NB_LENGTH_WEIGHT_KEY()); - assertCsvImportResult(result, 0, LengthWeightKey.class, fixtures.NB_LENGTH_WEIGHT_KEY()); - } - - @Ignore - @Test - public void doImportEchotype() throws Exception { - - assertImportCommonData(); - assertImportOperations(); - assertImportSampleDatas(); - - assertNoEntities(Echotype.class); - - ResultsImportConfiguration conf = - new ResultsImportConfiguration(getLocale()); - - conf.setVoyageId(getVoyageId()); - conf.setImportType(ImportType.RESULT_VOYAGE); - - prepareInputFile(conf.getEchotypeFile(), getImportPath("echotype.csv.gz")); - - List<EchoBaseCsvFileImportResult> result; - result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); - - assertNbIDs(result, 0, fixtures.NB_ECHOTYPE()); - assertCsvImportResult(result, 0, Echotype.class, fixtures.NB_ECHOTYPE()); - } - } diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyEchotypeIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyEchotypeIT.java new file mode 100644 index 0000000..9d6122e --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyEchotypeIT.java @@ -0,0 +1,66 @@ +/* + * #%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; + +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Echotype; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import org.junit.Test; + +import java.util.Set; + +/** + * @author Tony Chemit - chemit@codelutin.com + * @since 0.3 + */ +public class ResultsVoyageImportServiceOnlyEchotypeIT extends AbstractImportDataServiceIT { + + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_CATCHES()); + } + + protected String[] getImportPath(String filename) { + return new String[]{"/import-data", "result", "voyage", filename}; + } + + @Test + public void doImportEchotype() throws Exception { + + assertImportCommonData(); + assertImportOperations(); + assertImportSampleDatas(); + + assertNoEntities(Echotype.class); + + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); + + conf.setVoyageId(getVoyageId()); + conf.setImportType(ImportType.RESULT_VOYAGE); + + prepareInputFile(conf.getEchotypeFile(), getImportPath("echotype.csv.gz")); + + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + + assertNbIDs(result, 0, fixtures.NB_ECHOTYPE()); + assertCsvImportResult(result, 0, Echotype.class, fixtures.NB_ECHOTYPE()); + } + +} diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyLengthAgeKeyIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyLengthAgeKeyIT.java new file mode 100644 index 0000000..ee8cee9 --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyLengthAgeKeyIT.java @@ -0,0 +1,67 @@ +/* + * #%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; + +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.LengthAgeKey; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import org.junit.Test; + +import java.util.Set; + +/** + * @author Tony Chemit - chemit@codelutin.com + * @since 0.3 + */ +public class ResultsVoyageImportServiceOnlyLengthAgeKeyIT extends AbstractImportDataServiceIT { + + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_CATCHES()); + } + + protected String[] getImportPath(String filename) { + return new String[]{"/import-data", "result", "voyage", filename}; + } + + @Test + public void doImportLengthAgeKey() throws Exception { + + assertImportCommonData(); + assertImportOperations(); + assertImportSampleDatas(); + + assertNoEntities(LengthAgeKey.class); + + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); + + conf.setVoyageId(getVoyageId()); + conf.setImportType(ImportType.RESULT_VOYAGE); + + prepareInputFile(conf.getLengthAgeKeyFile(), + getImportPath("lengthAgeKey.csv.gz")); + + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + + assertNbIDs(result, 0, fixtures.NB_LENGTH_AGE_KEY()); + assertCsvImportResult(result, 0, LengthAgeKey.class, fixtures.NB_LENGTH_AGE_KEY()); + } + +} diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyLengthWeightKeyIT.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyLengthWeightKeyIT.java new file mode 100644 index 0000000..dab283c --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/importdata/ResultsVoyageImportServiceOnlyLengthWeightKeyIT.java @@ -0,0 +1,67 @@ +/* + * #%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; + +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.LengthWeightKey; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import org.junit.Test; + +import java.util.Set; + +/** + * @author Tony Chemit - chemit@codelutin.com + * @since 0.3 + */ +public class ResultsVoyageImportServiceOnlyLengthWeightKeyIT extends AbstractImportDataServiceIT { + + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_CATCHES()); + } + + protected String[] getImportPath(String filename) { + return new String[]{"/import-data", "result", "voyage", filename}; + } + + @Test + public void doImportLengthWeightKey() throws Exception { + + assertImportCommonData(); + assertImportOperations(); + assertImportSampleDatas(); + + assertNoEntities(LengthWeightKey.class); + + ResultsImportConfiguration conf = new ResultsImportConfiguration(getLocale()); + + conf.setVoyageId(getVoyageId()); + conf.setImportType(ImportType.RESULT_VOYAGE); + + prepareInputFile(conf.getLengthWeightKeyFile(), + getImportPath("lengthWeightKey.csv.gz")); + + Set<ImportDataFileResult> result = doImport(conf, new ImportDataService.ResultsImportDataAction(), 1); + + assertNbIDs(result, 0, fixtures.NB_LENGTH_WEIGHT_KEY()); + assertCsvImportResult(result, 0, LengthWeightKey.class, fixtures.NB_LENGTH_WEIGHT_KEY()); + } + +} diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/AbstractLaunchImport.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/AbstractLaunchImport.java index 400a95d..9d93e9b 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/AbstractLaunchImport.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/AbstractLaunchImport.java @@ -24,6 +24,7 @@ import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.entities.EchoBaseUserPersistenceContext; import fr.ifremer.echobase.services.EchoBaseServiceSupport; import fr.ifremer.echobase.services.service.importdata.AbstractImportConfiguration; +import fr.ifremer.echobase.services.service.importdata.ImportDataResult; import fr.ifremer.echobase.services.service.importdata.ImportException; import fr.ifremer.echobase.ui.actions.AbstractWaitAndExecAction; import org.apache.commons.logging.Log; @@ -61,7 +62,7 @@ public abstract class AbstractLaunchImport<M extends AbstractImportConfiguration return t("echobase.info.importData.failed"); } - protected abstract String doImport(S service, M model, EchoBaseUser user) throws ImportException; + protected abstract ImportDataResult<M> doImport(S service, M model, EchoBaseUser user) throws ImportException; @Override protected String getResultMessage(M model) { @@ -83,8 +84,8 @@ public abstract class AbstractLaunchImport<M extends AbstractImportConfiguration log.info("Start imports for " + getModel()); } - String importResult = doImport(service, model, getEchoBaseSession().getUser()); - model.setResultMessage(importResult); + ImportDataResult<M> importResult = doImport(service, model, getEchoBaseSession().getUser()); + model.setResultMessage(importResult.getImportSummary()); } diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/GetDataProcessingsForVoyage.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/GetDataProcessingsForVoyage.java index 0db9eb7..eeb27dd 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/GetDataProcessingsForVoyage.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/GetDataProcessingsForVoyage.java @@ -24,7 +24,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.service.UserDbPersistenceService; -import fr.ifremer.echobase.services.service.importdata.ResultsImportService; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.lang3.StringUtils; @@ -68,7 +67,7 @@ public class GetDataProcessingsForVoyage extends EchoBaseActionSupport { voyage, "Could not find voyage with id " + voyageId); - dataProcessings = resultsImportService.getDataProcessings(voyage); + dataProcessings = userDbPersistenceService.getDataProcessings(voyage); } return SUCCESS; @@ -80,6 +79,4 @@ public class GetDataProcessingsForVoyage extends EchoBaseActionSupport { @Inject protected transient UserDbPersistenceService userDbPersistenceService; - @Inject - protected transient ResultsImportService resultsImportService; } diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchAcousticImport.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchAcousticImport.java index 3a22569..8c10048 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchAcousticImport.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchAcousticImport.java @@ -22,6 +22,7 @@ package fr.ifremer.echobase.ui.actions.importData; import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.services.service.importdata.AcousticImportConfiguration; +import fr.ifremer.echobase.services.service.importdata.ImportDataResult; import fr.ifremer.echobase.services.service.importdata.ImportDataService; import fr.ifremer.echobase.services.service.importdata.ImportException; @@ -40,7 +41,7 @@ public class LaunchAcousticImport extends AbstractLaunchImport<AcousticImportCon } @Override - protected String doImport(ImportDataService service, AcousticImportConfiguration model, EchoBaseUser user) throws ImportException { + protected ImportDataResult<AcousticImportConfiguration> doImport(ImportDataService service, AcousticImportConfiguration model, EchoBaseUser user) throws ImportException { return service.doImportAcoustics(model, user); } } diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchCatchesImport.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchCatchesImport.java index 1072b7e..597ff32 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchCatchesImport.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchCatchesImport.java @@ -22,6 +22,7 @@ package fr.ifremer.echobase.ui.actions.importData; import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.services.service.importdata.CatchesImportConfiguration; +import fr.ifremer.echobase.services.service.importdata.ImportDataResult; import fr.ifremer.echobase.services.service.importdata.ImportDataService; import fr.ifremer.echobase.services.service.importdata.ImportException; @@ -40,7 +41,7 @@ public class LaunchCatchesImport extends AbstractLaunchImport<CatchesImportConfi } @Override - protected String doImport(ImportDataService service, CatchesImportConfiguration model, EchoBaseUser user) throws ImportException { + protected ImportDataResult<CatchesImportConfiguration> doImport(ImportDataService service, CatchesImportConfiguration model, EchoBaseUser user) throws ImportException { return service.doImportCatches(model, user); } } diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchCommonImport.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchCommonImport.java index badc72c..5e6845f 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchCommonImport.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchCommonImport.java @@ -22,6 +22,7 @@ package fr.ifremer.echobase.ui.actions.importData; import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.services.service.importdata.CommonImportConfiguration; +import fr.ifremer.echobase.services.service.importdata.ImportDataResult; import fr.ifremer.echobase.services.service.importdata.ImportDataService; import fr.ifremer.echobase.services.service.importdata.ImportException; @@ -40,7 +41,7 @@ public class LaunchCommonImport extends AbstractLaunchImport<CommonImportConfigu } @Override - protected String doImport(ImportDataService service, CommonImportConfiguration model, EchoBaseUser user) throws ImportException { + protected ImportDataResult<CommonImportConfiguration> doImport(ImportDataService service, CommonImportConfiguration model, EchoBaseUser user) throws ImportException { return service.doImportCommons(model, user); } } diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchOperationImport.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchOperationImport.java index 676dd41..847944d 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchOperationImport.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchOperationImport.java @@ -21,6 +21,7 @@ package fr.ifremer.echobase.ui.actions.importData; import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.services.service.importdata.ImportDataResult; import fr.ifremer.echobase.services.service.importdata.ImportDataService; import fr.ifremer.echobase.services.service.importdata.ImportException; import fr.ifremer.echobase.services.service.importdata.OperationImportConfiguration; @@ -40,7 +41,7 @@ public class LaunchOperationImport extends AbstractLaunchImport<OperationImportC } @Override - protected String doImport(ImportDataService service, OperationImportConfiguration model, EchoBaseUser user) throws ImportException { + protected ImportDataResult<OperationImportConfiguration> doImport(ImportDataService service, OperationImportConfiguration model, EchoBaseUser user) throws ImportException { return service.doImportOperations(model, user); } } diff --git a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchResultsImport.java b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchResultsImport.java index 152c036..3bb7c6f 100644 --- a/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchResultsImport.java +++ b/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchResultsImport.java @@ -21,6 +21,7 @@ package fr.ifremer.echobase.ui.actions.importData; import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.services.service.importdata.ImportDataResult; import fr.ifremer.echobase.services.service.importdata.ImportDataService; import fr.ifremer.echobase.services.service.importdata.ImportException; import fr.ifremer.echobase.services.service.importdata.ResultsImportConfiguration; @@ -40,7 +41,7 @@ public class LaunchResultsImport extends AbstractLaunchImport<ResultsImportConfi } @Override - protected String doImport(ImportDataService service, ResultsImportConfiguration model, EchoBaseUser user) throws ImportException { + protected ImportDataResult<ResultsImportConfiguration> doImport(ImportDataService service, ResultsImportConfiguration model, EchoBaseUser user) throws ImportException { return service.doImportResults(model, user); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.