This is an automated email from the git hooks/post-receive script. New commit to branch feature/6688 in repository tutti. See http://git.codelutin.com/tutti.git commit 1e67a06126dcb434f3fcaf3aae7b25bccfacc50c Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Feb 25 19:25:14 2015 +0100 introduce file result --- .../genericformat/GenericFormatFileResult.java | 52 ++++++ .../genericformat/GenericFormatImportService.java | 178 +++++++++++++++------ .../GenericFormatReferentialImportResult.java | 32 +++- 3 files changed, 203 insertions(+), 59 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatFileResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatFileResult.java new file mode 100644 index 0000000..9f78be6 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatFileResult.java @@ -0,0 +1,52 @@ +package fr.ifremer.tutti.service.genericformat; + +import java.io.Serializable; +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +/** + * Created on 2/25/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14 + */ +public class GenericFormatFileResult implements Serializable { + + private static final long serialVersionUID = 1L; + + private final String filename; + + private final int linesCount; + + private final Map<Long, String> errors; + + public GenericFormatFileResult(String filename, int linesCount, Map<Long, String> errors) { + this.filename = filename; + this.linesCount = linesCount; + if (errors == null) { + errors = Collections.emptyMap(); + } + this.errors = errors; + } + + public String getFilename() { + return filename; + } + + public int getLinesCount() { + return linesCount; + } + + public Set<Map.Entry<Long, String>> getErrorsEntries() { + return errors.entrySet(); + } + + public boolean isValid() { + return errors.isEmpty(); + } + + public void addErrors(Map<Long, String> errors) { + errors.putAll(errors); + } +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportService.java index 8d60247..be0677f 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportService.java @@ -89,14 +89,14 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { GenericFormatArchive archive = createArchive(importConfiguration); int result = 6 // check sampleCategoryModel + import ( gear + person + species + vessel + protocol ) - + archive.countImportLines(archive.getSurveyPath()) // load cruises - + archive.countImportLines(archive.getGearCaracteristicsPath()) // load gear caracteristics - + archive.countImportLines(archive.getOperationPath()) // load operations - + archive.countImportLines(archive.getParameterPath()) // load parameters - + archive.countImportLines(archive.getCatchPath()) // load catches - + archive.countImportLines(archive.getMarineLitterPath()) // load marine litters - + archive.countImportLines(archive.getIndividualObservationPath()) // load individualObservations - + archive.countImportLines(archive.getAccidentalCatchPath()); // load accidental catches + + archive.getSurveyLineCount() // load cruises + + archive.getGearCaracteristicsPathLineCount()// load gear caracteristics + + archive.getOperationPathLineCount() // load operations + + archive.getParameterPathLineCount()// load parameters + + archive.getCatchPathLineCount()// load catches + + archive.getMarineLitterPathLineCount()// load marine litters + + archive.getIndividualObservationPathLineCount()// load individualObservations + + archive.getAccidentalCatchPathLineCount(); // load accidental catches return result; @@ -152,11 +152,11 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { GenericFormatArchive archive = createArchive(importConfiguration); - int nbCruises = archive.countImportLines(archive.getSurveyPath()); + int nbCruises = archive.getSurveyLineCount(); if (log.isInfoEnabled()) { log.info("Count " + nbCruises + " cruises to import."); } - int nbOperations = archive.countImportLines(archive.getOperationPath()); + int nbOperations = archive.getOperationPathLineCount(); if (log.isInfoEnabled()) { log.info("Count " + nbOperations + " operations to import."); } @@ -224,10 +224,10 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { try (GenericFormatValidateFileContext importContext = new GenericFormatValidateFileContext(request, progressionModel, persistenceService, cruiseDecorator, fishingOperationDecorator)) { checkSampleCategoryModel(importContext); - importTemporaryGears(importContext); - importTemporaryPersons(importContext); - importTemporarySpecies(importContext); - importTemporaryVessels(importContext); + importTemporaryGears(importContext, false); + importTemporaryPersons(importContext, false); + importTemporarySpecies(importContext, false); + importTemporaryVessels(importContext, false); importProtocol(importContext); validateCruises(importContext); @@ -253,10 +253,10 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { GenericformatImportPersitenceHelper persitenceHelper = new GenericformatImportPersitenceHelper(importContext, persistenceService, cruiseDecorator, fishingOperationDecorator); checkSampleCategoryModel(importContext); - importTemporaryGears(importContext); - importTemporaryPersons(importContext); - importTemporarySpecies(importContext); - importTemporaryVessels(importContext); + importTemporaryGears(importContext, true); + importTemporaryPersons(importContext, true); + importTemporarySpecies(importContext, true); + importTemporaryVessels(importContext, true); importProtocol(importContext); importCruises(importContext, persitenceHelper); @@ -329,7 +329,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.sampleCategoryModel")); - try (CsvConsumerForSampleCategory consumer = importContext.loadSampleCategories()) { + try (CsvConsumerForSampleCategory consumer = importContext.loadSampleCategories(true)) { int nbCategories = 0; for (ImportRow<SampleCategoryRow> row : consumer) { @@ -349,7 +349,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } - protected void importTemporaryGears(GenericFormatImportContext importContext) { + protected void importTemporaryGears(GenericFormatImportContext importContext, boolean reportError) { importContext.increments(t("tutti.service.genericFormat.import.temporaryGears")); GenericFormatArchive archive = importContext.getImportRequest().getArchive(); @@ -362,19 +362,27 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Import temporary gears."); } + Map<Long, String> rowsInError = null; + ReferentialImportRequest<Gear, Integer> referentialImportRequest = referentialTemporaryGearService.createReferentialImportRequest(); - try (CsvConsumerForTemporaryGear consumer = importContext.loadTemporaryGears()) { + try (CsvConsumerForTemporaryGear consumer = importContext.loadTemporaryGears(reportError)) { for (ImportRow<GearRow> row : consumer) { consumer.checkRowForGenericFormatImport(row, referentialImportRequest); } + + if (consumer.foundSomeErrors()) { + rowsInError = consumer.getRowsInError(); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close gears.csv file", e); } ReferentialImportResult<Gear> referentialImportResult = referentialTemporaryGearService.executeImportRequest(referentialImportRequest); - importResult = new GenericFormatReferentialImportResult<>(referentialImportRequest, referentialImportResult); + int linesCount = importContext.getImportRequest().getArchive().getTemporaryReferentialGearLineCount(); + importResult = new GenericFormatReferentialImportResult<>("gear.csv", linesCount, referentialImportRequest, referentialImportResult, rowsInError); if (log.isInfoEnabled()) { log.info("Temporary gears import result: " + importResult.getReport()); } @@ -384,7 +392,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { if (log.isInfoEnabled()) { log.info("Skip import temporary gears (no file found)."); } - importResult = new GenericFormatReferentialImportResult<>(); + importResult = new GenericFormatReferentialImportResult<>("gear.csv"); } @@ -392,7 +400,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } - protected void importTemporaryPersons(GenericFormatImportContext importContext) { + protected void importTemporaryPersons(GenericFormatImportContext importContext, boolean reportError) { importContext.increments(t("tutti.service.genericFormat.import.temporaryPersons")); GenericFormatArchive archive = importContext.getImportRequest().getArchive(); @@ -405,19 +413,26 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Import temporary persons."); } + Map<Long, String> rowsInError = null; + ReferentialImportRequest<Person, Integer> referentialImportRequest = referentialTemporaryPersonService.createReferentialImportRequest(); - try (CsvConsumerForTemporaryPerson consumer = importContext.loadTemporaryPersons()) { + try (CsvConsumerForTemporaryPerson consumer = importContext.loadTemporaryPersons(reportError)) { for (ImportRow<PersonRow> row : consumer) { consumer.checkRowForGenericFormatImport(row, referentialImportRequest); } + + if (consumer.foundSomeErrors()) { + rowsInError = consumer.getRowsInError(); + } } catch (IOException e) { throw new ApplicationTechnicalException("Could not close person.csv file", e); } ReferentialImportResult<Person> referentialImportResult = referentialTemporaryPersonService.executeImportRequest(referentialImportRequest); - importResult = new GenericFormatReferentialImportResult<>(referentialImportRequest, referentialImportResult); + int linesCount = importContext.getImportRequest().getArchive().getTemporaryReferentialPersonLineCount(); + importResult = new GenericFormatReferentialImportResult<>("person.csv", linesCount, referentialImportRequest, referentialImportResult, rowsInError); if (log.isInfoEnabled()) { log.info("Temporary persons import result: " + importResult.getReport()); } @@ -427,7 +442,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { if (log.isInfoEnabled()) { log.info("Skip import temporary persons (no file found)."); } - importResult = new GenericFormatReferentialImportResult<>(); + importResult = new GenericFormatReferentialImportResult<>("person.csv"); } @@ -435,7 +450,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } - protected void importTemporarySpecies(GenericFormatImportContext importContext) { + protected void importTemporarySpecies(GenericFormatImportContext importContext, boolean reportError) { importContext.increments(t("tutti.service.genericFormat.import.temporarySpecies")); @@ -450,17 +465,23 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { ReferentialImportRequest<Species, Integer> referentialImportRequest = referentialTemporarySpeciesService.createReferentialImportRequest(); - try (CsvConsumerForTemporarySpecies consumer = importContext.loadTemporarySpecies()) { + Map<Long, String> rowsInError = null; + try (CsvConsumerForTemporarySpecies consumer = importContext.loadTemporarySpecies(reportError)) { for (ImportRow<SpeciesRow> row : consumer) { consumer.checkRowForGenericFormatImport(row, referentialImportRequest); } + + if (consumer.foundSomeErrors()) { + rowsInError = consumer.getRowsInError(); + } } catch (IOException e) { throw new ApplicationTechnicalException("Could not close species.csv file", e); } ReferentialImportResult<Species> referentialImportResult = referentialTemporarySpeciesService.executeImportRequest(referentialImportRequest); - importResult = new GenericFormatReferentialImportResult<>(referentialImportRequest, referentialImportResult); + int linesCount = importContext.getImportRequest().getArchive().getTemporaryReferentialSpeciesLineCount(); + importResult = new GenericFormatReferentialImportResult<>("species.csv", linesCount, referentialImportRequest, referentialImportResult, rowsInError); if (log.isInfoEnabled()) { log.info("Temporary species import result: " + importResult.getReport()); @@ -470,7 +491,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { if (log.isInfoEnabled()) { log.info("Skip import temporary species (no file found)."); } - importResult = new GenericFormatReferentialImportResult<>(); + importResult = new GenericFormatReferentialImportResult<>("species.csv"); } @@ -478,7 +499,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } - protected void importTemporaryVessels(GenericFormatImportContext importContext) { + protected void importTemporaryVessels(GenericFormatImportContext importContext, boolean reportError) { importContext.increments(t("tutti.service.genericFormat.import.temporaryVessels")); GenericFormatArchive archive = importContext.getImportRequest().getArchive(); @@ -493,17 +514,23 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { ReferentialImportRequest<Vessel, String> referentialImportRequest = referentialTemporaryVesselService.createReferentialImportRequest(); - try (CsvConsumerForTemporaryVessel consumer = importContext.loadTemporaryVessels()) { + Map<Long, String> rowsInError = null; + try (CsvConsumerForTemporaryVessel consumer = importContext.loadTemporaryVessels(reportError)) { for (ImportRow<VesselRow> row : consumer) { consumer.checkRowForGenericFormatImport(row, referentialImportRequest); } + + if (consumer.foundSomeErrors()) { + rowsInError = consumer.getRowsInError(); + } } catch (IOException e) { throw new ApplicationTechnicalException("Could not close vessel.csv file", e); } ReferentialImportResult<Vessel> referentialImportResult = referentialTemporaryVesselService.executeImportRequest(referentialImportRequest); - importResult = new GenericFormatReferentialImportResult<>(referentialImportRequest, referentialImportResult); + int linesCount = importContext.getImportRequest().getArchive().getTemporaryReferentialVesselLineCount(); + importResult = new GenericFormatReferentialImportResult<>("vessel.csv", linesCount, referentialImportRequest, referentialImportResult, rowsInError); if (log.isInfoEnabled()) { log.info("Temporary vessels import result: " + importResult.getReport()); @@ -514,7 +541,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { if (log.isInfoEnabled()) { log.info("Skip import temporary vessels (no file found)."); } - importResult = new GenericFormatReferentialImportResult<>(); + importResult = new GenericFormatReferentialImportResult<>("vessel.csv"); } @@ -563,7 +590,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Validate survey.csv file."); } - try (CsvConsumerForSurvey consumer = importContext.loadSurveys()) { + try (CsvConsumerForSurvey consumer = importContext.loadSurveys(false)) { for (ImportRow<SurveyRow> row : consumer) { importContext.increments(t("tutti.service.genericFormat.validate.cruises", row.getLineNumber())); @@ -577,10 +604,17 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { importContext.addImportedCruise(cruise, !createCruise); } + + if (consumer.foundSomeErrors()) { + Map<Long, String> rowsInError = consumer.getRowsInError(); + importContext.getSurveyFileResult().addErrors(rowsInError); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close survey.csv file", e); } + } protected void validateGearCaracteristics(GenericFormatValidateFileContext importContext) { @@ -589,7 +623,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Validate gearCaracteristics.csv file."); } - try (CsvConsumerForGearCaracteristic consumer = importContext.loadGearCaracteristics()) { + try (CsvConsumerForGearCaracteristic consumer = importContext.loadGearCaracteristics(false)) { for (ImportRow<GearCaracteristicRow> row : consumer) { importContext.increments(t("tutti.service.genericFormat.validate.gearCaracteristics", row.getLineNumber())); @@ -598,6 +632,12 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { consumer.prepareRowForPersist(cruiseContext, row); } + + if (consumer.foundSomeErrors()) { + Map<Long, String> rowsInError = consumer.getRowsInError(); + importContext.getGearCaracteristicFileResult().addErrors(rowsInError); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close gearCaracteristic.csv file", e); } @@ -610,7 +650,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Validate operation.csv file."); } - try (CsvConsumerForOperation consumer = importContext.loadOperations()) { + try (CsvConsumerForOperation consumer = importContext.loadOperations(false)) { for (ImportRow<OperationRow> row : consumer) { importContext.increments(t("tutti.service.genericFormat.validate.operations", row.getLineNumber())); @@ -626,6 +666,12 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { importContext.addImportedFishingOperation(fishingOperation, catchBatch); } + + if (consumer.foundSomeErrors()) { + Map<Long, String> rowsInError = consumer.getRowsInError(); + importContext.getOperationFileResult().addErrors(rowsInError); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close operation.csv file", e); } @@ -638,7 +684,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Validate parameter.csv file."); } - try (CsvConsumerForParameter consumer = importContext.loadParameters()) { + try (CsvConsumerForParameter consumer = importContext.loadParameters(false)) { for (ImportRow<ParameterRow> row : consumer) { importContext.increments(t("tutti.service.genericFormat.validate.parameters", row.getLineNumber())); @@ -647,6 +693,12 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { consumer.prepareRowForPersist(operationContext, row); } + + if (consumer.foundSomeErrors()) { + Map<Long, String> rowsInError = consumer.getRowsInError(); + importContext.getParameterFileResult().addErrors(rowsInError); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close parameter.csv file", e); } @@ -659,7 +711,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Validate catch.csv file."); } - try (CsvConsumerForCatch consumer = importContext.loadCatches()) { + try (CsvConsumerForCatch consumer = importContext.loadCatches(false)) { for (ImportRow<CatchRow> row : consumer) { importContext.increments(t("tutti.service.genericFormat.validate.catches", row.getLineNumber())); @@ -668,6 +720,12 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { consumer.prepareRowForPersist(operationContext, row); } + + if (consumer.foundSomeErrors()) { + Map<Long, String> rowsInError = consumer.getRowsInError(); + importContext.getCatchFileResult().addErrors(rowsInError); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close catch.csv file", e); } @@ -680,7 +738,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Validate marineLitter.csv file."); } - try (CsvConsumerForMarineLitter consumer = importContext.loadMarineLitters()) { + try (CsvConsumerForMarineLitter consumer = importContext.loadMarineLitters(false)) { for (ImportRow<MarineLitterRow> row : consumer) { importContext.increments(t("tutti.service.genericFormat.validate.marineLitters", row.getLineNumber())); @@ -689,6 +747,12 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { consumer.prepareRowForPersist(operationContext, row); } + + if (consumer.foundSomeErrors()) { + Map<Long, String> rowsInError = consumer.getRowsInError(); + importContext.getMarineLitterFileResult().addErrors(rowsInError); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close marineLitter.csv file", e); } @@ -701,7 +765,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Validate individualObservation.csv file."); } - try (CsvConsumerForIndividualObservation consumer = importContext.loadIndividualObservations()) { + try (CsvConsumerForIndividualObservation consumer = importContext.loadIndividualObservations(false)) { for (ImportRow<IndividualObservationRow> row : consumer) { importContext.increments(t("tutti.service.genericFormat.validate.individualObservations", row.getLineNumber())); @@ -710,6 +774,12 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { consumer.prepareRowForPersist(operationContext, row); } + + if (consumer.foundSomeErrors()) { + Map<Long, String> rowsInError = consumer.getRowsInError(); + importContext.getIndividualObservationFileResult().addErrors(rowsInError); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close individualObservation.csv file", e); } @@ -722,7 +792,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Validate accidentalCatch.csv file."); } - try (CsvConsumerForAccidentalCatch consumer = importContext.loadAccidentalCatches()) { + try (CsvConsumerForAccidentalCatch consumer = importContext.loadAccidentalCatches(false)) { for (ImportRow<AccidentalCatchRow> row : consumer) { importContext.increments(t("tutti.service.genericFormat.validate.accidentalCatches", row.getLineNumber())); @@ -731,6 +801,12 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { consumer.prepareRowForPersist(operationContext, row); } + + if (consumer.foundSomeErrors()) { + Map<Long, String> rowsInError = consumer.getRowsInError(); + importContext.getAccidentalCatchFileResult().addErrors(rowsInError); + } + } catch (IOException e) { throw new ApplicationTechnicalException("Could not close accidentalCatch.csv file", e); } @@ -744,7 +820,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.cruises")); - try (CsvConsumerForSurvey consumer = importContext.loadSurveys()) { + try (CsvConsumerForSurvey consumer = importContext.loadSurveys(true)) { for (ImportRow<SurveyRow> row : consumer) { consumer.validateRow(row, importContext); @@ -766,7 +842,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.gearCaracteristics")); - try (CsvConsumerForGearCaracteristic consumer = importContext.loadGearCaracteristics()) { + try (CsvConsumerForGearCaracteristic consumer = importContext.loadGearCaracteristics(true)) { for (ImportRow<GearCaracteristicRow> row : consumer) { GenericFormatImportCruiseContext cruiseContext = consumer.validateRow(row, importContext); @@ -788,7 +864,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.operations")); - try (CsvConsumerForOperation consumer = importContext.loadOperations()) { + try (CsvConsumerForOperation consumer = importContext.loadOperations(true)) { for (ImportRow<OperationRow> row : consumer) { GenericFormatImportCruiseContext cruiseContext = consumer.validateRow(row, importContext); @@ -815,7 +891,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.parameters")); - try (CsvConsumerForParameter consumer = importContext.loadParameters()) { + try (CsvConsumerForParameter consumer = importContext.loadParameters(true)) { for (ImportRow<ParameterRow> row : consumer) { GenericFormatImportOperationContext operationContext = consumer.validateRow(row, importContext); @@ -837,7 +913,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.catches")); - try (CsvConsumerForCatch consumer = importContext.loadCatches()) { + try (CsvConsumerForCatch consumer = importContext.loadCatches(true)) { for (ImportRow<CatchRow> row : consumer) { GenericFormatImportOperationContext operationContext = consumer.validateRow(row, importContext); @@ -860,7 +936,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.marineLitters")); - try (CsvConsumerForMarineLitter consumer = importContext.loadMarineLitters()) { + try (CsvConsumerForMarineLitter consumer = importContext.loadMarineLitters(true)) { for (ImportRow<MarineLitterRow> row : consumer) { GenericFormatImportOperationContext operationContext = consumer.validateRow(row, importContext); @@ -882,7 +958,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.individualObservations")); - try (CsvConsumerForIndividualObservation consumer = importContext.loadIndividualObservations()) { + try (CsvConsumerForIndividualObservation consumer = importContext.loadIndividualObservations(true)) { for (ImportRow<IndividualObservationRow> row : consumer) { GenericFormatImportOperationContext operationContext = consumer.validateRow(row, importContext); @@ -904,7 +980,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } importContext.increments(t("tutti.service.genericFormat.import.accidentalCatches")); - try (CsvConsumerForAccidentalCatch consumer = importContext.loadAccidentalCatches()) { + try (CsvConsumerForAccidentalCatch consumer = importContext.loadAccidentalCatches(true)) { for (ImportRow<AccidentalCatchRow> row : consumer) { GenericFormatImportOperationContext operationContext = consumer.validateRow(row, importContext); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatReferentialImportResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatReferentialImportResult.java index bf4bb86..7b13241 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatReferentialImportResult.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatReferentialImportResult.java @@ -6,11 +6,11 @@ import fr.ifremer.tutti.persistence.entities.referential.TuttiReferentialEntity; import fr.ifremer.tutti.service.referential.ReferentialImportRequest; import fr.ifremer.tutti.service.referential.ReferentialImportResult; -import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; /** @@ -19,7 +19,7 @@ import java.util.TreeMap; * @author Tony Chemit - chemit@codelutin.com * @since 3.14 */ -public class GenericFormatReferentialImportResult<E extends TuttiReferentialEntity, K extends Comparable<K>> implements Serializable { +public class GenericFormatReferentialImportResult<E extends TuttiReferentialEntity, K extends Comparable<K>> extends GenericFormatFileResult { private static final long serialVersionUID = 1L; @@ -29,13 +29,16 @@ public class GenericFormatReferentialImportResult<E extends TuttiReferentialEnti private final Map<String, String> idTranslationMap; - public GenericFormatReferentialImportResult() { + public GenericFormatReferentialImportResult(String filename) { + super(filename, 0, null); this.entitiesAdded = Collections.emptyMap(); this.entitiesLinked = Collections.emptyMap(); this.idTranslationMap = Collections.emptyMap(); } - public GenericFormatReferentialImportResult(ReferentialImportRequest<E, K> importRequest, ReferentialImportResult<E> importResult) { + public GenericFormatReferentialImportResult(String filename, int linesCount, ReferentialImportRequest<E, K> importRequest, ReferentialImportResult<E> importResult, Map<Long, String> rowsInError) { + + super(filename, linesCount, rowsInError); Map<String, String> translationMap = new TreeMap<>(); @@ -55,12 +58,12 @@ public class GenericFormatReferentialImportResult<E extends TuttiReferentialEnti } - public Map<String, E> getEntitiesAdded() { - return entitiesAdded; + public Set<Map.Entry<String, E>> getEntitiesAddedEntries() { + return entitiesAdded.entrySet(); } - public Map<String, E> getEntitiesLinked() { - return entitiesLinked; + public Set<Map.Entry<String, E>> getEntitiesLinkedEntries() { + return entitiesLinked.entrySet(); } public Map<String, String> getIdTranslationMap() { @@ -98,6 +101,19 @@ public class GenericFormatReferentialImportResult<E extends TuttiReferentialEnti StringBuilder builder = new StringBuilder(); + Set<Map.Entry<Long, String>> errors = getErrorsEntries(); + + if (!errors.isEmpty()) { + + builder.append(String.format("%s lines in error:", errors.size())); + for (Map.Entry<Long, String> entry : errors) { + Long lineNumber = entry.getKey(); + String error = entry.getValue(); + builder.append(String.format("\nline %s : \n%s", lineNumber, error)); + } + + } + List<String> added = getMapReport(entitiesAdded); if (!added.isEmpty()) { builder.append(String.format("\n%s entities added: \n%s", added.size(), Joiner.on("\n").join(added))); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.