Author: tchemit Date: 2013-04-22 15:38:24 +0200 (Mon, 22 Apr 2013) New Revision: 851 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/851 Log: fixes #2345: [CAPTURES] Muavaise remont?\195?\169 des arbres d'?\195?\169chantillonage Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-04-22 13:37:22 UTC (rev 850) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-04-22 13:38:24 UTC (rev 851) @@ -43,6 +43,7 @@ import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.service.batch.BatchPersistenceHelper; @@ -115,10 +116,14 @@ BatchContainer<BenthosBatch> result = new BatchContainer<BenthosBatch>(); result.setId(vracBenthosBatch.getId()); - for (Batch batch1 : vracBenthosBatch.getChildBatchs()) { - SortingBatch source = (SortingBatch) batch1; + for (Batch batch : vracBenthosBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; + ReferenceTaxon referenceTaxon = source.getReferenceTaxon(); + Preconditions.checkNotNull(referenceTaxon, "Can't have a rootBenthosBatch with a null taxon, but was for " + batch.getId()); + Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); BenthosBatch target = TuttiBeanFactory.newBenthosBatch(); + target.setSpecies(species); entityToBenthosBatch(source, target); result.addChildren(target); if (log.isInfoEnabled()) { @@ -134,18 +139,18 @@ ); if (horsVracBenthosBatch != null) { for (Batch batch : horsVracBenthosBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; + ReferenceTaxon referenceTaxon = source.getReferenceTaxon(); + Preconditions.checkNotNull(referenceTaxon, "Can't have a rootSpeciesBatch with a null taxon, but was for " + source.getId()); + Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); BenthosBatch target = TuttiBeanFactory.newBenthosBatch(); - entityToBenthosBatch((SortingBatch) batch, target); + target.setSpecies(species); + + entityToBenthosBatch(source, target); result.addChildren(target); if (log.isInfoEnabled()) { - String species; - if (target.getSpecies() != null) { - species = String.valueOf(target.getSpecies().getReferenceTaxonId()); - } else { - species = "no species"; - } - log.info("Loaded CatchBatch Hors Vrac > Benthos > " + species + " : " + target.getId()); + log.info("Loaded CatchBatch Hors Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); } } } @@ -285,20 +290,6 @@ public List<BenthosBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) { Preconditions.checkNotNull(benthosBatchId); -// List<BenthosBatchFrequency> results = Lists.newArrayList(); -// -// Integer sortingBatchId = Integer.valueOf(benthosBatchId); -// Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(sortingBatchId); -// Preconditions.checkNotNull( -// catchBatchId, -// "Could not find catchBatch for benthosBatch: " + benthosBatchId); -// -// CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); -// -// SortingBatch sortingBatch = catchBatchDao.getSortingBatchById( -// catchBatch, sortingBatchId); -// -// List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(sortingBatch); List<SortingBatch> frequencyChilds = batchHelper.getFrequencies(benthosBatchId); List<BenthosBatchFrequency> results = Lists.newArrayList(); for (SortingBatch child : frequencyChilds) { @@ -346,10 +337,6 @@ for (SortingBatch child : frequencyChilds) { notUpdatedChildIds.add(child.getId()); } -// for (Batch batch : parentBatch.getChildBatchs()) { -// SortingBatch sortingBatch = (SortingBatch) batch; -// notUpdatedChildIds.add(sortingBatch.getId()); -// } short rankOrder = 0; List<SortingBatch> batchsToUpdate = Lists.newArrayList(); @@ -399,7 +386,6 @@ return Collections.unmodifiableList(frequencies); } - //------------------------------------------------------------------------// //-- Internal methods --// //------------------------------------------------------------------------// @@ -407,6 +393,8 @@ protected BenthosBatch entityToBenthosBatch(SortingBatch source, BenthosBatch target) { + Preconditions.checkNotNull(target.getSpecies()); + target.setId(source.getId().toString()); // Individual count @@ -446,27 +434,15 @@ } } - // Species - Integer referenceTaxonId = source.getInheritedReferenceTaxonId(); - if (referenceTaxonId == null && source.getReferenceTaxon() != null) { - referenceTaxonId = source.getReferenceTaxon().getId(); - } - if (referenceTaxonId != null) { - // TODO : add cache on getSpeciesByReferenceTaxonId - Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId); - target.setSpecies(species); - } - //FIXME-TC Check the test is still ok? - //FIXME-TC We should a stronger test -// if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) { if (target.getSampleCategoryType() != null) { List<BenthosBatch> targetChilds = Lists.newArrayList(); for (Batch batch : source.getChildBatchs()) { SortingBatch sourceChild = (SortingBatch) batch; BenthosBatch targetChild = TuttiBeanFactory.newBenthosBatch(); + targetChild.setSpecies(target.getSpecies()); entityToBenthosBatch(sourceChild, targetChild); if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Hors Vrac > (Species|Benthos) > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); + log.info("Loaded CatchBatch Hors Vrac > (Species|Benthos) > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); } if (targetChild.getSampleCategoryValue() != null) { targetChilds.add(targetChild); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-22 13:37:22 UTC (rev 850) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-22 13:38:24 UTC (rev 851) @@ -116,10 +116,14 @@ BatchContainer<SpeciesBatch> result = new BatchContainer<SpeciesBatch>(); result.setId(vracSpeciesBatch.getId()); - for (Batch batch1 : vracSpeciesBatch.getChildBatchs()) { - SortingBatch source = (SortingBatch) batch1; + for (Batch batch : vracSpeciesBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; + ReferenceTaxon referenceTaxon = source.getReferenceTaxon(); + Preconditions.checkNotNull(referenceTaxon, "Can't have a rootSpeciesBatch with a null taxon, but was for " + batch.getId()); + Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); SpeciesBatch target = TuttiBeanFactory.newSpeciesBatch(); + target.setSpecies(species); entityToSpeciesBatch(source, target); result.addChildren(target); @@ -135,9 +139,14 @@ BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (horsVracSpeciesBatch != null) { for (Batch batch : horsVracSpeciesBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; + ReferenceTaxon referenceTaxon = source.getReferenceTaxon(); + Preconditions.checkNotNull(referenceTaxon, "Can't have a rootSpeciesBatch with a null taxon, but was for " + source.getId()); + Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); SpeciesBatch target = TuttiBeanFactory.newSpeciesBatch(); - entityToSpeciesBatch((SortingBatch) batch, target); + target.setSpecies(species); + entityToSpeciesBatch(source, target); result.addChildren(target); if (log.isInfoEnabled()) { log.info("Loaded CatchBatch Hors Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); @@ -415,6 +424,8 @@ protected SpeciesBatch entityToSpeciesBatch(SortingBatch source, SpeciesBatch target) { + Preconditions.checkNotNull(target.getSpecies()); + target.setId(source.getId().toString()); // Individual count @@ -454,27 +465,15 @@ } } - // Species - Integer referenceTaxonId = source.getInheritedReferenceTaxonId(); - if (referenceTaxonId == null && source.getReferenceTaxon() != null) { - referenceTaxonId = source.getReferenceTaxon().getId(); - } - if (referenceTaxonId != null) { - // TODO : add cache on getSpeciesByReferenceTaxonId - Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId); - target.setSpecies(species); - } - //FIXME-TC Check the test is still ok? - //FIXME-TC We should a stronger test -// if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) { if (target.getSampleCategoryType() != null) { List<SpeciesBatch> targetChilds = Lists.newArrayList(); for (Batch batch : source.getChildBatchs()) { SortingBatch sourceChild = (SortingBatch) batch; SpeciesBatch targetChild = TuttiBeanFactory.newSpeciesBatch(); + targetChild.setSpecies(target.getSpecies()); entityToSpeciesBatch(sourceChild, targetChild); if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Hors Vrac > (Species|Benthos) > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); + log.info("Loaded CatchBatch Hors Vrac > (Species|Benthos) > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); } if (targetChild.getSampleCategoryValue() != null) { targetChilds.add(targetChild);