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 51e9b2fa3a92c5be9d6afd0ec61dd0de3eb0413f Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Nov 21 18:36:50 2014 +0100 amelioration du code d'import pupitri + ajout d'un test pour la fonctionnalite #6149 --- .../tutti/service/pupitri/PupitriCatch.java | 10 +- .../tutti/service/pupitri/PupitriImportResult.java | 10 +- .../service/pupitri/PupitriImportService.java | 2 +- .../pupitri/PupitriImportServiceEvo6149.java | 153 ++++++++++++++++++++ .../src/test/resources/pupitri/evo-6149.car | 6 + .../src/test/resources/pupitri/evo-6149.tnk | 32 +++++ .../test/resources/pupitri/evo-6149.tuttiProtocol | 154 +++++++++++++++++++++ 7 files changed, 355 insertions(+), 12 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java index 26238c2..5112ceb 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java @@ -70,7 +70,7 @@ public class PupitriCatch implements Serializable { * * We will look after this sign while crzating species batch to import. */ - protected Signs addMelagCommentForSign; + protected Signs melagElevatedSign; protected Map<Signs, MutableFloat> weightBySign = Maps.newHashMap(); @@ -88,7 +88,7 @@ public class PupitriCatch implements Serializable { } public boolean isAddMelagComment(Signs sign) { - return addMelagCommentForSign != null && addMelagCommentForSign.equals(sign); + return melagElevatedSign != null && melagElevatedSign.equals(sign); } public boolean isForMelag() { @@ -126,8 +126,10 @@ public class PupitriCatch implements Serializable { weightBySign.remove(sign); } - public void setAddMelagCommentForSign(Signs addMelagCommentForSign) { - this.addMelagCommentForSign = addMelagCommentForSign; + public void setMelagElevatedWeight(Signs melagElevatedSign, Float weight) { + addToSign(melagElevatedSign, weight); + removeSign(Signs.MELAG); + this.melagElevatedSign = melagElevatedSign; } @Override diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java index e5f864b..7acb4ed 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java @@ -260,8 +260,7 @@ public class PupitriImportResult { // No BIG batch associated with this melag species // use default batch // see https://forge.codelutin.com/issues/5742 - aCatch.addToSign(Signs.DEFAULT, weight); - aCatch.setAddMelagCommentForSign(Signs.DEFAULT); + aCatch.setMelagElevatedWeight(Signs.DEFAULT, weight); if (log.isInfoEnabled()) { log.info("Add melag batch for " + aCatch + " as default (no G found) : " + weight); @@ -272,17 +271,14 @@ public class PupitriImportResult { // also found a big batch associated with this melga species // transform it as a small batch instead of default // see https://forge.codelutin.com/issues/5742 - aCatch.addToSign(Signs.SMALL, weight); - aCatch.setAddMelagCommentForSign(Signs.SMALL); + aCatch.setMelagElevatedWeight(Signs.SMALL, weight); if (log.isInfoEnabled()) { log.info("Add melag batch for " + aCatch + " as small (G found) : " + weight); } } - - aCatch.removeSign(Signs.MELAG); - + melagCommentBuilder.append(t("tutti.service.pupitri.import.createMelag.comment.part2", sampleWeight, unitLabel, speciesDecorator.toString(aCatch.getSpecies()))).append("\n"); } else { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java index 45aa3e3..09a8ae1 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java @@ -491,7 +491,7 @@ public class PupitriImportService extends AbstractTuttiService { if (addMelagComment) { childBatch.setComment(melagComment); if (log.isInfoEnabled()) { - log.info("Add melag comment for sign " + signs + "on " + speciesDecorator.toString(species)); + log.info("Add melag comment for sign " + signs + " on " + speciesDecorator.toString(species)); } } diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149.java new file mode 100644 index 0000000..3ebe58b --- /dev/null +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149.java @@ -0,0 +1,153 @@ +package fr.ifremer.tutti.service.pupitri; + +import com.google.common.base.Predicate; +import com.google.common.collect.Sets; +import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; +import fr.ifremer.tutti.TuttiConfigurationOption; +import fr.ifremer.tutti.persistence.entities.data.BatchContainer; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +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.protocol.TuttiProtocol; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Test; +import org.nuiton.decorator.Decorator; + +import java.io.File; +import java.io.IOException; +import java.util.Set; + +/** + * Created on 11/21/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.10 + */ +public class PupitriImportServiceEvo6149 extends PupitryImportServiceTestSupport { + + /** Logger. */ + private static final Log log = LogFactory.getLog(PupitriImportServiceEvo5062Test.class); + + @Test + public void importPupitri() throws IOException { + + File trunk = dbResource.copyClassPathResource("pupitri/evo-6149.tnk", "pupitri.tnk"); + File carroussel = dbResource.copyClassPathResource("pupitri/evo-6149.car", "pupitri.car"); + File protocol = dbResource.copyClassPathResource("pupitri/evo-6149.tuttiProtocol", "evo-6149.tuttiProtocol"); + dbResource.getConfig().getApplicationConfig().setOption(TuttiConfigurationOption.DB_PROTOCOL_DIRECTORY.getKey(), protocol.getParentFile().getAbsolutePath()); + TuttiProtocol protocol1 = persistenceService.getProtocol("evo-6149"); + persistenceService.setProtocol(protocol1); + + FishingOperation operation = dataContext.operations.get(1); + CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(operation.getId()); + catchBatch.setFishingOperation(operation); + + BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId(), false); + Assert.assertEquals(0, rootSpeciesBatch.sizeChildren()); + + PupitriImportResult pupitriImportResult = service.importPupitri(trunk, carroussel, operation, catchBatch); + Assert.assertTrue(pupitriImportResult.isFishingOperationFound()); + int nbNotAdded = pupitriImportResult.getNbCarrousselNotImported(); + Assert.assertEquals(0, nbNotAdded); + Set<String> notImportedSpeciesIds = pupitriImportResult.getNotImportedSpeciesIds(); + Assert.assertNotNull(notImportedSpeciesIds); + Assert.assertTrue(notImportedSpeciesIds.isEmpty()); + + BatchContainer<SpeciesBatch> rootSpeciesBatchAfter = persistenceService.getRootSpeciesBatch(operation.getId(), false); + Assert.assertEquals(2, rootSpeciesBatchAfter.sizeChildren()); + + /* + Melange total 100Kg / sorted 50Kg -> ratio = x2 + MERL-MCC un lot G (50Kg) + MERL-MCC un lot P (25x2 -> 50Kg) + TRAC-TRU un lot VRAC (25x2 -> 50Kg) + */ + Set<Integer> expectedSpecies = Sets.newHashSet( + + 16994, // MERL-MCC + 17116 // TRAC-TRU + ); + + + Predicate<SpeciesAbleBatch> batchVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + PmfmId.SORTED_UNSORTED.getValue(), + QualitativeValueId.SORTED_VRAC.getValue()); + + Predicate<SpeciesAbleBatch> bigVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + PmfmId.SIZE_CATEGORY.getValue(), + QualitativeValueId.SIZE_BIG.getValue()); + + Predicate<SpeciesAbleBatch> smallVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + PmfmId.SIZE_CATEGORY.getValue(), + QualitativeValueId.SIZE_SMALL.getValue()); + + Decorator<Species> speciesDecorator = decoratorService.getDecoratorByType(Species.class); + + for (SpeciesBatch speciesBatch : rootSpeciesBatchAfter.getChildren()) { + + Species species = speciesBatch.getSpecies(); + Integer speciesId = species.getIdAsInt(); + + Assert.assertTrue("l'espece " + speciesId + " ne doit pas etre importe", expectedSpecies.contains(speciesId)); + + if (log.isInfoEnabled()) { + log.info("Species : " + speciesId + " : " + speciesDecorator.toString(species)); + } + + if (16994 == speciesId) { + + // un lot VRAC (sans poids) avec deux fils + // un G (100Kg) + // un P (50Kg) + + Assert.assertTrue(batchVracPredicate.apply(speciesBatch)); + Assert.assertFalse(speciesBatch.isChildBatchsEmpty()); + Assert.assertEquals(2, speciesBatch.sizeChildBatchs()); + + { + SpeciesBatch child = speciesBatch.getChildBatchs(0); + + if (bigVracPredicate.apply(child)) { + + Assert.assertEquals(100, child.getSampleCategoryWeight(), 0.001); + + } else if (smallVracPredicate.apply(child)) { + + Assert.assertEquals(50, child.getSampleCategoryWeight(), 0.001); + } else { + Assert.fail("le lot " + child + " doit etre une categorisation Taille Gros ou petit"); + } + } + { + SpeciesBatch child = speciesBatch.getChildBatchs(1); + if (bigVracPredicate.apply(child)) { + + Assert.assertEquals(100, child.getSampleCategoryWeight(), 0.001); + + } else if (smallVracPredicate.apply(child)) { + + Assert.assertEquals(50, child.getSampleCategoryWeight(), 0.001); + } else { + Assert.fail("le lot " + child + " doit etre une categorisation Taille Gros ou petit"); + } + } + } + + if (17116 == speciesId) { + + // un unique lot vrac de 50Kg + Assert.assertTrue(batchVracPredicate.apply(speciesBatch)); + Assert.assertTrue(speciesBatch.isChildBatchsEmpty()); + Assert.assertEquals(50, speciesBatch.getSampleCategoryWeight(), 0.001); + } + + } + + } +} \ No newline at end of file diff --git a/tutti-service/src/test/resources/pupitri/evo-6149.car b/tutti-service/src/test/resources/pupitri/evo-6149.car new file mode 100644 index 0000000..0478192 --- /dev/null +++ b/tutti-service/src/test/resources/pupitri/evo-6149.car @@ -0,0 +1,6 @@ +$TSMES,27/11/13,13:14:46.647,BLCAR, 0,A,1,002,MELA-NGE,0,VAT,0025.0, +$TSMES,27/11/13,13:16:26.243,BLCAR, 0,A,1,002,MELA-NGE,0,VAT,0025.0, +$TSMES,27/11/13,13:16:41.355,BLCAR, 0,A,1,002,MELA-NGE,0,VAT,0050.0, +$TSMES,27/11/13,13:28:27.717,BLCAR, 0,A,1,002,MERL-MCC,G,VAT,0100.0, (du merlu gros) +$TSMES,27/11/13,13:30:30.398,BLCAR, 0,A,1,001,MERL-MCC,T,VAT,0025.0, (du merlu petit) +$TSMES,27/11/13,13:31:17.004,BLCAR, 0,A,1,001,TRAC-TRU,T,VAT,0025.0, (du trac-tru en melange) -> lot unique \ No newline at end of file diff --git a/tutti-service/src/test/resources/pupitri/evo-6149.tnk b/tutti-service/src/test/resources/pupitri/evo-6149.tnk new file mode 100644 index 0000000..bdb8624 --- /dev/null +++ b/tutti-service/src/test/resources/pupitri/evo-6149.tnk @@ -0,0 +1,32 @@ +$TSMES,27/11/13,09:08:45.130,BLTNK, 0,A,1,VAT,0045.4, +$TSMES,27/11/13,09:10:10.522,BLTNK, 0,A,1,VAT,0045.0, +$TSMES,27/11/13,09:12:14.730,BLTNK, 0,A,1,VAT,0043.9, +$TSMES,27/11/13,09:14:06.033,BLTNK, 0,A,1,VAT,0044.0, +$TSMES,27/11/13,09:16:08.907,BLTNK, 0,A,1,VAT,0042.4, +$TSMES,27/11/13,09:17:47.515,BLTNK, 0,A,1,VAT,0044.3, +$TSMES,27/11/13,09:19:44.039,BLTNK, 0,A,1,VAT,0043.6, +$TSMES,27/11/13,09:21:49.166,BLTNK, 0,A,1,VAT,0044.2, +$TSMES,27/11/13,09:26:57.681,BLTNK, 0,A,1,VAT,0045.9, +$TSMES,27/11/13,09:29:20.020,BLTNK, 0,A,1,VAT,0045.8, +$TSMES,27/11/13,09:30:37.535,BLTNK, 0,A,1,VAT,0047.0, +$TSMES,27/11/13,09:32:16.153,BLTNK, 0,A,1,VAT,0046.6, +$TSMES,27/11/13,09:33:30.882,BLTNK, 0,A,1,VAT,0044.4, +$TSMES,27/11/13,09:34:50.649,BLTNK, 0,A,1,VAT,0044.5, +$TSMES,27/11/13,09:36:36.933,BLTNK, 0,A,1,VAT,0043.7, +$TSMES,27/11/13,09:37:53.424,BLTNK, 0,A,1,VAT,0046.4, +$TSMES,27/11/13,09:41:40.944,BLTNK, 0,A,1,VAT,0048.6, +$TSMES,27/11/13,09:43:33.377,BLTNK, 0,A,1,VAT,0046.4, +$TSMES,27/11/13,09:44:46.487,BLTNK, 0,A,1,VAT,0046.4, +$TSMES,27/11/13,09:46:12.192,BLTNK, 0,A,1,VAT,0045.2, +$TSMES,27/11/13,09:47:34.846,BLTNK, 0,A,1,VAT,0045.4, +$TSMES,27/11/13,09:48:55.920,BLTNK, 0,A,1,VAT,0048.4, +$TSMES,27/11/13,09:51:12.724,BLTNK, 0,A,1,VAT,0046.4, +$TSMES,27/11/13,09:54:14.063,BLTNK, 0,A,1,VAT,0040.4, +$TSMES,27/11/13,09:56:11.000,BLTNK, 0,A,1,VAT,0044.2, +$TSMES,27/11/13,09:57:38.344,BLTNK, 0,A,1,VAT,0047.3, +$TSMES,27/11/13,09:59:23.603,BLTNK, 0,A,1,VAT,0047.6, +$TSMES,27/11/13,10:00:51.868,BLTNK, 0,A,1,VAT,0047.9, +$TSMES,27/11/13,10:02:29.655,BLTNK, 0,A,1,VAT,0044.2, +$TSMES,27/11/13,10:04:14.101,BLTNK, 0,A,1,VAT,0045.9, +$TSMES,27/11/13,10:06:08.886,BLTNK, 0,A,1,VAT,0043.2, +$TSMES,27/11/13,10:08:35.000,BLTNK, 0,A,1,VAT,0007.5, diff --git a/tutti-service/src/test/resources/pupitri/evo-6149.tuttiProtocol b/tutti-service/src/test/resources/pupitri/evo-6149.tuttiProtocol new file mode 100644 index 0000000..62af9e3 --- /dev/null +++ b/tutti-service/src/test/resources/pupitri/evo-6149.tuttiProtocol @@ -0,0 +1,154 @@ +id: c6ee2088-9720-46c0-b8d2-8f21c902676f +name: Protocole EVHOE 2013 +benthos: +comment: Protocole pour les tests 2013 avec Jean Jacques Rivoalen +gearUseFeaturePmfmId: +- 131 +- 828 +- 884 +- 965 +lengthClassesPmfmId: +- 306 +- 622 +- 307 +- 302 +- 299 +- 1394 +- 1417 +- 1425 +- 1426 +- 1427 +- 283 +- 284 +- 285 +- 294 +- 295 +- 300 +- 301 +- 304 +- 318 +- 319 +- 322 +- 323 +- 661 +- 662 +species: +- !SpeciesProtocol + id: 056a7ad4-934c-4d69-b068-1a2dd64012cb + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: [] + speciesReferenceTaxonId: 2786 + speciesSurveyCode: EUPH-AUX + weightEnabled: true +- !SpeciesProtocol + id: 5f7e400c-6a03-4092-9ccf-0031823b3a14 + calcifySampleEnabled: true + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: + - 198 + - 196 + speciesReferenceTaxonId: 1540 + speciesSurveyCode: MERL-MCC + weightEnabled: true +- !SpeciesProtocol + id: dc5738bb-ed38-4814-a016-9fabfd833212 + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: + - 198 + speciesReferenceTaxonId: 1662 + speciesSurveyCode: TRAC-TRU + weightEnabled: true +- !SpeciesProtocol + id: e4577b1e-18d1-459c-acff-04aedf4e917d + calcifySampleEnabled: true + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 307 + mandatorySampleCategoryId: [] + speciesReferenceTaxonId: 1362 + speciesSurveyCode: ENGR-ENC + weightEnabled: true +- !SpeciesProtocol + id: 4076fe7e-01fe-4164-820a-47b50dfa8e02 + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: [] + speciesReferenceTaxonId: 1920 + speciesSurveyCode: EUTR-GUR + weightEnabled: true +- !SpeciesProtocol + id: 16f4a094-1904-4e50-aff9-1f2dcab3a909 + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: + - 198 + speciesReferenceTaxonId: 1772 + speciesSurveyCode: SCOM-SCO + weightEnabled: true +- !SpeciesProtocol + id: d5887f0e-bd99-4f66-a967-8fcff8224b32 + calcifySampleEnabled: true + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: + - 198 + - 196 + speciesReferenceTaxonId: 1553 + speciesSurveyCode: MICR-POU + weightEnabled: true +- !SpeciesProtocol + id: 944db3c6-d870-4f03-8abc-9a985a6feb65 + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: [] + speciesReferenceTaxonId: 1415 + speciesSurveyCode: MYCT-PUN + weightEnabled: true +- !SpeciesProtocol + id: 2a8122cf-d238-4820-a7b9-eacaf1f302bd + calcifySampleEnabled: true + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: [] + speciesReferenceTaxonId: 1551 + speciesSurveyCode: MELA-NGE + weightEnabled: true +- !SpeciesProtocol + id: 0de3f5c9-0ca9-4a7c-84aa-323d9eaa7f7f + countIfNoFrequencyEnabled: true + mandatorySampleCategoryId: [] + speciesReferenceTaxonId: 872 + speciesSurveyCode: ACAN-PEL + weightEnabled: true +- !SpeciesProtocol + id: ddffa4c9-cbb5-447f-a829-e2ac0cfea0f5 + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 306 + mandatorySampleCategoryId: [] + speciesReferenceTaxonId: 1732 + speciesSurveyCode: ACANPAL + weightEnabled: true +vesselUseFeaturePmfmId: +- 173 +- 194 +- 230 +- 782 +- 843 +- 844 +- 846 +- 847 +- 848 +- 849 +- 850 +- 851 +- 857 +- 858 +- 859 +- 861 +- 862 +- 863 +- 881 +- 882 +- 883 -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.