branch support/3.13.x updated (def4911 -> 009c0c9)
This is an automated email from the git hooks/post-receive script. New change to branch support/3.13.x in repository tutti. See http://git.codelutin.com/tutti.git from def4911 fixes #6799: [TECH] Problème de fermeture de l'écran résumé new 009c0c9 fixes #6796: [IMPORT] En 3.13.1 import big fin, rendre l'erreur plus explicite The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 009c0c94f59bf7e1a7c4297a9ce7cc2f6c125eca Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 9 19:40:05 2015 +0100 fixes #6796: [IMPORT] En 3.13.1 import big fin, rendre l'erreur plus explicite Summary of changes: .../tutti/service/bigfin/BigfinImportContext.java | 40 +++-- .../resources/i18n/tutti-service_fr_FR.properties | 10 +- .../service/bigfin/BigfinImportService2Test.java | 191 +++++++++++++++++++++ 3 files changed, 221 insertions(+), 20 deletions(-) create mode 100644 tutti-service/src/test/java/fr/ifremer/tutti/service/bigfin/BigfinImportService2Test.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch support/3.13.x in repository tutti. See http://git.codelutin.com/tutti.git commit 009c0c94f59bf7e1a7c4297a9ce7cc2f6c125eca Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 9 19:40:05 2015 +0100 fixes #6796: [IMPORT] En 3.13.1 import big fin, rendre l'erreur plus explicite --- .../tutti/service/bigfin/BigfinImportContext.java | 40 +++-- .../resources/i18n/tutti-service_fr_FR.properties | 10 +- .../service/bigfin/BigfinImportService2Test.java | 191 +++++++++++++++++++++ 3 files changed, 221 insertions(+), 20 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/bigfin/BigfinImportContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/bigfin/BigfinImportContext.java index 0bd2fd7..3f5f8c1 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/bigfin/BigfinImportContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/bigfin/BigfinImportContext.java @@ -213,6 +213,8 @@ public class BigfinImportContext { if (stationFound) { + String recordId = bigfinDataRow.getRecordId(); + SpeciesOrSpeciesBatch speciesOrspeciesBatch = bigfinDataRow.getSpeciesOrSpeciesBatch(); if (speciesOrspeciesBatch.isSpecies()) { @@ -223,11 +225,11 @@ public class BigfinImportContext { Species species = speciesOrspeciesBatch.getSpecies(); - boolean speciesIsKnown = checkSpeciesIsKnown(species); + boolean speciesIsKnown = checkSpeciesIsKnown(recordId, species); if (speciesIsKnown) { - boolean speciesProtocoleIsSafe = checkSpeciesProtocol(species); + boolean speciesProtocoleIsSafe = checkSpeciesProtocol(recordId, species); if (speciesProtocoleIsSafe) { @@ -240,13 +242,25 @@ public class BigfinImportContext { // do some checks on the given species batch - boolean speciesBatchIsLeaf = checkSpeciesBatchIsLeaf(bigfinDataRow); + SpeciesBatch speciesBatch = speciesOrspeciesBatch.getBatch(); + + // Check Species batch is a leaf + boolean speciesBatchIsLeaf = checkSpeciesBatchIsLeaf(recordId, speciesBatch); if (speciesBatchIsLeaf) { - canBeAdd = true; + // Check Species protocol is safe + + boolean speciesProtocoleIsSafe = checkSpeciesProtocol(recordId, speciesBatch.getSpecies()); + + if (speciesProtocoleIsSafe) { + + canBeAdd = true; + + } } + } } else { @@ -258,17 +272,13 @@ public class BigfinImportContext { return canBeAdd; } - public boolean checkSpeciesBatchIsLeaf(BigfinDataRow bigfinDataRow) { - - Preconditions.checkArgument(bigfinDataRow.getSpeciesOrSpeciesBatch().isBatch()); - + public boolean checkSpeciesBatchIsLeaf(String recordId, SpeciesBatch batch) { - SpeciesBatch batch = bigfinDataRow.getSpeciesOrSpeciesBatch().getBatch(); boolean speciesBatchIsLeaf = batch.isChildBatchsEmpty(); if (!speciesBatchIsLeaf) { - String warning = t("tutti.service.bigfinImport.warning.speciesBatch.tooCategorized", batch.getId()); + String warning = t("tutti.service.bigfinImport.warning.speciesBatch.tooCategorized", recordId, batch.getId()); if (log.isWarnEnabled()) { log.warn(warning); } @@ -293,7 +303,7 @@ public class BigfinImportContext { } - public boolean checkSpeciesIsKnown(Species species) { + public boolean checkSpeciesIsKnown(String recordId, Species species) { boolean speciesIsKnown = true; @@ -301,7 +311,7 @@ public class BigfinImportContext { // bloquer tout si un "species" ne match pas le référentiel de Tutti : lister dans ce cas les codes non reconnus if (speciesNotRecognized.add(species)) { - String error = t("tutti.service.bigfinImport.error.species.not.found", species.getExternalCode()); + String error = t("tutti.service.bigfinImport.error.species.not.found", recordId, species.getExternalCode()); if (log.isErrorEnabled()) { log.error(error); } @@ -316,7 +326,7 @@ public class BigfinImportContext { } - public boolean checkSpeciesProtocol(Species species) { + public boolean checkSpeciesProtocol(String recordId, Species species) { boolean speciesProtocoleIsSafe = true; @@ -333,7 +343,7 @@ public class BigfinImportContext { if (speciesNotInProtocol.add(species)) { - String error = t("tutti.service.bigfinImport.warning.species.notInProtocol", speciesLabel); + String error = t("tutti.service.bigfinImport.warning.species.notInProtocol", recordId, speciesLabel); if (log.isWarnEnabled()) { log.warn(error); } @@ -348,7 +358,7 @@ public class BigfinImportContext { if (speciesInProtocolButWithoutLengthStepPmfmId.add(species)) { // bloquer toute espèce reconnue du protocole mais qui n'a pas de méthode de mesure - String error = t("tutti.service.bigfinImport.error.species.without.lengthstep", speciesLabel); + String error = t("tutti.service.bigfinImport.error.species.without.lengthstep", recordId, speciesLabel); if (log.isErrorEnabled()) { log.error(error); } diff --git a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties index 221c6fe..e02140c 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties @@ -50,15 +50,15 @@ tutti.report.step.export.fishingOperation=Exporter le trait sélectionné tutti.report.step.generateReport=Générer le rapport tutti.report.step.load.fishingOperation=Charger le trait sélectionné tutti.service.bigfin.import.attachment.comment=Import Bigfin du %s -tutti.service.bigfinImport.error.species.not.found=L'espèce '<strong>%s</strong>' est inconnue -tutti.service.bigfinImport.error.species.without.lengthstep=L'espèce '<strong>%s</strong>' n'a pas de classe de taille associée dans le protocole. -tutti.service.bigfinImport.error.szClass.unknwon=Ligne <i>%s</i>, catégorie de taille inconnue (doit être 0, 1 ou 2) +tutti.service.bigfinImport.error.species.not.found=[Enregistrement %s] L'espèce '<strong>%s</strong>' est inconnue +tutti.service.bigfinImport.error.species.without.lengthstep=[Enregistrement %s] L'espèce '<strong>%s</strong>' n'a pas de classe de taille associée dans le protocole. +tutti.service.bigfinImport.error.szClass.unknwon=[Enregistrement %s] catégorie de taille inconnue (doit être 0, 1 ou 2) tutti.service.bigfinImport.warning.species.batch.frequenciesOnHigherLevel=Le lot de '<strong>%1s / %2s</strong>' a déjà des mensurations tutti.service.bigfinImport.warning.species.categoriesSkipped=L'espèce '<strong>%1s</strong>' a été catégorisée sans les catégories '<strong>%2s</strong>' et '<strong>%3s</strong>' tutti.service.bigfinImport.warning.species.categorySkipped=L'espèce '<strong>%1s</strong>' a été catégorisée sans la catégorie '<strong>%2s</strong>' -tutti.service.bigfinImport.warning.species.notInProtocol=L'espèce '<strong>%1s</strong>' n'est pas présente dans le protocole +tutti.service.bigfinImport.warning.species.notInProtocol=[Enregistrement %s] L'espèce '<strong>%1s</strong>' n'est pas présente dans le protocole tutti.service.bigfinImport.warning.species.tooCategorized=L'espèce '<strong>%1s</strong>' est trop catégorisée (pas limitée à '<strong>%2s</strong>' et '<strong>%3s</strong>') -tutti.service.bigfinImport.warning.speciesBatch.tooCategorized=Le lot '<strong>%1s</strong>' contient des sous catégories, on ne peut pas y ajouter des mensurations. +tutti.service.bigfinImport.warning.speciesBatch.tooCategorized=[Enregistrement %s] Le lot '<strong>%1s</strong>' contient des sous catégories, on ne peut pas y ajouter des mensurations. tutti.service.bigfinimport.error.no.protocol=Impossible de faire un import Bigfin sans protocol. tutti.service.compressZipFile.error=Erreur lors de la compression du dossier %1s dans le fichier %2s tutti.service.context.serviceInstanciation.error=Erreur lors de l'instanciation du service %s diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/bigfin/BigfinImportService2Test.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/bigfin/BigfinImportService2Test.java new file mode 100644 index 0000000..830708b --- /dev/null +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/bigfin/BigfinImportService2Test.java @@ -0,0 +1,191 @@ +package fr.ifremer.tutti.service.bigfin; + +import com.google.common.base.Charsets; +import com.google.common.base.Predicate; +import com.google.common.collect.Lists; +import com.google.common.io.Files; +import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.persistence.entities.data.CatchBatchs; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.Cruises; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.FishingOperations; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchs; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; +import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValues; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.ServiceDbResource; +import fr.ifremer.tutti.service.TuttiServiceContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.util.DateUtil; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * Created on 3/9/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14 + */ +public class BigfinImportService2Test { + + /** Logger. */ + private static final Log log = LogFactory.getLog(BigfinImportService2Test.class); + + @Rule + public final ServiceDbResource dbResource = ServiceDbResource.writeDb("dbEmpty"); + + protected BigfinImportService service; + + protected PersistenceService persistenceService; + + protected ServiceDbResource.DataContext dataContext; + + protected File dataDirectory; + + protected Predicate<SpeciesAbleBatch> vracPredicate; + + public static final String PROGRAM_ID = "CAM-CGFS"; + + public static final String CRUISE_ID = "0"; + + public static final String OPERATION_1_ID = "1"; + + public static final String OPERATION_2_ID = "2"; + + public static final String OPERATION_3_ID = "0"; + + @Before + public void setUp() throws Exception { + + dataDirectory = dbResource.getConfig().getDataDirectory(); + + TuttiServiceContext serviceContext = dbResource.getServiceContext(); + + dbResource.openDataContext(); + + persistenceService = serviceContext.getService(PersistenceService.class); + service = serviceContext.getService(BigfinImportService.class); + + dataContext = dbResource.loadContext(PROGRAM_ID); + + vracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate(PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.VRAC.getValue()); + } + + @Test + public void testASpeciesWithNoLengthPmfmInProtocol() throws IOException { + + // Load protocol + + dbResource.loadInternalProtocolFile("bigfin/", "protocol"); + + // Create cruise + + Cruise cruise = Cruises.newCruise(); + cruise.setName("MyCruise"); + cruise.setMultirigNumber(1); + cruise.setBeginDate(DateUtil.createDate(1, 5, 2014)); + cruise.setEndDate(DateUtil.createDate(21, 5, 2014)); + TuttiLocation harbour = persistenceService.getAllHarbour().get(0); + cruise.setDepartureLocation(harbour); + cruise.setReturnLocation(harbour); + cruise.setProgram(dataContext.program); + cruise.setVessel(persistenceService.getAllScientificVessel().get(0)); + cruise.setHeadOfMission(Lists.newArrayList(persistenceService.getAllPerson().get(0))); + + cruise = persistenceService.createCruise(cruise); + + // Create empty fishing operation + FishingOperation fishingOperation = FishingOperations.newFishingOperation(); + fishingOperation.setCruise(cruise); + fishingOperation.setFishingOperationNumber(1); + fishingOperation.setStationNumber("S0419"); + fishingOperation.setGearShootingStartDate(DateUtil.createDate(14, 5, 2014)); + fishingOperation.setGearShootingEndDate(DateUtil.createDate(14, 5, 2014)); + fishingOperation = persistenceService.createFishingOperation(fishingOperation); + + CatchBatch catchBatch = CatchBatchs.newCatchBatch(); + catchBatch.setFishingOperation(fishingOperation); + + persistenceService.createCatchBatch(catchBatch); + + { + String fileContent = "Study name,ID,Date,LOC,STA,COMMENT,GPS X,GPS Y,SP CODE,SPEC,LENGTH (mm),WEIGHT (g),SEX,SIZE,MT,MS\n" + + "Test,1,05/14/14 09:49:32, ,S0419, ,47.24713560992085,-1.5474773011082363, ,URANSCA,210, ,None,0,None,"; + + File importFile = dbResource.getConfig().newTempFile("bigFin1"); + Files.write(fileContent, importFile, Charsets.UTF_8); + + BigfinImportResult importResult = service.importFile(importFile, fishingOperation, catchBatch); + + int nbFrequenciesAdded = importResult.getNbFrequenciesImported(); + List<String> errors = importResult.getErrors(); + List<String> warnings = importResult.getWarnings(); + + if (log.isInfoEnabled()) { + log.info("Frequencies Imported: " + nbFrequenciesAdded); + log.info("Errors: " + errors.size()); + log.info("Warnings: " + warnings.size()); + } + + int nbNewFrequencies = 0; + Assert.assertEquals(nbNewFrequencies, nbFrequenciesAdded); + Assert.assertEquals(1, errors.size()); + Assert.assertEquals(0, warnings.size()); + + } + + // Create a species batch for the species + SpeciesBatch speciesBatch = SpeciesBatchs.newSpeciesBatch(); + speciesBatch.setFishingOperation(fishingOperation); + Species species = persistenceService.getSpeciesByReferenceTaxonId(1764); + speciesBatch.setSpecies(species); + speciesBatch.setSampleCategoryId(PmfmId.SORTED_UNSORTED.getValue()); + Caracteristic sortedUnsortedCaracteristic = persistenceService.getSortedUnsortedCaracteristic(); + CaracteristicQualitativeValue qualitativeValue = CaracteristicQualitativeValues.getQualitativeValue(sortedUnsortedCaracteristic, QualitativeValueId.SORTED_VRAC.getValue()); + speciesBatch.setSampleCategoryValue(qualitativeValue); + + speciesBatch = persistenceService.createSpeciesBatch(speciesBatch, null); + { + + String fileContent = "Study name,ID,Date,LOC,STA,COMMENT,GPS X,GPS Y,SP CODE,SPEC,LENGTH (mm),WEIGHT (g),SEX,SIZE,MT,MS\n" + + "Test,1,05/14/14 09:49:32, ,S0419, ,47.24713560992085,-1.5474773011082363, ," + speciesBatch.getId() + ",210, ,None,0,None,"; + + File importFile = dbResource.getConfig().newTempFile("bigFin1"); + Files.write(fileContent, importFile, Charsets.UTF_8); + + BigfinImportResult importResult = service.importFile(importFile, fishingOperation, catchBatch); + + int nbFrequenciesAdded = importResult.getNbFrequenciesImported(); + List<String> errors = importResult.getErrors(); + List<String> warnings = importResult.getWarnings(); + + if (log.isInfoEnabled()) { + log.info("Frequencies Imported: " + nbFrequenciesAdded); + log.info("Errors: " + errors.size()); + log.info("Warnings: " + warnings.size()); + } + + int nbNewFrequencies = 0; + Assert.assertEquals(nbNewFrequencies, nbFrequenciesAdded); + Assert.assertEquals(1, errors.size()); + Assert.assertEquals(0, warnings.size()); + } + + } +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm