This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit 27daf67ccf5b0743ea72a453cb29d8ecb9e7780e Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Feb 15 20:36:27 2015 +0100 - normalize entity list parser formatter - make samplecategorymodel import ok - survey are ok to be imported now - start writting test of import --- .../csv/EntityListParserFormatterSupport.java | 4 +- .../tutti/service/csv/GearListParserFormatter.java | 25 ++++++ ...matter.java => IntegerListParserFormatter.java} | 2 +- .../tutti/service/csv/ProgramFormatter.java | 23 ----- .../tutti/service/csv/ProgramParserFormatter.java | 46 ++++++++++ .../fr/ifremer/tutti/service/csv/TuttiCsvUtil.java | 20 +++-- .../GenericFormatImportEntityParserFactory.java | 58 ++++++++++--- .../genericformat/GenericFormatImportService.java | 98 ++++++++++++++++++++-- .../consumer/CsvConsumerForSampleCategory.java | 2 +- .../service/genericformat/csv/OperationModel.java | 12 +-- .../genericformat/csv/SampleCategoryModel.java | 2 +- .../genericformat/csv/SampleCategoryRow.java | 3 + .../service/genericformat/csv/SurveyModel.java | 22 +++-- .../tutti/service/protocol/SpeciesRowModel.java | 4 +- .../consumer/CsvConsumerForTemporarySpecies.java | 4 +- .../GenericFormatImportServiceTest.java | 80 ++++++++++++++++++ .../genericFormat/empty/accidentalCatch.csv | 1 + .../test/resources/genericFormat/empty/catch.csv | 1 + .../genericFormat/empty/gearCaracteristics.csv | 1 + .../genericFormat/empty/individualObservation.csv | 1 + .../resources/genericFormat/empty/marineLitter.csv | 1 + .../resources/genericFormat/empty/operation.csv | 1 + .../resources/genericFormat/empty/parameter.csv | 1 + .../genericFormat/empty/protocol.tuttiProtocol | 81 ++++++++++++++++++ .../genericFormat/empty/sampleCategory.csv | 6 ++ .../test/resources/genericFormat/empty/survey.csv | 2 + .../genericFormat/empty/temporaryPersons.csv | 4 + .../genericFormat/empty/temporarySpecies.csv | 9 ++ .../genericFormat/empty/temporaryVessels.csv | 1 + .../ImportGenericFormatProgramCruisesAction.java | 20 ++--- 30 files changed, 453 insertions(+), 82 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/EntityListParserFormatterSupport.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/EntityListParserFormatterSupport.java index 14b80d9..91a08be 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/EntityListParserFormatterSupport.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/EntityListParserFormatterSupport.java @@ -26,10 +26,10 @@ public abstract class EntityListParserFormatterSupport<E extends TuttiEntity> im public List<E> parse(String value) throws ParseException { List<E> list = new ArrayList<>(); - String[] ids = value.split("|"); + String[] ids = value.split("\\|"); for (String id : ids) { - E entity = delegateParserFormatter.parse(id); + E entity = delegateParserFormatter.parse(id.trim()); list.add(entity); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/GearListParserFormatter.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/GearListParserFormatter.java new file mode 100644 index 0000000..e24f33b --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/GearListParserFormatter.java @@ -0,0 +1,25 @@ +package fr.ifremer.tutti.service.csv; + +import fr.ifremer.tutti.persistence.entities.referential.Gear; + +/** + * Created on 2/15/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14 + */ +public class GearListParserFormatter extends EntityListParserFormatterSupport<Gear> { + + public static GearListParserFormatter newFormatter(GearParserFormatter delegateParserFormatter) { + return new GearListParserFormatter(delegateParserFormatter); + } + + public static GearListParserFormatter newParser(GearParserFormatter delegateParserFormatter) { + return new GearListParserFormatter(delegateParserFormatter); + } + + protected GearListParserFormatter(GearParserFormatter delegateParserFormatter) { + super(delegateParserFormatter); + } + +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ListIntegerFormatter.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/IntegerListParserFormatter.java similarity index 93% rename from tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ListIntegerFormatter.java rename to tutti-service/src/main/java/fr/ifremer/tutti/service/csv/IntegerListParserFormatter.java index 1bdf0a9..e79c0a0 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ListIntegerFormatter.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/IntegerListParserFormatter.java @@ -15,7 +15,7 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 3.13 */ -public class ListIntegerFormatter implements ValueParserFormatter<List<Integer>> { +public class IntegerListParserFormatter implements ValueParserFormatter<List<Integer>> { @Override public String format(List<Integer> value) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ProgramFormatter.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ProgramFormatter.java deleted file mode 100644 index 8acd5d1..0000000 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ProgramFormatter.java +++ /dev/null @@ -1,23 +0,0 @@ -package fr.ifremer.tutti.service.csv; - -import fr.ifremer.tutti.persistence.entities.data.Program; -import fr.ifremer.tutti.persistence.entities.data.Programs; -import org.nuiton.csv.ValueFormatter; - -/** - * Created on 2/8/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.13 - */ -public class ProgramFormatter implements ValueFormatter<Program> { - - @Override - public String format(Program value) { - String result = ""; - if (value != null) { - result = Programs.GET_NAME.apply(value); - } - return result; - } -} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ProgramParserFormatter.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ProgramParserFormatter.java new file mode 100644 index 0000000..b0e3936 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/ProgramParserFormatter.java @@ -0,0 +1,46 @@ +package fr.ifremer.tutti.service.csv; + +import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.persistence.entities.data.Programs; +import fr.ifremer.tutti.service.PersistenceService; + +import java.util.List; + +/** + * Created on 2/15/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14 + */ +public class ProgramParserFormatter extends EntityParserFormatterSupport<Program> { + + public static ProgramParserFormatter newFormatter() { + return new ProgramParserFormatter(false, null); + } + + public static ProgramParserFormatter newTechnicalFormatter() { + return new ProgramParserFormatter(true, null); + } + + public static ProgramParserFormatter newParser(PersistenceService persistenceService) { + return new ProgramParserFormatter(true, persistenceService); + } + + private final PersistenceService persistenceService; + + protected ProgramParserFormatter(boolean technical, PersistenceService persistenceService) { + super("", technical, Program.class); + this.persistenceService = persistenceService; + } + + @Override + protected List<Program> getEntities() { + return persistenceService.getAllProgram(); + } + + @Override + protected String formatBusiness(Program value) { + return Programs.GET_NAME.apply(value); + } + +} \ No newline at end of file diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java index 9956e30..8f10b44 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java @@ -163,12 +163,18 @@ public class TuttiCsvUtil extends Common { public static ValueFormatter<Serializable> CARACTERISTIC_VALUE_TECHNICAL_FORMATTER = CaracteristicValueParserFormatter.newTechnicalFormatter(); - public static final ValueFormatter<Program> PROGRAM_FORMATTER = new ProgramFormatter(); + public static final ValueFormatter<Program> PROGRAM_FORMATTER = ProgramParserFormatter.newFormatter(); + + public static final ValueFormatter<Program> PROGRAM_TECHNICAL_FORMATTER = ProgramParserFormatter.newTechnicalFormatter(); public static final ValueFormatter<Gear> GEAR_FORMATTER = GearParserFormatter.newFormatter(); public static final ValueFormatter<Gear> GEAR_TECHNICAL_FORMATTER = GearParserFormatter.newTechnicalFormatter(); + public static final ValueFormatter<List<Gear>> GEAR_LIST_FORMATTER = GearListParserFormatter.newFormatter(GearParserFormatter.newFormatter()); + + public static final ValueFormatter<List<Gear>> GEAR_LIST_TECHNICAL_FORMATTER = GearListParserFormatter.newFormatter(GearParserFormatter.newTechnicalFormatter()); + public static final ValueFormatter<TuttiLocation> COUNTRY_FORMATTER = new CountryFormatter(); public static final ValueFormatter<TuttiLocation> PROGRAM_ZONE_FORMATTER = new ProgramZoneFormatter(); @@ -197,18 +203,18 @@ public class TuttiCsvUtil extends Common { public static final ValueFormatter<Species> SPECIES_TECHNICAL_FORMATTER = SpeciesParserFormatter.newTechnicalFormatter(); - public static final ValueFormatter<List<Person>> LIST_PERSON_FORMATTER = PersonListParserFormatter.newFormatter(PersonParserFormatter.newFormatter()); + public static final ValueFormatter<List<Person>> PERSON_LIST_FORMATTER = PersonListParserFormatter.newFormatter(PersonParserFormatter.newFormatter()); - public static final ValueFormatter<List<Person>> LIST_PERSON_TECHNICAL_FORMATTER = PersonListParserFormatter.newFormatter(PersonParserFormatter.newTechnicalFormatter()); + public static final ValueFormatter<List<Person>> PERSON_LIST_TECHNICAL_FORMATTER = PersonListParserFormatter.newFormatter(PersonParserFormatter.newTechnicalFormatter()); - public static final ValueFormatter<List<Vessel>> LIST_VESSEL_FORMATTER = VesselListParserFormatter.newFormatter(VesselParserFormatter.newFormatter()); + public static final ValueFormatter<List<Vessel>> VESSEL_LIST_FORMATTER = VesselListParserFormatter.newFormatter(VesselParserFormatter.newFormatter()); - public static final ValueFormatter<List<Vessel>> LIST_VESSEL_TECHNICAL_FORMATTER = VesselListParserFormatter.newFormatter(VesselParserFormatter.newTechnicalFormatter()); + public static final ValueFormatter<List<Vessel>> VESSEL_LIST_TECHNICAL_FORMATTER = VesselListParserFormatter.newFormatter(VesselParserFormatter.newTechnicalFormatter()); - public static final ValueParserFormatter<List<Integer>> LIST_INTEGER_PARSER_FORMATTER = new ListIntegerFormatter(); + public static final ValueParserFormatter<List<Integer>> INTEGER_LIST_PARSER_FORMATTER = new IntegerListParserFormatter(); public static <E extends Enum<E>> ValueParserFormatter<E> newEnumByNameParserFormatter(Class<E> enumType, boolean mandatory) { - return new fr.ifremer.tutti.service.csv.EnumByNameParserFormatter<E>(enumType, mandatory); + return new fr.ifremer.tutti.service.csv.EnumByNameParserFormatter<>(enumType, mandatory); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportEntityParserFactory.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportEntityParserFactory.java index ebe644d..7c24386 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportEntityParserFactory.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportEntityParserFactory.java @@ -1,20 +1,25 @@ package fr.ifremer.tutti.service.genericformat; import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.csv.CaracteristicParserFormatter; import fr.ifremer.tutti.service.csv.CaracteristicValueParserFormatter; import fr.ifremer.tutti.service.csv.FishingOperationLocationParserFormatter; import fr.ifremer.tutti.service.csv.FishingOperationStrataParserFormatter; import fr.ifremer.tutti.service.csv.FishingOperationSubStrataParserFormatter; +import fr.ifremer.tutti.service.csv.GearListParserFormatter; import fr.ifremer.tutti.service.csv.GearParserFormatter; import fr.ifremer.tutti.service.csv.HarbourParserFormatter; import fr.ifremer.tutti.service.csv.PersonListParserFormatter; import fr.ifremer.tutti.service.csv.PersonParserFormatter; +import fr.ifremer.tutti.service.csv.ProgramParserFormatter; import fr.ifremer.tutti.service.csv.SpeciesParserFormatter; import fr.ifremer.tutti.service.csv.VesselListParserFormatter; import fr.ifremer.tutti.service.csv.VesselParserFormatter; +import java.util.List; + /** * Created on 2/15/15. * @@ -29,23 +34,29 @@ public class GenericFormatImportEntityParserFactory { private final GenericFormatImportResult importResult; + private ProgramParserFormatter programParser; + private VesselParserFormatter vesselParser; private HarbourParserFormatter harbourParser; private GearParserFormatter gearParser; - private PersonListParserFormatter listPersonParser; + private GearListParserFormatter gearListParser; + + private PersonListParserFormatter personListParser; private CaracteristicParserFormatter caracteristicParser; + private CaracteristicParserFormatter caracteristicForSampleCategoryParser; + private FishingOperationStrataParserFormatter fishingOperationStrataParser; private FishingOperationSubStrataParserFormatter fishingOperationSubStrataParser; private FishingOperationLocationParserFormatter fishingOperationLocationParser; - private VesselListParserFormatter listVesselParser; + private VesselListParserFormatter vesselListParser; private SpeciesParserFormatter speciesParser; @@ -82,21 +93,46 @@ public class GenericFormatImportEntityParserFactory { return gearParser; } - public PersonListParserFormatter getListPersonParser() { - if (listPersonParser == null) { + public GearListParserFormatter getGearListParser() { + if (gearListParser == null) { + GearParserFormatter delegateParserFormatter = getGearParser(); + gearListParser = GearListParserFormatter.newParser(delegateParserFormatter); + } + return gearListParser; + } + + public PersonListParserFormatter getPersonListParser() { + if (personListParser == null) { PersonParserFormatter delegateParserFormatter = PersonParserFormatter.newParser(persistenceService, importResult.getImportedPersons().getIdTranslationMap()); - listPersonParser = PersonListParserFormatter.newParser(delegateParserFormatter); + personListParser = PersonListParserFormatter.newParser(delegateParserFormatter); } - return listPersonParser; + return personListParser; + } + + public ProgramParserFormatter getProgramParser() { + if (programParser == null) { + programParser = ProgramParserFormatter.newParser(persistenceService); + } + return programParser; } public CaracteristicParserFormatter getCaracteristicParser() { if (caracteristicParser == null) { - caracteristicParser = CaracteristicParserFormatter.newParser(persistenceService); + List<Caracteristic> caracteristics = persistenceService.getAllCaracteristic(); + caracteristicParser = CaracteristicParserFormatter.newParser(caracteristics); } return caracteristicParser; } + public CaracteristicParserFormatter getCaracteristicForSampleCategoryParser() { + if (caracteristicForSampleCategoryParser == null) { + List<Caracteristic> caracteristics = persistenceService.getAllCaracteristicForSampleCategory(); + caracteristicForSampleCategoryParser = CaracteristicParserFormatter.newParser(caracteristics); + + } + return caracteristicForSampleCategoryParser; + } + public FishingOperationStrataParserFormatter getFishingOperationStrataParser() { if (fishingOperationStrataParser == null) { Program program = importRequest.getProgram(); @@ -121,11 +157,11 @@ public class GenericFormatImportEntityParserFactory { return fishingOperationLocationParser; } - public VesselListParserFormatter getListVesselParser() { - if (listVesselParser == null) { - listVesselParser = VesselListParserFormatter.newParser(getVesselParser()); + public VesselListParserFormatter getVesselListParser() { + if (vesselListParser == null) { + vesselListParser = VesselListParserFormatter.newParser(getVesselParser()); } - return listVesselParser; + return vesselListParser; } public SpeciesParserFormatter getSpeciesParser() { 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 d9be17f..e641ea3 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 @@ -98,6 +98,7 @@ public class GenericFormatImportService extends AbstractTuttiService { super.setServiceContext(context); persistenceService = getService(PersistenceService.class); decoratorService = getService(DecoratorService.class); + validationService = getService(ValidationService.class); weightComputingService = getService(WeightComputingService.class); referentialTemporaryGearService = getService(ReferentialTemporaryGearService.class); referentialTemporaryPersonService = getService(ReferentialTemporaryPersonService.class); @@ -126,13 +127,6 @@ public class GenericFormatImportService extends AbstractTuttiService { } } - public void checkArchive(File importFile) { - - GenericFormatArchive archive = GenericFormatArchive.forImport(importFile, context.getConfig().getTmpDirectory()); - archive.checkArchiveLayout(); - - } - public GenericFormatImportResult importProgram(String programId, File importFile, ProgressionModel progressionModel) { Preconditions.checkNotNull(programId); @@ -146,7 +140,6 @@ public class GenericFormatImportService extends AbstractTuttiService { } GenericFormatArchive archive = GenericFormatArchive.forImport(importFile, context.getConfig().getTmpDirectory()); - archive.checkArchiveLayout(); GenericFormatImportRequest request = new GenericFormatImportRequest(persistenceService, archive, @@ -184,6 +177,10 @@ public class GenericFormatImportService extends AbstractTuttiService { protected void checkSampleCategoryModel(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import sample category model."); + } + progressionModel.increments(t("tutti.genericFormat.import.sampleCategoryModel")); try (CsvConsumerForSampleCategory consumer = importContext.loadSampleCategories()) { @@ -211,6 +208,10 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatArchive archive = importContext.getImportRequest().getArchive(); if (archive.isTemporaryReferentialGearsPathExists()) { + if (log.isInfoEnabled()) { + log.info("Import temporary gears."); + } + ReferentialImportRequest<Gear, Integer> referentialImportRequest = referentialTemporaryGearService.createReferentialImportRequest(); try (CsvConsumerForTemporaryGear consumer = importContext.loadTemporaryGears()) { @@ -226,6 +227,12 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatReferentialImportResult<Gear, Integer> genericFormatReferentialImportResult = new GenericFormatReferentialImportResult<>(referentialImportRequest, referentialImportResult); importContext.getImportResult().setImportedGears(genericFormatReferentialImportResult); + } else { + + if (log.isInfoEnabled()) { + log.info("Skip import temporary gears (no file found)."); + } + } } @@ -236,6 +243,10 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatArchive archive = importContext.getImportRequest().getArchive(); if (archive.isTemporaryReferentialPersonsPathExists()) { + if (log.isInfoEnabled()) { + log.info("Import temporary persons."); + } + ReferentialImportRequest<Person, Integer> referentialImportRequest = referentialTemporaryPersonService.createReferentialImportRequest(); try (CsvConsumerForTemporaryPerson consumer = importContext.loadTemporaryPersons()) { @@ -251,6 +262,12 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatReferentialImportResult<Person, Integer> genericFormatReferentialImportResult = new GenericFormatReferentialImportResult<>(referentialImportRequest, referentialImportResult); importContext.getImportResult().setImportedPersons(genericFormatReferentialImportResult); + } else { + + if (log.isInfoEnabled()) { + log.info("Skip import temporary persons (no file found)."); + } + } } @@ -261,6 +278,10 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatArchive archive = importContext.getImportRequest().getArchive(); if (archive.isTemporaryReferentialSpeciesPathExists()) { + if (log.isInfoEnabled()) { + log.info("Import temporary species."); + } + ReferentialImportRequest<Species, Integer> referentialImportRequest = referentialTemporarySpeciesService.createReferentialImportRequest(); try (CsvConsumerForTemporarySpecies consumer = importContext.loadTemporarySpecies()) { @@ -276,6 +297,12 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatReferentialImportResult<Species, Integer> genericFormatReferentialImportResult = new GenericFormatReferentialImportResult<>(referentialImportRequest, referentialImportResult); importContext.getImportResult().setImportedSpecies(genericFormatReferentialImportResult); + } else { + + if (log.isInfoEnabled()) { + log.info("Skip import temporary species (no file found)."); + } + } } @@ -286,6 +313,10 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatArchive archive = importContext.getImportRequest().getArchive(); if (archive.isTemporaryReferentialVesselsPathExists()) { + if (log.isInfoEnabled()) { + log.info("Import temporary vessels."); + } + ReferentialImportRequest<Vessel, String> referentialImportRequest = referentialTemporaryVesselService.createReferentialImportRequest(); try (CsvConsumerForTemporaryVessel consumer = importContext.loadTemporaryVessels()) { @@ -301,6 +332,12 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatReferentialImportResult<Vessel, String> genericFormatReferentialImportResult = new GenericFormatReferentialImportResult<>(referentialImportRequest, referentialImportResult); importContext.getImportResult().setImportedVessels(genericFormatReferentialImportResult); + } else { + + if (log.isInfoEnabled()) { + log.info("Skip import temporary vessels (no file found)."); + } + } } @@ -311,6 +348,10 @@ public class GenericFormatImportService extends AbstractTuttiService { GenericFormatArchive archive = importContext.getImportRequest().getArchive(); if (archive.isProtocolExists()) { + if (log.isInfoEnabled()) { + log.info("Import protocol."); + } + TuttiProtocol tuttiProtocol = protocolImportExportService.importProtocol(archive.getProtocolPath().toFile()); Map<String, String> idTranslationMap = importContext.getImportResult().getImportedSpecies().getIdTranslationMap(); @@ -326,11 +367,20 @@ public class GenericFormatImportService extends AbstractTuttiService { importContext.getImportResult().setProtocol(tuttiProtocol); + } else { + + if (log.isInfoEnabled()) { + log.info("Skip import protocol (no file found)."); + } + } } protected void importCruises(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import survey.csv file."); + } progressionModel.increments(t("tutti.genericFormat.import.cruises")); try (CsvConsumerForSurvey consumer = importContext.loadSurveys()) { @@ -338,6 +388,10 @@ public class GenericFormatImportService extends AbstractTuttiService { consumer.checkRow(row, importContext, validationService); + if (log.isInfoEnabled()) { + log.info("Will persist cruise: " + row.getBean().getName()); + } + } } catch (IOException e) { throw new ApplicationTechnicalException("Could not close survey.csv file", e); @@ -347,7 +401,11 @@ public class GenericFormatImportService extends AbstractTuttiService { protected void importGearCaracteristics(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import gearCaracteristics.csv file."); + } progressionModel.increments(t("tutti.genericFormat.import.gearCaracteristics")); + try (CsvConsumerForGearCaracteristic consumer = importContext.loadGearCaracteristics()) { for (ImportRow<GearCaracteristicRow> row : consumer) { @@ -362,7 +420,11 @@ public class GenericFormatImportService extends AbstractTuttiService { protected void importOperations(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import operation.csv file."); + } progressionModel.increments(t("tutti.genericFormat.import.operations")); + try (CsvConsumerForOperation consumer = importContext.loadOperations()) { for (ImportRow<OperationRow> row : consumer) { @@ -377,7 +439,11 @@ public class GenericFormatImportService extends AbstractTuttiService { protected void importParameters(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import parameter.csv file."); + } progressionModel.increments(t("tutti.genericFormat.import.parameters")); + try (CsvConsumerForParameter consumer = importContext.loadParameters()) { for (ImportRow<ParameterRow> row : consumer) { @@ -392,7 +458,11 @@ public class GenericFormatImportService extends AbstractTuttiService { protected void importCatches(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import catch.csv file."); + } progressionModel.increments(t("tutti.genericFormat.import.catches")); + try (CsvConsumerForCatch consumer = importContext.loadCatches()) { for (ImportRow<CatchRow> row : consumer) { @@ -407,7 +477,11 @@ public class GenericFormatImportService extends AbstractTuttiService { protected void importAccidentalCatches(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import accidentalCatch.csv file."); + } progressionModel.increments(t("tutti.genericFormat.import.accidentalCatches")); + try (CsvConsumerForAccidentalCatch consumer = importContext.loadAccidentalCatches()) { for (ImportRow<AccidentalCatchRow> row : consumer) { @@ -422,7 +496,11 @@ public class GenericFormatImportService extends AbstractTuttiService { protected void importIndividualObservations(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import individualObservation.csv file."); + } progressionModel.increments(t("tutti.genericFormat.import.individualObservations")); + try (CsvConsumerForIndividualObservation consumer = importContext.loadIndividualObservations()) { for (ImportRow<IndividualObservationRow> row : consumer) { @@ -437,7 +515,11 @@ public class GenericFormatImportService extends AbstractTuttiService { protected void importMarineLitters(GenericFormatImportContext importContext, ProgressionModel progressionModel) { + if (log.isInfoEnabled()) { + log.info("Import marineLitter.csv file."); + } progressionModel.increments(t("tutti.genericFormat.import.marineLitters")); + try (CsvConsumerForMarineLitter consumer = importContext.loadMarineLitters()) { for (ImportRow<MarineLitterRow> row : consumer) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForSampleCategory.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForSampleCategory.java index 7956793..76e8ce5 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForSampleCategory.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForSampleCategory.java @@ -31,7 +31,7 @@ public class CsvConsumerForSampleCategory extends CsvComsumer<SampleCategoryRow, if (row.isValid()) { - int categoryIndex = (int) row.getLineNumber(); + int categoryIndex = (int) row.getLineNumber() -1; fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel sampleCategoryModel = importContext.getImportRequest().getSampleCategoryModel(); int nbSampling = sampleCategoryModel.getNbSampling(); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationModel.java index 9c954a9..499ef42 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationModel.java @@ -99,8 +99,8 @@ public class OperationModel extends AbstractTuttiImportExportModel<OperationRow> newColumnForExport("Validite_OP", FishingOperation.PROPERTY_FISHING_OPERATION_VALID, TuttiCsvUtil.BOOLEAN); newColumnForExport("Rectiligne", FishingOperation.PROPERTY_FISHING_OPERATION_RECTILIGNE, TuttiCsvUtil.BOOLEAN); newColumnForExport("Distance", FishingOperation.PROPERTY_TRAWL_DISTANCE, TuttiCsvUtil.INTEGER_NULL_TO_9); - newColumnForExport("Saisisseur", FishingOperation.PROPERTY_RECORDER_PERSON, TuttiCsvUtil.LIST_PERSON_FORMATTER); - newColumnForExport("Navire_Associe", FishingOperation.PROPERTY_SECONDARY_VESSEL, TuttiCsvUtil.LIST_VESSEL_FORMATTER); + newColumnForExport("Saisisseur", FishingOperation.PROPERTY_RECORDER_PERSON, TuttiCsvUtil.PERSON_LIST_FORMATTER); + newColumnForExport("Navire_Associe", FishingOperation.PROPERTY_SECONDARY_VESSEL, TuttiCsvUtil.VESSEL_LIST_FORMATTER); newColumnForExport("Commentaire", FishingOperation.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); newNullableColumnForExport("Poids_Total", OperationRow.PROPERTY_CATCH_TOTAL_WEIGHT, TuttiCsvUtil.WEIGHT_NULL_TO_9); @@ -164,8 +164,8 @@ public class OperationModel extends AbstractTuttiImportExportModel<OperationRow> newColumnForExport("Strate_Id", FishingOperation.PROPERTY_STRATA, TuttiCsvUtil.FISHING_OPERATION_STRATA_TECHNICAL_FORMATTER); newColumnForExport("Sous_Strate_Id", FishingOperation.PROPERTY_SUB_STRATA, TuttiCsvUtil.FISHING_OPERATION_SUB_STRATA_TECHNICAL_FORMATTER); newColumnForExport("Localite_Id", FishingOperation.PROPERTY_LOCATION, TuttiCsvUtil.FISHING_OPERATION_LOCATION_TECHNICAL_FORMATTER); - newColumnForExport("Saisisseur_Id", FishingOperation.PROPERTY_RECORDER_PERSON, TuttiCsvUtil.LIST_PERSON_TECHNICAL_FORMATTER); - newColumnForExport("Navire_Associe_Id", FishingOperation.PROPERTY_SECONDARY_VESSEL, TuttiCsvUtil.LIST_VESSEL_TECHNICAL_FORMATTER); + newColumnForExport("Saisisseur_Id", FishingOperation.PROPERTY_RECORDER_PERSON, TuttiCsvUtil.PERSON_LIST_TECHNICAL_FORMATTER); + newColumnForExport("Navire_Associe_Id", FishingOperation.PROPERTY_SECONDARY_VESSEL, TuttiCsvUtil.VESSEL_LIST_TECHNICAL_FORMATTER); } @@ -260,8 +260,8 @@ public class OperationModel extends AbstractTuttiImportExportModel<OperationRow> newMandatoryColumn("Strate_Id", FishingOperation.PROPERTY_STRATA, parserFactory.getFishingOperationStrataParser()); newMandatoryColumn("Sous_Strate_Id", FishingOperation.PROPERTY_SUB_STRATA, parserFactory.getFishingOperationSubStrataParser()); newMandatoryColumn("Localite_Id", FishingOperation.PROPERTY_LOCATION, parserFactory.getFishingOperationLocationParser()); - newMandatoryColumn("Saisisseur_Id", FishingOperation.PROPERTY_RECORDER_PERSON, parserFactory.getListPersonParser()); - newMandatoryColumn("Navire_Associe_Id", FishingOperation.PROPERTY_SECONDARY_VESSEL, parserFactory.getListVesselParser()); + newMandatoryColumn("Saisisseur_Id", FishingOperation.PROPERTY_RECORDER_PERSON, parserFactory.getPersonListParser()); + newMandatoryColumn("Navire_Associe_Id", FishingOperation.PROPERTY_SECONDARY_VESSEL, parserFactory.getVesselListParser()); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SampleCategoryModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SampleCategoryModel.java index c86ac2f..72df2ed 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SampleCategoryModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SampleCategoryModel.java @@ -54,7 +54,7 @@ public class SampleCategoryModel extends AbstractTuttiImportExportModel<SampleCa newMandatoryColumn(SampleCategoryRow.PROPERTY_CODE); newMandatoryColumn(SampleCategoryRow.PROPERTY_ORDER, TuttiCsvUtil.INTEGER); - newMandatoryColumn(SampleCategoryRow.PROPERTY_CARACTERISTIC, parserFactory.getCaracteristicParser()); + newMandatoryColumn(SampleCategoryRow.PROPERTY_CARACTERISTIC, parserFactory.getCaracteristicForSampleCategoryParser()); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SampleCategoryRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SampleCategoryRow.java index e09bb42..5b9e2ca 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SampleCategoryRow.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SampleCategoryRow.java @@ -45,6 +45,9 @@ public class SampleCategoryRow implements Serializable { public void setCaracteristic(Caracteristic caracteristic) { sampleCategoryModelEntry.setCaracteristic(caracteristic); + if (caracteristic!=null) { + sampleCategoryModelEntry.setCategoryId(caracteristic.getIdAsInt()); + } } public void setCode(String code) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyModel.java index b33b316..e700cc2 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyModel.java @@ -73,6 +73,7 @@ public class SurveyModel extends AbstractTuttiImportExportModel<SurveyRow> { newColumnForExport("Serie", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_FORMATTER); newColumnForExport("Serie_Partielle", Cruise.PROPERTY_SURVEY_PART); newColumnForExport("Navire", Cruise.PROPERTY_VESSEL, TuttiCsvUtil.VESSEL_FORMATTER); + newColumnForExport("Nombre_Poches", Cruise.PROPERTY_MULTIRIG_NUMBER, TuttiCsvUtil.PRIMITIVE_INTEGER); newColumnForExport("Pays", SurveyRow.PROPERTY_COUNTRY, TuttiCsvUtil.COUNTRY_FORMATTER); newColumnForExport("Zone_Etude", Program.PROPERTY_ZONE, TuttiCsvUtil.PROGRAM_ZONE_FORMATTER); newColumnForExport("Campagne", Cruise.PROPERTY_NAME); @@ -81,15 +82,17 @@ public class SurveyModel extends AbstractTuttiImportExportModel<SurveyRow> { newColumnForExport("Port_Deb_Campagne", Cruise.PROPERTY_DEPARTURE_LOCATION, TuttiCsvUtil.HARBOUR_FORMATTER); newColumnForExport("Date_Fin_Campagne", Cruise.PROPERTY_END_DATE, TuttiCsvUtil.DAY_TIME_SECOND); newColumnForExport("Port_Fin_Campagne", Cruise.PROPERTY_RETURN_LOCATION, TuttiCsvUtil.HARBOUR_FORMATTER); - newColumnForExport("Chef_Mission", Cruise.PROPERTY_HEAD_OF_MISSION, TuttiCsvUtil.LIST_PERSON_FORMATTER); - newColumnForExport("Resp_Salle_Tri", Cruise.PROPERTY_HEAD_OF_SORT_ROOM, TuttiCsvUtil.LIST_PERSON_FORMATTER); + newColumnForExport("Chef_Mission", Cruise.PROPERTY_HEAD_OF_MISSION, TuttiCsvUtil.PERSON_LIST_FORMATTER); + newColumnForExport("Resp_Salle_Tri", Cruise.PROPERTY_HEAD_OF_SORT_ROOM, TuttiCsvUtil.PERSON_LIST_FORMATTER); newColumnForExport("Commentaire", Cruise.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); + newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER); newColumnForExport("Navire_Id", Cruise.PROPERTY_VESSEL, TuttiCsvUtil.VESSEL_TECHNICAL_FORMATTER); + newColumnForExport("Engin_Id", Cruise.PROPERTY_GEAR, TuttiCsvUtil.GEAR_LIST_TECHNICAL_FORMATTER); newColumnForExport("Port_Deb_Campagne_Id", Cruise.PROPERTY_DEPARTURE_LOCATION, TuttiCsvUtil.HARBOUR_TECHNICAL_FORMATTER); newColumnForExport("Port_Fin_Campagne_Id", Cruise.PROPERTY_RETURN_LOCATION, TuttiCsvUtil.HARBOUR_TECHNICAL_FORMATTER); - newColumnForExport("Chef_Mission_Id", Cruise.PROPERTY_HEAD_OF_MISSION, TuttiCsvUtil.LIST_PERSON_TECHNICAL_FORMATTER); - newColumnForExport("Resp_Salle_Tri_Id", Cruise.PROPERTY_HEAD_OF_SORT_ROOM, TuttiCsvUtil.LIST_PERSON_TECHNICAL_FORMATTER); + newColumnForExport("Chef_Mission_Id", Cruise.PROPERTY_HEAD_OF_MISSION, TuttiCsvUtil.PERSON_LIST_TECHNICAL_FORMATTER); + newColumnForExport("Resp_Salle_Tri_Id", Cruise.PROPERTY_HEAD_OF_SORT_ROOM, TuttiCsvUtil.PERSON_LIST_TECHNICAL_FORMATTER); } @@ -99,8 +102,11 @@ public class SurveyModel extends AbstractTuttiImportExportModel<SurveyRow> { newIgnoredColumn("Serie"); newMandatoryColumn("Serie_Partielle", Cruise.PROPERTY_SURVEY_PART); newIgnoredColumn("Navire"); + newMandatoryColumn("Nombre_Poches", Cruise.PROPERTY_MULTIRIG_NUMBER, TuttiCsvUtil.PRIMITIVE_INTEGER); + newIgnoredColumn("Pays"); + newIgnoredColumn("Zone_Etude"); newMandatoryColumn("Campagne", Cruise.PROPERTY_NAME); - newMandatoryColumn("Id_Sismer", SurveyRow.PROPERTY_ID_SISMER); + newIgnoredColumn("Id_Sismer"); newMandatoryColumn("Date_Deb_Campagne", Cruise.PROPERTY_BEGIN_DATE, TuttiCsvUtil.DAY_TIME_SECOND); newIgnoredColumn("Port_Deb_Campagne"); newMandatoryColumn("Date_Fin_Campagne", Cruise.PROPERTY_END_DATE, TuttiCsvUtil.DAY_TIME_SECOND); @@ -109,11 +115,13 @@ public class SurveyModel extends AbstractTuttiImportExportModel<SurveyRow> { newIgnoredColumn("Resp_Salle_Tri"); newMandatoryColumn("Commentaire", Cruise.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); + newMandatoryColumn("Serie_Id", Cruise.PROPERTY_PROGRAM, parserFactory.getProgramParser()); newMandatoryColumn("Navire_Id", Cruise.PROPERTY_VESSEL, parserFactory.getVesselParser()); + newMandatoryColumn("Engin_Id", Cruise.PROPERTY_GEAR, parserFactory.getGearListParser()); newMandatoryColumn("Port_Deb_Campagne_Id", Cruise.PROPERTY_DEPARTURE_LOCATION, parserFactory.getHarbourParser()); newMandatoryColumn("Port_Fin_Campagne_Id", Cruise.PROPERTY_RETURN_LOCATION, parserFactory.getHarbourParser()); - newMandatoryColumn("Chef_Mission_Id", Cruise.PROPERTY_HEAD_OF_MISSION, parserFactory.getListPersonParser()); - newMandatoryColumn("Resp_Salle_Tri_Id", Cruise.PROPERTY_HEAD_OF_SORT_ROOM, parserFactory.getListPersonParser()); + newMandatoryColumn("Chef_Mission_Id", Cruise.PROPERTY_HEAD_OF_MISSION, parserFactory.getPersonListParser()); + newMandatoryColumn("Resp_Salle_Tri_Id", Cruise.PROPERTY_HEAD_OF_SORT_ROOM, parserFactory.getPersonListParser()); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/SpeciesRowModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/SpeciesRowModel.java index 8fc5fdb..47c3638 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/SpeciesRowModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/protocol/SpeciesRowModel.java @@ -91,7 +91,7 @@ public class SpeciesRowModel extends AbstractTuttiImportExportModel<SpeciesRow> //FIXME See if really needed, otherwise just use the default String parser // newMandatoryColumn(SpeciesRow.PROPERTY_SPECIES_SURVEY_CODE); newMandatoryColumn(SpeciesRow.PROPERTY_SPECIES_SURVEY_CODE, new StringParserFormatter(null, true)); - newMandatoryColumn(SpeciesRow.PROPERTY_MANDATORY_SAMPLE_CATEGORY_ID, TuttiCsvUtil.LIST_INTEGER_PARSER_FORMATTER); + newMandatoryColumn(SpeciesRow.PROPERTY_MANDATORY_SAMPLE_CATEGORY_ID, TuttiCsvUtil.INTEGER_LIST_PARSER_FORMATTER); newMandatoryColumn(SpeciesRow.PROPERTY_WEIGHT_ENABLED, Common.PRIMITIVE_BOOLEAN); newMandatoryColumn(SpeciesRow.PROPERTY_COUNT_IF_NO_FREQUENCY_ENABLED, Common.PRIMITIVE_BOOLEAN); newMandatoryColumn(SpeciesRow.PROPERTY_CALCIFY_SAMPLE_ENABLED, Common.PRIMITIVE_BOOLEAN); @@ -107,7 +107,7 @@ public class SpeciesRowModel extends AbstractTuttiImportExportModel<SpeciesRow> newColumnForExport(SpeciesRow.PROPERTY_LENGTH_STEP_PMFM_MATRIX_NAME); newColumnForExport(SpeciesRow.PROPERTY_LENGTH_STEP_PMFM_FRACTION_NAME); newColumnForExport(SpeciesRow.PROPERTY_LENGTH_STEP_PMFM_METHOD_NAME); - newColumnForExport(SpeciesRow.PROPERTY_MANDATORY_SAMPLE_CATEGORY_ID, TuttiCsvUtil.LIST_INTEGER_PARSER_FORMATTER); + newColumnForExport(SpeciesRow.PROPERTY_MANDATORY_SAMPLE_CATEGORY_ID, TuttiCsvUtil.INTEGER_LIST_PARSER_FORMATTER); newColumnForExport(SpeciesRow.PROPERTY_WEIGHT_ENABLED, Common.PRIMITIVE_BOOLEAN); newColumnForExport(SpeciesRow.PROPERTY_COUNT_IF_NO_FREQUENCY_ENABLED, Common.PRIMITIVE_BOOLEAN); newColumnForExport(SpeciesRow.PROPERTY_CALCIFY_SAMPLE_ENABLED, Common.PRIMITIVE_BOOLEAN); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/consumer/CsvConsumerForTemporarySpecies.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/consumer/CsvConsumerForTemporarySpecies.java index 60fa0b1..86357d4 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/consumer/CsvConsumerForTemporarySpecies.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/consumer/CsvConsumerForTemporarySpecies.java @@ -110,14 +110,14 @@ public class CsvConsumerForTemporarySpecies extends CsvComsumer<SpeciesRow, Spec if (toAdd) { if (log.isInfoEnabled()) { - log.info("Will add gear with name: " + name); + log.info("Will add species with name: " + name); } requestResult.addEntityToAdd(entity); } else { if (log.isInfoEnabled()) { - log.info("Will link gear with name: " + name); + log.info("Will link species with name: " + name); } requestResult.addEntityToLink(entity); diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportServiceTest.java new file mode 100644 index 0000000..7b8354d --- /dev/null +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportServiceTest.java @@ -0,0 +1,80 @@ +package fr.ifremer.tutti.service.genericformat; + +import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.ServiceDbResource; +import fr.ifremer.tutti.service.TuttiServiceContext; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.nuiton.util.FileUtil; + +import java.io.File; + +/** + * Created on 2/15/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14 + */ +public class GenericFormatImportServiceTest { + + @ClassRule + public static final ServiceDbResource dbResource = ServiceDbResource.writeDb("dbGenericFormatImport"); + + public static final String PROGRAM_ID = "CAM-CGFS"; + + protected GenericFormatImportService service; + + protected PersistenceService persistenceService; + + protected ServiceDbResource.DataContext dataContext; + + protected ProgressionModel progressionModel; + + @Before + public void setUp() throws Exception { + + TuttiServiceContext serviceContext = dbResource.getServiceContext(); + + persistenceService = serviceContext.getService(PersistenceService.class); + + dbResource.setCountryInConfig("12"); + dbResource.openDataContext(); + + service = serviceContext.getService(GenericFormatImportService.class); + + dataContext = dbResource.loadContext(PROGRAM_ID); + + progressionModel = new ProgressionModel(); + + } + + protected File createArchive(String directoryName, String archiveFileName) { + + File explodedDirectory = FileUtil.getFileFromPaths(new File("src"), "test", "resources", "genericFormat", directoryName); + + File dataDirectory = dbResource.getConfig().getDataDirectory(); + File archiveFile = new File(dataDirectory, archiveFileName); + + GenericFormatArchive archiveToExport = GenericFormatArchive.forExportFromWorkingDirectory(archiveFile, explodedDirectory); + + archiveToExport.createZip(null); + + return archiveFile; + + } + + @Test + public void loadEmptyImport() { + + File archiveFile = createArchive("empty", "empty.zip"); + + int nbSteps = service.getImportProgramNbSteps(archiveFile); + progressionModel.adaptTotal(nbSteps); + + service.importProgram(dataContext.program.getId(), archiveFile, progressionModel); + + + } +} diff --git a/tutti-service/src/test/resources/genericFormat/empty/accidentalCatch.csv b/tutti-service/src/test/resources/genericFormat/empty/accidentalCatch.csv new file mode 100644 index 0000000..1d7f9f1 --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/accidentalCatch.csv @@ -0,0 +1 @@ +Annee;Serie;Serie_Partielle;Code_Station;Id_Operation;Poche;Engin;Rang_Engin;Id_Lot;Code_Taxon;Nom_Scientifique;Commentaire;Code_PMFM;Libelle_PMFM;Valeur;Valeur_Id diff --git a/tutti-service/src/test/resources/genericFormat/empty/catch.csv b/tutti-service/src/test/resources/genericFormat/empty/catch.csv new file mode 100644 index 0000000..65d3a64 --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/catch.csv @@ -0,0 +1 @@ +Annee;Serie;Serie_Partielle;Code_Station;Id_Operation;Poche;Engin;Rang_Engin;Code_Taxon;Code_Espece_Campagne;Nom_Scientifique;Benthos;Commentaire;V_HV;Num_Ordre_V_HV_H2;Tot_V_HV;Ech_V_HV;Type_Volume_Poids_V_HV;Unite_Volume_Poids_V_HV;Class_Tri;Num_Ordre_Class_Tri_H2;Tot_Class_Tri;Ech_Class_Tri;Type_Volume_Poids_Class_Tri;Unite_Volume_Poids_Class_Tri;Sexe;Num_Ordre_Sexe_H2;Tot_Sexe;Ech_Sexe;Type_Volume_Poids_Sexe;Unite_Volume_Poids_Sexe;Maturite;Num_Ordre_Maturite_H2;Tot_Maturite;Ech_Matu [...] \ No newline at end of file diff --git a/tutti-service/src/test/resources/genericFormat/empty/gearCaracteristics.csv b/tutti-service/src/test/resources/genericFormat/empty/gearCaracteristics.csv new file mode 100644 index 0000000..3c40757 --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/gearCaracteristics.csv @@ -0,0 +1 @@ +Annee;Serie;Serie_Partielle;Engin;Rang_Engin;Code_PMFM;Libelle_PMFM;Valeur diff --git a/tutti-service/src/test/resources/genericFormat/empty/individualObservation.csv b/tutti-service/src/test/resources/genericFormat/empty/individualObservation.csv new file mode 100644 index 0000000..1d7f9f1 --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/individualObservation.csv @@ -0,0 +1 @@ +Annee;Serie;Serie_Partielle;Code_Station;Id_Operation;Poche;Engin;Rang_Engin;Id_Lot;Code_Taxon;Nom_Scientifique;Commentaire;Code_PMFM;Libelle_PMFM;Valeur;Valeur_Id diff --git a/tutti-service/src/test/resources/genericFormat/empty/marineLitter.csv b/tutti-service/src/test/resources/genericFormat/empty/marineLitter.csv new file mode 100644 index 0000000..e308bed --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/marineLitter.csv @@ -0,0 +1 @@ +Annee;Serie;Serie_Partielle;Code_Station;Id_Operation;Poche;Engin;Rang_Engin;Categorie;Categorie_Taille;Nombre;Poids;Commentaire;Categorie_Id;Categorie_Taille_Id \ No newline at end of file diff --git a/tutti-service/src/test/resources/genericFormat/empty/operation.csv b/tutti-service/src/test/resources/genericFormat/empty/operation.csv new file mode 100644 index 0000000..a50e33e --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/operation.csv @@ -0,0 +1 @@ +Annee;Serie;Serie_Partielle;Code_Station;Id_Operation;Poche;Engin;Rang_Engin;Navire;DateDeb;LatDeb;LongDeb;DateFin;LatFin;LongFin;Duree;Strate;Sous_Strate;Localite;Validite_OP;Rectiligne;Distance;Saisisseur;Navire_Associe;Commentaire;Poids_Total;Poids_Total_Calcule;Poids_Total_Vrac;Poids_Total_Vrac_Calcule;Poids_Total_HorsVrac;Poids_Total_HorsVrac_Calcule;Poids_Total_Non_Trie;Poids_Total_Non_Trie_Calcule;Poids_Total_Tremis;Poids_Total_Tremis_Calcule;Poids_Total_Carroussel;Poids_Total_Car [...] \ No newline at end of file diff --git a/tutti-service/src/test/resources/genericFormat/empty/parameter.csv b/tutti-service/src/test/resources/genericFormat/empty/parameter.csv new file mode 100644 index 0000000..0f9cf03 --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/parameter.csv @@ -0,0 +1 @@ +Annee;Serie;Serie_Partielle;Code_Station;Id_Operation;Poche;Code_PMFM;Libelle_PMFM;Valeur;Valeur_Id diff --git a/tutti-service/src/test/resources/genericFormat/empty/protocol.tuttiProtocol b/tutti-service/src/test/resources/genericFormat/empty/protocol.tuttiProtocol new file mode 100644 index 0000000..344c7dd --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/protocol.tuttiProtocol @@ -0,0 +1,81 @@ +id: 2b5f8ccd-1a91-4902-93db-c209f02b6e1a +name: Protocole EVHOE 2014 +benthos: +- !SpeciesProtocol + id: d315e520-dfb8-47e5-bad9-8bb9a7e13692 + countIfNoFrequencyEnabled: true + speciesReferenceTaxonId: -3 + speciesSurveyCode: MELANGE + weightEnabled: true +- !SpeciesProtocol + id: ea6c48e3-d7d9-4482-996c-637c9c34ccc0 + calcifySampleEnabled: true + countIfNoFrequencyEnabled: true + mandatorySampleCategoryId: + - 198 + - 196 + speciesReferenceTaxonId: 4001 + speciesSurveyCode: SAGASCH + weightEnabled: true +caracteristicMapping: +- !CaracteristicMappingRow + pmfmId: 828 + tab: GEAR_USE_FEATURE +comment: "Protocole en pr\u00e9paration pour EVHOE 2014" +lengthClassesPmfmId: +- 306 +- 622 +- 307 +- 302 +- 299 +- 1394 +- 1417 +- 1425 +- 1426 +- 1427 +- 284 +- 285 +- 294 +- 295 +- 300 +- 301 +- 304 +- 318 +- 319 +- 322 +- 323 +- 661 +- 662 +species: +- !SpeciesProtocol + id: 609eb1b2-7d9f-4277-91fb-0b18cf5a81f9 + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + speciesReferenceTaxonId: -4 + speciesSurveyCode: DIVE-RS1 + weightEnabled: true +- !SpeciesProtocol + id: f5f7c134-55dd-4c4c-a635-ae8d8fc2ff75 + countIfNoFrequencyEnabled: true + speciesReferenceTaxonId: -5 + speciesSurveyCode: DIVE-RS1 + weightEnabled: true +- !SpeciesProtocol + id: d7006c1f-8cca-4c0e-92ae-492e40941c44 + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: + - 196 + speciesReferenceTaxonId: 1055 + speciesSurveyCode: CANC-BEL + weightEnabled: true +- !SpeciesProtocol + id: 06957d3a-7677-47bd-b953-454f752b5ec6 + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: + - 198 + speciesReferenceTaxonId: 1663 + speciesSurveyCode: TRAC-MED + weightEnabled: true +version: 3 diff --git a/tutti-service/src/test/resources/genericFormat/empty/sampleCategory.csv b/tutti-service/src/test/resources/genericFormat/empty/sampleCategory.csv new file mode 100644 index 0000000..2f2b57f --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/sampleCategory.csv @@ -0,0 +1,6 @@ +code;order;caracteristic +V_HV;0;1428 +Class_Tri;1;198 +Sexe;2;196 +Maturite;3;174 +Age;4;1430 diff --git a/tutti-service/src/test/resources/genericFormat/empty/survey.csv b/tutti-service/src/test/resources/genericFormat/empty/survey.csv new file mode 100644 index 0000000..a54b3c7 --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/survey.csv @@ -0,0 +1,2 @@ +Annee;Serie;Serie_Partielle;Navire;Nombre_Poches;Pays;Zone_Etude;Campagne;Id_Sismer;Date_Deb_Campagne;Port_Deb_Campagne;Date_Fin_Campagne;Port_Fin_Campagne;Chef_Mission;Resp_Salle_Tri;Commentaire;Serie_Id;Navire_Id;Engin_Id;Port_Deb_Campagne_Id;Port_Fin_Campagne_Id;Chef_Mission_Id;Resp_Salle_Tri_Id +2014;Campagne EVHOE;1;868095;1;FRA;EVHOE - Golfe de Gascogne / Mer Celtique;Campagne EVHOE 2014;;17/10/2014 07:00:00;Brest;01/12/2014 07:00:00;Brest;Jean-Pierre LEAUTE|Michele SALAUN|Lionel PAWLOWSKI;Erwan DUHAMEL|Nicolas CAROFF;;CAM-CGFS;868095;1|2;530;530;143|70|2332;128|59 diff --git a/tutti-service/src/test/resources/genericFormat/empty/temporaryPersons.csv b/tutti-service/src/test/resources/genericFormat/empty/temporaryPersons.csv new file mode 100644 index 0000000..372a462 --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/temporaryPersons.csv @@ -0,0 +1,4 @@ +id;firstName;lastName;toDelete +-1;Léo;Paul; +-2;Paul;Valery; +-3;Valery;François; \ No newline at end of file diff --git a/tutti-service/src/test/resources/genericFormat/empty/temporarySpecies.csv b/tutti-service/src/test/resources/genericFormat/empty/temporarySpecies.csv new file mode 100644 index 0000000..16277a6 --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/temporarySpecies.csv @@ -0,0 +1,9 @@ +id;name;toDelete +-6;Benthos; +-4;Divers 1; +-5;Divers 2; +-1;Divers 3; +-2;Divers 4; +-7;Gelatineux; +-8;MBECTOP; +-3;Melange; \ No newline at end of file diff --git a/tutti-service/src/test/resources/genericFormat/empty/temporaryVessels.csv b/tutti-service/src/test/resources/genericFormat/empty/temporaryVessels.csv new file mode 100644 index 0000000..850442a --- /dev/null +++ b/tutti-service/src/test/resources/genericFormat/empty/temporaryVessels.csv @@ -0,0 +1 @@ +id;name;internationalRegistrationCode;scientificVessel;toDelete diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportGenericFormatProgramCruisesAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportGenericFormatProgramCruisesAction.java index ab1be99..de785a3 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportGenericFormatProgramCruisesAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportGenericFormatProgramCruisesAction.java @@ -50,10 +50,11 @@ public class ImportGenericFormatProgramCruisesAction extends AbstractTuttiAction if (doAction) { - // check archive is sane + // compute number of steps (will also check archive format) GenericFormatImportService service = getContext().getGenericFormatImportService(); - service.checkArchive(file); + int nbSteps = service.getImportProgramNbSteps(file); + createProgressionModelIfRequired(nbSteps); } @@ -69,32 +70,29 @@ public class ImportGenericFormatProgramCruisesAction extends AbstractTuttiAction Preconditions.checkNotNull(file); if (log.isInfoEnabled()) { - log.info("Will import cruise to program " + program.getId() + " from archive: " + file); + log.info("Will import cruises to program " + program.getName() + " from archive: " + file); } GenericFormatImportService service = getContext().getGenericFormatImportService(); - int nbSteps = service.getImportProgramNbSteps(file); - createProgressionModelIfRequired(nbSteps); - - ApplicationBusinessException exportError = null; + ApplicationBusinessException importError = null; try { service.importProgram(program.getId(), file, getProgressionModel()); } catch (ApplicationBusinessException e) { String errorMessage; - errorMessage = t("tutti.importProgram.action.exportErrors", program.getName(), e.getMessage()); + errorMessage = t("tutti.importProgram.action.importErrors", program.getName(), e.getMessage()); - exportError = new ApplicationBusinessException(errorMessage); + importError = new ApplicationBusinessException(errorMessage); } handler.resetEditProgramAction(); sendMessage(t("tutti.importProgram.action.success", program.getName(), file.getName())); - if (exportError != null) { - throw exportError; + if (importError != null) { + throw importError; } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.