[tutti] branch feature/5842 created (now 3cd4263)
This is an automated email from the git hooks/post-receive script. New change to branch feature/5842 in repository tutti. See http://git.codelutin.com/tutti.git at 3cd4263 refs #5842 use adagio 3.6.4 (fix catch batch loading) + remove quantification measurement at synchronize action operation + foacotrize code between speciesBatch and benthosBatch This branch includes the following new commits: new b1e6e58 refs #5842 use adagio 3.6.4 (fix catch batch loading) + remove quantification measurement at synchronize action operation + foacotrize code between speciesBatch and benthosBatch new 3cd4263 refs #5842 use adagio 3.6.4 (fix catch batch loading) + remove quantification measurement at synchronize action operation + foacotrize code between speciesBatch and benthosBatch The 2 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 3cd4263d473284fb04f9d80828f971fbd3c8e3be Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Oct 21 13:21:00 2014 +0200 refs #5842 use adagio 3.6.4 (fix catch batch loading) + remove quantification measurement at synchronize action operation + foacotrize code between speciesBatch and benthosBatch commit b1e6e58457bc097fcb8448aebab5c240482a2446 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Oct 21 13:20:36 2014 +0200 refs #5842 use adagio 3.6.4 (fix catch batch loading) + remove quantification measurement at synchronize action operation + foacotrize code between speciesBatch and benthosBatch -- 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 feature/5842 in repository tutti. See http://git.codelutin.com/tutti.git commit b1e6e58457bc097fcb8448aebab5c240482a2446 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Oct 21 13:20:36 2014 +0200 refs #5842 use adagio 3.6.4 (fix catch batch loading) + remove quantification measurement at synchronize action operation + foacotrize code between speciesBatch and benthosBatch --- .../entities/data/SpeciesAbleBatch.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatch.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatch.java new file mode 100644 index 0000000..bcc1ce3 --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatch.java @@ -0,0 +1,67 @@ +package fr.ifremer.tutti.persistence.entities.data; + +import fr.ifremer.tutti.persistence.entities.CommentAware; +import fr.ifremer.tutti.persistence.entities.TuttiEntity; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import java.io.Serializable; +import java.util.List; +import javax.annotation.Generated; + +@Generated(value = "org.nuiton.eugene.java.JavaInterfaceTransformer", date = "Mon Oct 20 10:51:27 CEST 2014") +public interface SpeciesAbleBatch extends TuttiEntity, CommentAware { + + Species getSpecies(); + + void setSpecies(Species species); + + Integer getSampleCategoryId(); + + Serializable getSampleCategoryValue(); + + Float getSampleCategoryWeight(); + + Integer getNumber(); + + boolean isSpeciesToConfirm(); + + Float getSampleCategoryComputedWeight(); + + Integer getComputedNumber(); + + Float getComputedWeight(); + + void setSampleCategoryId(Integer categoryId); + + void setSampleCategoryValue(Serializable categoryValue); + + void setSampleCategoryWeight(Float categoryWeight); + + void setNumber(Integer number); + + void setSpeciesToConfirm(boolean speciesToConfirm); + + void setSampleCategoryComputedWeight(Float sampleCategoryComputedWeight); + + void setComputedNumber(Integer computedNumber); + + void setComputedWeight(Float computedWeight); + + SpeciesAbleBatch getParentBatch(); + + boolean isChildBatchsEmpty(); + + List<? extends SpeciesAbleBatch> getChildBatchs(); + + Float getWeight(); + + void setWeight(Float weight); + + Integer getRankOrder(); + + void setRankOrder(Integer rankOrder); + + void setParentBatch(SpeciesAbleBatch parentBatch); + + void setChildBatchs(List childs); + +} //SpeciesAbleBatch -- 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 feature/5842 in repository tutti. See http://git.codelutin.com/tutti.git commit 3cd4263d473284fb04f9d80828f971fbd3c8e3be Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Oct 21 13:21:00 2014 +0200 refs #5842 use adagio 3.6.4 (fix catch batch loading) + remove quantification measurement at synchronize action operation + foacotrize code between speciesBatch and benthosBatch --- pom.xml | 4 +- .../entities/data/SpeciesAbleBatchs.java | 31 +++ .../BenthosBatchPersistenceServiceImpl.java | 165 ++++++++-------- .../service/CatchBatchPersistenceServiceImpl.java | 53 +++--- .../SpeciesBatchPersistenceServiceImpl.java | 210 ++++++++++----------- .../service/util/BatchPersistenceHelper.java | 120 ++++++++++++ .../service/util/MeasurementPersistenceHelper.java | 13 ++ .../src/main/xmi/tutti-persistence.zargo | Bin 56700 -> 56767 bytes 8 files changed, 377 insertions(+), 219 deletions(-) diff --git a/pom.xml b/pom.xml index 37ba771..8b6fa2f 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>codelutinpom</artifactId> - <version>1.3</version> + <version>1.5</version> </parent> <groupId>fr.ifremer</groupId> @@ -135,7 +135,7 @@ <jaxxVersion>2.13</jaxxVersion> <swingXVersion>1.6.4</swingXVersion> <slf4jVersion>1.7.7</slf4jVersion> - <adagioVersion>3.6.3</adagioVersion> + <adagioVersion>3.6.4-SNAPSHOT</adagioVersion> <bluecoveVersion>2.1.0</bluecoveVersion> <hibernateVersion>4.3.6.Final</hibernateVersion> <springVersion>4.1.0.RELEASE</springVersion> diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java index 3177d2a..0277f23 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java @@ -27,6 +27,8 @@ package fr.ifremer.tutti.persistence.entities.data; import com.google.common.base.Predicate; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import java.util.List; + /** * Created on 8/26/14. * @@ -40,6 +42,34 @@ public class SpeciesAbleBatchs { return new SpeciesAbleBatchCategoryPredicate(cateogryId, value); } + public static <B extends SpeciesAbleBatch> B newInstance(B parent) { + + B targetChild = (B) (parent instanceof SpeciesBatch ? SpeciesBatchs.newSpeciesBatch() : BenthosBatchs.newBenthosBatch()); + return targetChild; + + } + + public static <B extends SpeciesAbleBatch> void setChildBatchs(B target, List<B> targetChilds) { + + if (target instanceof SpeciesBatch) { + ((SpeciesBatch) target).setChildBatchs((List<SpeciesBatch>) targetChilds); + } else { + ((BenthosBatch) target).setChildBatchs((List<BenthosBatch>) targetChilds); + } + + } + + public static <B extends SpeciesAbleBatch> void setParentBatch(B target, B targetChild) { + + if (target instanceof SpeciesBatch) { + ((SpeciesBatch) targetChild).setParentBatch((SpeciesBatch) target); + } else { + ((BenthosBatch) targetChild).setParentBatch((BenthosBatch) target); + } + + } + + public static class SpeciesAbleBatchCategoryPredicate implements Predicate<SpeciesAbleBatch> { private final Integer id; @@ -57,5 +87,6 @@ public class SpeciesAbleBatchs { input.getSampleCategoryValue() instanceof CaracteristicQualitativeValue && qualitativeValue.equals(((CaracteristicQualitativeValue) input.getSampleCategoryValue()).getIdAsInt()); } + } } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java index 39805d7..78fe6db 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java @@ -57,6 +57,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; import java.util.List; +import java.util.Objects; import static org.nuiton.i18n.I18n.t; @@ -127,7 +128,7 @@ public class BenthosBatchPersistenceServiceImpl extends AbstractPersistenceServi BenthosBatch target = BenthosBatchs.newBenthosBatch(); target.setSpecies(species); - entityToBean(sampleCategoryModel, source, target); + batchHelper.entityToBean(sampleCategoryModel, source, target); result.addChildren(target); if (log.isDebugEnabled()) { log.debug("Loaded CatchBatch Vrac > Benthos > Alive Itemized > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); @@ -153,7 +154,7 @@ public class BenthosBatchPersistenceServiceImpl extends AbstractPersistenceServi BenthosBatch target = BenthosBatchs.newBenthosBatch(); target.setSpecies(species); - entityToBean(sampleCategoryModel, source, target); + batchHelper.entityToBean(sampleCategoryModel, source, target); result.addChildren(target); if (log.isDebugEnabled()) { log.debug("Loaded CatchBatch Hors Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); @@ -356,86 +357,86 @@ public class BenthosBatchPersistenceServiceImpl extends AbstractPersistenceServi //-- Internal methods --// //------------------------------------------------------------------------// - protected BenthosBatch entityToBean(SampleCategoryModel sampleCategoryModel, - SortingBatch source, - BenthosBatch target) { - - Preconditions.checkNotNull(target.getSpecies()); - - target.setId(source.getId().toString()); - - // Rank order - target.setRankOrder(Integer.valueOf(source.getRankOrder())); - - // Individual count - target.setNumber(source.getIndividualCount()); - - // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight - if (source.getWeight() != null && source.getWeightBeforeSampling() == null) { - target.setSampleCategoryWeight(source.getWeight()); - } else { - target.setWeight(source.getWeight()); - target.setSampleCategoryWeight(source.getWeightBeforeSampling()); - } - - if (CollectionUtils.isNotEmpty(source.getChildBatchs()) && target.getWeight() != null) { - - // can't use this sample weight on a node - // the weight comes from sampleRatioText, but must NOT be used here - target.setWeight(null); - - } - - // Comments - target.setComment(source.getComments()); - - // Sample category type (only one is applied) - SortingMeasurement sm = null; - if (source.getSortingMeasurements().size() == 1) { - sm = source.getSortingMeasurements().iterator().next(); - } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) { - sm = measurementPersistenceHelper.getInheritedSortingMeasurement(source); - } - if (sm != null) { - boolean isSamplingCategory = sampleCategoryModel.containsCategoryId( - sm.getPmfm().getId()); - if (isSamplingCategory) { - Integer qualitativeId = null; - if (sm.getQualitativeValue() != null) { - qualitativeId = sm.getQualitativeValue().getId(); - } - batchHelper.setSampleCategoryQualitative( - target, - sm.getPmfm().getId(), - sm.getNumericalValue(), - sm.getAlphanumericalValue(), - qualitativeId); - } - } - - if (target.getSampleCategoryId() != null) { - List<BenthosBatch> targetChilds = Lists.newArrayList(); - for (Batch batch : source.getChildBatchs()) { - SortingBatch sourceChild = (SortingBatch) batch; - BenthosBatch targetChild = BenthosBatchs.newBenthosBatch(); - targetChild.setSpecies(target.getSpecies()); - entityToBean(sampleCategoryModel, sourceChild, targetChild); - if (log.isDebugEnabled()) { - log.debug("Loaded CatchBatch Hors Vrac > Benthos > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); - } - if (targetChild.getSampleCategoryValue() != null) { - targetChilds.add(targetChild); - targetChild.setParentBatch(target); - } - } - target.setChildBatchs(targetChilds); - } - - QualityFlag qualityFlag = source.getQualityFlag(); - target.setSpeciesToConfirm(qualityFlag != null && QualityFlagCode.DOUBTFUL.getValue().equals(qualityFlag.getCode())); - - return target; - } +// protected BenthosBatch entityToBean(SampleCategoryModel sampleCategoryModel, +// SortingBatch source, +// BenthosBatch target) { +// +// Preconditions.checkNotNull(target.getSpecies()); +// +// target.setId(source.getId().toString()); +// +// // Rank order +// target.setRankOrder(Integer.valueOf(source.getRankOrder())); +// +// // Individual count +// target.setNumber(source.getIndividualCount()); +// +// // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight +// if (source.getWeight() != null && source.getWeightBeforeSampling() == null) { +// target.setSampleCategoryWeight(source.getWeight()); +// } else { +// target.setWeight(source.getWeight()); +// target.setSampleCategoryWeight(source.getWeightBeforeSampling()); +// } +// +// if (CollectionUtils.isNotEmpty(source.getChildBatchs()) && target.getWeight() != null) { +// +// // can't use this sample weight on a node +// // the weight comes from sampleRatioText, but must NOT be used here +// target.setWeight(null); +// +// } +// +// // Comments +// target.setComment(source.getComments()); +// +// // Sample category type (only one is applied) +// SortingMeasurement sm = null; +// if (source.getSortingMeasurements().size() == 1) { +// sm = source.getSortingMeasurements().iterator().next(); +// } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) { +// sm = measurementPersistenceHelper.getInheritedSortingMeasurement(source); +// } +// if (sm != null) { +// boolean isSamplingCategory = sampleCategoryModel.containsCategoryId( +// sm.getPmfm().getId()); +// if (isSamplingCategory) { +// Integer qualitativeId = null; +// if (sm.getQualitativeValue() != null) { +// qualitativeId = sm.getQualitativeValue().getId(); +// } +// batchHelper.setSampleCategoryQualitative( +// target, +// sm.getPmfm().getId(), +// sm.getNumericalValue(), +// sm.getAlphanumericalValue(), +// qualitativeId); +// } +// } +// +// if (target.getSampleCategoryId() != null) { +// List<BenthosBatch> targetChilds = Lists.newArrayList(); +// for (Batch batch : source.getChildBatchs()) { +// SortingBatch sourceChild = (SortingBatch) batch; +// BenthosBatch targetChild = BenthosBatchs.newBenthosBatch(); +// targetChild.setSpecies(target.getSpecies()); +// entityToBean(sampleCategoryModel, sourceChild, targetChild); +// if (log.isDebugEnabled()) { +// log.debug("Loaded CatchBatch Hors Vrac > Benthos > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); +// } +// if (targetChild.getSampleCategoryValue() != null) { +// targetChilds.add(targetChild); +// targetChild.setParentBatch(target); +// } +// } +// target.setChildBatchs(targetChilds); +// } +// +// QualityFlag qualityFlag = source.getQualityFlag(); +// target.setSpeciesToConfirm(qualityFlag != null && QualityFlagCode.DOUBTFUL.getValue().equals(qualityFlag.getCode())); +// +// return target; +// } protected void beanToEntity(BenthosBatch source, SortingBatch target, diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java index c207460..2c6b5ca 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java @@ -27,21 +27,21 @@ import com.google.common.base.Preconditions; import fr.ifremer.adagio.core.dao.data.batch.Batch; import fr.ifremer.adagio.core.dao.data.batch.CatchBatchImpl; import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; +import fr.ifremer.adagio.core.dao.data.batch.SortingBatchImpl; import fr.ifremer.adagio.core.dao.data.measure.QuantificationMeasurement; import fr.ifremer.adagio.core.dao.data.operation.FishingOperationImpl; import fr.ifremer.adagio.core.dao.referential.QualityFlagCode; import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl; import fr.ifremer.tutti.TuttiConfiguration; -import fr.ifremer.tutti.util.Numbers; -import fr.ifremer.tutti.util.Weights; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatchBean; import fr.ifremer.tutti.persistence.service.util.BatchPersistenceHelper; import fr.ifremer.tutti.persistence.service.util.BatchTreeHelper; import fr.ifremer.tutti.persistence.service.util.MeasurementPersistenceHelper; import fr.ifremer.tutti.persistence.service.util.SynchronizationStatusHelper; +import fr.ifremer.tutti.util.Numbers; +import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.FlushMode; @@ -204,7 +204,7 @@ public class CatchBatchPersistenceServiceImpl // To store quantification measurement ids which need to update to pass // is_reference_quantification to false // such measurements are only on batch nodes (leaf always keep the value to true) - Set<Integer> quantificationMeasurementIds = new HashSet<>(); + Set<QuantificationMeasurement> quantificationMeasurements = new HashSet<>(); Set<Integer> indirectWeightByBatchSkip = new HashSet<>(); @@ -213,7 +213,7 @@ public class CatchBatchPersistenceServiceImpl computeIndirectWeight(rootBatch, indirectWeightByBatch, indirectWeightByBatchSkip, - quantificationMeasurementIds); + quantificationMeasurements); } @@ -236,19 +236,28 @@ public class CatchBatchPersistenceServiceImpl log.info(String.format("setWeightAndSampleRatio :: %d (%s // %s)", batch.getId(), weight, indirectWeight)); } - batchTreeHelper.setSortingSamplingRatio(batch, indirectWeight, weight); + SortingBatch sortingBatch = load(SortingBatchImpl.class, batch.getId()); + batchTreeHelper.setSortingSamplingRatio(sortingBatch, indirectWeight, weight); } } - if (!quantificationMeasurementIds.isEmpty()) { + if (!quantificationMeasurements.isEmpty()) { - // update measurements + // remove measurements if (log.isInfoEnabled()) { - log.info("updateQuantificationMeasurementsForBatchNodes :: " + quantificationMeasurementIds); + log.info("updateQuantificationMeasurementsForBatchNodes :: " + quantificationMeasurements); + } + + for (QuantificationMeasurement quantificationMeasurement : quantificationMeasurements) { + + if (log.isInfoEnabled()) { + log.info(String.format("Remove quantification measurement %d on batch %d (batch is not a leaf)", quantificationMeasurement.getId(), quantificationMeasurement.getBatch().getId())); + } + Batch batch = quantificationMeasurement.getBatch(); + SortingBatch sortingBatch = load(SortingBatchImpl.class, batch.getId()); + measurementPersistenceHelper.removeWeightMeasurementQuantificationMeasurement(sortingBatch, quantificationMeasurement); } - queryUpdate("updateQuantificationMeasurementsForBatchNodes", - "ids", IntegerType.INSTANCE, quantificationMeasurementIds); } @@ -561,7 +570,7 @@ public class CatchBatchPersistenceServiceImpl protected void computeIndirectWeight(Batch batch, Map<Integer, SortingBatch> indirectWeightByBatch, Set<Integer> indirectWeightByBatchSkip, - Set<Integer> quantificationMeasurements) { + Set<QuantificationMeasurement> quantificationMeasurements) { Integer batchId = batch.getId(); @@ -587,14 +596,13 @@ public class CatchBatchPersistenceServiceImpl } QuantificationMeasurement measurement = measurementPersistenceHelper.getWeightMeasurementQuantificationMeasurement(batch); - if (measurement != null && - BooleanUtils.isTrue(measurement.getIsReferenceQuantification())) { + if (measurement != null) { - // need to pass this to false - quantificationMeasurements.add(measurement.getId()); + // need to remove the quantification measurement + quantificationMeasurements.add(measurement); if (log.isDebugEnabled()) { - log.debug("[BATCH :: " + batchId + "] - Need to update the quantification measurement (not a leaf) :: " + measurement.getId()); + log.debug("[BATCH :: " + batchId + "] - Need to remove the quantification measurement (not a leaf) :: " + measurement.getId()); } } @@ -607,17 +615,6 @@ public class CatchBatchPersistenceServiceImpl } -// if (batch.getWeight() == null) { -// -// // no need to compute indirect weight, mark batch -// indirectWeightByBatchSkip.add(batchId); -// -// if (log.isDebugEnabled()) { -// log.debug("[BATCH :: " + batchId + "] - No need of indirect weight (no weight on it) "); -// } -// return; -// -// } if (batch.getWeightBeforeSampling() != null) { // no need to compute indirect weight, mark batch diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java index 32b095e..e803abd 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java @@ -24,15 +24,11 @@ package fr.ifremer.tutti.persistence.service; import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import fr.ifremer.adagio.core.dao.data.batch.Batch; import fr.ifremer.adagio.core.dao.data.batch.CatchBatch; import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; -import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement; -import fr.ifremer.adagio.core.dao.referential.QualityFlag; -import fr.ifremer.adagio.core.dao.referential.QualityFlagCode; import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxon; import fr.ifremer.tutti.persistence.InvalidBatchModelException; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; @@ -135,7 +131,7 @@ public class SpeciesBatchPersistenceServiceImpl extends AbstractPersistenceServi SpeciesBatch target = SpeciesBatchs.newSpeciesBatch(); target.setSpecies(species); - entityToBean(sampleCategoryModel, source, target); + batchHelper.entityToBean(sampleCategoryModel, source, target); result.addChildren(target); if (log.isDebugEnabled()) { @@ -163,7 +159,7 @@ public class SpeciesBatchPersistenceServiceImpl extends AbstractPersistenceServi } SpeciesBatch target = SpeciesBatchs.newSpeciesBatch(); target.setSpecies(species); - entityToBean(sampleCategoryModel, source, target); + batchHelper.entityToBean(sampleCategoryModel, source, target); result.addChildren(target); if (log.isDebugEnabled()) { log.debug("Loaded CatchBatch Hors Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); @@ -393,111 +389,111 @@ public class SpeciesBatchPersistenceServiceImpl extends AbstractPersistenceServi //-- Internal methods --// //------------------------------------------------------------------------// - protected SpeciesBatch entityToBean(SampleCategoryModel sampleCategoryModel, - SortingBatch source, - SpeciesBatch target) { - - Preconditions.checkNotNull(target.getSpecies()); - - target.setId(source.getId().toString()); - - // Rank order - target.setRankOrder(Integer.valueOf(source.getRankOrder())); - - // Individual count - target.setNumber(source.getIndividualCount()); - - // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight - if (source.getWeight() != null && source.getWeightBeforeSampling() == null) { - target.setSampleCategoryWeight(source.getWeight()); - } else { - target.setWeight(source.getWeight()); - target.setSampleCategoryWeight(source.getWeightBeforeSampling()); - } - +// protected SpeciesBatch entityToBean(SampleCategoryModel sampleCategoryModel, +// SortingBatch source, +// SpeciesBatch target) { +// +// Preconditions.checkNotNull(target.getSpecies()); +// +// target.setId(source.getId().toString()); +// +// // Rank order +// target.setRankOrder(Integer.valueOf(source.getRankOrder())); +// +// // Individual count +// target.setNumber(source.getIndividualCount()); +// +// // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight +// if (source.getWeight() != null && source.getWeightBeforeSampling() == null) { +// target.setSampleCategoryWeight(source.getWeight()); +// } else { +// target.setWeight(source.getWeight()); +// target.setSampleCategoryWeight(source.getWeightBeforeSampling()); +// } +// +//// if (CollectionUtils.isNotEmpty(source.getChildBatchs()) && target.getWeight() != null) { +//// +//// // can't use this sample weight on a node +//// // the weight comes from sampleRatioText, but must NOT be used here +//// target.setWeight(null); +//// +//// } +// +// +// // Comments +// target.setComment(source.getComments()); +// +// // Sample category type (only one is applied) +// SortingMeasurement sm = null; +// if (source.getSortingMeasurements().size() == 1) { +// sm = source.getSortingMeasurements().iterator().next(); +// } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) { +// sm = measurementPersistenceHelper.getInheritedSortingMeasurement(source); +// } +// if (sm != null) { +// +// boolean isFrequency = batchHelper.isFrequencyBatch(sampleCategoryModel, source); +// +// if (!isFrequency) { +// Integer qualitativeId = null; +// if (sm.getQualitativeValue() != null) { +// qualitativeId = sm.getQualitativeValue().getId(); +// } +// batchHelper.setSampleCategoryQualitative( +// target, +// sm.getPmfm().getId(), +// sm.getNumericalValue(), +// sm.getAlphanumericalValue(), +// qualitativeId); +// } +// } +// +// if (target.getSampleCategoryId() != null) { +// List<SpeciesBatch> targetChilds = Lists.newArrayList(); +// for (Batch batch : source.getChildBatchs()) { +// SortingBatch sourceChild = (SortingBatch) batch; +// SpeciesBatch targetChild = SpeciesBatchs.newSpeciesBatch(); +// targetChild.setSpecies(target.getSpecies()); +// entityToBean(sampleCategoryModel, sourceChild, targetChild); +// if (log.isDebugEnabled()) { +// log.debug("Loaded CatchBatch (Vrac|Hors Vrac) > Species > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); +// } +// if (targetChild.getSampleCategoryValue() != null) { +// targetChilds.add(targetChild); +// targetChild.setParentBatch(target); +// } +// } +// target.setChildBatchs(targetChilds); +// } +// +// //FIXME tchemit-2014-08-29 We can only do this if not an a leaf node (means with no frequencies...) +// //FIXME tchemit-2014-08-29 But need to see if this is really need to do that . +// // see https://forge.codelutin.com/issues/5698 +// // if (CollectionUtils.isNotEmpty(source.getChildBatchs()) && target.getWeight() != null) { // -// // can't use this sample weight on a node -// // the weight comes from sampleRatioText, but must NOT be used here -// target.setWeight(null); +// SortingBatch childBatch = (SortingBatch) Iterables.get(source.getChildBatchs(), 0); +// +// boolean isFrequency = batchHelper.isFrequencyBatch(sampleCategoryModel, childBatch); +// +// if (!isFrequency) { +// +// // can't use this sample weight on a node +// // the weight comes from sampleRatioText, but must NOT be used here +// // but we can only do this if childs are not frequencies +// +// target.setWeight(null); +// +// } // // } - - - // Comments - target.setComment(source.getComments()); - - // Sample category type (only one is applied) - SortingMeasurement sm = null; - if (source.getSortingMeasurements().size() == 1) { - sm = source.getSortingMeasurements().iterator().next(); - } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) { - sm = measurementPersistenceHelper.getInheritedSortingMeasurement(source); - } - if (sm != null) { - - boolean isFrequency = batchHelper.isFrequencyBatch(sampleCategoryModel, source); - - if (!isFrequency) { - Integer qualitativeId = null; - if (sm.getQualitativeValue() != null) { - qualitativeId = sm.getQualitativeValue().getId(); - } - batchHelper.setSampleCategoryQualitative( - target, - sm.getPmfm().getId(), - sm.getNumericalValue(), - sm.getAlphanumericalValue(), - qualitativeId); - } - } - - if (target.getSampleCategoryId() != null) { - List<SpeciesBatch> targetChilds = Lists.newArrayList(); - for (Batch batch : source.getChildBatchs()) { - SortingBatch sourceChild = (SortingBatch) batch; - SpeciesBatch targetChild = SpeciesBatchs.newSpeciesBatch(); - targetChild.setSpecies(target.getSpecies()); - entityToBean(sampleCategoryModel, sourceChild, targetChild); - if (log.isDebugEnabled()) { - log.debug("Loaded CatchBatch (Vrac|Hors Vrac) > Species > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); - } - if (targetChild.getSampleCategoryValue() != null) { - targetChilds.add(targetChild); - targetChild.setParentBatch(target); - } - } - target.setChildBatchs(targetChilds); - } - - //FIXME tchemit-2014-08-29 We can only do this if not an a leaf node (means with no frequencies...) - //FIXME tchemit-2014-08-29 But need to see if this is really need to do that . - // see https://forge.codelutin.com/issues/5698 - - if (CollectionUtils.isNotEmpty(source.getChildBatchs()) && target.getWeight() != null) { - - SortingBatch childBatch = (SortingBatch) Iterables.get(source.getChildBatchs(), 0); - - boolean isFrequency = batchHelper.isFrequencyBatch(sampleCategoryModel, childBatch); - - if (!isFrequency) { - - // can't use this sample weight on a node - // the weight comes from sampleRatioText, but must NOT be used here - // but we can only do this if childs are not frequencies - - target.setWeight(null); - - } - - } - - - QualityFlag qualityFlag = source.getQualityFlag(); - target.setSpeciesToConfirm(qualityFlag != null && QualityFlagCode.DOUBTFUL.getValue().equals(qualityFlag.getCode())); - - return target; - } +// +// +// QualityFlag qualityFlag = source.getQualityFlag(); +// target.setSpeciesToConfirm(qualityFlag != null && QualityFlagCode.DOUBTFUL.getValue().equals(qualityFlag.getCode())); +// +// return target; +// } protected void beanToEntity(SpeciesBatch source, SortingBatch target, diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java index 450b013..f49d954 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java @@ -24,6 +24,7 @@ package fr.ifremer.tutti.persistence.service.util; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ifremer.adagio.core.dao.data.batch.Batch; @@ -37,6 +38,7 @@ import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement; import fr.ifremer.adagio.core.dao.data.operation.FishingOperation; import fr.ifremer.adagio.core.dao.data.operation.FishingOperationDao; import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; +import fr.ifremer.adagio.core.dao.referential.QualityFlag; import fr.ifremer.adagio.core.dao.referential.QualityFlagCode; import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl; import fr.ifremer.adagio.core.dao.referential.pmfm.Pmfm; @@ -51,6 +53,7 @@ import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchs; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; @@ -73,6 +76,7 @@ import java.io.Serializable; import java.text.MessageFormat; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -649,6 +653,122 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { } + public <B extends SpeciesAbleBatch> B entityToBean(SampleCategoryModel sampleCategoryModel, + SortingBatch source, + B target) { + + Preconditions.checkNotNull(target.getSpecies()); + + target.setId(source.getId().toString()); + + // Rank order + target.setRankOrder(Integer.valueOf(source.getRankOrder())); + + // Individual count + target.setNumber(source.getIndividualCount()); + + // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight + if (source.getWeight() != null && source.getWeightBeforeSampling() == null) { + target.setSampleCategoryWeight(source.getWeight()); + } else { + target.setWeight(source.getWeight()); + target.setSampleCategoryWeight(source.getWeightBeforeSampling()); + +// if (Objects.equals(source.getWeight(), source.getWeightBeforeSampling())) { +// +// // after a allegro synchronize, can happen, we do not use quantification measurement on a not leaf node +// // the weight comes from sampleRatioText, but in facts there only one weight... +// target.setWeight(null); +// +// } + } + +// if (CollectionUtils.isNotEmpty(source.getChildBatchs()) && target.getWeight() != null) { +// +// // can't use this sample weight on a node +// // the weight comes from sampleRatioText, but must NOT be used here +// target.setWeight(null); +// +// } + + + // Comments + target.setComment(source.getComments()); + + // Sample category type (only one is applied) + SortingMeasurement sm = null; + if (source.getSortingMeasurements().size() == 1) { + sm = source.getSortingMeasurements().iterator().next(); + } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) { + sm = measurementPersistenceHelper.getInheritedSortingMeasurement(source); + } + if (sm != null) { + + boolean isFrequency = isFrequencyBatch(sampleCategoryModel, source); + + if (!isFrequency) { + Integer qualitativeId = null; + if (sm.getQualitativeValue() != null) { + qualitativeId = sm.getQualitativeValue().getId(); + } + setSampleCategoryQualitative( + target, + sm.getPmfm().getId(), + sm.getNumericalValue(), + sm.getAlphanumericalValue(), + qualitativeId); + } + } + + if (target.getSampleCategoryId() != null) { + List<B> targetChilds = Lists.newArrayList(); + for (Batch batch : source.getChildBatchs()) { + SortingBatch sourceChild = (SortingBatch) batch; + B targetChild = SpeciesAbleBatchs.newInstance(target); + targetChild.setSpecies(target.getSpecies()); + entityToBean(sampleCategoryModel, sourceChild, targetChild); + if (log.isDebugEnabled()) { + log.debug("Loaded CatchBatch (Vrac|Hors Vrac) > Species > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); + } + if (targetChild.getSampleCategoryValue() != null) { + targetChilds.add(targetChild); + SpeciesAbleBatchs.setParentBatch(target, targetChild); + } + } + + SpeciesAbleBatchs.setChildBatchs(target, targetChilds); + + } + + //FIXME tchemit-2014-08-29 We can only do this if not an a leaf node (means with no frequencies...) + //FIXME tchemit-2014-08-29 But need to see if this is really need to do that . + // see https://forge.codelutin.com/issues/5698 + + if (CollectionUtils.isNotEmpty(source.getChildBatchs()) && target.getWeight() != null) { + + SortingBatch childBatch = (SortingBatch) Iterables.get(source.getChildBatchs(), 0); + + boolean isFrequency = isFrequencyBatch(sampleCategoryModel, childBatch); + + if (!isFrequency) { + + // can't use this sample weight on a node + // the weight comes from sampleRatioText, but must NOT be used here + // but we can only do this if childs are not frequencies + + target.setWeight(null); + + } + + } + + QualityFlag qualityFlag = source.getQualityFlag(); + target.setSpeciesToConfirm(qualityFlag != null && QualityFlagCode.DOUBTFUL.getValue().equals(qualityFlag.getCode())); + + return target; + + } + public Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { if (value == null) { return null; diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/MeasurementPersistenceHelper.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/MeasurementPersistenceHelper.java index 64de421..e576e13 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/MeasurementPersistenceHelper.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/MeasurementPersistenceHelper.java @@ -54,6 +54,7 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.io.Serializable; import java.util.Collection; +import java.util.Iterator; import java.util.Set; /** @@ -141,6 +142,18 @@ public class MeasurementPersistenceHelper extends AbstractPersistenceService { return quantificationMeasurement; } + public void removeWeightMeasurementQuantificationMeasurement(Batch batch, QuantificationMeasurement quantificationMeasurement) { + Collection<QuantificationMeasurement> measurements = batch.getQuantificationMeasurements(); + Iterator<QuantificationMeasurement> iterator = measurements.iterator(); + while (iterator.hasNext()) { + QuantificationMeasurement next = iterator.next(); + if (quantificationMeasurement.getId().equals(next.getId())) { + iterator.remove(); + break; + } + } + } + public SortingMeasurement getInheritedSortingMeasurement(SortingBatch sortingBatch) { return catchBatchDao.getInheritedSortingMeasurement(sortingBatch, PmfmId.SORTED_UNSORTED.getValue()); } diff --git a/tutti-persistence/src/main/xmi/tutti-persistence.zargo b/tutti-persistence/src/main/xmi/tutti-persistence.zargo index 3f7f384..6a566b8 100644 Binary files a/tutti-persistence/src/main/xmi/tutti-persistence.zargo and b/tutti-persistence/src/main/xmi/tutti-persistence.zargo differ -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm