branch feature/merge_species_benthos created (now ddeea47)
This is an automated email from the git hooks/post-receive script. New change to branch feature/merge_species_benthos in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git at ddeea47 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module swing This branch includes the following new commits: new 884591e suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module persistence new dfdf9c9 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module service new ddeea47 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module swing The 3 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 ddeea47392e1c59d79716c2eae9dc56f4d67b3e9 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 17 09:13:35 2016 +0100 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module swing commit dfdf9c990ae231e918481edd357b0d8d43d06816 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 17 08:46:55 2016 +0100 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module service commit 884591ea91b0c6b37b006d8035e6df58e4986026 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 17 08:46:23 2016 +0100 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module persistence -- 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/merge_species_benthos in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 884591ea91b0c6b37b006d8035e6df58e4986026 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 17 08:46:23 2016 +0100 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module persistence --- .../tutti/persistence/TuttiPersistenceImpl.java | 27 +- .../persistence/TuttiPersistenceNoDbImpl.java | 25 +- .../entities/data/SpeciesAbleBatchs.java | 142 --- .../entities/data/SpeciesBatchFrequencys.java | 9 + .../persistence/entities/data/SpeciesBatchs.java | 73 ++ .../entities/referential/TaxonCache.java | 16 +- .../service/BenthosBatchPersistenceService.java | 39 +- .../BenthosBatchPersistenceServiceImpl.java | 658 +++++----- .../service/CatchBatchPersistenceServiceImpl.java | 2 +- .../MarineLitterBatchPersistenceServiceImpl.java | 24 +- .../SpeciesBatchPersistenceServiceImpl.java | 700 ++++++----- .../SpeciesBatchPersistenceServiceSupport.java | 933 ++++++++++++++ .../batch/ScientificCruiseCatchBatchValidator.java | 16 +- .../service/batch/TuttiCatchBatchValidator.java | 3 +- .../CaracteristicPersistenceService.java | 8 +- .../CaracteristicPersistenceServiceImpl.java | 14 +- .../service/util/BatchPersistenceHelper.java | 1281 ++++++++++---------- .../persistence/service/util/BatchTreeHelper.java | 713 ----------- .../service/util/tree/BatchTreeHelper.java | 330 +++++ .../service/util/tree/BatchTreeHelperSupport.java | 365 ++++++ .../service/util/tree/BenthosBatchTreeHelper.java | 43 + .../service/util/tree/SpeciesBatchTreeHelper.java | 43 + .../util/tree/SpeciesBatchTreeHelperSupport.java | 424 +++++++ .../src/main/xmi/tutti-persistence.properties | 1 - .../src/main/xmi/tutti-persistence.zargo | Bin 65155 -> 59307 bytes .../BenthosBatchPersistenceServiceReadTest.java | 11 +- .../BenthosBatchPersistenceServiceWriteTest.java | 94 +- 27 files changed, 3669 insertions(+), 2325 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java index 4a06981..6d9d10b 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java @@ -32,8 +32,6 @@ import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.Cruises; @@ -42,7 +40,6 @@ import fr.ifremer.tutti.persistence.entities.data.FishingOperations; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.Program; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; @@ -461,17 +458,17 @@ public class TuttiPersistenceImpl implements TuttiPersistence { } @Override - public boolean isVracBatch(SpeciesAbleBatch speciesBatch) { + public boolean isVracBatch(SpeciesBatch speciesBatch) { return getCaracteristicService().isVracBatch(speciesBatch); } @Override - public Predicate<SpeciesAbleBatch> getVracBatchPredicate() { + public Predicate<SpeciesBatch> getVracBatchPredicate() { return getCaracteristicService().getVracBatchPredicate(); } @Override - public boolean isHorsVracBatch(SpeciesAbleBatch speciesBatch) { + public boolean isHorsVracBatch(SpeciesBatch speciesBatch) { return getCaracteristicService().isHorsVracBatch(speciesBatch); } @@ -1222,22 +1219,22 @@ public class TuttiPersistenceImpl implements TuttiPersistence { //------------------------------------------------------------------------// @Override - public BatchContainer<BenthosBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException { + public BatchContainer<SpeciesBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException { return getBenthosBatchService().getRootBenthosBatch(fishingOperationId, validateTree); } @Override - public BenthosBatch createBenthosBatch(BenthosBatch bean, Integer parentBatchId, boolean computeRankOrder) { + public SpeciesBatch createBenthosBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) { return getBenthosBatchService().createBenthosBatch(bean, parentBatchId, computeRankOrder); } @Override - public Collection<BenthosBatch> createBenthosBatches(Integer fishingOperationId, Collection<BenthosBatch> beans) { + public Collection<SpeciesBatch> createBenthosBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans) { return getBenthosBatchService().createBenthosBatches(fishingOperationId, beans); } @Override - public BenthosBatch saveBenthosBatch(BenthosBatch bean) { + public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) { return getBenthosBatchService().saveBenthosBatch(bean); } @@ -1257,23 +1254,23 @@ public class TuttiPersistenceImpl implements TuttiPersistence { } @Override - public List<BenthosBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { + public List<SpeciesBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { return getBenthosBatchService().getAllBenthosBatchToConfirm(fishingOperationId); } @Override - public List<BenthosBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) { + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) { return getBenthosBatchService().getAllBenthosBatchFrequency(benthosBatchId); } @Override - public Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer) { + public Multimap<Species, SpeciesBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) { return getBenthosBatchService().getAllBenthosBatchFrequencyForBatch(batchContainer); } @Override - public List<BenthosBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, - List<BenthosBatchFrequency> frequencies) { + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, + List<SpeciesBatchFrequency> frequencies) { return getBenthosBatchService().saveBenthosBatchFrequency(benthosBatchId, frequencies); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java index b703b50..c851073 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java @@ -29,15 +29,12 @@ import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.Program; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; @@ -335,17 +332,17 @@ public class TuttiPersistenceNoDbImpl implements TuttiPersistence { } @Override - public boolean isVracBatch(SpeciesAbleBatch speciesBatch) { + public boolean isVracBatch(SpeciesBatch speciesBatch) { throw notImplemented(); } @Override - public boolean isHorsVracBatch(SpeciesAbleBatch speciesBatch) { + public boolean isHorsVracBatch(SpeciesBatch speciesBatch) { throw notImplemented(); } @Override - public Predicate<SpeciesAbleBatch> getVracBatchPredicate() { + public Predicate<SpeciesBatch> getVracBatchPredicate() { throw notImplemented(); } @@ -746,22 +743,22 @@ public class TuttiPersistenceNoDbImpl implements TuttiPersistence { //------------------------------------------------------------------------// @Override - public BatchContainer<BenthosBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException { + public BatchContainer<SpeciesBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException { throw notImplemented(); } @Override - public BenthosBatch createBenthosBatch(BenthosBatch bean, Integer parentBatchId, boolean computeRankOrder) { + public SpeciesBatch createBenthosBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) { throw notImplemented(); } @Override - public Collection<BenthosBatch> createBenthosBatches(Integer fishingOperationId, Collection<BenthosBatch> beans) { + public Collection<SpeciesBatch> createBenthosBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans) { throw notImplemented(); } @Override - public BenthosBatch saveBenthosBatch(BenthosBatch bean) { + public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) { throw notImplemented(); } @@ -781,22 +778,22 @@ public class TuttiPersistenceNoDbImpl implements TuttiPersistence { } @Override - public List<BenthosBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { + public List<SpeciesBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { throw notImplemented(); } @Override - public List<BenthosBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) { + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) { throw notImplemented(); } @Override - public Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer) { + public Multimap<Species, SpeciesBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) { throw notImplemented(); } @Override - public List<BenthosBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, List<BenthosBatchFrequency> frequencies) { + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, List<SpeciesBatchFrequency> frequencies) { throw notImplemented(); } 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 deleted file mode 100644 index 2e3ca55..0000000 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java +++ /dev/null @@ -1,142 +0,0 @@ -package fr.ifremer.tutti.persistence.entities.data; - -/* - * #%L - * Tutti :: Persistence - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 - 2014 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Predicate; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.Species; - -import java.util.Collection; -import java.util.List; -import java.util.Set; - -/** - * Created on 8/26/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.7 - */ -public class SpeciesAbleBatchs { - - - public static Predicate<SpeciesAbleBatch> newSpeciesAbleBatchCategoryPredicate(Integer cateogryId, Integer value) { - return new SpeciesAbleBatchCategoryPredicate(cateogryId, value); - } - - public static <B extends SpeciesAbleBatch> B newInstance(B parent) { - - return (B) (parent instanceof SpeciesBatch ? SpeciesBatchs.newSpeciesBatch() : BenthosBatchs.newBenthosBatch()); - - } - - public static <B extends SpeciesAbleBatch> B createNewChild(B parent) { - - B child = newInstance(parent); - child.setFishingOperation(parent.getFishingOperation()); - child.setSpecies(parent.getSpecies()); - SpeciesAbleBatchs.setParentBatch(parent, child); - SpeciesAbleBatchs.addChildBatch(parent, child); - return child; - - } - - public static <B extends SpeciesAbleBatch> void setChildBatchs(B parent, List<B> childs) { - - if (parent instanceof SpeciesBatch) { - ((SpeciesBatch) parent).setChildBatchs((List<SpeciesBatch>) childs); - } else { - ((BenthosBatch) parent).setChildBatchs((List<BenthosBatch>) childs); - } - - } - - public static <B extends SpeciesAbleBatch> List<B> getChildBatchs(B batch) { - return (List<B>) batch.getChildBatchs(); - } - - - public static <B extends SpeciesAbleBatch> void setParentBatch(B parent, B child) { - - if (parent instanceof SpeciesBatch) { - ((SpeciesBatch) child).setParentBatch((SpeciesBatch) parent); - } else { - ((BenthosBatch) child).setParentBatch((BenthosBatch) parent); - } - - } - - public static <B extends SpeciesAbleBatch> void addChildBatch(B parent, B child) { - - if (child instanceof SpeciesBatch) { - ((SpeciesBatch) parent).addChildBatchs((SpeciesBatch) child); - } else { - ((BenthosBatch) parent).addChildBatchs((BenthosBatch) child); - } - - } - - public static <B extends SpeciesAbleBatch> void grabSpeciesChildBatchs(Collection<B> childs, Set<Species> speciesSet) { - - for (B child : childs) { - speciesSet.add(child.getSpecies()); - } - - } - - public static <B extends SpeciesAbleBatch> void grabSampleCategorieValuesChildBatchs(B batch, Set<Integer> categoryIds) { - - CaracteristicQualitativeValue sampleCategoryValue = (CaracteristicQualitativeValue) batch.getSampleCategoryValue(); - - categoryIds.add(sampleCategoryValue.getIdAsInt()); - if (!batch.isChildBatchsEmpty()) { - for (SpeciesAbleBatch child : batch.getChildBatchs()) { - grabSampleCategorieValuesChildBatchs(child, categoryIds); - } - } - - - } - - - public static class SpeciesAbleBatchCategoryPredicate implements Predicate<SpeciesAbleBatch> { - - private final Integer id; - - private final Integer qualitativeValue; - - public SpeciesAbleBatchCategoryPredicate(Integer id, Integer qualitativeValue) { - this.id = id; - this.qualitativeValue = qualitativeValue; - } - - @Override - public boolean apply(SpeciesAbleBatch input) { - return id.equals(input.getSampleCategoryId()) && - input.getSampleCategoryValue() instanceof CaracteristicQualitativeValue && - qualitativeValue.equals(((CaracteristicQualitativeValue) input.getSampleCategoryValue()).getIdAsInt()); - } - - } -} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesBatchFrequencys.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesBatchFrequencys.java new file mode 100644 index 0000000..34ab58a --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesBatchFrequencys.java @@ -0,0 +1,9 @@ +package fr.ifremer.tutti.persistence.entities.data; + +public class SpeciesBatchFrequencys extends AbstractSpeciesBatchFrequencys { + public static SpeciesBatchFrequency newBenthosBatchFrequency() { + SpeciesBatchFrequency speciesBatchFrequency = newSpeciesBatchFrequency(); + speciesBatchFrequency.setBenthosFrequencyBatch(true); + return speciesBatchFrequency; + } +} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesBatchs.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesBatchs.java index f051f0d..b6e8824 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesBatchs.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesBatchs.java @@ -25,9 +25,14 @@ package fr.ifremer.tutti.persistence.entities.data; */ import com.google.common.base.Function; +import com.google.common.base.Predicate; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.persistence.entities.referential.Species; import java.io.Serializable; +import java.util.Collection; import java.util.Map; +import java.util.Set; import java.util.TreeMap; /** @@ -37,6 +42,12 @@ public class SpeciesBatchs extends AbstractSpeciesBatchs { public static final Function<SpeciesBatch, Serializable> GET_SAMPLE_CATEGORY_VALUE = SpeciesBatch::getSampleCategoryValue; + public static SpeciesBatch newInstance(SpeciesBatch parent) { + SpeciesBatch speciesBatch = newSpeciesBatch(); + speciesBatch.setBenthosBatch(parent.isBenthosBatch()); + return speciesBatch; + } + public static Map<Integer, SpeciesBatch> getAllSpeciesBatchesById(BatchContainer<SpeciesBatch> rootSpeciesBatch) { Map<Integer, SpeciesBatch> result = new TreeMap<>(); @@ -55,4 +66,66 @@ public class SpeciesBatchs extends AbstractSpeciesBatchs { } } + public static Predicate<SpeciesBatch> newSpeciesAbleBatchCategoryPredicate(Integer cateogryId, Integer value) { + return new SpeciesAbleBatchCategoryPredicate(cateogryId, value); + } + + public static SpeciesBatch createNewChild(SpeciesBatch parent) { + + SpeciesBatch child = newInstance(parent); + child.setFishingOperation(parent.getFishingOperation()); + child.setSpecies(parent.getSpecies()); + child.setParentBatch(parent); + parent.addChildBatchs(child); + return child; + + } + + public static SpeciesBatch newBenthosBatch() { + SpeciesBatch speciesBatch = newSpeciesBatch(); + speciesBatch.setBenthosBatch(true); + return speciesBatch; + } + + public static void grabSpeciesChildBatchs(Collection<SpeciesBatch> childs, Set<Species> speciesSet) { + + for (SpeciesBatch child : childs) { + speciesSet.add(child.getSpecies()); + } + + } + + public static void grabSampleCategorieValuesChildBatchs(SpeciesBatch batch, Set<Integer> categoryIds) { + + CaracteristicQualitativeValue sampleCategoryValue = (CaracteristicQualitativeValue) batch.getSampleCategoryValue(); + + categoryIds.add(sampleCategoryValue.getIdAsInt()); + if (!batch.isChildBatchsEmpty()) { + for (SpeciesBatch child : batch.getChildBatchs()) { + grabSampleCategorieValuesChildBatchs(child, categoryIds); + } + } + + + } + + public static class SpeciesAbleBatchCategoryPredicate implements Predicate<SpeciesBatch> { + + private final Integer id; + + private final Integer qualitativeValue; + + public SpeciesAbleBatchCategoryPredicate(Integer id, Integer qualitativeValue) { + this.id = id; + this.qualitativeValue = qualitativeValue; + } + + @Override + public boolean apply(SpeciesBatch input) { + return id.equals(input.getSampleCategoryId()) && + input.getSampleCategoryValue() instanceof CaracteristicQualitativeValue && + qualitativeValue.equals(((CaracteristicQualitativeValue) input.getSampleCategoryValue()).getIdAsInt()); + } + + } } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCache.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCache.java index 042cf1b..e109c51 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCache.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCache.java @@ -25,7 +25,7 @@ package fr.ifremer.tutti.persistence.entities.referential; */ import fr.ifremer.tutti.persistence.TuttiPersistence; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import java.util.List; @@ -33,11 +33,11 @@ import java.util.Map; import java.util.TreeMap; /** -* Created on 2/17/15. -* -* @author Tony Chemit - chemit@codelutin.com -* @since 3.14 -*/ + * Created on 2/17/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14 + */ public class TaxonCache { protected final boolean loadVernacularCode; @@ -77,9 +77,9 @@ public class TaxonCache { } - public <A extends SpeciesAbleBatch> void loadInBatches(List<A> speciesAbleBatches) { + public void loadInBatches(List<SpeciesBatch> speciesAbleBatches) { - for (A speciesAbleBatch : speciesAbleBatches) { + for (SpeciesBatch speciesAbleBatch : speciesAbleBatches) { load(speciesAbleBatch.getSpecies()); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java index 617e7b5..93003b1 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java @@ -26,8 +26,8 @@ import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.InvalidBatchModelException; import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Species; import org.springframework.transaction.annotation.Transactional; @@ -35,7 +35,9 @@ import java.util.Collection; import java.util.List; /** - * Service to persist {@link BenthosBatch}. + * Service to persist {@link SpeciesBatch}. + * + * FIXME Merge it with speciesBatch. * * @author Tony Chemit - chemit@codelutin.com * @since 1.2 @@ -48,26 +50,26 @@ public interface BenthosBatchPersistenceService extends TuttiPersistenceServiceI //------------------------------------------------------------------------// /** - * Get all root {@link BenthosBatch} for the given fishing operation. + * Get all root {@link SpeciesBatch} for the given fishing operation. * * <strong>Note:</strong> All childs of the batch should be loaded here. * * @param fishingOperationId if of the fishing operation to seek * @param validateTree flag to validate sample category model - * @return the list of root {@link BenthosBatch} + * @return the list of root {@link SpeciesBatch} * @throws InvalidBatchModelException if batch does not respect the sample category model * @since 1.0 */ - BatchContainer<BenthosBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException; + BatchContainer<SpeciesBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException; @Transactional(readOnly = false) - BenthosBatch createBenthosBatch(BenthosBatch bean, Integer parentBatchId, boolean computeRankOrder); + SpeciesBatch createBenthosBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder); @Transactional(readOnly = false) - Collection<BenthosBatch> createBenthosBatches(Integer fishingOperationId, Collection<BenthosBatch> beans); + Collection<SpeciesBatch> createBenthosBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans); @Transactional(readOnly = false) - BenthosBatch saveBenthosBatch(BenthosBatch bean); + SpeciesBatch saveBenthosBatch(SpeciesBatch bean); @Transactional(readOnly = false) void deleteBenthosBatch(Integer id); @@ -78,7 +80,8 @@ public interface BenthosBatchPersistenceService extends TuttiPersistenceServiceI /** * Change the species in the given {@code batchId} and in all his * sub batches. - * @param batchId id of the root Benthos batch to treat + * + * @param batchId id of the root Benthos batch to treat * @param species species to affect to all batches */ @Transactional(readOnly = false) @@ -88,11 +91,11 @@ public interface BenthosBatchPersistenceService extends TuttiPersistenceServiceI * Get all the batches to confirm * * @param fishingOperationId if of the fishing operation to seek - * @return the list of {@link fr.ifremer.tutti.persistence.entities.data.BenthosBatch} to confirm + * @return the list of {@link fr.ifremer.tutti.persistence.entities.data.SpeciesBatch} to confirm * @throws InvalidBatchModelException if batch does not respect the sample category model * @since 3.13 */ - List<BenthosBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException; + List<SpeciesBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException; //------------------------------------------------------------------------// //-- BenthosBatchFrequency methods --// @@ -105,7 +108,7 @@ public interface BenthosBatchPersistenceService extends TuttiPersistenceServiceI * @return the list of frequencies for the given benthos batch id * @since 1.0 */ - List<BenthosBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId); + List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId); /** * Get all frequencies for the given root benthos batch container. @@ -114,21 +117,21 @@ public interface BenthosBatchPersistenceService extends TuttiPersistenceServiceI * @return the list of benthos frequencies indexed by their species * @since 3.3 */ - Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer); + Multimap<Species, SpeciesBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer); /** - * Save all given {@link BenthosBatchFrequency} into the given + * Save all given {@link SpeciesBatchFrequency} into the given * {@code benthosBatchId}. If some are not existing then creates them. * * <strong>Note:</strong> This will as a side effect remove all previous * frequency for this benthos batch. * - * @param benthosBatchId id of the {@link BenthosBatch} to use + * @param benthosBatchId id of the {@link SpeciesBatch} to use * @param frequencies list of frequencies to create or update * @return the persisted list of frequencies * @since 1.0 */ @Transactional(readOnly = false) - List<BenthosBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, - List<BenthosBatchFrequency> frequencies); + List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, + List<SpeciesBatchFrequency> frequencies); } 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 d497be6..0f1c1ce 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 @@ -22,45 +22,26 @@ package fr.ifremer.tutti.persistence.service; * #L% */ -import com.google.common.base.Preconditions; -import com.google.common.collect.ArrayListMultimap; -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.referential.taxon.ReferenceTaxon; import fr.ifremer.tutti.persistence.InvalidBatchModelException; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequencys; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchs; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequencys; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.service.referential.SpeciesPersistenceService; 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 org.apache.commons.collections4.CollectionUtils; +import fr.ifremer.tutti.persistence.service.util.tree.BenthosBatchTreeHelper; +import fr.ifremer.tutti.persistence.service.util.tree.SpeciesBatchTreeHelperSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; -import static org.nuiton.i18n.I18n.t; - /** * Default implementation of {@link BenthosBatchPersistenceService}. * @@ -68,370 +49,385 @@ import static org.nuiton.i18n.I18n.t; * @since 1.2 */ @Service("benthosBatchPersistenceService") -public class BenthosBatchPersistenceServiceImpl extends AbstractPersistenceService +public class BenthosBatchPersistenceServiceImpl extends SpeciesBatchPersistenceServiceSupport implements BenthosBatchPersistenceService { /** Logger. */ - private static final Log log = - LogFactory.getLog(BenthosBatchPersistenceServiceImpl.class); - - @Resource(name = "speciesPersistenceService") - private SpeciesPersistenceService speciesService; - - @Resource(name = "fishingOperationPersistenceService") - protected FishingOperationPersistenceService fishingOperationPersistenceService; - - @Resource(name = "batchPersistenceHelper") - protected BatchPersistenceHelper batchHelper; + private static final Log log = LogFactory.getLog(BenthosBatchPersistenceServiceImpl.class); - @Resource(name = "batchTreeHelper") - protected BatchTreeHelper batchTreeHelper; + @Resource(name = "benthosBatchTreeHelper") + protected BenthosBatchTreeHelper batchTreeHelper; - @Resource(name = "measurementPersistenceHelper") - protected MeasurementPersistenceHelper measurementPersistenceHelper; - - @Resource(name = "synchronizationStatusHelper") - protected SynchronizationStatusHelper synchronizationStatusHelper; + public BenthosBatchPersistenceServiceImpl() { + super("Benthos", SpeciesBatchs::newBenthosBatch, SpeciesBatchFrequencys::newBenthosBatchFrequency); + } //------------------------------------------------------------------------// //-- Benthos Batch methods --// //------------------------------------------------------------------------// @Override - public BatchContainer<BenthosBatch> getRootBenthosBatch(Integer fishingOperationId, - boolean validateTree) { - Preconditions.checkNotNull(fishingOperationId); - - DateFormat df = new SimpleDateFormat("dd/MM/yyy"); - - CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); - - // -- Vrac > Benthos > Alive Itemized - SortingBatch vracBenthosBatch = batchTreeHelper.getBenthosVracAliveItemizedRootBatch(catchBatch); - - SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); - - BatchContainer<BenthosBatch> result = new BatchContainer<>(); - if (vracBenthosBatch != null) { - result.setId(vracBenthosBatch.getId()); - - 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 = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); - if (species == null) { - FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); - String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); - throw new InvalidBatchModelException(t("tutti.persistence.benthosBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); - } - BenthosBatch target = BenthosBatchs.newBenthosBatch(); - target.setSpecies(species); - - batchHelper.entityToBean(sampleCategoryModel, source, target); - result.addChildren(target); - if (log.isDebugEnabled()) { - log.debug("Loaded CatchBatch Vrac > Benthos > Alive Itemized > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); - } - } - } - - // -- Hors Vrac > Benthos - SortingBatch horsVracBenthosBatch = batchTreeHelper.getBenthosHorsVracRootBatch(catchBatch); - - 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 = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); - if (species == null) { - FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); - String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); - throw new InvalidBatchModelException(t("tutti.persistence.benthosBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); - } - - BenthosBatch target = BenthosBatchs.newBenthosBatch(); - target.setSpecies(species); - - batchHelper.entityToBean(sampleCategoryModel, source, target); - result.addChildren(target); - if (log.isDebugEnabled()) { - log.debug("Loaded CatchBatch Hors Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); - } - } - } - - if (validateTree) { - - // validate with given sample category model - batchHelper.validateBenthos(sampleCategoryModel, result); - } - - return result; + protected SpeciesBatchTreeHelperSupport getBatchTreeHelper() { + return batchTreeHelper; } @Override - public BenthosBatch createBenthosBatch(BenthosBatch bean, Integer parentBatchId, boolean computeRankOrder) { - Preconditions.checkNotNull(bean); - Preconditions.checkArgument(TuttiEntities.isNew(bean)); - Preconditions.checkNotNull(bean.getSpecies()); - Preconditions.checkNotNull(bean.getSpecies().getId()); - Preconditions.checkNotNull(bean.getFishingOperation()); - Preconditions.checkNotNull(bean.getFishingOperation().getId()); - - CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(bean.getFishingOperation().getIdAsInt(), false); - - return createBenthosBatch(bean, parentBatchId, catchBatch, computeRankOrder); + protected void validate(BatchPersistenceHelper batchHelper, SampleCategoryModel sampleCategoryModel, BatchContainer<SpeciesBatch> result) { + batchHelper.validateBenthos(sampleCategoryModel, result); } @Override - public Collection<BenthosBatch> createBenthosBatches(Integer fishingOperationId, Collection<BenthosBatch> beans) { - - Preconditions.checkNotNull(beans); - Preconditions.checkNotNull(fishingOperationId); - - CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); - - Collection<BenthosBatch> result = new ArrayList<>(); - for (BenthosBatch bean : beans) { - - BenthosBatch created = createBenthosBatch(bean, null, catchBatch, true); - result.add(created); - - } - return result; - + public BatchContainer<SpeciesBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) { + + return getRootSpeciesBatch0(fishingOperationId, validateTree); + +// Preconditions.checkNotNull(fishingOperationId); +// +// DateFormat df = new SimpleDateFormat("dd/MM/yyy"); +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); +// +// // -- Vrac > Benthos > Alive Itemized +// SortingBatch vracBenthosBatch = batchTreeHelper.getBenthosVracAliveItemizedRootBatch(catchBatch); +// +// SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); +// +// BatchContainer<SpeciesBatch> result = new BatchContainer<>(); +// if (vracBenthosBatch != null) { +// result.setId(vracBenthosBatch.getId()); +// +// 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 = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); +// if (species == null) { +// FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); +// String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); +// throw new InvalidBatchModelException(t("tutti.persistence.benthosBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); +// } +// SpeciesBatch target = SpeciesBatchs.newBenthosBatch(); +// target.setSpecies(species); +// +// batchHelper.entityToBean(sampleCategoryModel, source, target); +// result.addChildren(target); +// if (log.isDebugEnabled()) { +// log.debug("Loaded CatchBatch Vrac > Benthos > Alive Itemized > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); +// } +// } +// } +// +// // -- Hors Vrac > Benthos +// SortingBatch horsVracBenthosBatch = batchTreeHelper.getBenthosHorsVracRootBatch(catchBatch); +// +// 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 = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); +// if (species == null) { +// FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); +// String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); +// throw new InvalidBatchModelException(t("tutti.persistence.benthosBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); +// } +// +// SpeciesBatch target = SpeciesBatchs.newBenthosBatch(); +// target.setSpecies(species); +// +// batchHelper.entityToBean(sampleCategoryModel, source, target); +// result.addChildren(target); +// if (log.isDebugEnabled()) { +// log.debug("Loaded CatchBatch Hors Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); +// } +// } +// } +// +// if (validateTree) { +// +// // validate with given sample category model +// batchHelper.validateBenthos(sampleCategoryModel, result); +// } +// +// return result; } - protected BenthosBatch createBenthosBatch(BenthosBatch bean, Integer parentBatchId, CatchBatch catchBatch, boolean computeRankOrder) { - - Preconditions.checkNotNull(bean); - Preconditions.checkArgument(TuttiEntities.isNew(bean)); - Preconditions.checkNotNull(bean.getSpecies()); - Preconditions.checkNotNull(bean.getSpecies().getId()); - Preconditions.checkNotNull(bean.getFishingOperation()); - Preconditions.checkNotNull(bean.getFishingOperation().getId()); + @Override + public SpeciesBatch createBenthosBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) { + + return createSpeciesBatch0(bean, parentBatchId, computeRankOrder); + +// Preconditions.checkNotNull(bean); +// Preconditions.checkArgument(TuttiEntities.isNew(bean)); +// Preconditions.checkNotNull(bean.getSpecies()); +// Preconditions.checkNotNull(bean.getSpecies().getId()); +// Preconditions.checkNotNull(bean.getFishingOperation()); +// Preconditions.checkNotNull(bean.getFishingOperation().getId()); +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(bean.getFishingOperation().getIdAsInt(), false); +// +// return createBenthosBatch(bean, parentBatchId, catchBatch, computeRankOrder); + } - SortingBatch batch = SortingBatch.Factory.newInstance(); - beanToEntity(bean, batch, parentBatchId, catchBatch, computeRankOrder); - bean = batchHelper.createSortingBatch(bean, catchBatch, batch); + @Override + public Collection<SpeciesBatch> createBenthosBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans) { + + return createSpeciesBatches0(fishingOperationId, beans); + +// Preconditions.checkNotNull(beans); +// Preconditions.checkNotNull(fishingOperationId); +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); +// +// Collection<SpeciesBatch> result = new ArrayList<>(); +// for (SpeciesBatch bean : beans) { +// +// SpeciesBatch created = createBenthosBatch(bean, null, catchBatch, true); +// result.add(created); +// +// } +// return result; - return bean; } +// protected SpeciesBatch createBenthosBatch(SpeciesBatch bean, Integer parentBatchId, CatchBatch catchBatch, boolean computeRankOrder) { +// +// Preconditions.checkNotNull(bean); +// Preconditions.checkArgument(TuttiEntities.isNew(bean)); +// Preconditions.checkNotNull(bean.getSpecies()); +// Preconditions.checkNotNull(bean.getSpecies().getId()); +// Preconditions.checkNotNull(bean.getFishingOperation()); +// Preconditions.checkNotNull(bean.getFishingOperation().getId()); +// +// SortingBatch batch = SortingBatch.Factory.newInstance(); +// beanToEntity(bean, batch, parentBatchId, catchBatch, computeRankOrder); +// bean = batchHelper.createSortingBatch(bean, catchBatch, batch); +// +// return bean; +// } + @Override - public BenthosBatch saveBenthosBatch(BenthosBatch bean) { - Preconditions.checkNotNull(bean); - Preconditions.checkNotNull(bean.getId()); - - Integer batchId = bean.getIdAsInt(); - CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(batchId); - SortingBatch batch = batchHelper.getSortingBatchById(catchBatch, batchId); - - Integer parentBatchId = null; - if (bean.getParentBatch() != null) { - parentBatchId = bean.getParentBatch().getIdAsInt(); - } - beanToEntity(bean, batch, parentBatchId, catchBatch, true); - batchHelper.updateSortingBatch(batch, catchBatch); - - return bean; + public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) { + + return saveSpeciesBatch0(bean); + +// Preconditions.checkNotNull(bean); +// Preconditions.checkNotNull(bean.getId()); +// +// Integer batchId = bean.getIdAsInt(); +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(batchId); +// SortingBatch batch = batchHelper.getSortingBatchById(catchBatch, batchId); +// +// Integer parentBatchId = null; +// if (bean.getParentBatch() != null) { +// parentBatchId = bean.getParentBatch().getIdAsInt(); +// } +// beanToEntity(bean, batch, parentBatchId, catchBatch, true); +// batchHelper.updateSortingBatch(batch, catchBatch); +// +// return bean; } @Override public void deleteBenthosBatch(Integer id) { - Preconditions.checkNotNull(id); - batchHelper.deleteBatch(id); + deleteSpeciesBatch0(id); +// Preconditions.checkNotNull(id); +// batchHelper.deleteBatch(id); } @Override public void deleteBenthosSubBatch(Integer id) { - Preconditions.checkNotNull(id); - batchHelper.deleteSpeciesSubBatch(id); + deleteSpeciesSubBatch0(id); +// Preconditions.checkNotNull(id); +// batchHelper.deleteSpeciesSubBatch(id); } @Override public void changeBenthosBatchSpecies(Integer id, Species species) { - Preconditions.checkNotNull(id); - Preconditions.checkNotNull(species); - Preconditions.checkNotNull(species.getReferenceTaxonId()); - batchHelper.changeBatchSpecies(id, species); + changeSpeciesBatchSpecies0(id, species); +// Preconditions.checkNotNull(id); +// Preconditions.checkNotNull(species); +// Preconditions.checkNotNull(species.getReferenceTaxonId()); +// batchHelper.changeBatchSpecies(id, species); } @Override - public List<BenthosBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { - List<BenthosBatch> batchesToConfirm = new ArrayList<>(); - - BatchContainer<BenthosBatch> rootBenthosBatch = getRootBenthosBatch(fishingOperationId, false); - for (BenthosBatch benthosBatch : rootBenthosBatch.getChildren()) { - findBenthosBatchesToConfirm(benthosBatch, batchesToConfirm); - } - - return batchesToConfirm; + public List<SpeciesBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { + return getAllSpeciesBatchToConfirm0(fishingOperationId); +// List<SpeciesBatch> batchesToConfirm = new ArrayList<>(); +// +// BatchContainer<SpeciesBatch> rootBenthosBatch = getRootBenthosBatch(fishingOperationId, false); +// for (SpeciesBatch benthosBatch : rootBenthosBatch.getChildren()) { +// findBenthosBatchesToConfirm(benthosBatch, batchesToConfirm); +// } +// +// return batchesToConfirm; } - protected void findBenthosBatchesToConfirm(BenthosBatch benthosBatch, List<BenthosBatch> batchesToConfirm) { - if (benthosBatch.isSpeciesToConfirm()) { - batchesToConfirm.add(benthosBatch); - - } else if (!benthosBatch.isChildBatchsEmpty()) { - for (BenthosBatch batch : benthosBatch.getChildBatchs()) { - findBenthosBatchesToConfirm(batch, batchesToConfirm); - } - } - } +// protected void findBenthosBatchesToConfirm(SpeciesBatch benthosBatch, List<SpeciesBatch> batchesToConfirm) { +// if (benthosBatch.isSpeciesToConfirm()) { +// batchesToConfirm.add(benthosBatch); +// +// } else if (!benthosBatch.isChildBatchsEmpty()) { +// for (SpeciesBatch batch : benthosBatch.getChildBatchs()) { +// findBenthosBatchesToConfirm(batch, batchesToConfirm); +// } +// } +// } //------------------------------------------------------------------------// - //-- BenthosBatchFrequency methods (for benthos) --// + //-- SpeciesBatchFrequency methods (for benthos) --// //------------------------------------------------------------------------// @Override - public List<BenthosBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) { - Preconditions.checkNotNull(benthosBatchId); - - List<SortingBatch> frequencyChilds = batchHelper.getFrequencies( - benthosBatchId); - List<BenthosBatchFrequency> results = Lists.newArrayList(); - for (SortingBatch child : frequencyChilds) { - BenthosBatchFrequency target = BenthosBatchFrequencys.newBenthosBatchFrequency(); - - batchHelper.entityToBatchFrequency(child, target); - results.add(target); - } - return Collections.unmodifiableList(results); + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) { + return getAllSpeciesBatchFrequency0(benthosBatchId); +// Preconditions.checkNotNull(benthosBatchId); +// +// List<SortingBatch> frequencyChilds = batchHelper.getFrequencies( +// benthosBatchId); +// List<SpeciesBatchFrequency> results = Lists.newArrayList(); +// for (SortingBatch child : frequencyChilds) { +// SpeciesBatchFrequency target = SpeciesBatchFrequencys.newBenthosBatchFrequency(); +// +// batchHelper.entityToBatchFrequency(child, target); +// results.add(target); +// } +// return Collections.unmodifiableList(results); } @Override - public Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer) { - Multimap<Species, BenthosBatchFrequency> result = ArrayListMultimap.create(); - for (BenthosBatch speciesBatch : batchContainer.getChildren()) { - getAllSpeciesBatchFrequencyForBatch(speciesBatch, result); - } - return result; + public Multimap<Species, SpeciesBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) { + return getAllSpeciesBatchFrequencyForBatch0(batchContainer); +// Multimap<Species, SpeciesBatchFrequency> result = ArrayListMultimap.create(); +// for (SpeciesBatch speciesBatch : batchContainer.getChildren()) { +// getAllSpeciesBatchFrequencyForBatch(speciesBatch, result); +// } +// return result; } - protected void getAllSpeciesBatchFrequencyForBatch(BenthosBatch batch, - Multimap<Species, BenthosBatchFrequency> result) { - - List<BenthosBatchFrequency> speciesBatchFrequency = getAllBenthosBatchFrequency(batch.getIdAsInt()); - result.putAll(batch.getSpecies(), speciesBatchFrequency); - - if (!batch.isChildBatchsEmpty()) { - for (BenthosBatch child : batch.getChildBatchs()) { - getAllSpeciesBatchFrequencyForBatch(child, result); - } - } - } +// protected void getAllSpeciesBatchFrequencyForBatch(SpeciesBatch batch, +// Multimap<Species, SpeciesBatchFrequency> result) { +// +// List<SpeciesBatchFrequency> speciesBatchFrequency = getAllBenthosBatchFrequency(batch.getIdAsInt()); +// result.putAll(batch.getSpecies(), speciesBatchFrequency); +// +// if (!batch.isChildBatchsEmpty()) { +// for (SpeciesBatch child : batch.getChildBatchs()) { +// getAllSpeciesBatchFrequencyForBatch(child, result); +// } +// } +// } @Override - public List<BenthosBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, - List<BenthosBatchFrequency> frequencies) { - Preconditions.checkNotNull(benthosBatchId); - Preconditions.checkNotNull(frequencies); - - // Check that all frequencies have the same length PMFM (before doing any db call) - String pmfmId = null; - for (BenthosBatchFrequency source : frequencies) { - - if (pmfmId == null) { - pmfmId = source.getLengthStepCaracteristic().getId(); - } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { - throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); - } - } - - CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(benthosBatchId); - - if (catchBatch == null) { - return frequencies; - } - - // Synchronization status - synchronizationStatusHelper.setDirty(catchBatch); - - // Retrieve parent - SortingBatch parentBatch = batchHelper.getSortingBatchById(catchBatch, benthosBatchId); - - // Remember child ids, to remove unchanged item (see at bottom in this method) - List<Integer> notUpdatedChildIds = Lists.newArrayList(); - List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds( - parentBatch); - for (SortingBatch child : frequencyChilds) { - notUpdatedChildIds.add(child.getId()); - } - - short rankOrder = 0; - List<SortingBatch> batchsToUpdate = Lists.newArrayList(); - for (BenthosBatchFrequency source : frequencies) { - rankOrder++; - - // Not existing batch - SortingBatch target; - if (source.getId() == null) { - target = SortingBatch.Factory.newInstance(); - - // Fill the sorting batch from the source - batchHelper.beanToEntity(source, target, parentBatch, rankOrder); - - // Create the targeted batch, then update the source id - batchHelper.createSortingBatch(source, catchBatch, target); - } - - // Existing batch - else { - target = batchHelper.getSortingBatchById(catchBatch, source.getIdAsInt()); - - // Fill the sorting batch from the source - batchHelper.beanToEntity(source, target, parentBatch, rankOrder); - - // Add the batch into a list (will be update later, using this list) - batchsToUpdate.add(target); - - notUpdatedChildIds.remove(target.getId()); - } - } - - // If some batchs need to be update, do it - if (CollectionUtils.isNotEmpty(batchsToUpdate)) { - batchHelper.updateSortingBatch(batchsToUpdate, catchBatch); - } - - if (CollectionUtils.isNotEmpty(notUpdatedChildIds)) { - for (Integer batchId : notUpdatedChildIds) { - batchHelper.removeWithChildren(batchId, catchBatch); - } - } - - return Collections.unmodifiableList(frequencies); + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, + List<SpeciesBatchFrequency> frequencies) { + return saveSpeciesBatchFrequency0(benthosBatchId, frequencies); +// Preconditions.checkNotNull(benthosBatchId); +// Preconditions.checkNotNull(frequencies); +// +// // Check that all frequencies have the same length PMFM (before doing any db call) +// String pmfmId = null; +// for (SpeciesBatchFrequency source : frequencies) { +// +// if (pmfmId == null) { +// pmfmId = source.getLengthStepCaracteristic().getId(); +// } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { +// throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); +// } +// } +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(benthosBatchId); +// +// if (catchBatch == null) { +// return frequencies; +// } +// +// // Synchronization status +// synchronizationStatusHelper.setDirty(catchBatch); +// +// // Retrieve parent +// SortingBatch parentBatch = batchHelper.getSortingBatchById(catchBatch, benthosBatchId); +// +// // Remember child ids, to remove unchanged item (see at bottom in this method) +// List<Integer> notUpdatedChildIds = Lists.newArrayList(); +// List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds( +// parentBatch); +// for (SortingBatch child : frequencyChilds) { +// notUpdatedChildIds.add(child.getId()); +// } +// +// short rankOrder = 0; +// List<SortingBatch> batchsToUpdate = Lists.newArrayList(); +// for (SpeciesBatchFrequency source : frequencies) { +// rankOrder++; +// +// // Not existing batch +// SortingBatch target; +// if (source.getId() == null) { +// target = SortingBatch.Factory.newInstance(); +// +// // Fill the sorting batch from the source +// batchHelper.beanToEntity(source, target, parentBatch, rankOrder); +// +// // Create the targeted batch, then update the source id +// batchHelper.createSortingBatch(source, catchBatch, target); +// } +// +// // Existing batch +// else { +// target = batchHelper.getSortingBatchById(catchBatch, source.getIdAsInt()); +// +// // Fill the sorting batch from the source +// batchHelper.beanToEntity(source, target, parentBatch, rankOrder); +// +// // Add the batch into a list (will be update later, using this list) +// batchsToUpdate.add(target); +// +// notUpdatedChildIds.remove(target.getId()); +// } +// } +// +// // If some batchs need to be update, do it +// if (CollectionUtils.isNotEmpty(batchsToUpdate)) { +// batchHelper.updateSortingBatch(batchsToUpdate, catchBatch); +// } +// +// if (CollectionUtils.isNotEmpty(notUpdatedChildIds)) { +// for (Integer batchId : notUpdatedChildIds) { +// batchHelper.removeWithChildren(batchId, catchBatch); +// } +// } +// +// return Collections.unmodifiableList(frequencies); } //------------------------------------------------------------------------// //-- Internal methods --// //------------------------------------------------------------------------// - protected void beanToEntity(BenthosBatch source, - SortingBatch target, - Integer parentBatchId, - CatchBatch catchBatch, - boolean computeRankOrder) { - - Preconditions.checkNotNull(source.getFishingOperation()); - Preconditions.checkNotNull(source.getFishingOperation().getId()); - - // If parent and root need to be set - if (target.getId() == null - || target.getRootBatch() == null - || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatchId))) { - batchHelper.setBenthosBatchParents( - source.getSampleCategoryId(), - source.getSampleCategoryValue(), - target, - parentBatchId, - catchBatch); - } - - batchHelper.beanToEntity(parentBatchId, source, target, computeRankOrder); - } +// protected void beanToEntity(SpeciesBatch source, +// SortingBatch target, +// Integer parentBatchId, +// CatchBatch catchBatch, +// boolean computeRankOrder) { +// +// Preconditions.checkNotNull(source.getFishingOperation()); +// Preconditions.checkNotNull(source.getFishingOperation().getId()); +// +// // If parent and root need to be set +// if (target.getId() == null +// || target.getRootBatch() == null +// || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatchId))) { +// batchHelper.setBenthosBatchParents( +// source.getSampleCategoryId(), +// source.getSampleCategoryValue(), +// target, +// parentBatchId, +// catchBatch); +// } +// +// batchHelper.beanToEntity(parentBatchId, source, target, computeRankOrder); +// } } 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 b50f139..b1c9682 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 @@ -36,7 +36,7 @@ import fr.ifremer.tutti.TuttiConfiguration; 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.tree.BatchTreeHelper; import fr.ifremer.tutti.persistence.service.util.MeasurementPersistenceHelper; import fr.ifremer.tutti.persistence.service.util.SynchronizationStatusHelper; import fr.ifremer.tutti.util.Numbers; diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java index df26d89..71198f2 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java @@ -39,7 +39,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.service.referential.CaracteristicPersistenceService; import fr.ifremer.tutti.persistence.service.util.BatchPersistenceHelper; -import fr.ifremer.tutti.persistence.service.util.BatchTreeHelper; +import fr.ifremer.tutti.persistence.service.util.tree.BatchTreeHelper; import fr.ifremer.tutti.persistence.service.util.MeasurementPersistenceHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -235,7 +235,7 @@ public class MarineLitterBatchPersistenceServiceImpl extends AbstractPersistence // If parent and root need to be set if (target.getId() == null || target.getRootBatch() == null) { - batchHelper.setMarineLitterBatchParents(target, catchBatch); + setMarineLitterBatchParents(target, catchBatch); } // RankOrder (initialize once, at creation) @@ -302,4 +302,24 @@ public class MarineLitterBatchPersistenceServiceImpl extends AbstractPersistence target.setExhaustiveInventory(true); } + + private void setMarineLitterBatchParents(SortingBatch target, CatchBatch catchBatch) { + + Preconditions.checkNotNull(target); + + // -- Hors Vrac > Marine Litter + SortingBatch parentBatch = batchTreeHelper.getMarineLitterRootBatch(catchBatch); + + if (parentBatch == null) { + + // -- Hors Vrac + SortingBatch horsVracBatch = batchTreeHelper.getOrCreateHorsVracBatch(catchBatch); + + // -- Hors Vrac > Marine Litter + parentBatch = batchTreeHelper.getOrCreateMarineLitterRootBatch(catchBatch, horsVracBatch, null); + } + + target.setParentBatch(parentBatch); + target.setRootBatch(catchBatch); + } } 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 b4d763e..e84841e 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 @@ -22,45 +22,26 @@ package fr.ifremer.tutti.persistence.service; * #L% */ -import com.google.common.base.Preconditions; -import com.google.common.collect.ArrayListMultimap; -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.referential.taxon.ReferenceTaxon; import fr.ifremer.tutti.persistence.InvalidBatchModelException; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequencys; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.service.referential.SpeciesPersistenceService; 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 org.apache.commons.collections4.CollectionUtils; +import fr.ifremer.tutti.persistence.service.util.tree.SpeciesBatchTreeHelper; +import fr.ifremer.tutti.persistence.service.util.tree.SpeciesBatchTreeHelperSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; - -import static org.nuiton.i18n.I18n.t; /** * Default implementation of {@link SpeciesBatchPersistenceService}. @@ -69,408 +50,419 @@ import static org.nuiton.i18n.I18n.t; * @since 1.2 */ @Service("speciesBatchPersistenceService") -public class SpeciesBatchPersistenceServiceImpl extends AbstractPersistenceService +public class SpeciesBatchPersistenceServiceImpl extends SpeciesBatchPersistenceServiceSupport implements SpeciesBatchPersistenceService { /** Logger. */ private static final Log log = LogFactory.getLog(SpeciesBatchPersistenceServiceImpl.class); - @Resource(name = "speciesPersistenceService") - private SpeciesPersistenceService speciesService; - - @Resource(name = "fishingOperationPersistenceService") - protected FishingOperationPersistenceService fishingOperationPersistenceService; - - @Resource(name = "batchPersistenceHelper") - protected BatchPersistenceHelper batchHelper; - - @Resource(name = "batchTreeHelper") - protected BatchTreeHelper batchTreeHelper; + @Resource(name = "speciesBatchTreeHelper") + protected SpeciesBatchTreeHelper batchTreeHelper; - @Resource(name = "measurementPersistenceHelper") - protected MeasurementPersistenceHelper measurementPersistenceHelper; - - @Resource(name = "synchronizationStatusHelper") - protected SynchronizationStatusHelper synchronizationStatusHelper; + public SpeciesBatchPersistenceServiceImpl() { + super("Species", SpeciesBatchs::newSpeciesBatch, SpeciesBatchFrequencys::newSpeciesBatchFrequency); + } //------------------------------------------------------------------------// //-- SpeciesBatch methods --// //------------------------------------------------------------------------// @Override - public BatchContainer<SpeciesBatch> getRootSpeciesBatch(Integer fishingOperationId, - boolean validateTree) throws InvalidBatchModelException { - Preconditions.checkNotNull(fishingOperationId); - - DateFormat df = new SimpleDateFormat("dd/MM/yyy"); - - CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); - - // -- Vrac > Species > Alive Itemized - SortingBatch vracSpeciesBatch = batchTreeHelper.getSpeciesVracAliveItemizedRootBatch(catchBatch); - - // container of speciesBatch is arbitraty put on vrac type (there is - // no common ancestor for all species batch). - BatchContainer<SpeciesBatch> result = new BatchContainer<>(); - - SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); - - if (vracSpeciesBatch != null) { - - result.setId(vracSpeciesBatch.getId()); - - 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()); - if (log.isTraceEnabled()) { - log.trace("Loading CatchBatch Vrac > Species > Alive Itemized > " + referenceTaxon.getId() + " - " + " (batch:" + source.getId() + ")"); - } - Species species = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); - if (species == null) { - FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); - String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); - throw new InvalidBatchModelException(t("tutti.persistence.speciesBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); - } - SpeciesBatch target = SpeciesBatchs.newSpeciesBatch(); - target.setSpecies(species); - - batchHelper.entityToBean(sampleCategoryModel, source, target); - result.addChildren(target); - - if (log.isDebugEnabled()) { - log.debug("Loaded CatchBatch Vrac > Species > Alive Itemized > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); - } - } - } - - // -- Hors Vrac > Species - SortingBatch horsVracSpeciesBatch = batchTreeHelper.getSpeciesHorsVracRootBatch(catchBatch); - - 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()); - if (log.isTraceEnabled()) { - log.trace("Loading CatchBatch Hors Vrac > Species > " + referenceTaxon.getId() + " - " + " (batch:" + source.getId() + ")"); - } - Species species = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); - if (species == null) { - FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); - String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); - throw new InvalidBatchModelException(t("tutti.persistence.speciesBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); - } - SpeciesBatch target = SpeciesBatchs.newSpeciesBatch(); - target.setSpecies(species); - batchHelper.entityToBean(sampleCategoryModel, source, target); - result.addChildren(target); - if (log.isDebugEnabled()) { - log.debug("Loaded CatchBatch Hors Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); - } - } - } - - if (validateTree) { - - // validate with given sample category model - batchHelper.validateSpecies(sampleCategoryModel, result); - } - - return result; + protected SpeciesBatchTreeHelperSupport getBatchTreeHelper() { + return batchTreeHelper; } @Override - public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) { - Preconditions.checkNotNull(bean); - Preconditions.checkArgument(TuttiEntities.isNew(bean)); - Preconditions.checkNotNull(bean.getSpecies()); - Preconditions.checkNotNull(bean.getSpecies().getId()); - Preconditions.checkNotNull(bean.getFishingOperation()); - Preconditions.checkNotNull(bean.getFishingOperation().getId()); - - CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(bean.getFishingOperation().getIdAsInt(), false); - - return createSpeciesBatch(bean, parentBatchId, catchBatch, computeRankOrder); + protected void validate(BatchPersistenceHelper batchHelper, SampleCategoryModel sampleCategoryModel, BatchContainer<SpeciesBatch> result) { + batchHelper.validateSpecies(sampleCategoryModel, result); } @Override - public Collection<SpeciesBatch> createSpeciesBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans) { - - Preconditions.checkNotNull(beans); - Preconditions.checkNotNull(fishingOperationId); + public BatchContainer<SpeciesBatch> getRootSpeciesBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException { + + return getRootSpeciesBatch0(fishingOperationId, validateTree); +// +// Preconditions.checkNotNull(fishingOperationId); +// +// DateFormat df = new SimpleDateFormat("dd/MM/yyy"); +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); +// +// // -- Vrac > Species > Alive Itemized +// SortingBatch vracSpeciesBatch = batchTreeHelper.getSpeciesVracAliveItemizedRootBatch(catchBatch); +// +// // container of speciesBatch is arbitraty put on vrac type (there is +// // no common ancestor for all species batch). +// BatchContainer<SpeciesBatch> result = new BatchContainer<>(); +// +// SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); +// +// if (vracSpeciesBatch != null) { +// +// result.setId(vracSpeciesBatch.getId()); +// +// 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()); +// if (log.isTraceEnabled()) { +// log.trace("Loading CatchBatch Vrac > Species > Alive Itemized > " + referenceTaxon.getId() + " - " + " (batch:" + source.getId() + ")"); +// } +// Species species = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); +// if (species == null) { +// FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); +// String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); +// throw new InvalidBatchModelException(t("tutti.persistence.speciesBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); +// } +// SpeciesBatch target = SpeciesBatchs.newSpeciesBatch(); +// target.setSpecies(species); +// +// batchHelper.entityToBean(sampleCategoryModel, source, target); +// result.addChildren(target); +// +// if (log.isDebugEnabled()) { +// log.debug("Loaded CatchBatch Vrac > Species > Alive Itemized > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); +// } +// } +// } +// +// // -- Hors Vrac > Species +// SortingBatch horsVracSpeciesBatch = batchTreeHelper.getSpeciesHorsVracRootBatch(catchBatch); +// +// 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()); +// if (log.isTraceEnabled()) { +// log.trace("Loading CatchBatch Hors Vrac > Species > " + referenceTaxon.getId() + " - " + " (batch:" + source.getId() + ")"); +// } +// Species species = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); +// if (species == null) { +// FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); +// String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); +// throw new InvalidBatchModelException(t("tutti.persistence.speciesBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); +// } +// SpeciesBatch target = SpeciesBatchs.newSpeciesBatch(); +// target.setSpecies(species); +// batchHelper.entityToBean(sampleCategoryModel, source, target); +// result.addChildren(target); +// if (log.isDebugEnabled()) { +// log.debug("Loaded CatchBatch Hors Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); +// } +// } +// } +// +// if (validateTree) { +// +// // validate with given sample category model +// batchHelper.validateSpecies(sampleCategoryModel, result); +// } +// +// return result; + } - CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); + @Override + public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) { - Collection<SpeciesBatch> result = new ArrayList<>(); - for (SpeciesBatch bean : beans) { + return createSpeciesBatch0(bean, parentBatchId, computeRankOrder); + +// Preconditions.checkNotNull(bean); +// Preconditions.checkArgument(TuttiEntities.isNew(bean)); +// Preconditions.checkNotNull(bean.getSpecies()); +// Preconditions.checkNotNull(bean.getSpecies().getId()); +// Preconditions.checkNotNull(bean.getFishingOperation()); +// Preconditions.checkNotNull(bean.getFishingOperation().getId()); +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(bean.getFishingOperation().getIdAsInt(), false); +// +// return createSpeciesBatch(bean, parentBatchId, catchBatch, computeRankOrder); + } - SpeciesBatch created = createSpeciesBatch(bean, null, catchBatch, true); - result.add(created); + @Override + public Collection<SpeciesBatch> createSpeciesBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans) { - } - return result; + return createSpeciesBatches0(fishingOperationId, beans); + +// Preconditions.checkNotNull(beans); +// Preconditions.checkNotNull(fishingOperationId); +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); +// +// Collection<SpeciesBatch> result = new ArrayList<>(); +// for (SpeciesBatch bean : beans) { +// +// SpeciesBatch created = createSpeciesBatch(bean, null, catchBatch, true); +// result.add(created); +// +// } +// return result; } protected SpeciesBatch createSpeciesBatch(SpeciesBatch bean, Integer parentBatchId, CatchBatch catchBatch, boolean computeRankOrder) { - - Preconditions.checkNotNull(bean); - Preconditions.checkArgument(TuttiEntities.isNew(bean)); - Preconditions.checkNotNull(bean.getSpecies()); - Preconditions.checkNotNull(bean.getSpecies().getId()); - Preconditions.checkNotNull(bean.getFishingOperation()); - Preconditions.checkNotNull(bean.getFishingOperation().getId()); - - SortingBatch batch = SortingBatch.Factory.newInstance(); - beanToEntity(bean, batch, parentBatchId, catchBatch, computeRankOrder); - bean = batchHelper.createSortingBatch(bean, catchBatch, batch); - - return bean; + return createSpeciesBatch0(bean, parentBatchId, catchBatch, computeRankOrder); +// Preconditions.checkNotNull(bean); +// Preconditions.checkArgument(TuttiEntities.isNew(bean)); +// Preconditions.checkNotNull(bean.getSpecies()); +// Preconditions.checkNotNull(bean.getSpecies().getId()); +// Preconditions.checkNotNull(bean.getFishingOperation()); +// Preconditions.checkNotNull(bean.getFishingOperation().getId()); +// +// SortingBatch batch = SortingBatch.Factory.newInstance(); +// beanToEntity(bean, batch, parentBatchId, catchBatch, computeRankOrder); +// bean = batchHelper.createSortingBatch(bean, catchBatch, batch); +// +// return bean; } @Override public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) { - Preconditions.checkNotNull(bean); - Preconditions.checkArgument(!TuttiEntities.isNew(bean)); - - Integer batchId = bean.getIdAsInt(); - - CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(batchId); - SortingBatch batch = batchHelper.getSortingBatchById(catchBatch, batchId); - Integer parentBatchId = null; - if (bean.getParentBatch() != null) { - parentBatchId = bean.getParentBatch().getIdAsInt(); - } - beanToEntity(bean, batch, parentBatchId, catchBatch, true); - batchHelper.updateSortingBatch(batch, catchBatch); - - return bean; + return saveSpeciesBatch0(bean); +// Preconditions.checkNotNull(bean); +// Preconditions.checkArgument(!TuttiEntities.isNew(bean)); +// +// Integer batchId = bean.getIdAsInt(); +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(batchId); +// SortingBatch batch = batchHelper.getSortingBatchById(catchBatch, batchId); +// Integer parentBatchId = null; +// if (bean.getParentBatch() != null) { +// parentBatchId = bean.getParentBatch().getIdAsInt(); +// } +// beanToEntity(bean, batch, parentBatchId, catchBatch, true); +// batchHelper.updateSortingBatch(batch, catchBatch); +// +// return bean; } @Override public void deleteSpeciesBatch(Integer id) { - Preconditions.checkNotNull(id); - batchHelper.deleteBatch(id); + deleteSpeciesBatch0(id); +// Preconditions.checkNotNull(id); +// batchHelper.deleteBatch(id); } @Override public void deleteSpeciesSubBatch(Integer id) { - Preconditions.checkNotNull(id); - batchHelper.deleteSpeciesSubBatch(id); + deleteSpeciesSubBatch0(id); +// Preconditions.checkNotNull(id); +// batchHelper.deleteSpeciesSubBatch(id); } @Override public void changeSpeciesBatchSpecies(Integer id, Species species) { - Preconditions.checkNotNull(id); - Preconditions.checkNotNull(species); - Preconditions.checkNotNull(species.getReferenceTaxonId()); - batchHelper.changeBatchSpecies(id, species); + changeSpeciesBatchSpecies0(id, species); +// Preconditions.checkNotNull(id); +// Preconditions.checkNotNull(species); +// Preconditions.checkNotNull(species.getReferenceTaxonId()); +// batchHelper.changeBatchSpecies(id, species); } @Override public List<SpeciesBatch> getAllSpeciesBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { - List<SpeciesBatch> batchesToConfirm = new ArrayList<>(); - - BatchContainer<SpeciesBatch> rootSpeciesBatch = getRootSpeciesBatch(fishingOperationId, false); - for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { - findSpeciesBatchesToConfirm(speciesBatch, batchesToConfirm); - } - - return batchesToConfirm; + return getAllSpeciesBatchToConfirm0(fishingOperationId); +// List<SpeciesBatch> batchesToConfirm = new ArrayList<>(); +// +// BatchContainer<SpeciesBatch> rootSpeciesBatch = getRootSpeciesBatch(fishingOperationId, false); +// for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { +// findSpeciesBatchesToConfirm(speciesBatch, batchesToConfirm); +// } +// +// return batchesToConfirm; } - protected void findSpeciesBatchesToConfirm(SpeciesBatch speciesBatch, List<SpeciesBatch> batchesToConfirm) { - if (speciesBatch.isSpeciesToConfirm()) { - batchesToConfirm.add(speciesBatch); - - } else if (!speciesBatch.isChildBatchsEmpty()) { - for (SpeciesBatch batch : speciesBatch.getChildBatchs()) { - findSpeciesBatchesToConfirm(batch, batchesToConfirm); - } - } - } +// protected void findSpeciesBatchesToConfirm(SpeciesBatch speciesBatch, List<SpeciesBatch> batchesToConfirm) { +// if (speciesBatch.isSpeciesToConfirm()) { +// batchesToConfirm.add(speciesBatch); +// +// } else if (!speciesBatch.isChildBatchsEmpty()) { +// for (SpeciesBatch batch : speciesBatch.getChildBatchs()) { +// findSpeciesBatchesToConfirm(batch, batchesToConfirm); +// } +// } +// } //------------------------------------------------------------------------// //-- SpeciesBatchFrequency methods --// //------------------------------------------------------------------------// @Override - public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency( - Integer speciesBatchId) { - Preconditions.checkNotNull(speciesBatchId); - - List<SortingBatch> frequencyChilds = - batchHelper.getFrequencies(speciesBatchId); - List<SpeciesBatchFrequency> results = Lists.newArrayList(); - for (SortingBatch child : frequencyChilds) { - SpeciesBatchFrequency target = - SpeciesBatchFrequencys.newSpeciesBatchFrequency(); - - batchHelper.entityToBatchFrequency(child, target); - results.add(target); - } - return Collections.unmodifiableList(results); + public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(Integer speciesBatchId) { + return getAllSpeciesBatchFrequency0(speciesBatchId); +// Preconditions.checkNotNull(speciesBatchId); +// +// List<SortingBatch> frequencyChilds = +// batchHelper.getFrequencies(speciesBatchId); +// List<SpeciesBatchFrequency> results = Lists.newArrayList(); +// for (SortingBatch child : frequencyChilds) { +// SpeciesBatchFrequency target = +// SpeciesBatchFrequencys.newSpeciesBatchFrequency(); +// +// batchHelper.entityToBatchFrequency(child, target); +// results.add(target); +// } +// return Collections.unmodifiableList(results); } @Override public Multimap<Species, SpeciesBatchFrequency> getAllSpeciesBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) { - Multimap<Species, SpeciesBatchFrequency> result = ArrayListMultimap.create(); - for (SpeciesBatch speciesBatch : batchContainer.getChildren()) { - getAllSpeciesBatchFrequencyForBatch(speciesBatch, result); - } - return result; + return getAllSpeciesBatchFrequencyForBatch0(batchContainer); +// Multimap<Species, SpeciesBatchFrequency> result = ArrayListMultimap.create(); +// for (SpeciesBatch speciesBatch : batchContainer.getChildren()) { +// getAllSpeciesBatchFrequencyForBatch(speciesBatch, result); +// } +// return result; } - protected void getAllSpeciesBatchFrequencyForBatch(SpeciesBatch batch, - Multimap<Species, SpeciesBatchFrequency> result) { - - List<SpeciesBatchFrequency> speciesBatchFrequency = getAllSpeciesBatchFrequency(batch.getIdAsInt()); - result.putAll(batch.getSpecies(), speciesBatchFrequency); - - if (!batch.isChildBatchsEmpty()) { - for (SpeciesBatch child : batch.getChildBatchs()) { - getAllSpeciesBatchFrequencyForBatch(child, result); - } - } - } +// protected void getAllSpeciesBatchFrequencyForBatch(SpeciesBatch batch, +// Multimap<Species, SpeciesBatchFrequency> result) { +// +// List<SpeciesBatchFrequency> speciesBatchFrequency = getAllSpeciesBatchFrequency(batch.getIdAsInt()); +// result.putAll(batch.getSpecies(), speciesBatchFrequency); +// +// if (!batch.isChildBatchsEmpty()) { +// for (SpeciesBatch child : batch.getChildBatchs()) { +// getAllSpeciesBatchFrequencyForBatch(child, result); +// } +// } +// } @Override - public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency( - Integer speciesBatchId, - List<SpeciesBatchFrequency> frequencies) { - Preconditions.checkNotNull(speciesBatchId); - Preconditions.checkNotNull(frequencies); - - List<SpeciesBatchFrequency> notNullFrequencies = Lists.newArrayList(); - - // Check that all frequencies have the same length PMFM (before doing any db call) - // and remove null frequencies - String pmfmId = null; - for (SpeciesBatchFrequency source : frequencies) { - - if (source.getLengthStepCaracteristic() != null) { - if (pmfmId == null) { - pmfmId = source.getLengthStepCaracteristic().getId(); - } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { - throw new DataIntegrityViolationException("Batch frequencies under one SpeciesBatch must have all the same lengthStepCaracteristic"); - } - notNullFrequencies.add(source); - } - } - - CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(speciesBatchId); - - if (catchBatch == null) { - return notNullFrequencies; - } - - // Synchronization status - synchronizationStatusHelper.setDirty(catchBatch); - - // Retrieve parent - SortingBatch parentBatch = batchHelper.getSortingBatchById(catchBatch, speciesBatchId); - - // Remember child ids, to remove unchanged item (see at bottom in this method) - List<Integer> notUpdatedChildIds = Lists.newArrayList(); - List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(parentBatch); - notUpdatedChildIds.addAll(frequencyChilds.stream().map(SortingBatch::getId).collect(Collectors.toList())); - - short rankOrder = 0; - List<SortingBatch> batchsToUpdate = Lists.newArrayList(); - for (SpeciesBatchFrequency source : notNullFrequencies) { - rankOrder++; - - SortingBatch target; - if (source.getId() == null) { - - // Not existing batch - target = SortingBatch.Factory.newInstance(); - - // Fill the sorting batch from the source - batchHelper.beanToEntity(source, target, parentBatch, rankOrder); - - // Create the targeted batch, then update the source id - batchHelper.createSortingBatch(source, catchBatch, target); - - // push back id of created sortingBatch - source.setId(target.getId()); - - if (log.isDebugEnabled()) { - log.debug("Create frequency sortingBatch(" + rankOrder + "): " + target.getId()); - } - } else { - - // Existing batch - target = batchHelper.loadSortingBatch(source.getIdAsInt(), catchBatch); - - // Fill the sorting batch from the source - batchHelper.beanToEntity(source, target, parentBatch, rankOrder); - - // Add the batch into a list (will be update later, using this list) - batchsToUpdate.add(target); - - // Remove id from id to remove - notUpdatedChildIds.remove(target.getId()); - - if (log.isDebugEnabled()) { - log.debug("Update frequency sortingBatch(" + rankOrder + "): " + target.getId()); - } - } - } - - if (CollectionUtils.isNotEmpty(batchsToUpdate)) { - - // update some batchs - batchHelper.updateSortingBatch(batchsToUpdate, catchBatch); - } - - if (CollectionUtils.isNotEmpty(notUpdatedChildIds)) { - - // Remove obsolete frequencies - for (Integer batchId : notUpdatedChildIds) { - - if (log.isDebugEnabled()) { - log.debug("Remove obsolete frequency sortingBatch: " + batchId); - } - batchHelper.removeWithChildren(batchId, catchBatch); - } - } - - return Collections.unmodifiableList(notNullFrequencies); + public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(Integer speciesBatchId, List<SpeciesBatchFrequency> frequencies) { + return saveSpeciesBatchFrequency0(speciesBatchId, frequencies); +// Preconditions.checkNotNull(speciesBatchId); +// Preconditions.checkNotNull(frequencies); +// +// List<SpeciesBatchFrequency> notNullFrequencies = Lists.newArrayList(); +// +// // Check that all frequencies have the same length PMFM (before doing any db call) +// // and remove null frequencies +// String pmfmId = null; +// for (SpeciesBatchFrequency source : frequencies) { +// +// if (source.getLengthStepCaracteristic() != null) { +// if (pmfmId == null) { +// pmfmId = source.getLengthStepCaracteristic().getId(); +// } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { +// throw new DataIntegrityViolationException("Batch frequencies under one SpeciesBatch must have all the same lengthStepCaracteristic"); +// } +// notNullFrequencies.add(source); +// } +// } +// +// CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(speciesBatchId); +// +// if (catchBatch == null) { +// return notNullFrequencies; +// } +// +// // Synchronization status +// synchronizationStatusHelper.setDirty(catchBatch); +// +// // Retrieve parent +// SortingBatch parentBatch = batchHelper.getSortingBatchById(catchBatch, speciesBatchId); +// +// // Remember child ids, to remove unchanged item (see at bottom in this method) +// List<Integer> notUpdatedChildIds = Lists.newArrayList(); +// List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(parentBatch); +// notUpdatedChildIds.addAll(frequencyChilds.stream().map(SortingBatch::getId).collect(Collectors.toList())); +// +// short rankOrder = 0; +// List<SortingBatch> batchsToUpdate = Lists.newArrayList(); +// for (SpeciesBatchFrequency source : notNullFrequencies) { +// rankOrder++; +// +// SortingBatch target; +// if (source.getId() == null) { +// +// // Not existing batch +// target = SortingBatch.Factory.newInstance(); +// +// // Fill the sorting batch from the source +// batchHelper.beanToEntity(source, target, parentBatch, rankOrder); +// +// // Create the targeted batch, then update the source id +// batchHelper.createSortingBatch(source, catchBatch, target); +// +// // push back id of created sortingBatch +// source.setId(target.getId()); +// +// if (log.isDebugEnabled()) { +// log.debug("Create frequency sortingBatch(" + rankOrder + "): " + target.getId()); +// } +// } else { +// +// // Existing batch +// target = batchHelper.loadSortingBatch(source.getIdAsInt(), catchBatch); +// +// // Fill the sorting batch from the source +// batchHelper.beanToEntity(source, target, parentBatch, rankOrder); +// +// // Add the batch into a list (will be update later, using this list) +// batchsToUpdate.add(target); +// +// // Remove id from id to remove +// notUpdatedChildIds.remove(target.getId()); +// +// if (log.isDebugEnabled()) { +// log.debug("Update frequency sortingBatch(" + rankOrder + "): " + target.getId()); +// } +// } +// } +// +// if (CollectionUtils.isNotEmpty(batchsToUpdate)) { +// +// // update some batchs +// batchHelper.updateSortingBatch(batchsToUpdate, catchBatch); +// } +// +// if (CollectionUtils.isNotEmpty(notUpdatedChildIds)) { +// +// // Remove obsolete frequencies +// for (Integer batchId : notUpdatedChildIds) { +// +// if (log.isDebugEnabled()) { +// log.debug("Remove obsolete frequency sortingBatch: " + batchId); +// } +// batchHelper.removeWithChildren(batchId, catchBatch); +// } +// } +// +// return Collections.unmodifiableList(notNullFrequencies); } //------------------------------------------------------------------------// //-- Internal methods --// //------------------------------------------------------------------------// - protected void beanToEntity(SpeciesBatch source, - SortingBatch target, - Integer parentBatchId, - CatchBatch catchBatch, - boolean computeRankOrder) { - - Preconditions.checkNotNull(source.getFishingOperation()); - Preconditions.checkNotNull(source.getFishingOperation().getId()); - - // If parent and root need to be set - if (target.getId() == null - || target.getRootBatch() == null - || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatchId))) { - - batchHelper.setSpeciesBatchParents( - source.getSampleCategoryId(), - source.getSampleCategoryValue(), - target, - parentBatchId, - catchBatch - ); - } - - batchHelper.beanToEntity(parentBatchId, source, target, computeRankOrder); - - } +// protected void beanToEntity(SpeciesBatch source, +// SortingBatch target, +// Integer parentBatchId, +// CatchBatch catchBatch, +// boolean computeRankOrder) { +// +// Preconditions.checkNotNull(source.getFishingOperation()); +// Preconditions.checkNotNull(source.getFishingOperation().getId()); +// +// // If parent and root need to be set +// if (target.getId() == null +// || target.getRootBatch() == null +// || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatchId))) { +// +// batchHelper.setSpeciesBatchParents( +// source.getSampleCategoryId(), +// source.getSampleCategoryValue(), +// target, +// parentBatchId, +// catchBatch +// ); +// } +// +// batchHelper.beanToEntity(parentBatchId, source, target, computeRankOrder); +// +// } } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceSupport.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceSupport.java new file mode 100644 index 0000000..cdd6351 --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceSupport.java @@ -0,0 +1,933 @@ +package fr.ifremer.tutti.persistence.service; + +/* + * #%L + * Tutti :: Persistence + * %% + * Copyright (C) 2012 - 2014 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +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 com.google.common.collect.Sets; +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.QualityFlagImpl; +import fr.ifremer.adagio.core.dao.referential.pmfm.Pmfm; +import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; +import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxon; +import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl; +import fr.ifremer.tutti.persistence.InvalidBatchModelException; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.entities.data.BatchContainer; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +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.CaracteristicType; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.service.referential.CaracteristicPersistenceService; +import fr.ifremer.tutti.persistence.service.referential.SpeciesPersistenceService; +import fr.ifremer.tutti.persistence.service.util.BatchPersistenceHelper; +import fr.ifremer.tutti.persistence.service.util.MeasurementPersistenceHelper; +import fr.ifremer.tutti.persistence.service.util.tree.SpeciesBatchTreeHelperSupport; +import fr.ifremer.tutti.persistence.service.util.SynchronizationStatusHelper; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.dao.DataIntegrityViolationException; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import static org.nuiton.i18n.I18n.t; + +/** + * Default implementation of {@link SpeciesBatchPersistenceService}. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 1.2 + */ +public abstract class SpeciesBatchPersistenceServiceSupport extends AbstractPersistenceService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(SpeciesBatchPersistenceServiceSupport.class); + + @Resource(name = "speciesPersistenceService") + private SpeciesPersistenceService speciesService; + + @Resource(name = "fishingOperationPersistenceService") + private FishingOperationPersistenceService fishingOperationPersistenceService; + + @Resource(name = "caracteristicPersistenceService") + private CaracteristicPersistenceService caracteristicService; + + @Resource(name = "batchPersistenceHelper") + private BatchPersistenceHelper batchHelper; + + @Resource(name = "measurementPersistenceHelper") + protected MeasurementPersistenceHelper measurementPersistenceHelper; + + @Resource(name = "synchronizationStatusHelper") + private SynchronizationStatusHelper synchronizationStatusHelper; + + private final String prefix; + + private final Supplier<SpeciesBatch> batchFactory; + private final Supplier<SpeciesBatchFrequency> frequencyFactory; + + protected SpeciesBatchPersistenceServiceSupport(String prefix, Supplier<SpeciesBatch> batchFactory, Supplier<SpeciesBatchFrequency> frequencyFactory) { + this.prefix = prefix; + this.batchFactory = batchFactory; + this.frequencyFactory = frequencyFactory; + } + //------------------------------------------------------------------------// + //-- SpeciesBatch methods --// + //------------------------------------------------------------------------// + + protected abstract SpeciesBatchTreeHelperSupport getBatchTreeHelper(); + + protected abstract void validate(BatchPersistenceHelper batchHelper, SampleCategoryModel sampleCategoryModel, BatchContainer<SpeciesBatch> result); + + protected final BatchContainer<SpeciesBatch> getRootSpeciesBatch0(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException { + + Objects.requireNonNull(fishingOperationId); + + DateFormat df = new SimpleDateFormat("dd/MM/yyy"); + + CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); + + // -- Vrac > Species > Alive Itemized + SortingBatch vracSpeciesBatch = getBatchTreeHelper().getVracAliveItemizedRootBatch(catchBatch); + + // container of speciesBatch is arbitraty put on vrac type (there is + // no common ancestor for all species batch). + BatchContainer<SpeciesBatch> result = new BatchContainer<>(); + + SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); + + if (vracSpeciesBatch != null) { + + result.setId(vracSpeciesBatch.getId()); + + for (Batch batch : vracSpeciesBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; + ReferenceTaxon referenceTaxon = source.getReferenceTaxon(); + Objects.requireNonNull(referenceTaxon, "Can't have a rootSpeciesBatch with a null taxon, but was for " + batch.getId()); + if (log.isTraceEnabled()) { + log.trace("Loading CatchBatch Vrac > " + prefix + " > Alive Itemized > " + referenceTaxon.getId() + " - " + " (batch:" + source.getId() + ")"); + } + Species species = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); + if (species == null) { + FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); + String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); + throw new InvalidBatchModelException(t("tutti.persistence.speciesBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); + } + SpeciesBatch target = batchFactory.get(); + target.setSpecies(species); + + entityToBean(sampleCategoryModel, source, target); + result.addChildren(target); + + if (log.isDebugEnabled()) { + log.debug("Loaded CatchBatch Vrac > " + prefix + " > Alive Itemized > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); + } + } + } + + // -- Hors Vrac > Species + SortingBatch horsVracSpeciesBatch = getBatchTreeHelper().getHorsVracRootBatch(catchBatch); + + if (horsVracSpeciesBatch != null) { + for (Batch batch : horsVracSpeciesBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; + ReferenceTaxon referenceTaxon = source.getReferenceTaxon(); + Objects.requireNonNull(referenceTaxon, "Can't have a rootSpeciesBatch with a null taxon, but was for " + source.getId()); + if (log.isTraceEnabled()) { + log.trace("Loading CatchBatch Hors Vrac > " + prefix + " > " + referenceTaxon.getId() + " - " + " (batch:" + source.getId() + ")"); + } + Species species = speciesService.getSpeciesByReferenceTaxonId(referenceTaxon.getId()); + if (species == null) { + FishingOperation fishingOperation = fishingOperationPersistenceService.getFishingOperation(fishingOperationId); + String fishingOperationName = fishingOperation.getStationNumber() + " - " + fishingOperation.getFishingOperationNumber() + " - " + df.format(fishingOperation.getGearShootingStartDate()); + throw new InvalidBatchModelException(t("tutti.persistence.speciesBatch.validation.unkonwn.taxon", fishingOperationName, source.getId(), referenceTaxon.getId())); + } + SpeciesBatch target = batchFactory.get(); + target.setSpecies(species); + entityToBean(sampleCategoryModel, source, target); + result.addChildren(target); + if (log.isDebugEnabled()) { + log.debug("Loaded CatchBatch Hors Vrac > " + prefix + " > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); + } + } + } + + if (validateTree) { + + // validate with given sample category model + validate(batchHelper, sampleCategoryModel, result); + } + + return result; + } + + protected SpeciesBatch createSpeciesBatch0(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) { + Objects.requireNonNull(bean); + Preconditions.checkArgument(TuttiEntities.isNew(bean)); + Objects.requireNonNull(bean.getSpecies()); + Objects.requireNonNull(bean.getSpecies().getId()); + Objects.requireNonNull(bean.getFishingOperation()); + Objects.requireNonNull(bean.getFishingOperation().getId()); + + CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(bean.getFishingOperation().getIdAsInt(), false); + + return createSpeciesBatch0(bean, parentBatchId, catchBatch, computeRankOrder); + } + + + protected Collection<SpeciesBatch> createSpeciesBatches0(Integer fishingOperationId, Collection<SpeciesBatch> beans) { + + Objects.requireNonNull(beans); + Objects.requireNonNull(fishingOperationId); + + CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(fishingOperationId, false); + + Collection<SpeciesBatch> result = new ArrayList<>(); + for (SpeciesBatch bean : beans) { + + SpeciesBatch created = createSpeciesBatch0(bean, null, catchBatch, true); + result.add(created); + + } + return result; + + } + + protected SpeciesBatch createSpeciesBatch0(SpeciesBatch bean, Integer parentBatchId, CatchBatch catchBatch, boolean computeRankOrder) { + + Objects.requireNonNull(bean); + Preconditions.checkArgument(TuttiEntities.isNew(bean)); + Objects.requireNonNull(bean.getSpecies()); + Objects.requireNonNull(bean.getSpecies().getId()); + Objects.requireNonNull(bean.getFishingOperation()); + Objects.requireNonNull(bean.getFishingOperation().getId()); + + SortingBatch batch = SortingBatch.Factory.newInstance(); + beanToEntity0(bean, batch, parentBatchId, catchBatch, computeRankOrder); + bean = batchHelper.createSortingBatch(bean, catchBatch, batch); + + return bean; + } + + protected SpeciesBatch saveSpeciesBatch0(SpeciesBatch bean) { + Objects.requireNonNull(bean); + Preconditions.checkArgument(!TuttiEntities.isNew(bean)); + + Integer batchId = bean.getIdAsInt(); + + CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(batchId); + SortingBatch batch = batchHelper.getSortingBatchById(catchBatch, batchId); + Integer parentBatchId = null; + if (bean.getParentBatch() != null) { + parentBatchId = bean.getParentBatch().getIdAsInt(); + } + beanToEntity0(bean, batch, parentBatchId, catchBatch, true); + batchHelper.updateSortingBatch(batch, catchBatch); + + return bean; + } + + protected void deleteSpeciesBatch0(Integer id) { + Objects.requireNonNull(id); + batchHelper.deleteBatch(id); + } + + protected void deleteSpeciesSubBatch0(Integer id) { + Objects.requireNonNull(id); + deleteSpeciesSubBatch(id); + } + + protected void changeSpeciesBatchSpecies0(Integer id, Species species) { + Objects.requireNonNull(id); + Objects.requireNonNull(species); + Objects.requireNonNull(species.getReferenceTaxonId()); + changeBatchSpecies(id, species); + } + + protected List<SpeciesBatch> getAllSpeciesBatchToConfirm0(Integer fishingOperationId) throws InvalidBatchModelException { + List<SpeciesBatch> batchesToConfirm = new ArrayList<>(); + + BatchContainer<SpeciesBatch> rootSpeciesBatch = getRootSpeciesBatch0(fishingOperationId, false); + for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { + findSpeciesBatchesToConfirm(speciesBatch, batchesToConfirm); + } + + return batchesToConfirm; + } + + private void findSpeciesBatchesToConfirm(SpeciesBatch speciesBatch, List<SpeciesBatch> batchesToConfirm) { + if (speciesBatch.isSpeciesToConfirm()) { + batchesToConfirm.add(speciesBatch); + + } else if (!speciesBatch.isChildBatchsEmpty()) { + for (SpeciesBatch batch : speciesBatch.getChildBatchs()) { + findSpeciesBatchesToConfirm(batch, batchesToConfirm); + } + } + } + + //------------------------------------------------------------------------// + //-- SpeciesBatchFrequency methods --// + //------------------------------------------------------------------------// + + protected List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency0(Integer speciesBatchId) { + Objects.requireNonNull(speciesBatchId); + + List<SortingBatch> frequencyChilds = getFrequencies(speciesBatchId); + List<SpeciesBatchFrequency> results = new ArrayList<>(); + for (SortingBatch child : frequencyChilds) { + SpeciesBatchFrequency target = frequencyFactory.get(); + + entityToBatchFrequency(child, target); + results.add(target); + } + return Collections.unmodifiableList(results); + } + + protected Multimap<Species, SpeciesBatchFrequency> getAllSpeciesBatchFrequencyForBatch0(BatchContainer<SpeciesBatch> batchContainer) { + Multimap<Species, SpeciesBatchFrequency> result = ArrayListMultimap.create(); + for (SpeciesBatch speciesBatch : batchContainer.getChildren()) { + getAllSpeciesBatchFrequencyForBatch(speciesBatch, result); + } + return result; + } + + private void getAllSpeciesBatchFrequencyForBatch(SpeciesBatch batch, Multimap<Species, SpeciesBatchFrequency> result) { + + List<SpeciesBatchFrequency> speciesBatchFrequency = getAllSpeciesBatchFrequency0(batch.getIdAsInt()); + result.putAll(batch.getSpecies(), speciesBatchFrequency); + + if (!batch.isChildBatchsEmpty()) { + for (SpeciesBatch child : batch.getChildBatchs()) { + getAllSpeciesBatchFrequencyForBatch(child, result); + } + } + } + + protected List<SpeciesBatchFrequency> saveSpeciesBatchFrequency0(Integer speciesBatchId, List<SpeciesBatchFrequency> frequencies) { + Objects.requireNonNull(speciesBatchId); + Objects.requireNonNull(frequencies); + + List<SpeciesBatchFrequency> notNullFrequencies = new ArrayList<>(); + + // Check that all frequencies have the same length PMFM (before doing any db call) + // and remove null frequencies + String pmfmId = null; + for (SpeciesBatchFrequency source : frequencies) { + + if (source.getLengthStepCaracteristic() != null) { + if (pmfmId == null) { + pmfmId = source.getLengthStepCaracteristic().getId(); + } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { + throw new DataIntegrityViolationException("Batch frequencies under one SpeciesBatch must have all the same lengthStepCaracteristic"); + } + notNullFrequencies.add(source); + } + } + + CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(speciesBatchId); + + if (catchBatch == null) { + return notNullFrequencies; + } + + // Synchronization status + synchronizationStatusHelper.setDirty(catchBatch); + + // Retrieve parent + SortingBatch parentBatch = batchHelper.getSortingBatchById(catchBatch, speciesBatchId); + + // Remember child ids, to remove unchanged item (see at bottom in this method) + List<Integer> notUpdatedChildIds = new ArrayList<>(); + List<SortingBatch> frequencyChilds = getFrequencyChilds(parentBatch); + notUpdatedChildIds.addAll(frequencyChilds.stream().map(SortingBatch::getId).collect(Collectors.toList())); + + short rankOrder = 0; + List<SortingBatch> batchsToUpdate = new ArrayList<>(); + for (SpeciesBatchFrequency source : notNullFrequencies) { + rankOrder++; + + SortingBatch target; + if (source.getId() == null) { + + // Not existing batch + target = SortingBatch.Factory.newInstance(); + + // Fill the sorting batch from the source + beanToEntity0(source, target, parentBatch, rankOrder); + + // Create the targeted batch, then update the source id + batchHelper.createSortingBatch(source, catchBatch, target); + + // push back id of created sortingBatch + source.setId(target.getId()); + + if (log.isDebugEnabled()) { + log.debug("Create frequency sortingBatch(" + rankOrder + "): " + target.getId()); + } + } else { + + // Existing batch + target = batchHelper.loadSortingBatch(source.getIdAsInt(), catchBatch); + + // Fill the sorting batch from the source + beanToEntity0(source, target, parentBatch, rankOrder); + + // Add the batch into a list (will be update later, using this list) + batchsToUpdate.add(target); + + // Remove id from id to remove + notUpdatedChildIds.remove(target.getId()); + + if (log.isDebugEnabled()) { + log.debug("Update frequency sortingBatch(" + rankOrder + "): " + target.getId()); + } + } + } + + if (CollectionUtils.isNotEmpty(batchsToUpdate)) { + + // update some batchs + batchHelper.updateSortingBatch(batchsToUpdate, catchBatch); + } + + if (CollectionUtils.isNotEmpty(notUpdatedChildIds)) { + + // Remove obsolete frequencies + for (Integer batchId : notUpdatedChildIds) { + + if (log.isDebugEnabled()) { + log.debug("Remove obsolete frequency sortingBatch: " + batchId); + } + batchHelper.removeWithChildren(batchId, catchBatch); + } + } + + return Collections.unmodifiableList(notNullFrequencies); + } + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected void beanToEntity0(SpeciesBatch source, + SortingBatch target, + Integer parentBatchId, + CatchBatch catchBatch, + boolean computeRankOrder) { + + Objects.requireNonNull(source.getFishingOperation()); + Objects.requireNonNull(source.getFishingOperation().getId()); + + // If parent and root need to be set + if (target.getId() == null + || target.getRootBatch() == null + || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatchId))) { + + getBatchTreeHelper().setBatchParents(source.getSampleCategoryId(), + source.getSampleCategoryValue(), + target, + parentBatchId, + catchBatch); + } + + // --- RankOrder (initialize once, at creation) --- // + { + if (target.getRankOrder() == null) { + + short rankOrder; + + if (computeRankOrder) { + + // Start rank order at 1 + rankOrder = (short) 1; + //FIXME : tchemit-2015-04-04 This code can not be used to save multiple batches at the same time, since it will always give the + //FIXME : tchemit-2015-04-04 same values for all batches + if (source.getParentBatch() != null && CollectionUtils.isNotEmpty(source.getParentBatch().getChildBatchs())) { + int maxRankOrder = 0; + for (SpeciesBatch batch : source.getParentBatch().getChildBatchs()) { + Integer r = batch.getRankOrder(); + if (r != null && r > maxRankOrder) { + maxRankOrder = r; + } + } + rankOrder += (short) maxRankOrder; + + } else { + + rankOrder = batchHelper.computeRankOrder(target); + + } + + } else { + + Preconditions.checkState(source.getRankOrder() != null, "Not using computeRankOrder requires source rankOrder to be not null, but was on batch: " + source); + rankOrder = (short) (int) source.getRankOrder(); + + } + + target.setRankOrder(rankOrder); + + } + } + + // --- Force subgroup count to '1', as Allegro --- // + target.setSubgroupCount(1f); + + // --- Individual count --- // + target.setIndividualCount(source.getNumber()); + + // --- Comments --- // + target.setComments(source.getComment()); + + // --- Exhaustive inventory (always true under a species batch) --- // + target.setExhaustiveInventory(true); + + // --- Species --- // + { + ReferenceTaxon referenceTaxon; + if (source.getSpecies() == null || parentBatchId != null) { + referenceTaxon = null; + } else { + referenceTaxon = load(ReferenceTaxonImpl.class, source.getSpecies().getReferenceTaxonId()); + } + target.setReferenceTaxon(referenceTaxon); + } + + // --- QualityFlag --- // + { + String qualityFlag; + if (source.isSpeciesToConfirm()) { + qualityFlag = QualityFlagCode.DOUBTFUL.getValue(); + } else { + qualityFlag = QualityFlagCode.NOTQUALIFIED.getValue(); + } + target.setQualityFlag(load(QualityFlagImpl.class, qualityFlag)); + } + + Float weight = source.getWeight(); + Float sampleCategoryWeight = source.getSampleCategoryWeight(); + + // --- Sampling Ratio + QuantificationMeasurement --- // + getBatchTreeHelper().setWeightAndSampleRatio(target, weight, sampleCategoryWeight); + + // --- Sorting measurement --- // + { + Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); + Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); + if (sortingMeasurements != null) { + notChangedSortingMeasurements.addAll(sortingMeasurements); + } + + if (source.getSampleCategoryId() != null && source.getSampleCategoryValue() != null) { + Integer pmfmId = source.getSampleCategoryId(); + // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch) + if (!pmfmId.equals(PmfmId.SORTED_UNSORTED.getValue())) { + SortingMeasurement sortingMeasurement = measurementPersistenceHelper.setSortingMeasurement( + target, + pmfmId, + source.getSampleCategoryValue()); + notChangedSortingMeasurements.remove(sortingMeasurement); + } + } + if (sortingMeasurements != null) { + sortingMeasurements.removeAll(notChangedSortingMeasurements); + } + } + + } + + private void beanToEntity0(SpeciesBatchFrequency source, + SortingBatch target, + SortingBatch parentBatch, + short rankOrder) { + Preconditions.checkNotNull(source.getBatch()); + Preconditions.checkNotNull(source.getBatch().getId()); + + // If parent and root need to be set + if (target.getId() == null + || target.getRootBatch() == null + || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatch.getId()))) { + + target.setParentBatch(parentBatch); + target.setRootBatch(parentBatch.getRootBatch()); + } + + // --- RankOrder --- // + target.setRankOrder(rankOrder); + + // --- Individual count --- // + target.setIndividualCount(source.getNumber()); + + // --- Species --- // + target.setReferenceTaxon(null); + + // --- QualityFlag --- // + target.setQualityFlag(parentBatch.getQualityFlag()); + + // --- Exhaustive inventory (always true under a species batch) --- // + target.setExhaustiveInventory(true); + + // --- Sampling Ratio + QuantificationMeasurement --- // + getBatchTreeHelper().setWeightAndSampleRatio(target, source.getWeight(), null); + + // --- Sorting measurement --- // + { + Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); + Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); + if (sortingMeasurements != null) { + notChangedSortingMeasurements.addAll(sortingMeasurements); + } + if ((source.getLengthStepCaracteristic() != null && source.getLengthStep() != null)) { + Integer pmfmId = source.getLengthStepCaracteristic().getIdAsInt(); + SortingMeasurement sortingMeasurement = measurementPersistenceHelper.setSortingMeasurement(target, pmfmId, + source.getLengthStep()); + notChangedSortingMeasurements.remove(sortingMeasurement); + } + if (sortingMeasurements != null) { + sortingMeasurements.removeAll(notChangedSortingMeasurements); + } + } + + } + + + private 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 (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<SpeciesBatch> targetChilds = Lists.newArrayList(); + for (Batch batch : source.getChildBatchs()) { + SortingBatch sourceChild = (SortingBatch) batch; + SpeciesBatch targetChild = SpeciesBatchs.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); + 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 = 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; + + } + +// private short computeRankOrder(SortingBatch target) { +// +// // Start rank order at 1, nothing before it +// short rankOrder = (short) 1; +// if (target.getParentBatch() != null && target.getParentBatch().getChildBatchs() != null) { +// int maxRankOrder = 0; +// for (Batch batch : target.getParentBatch().getChildBatchs()) { +// Short r = batch.getRankOrder(); +// if (r != null && r > maxRankOrder) { +// maxRankOrder = r; +// } +// } +// rankOrder += maxRankOrder; +// } +// return rankOrder; +// +// } + + private void setSampleCategoryQualitative(SpeciesBatch target, + Integer pmfmId, + Float numericalvalue, + String alphanumericalValue, + Integer qualitativeValueId) { + // skip if null or corresponding to the SORTING_TYPE PMFM (Espèce, Benthos, Plancton, etc.) + if (pmfmId == null || pmfmId.equals(SpeciesBatchTreeHelperSupport.SORTING_TYPE_ID)) { + return; + } + SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); + + boolean isSamplingCategory = sampleCategoryModel.containsCategoryId(pmfmId); + Preconditions.checkNotNull(isSamplingCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId); + + target.setSampleCategoryId(pmfmId); + Serializable categoryValue = getSampleCategoryQualitative( + pmfmId, + numericalvalue, + alphanumericalValue, + qualitativeValueId); + target.setSampleCategoryValue(categoryValue); + } + + /** + * Check if the given {@code sortingBatch} is a frequency one. + * + * We test that: + * <ul> + * <li>batch has exactly one measurement</li> + * <li>the measurement pmfm is not a sample category</li> + * </ul> + * + * @param sampleCategoryModel model of authorized sample categories + * @param sortingBatch batch to check + * @return {@code true} if given batch is a frequency batch, + * {@code false} otherwise. + */ + private boolean isFrequencyBatch(SampleCategoryModel sampleCategoryModel, SortingBatch sortingBatch) { + boolean result = false; + if (sortingBatch.getSortingMeasurements().size() == 1) { + SortingMeasurement sm + = sortingBatch.getSortingMeasurements().iterator().next(); + Pmfm pmfm = sm.getPmfm(); + + result = sortingBatch.getIndividualCount() != null && + !sampleCategoryModel.containsCategoryId(pmfm.getId()); + } + return result; + } + + private Serializable getSampleCategoryQualitative(Integer pmfmId, + Float numericalvalue, + String alphanumericalValue, + Integer qualitativeValueId) { + + if (numericalvalue != null) { + return numericalvalue; + } + if (alphanumericalValue != null) { + return alphanumericalValue; + } + + Caracteristic caracteristic = caracteristicService.getCaracteristic(pmfmId); + if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) { + return null; + } + CaracteristicQualitativeValue value = null; + for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { + if (qualitativeValueId.equals(qv.getIdAsInt())) { + value = qv; + break; + } + } + + return value; + } + + private void entityToBatchFrequency(SortingBatch source, + SpeciesBatchFrequency target) { + + target.setId(source.getId()); + + // Rank order + target.setRankOrder(Integer.valueOf(source.getRankOrder())); + + target.setNumber(source.getIndividualCount()); + target.setWeight(source.getWeight()); + + Preconditions.checkState(source.getSortingMeasurements().size() == 1, "SortingBatch [" + source.getId() + "] need exactly one sortingMeasurement (to store the length step category), but had " + source.getSortingMeasurements().size()); + SortingMeasurement sm = source.getSortingMeasurements().iterator().next(); + Preconditions.checkNotNull(sm.getPmfm(), "SortingMeasurement [" + sm.getId() + "] can not have a null pmfm"); + Preconditions.checkNotNull(sm.getPmfm().getId(), "SortingMeasurement [" + sm.getId() + "] can not have a pmfm with null id"); + + // Length step category + Caracteristic lengthStepCaracteristic = caracteristicService.getCaracteristic(sm.getPmfm().getId()); + target.setLengthStepCaracteristic(lengthStepCaracteristic); + + // Length + target.setLengthStep(sm.getNumericalValue()); + } + + private List<SortingBatch> getFrequencyChilds(SortingBatch sortingBatch) { + List<SortingBatch> result = Lists.newArrayList(); + + SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); + + for (Batch batch : sortingBatch.getChildBatchs()) { + SortingBatch child = (SortingBatch) batch; + if (isFrequencyBatch(sampleCategoryModel, child)) { + result.add(child); + } + } + return result; + } + + private List<SortingBatch> getFrequencies(Integer batchId) { + Preconditions.checkNotNull(batchId); + CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(batchId); + SortingBatch sortingBatch = batchHelper.getSortingBatchById(catchBatch, batchId); + + return getFrequencyChilds(sortingBatch); + } + + private void deleteSpeciesSubBatch(Integer speciesBatchId) { + Preconditions.checkNotNull(speciesBatchId); + + CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(speciesBatchId); + synchronizationStatusHelper.setDirty(catchBatch); + + SortingBatch sortingBatch = batchHelper.getSortingBatchById(catchBatch, speciesBatchId); + + // get his children + Collection<Batch> childBatchs = sortingBatch.getChildBatchs(); + + if (CollectionUtils.isNotEmpty(childBatchs)) { + + for (Batch childBatch : childBatchs) { + + // delete this child and all his children + Integer childBatchId = childBatch.getId(); + + if (log.isDebugEnabled()) { + log.debug("Delete child [" + childBatchId + "] of species batch: " + speciesBatchId); + } + batchHelper.removeWithChildren(childBatchId); + } + } + } + + private void changeBatchSpecies(Integer batchId, Species species) { + + Preconditions.checkNotNull(batchId); + Preconditions.checkNotNull(species); + Preconditions.checkNotNull(species.getReferenceTaxonId()); + + CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(batchId); + synchronizationStatusHelper.setDirty(catchBatch); + + batchHelper.setSortingBatchReferenceTaxon(batchId, species); + } +} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java index c03609b..f0a4ca2 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java @@ -27,12 +27,10 @@ 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.batch.validator.CatchBatchValidationError; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.service.util.BatchTreeHelper; +import fr.ifremer.tutti.persistence.service.util.tree.BatchTreeHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Component; @@ -111,14 +109,14 @@ public class ScientificCruiseCatchBatchValidator implements TuttiCatchBatchValid @Override public List<CatchBatchValidationError> validateBenthos(SampleCategoryModel sampleCategoryModel, - BatchContainer<BenthosBatch> benthos) { + BatchContainer<SpeciesBatch> benthos) { List<CatchBatchValidationError> errors = Lists.newArrayList(); Map<Integer, SampleCategoryModelEntry> categoriesById = sampleCategoryModel.getCategoryMap(); - for (BenthosBatch benthosBatch : benthos.getChildren()) { + for (SpeciesBatch benthosBatch : benthos.getChildren()) { // check all sample categories are accepted validateSampleCategoriesUniverse( @@ -255,7 +253,7 @@ public class ScientificCruiseCatchBatchValidator implements TuttiCatchBatchValid protected void validateSampleCategoriesUniverse(SampleCategoryModel sampleCategoryModel, List<CatchBatchValidationError> errors, - SpeciesAbleBatch aBatch, + SpeciesBatch aBatch, String messageKey) { Integer sampleCategoryId = aBatch.getSampleCategoryId(); @@ -273,7 +271,7 @@ public class ScientificCruiseCatchBatchValidator implements TuttiCatchBatchValid if (!aBatch.isChildBatchsEmpty()) { - for (SpeciesAbleBatch speciesAbleBatch : aBatch.getChildBatchs()) { + for (SpeciesBatch speciesAbleBatch : aBatch.getChildBatchs()) { validateSampleCategoriesUniverse(sampleCategoryModel, errors, @@ -285,7 +283,7 @@ public class ScientificCruiseCatchBatchValidator implements TuttiCatchBatchValid protected void validateSampleCategoriesOrder(Map<Integer, SampleCategoryModelEntry> categoriesById, List<CatchBatchValidationError> errors, - SpeciesAbleBatch aBatch, + SpeciesBatch aBatch, SampleCategoryModelEntry lastSampleCategory, String messageKey) { @@ -320,7 +318,7 @@ public class ScientificCruiseCatchBatchValidator implements TuttiCatchBatchValid if (!aBatch.isChildBatchsEmpty()) { - for (SpeciesAbleBatch speciesAbleBatch : aBatch.getChildBatchs()) { + for (SpeciesBatch speciesAbleBatch : aBatch.getChildBatchs()) { validateSampleCategoriesOrder( categoriesById, diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/TuttiCatchBatchValidator.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/TuttiCatchBatchValidator.java index f1b77b2..5ff711b 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/TuttiCatchBatchValidator.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/TuttiCatchBatchValidator.java @@ -25,7 +25,6 @@ package fr.ifremer.tutti.persistence.service.batch; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationError; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidator; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; @@ -43,5 +42,5 @@ public interface TuttiCatchBatchValidator extends CatchBatchValidator { BatchContainer<SpeciesBatch> species); List<CatchBatchValidationError> validateBenthos(SampleCategoryModel sampleCategoryModel, - BatchContainer<BenthosBatch> benthos); + BatchContainer<SpeciesBatch> benthos); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/CaracteristicPersistenceService.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/CaracteristicPersistenceService.java index e727fad..5f0595e 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/CaracteristicPersistenceService.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/CaracteristicPersistenceService.java @@ -27,7 +27,7 @@ package fr.ifremer.tutti.persistence.service.referential; import com.google.common.base.Predicate; import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import org.springframework.cache.annotation.Cacheable; import org.springframework.transaction.annotation.Transactional; @@ -109,10 +109,10 @@ public interface CaracteristicPersistenceService extends TuttiPersistenceService @Cacheable(value = "pmfmById", key = "#pmfmId") Caracteristic getCaracteristic(Integer pmfmId); - Predicate<SpeciesAbleBatch> getVracBatchPredicate(); + Predicate<SpeciesBatch> getVracBatchPredicate(); - boolean isVracBatch(SpeciesAbleBatch speciesBatch); + boolean isVracBatch(SpeciesBatch speciesBatch); - boolean isHorsVracBatch(SpeciesAbleBatch speciesBatch); + boolean isHorsVracBatch(SpeciesBatch speciesBatch); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/CaracteristicPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/CaracteristicPersistenceServiceImpl.java index 0c233ee..6bafa05 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/CaracteristicPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/CaracteristicPersistenceServiceImpl.java @@ -31,8 +31,8 @@ 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.adagio.core.dao.referential.pmfm.UnitId; -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; @@ -68,13 +68,13 @@ public class CaracteristicPersistenceServiceImpl extends ReferentialPersistenceS protected Set<Integer> propertedPmfmIds; - protected Predicate<SpeciesAbleBatch> batchVracPredicate; + protected Predicate<SpeciesBatch> batchVracPredicate; @Override public void init() { super.init(); - batchVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + batchVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_VRAC.getValue()); @@ -259,17 +259,17 @@ public class CaracteristicPersistenceServiceImpl extends ReferentialPersistenceS } @Override - public boolean isVracBatch(SpeciesAbleBatch speciesBatch) { + public boolean isVracBatch(SpeciesBatch speciesBatch) { return batchVracPredicate.apply(speciesBatch); } @Override - public boolean isHorsVracBatch(SpeciesAbleBatch speciesBatch) { + public boolean isHorsVracBatch(SpeciesBatch speciesBatch) { return !batchVracPredicate.apply(speciesBatch); } @Override - public Predicate<SpeciesAbleBatch> getVracBatchPredicate() { + public Predicate<SpeciesBatch> getVracBatchPredicate() { return batchVracPredicate; } 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 ce8b4c4..17e51fa 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,7 +24,6 @@ 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; @@ -34,48 +33,26 @@ import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; import fr.ifremer.adagio.core.dao.data.batch.SortingBatchDao; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationError; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; -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; import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; -import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; -import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxon; -import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl; import fr.ifremer.tutti.persistence.InvalidBatchModelException; import fr.ifremer.tutti.persistence.entities.TuttiEntity; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -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; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.service.AbstractPersistenceService; import fr.ifremer.tutti.persistence.service.AccidentalBatchPersistenceService; import fr.ifremer.tutti.persistence.service.AttachmentPersistenceService; import fr.ifremer.tutti.persistence.service.IndividualObservationBatchPersistenceService; import fr.ifremer.tutti.persistence.service.batch.TuttiCatchBatchValidator; -import fr.ifremer.tutti.persistence.service.referential.CaracteristicPersistenceService; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataRetrievalFailureException; import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.Collection; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -91,12 +68,12 @@ import static org.nuiton.i18n.I18n.t; @Component("batchPersistenceHelper") public class BatchPersistenceHelper extends AbstractPersistenceService { - /** Logger. */ - private static final Log log = - LogFactory.getLog(BatchPersistenceHelper.class); +// /** Logger. */ +// private static final Log log = +// LogFactory.getLog(BatchPersistenceHelper.class); - @Resource(name = "caracteristicPersistenceService") - private CaracteristicPersistenceService caracteristicService; +// @Resource(name = "caracteristicPersistenceService") +// private CaracteristicPersistenceService caracteristicService; @Resource(name = "attachmentPersistenceService") protected AttachmentPersistenceService attachmentPersistenceService; @@ -122,8 +99,8 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { @Resource(name = "measurementPersistenceHelper") protected MeasurementPersistenceHelper measurementPersistenceHelper; - @Resource(name = "batchTreeHelper") - protected BatchTreeHelper batchTreeHelper; +// @Resource(name = "batchTreeHelper") +// protected BatchTreeHelper batchTreeHelper; @Resource(name = "synchronizationStatusHelper") protected SynchronizationStatusHelper synchronizationStatusHelper; @@ -161,7 +138,7 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { } public void validateBenthos(SampleCategoryModel sampleCategoryModel, - BatchContainer<BenthosBatch> benthos) throws InvalidBatchModelException { + BatchContainer<SpeciesBatch> benthos) throws InvalidBatchModelException { List<CatchBatchValidationError> errors = catchBatchValidator.validateBenthos(sampleCategoryModel, benthos); if (CollectionUtils.isNotEmpty(errors)) { @@ -263,28 +240,28 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { catchBatchDao.updateSortingBatch(sortingBatch, parentCatchBatch); } - public List<SortingBatch> getFrequencyChilds(SortingBatch sortingBatch) { - List<SortingBatch> result = Lists.newArrayList(); - - SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); - - for (Batch batch : sortingBatch.getChildBatchs()) { - SortingBatch child = (SortingBatch) batch; - if (isFrequencyBatch(sampleCategoryModel, child)) { - result.add(child); - } - } - return result; - } - - public List<SortingBatch> getFrequencies(Integer batchId) { - Preconditions.checkNotNull(batchId); - CatchBatch catchBatch = getRootCatchBatchByBatchId(batchId); - SortingBatch sortingBatch = catchBatchDao.getSortingBatchById( - catchBatch, batchId); - - return getFrequencyChilds(sortingBatch); - } +// public List<SortingBatch> getFrequencyChilds(SortingBatch sortingBatch) { +// List<SortingBatch> result = Lists.newArrayList(); +// +// SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); +// +// for (Batch batch : sortingBatch.getChildBatchs()) { +// SortingBatch child = (SortingBatch) batch; +// if (isFrequencyBatch(sampleCategoryModel, child)) { +// result.add(child); +// } +// } +// return result; +// } + +// public List<SortingBatch> getFrequencies(Integer batchId) { +// Preconditions.checkNotNull(batchId); +// CatchBatch catchBatch = getRootCatchBatchByBatchId(batchId); +// SortingBatch sortingBatch = catchBatchDao.getSortingBatchById( +// catchBatch, batchId); +// +// return getFrequencyChilds(sortingBatch); +// } public fr.ifremer.adagio.core.dao.data.batch.CatchBatch getRootCatchBatchByFishingOperationId(Integer fishingOperationId, boolean validate) { Preconditions.checkNotNull(fishingOperationId); @@ -333,464 +310,466 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { return result; } - public void setSpeciesBatchParents(Integer sampleCategoryId, - Serializable sampleCategoryValue, - SortingBatch target, - Integer parentBatchId, - CatchBatch catchBatch) { - - Preconditions.checkNotNull(target); - Preconditions.checkNotNull(catchBatch); - - target.setRootBatch(catchBatch); - - SortingBatch parentBatch; - if (parentBatchId != null) { - - // Load existing parent and root - parentBatch = catchBatchDao.getSortingBatchById(catchBatch, parentBatchId); - } else { - - // Or retrieve parent batch, from pmfm id - // Retrieve category type - if (!sampleCategoryId.equals(PmfmId.SORTED_UNSORTED.getValue())) { - throw new DataIntegrityViolationException(MessageFormat.format( - "A species or benthos batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", - PmfmId.SORTED_UNSORTED.getValue(), - sampleCategoryId)); - } - - Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(sampleCategoryValue); - - if (QualitativeValueId.SORTED_VRAC.getValue().equals(qualitativeValueId)) { - - // -- Vrac > Species > Alive itemized - parentBatch = batchTreeHelper.getSpeciesVracAliveItemizedRootBatch(catchBatch); - - if (parentBatch == null) { - - // -- Vrac - SortingBatch vracBatch = batchTreeHelper.getVracBatch(catchBatch); - - if (vracBatch == null) { - vracBatch = batchTreeHelper.getOrCreateVracBatch(catchBatch, null, null); - } - - // -- Vrac > Species - SortingBatch vracSpeciesBatch = batchTreeHelper.getSpeciesVracRootBatch(vracBatch); - - if (vracSpeciesBatch == null) { - vracSpeciesBatch = batchTreeHelper.getOrCreateSpeciesVracRootBatch(catchBatch, vracBatch, null); - } - - // -- Vrac > Species > Alive itemized - parentBatch = batchTreeHelper.getOrCreateSpeciesVracAliveItemizedRootBatch(catchBatch, vracSpeciesBatch); - - } - } else if (QualitativeValueId.SORTED_HORS_VRAC.getValue().equals(qualitativeValueId)) { - - // -- Hors Vrac > Species - parentBatch = batchTreeHelper.getSpeciesHorsVracRootBatch(catchBatch); - - if (parentBatch == null) { - - // -- Hors Vrac - SortingBatch horsVracBatch = batchTreeHelper.getOrCreateHorsVracBatch(catchBatch); - - // -- Hors Vrac > Species - parentBatch = batchTreeHelper.getOrCreateSpeciesHorsVracRootBatch(catchBatch, horsVracBatch); - } - } else { - - // not possible - throw new DataIntegrityViolationException("Should have Vrac / Hor Vrac qualitative value, but had: " + qualitativeValueId); - } - - } - - Preconditions.checkNotNull(parentBatch); - target.setParentBatch(parentBatch); - } - - public void setBenthosBatchParents(Integer sampleCategoryType, - Serializable sampleCategoryValue, - SortingBatch target, - Integer parentBatchId, - CatchBatch catchBatch) { - - Preconditions.checkNotNull(target); - Preconditions.checkNotNull(catchBatch); - - target.setRootBatch(catchBatch); - - SortingBatch parentBatch; - if (parentBatchId != null) { - - // Load existing parent and root - parentBatch = catchBatchDao.getSortingBatchById(catchBatch, parentBatchId); - } else { - - // Or retrieve parent batch, from pmfm id - // Retrieve category type - if (!sampleCategoryType.equals(PmfmId.SORTED_UNSORTED.getValue())) { - throw new DataIntegrityViolationException(MessageFormat.format( - "A species or benthos batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", - sampleCategoryType, - PmfmId.SORTED_UNSORTED.getValue())); - } - - Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(sampleCategoryValue); - - if (QualitativeValueId.SORTED_VRAC.getValue().equals(qualitativeValueId)) { - - // -- Vrac > Benthos > Alive Itemized - parentBatch = batchTreeHelper.getBenthosVracAliveItemizedRootBatch(catchBatch); - - if (parentBatch == null) { - - // -- Vrac - SortingBatch vracBatch = batchTreeHelper.getVracBatch(catchBatch); - - if (vracBatch == null) { - vracBatch = batchTreeHelper.getOrCreateVracBatch(catchBatch, null, null); - } - - // -- Vrac > Benthos - SortingBatch vracBenthosBatch = batchTreeHelper.getBenthosVracRootBatch(vracBatch); - - if (vracBenthosBatch == null) { - vracBenthosBatch = batchTreeHelper.getOrCreateBenthosVracRootBatch(catchBatch, vracBatch, null); - } - - // -- Vrac > Benthos > Alive itemized - parentBatch = batchTreeHelper.getOrCreateBenthosVracAliveItemizedRootBatch(catchBatch, vracBenthosBatch); - - } - } else if (QualitativeValueId.SORTED_HORS_VRAC.getValue().equals(qualitativeValueId)) { - - // -- Hors Vrac > Benthos - parentBatch = batchTreeHelper.getBenthosHorsVracRootBatch(catchBatch); - - if (parentBatch == null) { - - // -- Hors Vrac - SortingBatch horsVracBatch = batchTreeHelper.getOrCreateHorsVracBatch(catchBatch); - - // -- Hors Vrac > Benthos - parentBatch = batchTreeHelper.getOrCreateBenthosHorsVracRootBatch(catchBatch, horsVracBatch); - } - } else { - - // not possible - throw new DataIntegrityViolationException("Should have Vrac / Hors Vrac qualitative value, but had: " + qualitativeValueId); - } - } - - Preconditions.checkNotNull(parentBatch); - target.setParentBatch(parentBatch); - } - - public void setMarineLitterBatchParents(SortingBatch target, CatchBatch catchBatch) { - - Preconditions.checkNotNull(target); - - // -- Hors Vrac > Marine Litter - SortingBatch parentBatch = batchTreeHelper.getMarineLitterRootBatch(catchBatch); - - if (parentBatch == null) { - - // -- Hors Vrac - SortingBatch horsVracBatch = batchTreeHelper.getOrCreateHorsVracBatch(catchBatch); - - // -- Hors Vrac > Marine Litter - parentBatch = batchTreeHelper.getOrCreateMarineLitterRootBatch(catchBatch, horsVracBatch, null); - } - - target.setParentBatch(parentBatch); - target.setRootBatch(catchBatch); - } - - public void beanToEntity(Integer parentBatchId, - SpeciesAbleBatch source, - SortingBatch target, - boolean computeRankOrder) { - - // --- RankOrder (initialize once, at creation) --- // - { - if (target.getRankOrder() == null) { - - short rankOrder; - - if (computeRankOrder) { - - // Start rank order at 1 - rankOrder = (short) 1; - //FIXME : tchemit-2015-04-04 This code can not be used to save multiple batches at the same time, since it will always give the - //FIXME : tchemit-2015-04-04 same values for all batches - if (source.getParentBatch() != null && CollectionUtils.isNotEmpty(source.getParentBatch().getChildBatchs())) { - int maxRankOrder = 0; - for (SpeciesAbleBatch batch : source.getParentBatch().getChildBatchs()) { - Integer r = batch.getRankOrder(); - if (r != null && r > maxRankOrder) { - maxRankOrder = r; - } - } - rankOrder += (short) maxRankOrder; - - } else { - - rankOrder = computeRankOrder(target); - - } - - } else { - - Preconditions.checkState(source.getRankOrder() != null, "Not using computeRankOrder requires source rankOrder to be not null, but was on batch: " + source); - rankOrder = (short) (int) source.getRankOrder(); - - } - - target.setRankOrder(rankOrder); - - } - } - - // --- Force subgroup count to '1', as Allegro --- // - target.setSubgroupCount(1f); - - // --- Individual count --- // - target.setIndividualCount(source.getNumber()); - - // --- Comments --- // - target.setComments(source.getComment()); - - // --- Exhaustive inventory (always true under a species batch) --- // - target.setExhaustiveInventory(true); - - // --- Species --- // - { - ReferenceTaxon referenceTaxon; - if (source.getSpecies() == null || parentBatchId != null) { - referenceTaxon = null; - } else { - referenceTaxon = load(ReferenceTaxonImpl.class, source.getSpecies().getReferenceTaxonId()); - } - target.setReferenceTaxon(referenceTaxon); - } - - // --- QualityFlag --- // - { - String qualityFlag; - if (source.isSpeciesToConfirm()) { - qualityFlag = QualityFlagCode.DOUBTFUL.getValue(); - } else { - qualityFlag = QualityFlagCode.NOTQUALIFIED.getValue(); - } - target.setQualityFlag(load(QualityFlagImpl.class, qualityFlag)); - } - - Float weight = source.getWeight(); - Float sampleCategoryWeight = source.getSampleCategoryWeight(); - - // --- Sampling Ratio + QuantificationMeasurement --- // - batchTreeHelper.setWeightAndSampleRatio(target, weight, sampleCategoryWeight); - - // --- Sorting measurement --- // - { - Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); - Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); - if (sortingMeasurements != null) { - notChangedSortingMeasurements.addAll(sortingMeasurements); - } - - if (source.getSampleCategoryId() != null && source.getSampleCategoryValue() != null) { - Integer pmfmId = source.getSampleCategoryId(); - // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch) - if (!pmfmId.equals(PmfmId.SORTED_UNSORTED.getValue())) { - SortingMeasurement sortingMeasurement = measurementPersistenceHelper.setSortingMeasurement( - target, - pmfmId, - source.getSampleCategoryValue()); - notChangedSortingMeasurements.remove(sortingMeasurement); - } - } - if (sortingMeasurements != null) { - sortingMeasurements.removeAll(notChangedSortingMeasurements); - } - } - - } - - public void beanToEntity(SpeciesAbleBatchFrequency source, - SortingBatch target, - SortingBatch parentBatch, - short rankOrder) { - Preconditions.checkNotNull(source.getBatch()); - Preconditions.checkNotNull(source.getBatch().getId()); - - // If parent and root need to be set - if (target.getId() == null - || target.getRootBatch() == null - || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatch.getId()))) { - - target.setParentBatch(parentBatch); - target.setRootBatch(parentBatch.getRootBatch()); - } - - // --- RankOrder --- // - target.setRankOrder(rankOrder); - - // --- Individual count --- // - target.setIndividualCount(source.getNumber()); - - // --- Species --- // - target.setReferenceTaxon(null); - - // --- QualityFlag --- // - target.setQualityFlag(parentBatch.getQualityFlag()); - - // --- Exhaustive inventory (always true under a species batch) --- // - target.setExhaustiveInventory(true); - - // --- Sampling Ratio + QuantificationMeasurement --- // - batchTreeHelper.setWeightAndSampleRatio(target, source.getWeight(), null); - - // --- Sorting measurement --- // - { - Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); - Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); - if (sortingMeasurements != null) { - notChangedSortingMeasurements.addAll(sortingMeasurements); - } - if ((source.getLengthStepCaracteristic() != null && source.getLengthStep() != null)) { - Integer pmfmId = source.getLengthStepCaracteristic().getIdAsInt(); - SortingMeasurement sortingMeasurement = measurementPersistenceHelper.setSortingMeasurement(target, pmfmId, - source.getLengthStep()); - notChangedSortingMeasurements.remove(sortingMeasurement); - } - if (sortingMeasurements != null) { - sortingMeasurements.removeAll(notChangedSortingMeasurements); - } - } - + public void setSortingBatchReferenceTaxon(Integer batchId, Species species) { + catchBatchDao.setSortingBatchReferenceTaxon(String.valueOf(batchId), species.getReferenceTaxonId()); } +// public void setSpeciesBatchParents(Integer sampleCategoryId, +// Serializable sampleCategoryValue, +// SortingBatch target, +// Integer parentBatchId, +// CatchBatch catchBatch) { +// +// Preconditions.checkNotNull(target); +// Preconditions.checkNotNull(catchBatch); +// +// target.setRootBatch(catchBatch); +// +// SortingBatch parentBatch; +// if (parentBatchId != null) { +// +// // Load existing parent and root +// parentBatch = catchBatchDao.getSortingBatchById(catchBatch, parentBatchId); +// } else { +// +// // Or retrieve parent batch, from pmfm id +// // Retrieve category type +// if (!sampleCategoryId.equals(PmfmId.SORTED_UNSORTED.getValue())) { +// throw new DataIntegrityViolationException(MessageFormat.format( +// "A species or benthos batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", +// PmfmId.SORTED_UNSORTED.getValue(), +// sampleCategoryId)); +// } +// +// Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(sampleCategoryValue); +// +// if (QualitativeValueId.SORTED_VRAC.getValue().equals(qualitativeValueId)) { +// +// // -- Vrac > Species > Alive itemized +// parentBatch = batchTreeHelper.getSpeciesVracAliveItemizedRootBatch(catchBatch); +// +// if (parentBatch == null) { +// +// // -- Vrac +// SortingBatch vracBatch = batchTreeHelper.getVracBatch(catchBatch); +// +// if (vracBatch == null) { +// vracBatch = batchTreeHelper.getOrCreateVracBatch(catchBatch, null, null); +// } +// +// // -- Vrac > Species +// SortingBatch vracSpeciesBatch = batchTreeHelper.getSpeciesVracRootBatch(vracBatch); +// +// if (vracSpeciesBatch == null) { +// vracSpeciesBatch = batchTreeHelper.getOrCreateSpeciesVracRootBatch(catchBatch, vracBatch, null); +// } +// +// // -- Vrac > Species > Alive itemized +// parentBatch = batchTreeHelper.getOrCreateSpeciesVracAliveItemizedRootBatch(catchBatch, vracSpeciesBatch); +// +// } +// } else if (QualitativeValueId.SORTED_HORS_VRAC.getValue().equals(qualitativeValueId)) { +// +// // -- Hors Vrac > Species +// parentBatch = batchTreeHelper.getSpeciesHorsVracRootBatch(catchBatch); +// +// if (parentBatch == null) { +// +// // -- Hors Vrac +// SortingBatch horsVracBatch = batchTreeHelper.getOrCreateHorsVracBatch(catchBatch); +// +// // -- Hors Vrac > Species +// parentBatch = batchTreeHelper.getOrCreateSpeciesHorsVracRootBatch(catchBatch, horsVracBatch); +// } +// } else { +// +// // not possible +// throw new DataIntegrityViolationException("Should have Vrac / Hors Vrac qualitative value, but had: " + qualitativeValueId); +// } +// +// } +// +// Preconditions.checkNotNull(parentBatch); +// target.setParentBatch(parentBatch); +// } + +// public void setBenthosBatchParents(Integer sampleCategoryType, +// Serializable sampleCategoryValue, +// SortingBatch target, +// Integer parentBatchId, +// CatchBatch catchBatch) { +// +// Preconditions.checkNotNull(target); +// Preconditions.checkNotNull(catchBatch); +// +// target.setRootBatch(catchBatch); +// +// SortingBatch parentBatch; +// if (parentBatchId != null) { +// +// // Load existing parent and root +// parentBatch = catchBatchDao.getSortingBatchById(catchBatch, parentBatchId); +// } else { +// +// // Or retrieve parent batch, from pmfm id +// // Retrieve category type +// if (!sampleCategoryType.equals(PmfmId.SORTED_UNSORTED.getValue())) { +// throw new DataIntegrityViolationException(MessageFormat.format( +// "A species or benthos batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", +// sampleCategoryType, +// PmfmId.SORTED_UNSORTED.getValue())); +// } +// +// Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(sampleCategoryValue); +// +// if (QualitativeValueId.SORTED_VRAC.getValue().equals(qualitativeValueId)) { +// +// // -- Vrac > Benthos > Alive Itemized +// parentBatch = batchTreeHelper.getBenthosVracAliveItemizedRootBatch(catchBatch); +// +// if (parentBatch == null) { +// +// // -- Vrac +// SortingBatch vracBatch = batchTreeHelper.getVracBatch(catchBatch); +// +// if (vracBatch == null) { +// vracBatch = batchTreeHelper.getOrCreateVracBatch(catchBatch, null, null); +// } +// +// // -- Vrac > Benthos +// SortingBatch vracBenthosBatch = batchTreeHelper.getBenthosVracRootBatch(vracBatch); +// +// if (vracBenthosBatch == null) { +// vracBenthosBatch = batchTreeHelper.getOrCreateBenthosVracRootBatch(catchBatch, vracBatch, null); +// } +// +// // -- Vrac > Benthos > Alive itemized +// parentBatch = batchTreeHelper.getOrCreateBenthosVracAliveItemizedRootBatch(catchBatch, vracBenthosBatch); +// +// } +// } else if (QualitativeValueId.SORTED_HORS_VRAC.getValue().equals(qualitativeValueId)) { +// +// // -- Hors Vrac > Benthos +// parentBatch = batchTreeHelper.getBenthosHorsVracRootBatch(catchBatch); +// +// if (parentBatch == null) { +// +// // -- Hors Vrac +// SortingBatch horsVracBatch = batchTreeHelper.getOrCreateHorsVracBatch(catchBatch); +// +// // -- Hors Vrac > Benthos +// parentBatch = batchTreeHelper.getOrCreateBenthosHorsVracRootBatch(catchBatch, horsVracBatch); +// } +// } else { +// +// // not possible +// throw new DataIntegrityViolationException("Should have Vrac / Hors Vrac qualitative value, but had: " + qualitativeValueId); +// } +// } +// +// Preconditions.checkNotNull(parentBatch); +// target.setParentBatch(parentBatch); +// } - 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())) { +// public void setMarineLitterBatchParents(SortingBatch target, CatchBatch catchBatch) { // -// // 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); +// Preconditions.checkNotNull(target); +// +// // -- Hors Vrac > Marine Litter +// SortingBatch parentBatch = batchTreeHelper.getMarineLitterRootBatch(catchBatch); +// +// if (parentBatch == null) { +// +// // -- Hors Vrac +// SortingBatch horsVracBatch = batchTreeHelper.getOrCreateHorsVracBatch(catchBatch); +// +// // -- Hors Vrac > Marine Litter +// parentBatch = batchTreeHelper.getOrCreateMarineLitterRootBatch(catchBatch, horsVracBatch, null); +// } +// +// target.setParentBatch(parentBatch); +// target.setRootBatch(catchBatch); +// } + +// public void beanToEntity(Integer parentBatchId, +// SpeciesBatch source, +// SortingBatch target, +// boolean computeRankOrder) { +// +// // --- RankOrder (initialize once, at creation) --- // +// { +// if (target.getRankOrder() == null) { +// +// short rankOrder; +// +// if (computeRankOrder) { +// +// // Start rank order at 1 +// rankOrder = (short) 1; +// //FIXME : tchemit-2015-04-04 This code can not be used to save multiple batches at the same time, since it will always give the +// //FIXME : tchemit-2015-04-04 same values for all batches +// if (source.getParentBatch() != null && CollectionUtils.isNotEmpty(source.getParentBatch().getChildBatchs())) { +// int maxRankOrder = 0; +// for (SpeciesBatch batch : source.getParentBatch().getChildBatchs()) { +// Integer r = batch.getRankOrder(); +// if (r != null && r > maxRankOrder) { +// maxRankOrder = r; +// } +// } +// rankOrder += (short) maxRankOrder; +// +// } else { +// +// rankOrder = computeRankOrder(target); +// +// } +// +// } else { +// +// Preconditions.checkState(source.getRankOrder() != null, "Not using computeRankOrder requires source rankOrder to be not null, but was on batch: " + source); +// rankOrder = (short) (int) source.getRankOrder(); +// +// } +// +// target.setRankOrder(rankOrder); // // } - } +// } +// +// // --- Force subgroup count to '1', as Allegro --- // +// target.setSubgroupCount(1f); +// +// // --- Individual count --- // +// target.setIndividualCount(source.getNumber()); +// +// // --- Comments --- // +// target.setComments(source.getComment()); +// +// // --- Exhaustive inventory (always true under a species batch) --- // +// target.setExhaustiveInventory(true); +// +// // --- Species --- // +// { +// ReferenceTaxon referenceTaxon; +// if (source.getSpecies() == null || parentBatchId != null) { +// referenceTaxon = null; +// } else { +// referenceTaxon = load(ReferenceTaxonImpl.class, source.getSpecies().getReferenceTaxonId()); +// } +// target.setReferenceTaxon(referenceTaxon); +// } +// +// // --- QualityFlag --- // +// { +// String qualityFlag; +// if (source.isSpeciesToConfirm()) { +// qualityFlag = QualityFlagCode.DOUBTFUL.getValue(); +// } else { +// qualityFlag = QualityFlagCode.NOTQUALIFIED.getValue(); +// } +// target.setQualityFlag(load(QualityFlagImpl.class, qualityFlag)); +// } +// +// Float weight = source.getWeight(); +// Float sampleCategoryWeight = source.getSampleCategoryWeight(); +// +// // --- Sampling Ratio + QuantificationMeasurement --- // +// batchTreeHelper.setWeightAndSampleRatio(target, weight, sampleCategoryWeight); +// +// // --- Sorting measurement --- // +// { +// Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); +// Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); +// if (sortingMeasurements != null) { +// notChangedSortingMeasurements.addAll(sortingMeasurements); +// } +// +// if (source.getSampleCategoryId() != null && source.getSampleCategoryValue() != null) { +// Integer pmfmId = source.getSampleCategoryId(); +// // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch) +// if (!pmfmId.equals(PmfmId.SORTED_UNSORTED.getValue())) { +// SortingMeasurement sortingMeasurement = measurementPersistenceHelper.setSortingMeasurement( +// target, +// pmfmId, +// source.getSampleCategoryValue()); +// notChangedSortingMeasurements.remove(sortingMeasurement); +// } +// } +// if (sortingMeasurements != null) { +// sortingMeasurements.removeAll(notChangedSortingMeasurements); +// } +// } +// +// } + +// public void beanToEntity(SpeciesBatchFrequency source, +// SortingBatch target, +// SortingBatch parentBatch, +// short rankOrder) { +// Preconditions.checkNotNull(source.getBatch()); +// Preconditions.checkNotNull(source.getBatch().getId()); +// +// // If parent and root need to be set +// if (target.getId() == null +// || target.getRootBatch() == null +// || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatch.getId()))) { +// +// target.setParentBatch(parentBatch); +// target.setRootBatch(parentBatch.getRootBatch()); +// } +// +// // --- RankOrder --- // +// target.setRankOrder(rankOrder); +// +// // --- Individual count --- // +// target.setIndividualCount(source.getNumber()); +// +// // --- Species --- // +// target.setReferenceTaxon(null); +// +// // --- QualityFlag --- // +// target.setQualityFlag(parentBatch.getQualityFlag()); +// +// // --- Exhaustive inventory (always true under a species batch) --- // +// target.setExhaustiveInventory(true); +// +// // --- Sampling Ratio + QuantificationMeasurement --- // +// batchTreeHelper.setWeightAndSampleRatio(target, source.getWeight(), null); +// +// // --- Sorting measurement --- // +// { +// Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); +// Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); +// if (sortingMeasurements != null) { +// notChangedSortingMeasurements.addAll(sortingMeasurements); +// } +// if ((source.getLengthStepCaracteristic() != null && source.getLengthStep() != null)) { +// Integer pmfmId = source.getLengthStepCaracteristic().getIdAsInt(); +// SortingMeasurement sortingMeasurement = measurementPersistenceHelper.setSortingMeasurement(target, pmfmId, +// source.getLengthStep()); +// notChangedSortingMeasurements.remove(sortingMeasurement); +// } +// if (sortingMeasurements != null) { +// sortingMeasurements.removeAll(notChangedSortingMeasurements); +// } +// } +// +// } +// public 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 (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<SpeciesBatch> targetChilds = Lists.newArrayList(); +// for (Batch batch : source.getChildBatchs()) { +// SortingBatch sourceChild = (SortingBatch) batch; +// SpeciesBatch targetChild = SpeciesBatchs.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); +// 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 = 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 = 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; - - } +// +// QualityFlag qualityFlag = source.getQualityFlag(); +// target.setSpeciesToConfirm(qualityFlag != null && QualityFlagCode.DOUBTFUL.getValue().equals(qualityFlag.getCode())); +// +// return target; +// +// } public short computeRankOrder(SortingBatch target) { @@ -810,19 +789,19 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { } - public Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { - if (value == null) { - return null; - } - Integer qualitativeValueId = null; - if (value instanceof CaracteristicQualitativeValue) { - CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value; - qualitativeValueId = cqValue.getIdAsInt(); - } else if (value instanceof String) { - qualitativeValueId = Integer.valueOf((String) value); - } - return qualitativeValueId; - } +// public Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { +// if (value == null) { +// return null; +// } +// Integer qualitativeValueId = null; +// if (value instanceof CaracteristicQualitativeValue) { +// CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value; +// qualitativeValueId = cqValue.getIdAsInt(); +// } else if (value instanceof String) { +// qualitativeValueId = Integer.valueOf((String) value); +// } +// return qualitativeValueId; +// } public void deleteBatch(Integer batchId) { Preconditions.checkNotNull(batchId); @@ -833,144 +812,144 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { removeWithChildren(batchId); } - public void deleteSpeciesSubBatch(Integer speciesBatchId) { - Preconditions.checkNotNull(speciesBatchId); - - CatchBatch catchBatch = getRootCatchBatchByBatchId(speciesBatchId); - synchronizationStatusHelper.setDirty(catchBatch); - - SortingBatch sortingBatch = getSortingBatchById(catchBatch, speciesBatchId); - - // get his children - Collection<Batch> childBatchs = sortingBatch.getChildBatchs(); - - if (CollectionUtils.isNotEmpty(childBatchs)) { - - for (Batch childBatch : childBatchs) { - - // delete this child and all his children - Integer childBatchId = childBatch.getId(); - - if (log.isDebugEnabled()) { - log.debug("Delete child [" + childBatchId + "] of species batch: " + speciesBatchId); - } - removeWithChildren(childBatchId); - } - } - } - - public void changeBatchSpecies(Integer batchId, Species species) { - - Preconditions.checkNotNull(batchId); - Preconditions.checkNotNull(species); - Preconditions.checkNotNull(species.getReferenceTaxonId()); - - CatchBatch catchBatch = getRootCatchBatchByBatchId(batchId); - synchronizationStatusHelper.setDirty(catchBatch); - - catchBatchDao.setSortingBatchReferenceTaxon(String.valueOf(batchId), species.getReferenceTaxonId()); - } - - public <S extends SpeciesAbleBatch> void setSampleCategoryQualitative(S target, - Integer pmfmId, - Float numericalvalue, - String alphanumericalValue, - Integer qualitativeValueId) { - // skip if null or corresponding to the SORTING_TYPE PMFM (Espèce, Benthos, Plancton, etc.) - if (pmfmId == null || pmfmId.equals(BatchTreeHelper.SORTING_TYPE_ID)) { - return; - } - SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); - - boolean isSamplingCategory = sampleCategoryModel.containsCategoryId(pmfmId); - Preconditions.checkNotNull(isSamplingCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId); - - target.setSampleCategoryId(pmfmId); - Serializable categoryValue = getSampleCategoryQualitative( - pmfmId, - numericalvalue, - alphanumericalValue, - qualitativeValueId); - target.setSampleCategoryValue(categoryValue); - } - - public <F extends SpeciesAbleBatchFrequency & TuttiEntity> void entityToBatchFrequency(SortingBatch source, - F target) { - - target.setId(source.getId()); - - // Rank order - target.setRankOrder(Integer.valueOf(source.getRankOrder())); - - target.setNumber(source.getIndividualCount()); - target.setWeight(source.getWeight()); - - Preconditions.checkState(source.getSortingMeasurements().size() == 1, "SortingBatch [" + source.getId() + "] need exactly one sortingMeasurement (to store the length step category), but had " + source.getSortingMeasurements().size()); - SortingMeasurement sm = source.getSortingMeasurements().iterator().next(); - Preconditions.checkNotNull(sm.getPmfm(), "SortingMeasurement [" + sm.getId() + "] can not have a null pmfm"); - Preconditions.checkNotNull(sm.getPmfm().getId(), "SortingMeasurement [" + sm.getId() + "] can not have a pmfm with null id"); - - // Length step category - Caracteristic lengthStepCaracteristic = caracteristicService.getCaracteristic(sm.getPmfm().getId()); - target.setLengthStepCaracteristic(lengthStepCaracteristic); - - // Length - target.setLengthStep(sm.getNumericalValue()); - } - - public Serializable getSampleCategoryQualitative(Integer pmfmId, - Float numericalvalue, - String alphanumericalValue, - Integer qualitativeValueId) { - - if (numericalvalue != null) { - return numericalvalue; - } - if (alphanumericalValue != null) { - return alphanumericalValue; - } - - Caracteristic caracteristic = caracteristicService.getCaracteristic(pmfmId); - if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) { - return null; - } - CaracteristicQualitativeValue value = null; - for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { - if (qualitativeValueId.equals(qv.getIdAsInt())) { - value = qv; - break; - } - } - - return value; - } +// public void deleteSpeciesSubBatch(Integer speciesBatchId) { +// Preconditions.checkNotNull(speciesBatchId); +// +// CatchBatch catchBatch = getRootCatchBatchByBatchId(speciesBatchId); +// synchronizationStatusHelper.setDirty(catchBatch); +// +// SortingBatch sortingBatch = getSortingBatchById(catchBatch, speciesBatchId); +// +// // get his children +// Collection<Batch> childBatchs = sortingBatch.getChildBatchs(); +// +// if (CollectionUtils.isNotEmpty(childBatchs)) { +// +// for (Batch childBatch : childBatchs) { +// +// // delete this child and all his children +// Integer childBatchId = childBatch.getId(); +// +// if (log.isDebugEnabled()) { +// log.debug("Delete child [" + childBatchId + "] of species batch: " + speciesBatchId); +// } +// removeWithChildren(childBatchId); +// } +// } +// } - /** - * Check if the given {@code sortingBatch} is a frequency one. - * - * We test that: - * <ul> - * <li>batch has exactly one measurement</li> - * <li>the measurement pmfm is not a sample category</li> - * </ul> - * - * @param sampleCategoryModel model of authorized sample categories - * @param sortingBatch batch to check - * @return {@code true} if given batch is a frequency batch, - * {@code false} otherwise. - */ - public boolean isFrequencyBatch(SampleCategoryModel sampleCategoryModel, - SortingBatch sortingBatch) { - boolean result = false; - if (sortingBatch.getSortingMeasurements().size() == 1) { - SortingMeasurement sm - = sortingBatch.getSortingMeasurements().iterator().next(); - Pmfm pmfm = sm.getPmfm(); - - result = sortingBatch.getIndividualCount() != null && - !sampleCategoryModel.containsCategoryId(pmfm.getId()); - } - return result; - } +// public void changeBatchSpecies(Integer batchId, Species species) { +// +// Preconditions.checkNotNull(batchId); +// Preconditions.checkNotNull(species); +// Preconditions.checkNotNull(species.getReferenceTaxonId()); +// +// CatchBatch catchBatch = getRootCatchBatchByBatchId(batchId); +// synchronizationStatusHelper.setDirty(catchBatch); +// +// catchBatchDao.setSortingBatchReferenceTaxon(String.valueOf(batchId), species.getReferenceTaxonId()); +// } + +// public void setSampleCategoryQualitative(SpeciesBatch target, +// Integer pmfmId, +// Float numericalvalue, +// String alphanumericalValue, +// Integer qualitativeValueId) { +// // skip if null or corresponding to the SORTING_TYPE PMFM (Espèce, Benthos, Plancton, etc.) +// if (pmfmId == null || pmfmId.equals(BatchTreeHelper.SORTING_TYPE_ID)) { +// return; +// } +// SampleCategoryModel sampleCategoryModel = getSampleCategoryModel(); +// +// boolean isSamplingCategory = sampleCategoryModel.containsCategoryId(pmfmId); +// Preconditions.checkNotNull(isSamplingCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId); +// +// target.setSampleCategoryId(pmfmId); +// Serializable categoryValue = getSampleCategoryQualitative( +// pmfmId, +// numericalvalue, +// alphanumericalValue, +// qualitativeValueId); +// target.setSampleCategoryValue(categoryValue); +// } + +// public void entityToBatchFrequency(SortingBatch source, +// SpeciesBatchFrequency target) { +// +// target.setId(source.getId()); +// +// // Rank order +// target.setRankOrder(Integer.valueOf(source.getRankOrder())); +// +// target.setNumber(source.getIndividualCount()); +// target.setWeight(source.getWeight()); +// +// Preconditions.checkState(source.getSortingMeasurements().size() == 1, "SortingBatch [" + source.getId() + "] need exactly one sortingMeasurement (to store the length step category), but had " + source.getSortingMeasurements().size()); +// SortingMeasurement sm = source.getSortingMeasurements().iterator().next(); +// Preconditions.checkNotNull(sm.getPmfm(), "SortingMeasurement [" + sm.getId() + "] can not have a null pmfm"); +// Preconditions.checkNotNull(sm.getPmfm().getId(), "SortingMeasurement [" + sm.getId() + "] can not have a pmfm with null id"); +// +// // Length step category +// Caracteristic lengthStepCaracteristic = caracteristicService.getCaracteristic(sm.getPmfm().getId()); +// target.setLengthStepCaracteristic(lengthStepCaracteristic); +// +// // Length +// target.setLengthStep(sm.getNumericalValue()); +// } + +// public Serializable getSampleCategoryQualitative(Integer pmfmId, +// Float numericalvalue, +// String alphanumericalValue, +// Integer qualitativeValueId) { +// +// if (numericalvalue != null) { +// return numericalvalue; +// } +// if (alphanumericalValue != null) { +// return alphanumericalValue; +// } +// +// Caracteristic caracteristic = caracteristicService.getCaracteristic(pmfmId); +// if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) { +// return null; +// } +// CaracteristicQualitativeValue value = null; +// for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { +// if (qualitativeValueId.equals(qv.getIdAsInt())) { +// value = qv; +// break; +// } +// } +// +// return value; +// } + +// /** +// * Check if the given {@code sortingBatch} is a frequency one. +// * +// * We test that: +// * <ul> +// * <li>batch has exactly one measurement</li> +// * <li>the measurement pmfm is not a sample category</li> +// * </ul> +// * +// * @param sampleCategoryModel model of authorized sample categories +// * @param sortingBatch batch to check +// * @return {@code true} if given batch is a frequency batch, +// * {@code false} otherwise. +// */ +// public boolean isFrequencyBatch(SampleCategoryModel sampleCategoryModel, +// SortingBatch sortingBatch) { +// boolean result = false; +// if (sortingBatch.getSortingMeasurements().size() == 1) { +// SortingMeasurement sm +// = sortingBatch.getSortingMeasurements().iterator().next(); +// Pmfm pmfm = sm.getPmfm(); +// +// result = sortingBatch.getIndividualCount() != null && +// !sampleCategoryModel.containsCategoryId(pmfm.getId()); +// } +// return result; +// } } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchTreeHelper.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchTreeHelper.java deleted file mode 100644 index c441b01..0000000 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchTreeHelper.java +++ /dev/null @@ -1,713 +0,0 @@ -package fr.ifremer.tutti.persistence.service.util; - -/* - * #%L - * Tutti :: Persistence - * %% - * Copyright (C) 2012 - 2014 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Joiner; -import com.google.common.collect.Sets; -import fr.ifremer.adagio.core.dao.data.batch.Batch; -import fr.ifremer.adagio.core.dao.data.batch.Batchs; -import fr.ifremer.adagio.core.dao.data.batch.CatchBatch; -import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; -import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; -import fr.ifremer.adagio.core.dao.data.measure.QuantificationMeasurement; -import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement; -import fr.ifremer.adagio.core.dao.referential.QualityFlagCode; -import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl; -import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; -import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; -import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxon; -import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl; -import fr.ifremer.tutti.persistence.service.AbstractPersistenceService; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.SystemUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - -/** - * Helper to build or navigauet into the batch tree. - * - * Created on 4/20/14. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.5 - */ -@Component("batchTreeHelper") -public class BatchTreeHelper extends AbstractPersistenceService { - - public static final Integer SORTING_TYPE_ID = PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE.getValue(); - - public static final Integer SORTING_TYPE2_ID = PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE2.getValue(); - - /** Logger. */ - private static final Log log = LogFactory.getLog(BatchTreeHelper.class); - - @Resource(name = "measurementPersistenceHelper") - protected MeasurementPersistenceHelper measurementPersistenceHelper; - - @Resource(name = "catchBatchDao") - protected CatchBatchExtendDao catchBatchDao; - - protected Comparator<Batch> batchComparator = Batchs.newRankOrderComparator(); - - //------------------------------------------------------------------------// - //-- Get CatchBatch navigation methods --// - //------------------------------------------------------------------------// - - public SortingBatch getSpeciesVracAliveItemizedRootBatch(CatchBatch batch) { - return getSortingBatch( - batch, - "Vrac > Species > Alive Itemized", - PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_VRAC.getValue(), - SORTING_TYPE_ID, QualitativeValueId.SORTING_TYPE_SPECIES.getValue(), - SORTING_TYPE2_ID, QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue() - ); - } - - public SortingBatch getBenthosVracAliveItemizedRootBatch(CatchBatch batch) { - return getSortingBatch( - batch, - "Vrac > Benthos > Alive itemized", - PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_VRAC.getValue(), - SORTING_TYPE_ID, QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(), - SORTING_TYPE2_ID, QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue() - ); - } - - public SortingBatch getSpeciesHorsVracRootBatch(CatchBatch batch) { - return getSortingBatch( - batch, - "Hors Vrac > Species", - PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_HORS_VRAC.getValue(), - SORTING_TYPE_ID, QualitativeValueId.SORTING_TYPE_SPECIES.getValue() - ); - } - - public SortingBatch getBenthosHorsVracRootBatch(CatchBatch batch) { - return getSortingBatch( - batch, - "Hors Vrac > Benthos", - PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_HORS_VRAC.getValue(), - SORTING_TYPE_ID, QualitativeValueId.SORTING_TYPE_BENTHOS.getValue() - ); - } - - public SortingBatch getMarineLitterRootBatch(CatchBatch batch) { - return getSortingBatch( - batch, - "Hors Vrac > Marine Litter", - PmfmId.SORTED_UNSORTED.getValue(), - QualitativeValueId.SORTED_HORS_VRAC.getValue(), - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue() - ); - } - - public SortingBatch getVracBatch(CatchBatch batch) { - return getSortingBatch( - batch, - "Vrac", - PmfmId.SORTED_UNSORTED.getValue(), - QualitativeValueId.SORTED_VRAC.getValue() - ); - } - - public SortingBatch getHorsVracBatch(CatchBatch batch) { - return getSortingBatch( - batch, - "Hors Vrac", - PmfmId.SORTED_UNSORTED.getValue(), - QualitativeValueId.SORTED_HORS_VRAC.getValue() - ); - } - - public SortingBatch getRejectedBatch(CatchBatch batch) { - return getSortingBatch( - batch, - "Unsorted", - PmfmId.SORTED_UNSORTED.getValue(), - QualitativeValueId.UNSORTED.getValue() - ); - } - - //------------------------------------------------------------------------// - //-- Get SortingBatch navigation methods --// - //------------------------------------------------------------------------// - - public SortingBatch getSpeciesVracRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Vrac > Species", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_SPECIES.getValue() - ); - } - - public SortingBatch getBenthosVracRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Vrac > Benthos", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_BENTHOS.getValue() - ); - } - - public SortingBatch getSpeciesVracAliveNotItemizedRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Vrac > Species > Alive not itemized", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue() - ); - } - - public SortingBatch getBenthosVracAliveNotItemizedRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Vrac > Benthos > Alive not itemized", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue() - ); - } - - public SortingBatch getSpeciesVracInertRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Vrac > Species > Inert (not alive)", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_INERT.getValue() - ); - } - - public SortingBatch getBenthosVracInertRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Vrac > Benthos > Inert (not alive)", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_INERT.getValue() - ); - } - - public SortingBatch getSpeciesVracAliveItemizedRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Vrac > Species > Alive itemized", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue() - ); - } - - public SortingBatch getBenthosVracAliveItemizedRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Vrac > Benthos > Alive itemized", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue() - ); - } - - public SortingBatch getSpeciesHorsVracRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Hors Vrac > Species", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_SPECIES.getValue() - ); - } - - public SortingBatch getBenthosHorsVracRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Hors Vrac > Benthos", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_BENTHOS.getValue() - ); - } - - public SortingBatch getMarineLitterRootBatch(SortingBatch batch) { - return getSortingBatch( - batch, - "Hors Vrac > MarineLitter", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue() - ); - } - - //------------------------------------------------------------------------// - //-- getOrCreate methods --// - //------------------------------------------------------------------------// - - public SortingBatch getOrCreateVracBatch(CatchBatch batch, - Float weight, - Float weightBeforeSampling) { - return getOrCreate( - batch, - batch, - "Vrac", - PmfmId.SORTED_UNSORTED.getValue(), - QualitativeValueId.SORTED_VRAC.getValue(), - weight, - weightBeforeSampling, - (short) 1 - ); - } - - public SortingBatch getOrCreateSpeciesVracRootBatch(CatchBatch target, - SortingBatch batch, - Float totalWeight) { - return getOrCreate( - target, - batch, - "Vrac > Species", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_SPECIES.getValue(), - totalWeight, - (short) 1 - ); - } - - public SortingBatch getOrCreateSpeciesVracAliveNotItemizedRootBatch(CatchBatch target, - SortingBatch batch, - Float totalWeight) { - return getOrCreate( - target, - batch, - "Vrac > Species > Alive Not Itemized", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue(), - totalWeight, - (short) 1 - ); - } - - public SortingBatch getOrCreateSpeciesVracInertRootBatch(CatchBatch target, - SortingBatch batch, - Float totalWeight) { - return getOrCreate( - target, - batch, - "Vrac > Species > Inert", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_INERT.getValue(), - totalWeight, - (short) 2 - ); - } - - public SortingBatch getOrCreateSpeciesVracAliveItemizedRootBatch(CatchBatch target, - SortingBatch batch) { - return getOrCreate( - target, - batch, - "Vrac > Benthos > Alive Itemized", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue(), - (short) 3 - ); - } - - public SortingBatch getOrCreateBenthosVracRootBatch(CatchBatch target, - SortingBatch batch, - Float totalWeight) { - return getOrCreate( - target, - batch, - "Vrac > Benthos", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(), - totalWeight, - (short) 2 - ); - } - - public SortingBatch getOrCreateBenthosVracAliveNotItemizedRootBatch(CatchBatch target, - SortingBatch batch, - Float totalWeight) { - return getOrCreate( - target, - batch, - "Vrac > Benthos > Alive Not itemized", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue(), - totalWeight, - (short) 1 - ); - } - - public SortingBatch getOrCreateBenthosVracInertRootBatch(fr.ifremer.adagio.core.dao.data.batch.CatchBatch target, - SortingBatch batch, - Float totalWeight) { - return getOrCreate( - target, - batch, - "Vrac > Benthos > Inert", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_INERT.getValue(), - totalWeight, - (short) 2 - ); - } - - public SortingBatch getOrCreateBenthosVracAliveItemizedRootBatch(CatchBatch target, - SortingBatch batch) { - return getOrCreate( - target, - batch, - "Vrac > Benthos > Alive Itemized", - SORTING_TYPE2_ID, - QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue(), - (short) 3 - ); - } - - public SortingBatch getOrCreateHorsVracBatch(CatchBatch batch) { - return getOrCreate( - batch, - batch, - "Hors Vrac", - PmfmId.SORTED_UNSORTED.getValue(), - QualitativeValueId.SORTED_HORS_VRAC.getValue(), - (short) 2 - ); - } - - public SortingBatch getOrCreateSpeciesHorsVracRootBatch(CatchBatch target, - SortingBatch batch) { - return getOrCreate( - target, - batch, - "Hors Vrac > Species", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_SPECIES.getValue(), - (short) 1 - ); - } - - public SortingBatch getOrCreateBenthosHorsVracRootBatch(CatchBatch target, - SortingBatch batch) { - return getOrCreate( - target, - batch, - "Hors Vrac > Benthos", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(), - (short) 2 - ); - } - - public SortingBatch getOrCreateMarineLitterRootBatch(CatchBatch target, - SortingBatch batch, - Float totalWeight) { - return getOrCreate( - target, - batch, - "Hors Vrac > Marine Litter", - SORTING_TYPE_ID, - QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue(), - totalWeight, - (short) 3 - ); - } - - public SortingBatch getOrCreateRejectedBatch(CatchBatch batch, - Float weight) { - - return getOrCreate( - batch, - batch, - "Unsorted", - PmfmId.SORTED_UNSORTED.getValue(), - QualitativeValueId.UNSORTED.getValue(), - weight, - (short) 3 - ); - } - - public void setWeightAndSampleRatio(SortingBatch target, Float weight, Float weightBeforeSampling) { - - catchBatchDao.setSortingBatchWeights(target, - weight, - weightBeforeSampling, - PmfmId.WEIGHT_MEASURED.getValue(), - measurementPersistenceHelper.getRecorderDepartmentId()); - - } - - public void setSortingSamplingRatio(SortingBatch target, Float weight, Float weightBeforeSampling) { - - catchBatchDao.setSortingSamplingRatio(target, - weight, - weightBeforeSampling); - - } - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - - protected SortingBatch get(Batch parentBatch, - Integer sortingPmfmId, - Integer sortingQualitativeValueId) { - return getSortingBatch( - parentBatch, - null, - sortingPmfmId, - sortingQualitativeValueId); - } - - protected SortingBatch getSortingBatch(Batch source, - String debugMessage, - Integer... ids) { - - return getSortingBatch(source.getChildBatchs(), debugMessage, ids); - } - - protected SortingBatch getSortingBatch(Collection<Batch> childs, - String debugMessage, - Integer... ids) { - - int nbParams = ids.length / 2; - - Object[] params = new Object[nbParams * 3]; - for (int i = 0; i < nbParams; i++) { - Integer sortingPmfmId = ids[2 * i]; - Integer sortingQualitativeValueId = ids[2 * i + 1]; - params[3 * i] = CatchBatchExtendDao.PMFM_ID; - params[3 * i + 1] = sortingPmfmId; - params[3 * i + 2] = sortingQualitativeValueId; - } - SortingBatch result = catchBatchDao.getSortingBatch(childs, params); - if (result != null && debugMessage != null && log.isDebugEnabled()) { - log.debug("Loaded " + debugMessage + ": " + result.getId()); - } - return result; - } - - protected SortingBatch getOrCreate(fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, - Batch batch, - String debugMessage, - Integer sortingPmfmId, - Integer sortingQualitativeValueId, - short rankOrder) { - return getOrCreate( - rootBatch, - batch, - debugMessage, - sortingPmfmId, - sortingQualitativeValueId, - null, - null, - rankOrder - ); - } - - protected SortingBatch getOrCreate(fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, - Batch batch, - String debugMessage, - Integer sortingPmfmId, - Integer sortingQualitativeValueId, - Float totalWeight, - short rankOrder) { - return getOrCreate( - rootBatch, - batch, - debugMessage, - sortingPmfmId, - sortingQualitativeValueId, - totalWeight, - null, - rankOrder - ); - } - - protected SortingBatch getOrCreate(fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, - Batch batch, - String debugMessage, - Integer sortingPmfmId, - Integer sortingQualitativeValueId, - Float weight, - Float weightBeforeSampling, - short rankOrder) { - - SortingBatch result = getSortingBatch( - batch, - debugMessage, - sortingPmfmId, - sortingQualitativeValueId); - - if (result == null) { - - result = SortingBatch.Factory.newInstance(); - if (batch.getChildBatchs() == null) { - batch.setChildBatchs(Sets.<Batch>newHashSet()); - } - batch.getChildBatchs().add(result); - - // --- Some mandatory properties --- // - - QualityFlagImpl qualityFlag = load(QualityFlagImpl.class, QualityFlagCode.NOTQUALIFIED.getValue()); - result.setQualityFlag(qualityFlag); - result.setRootBatch(rootBatch); - result.setParentBatch(batch); - result.setExhaustiveInventory(true); - result.setRankOrder(rankOrder); - - // No taxon or taxon group - result.setReferenceTaxon(null); - result.setTaxonGroup(null); - - // --- Sorting measurement --- // - - Collection<SortingMeasurement> sortingMeasurements = result.getSortingMeasurements(); - Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); - if (sortingMeasurements != null) { - notChangedSortingMeasurements.addAll(sortingMeasurements); - } - - if (sortingPmfmId != null && sortingQualitativeValueId != null) { - SortingMeasurement sm = measurementPersistenceHelper.setSortingMeasurement( - result, - sortingPmfmId, - sortingQualitativeValueId); - notChangedSortingMeasurements.remove(sm); - } - if (sortingMeasurements != null) { - sortingMeasurements.removeAll(notChangedSortingMeasurements); - } - - catchBatchDao.createSortingBatch(result, rootBatch); - } - - // --- Sampling Ratio + QuantificationMeasurement --- // - - setWeightAndSampleRatio(result, weight, weightBeforeSampling); - - return result; - } - - //------------------------------------------------------------------------// - //-- Debug methods --// - //------------------------------------------------------------------------// - - public void displayCatchBatch(CatchBatch result) { - StringBuilder sb = new StringBuilder(); - displayBatch(result, 0, sb); - log.info(sb.toString()); - } - - protected void displayBatch(Batch batch, int level, StringBuilder sb) { - - ToStringStyle style = new BatchTreeToStringStyle(); - - ToStringBuilder builder = new ToStringBuilder(batch, style); - builder.append("id", batch.getId()); - builder.append("rankOrder", batch.getRankOrder()); - - if (batch instanceof CatchBatch) { - CatchBatch catchBatch = (CatchBatch) batch; - builder.append("synchronizationStatus", catchBatch.getSynchronizationStatus()); - } - if (batch instanceof SortingBatch) { - SortingBatch sortingBatch = (SortingBatch) batch; - if (sortingBatch.getSamplingRatio() != null) { - builder.append("samplingRatio", sortingBatch.getSamplingRatio()); - } - if (sortingBatch.getSamplingRatioText() != null) { - builder.append("samplingRatioText", sortingBatch.getSamplingRatioText()); - } - if (sortingBatch.getIndividualCount() != null) { - builder.append("individualCount", sortingBatch.getIndividualCount()); - } - if (sortingBatch.getReferenceTaxon() != null) { - ReferenceTaxon referenceTaxon = sortingBatch.getReferenceTaxon(); - builder.append("referenceTaxon", load(ReferenceTaxonImpl.class, referenceTaxon.getId()).getName()); - } - - SortingMeasurement sm = null; - if (sortingBatch.getSortingMeasurements() != null && sortingBatch.getSortingMeasurements().size() == 1) { - sm = sortingBatch.getSortingMeasurements().iterator().next(); - } else if (sortingBatch.getReferenceTaxon() != null && sortingBatch.getReferenceTaxon().getId() != null) { - sm = measurementPersistenceHelper.getInheritedSortingMeasurement(sortingBatch); - } - if (sm != null) { - String sortingMeasurementStr = measurementPersistenceHelper.toString(sm); - builder.append("sortingMeasurement", sortingMeasurementStr); - } - } - QuantificationMeasurement quantificationMeasurement = measurementPersistenceHelper.getWeightMeasurementQuantificationMeasurement(batch); - if (quantificationMeasurement != null) { - String quantificationMeasurementStr = measurementPersistenceHelper.toString(quantificationMeasurement); - builder.append("weightQuantificationMeasurement", quantificationMeasurementStr); - builder.append("weightQuantificationMeasurement.isReferenceQuantification", quantificationMeasurement.getIsReferenceQuantification()); - } - if (batch.getWeight() != null) { - builder.append("weight", batch.getWeight()); - } - if (batch.getWeightBeforeSampling() != null) { - builder.append("weightBeforeSampling", batch.getWeightBeforeSampling()); - } - builder.append("qualityFlag", load(QualityFlagImpl.class, batch.getQualityFlag().getCode()).getName()); - - String prefix = "\n" + StringUtils.leftPad("", 2 * level); - String batchStr = Joiner.on(prefix).join(builder.build().split("\n")); - sb.append(prefix).append(batchStr); - Collection<Batch> childBatchs = batch.getChildBatchs(); - if (childBatchs != null) { - List<Batch> childBatchList = new ArrayList<>(childBatchs); - Collections.sort(childBatchList, batchComparator); - for (Batch childBatch : childBatchList) { - displayBatch(childBatch, level + 1, sb); - } - } - } - - public CatchBatch loadCatchBatch(Integer catchBatchId) { - return catchBatchDao.loadFullTreeWithCache(catchBatchId, PmfmId.WEIGHT_MEASURED.getValue(), true, true); - } - - - static final class BatchTreeToStringStyle extends ToStringStyle { - - private static final long serialVersionUID = 1L; - - BatchTreeToStringStyle() { - super(); - this.setUseClassName(true); - this.setUseShortClassName(true); - this.setContentStart(""); - this.setFieldSeparator(SystemUtils.LINE_SEPARATOR + " | "); - this.setFieldSeparatorAtStart(true); - this.setContentEnd(""); - } - } -} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BatchTreeHelper.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BatchTreeHelper.java new file mode 100644 index 0000000..29481c3 --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BatchTreeHelper.java @@ -0,0 +1,330 @@ +package fr.ifremer.tutti.persistence.service.util.tree; + +/* + * #%L + * Tutti :: Persistence + * %% + * Copyright (C) 2012 - 2014 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.adagio.core.dao.data.batch.CatchBatch; +import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; +import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * Helper to build or navigauet into the batch tree. + * + * Created on 4/20/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.5 + */ +@Component("batchTreeHelper") +public class BatchTreeHelper extends BatchTreeHelperSupport { + +// /** Logger. */ +// private static final Log log = LogFactory.getLog(BatchTreeHelper.class); + + @Resource(name = "benthosBatchTreeHelper") + protected BenthosBatchTreeHelper benthosBatchTreeHelper; + + @Resource(name = "speciesBatchTreeHelper") + protected SpeciesBatchTreeHelper speciesBatchTreeHelper; + + //------------------------------------------------------------------------// + //-- Get CatchBatch navigation methods --// + //------------------------------------------------------------------------// + +// public SortingBatch getSpeciesVracAliveItemizedRootBatch(CatchBatch batch) { +// return speciesBatchTreeHelper.getVracAliveItemizedRootBatch(batch); +// } +// +// public SortingBatch getBenthosVracAliveItemizedRootBatch(CatchBatch batch) { +// return benthosBatchTreeHelper.getVracAliveItemizedRootBatch(batch); +// } +// +// public SortingBatch getSpeciesHorsVracRootBatch(CatchBatch batch) { +// return speciesBatchTreeHelper.getHorsVracRootBatch(batch); +// } +// +// public SortingBatch getBenthosHorsVracRootBatch(CatchBatch batch) { +// return benthosBatchTreeHelper.getHorsVracRootBatch(batch); +// } + + public SortingBatch getMarineLitterRootBatch(CatchBatch batch) { + return getSortingBatch(batch, + "Hors Vrac > Marine Litter", + PmfmId.SORTED_UNSORTED.getValue(), + QualitativeValueId.SORTED_HORS_VRAC.getValue(), + SORTING_TYPE_ID, + QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue()); + } + +// public SortingBatch getVracBatch(CatchBatch batch) { +// return getSortingBatch( +// batch, +// "Vrac", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.SORTED_VRAC.getValue() +// ); +// } + +// public SortingBatch getHorsVracBatch(CatchBatch batch) { +// return getSortingBatch( +// batch, +// "Hors Vrac", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.SORTED_HORS_VRAC.getValue() +// ); +// } +// + public SortingBatch getRejectedBatch(CatchBatch batch) { + return getSortingBatch( + batch, + "Unsorted", + PmfmId.SORTED_UNSORTED.getValue(), + QualitativeValueId.UNSORTED.getValue() + ); + } + + //------------------------------------------------------------------------// + //-- Get SortingBatch navigation methods --// + //------------------------------------------------------------------------// + + public SortingBatch getSpeciesVracRootBatch(SortingBatch batch) { + return speciesBatchTreeHelper.getVracRootBatch(batch); + } + + public SortingBatch getBenthosVracRootBatch(SortingBatch batch) { + return benthosBatchTreeHelper.getVracRootBatch(batch); + } + + public SortingBatch getSpeciesVracAliveNotItemizedRootBatch(SortingBatch batch) { + return speciesBatchTreeHelper.getVracAliveNotItemizedRootBatch(batch); + } + + public SortingBatch getBenthosVracAliveNotItemizedRootBatch(SortingBatch batch) { + return benthosBatchTreeHelper.getVracAliveNotItemizedRootBatch(batch); + } + + public SortingBatch getSpeciesVracInertRootBatch(SortingBatch batch) { + return speciesBatchTreeHelper.getVracInertRootBatch(batch); + } + + public SortingBatch getBenthosVracInertRootBatch(SortingBatch batch) { + return benthosBatchTreeHelper.getVracInertRootBatch(batch); + } + + public SortingBatch getSpeciesVracAliveItemizedRootBatch(SortingBatch batch) { + return speciesBatchTreeHelper.getVracAliveItemizedRootBatch(batch); + } + + public SortingBatch getBenthosVracAliveItemizedRootBatch(SortingBatch batch) { + return benthosBatchTreeHelper.getVracAliveItemizedRootBatch(batch); + } + + public SortingBatch getSpeciesHorsVracRootBatch(SortingBatch batch) { + return speciesBatchTreeHelper.getHorsVracRootBatch(batch); + } + + public SortingBatch getBenthosHorsVracRootBatch(SortingBatch batch) { + return benthosBatchTreeHelper.getHorsVracRootBatch(batch); + } + + public SortingBatch getMarineLitterRootBatch(SortingBatch batch) { + return getSortingBatch( + batch, + "Hors Vrac > MarineLitter", + SORTING_TYPE_ID, + QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue()); + } + + //------------------------------------------------------------------------// + //-- getOrCreate methods --// + //------------------------------------------------------------------------// + +// public SortingBatch getOrCreateVracBatch(CatchBatch batch, Float weight, Float weightBeforeSampling) { +// return getOrCreate(batch, +// batch, +// "Vrac", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.SORTED_VRAC.getValue(), +// weight, +// weightBeforeSampling, +// (short) 1); +// } + + public SortingBatch getOrCreateSpeciesVracRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return speciesBatchTreeHelper.getOrCreateVracRootBatch(target, batch, totalWeight); +// target, +// batch, +// "Vrac > Species", +// SORTING_TYPE_ID, +// QualitativeValueId.SORTING_TYPE_SPECIES.getValue(), +// totalWeight, +// (short) 1 +// ); + } + + public SortingBatch getOrCreateSpeciesVracAliveNotItemizedRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return speciesBatchTreeHelper.getOrCreateVracAliveNotItemizedRootBatch(target, batch, totalWeight); +// return getOrCreate( +// target, +// batch, +// "Vrac > Species > Alive Not Itemized", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue(), +// totalWeight, +// (short) 1 +// ); + } + + public SortingBatch getOrCreateSpeciesVracInertRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return speciesBatchTreeHelper.getOrCreateVracInertRootBatch(target, batch, totalWeight); +// return getOrCreate( +// target, +// batch, +// "Vrac > Species > Inert", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_INERT.getValue(), +// totalWeight, +// (short) 2 +// ); + } + + public SortingBatch getOrCreateSpeciesVracAliveItemizedRootBatch(CatchBatch target, SortingBatch batch) { + return speciesBatchTreeHelper.getOrCreateVracAliveItemizedRootBatch(target, batch); +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos > Alive Itemized", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue(), +// (short) 3 +// ); + } + + public SortingBatch getOrCreateBenthosVracRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return benthosBatchTreeHelper.getOrCreateVracRootBatch(target, batch, totalWeight); +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos", +// SORTING_TYPE_ID, +// QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(), +// totalWeight, +// (short) 2 +// ); + } + + public SortingBatch getOrCreateBenthosVracAliveNotItemizedRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return benthosBatchTreeHelper.getOrCreateVracAliveNotItemizedRootBatch(target, batch, totalWeight); +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos > Alive Not itemized", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue(), +// totalWeight, +// (short) 1 +// ); + } + + public SortingBatch getOrCreateBenthosVracInertRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return benthosBatchTreeHelper.getOrCreateVracInertRootBatch(target, batch, totalWeight); +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos > Inert", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_INERT.getValue(), +// totalWeight, +// (short) 2 +// ); + } + + public SortingBatch getOrCreateBenthosVracAliveItemizedRootBatch(CatchBatch target, SortingBatch batch) { + return benthosBatchTreeHelper.getOrCreateVracAliveItemizedRootBatch(target, batch); +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos > Alive Itemized", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue(), +// (short) 3 +// ); + } + +// public SortingBatch getOrCreateHorsVracBatch(CatchBatch batch) { +// return getOrCreate(batch, +// batch, +// "Hors Vrac", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.SORTED_HORS_VRAC.getValue(), +// (short) 2); +// } + + public SortingBatch getOrCreateSpeciesHorsVracRootBatch(CatchBatch target, SortingBatch batch) { + return speciesBatchTreeHelper.getOrCreateHorsVracRootBatch(target, batch); +// return getOrCreate( +// target, +// batch, +// "Hors Vrac > Species", +// SORTING_TYPE_ID, +// QualitativeValueId.SORTING_TYPE_SPECIES.getValue(), +// (short) 1 +// ); + } + + public SortingBatch getOrCreateBenthosHorsVracRootBatch(CatchBatch target, SortingBatch batch) { + return benthosBatchTreeHelper.getOrCreateHorsVracRootBatch(target, batch); +// return getOrCreate( +// target, +// batch, +// "Hors Vrac > Benthos", +// SORTING_TYPE_ID, +// QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(), +// (short) 2 +// ); + } + + public SortingBatch getOrCreateMarineLitterRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return getOrCreate(target, + batch, + "Hors Vrac > Marine Litter", + SORTING_TYPE_ID, + QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue(), + totalWeight, + (short) 3); + } + + public SortingBatch getOrCreateRejectedBatch(CatchBatch batch, Float weight) { + return getOrCreate(batch, + batch, + "Unsorted", + PmfmId.SORTED_UNSORTED.getValue(), + QualitativeValueId.UNSORTED.getValue(), + weight, + (short) 3); + } + +} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BatchTreeHelperSupport.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BatchTreeHelperSupport.java new file mode 100644 index 0000000..b93a17b --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BatchTreeHelperSupport.java @@ -0,0 +1,365 @@ +package fr.ifremer.tutti.persistence.service.util.tree; + +/* + * #%L + * Tutti :: Persistence + * %% + * Copyright (C) 2012 - 2014 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Joiner; +import com.google.common.collect.Sets; +import fr.ifremer.adagio.core.dao.data.batch.Batch; +import fr.ifremer.adagio.core.dao.data.batch.Batchs; +import fr.ifremer.adagio.core.dao.data.batch.CatchBatch; +import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; +import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; +import fr.ifremer.adagio.core.dao.data.measure.QuantificationMeasurement; +import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement; +import fr.ifremer.adagio.core.dao.referential.QualityFlagCode; +import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl; +import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; +import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxon; +import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl; +import fr.ifremer.tutti.persistence.service.AbstractPersistenceService; +import fr.ifremer.tutti.persistence.service.util.MeasurementPersistenceHelper; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Set; + +/** + * Helper to build or navigauet into the batch tree. + * + * Created on 4/20/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.5 + */ +public abstract class BatchTreeHelperSupport extends AbstractPersistenceService { + + public static final Integer SORTING_TYPE_ID = PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE.getValue(); + + public static final Integer SORTING_TYPE2_ID = PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE2.getValue(); + + /** Logger. */ + private static final Log log = LogFactory.getLog(BatchTreeHelperSupport.class); + + @Resource(name = "measurementPersistenceHelper") + protected MeasurementPersistenceHelper measurementPersistenceHelper; + + @Resource(name = "catchBatchDao") + protected CatchBatchExtendDao catchBatchDao; + + protected Comparator<Batch> batchComparator = Batchs.newRankOrderComparator(); + + //------------------------------------------------------------------------// + //-- Get CatchBatch navigation methods --// + //------------------------------------------------------------------------// + + public final SortingBatch getVracBatch(CatchBatch batch) { + return getSortingBatch(batch, + "Vrac", + PmfmId.SORTED_UNSORTED.getValue(), + QualitativeValueId.SORTED_VRAC.getValue()); + } + + public final SortingBatch getHorsVracBatch(CatchBatch batch) { + return getSortingBatch(batch, + "Hors Vrac", + PmfmId.SORTED_UNSORTED.getValue(), + QualitativeValueId.SORTED_HORS_VRAC.getValue()); + } + + public final SortingBatch getOrCreateVracBatch(CatchBatch batch, Float weight, Float weightBeforeSampling) { + return getOrCreate(batch, + batch, + "Vrac", + PmfmId.SORTED_UNSORTED.getValue(), + QualitativeValueId.SORTED_VRAC.getValue(), + weight, + weightBeforeSampling, + (short) 1); + } + + public final SortingBatch getOrCreateHorsVracBatch(CatchBatch batch) { + return getOrCreate(batch, + batch, + "Hors Vrac", + PmfmId.SORTED_UNSORTED.getValue(), + QualitativeValueId.SORTED_HORS_VRAC.getValue(), + (short) 2); + } + + public final void setWeightAndSampleRatio(SortingBatch target, Float weight, Float weightBeforeSampling) { + + catchBatchDao.setSortingBatchWeights(target, + weight, + weightBeforeSampling, + PmfmId.WEIGHT_MEASURED.getValue(), + measurementPersistenceHelper.getRecorderDepartmentId()); + + } + + public final void setSortingSamplingRatio(SortingBatch target, Float weight, Float weightBeforeSampling) { + + catchBatchDao.setSortingSamplingRatio(target, weight, weightBeforeSampling); + + } + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected final SortingBatch get(Batch parentBatch, Integer sortingPmfmId, Integer sortingQualitativeValueId) { + return getSortingBatch( + parentBatch, + null, + sortingPmfmId, + sortingQualitativeValueId); + } + + protected final SortingBatch getSortingBatch(Batch source, String debugMessage, Integer... ids) { + + return getSortingBatch(source.getChildBatchs(), debugMessage, ids); + } + + protected final SortingBatch getSortingBatch(Collection<Batch> childs, String debugMessage, Integer... ids) { + + int nbParams = ids.length / 2; + + Object[] params = new Object[nbParams * 3]; + for (int i = 0; i < nbParams; i++) { + Integer sortingPmfmId = ids[2 * i]; + Integer sortingQualitativeValueId = ids[2 * i + 1]; + params[3 * i] = CatchBatchExtendDao.PMFM_ID; + params[3 * i + 1] = sortingPmfmId; + params[3 * i + 2] = sortingQualitativeValueId; + } + SortingBatch result = catchBatchDao.getSortingBatch(childs, params); + if (result != null && debugMessage != null && log.isDebugEnabled()) { + log.debug("Loaded " + debugMessage + ": " + result.getId()); + } + return result; + } + + protected final SortingBatch getOrCreate(CatchBatch rootBatch, + Batch batch, + String debugMessage, + Integer sortingPmfmId, + Integer sortingQualitativeValueId, + short rankOrder) { + return getOrCreate(rootBatch, + batch, + debugMessage, + sortingPmfmId, + sortingQualitativeValueId, + null, + null, + rankOrder); + } + + protected final SortingBatch getOrCreate(CatchBatch rootBatch, + Batch batch, + String debugMessage, + Integer sortingPmfmId, + Integer sortingQualitativeValueId, + Float totalWeight, + short rankOrder) { + return getOrCreate(rootBatch, + batch, + debugMessage, + sortingPmfmId, + sortingQualitativeValueId, + totalWeight, + null, + rankOrder); + } + + protected final SortingBatch getOrCreate(CatchBatch rootBatch, + Batch batch, + String debugMessage, + Integer sortingPmfmId, + Integer sortingQualitativeValueId, + Float weight, + Float weightBeforeSampling, + short rankOrder) { + + SortingBatch result = getSortingBatch( + batch, + debugMessage, + sortingPmfmId, + sortingQualitativeValueId); + + if (result == null) { + + result = SortingBatch.Factory.newInstance(); + if (batch.getChildBatchs() == null) { + batch.setChildBatchs(Sets.<Batch>newHashSet()); + } + batch.getChildBatchs().add(result); + + // --- Some mandatory properties --- // + + QualityFlagImpl qualityFlag = load(QualityFlagImpl.class, QualityFlagCode.NOTQUALIFIED.getValue()); + result.setQualityFlag(qualityFlag); + result.setRootBatch(rootBatch); + result.setParentBatch(batch); + result.setExhaustiveInventory(true); + result.setRankOrder(rankOrder); + + // No taxon or taxon group + result.setReferenceTaxon(null); + result.setTaxonGroup(null); + + // --- Sorting measurement --- // + + Collection<SortingMeasurement> sortingMeasurements = result.getSortingMeasurements(); + Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); + if (sortingMeasurements != null) { + notChangedSortingMeasurements.addAll(sortingMeasurements); + } + + if (sortingPmfmId != null && sortingQualitativeValueId != null) { + SortingMeasurement sm = measurementPersistenceHelper.setSortingMeasurement( + result, + sortingPmfmId, + sortingQualitativeValueId); + notChangedSortingMeasurements.remove(sm); + } + if (sortingMeasurements != null) { + sortingMeasurements.removeAll(notChangedSortingMeasurements); + } + + catchBatchDao.createSortingBatch(result, rootBatch); + } + + // --- Sampling Ratio + QuantificationMeasurement --- // + + setWeightAndSampleRatio(result, weight, weightBeforeSampling); + + return result; + } + + //------------------------------------------------------------------------// + //-- Debug methods --// + //------------------------------------------------------------------------// + + public final void displayCatchBatch(CatchBatch result) { + StringBuilder sb = new StringBuilder(); + displayBatch(result, 0, sb); + log.info(sb.toString()); + } + + protected final void displayBatch(Batch batch, int level, StringBuilder sb) { + + ToStringStyle style = new BatchTreeToStringStyle(); + + ToStringBuilder builder = new ToStringBuilder(batch, style); + builder.append("id", batch.getId()); + builder.append("rankOrder", batch.getRankOrder()); + + if (batch instanceof CatchBatch) { + CatchBatch catchBatch = (CatchBatch) batch; + builder.append("synchronizationStatus", catchBatch.getSynchronizationStatus()); + } + if (batch instanceof SortingBatch) { + SortingBatch sortingBatch = (SortingBatch) batch; + if (sortingBatch.getSamplingRatio() != null) { + builder.append("samplingRatio", sortingBatch.getSamplingRatio()); + } + if (sortingBatch.getSamplingRatioText() != null) { + builder.append("samplingRatioText", sortingBatch.getSamplingRatioText()); + } + if (sortingBatch.getIndividualCount() != null) { + builder.append("individualCount", sortingBatch.getIndividualCount()); + } + if (sortingBatch.getReferenceTaxon() != null) { + ReferenceTaxon referenceTaxon = sortingBatch.getReferenceTaxon(); + builder.append("referenceTaxon", load(ReferenceTaxonImpl.class, referenceTaxon.getId()).getName()); + } + + SortingMeasurement sm = null; + if (sortingBatch.getSortingMeasurements() != null && sortingBatch.getSortingMeasurements().size() == 1) { + sm = sortingBatch.getSortingMeasurements().iterator().next(); + } else if (sortingBatch.getReferenceTaxon() != null && sortingBatch.getReferenceTaxon().getId() != null) { + sm = measurementPersistenceHelper.getInheritedSortingMeasurement(sortingBatch); + } + if (sm != null) { + String sortingMeasurementStr = measurementPersistenceHelper.toString(sm); + builder.append("sortingMeasurement", sortingMeasurementStr); + } + } + QuantificationMeasurement quantificationMeasurement = measurementPersistenceHelper.getWeightMeasurementQuantificationMeasurement(batch); + if (quantificationMeasurement != null) { + String quantificationMeasurementStr = measurementPersistenceHelper.toString(quantificationMeasurement); + builder.append("weightQuantificationMeasurement", quantificationMeasurementStr); + builder.append("weightQuantificationMeasurement.isReferenceQuantification", quantificationMeasurement.getIsReferenceQuantification()); + } + if (batch.getWeight() != null) { + builder.append("weight", batch.getWeight()); + } + if (batch.getWeightBeforeSampling() != null) { + builder.append("weightBeforeSampling", batch.getWeightBeforeSampling()); + } + builder.append("qualityFlag", load(QualityFlagImpl.class, batch.getQualityFlag().getCode()).getName()); + + String prefix = "\n" + StringUtils.leftPad("", 2 * level); + String batchStr = Joiner.on(prefix).join(builder.build().split("\n")); + sb.append(prefix).append(batchStr); + Collection<Batch> childBatchs = batch.getChildBatchs(); + if (childBatchs != null) { + List<Batch> childBatchList = new ArrayList<>(childBatchs); + Collections.sort(childBatchList, batchComparator); + for (Batch childBatch : childBatchList) { + displayBatch(childBatch, level + 1, sb); + } + } + } + + public final CatchBatch loadCatchBatch(Integer catchBatchId) { + return catchBatchDao.loadFullTreeWithCache(catchBatchId, PmfmId.WEIGHT_MEASURED.getValue(), true, true); + } + + + static final class BatchTreeToStringStyle extends ToStringStyle { + + private static final long serialVersionUID = 1L; + + BatchTreeToStringStyle() { + super(); + this.setUseClassName(true); + this.setUseShortClassName(true); + this.setContentStart(""); + this.setFieldSeparator(SystemUtils.LINE_SEPARATOR + " | "); + this.setFieldSeparatorAtStart(true); + this.setContentEnd(""); + } + } +} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BenthosBatchTreeHelper.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BenthosBatchTreeHelper.java new file mode 100644 index 0000000..a43b4f1 --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/BenthosBatchTreeHelper.java @@ -0,0 +1,43 @@ +package fr.ifremer.tutti.persistence.service.util.tree; + +/* + * #%L + * Tutti :: Persistence + * %% + * Copyright (C) 2012 - 2014 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; +import org.springframework.stereotype.Component; + +/** + * Helper to build or navigate into the benthos batch tree. + * + * Created on 4/20/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.5 + */ +@Component("benthosBatchTreeHelper") +public class BenthosBatchTreeHelper extends SpeciesBatchTreeHelperSupport { + + public BenthosBatchTreeHelper() { + super("Benthos", QualitativeValueId.SORTING_TYPE_BENTHOS, (short)2); + } + +} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/SpeciesBatchTreeHelper.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/SpeciesBatchTreeHelper.java new file mode 100644 index 0000000..7e313e2 --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/SpeciesBatchTreeHelper.java @@ -0,0 +1,43 @@ +package fr.ifremer.tutti.persistence.service.util.tree; + +/* + * #%L + * Tutti :: Persistence + * %% + * Copyright (C) 2012 - 2014 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; +import org.springframework.stereotype.Component; + +/** + * Helper to build or navigate into the species batch tree. + * + * Created on 4/20/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.5 + */ +@Component("speciesBatchTreeHelper") +public class SpeciesBatchTreeHelper extends SpeciesBatchTreeHelperSupport { + + public SpeciesBatchTreeHelper() { + super("Species", QualitativeValueId.SORTING_TYPE_SPECIES, (short)1); + } + +} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/SpeciesBatchTreeHelperSupport.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/SpeciesBatchTreeHelperSupport.java new file mode 100644 index 0000000..0ef0ec8 --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/tree/SpeciesBatchTreeHelperSupport.java @@ -0,0 +1,424 @@ +package fr.ifremer.tutti.persistence.service.util.tree; + +/* + * #%L + * Tutti :: Persistence + * %% + * Copyright (C) 2012 - 2014 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.adagio.core.dao.data.batch.CatchBatch; +import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; +import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import org.springframework.dao.DataIntegrityViolationException; + +import java.io.Serializable; +import java.text.MessageFormat; + +/** + * Helper to build or navigauet into the batch tree. + * + * Created on 4/20/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.5 + */ +public abstract class SpeciesBatchTreeHelperSupport extends BatchTreeHelperSupport { + + private final String prefix; + + private final QualitativeValueId sortingType; + + private final short rootBatchRankOrder; + + protected SpeciesBatchTreeHelperSupport(String prefix, QualitativeValueId sortingType, short rootBatchRankOrder) { + this.prefix = prefix; + this.sortingType = sortingType; + this.rootBatchRankOrder = rootBatchRankOrder; + } + + + public void setBatchParents(Integer sampleCategoryId, + Serializable sampleCategoryValue, + SortingBatch target, + Integer parentBatchId, + CatchBatch catchBatch) { + + Preconditions.checkNotNull(target); + Preconditions.checkNotNull(catchBatch); + + target.setRootBatch(catchBatch); + + SortingBatch parentBatch; + if (parentBatchId != null) { + + // Load existing parent and root + parentBatch = catchBatchDao.getSortingBatchById(catchBatch, parentBatchId); + } else { + + // Or retrieve parent batch, from pmfm id + // Retrieve category type + if (!sampleCategoryId.equals(PmfmId.SORTED_UNSORTED.getValue())) { + throw new DataIntegrityViolationException(MessageFormat.format( + "A species or benthos batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", + PmfmId.SORTED_UNSORTED.getValue(), + sampleCategoryId)); + } + + Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(sampleCategoryValue); + + if (QualitativeValueId.SORTED_VRAC.getValue().equals(qualitativeValueId)) { + + // -- Vrac > Species > Alive itemized + parentBatch = getVracAliveItemizedRootBatch(catchBatch); + + if (parentBatch == null) { + + // -- Vrac + SortingBatch vracBatch = getVracBatch(catchBatch); + + if (vracBatch == null) { + vracBatch = getOrCreateVracBatch(catchBatch, null, null); + } + + // -- Vrac > Species + SortingBatch vracSpeciesBatch = getVracRootBatch(vracBatch); + + if (vracSpeciesBatch == null) { + vracSpeciesBatch = getOrCreateVracRootBatch(catchBatch, vracBatch, null); + } + + // -- Vrac > Species > Alive itemized + parentBatch = getOrCreateVracAliveItemizedRootBatch(catchBatch, vracSpeciesBatch); + + } + } else if (QualitativeValueId.SORTED_HORS_VRAC.getValue().equals(qualitativeValueId)) { + + // -- Hors Vrac > Species + parentBatch = getHorsVracRootBatch(catchBatch); + + if (parentBatch == null) { + + // -- Hors Vrac + SortingBatch horsVracBatch = getOrCreateHorsVracBatch(catchBatch); + + // -- Hors Vrac > Species + parentBatch = getOrCreateHorsVracRootBatch(catchBatch, horsVracBatch); + } + } else { + + // not possible + throw new DataIntegrityViolationException("Should have Vrac / Hors Vrac qualitative value, but had: " + qualitativeValueId); + } + + } + + Preconditions.checkNotNull(parentBatch); + target.setParentBatch(parentBatch); + } + + //------------------------------------------------------------------------// + //-- Get CatchBatch navigation methods --// + //------------------------------------------------------------------------// + + public SortingBatch getVracAliveItemizedRootBatch(CatchBatch batch) { + return getSortingBatch(batch, + "Vrac > " + prefix + " > Alive Itemized", + PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_VRAC.getValue(), + SORTING_TYPE_ID, sortingType.getValue(), + SORTING_TYPE2_ID, QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue()); + } + + public SortingBatch getHorsVracRootBatch(CatchBatch batch) { + return getSortingBatch(batch, + "Hors Vrac > " + prefix, + PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_HORS_VRAC.getValue(), + SORTING_TYPE_ID, sortingType.getValue()); + } + +// public SortingBatch getVracBatch(CatchBatch batch) { +// return getSortingBatch( +// batch, +// "Vrac", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.SORTED_VRAC.getValue() +// ); +// } +// +// public SortingBatch getHorsVracBatch(CatchBatch batch) { +// return getSortingBatch( +// batch, +// "Hors Vrac", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.SORTED_HORS_VRAC.getValue() +// ); +// } + +// public SortingBatch getRejectedBatch(CatchBatch batch) { +// return getSortingBatch( +// batch, +// "Unsorted", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.UNSORTED.getValue() +// ); +// } + + //------------------------------------------------------------------------// + //-- Get SortingBatch navigation methods --// + //------------------------------------------------------------------------// + + public SortingBatch getVracRootBatch(SortingBatch batch) { + return getSortingBatch(batch, + "Vrac > " + prefix, + SORTING_TYPE_ID, + sortingType.getValue()); + } + + public SortingBatch getVracAliveNotItemizedRootBatch(SortingBatch batch) { + return getSortingBatch(batch, + "Vrac > " + prefix + " > Alive not itemized", + SORTING_TYPE2_ID, + QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue()); + } + +// public SortingBatch getBenthosVracAliveNotItemizedRootBatch(SortingBatch batch) { +// return getSortingBatch( +// batch, +// "Vrac > Benthos > Alive not itemized", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue() +// ); +// } + + public SortingBatch getVracInertRootBatch(SortingBatch batch) { + return getSortingBatch(batch, + "Vrac > " + prefix + " > Inert (not alive)", + SORTING_TYPE2_ID, + QualitativeValueId.SORTING_TYPE2_INERT.getValue()); + } + +// public SortingBatch getBenthosVracInertRootBatch(SortingBatch batch) { +// return getSortingBatch( +// batch, +// "Vrac > Benthos > Inert (not alive)", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_INERT.getValue() +// ); +// } + + public SortingBatch getVracAliveItemizedRootBatch(SortingBatch batch) { + return getSortingBatch(batch, + "Vrac > " + prefix + "> Alive itemized", + SORTING_TYPE2_ID, + QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue()); + } + +// public SortingBatch getBenthosVracAliveItemizedRootBatch(SortingBatch batch) { +// return getSortingBatch( +// batch, +// "Vrac > Benthos > Alive itemized", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue() +// ); +// } + + public SortingBatch getHorsVracRootBatch(SortingBatch batch) { + return getSortingBatch(batch, + "Hors Vrac > " + prefix, + SORTING_TYPE_ID, + QualitativeValueId.SORTING_TYPE_SPECIES.getValue()); + } + +// public SortingBatch getBenthosHorsVracRootBatch(SortingBatch batch) { +// return getSortingBatch( +// batch, +// "Hors Vrac > Benthos", +// SORTING_TYPE_ID, +// QualitativeValueId.SORTING_TYPE_BENTHOS.getValue() +// ); +// } + + //------------------------------------------------------------------------// + //-- getOrCreate methods --// + //------------------------------------------------------------------------// + +// public SortingBatch getOrCreateVracBatch(CatchBatch batch, Float weight, Float weightBeforeSampling) { +// return getOrCreate(batch, +// batch, +// "Vrac", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.SORTED_VRAC.getValue(), +// weight, +// weightBeforeSampling, +// (short) 1); +// } + + public SortingBatch getOrCreateVracRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return getOrCreate( + target, + batch, + "Vrac > " + prefix, + SORTING_TYPE_ID, + sortingType.getValue(), + totalWeight, + rootBatchRankOrder + ); + } + + public SortingBatch getOrCreateVracAliveNotItemizedRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return getOrCreate( + target, + batch, + "Vrac > " + prefix + " > Alive Not Itemized", + SORTING_TYPE2_ID, + QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue(), + totalWeight, + (short) 1 + ); + } + + public SortingBatch getOrCreateVracInertRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) { + return getOrCreate( + target, + batch, + "Vrac > " + prefix + " > Inert", + SORTING_TYPE2_ID, + QualitativeValueId.SORTING_TYPE2_INERT.getValue(), + totalWeight, + (short) 2 + ); + } + + public SortingBatch getOrCreateVracAliveItemizedRootBatch(CatchBatch target, SortingBatch batch) { + return getOrCreate( + target, + batch, + "Vrac > " + prefix + " > Alive Itemized", + SORTING_TYPE2_ID, + QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue(), + (short) 3 + ); + } + +// public SortingBatch getOrCreateBenthosVracRootBatch(CatchBatch target, +// SortingBatch batch, +// Float totalWeight) { +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos", +// SORTING_TYPE_ID, +// QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(), +// totalWeight, +// (short) 2 +// ); +// } + +// public SortingBatch getOrCreateBenthosVracAliveNotItemizedRootBatch(CatchBatch target, +// SortingBatch batch, +// Float totalWeight) { +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos > Alive Not itemized", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue(), +// totalWeight, +// (short) 1 +// ); +// } + +// public SortingBatch getOrCreateBenthosVracInertRootBatch(CatchBatch target, +// SortingBatch batch, +// Float totalWeight) { +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos > Inert", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_INERT.getValue(), +// totalWeight, +// (short) 2 +// ); +// } + +// public SortingBatch getOrCreateBenthosVracAliveItemizedRootBatch(CatchBatch target, +// SortingBatch batch) { +// return getOrCreate( +// target, +// batch, +// "Vrac > Benthos > Alive Itemized", +// SORTING_TYPE2_ID, +// QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue(), +// (short) 3 +// ); +// } + +// public SortingBatch getOrCreateHorsVracBatch(CatchBatch batch) { +// return getOrCreate( +// batch, +// batch, +// "Hors Vrac", +// PmfmId.SORTED_UNSORTED.getValue(), +// QualitativeValueId.SORTED_HORS_VRAC.getValue(), +// (short) 2 +// ); +// } + + public SortingBatch getOrCreateHorsVracRootBatch(CatchBatch target, SortingBatch batch) { + return getOrCreate( + target, + batch, + "Hors Vrac > " + prefix, + SORTING_TYPE_ID, + sortingType.getValue(), + rootBatchRankOrder + ); + } + +// public SortingBatch getOrCreateBenthosHorsVracRootBatch(CatchBatch target, +// SortingBatch batch) { +// return getOrCreate( +// target, +// batch, +// "Hors Vrac > Benthos", +// SORTING_TYPE_ID, +// QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(), +// (short) 2 +// ); +// } + + + private Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { + if (value == null) { + return null; + } + Integer qualitativeValueId = null; + if (value instanceof CaracteristicQualitativeValue) { + CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value; + qualitativeValueId = cqValue.getIdAsInt(); + } else if (value instanceof String) { + qualitativeValueId = Integer.valueOf((String) value); + } + return qualitativeValueId; + } + +} diff --git a/tutti-persistence/src/main/xmi/tutti-persistence.properties b/tutti-persistence/src/main/xmi/tutti-persistence.properties index 9606d6f..d92795b 100644 --- a/tutti-persistence/src/main/xmi/tutti-persistence.properties +++ b/tutti-persistence/src/main/xmi/tutti-persistence.properties @@ -37,7 +37,6 @@ fr.ifremer.tutti.persistence.entities.data.FishingOperation.attribute.recorderPe fr.ifremer.tutti.persistence.entities.data.FishingOperation.attribute.secondaryVessel.stereotype=ordered fr.ifremer.tutti.persistence.entities.data.SpeciesBatch.attribute.childBatchs.stereotype=ordered -fr.ifremer.tutti.persistence.entities.data.BenthosBatch.attribute.childBatchs.stereotype=ordered fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol.attribute.caracteristicMapping.stereotype=ordered fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol.attribute.individualObservationPmfmId.stereotype=ordered diff --git a/tutti-persistence/src/main/xmi/tutti-persistence.zargo b/tutti-persistence/src/main/xmi/tutti-persistence.zargo index dd234c0..c721325 100644 Binary files a/tutti-persistence/src/main/xmi/tutti-persistence.zargo and b/tutti-persistence/src/main/xmi/tutti-persistence.zargo differ diff --git a/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java b/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java index ca8210d..4342cbd 100644 --- a/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java +++ b/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java @@ -25,7 +25,6 @@ package fr.ifremer.tutti.persistence.service; import com.google.common.collect.Maps; import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; @@ -158,18 +157,18 @@ public class BenthosBatchPersistenceServiceReadTest { } } - public BenthosBatch getBenthosBatch(Integer fishingOperationId, + public SpeciesBatch getBenthosBatch(Integer fishingOperationId, Integer speciesBatchId) { - BatchContainer<BenthosBatch> rootSpeciesBatch = service.getRootBenthosBatch(fishingOperationId, false); + BatchContainer<SpeciesBatch> rootSpeciesBatch = service.getRootBenthosBatch(fishingOperationId, false); return getBenthosBatch(speciesBatchId, rootSpeciesBatch.getChildren()); } - public static BenthosBatch getBenthosBatch(Integer speciesBatchId, - List<BenthosBatch> speciesBatchs) { + public static SpeciesBatch getBenthosBatch(Integer speciesBatchId, + List<SpeciesBatch> speciesBatchs) { if (speciesBatchs == null) { return null; } - for (BenthosBatch speciesBatch : speciesBatchs) { + for (SpeciesBatch speciesBatch : speciesBatchs) { if (speciesBatchId.equals(speciesBatch.getId())) { return speciesBatch; } diff --git a/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java b/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java index 3fd2ddd..6ccd158 100644 --- a/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java +++ b/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java @@ -25,14 +25,14 @@ package fr.ifremer.tutti.persistence.service; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequencys; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchs; 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.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequencys; +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.CaracteristicType; @@ -199,8 +199,8 @@ public class BenthosBatchPersistenceServiceWriteTest { List<Caracteristic> cara = caracteristicService.getAllCaracteristic(); for (Caracteristic caracteristic : cara) { if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER - && caracteristic.getPrecision() != null - && caracteristic.getPrecision() == 0.5f) { + && caracteristic.getPrecision() != null + && caracteristic.getPrecision() == 0.5f) { frequencyPMFM = caracteristic; break; } @@ -211,10 +211,10 @@ public class BenthosBatchPersistenceServiceWriteTest { @Test public void createAndSaveBenthosBatchAndFrequencies() { - BenthosBatch esp1Batch; - BenthosBatch esp2Batch; - BenthosBatch frequenciesParentBatch; - BenthosBatch batch; + SpeciesBatch esp1Batch; + SpeciesBatch esp2Batch; + SpeciesBatch frequenciesParentBatch; + SpeciesBatch batch; Species taxon1 = species.get(0); Species taxon2 = species.get(1); @@ -222,7 +222,7 @@ public class BenthosBatchPersistenceServiceWriteTest { // 1. Test with only mandatory properties // ----------------------------------------------------------------------------- // batch : "ESP1 - Vrac/5" - batch = BenthosBatchs.newBenthosBatch(); + batch = SpeciesBatchs.newBenthosBatch(); batch.setParentBatch(null); batch.setFishingOperation(fishingOperationNoCatchBatch); batch.setSpecies(taxon1); @@ -239,7 +239,7 @@ public class BenthosBatchPersistenceServiceWriteTest { // 2. Test child "Male/2" // ----------------------------------------------------------------------------- // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7 - batch = BenthosBatchs.newBenthosBatch(); + batch = SpeciesBatchs.newBenthosBatch(); batch.setId((String) null); batch.setParentBatch(esp1Batch); batch.setSpecies(taxon1); @@ -256,7 +256,7 @@ public class BenthosBatchPersistenceServiceWriteTest { // 3. Test child "Female/2" // ----------------------------------------------------------------------------- // Batch : ESP1 - Vrac/5 Female/3 Nombre/14 - batch = BenthosBatchs.newBenthosBatch(); + batch = SpeciesBatchs.newBenthosBatch(); batch.setId((String) null); batch.setParentBatch(esp1Batch); batch.setSpecies(taxon1); @@ -274,7 +274,7 @@ public class BenthosBatchPersistenceServiceWriteTest { // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 // ----------------------------------------------------------------------------- // batch : "ESP2 - Vrac/7 " - batch = BenthosBatchs.newBenthosBatch(); + batch = SpeciesBatchs.newBenthosBatch(); batch.setParentBatch(null); batch.setSpecies(taxon2); batch.setSampleCategoryId(PmfmId.SORTED_UNSORTED.getValue()); @@ -285,7 +285,7 @@ public class BenthosBatchPersistenceServiceWriteTest { esp2Batch = batch; // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 - batch = BenthosBatchs.newBenthosBatch(); + batch = SpeciesBatchs.newBenthosBatch(); batch.setId((String) null); batch.setParentBatch(esp2Batch); batch.setSpecies(taxon2); @@ -311,9 +311,9 @@ public class BenthosBatchPersistenceServiceWriteTest { batch.setNumber(99); // Save and reload, then check - BenthosBatch savedBatch = service.saveBenthosBatch(batch); + SpeciesBatch savedBatch = service.saveBenthosBatch(batch); assertBenthosBatch(savedBatch, batch, false); - BenthosBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getIdAsInt(), savedBatch.getIdAsInt()); + SpeciesBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getIdAsInt(), savedBatch.getIdAsInt()); assertBenthosBatch(savedBatch, reloadedBatch, true); // Save batch for later @@ -331,7 +331,7 @@ public class BenthosBatchPersistenceServiceWriteTest { // ----------------------------------------------------------------------------- // 7. Test get all root species // ----------------------------------------------------------------------------- - List<BenthosBatch> rootBenthosBatch = service.getRootBenthosBatch(fishingOperationWithEmptyBatch.getIdAsInt(), false).getChildren(); + List<SpeciesBatch> rootBenthosBatch = service.getRootBenthosBatch(fishingOperationWithEmptyBatch.getIdAsInt(), false).getChildren(); assertNotNull(rootBenthosBatch); assertEquals(2, rootBenthosBatch.size()); assertNotNull(rootBenthosBatch.get(0).getChildBatchs()); @@ -343,10 +343,10 @@ public class BenthosBatchPersistenceServiceWriteTest { // 8. Test batch frequency creation // ----------------------------------------------------------------------------- - List<BenthosBatchFrequency> frequencies = Lists.newArrayList(); + List<SpeciesBatchFrequency> frequencies = Lists.newArrayList(); float lengthStep = 0.5f; for (float length = lengthStep; length < lengthStep * 20; length += lengthStep) { - BenthosBatchFrequency frequency = BenthosBatchFrequencys.newBenthosBatchFrequency(); + SpeciesBatchFrequency frequency = SpeciesBatchFrequencys.newBenthosBatchFrequency(); frequency.setLengthStep(length); frequency.setNumber((int) (length * 2)); frequency.setWeight(0.01f * length * 2); @@ -354,13 +354,13 @@ public class BenthosBatchPersistenceServiceWriteTest { frequency.setBatch(frequenciesParentBatch); frequencies.add(frequency); } - List<BenthosBatchFrequency> createdFrequencies = assertCreateAndReloadBenthosBatchFrequency(frequencies, frequenciesParentBatch.getIdAsInt()); + List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadBenthosBatchFrequency(frequencies, frequenciesParentBatch.getIdAsInt()); // ----------------------------------------------------------------------------- // 9. Test batch frequency update // ----------------------------------------------------------------------------- // Update some batchs (1cm, 2cm, etc) - for (BenthosBatchFrequency speciesBatchFrequency : createdFrequencies) { + for (SpeciesBatchFrequency speciesBatchFrequency : createdFrequencies) { float length = speciesBatchFrequency.getLengthStep(); if ((float) (int) length == length) { speciesBatchFrequency.setNumber(12); @@ -371,21 +371,21 @@ public class BenthosBatchPersistenceServiceWriteTest { createdFrequencies = Lists.newArrayList(createdFrequencies); createdFrequencies.remove(createdFrequencies.size() - 1); - List<BenthosBatchFrequency> savedFrequencies = service.saveBenthosBatchFrequency(frequenciesParentBatch.getIdAsInt(), createdFrequencies); + List<SpeciesBatchFrequency> savedFrequencies = service.saveBenthosBatchFrequency(frequenciesParentBatch.getIdAsInt(), createdFrequencies); assertBatchFrequencies(createdFrequencies, savedFrequencies, true); } @Test public void deleteBenthosBatch(/* String id */) { - BenthosBatch esp1Batch; - BenthosBatch batch; + SpeciesBatch esp1Batch; + SpeciesBatch batch; Species taxon1 = species.get(0); // ----------------------------------------------------------------------------- // 1. Create two batchs (parent + child), then remove the parent batch // ----------------------------------------------------------------------------- // batch : ESP1 Vrac/5 - batch = BenthosBatchs.newBenthosBatch(); + batch = SpeciesBatchs.newBenthosBatch(); batch.setParentBatch(null); batch.setFishingOperation(fishingOperationWithEmptyBatch); batch.setSpecies(taxon1); @@ -396,7 +396,7 @@ public class BenthosBatchPersistenceServiceWriteTest { esp1Batch = batch; // batch : ESP1 Vrac/5 Male/2 - batch = BenthosBatchs.newBenthosBatch(); + batch = SpeciesBatchs.newBenthosBatch(); batch.setParentBatch(esp1Batch); batch.setFishingOperation(fishingOperationWithEmptyBatch); batch.setSpecies(taxon1); @@ -417,15 +417,15 @@ public class BenthosBatchPersistenceServiceWriteTest { } } - protected void assertCreateAndReloadBenthosBatch(BenthosBatch batch, Integer parentBatchId) { + protected void assertCreateAndReloadBenthosBatch(SpeciesBatch batch, Integer parentBatchId) { batch.setFishingOperation(fishingOperationWithEmptyBatch); // Create batch - BenthosBatch createdBatch = service.createBenthosBatch(batch, parentBatchId, true); + SpeciesBatch createdBatch = service.createBenthosBatch(batch, parentBatchId, true); assertBenthosBatch(batch, createdBatch, false); // then reload (for round trip check) - BenthosBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getIdAsInt(), createdBatch.getIdAsInt()); + SpeciesBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getIdAsInt(), createdBatch.getIdAsInt()); if (parentBatchId == null) { assertNull(reloadedBatch.getParentBatch()); } else { @@ -437,7 +437,7 @@ public class BenthosBatchPersistenceServiceWriteTest { batch.setId(createdBatch.getId()); } - protected void assertBenthosBatch(BenthosBatch expectedBatch, BenthosBatch actualBatch, boolean assertIdEquals) { + protected void assertBenthosBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { assertNotNull(actualBatch); assertNotNull(actualBatch.getId()); if (assertIdEquals && expectedBatch.getId() != null) { @@ -447,7 +447,7 @@ public class BenthosBatchPersistenceServiceWriteTest { assertEquals(expectedBatch.getSampleCategoryId(), actualBatch.getSampleCategoryId()); if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) { assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() - + "> but was <null>", + + "> but was <null>", actualBatch.getSampleCategoryValue() ); assertEquals( @@ -464,40 +464,40 @@ public class BenthosBatchPersistenceServiceWriteTest { // (Because getBenthosBatch(id) could not always retrieve the species) if (expectedBatch.getSpecies() != null && ( PmfmId.SORTED_UNSORTED.getValue().equals(expectedBatch.getSampleCategoryId()) - || actualBatch.getSpecies() != null)) { + || actualBatch.getSpecies() != null)) { assertNotNull(actualBatch.getSpecies()); assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); } } - protected List<BenthosBatchFrequency> assertCreateAndReloadBenthosBatchFrequency(List<BenthosBatchFrequency> frequencies, Integer parentBatchId) { + protected List<SpeciesBatchFrequency> assertCreateAndReloadBenthosBatchFrequency(List<SpeciesBatchFrequency> frequencies, Integer parentBatchId) { // Create batch - List<BenthosBatchFrequency> createdFrequencies = service.saveBenthosBatchFrequency(parentBatchId, frequencies); + List<SpeciesBatchFrequency> createdFrequencies = service.saveBenthosBatchFrequency(parentBatchId, frequencies); assertBatchFrequencies(frequencies, createdFrequencies, false); // then reload (for round trip check) - List<BenthosBatchFrequency> reloadedFrequencies = service.getAllBenthosBatchFrequency(parentBatchId); + List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllBenthosBatchFrequency(parentBatchId); assertBatchFrequencies(createdFrequencies, reloadedFrequencies, true); return createdFrequencies; } - protected void assertBatchFrequencies(List<BenthosBatchFrequency> expectedFrequencies, - List<BenthosBatchFrequency> actualFrequencies, + protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, + List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) { assertNotNull(actualFrequencies); assertEquals(expectedFrequencies.size(), actualFrequencies.size()); // Store actual batches into a map, using the length as key - Map<Float, BenthosBatchFrequency> expectedLengthMap = Maps.newHashMap(); - for (BenthosBatchFrequency speciesBatchFrequency : expectedFrequencies) { + Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap(); + for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) { expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); } // Store expected batches into a map, using the length as key - Map<Float, BenthosBatchFrequency> actualLengthMap = Maps.newHashMap(); - for (BenthosBatchFrequency speciesBatchFrequency : actualFrequencies) { + Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap(); + for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) { assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep())); actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); @@ -505,8 +505,8 @@ public class BenthosBatchPersistenceServiceWriteTest { } for (Float lengthStep : expectedLengthMap.keySet()) { - BenthosBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); - BenthosBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); + SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); + SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); if (assertIdEquals) { assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId()); } @@ -519,15 +519,15 @@ public class BenthosBatchPersistenceServiceWriteTest { } } - protected BenthosBatch getBenthosBatch(Integer fishingOperationId, Integer speciesBatchId) { + protected SpeciesBatch getBenthosBatch(Integer fishingOperationId, Integer speciesBatchId) { return getBenthosBatch(speciesBatchId, service.getRootBenthosBatch(fishingOperationId, false).getChildren()); } - protected BenthosBatch getBenthosBatch(Integer speciesBatchId, List<BenthosBatch> speciesBatchs) { + protected SpeciesBatch getBenthosBatch(Integer speciesBatchId, List<SpeciesBatch> speciesBatchs) { if (speciesBatchs == null) { return null; } - for (BenthosBatch speciesBatch : speciesBatchs) { + for (SpeciesBatch speciesBatch : speciesBatchs) { if (speciesBatchId.equals(speciesBatch.getIdAsInt())) { return speciesBatch; } -- 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/merge_species_benthos in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit dfdf9c990ae231e918481edd357b0d8d43d06816 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 17 08:46:55 2016 +0100 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module service --- .../ifremer/tutti/service/PersistenceService.java | 48 ++++++------ .../ifremer/tutti/service/ValidationService.java | 9 +-- .../catches/ValidateCruiseOperationsService.java | 45 +++++------ .../service/catches/WeightCleaningService.java | 78 +++++++++----------- .../service/catches/WeightComputingService.java | 40 +++++----- .../catches/multipost/MultiPostExportContext.java | 10 +-- .../catches/multipost/MultiPostExportService.java | 28 ++++--- .../catches/multipost/MultiPostImportService.java | 86 ++++++++++------------ .../tutti/service/export/ExportBatchEntry.java | 8 +- .../tutti/service/export/ExportCatchContext.java | 48 ++++++------ .../export/pdf/CatchesPdfExportService.java | 4 +- .../ToConfirmReportFishingOperationData.java | 9 +-- .../toconfirmreport/ToConfirmReportService.java | 10 +-- .../GenericFormatCheckDataService.java | 3 +- .../genericformat/GenericFormatContextSupport.java | 1 - .../GenericFormatExportOperationContext.java | 11 +-- .../GenericFormatImportOperationContext.java | 38 +++++----- .../GenericformatImportPersistenceHelper.java | 10 +-- .../consumer/CsvConsumerForCatch.java | 28 +++---- .../tutti/service/genericformat/csv/CatchRow.java | 4 +- .../exportactions/CreateCatchBatchRowsAction.java | 5 +- .../importactions/ImportCatchAction.java | 26 +++---- .../producer/CsvProducerForCatch.java | 22 +++--- .../producer/CsvProducerForSpecies.java | 5 +- .../data/BenthosBatch-edit-error-validation.xml | 53 ------------- .../BenthosBatch-validate-fatal-validation.xml | 38 ---------- .../tutti/service/BeanValidatorDetectorTest.java | 5 +- .../tutti/service/PersistenceServiceTest.java | 22 +++--- .../service/bigfin/BigfinImportService2Test.java | 10 +-- .../service/bigfin/BigfinImportServiceTest.java | 7 +- .../catches/WeightComputingServiceTest.java | 17 ++--- .../psionimport/PsionImportServiceTest.java | 7 +- .../pupitri/PupitriImportServiceEvo6116Test.java | 17 ++--- .../pupitri/PupitriImportServiceEvo6149Test.java | 11 ++- .../pupitri/PupitriImportServiceEvo6592Test.java | 11 ++- 35 files changed, 307 insertions(+), 467 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java index 568e881..2362184 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java @@ -38,8 +38,6 @@ import fr.ifremer.tutti.persistence.entities.TuttiEntity; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -47,8 +45,6 @@ import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.Program; 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.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; @@ -160,20 +156,20 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer return sourceList; } - public interface FrequencyFunction<S extends SpeciesAbleBatch, F extends SpeciesAbleBatchFrequency> extends Function<S, List<F>> { + public interface FrequencyFunction extends Function<SpeciesBatch, List<SpeciesBatchFrequency>> { } - public FrequencyFunction<SpeciesBatch, SpeciesBatchFrequency> newSpeciesFrequenciesFunction() { + public FrequencyFunction newSpeciesFrequenciesFunction() { return input -> getAllSpeciesBatchFrequency(input.getIdAsInt()); } - public FrequencyFunction<BenthosBatch, BenthosBatchFrequency> newBenthosFrequenciesFunction() { + public FrequencyFunction newBenthosFrequenciesFunction() { return input -> getAllBenthosBatchFrequency(input.getIdAsInt()); } - public <F extends SpeciesAbleBatchFrequency> Float countFrequenciesWeight(List<F> frequencies, boolean stopIfNullFound) { + public Float countFrequenciesWeight(List<SpeciesBatchFrequency> frequencies, boolean stopIfNullFound) { Float result = null; - for (F frequency : frequencies) { + for (SpeciesBatchFrequency frequency : frequencies) { Float w = frequency.getWeight(); if (w == null) { @@ -190,9 +186,9 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer return result; } - public <F extends SpeciesAbleBatchFrequency> Integer countFrequenciesNumber(List<F> frequencies, boolean stopIfNullFound) { + public Integer countFrequenciesNumber(List<SpeciesBatchFrequency> frequencies, boolean stopIfNullFound) { Integer result = null; - for (F frequency : frequencies) { + for (SpeciesBatchFrequency frequency : frequencies) { Integer number = frequency.getNumber(); if (number == null) { @@ -235,7 +231,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer @Override public ProgramDataModel loadCruise(String programId, Integer cruiseId, Integer... fishingOperationIds) { - return driver.loadCruise(programId, cruiseId, fishingOperationIds); + return driver.loadCruise(programId, cruiseId, fishingOperationIds); } @Override @@ -621,7 +617,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } TIME_LOG.log(t0, "Persistence driver *" + - driver.getImplementationName() + "* opened."); + driver.getImplementationName() + "* opened."); } @Override @@ -638,7 +634,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer IOUtils.closeQuietly(driver); TIME_LOG.log(t0, "Persistence driver *" + - driverName + "* closed."); + driverName + "* closed."); } //------------------------------------------------------------------------// @@ -893,17 +889,17 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } @Override - public boolean isVracBatch(SpeciesAbleBatch speciesBatch) { + public boolean isVracBatch(SpeciesBatch speciesBatch) { return driver.isVracBatch(speciesBatch); } @Override - public boolean isHorsVracBatch(SpeciesAbleBatch speciesBatch) { + public boolean isHorsVracBatch(SpeciesBatch speciesBatch) { return driver.isHorsVracBatch(speciesBatch); } @Override - public Predicate<SpeciesAbleBatch> getVracBatchPredicate() { + public Predicate<SpeciesBatch> getVracBatchPredicate() { return driver.getVracBatchPredicate(); } @@ -1429,22 +1425,22 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer //------------------------------------------------------------------------// @Override - public BatchContainer<BenthosBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException { + public BatchContainer<SpeciesBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException { return driver.getRootBenthosBatch(fishingOperationId, validateTree); } @Override - public BenthosBatch createBenthosBatch(BenthosBatch bean, Integer parentBatchId, boolean computeRankOrder) { + public SpeciesBatch createBenthosBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) { return driver.createBenthosBatch(bean, parentBatchId, computeRankOrder); } @Override - public Collection<BenthosBatch> createBenthosBatches(Integer fishingOperationId, Collection<BenthosBatch> beans) { + public Collection<SpeciesBatch> createBenthosBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans) { return driver.createBenthosBatches(fishingOperationId, beans); } @Override - public BenthosBatch saveBenthosBatch(BenthosBatch bean) { + public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) { return driver.saveBenthosBatch(bean); } @@ -1464,23 +1460,23 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } @Override - public List<BenthosBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { + public List<SpeciesBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException { return driver.getAllBenthosBatchToConfirm(fishingOperationId); } @Override - public List<BenthosBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) { + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) { return driver.getAllBenthosBatchFrequency(benthosBatchId); } @Override - public Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer) { + public Multimap<Species, SpeciesBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) { return driver.getAllBenthosBatchFrequencyForBatch(batchContainer); } @Override - public List<BenthosBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, - List<BenthosBatchFrequency> frequencies) { + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, + List<SpeciesBatchFrequency> frequencies) { return driver.saveBenthosBatchFrequency(benthosBatchId, frequencies); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/ValidationService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/ValidationService.java index 495e75f..4c40301 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/ValidationService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/ValidationService.java @@ -23,7 +23,6 @@ package fr.ifremer.tutti.service; */ import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -100,13 +99,13 @@ public class ValidationService implements TuttiService { return validator.validate(speciesBatch); } - public NuitonValidatorResult validateValidateBenthosBatch(BenthosBatch benthosBatch) { - NuitonValidator<BenthosBatch> validator = NuitonValidatorFactory.newValidator(BenthosBatch.class, VALIDATION_CONTEXT_VALIDATE); + public NuitonValidatorResult validateValidateBenthosBatch(SpeciesBatch benthosBatch) { + NuitonValidator<SpeciesBatch> validator = NuitonValidatorFactory.newValidator(SpeciesBatch.class, VALIDATION_CONTEXT_VALIDATE); return validator.validate(benthosBatch); } - public NuitonValidatorResult validateEditBenthosBatch(BenthosBatch benthosBatch) { - NuitonValidator<BenthosBatch> validator = NuitonValidatorFactory.newValidator(BenthosBatch.class, VALIDATION_CONTEXT_EDIT); + public NuitonValidatorResult validateEditBenthosBatch(SpeciesBatch benthosBatch) { + NuitonValidator<SpeciesBatch> validator = NuitonValidatorFactory.newValidator(SpeciesBatch.class, VALIDATION_CONTEXT_EDIT); return validator.validate(benthosBatch); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java index 17a347c..5dc7cf4 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java @@ -28,8 +28,6 @@ import fr.ifremer.tutti.persistence.InvalidBatchModelException; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -216,8 +214,7 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { * @param fishingOperation the operation to validate * @param validator the validatpr containing the messages. */ - protected void checkOperation(FishingOperation fishingOperation, - NuitonValidatorResult validator) { + protected void checkOperation(FishingOperation fishingOperation, NuitonValidatorResult validator) { Integer fishingOperationId = fishingOperation.getIdAsInt(); @@ -228,7 +225,7 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { if (!withCatchBatch) { if (log.isWarnEnabled()) { log.warn("Skip fishing operation " + fishingOperation + - " since no catchBatch associated."); + " since no catchBatch associated."); } Map<String, List<String>> errorMap = Maps.newHashMap(); errorMap.put("catches", Lists.newArrayList(t("tutti.validator.warning.fishingOperation.batch.notFound"))); @@ -314,15 +311,15 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, true); } - BatchContainer<BenthosBatch> rootBenthosBatch = null; + BatchContainer<SpeciesBatch> rootBenthosBatch = null; error = false; if (isCatchBatch) { rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, true); if (rootBenthosBatch != null) { - List<BenthosBatch> roots = rootBenthosBatch.getChildren(); + List<SpeciesBatch> roots = rootBenthosBatch.getChildren(); - for (BenthosBatch batch : roots) { + for (SpeciesBatch batch : roots) { NuitonValidatorResult benthosValidatorResult = validationService.validateValidateBenthosBatch(batch); transfertValidatorResult(benthosValidatorResult, errors); @@ -396,7 +393,7 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { if (isSpeciesBatchInvalid(batch)) { String species = speciesDecorator.toString(batch.getSpecies()); String categoryValue = decoratorService.getDecorator(batch.getSampleCategoryValue()) - .toString(batch.getSampleCategoryValue()); + .toString(batch.getSampleCategoryValue()); warnings.add(t("tutti.validator.warning.species.protocolNotRespected", species, categoryValue)); } } @@ -407,11 +404,11 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { if (rootBenthosBatch != null) { List<String> warnings = new ArrayList<>(); - for (BenthosBatch batch : rootBenthosBatch.getChildren()) { + for (SpeciesBatch batch : rootBenthosBatch.getChildren()) { if (isBenthosBatchInvalid(batch)) { String species = speciesDecorator.toString(batch.getSpecies()); String categoryValue = decoratorService.getDecorator(batch.getSampleCategoryValue()) - .toString(batch.getSampleCategoryValue()); + .toString(batch.getSampleCategoryValue()); warnings.add(t("tutti.validator.warning.benthos.protocolNotRespected", species, categoryValue)); } } @@ -433,8 +430,7 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { * @param frequencies the frequencies of the batch * @return true if the batch respects the protocol, false otherwise */ - public boolean isSpeciesBatchValid(SpeciesBatch batch, - List<SpeciesBatchFrequency> frequencies) { + public boolean isSpeciesBatchValid(SpeciesBatch batch, List<SpeciesBatchFrequency> frequencies) { boolean result = true; TuttiProtocol protocol = persistenceService.getProtocol(); @@ -453,9 +449,9 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { browsingBatch = browsingBatch.getParentBatch(); } result = mandatoryCategories.isEmpty() && - (speciesProtocol.getLengthStepPmfmId() != null - || CollectionUtils.isNotEmpty(frequencies) - || batch.getNumber() != null); + (speciesProtocol.getLengthStepPmfmId() != null + || CollectionUtils.isNotEmpty(frequencies) + || batch.getNumber() != null); } } return result; @@ -489,16 +485,16 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { * @param batch the batch to check * @return true if the batch or one of its children does not respect the protocol, false otherwise */ - protected boolean isBenthosBatchInvalid(BenthosBatch batch) { + protected boolean isBenthosBatchInvalid(SpeciesBatch batch) { if (batch.isChildBatchsEmpty()) { - List<BenthosBatchFrequency> frequencies = + List<SpeciesBatchFrequency> frequencies = persistenceService.getAllBenthosBatchFrequency(batch.getIdAsInt()); return !isBenthosBatchValid( batch, frequencies); } - for (BenthosBatch child : batch.getChildBatchs()) { + for (SpeciesBatch child : batch.getChildBatchs()) { boolean invalid = isBenthosBatchInvalid(child); if (invalid) { return true; @@ -532,8 +528,7 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { * @param frequencies the frequencies of the batch * @return true if the batch respects the protocol, false otherwise */ - public boolean isBenthosBatchValid(BenthosBatch batch, - List<BenthosBatchFrequency> frequencies) { + public boolean isBenthosBatchValid(SpeciesBatch batch, List<SpeciesBatchFrequency> frequencies) { TuttiProtocol protocol = persistenceService.getProtocol(); @@ -549,15 +544,15 @@ public class ValidateCruiseOperationsService extends AbstractTuttiService { List<Integer> mandatoryCategories = speciesProtocol.getMandatorySampleCategoryId(); - BenthosBatch browsingBatch = batch; + SpeciesBatch browsingBatch = batch; while (browsingBatch.getParentBatch() != null) { mandatoryCategories.remove(browsingBatch.getSampleCategoryId()); browsingBatch = browsingBatch.getParentBatch(); } result = mandatoryCategories.isEmpty() && - (speciesProtocol.getLengthStepPmfmId() != null - || CollectionUtils.isNotEmpty(frequencies) - || batch.getNumber() != null); + (speciesProtocol.getLengthStepPmfmId() != null + || CollectionUtils.isNotEmpty(frequencies) + || batch.getNumber() != null); } } return result; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java index 4421a52..92f8ef4 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java @@ -29,13 +29,9 @@ import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -75,9 +71,9 @@ public class WeightCleaningService extends AbstractTuttiService { protected SampleCategoryModel sampleCategoryModel; - protected FrequencyFunction<SpeciesBatch, SpeciesBatchFrequency> speciesFrequencyFunction; + protected FrequencyFunction speciesFrequencyFunction; - protected FrequencyFunction<BenthosBatch, BenthosBatchFrequency> benthosFrequencyFunction; + protected FrequencyFunction benthosFrequencyFunction; protected WeightUnit benthosWeightUnit; @@ -135,7 +131,7 @@ public class WeightCleaningService extends AbstractTuttiService { if (!withCatchBatch) { if (log.isWarnEnabled()) { log.warn("Skip fishing operation " + fishingOperation + - " since no catchBatch associated."); + " since no catchBatch associated."); } continue; } @@ -229,11 +225,11 @@ public class WeightCleaningService extends AbstractTuttiService { // check benthos batches - BatchContainer<BenthosBatch> benthosBatch = + BatchContainer<SpeciesBatch> benthosBatch = persistenceService.getRootBenthosBatch( fishingOperationId, true); - for (BenthosBatch batch : benthosBatch.getChildren()) { + for (SpeciesBatch batch : benthosBatch.getChildren()) { checkBatch(benthosBatchPrefix, benthosWeightUnit, @@ -247,7 +243,7 @@ public class WeightCleaningService extends AbstractTuttiService { if (log.isWarnEnabled()) { log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); + " since no catchBatch associated."); } } @@ -293,12 +289,12 @@ public class WeightCleaningService extends AbstractTuttiService { // clean benthos batches - Set<BenthosBatch> benthosToSave = Sets.newHashSet(); - BatchContainer<BenthosBatch> benthosBatch = + Set<SpeciesBatch> benthosToSave = Sets.newHashSet(); + BatchContainer<SpeciesBatch> benthosBatch = persistenceService.getRootBenthosBatch( fishingOperationId, true); - for (BenthosBatch batch : benthosBatch.getChildren()) { + for (SpeciesBatch batch : benthosBatch.getChildren()) { cleanBatch(benthosBatchPrefix, benthosWeightUnit, @@ -321,7 +317,7 @@ public class WeightCleaningService extends AbstractTuttiService { persistenceService.saveSpeciesBatch(toSave); } - for (BenthosBatch toSave : benthosToSave) { + for (SpeciesBatch toSave : benthosToSave) { toSave.setFishingOperation(fishingOperation); persistenceService.saveBenthosBatch(toSave); } @@ -333,7 +329,7 @@ public class WeightCleaningService extends AbstractTuttiService { if (log.isWarnEnabled()) { log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); + " since no catchBatch associated."); } } @@ -341,18 +337,16 @@ public class WeightCleaningService extends AbstractTuttiService { } - protected <B extends SpeciesAbleBatch, F extends SpeciesAbleBatchFrequency> void checkBatch(String batchPrefix, - WeightUnit weightUnit, - B batch, - Multimap<String, String> result, - FrequencyFunction<B, F> frequencyFunction) { + protected void checkBatch(String batchPrefix, + WeightUnit weightUnit, + SpeciesBatch batch, + Multimap<String, String> result, + FrequencyFunction frequencyFunction) { if (!batch.isChildBatchsEmpty()) { // check childs - for (SpeciesAbleBatch child : batch.getChildBatchs()) { - - B childBatch = (B) child; + for (SpeciesBatch childBatch : batch.getChildBatchs()) { // check batch sample category weight (before childs) String message = checkSampleCategoryWeightRedundant(weightUnit, batch, childBatch); @@ -403,18 +397,16 @@ public class WeightCleaningService extends AbstractTuttiService { } } - protected <B extends SpeciesAbleBatch, F extends SpeciesAbleBatchFrequency> void cleanBatch(String batchPrefix, - WeightUnit weightUnit, - B batch, - Set<B> result, - FrequencyFunction<B, F> frequencyFunction) { + protected void cleanBatch(String batchPrefix, + WeightUnit weightUnit, + SpeciesBatch batch, + Set<SpeciesBatch> result, + FrequencyFunction frequencyFunction) { if (!batch.isChildBatchsEmpty()) { // check childs - for (SpeciesAbleBatch child : batch.getChildBatchs()) { - - B childBatch = (B) child; + for (SpeciesBatch childBatch : batch.getChildBatchs()) { // check batch sample category weight String message = checkSampleCategoryWeightRedundant(weightUnit, batch, childBatch); @@ -472,8 +464,8 @@ public class WeightCleaningService extends AbstractTuttiService { } protected String checkSampleCategoryWeightRedundant(WeightUnit weightUnit, - SpeciesAbleBatch parentBatch, - SpeciesAbleBatch batch) { + SpeciesBatch parentBatch, + SpeciesBatch batch) { Preconditions.checkNotNull(parentBatch); @@ -484,7 +476,7 @@ public class WeightCleaningService extends AbstractTuttiService { Float parentSampleCategoryWeight = parentBatch.getSampleCategoryWeight(); if (sampleCategoryWeight != null && parentSampleCategoryWeight != null && - Weights.isEqualWeight(parentSampleCategoryWeight, sampleCategoryWeight)) { + Weights.isEqualWeight(parentSampleCategoryWeight, sampleCategoryWeight)) { result = t("tutti.service.operations.cleanWeights.error.redundant.sampleCategoryWeight", weightUnit.fromEntity(sampleCategoryWeight), @@ -498,9 +490,9 @@ public class WeightCleaningService extends AbstractTuttiService { } - protected <B extends SpeciesAbleBatch, F extends SpeciesAbleBatchFrequency> String checkFrequencyWeightRedundant(WeightUnit weightUnit, - B batch, - FrequencyFunction<B, F> frequencyFunction) { + protected String checkFrequencyWeightRedundant(WeightUnit weightUnit, + SpeciesBatch batch, + FrequencyFunction frequencyFunction) { Preconditions.checkState(batch.isChildBatchsEmpty()); String result = null; @@ -510,7 +502,7 @@ public class WeightCleaningService extends AbstractTuttiService { if (weight != null) { // check if there is some frequencies - List<F> frequencies = frequencyFunction.apply(batch); + List<SpeciesBatchFrequency> frequencies = frequencyFunction.apply(batch); Float frequenciesWeigth = persistenceService.countFrequenciesWeight(frequencies, true); @@ -526,7 +518,7 @@ public class WeightCleaningService extends AbstractTuttiService { } protected String checkWeightRedundant(WeightUnit weightUnit, - SpeciesAbleBatch batch) { + SpeciesBatch batch) { Preconditions.checkState(batch.isChildBatchsEmpty()); @@ -547,17 +539,17 @@ public class WeightCleaningService extends AbstractTuttiService { } protected String getBatchLabel(String type, WeightUnit weightUnit, - SpeciesAbleBatch batch) { + SpeciesBatch batch) { StringBuilder sb = new StringBuilder("[ " + type); String species = decoratorService.getDecoratorByType(Species.class).toString(batch.getSpecies()); sb.append(" ").append(species); List<String> categories = Lists.newArrayList(); - SpeciesAbleBatch b = batch; + SpeciesBatch b = batch; while (b.getParentBatch() != null) { String categoryValue = decoratorService.getDecorator(b.getSampleCategoryValue()) - .toString(b.getSampleCategoryValue()); + .toString(b.getSampleCategoryValue()); categories.add(0, categoryValue + " / " + weightUnit.fromEntity(b.getSampleCategoryWeight())); b = b.getParentBatch(); } @@ -569,7 +561,7 @@ public class WeightCleaningService extends AbstractTuttiService { return sb.toString(); } - protected String getCategoryLabel(SpeciesAbleBatch batch) { + protected String getCategoryLabel(SpeciesBatch batch) { SampleCategoryModelEntry category = sampleCategoryModel.getCategoryById(batch.getSampleCategoryId()); return category.getLabel(); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java index a286255..cb84112 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java @@ -23,8 +23,6 @@ package fr.ifremer.tutti.service.catches; */ import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; @@ -76,7 +74,7 @@ public class WeightComputingService extends AbstractTuttiService { */ public void computeCatchBatchWeights(CatchBatch catchBatch, BatchContainer<SpeciesBatch> rootSpeciesBatch, - BatchContainer<BenthosBatch> rootBenthosBatch, + BatchContainer<SpeciesBatch> rootBenthosBatch, BatchContainer<MarineLitterBatch> rootMarineLitterBatch) { // Species @@ -139,8 +137,8 @@ public class WeightComputingService extends AbstractTuttiService { Float benthosTotalComputedUnsortedWeight = 0f; if (rootBenthosBatch != null) { - List<BenthosBatch> benthosBatches = rootBenthosBatch.getChildren(); - for (BenthosBatch row : benthosBatches) { + List<SpeciesBatch> benthosBatches = rootBenthosBatch.getChildren(); + for (SpeciesBatch row : benthosBatches) { Float weight = Numbers.getValueOrComputedValue( row.getSampleCategoryWeight(), row.getSampleCategoryComputedWeight()); @@ -470,18 +468,18 @@ public class WeightComputingService extends AbstractTuttiService { private int currentBenthosRowIndex; - public BatchContainer<BenthosBatch> getComputedBenthosBatches(Integer operationId) { + public BatchContainer<SpeciesBatch> getComputedBenthosBatches(Integer operationId) { - BatchContainer<BenthosBatch> rootBenthosBatch = null; + BatchContainer<SpeciesBatch> rootBenthosBatch = null; if (persistenceService.isFishingOperationWithCatchBatch(operationId)) { rootBenthosBatch = persistenceService.getRootBenthosBatch(operationId, false); currentBenthosRowIndex = 0; if (rootBenthosBatch != null) { - List<BenthosBatch> roots = rootBenthosBatch.getChildren(); + List<SpeciesBatch> roots = rootBenthosBatch.getChildren(); - for (BenthosBatch batch : roots) { + for (SpeciesBatch batch : roots) { computeBenthosBatch(batch); } } @@ -490,7 +488,7 @@ public class WeightComputingService extends AbstractTuttiService { return rootBenthosBatch; } - public Float computeBenthosBatch(BenthosBatch batch) { + public Float computeBenthosBatch(SpeciesBatch batch) { Float result = null; int thisIndex = currentBenthosRowIndex++; Float categoryWeight = batch.getSampleCategoryWeight(); @@ -501,7 +499,7 @@ public class WeightComputingService extends AbstractTuttiService { NuitonValidatorResult validation = validationService.validateEditBenthosBatch(batch); if (!validation.isValid()) { - List<String> messages = validation.getErrorMessages(BenthosBatch.PROPERTY_WEIGHT); + List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); throw new TuttiWeightComputingException(t(messages.get(0), @@ -510,16 +508,16 @@ public class WeightComputingService extends AbstractTuttiService { categoryValue, batch.getWeight(), batch.getSampleCategoryWeight()), - BenthosBatch.PROPERTY_WEIGHT, + SpeciesBatch.PROPERTY_WEIGHT, thisIndex); } - List<BenthosBatch> children = batch.getChildBatchs(); + List<SpeciesBatch> children = batch.getChildBatchs(); // if the row is not a leaf if (!batch.isChildBatchsEmpty()) { Float sum = 0f; // make the sum of the children weights - for (BenthosBatch child : children) { + for (SpeciesBatch child : children) { Float weight = computeBenthosBatch(child); if (weight == null) { sum = null; @@ -543,7 +541,7 @@ public class WeightComputingService extends AbstractTuttiService { categoryValue, categoryWeight, sum), - BenthosBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); } else { @@ -557,12 +555,12 @@ public class WeightComputingService extends AbstractTuttiService { batch.setComputedWeight(null); - List<BenthosBatchFrequency> frequencies = persistenceService.getAllBenthosBatchFrequency(batch.getIdAsInt()); + List<SpeciesBatchFrequency> frequencies = persistenceService.getAllBenthosBatchFrequency(batch.getIdAsInt()); if (CollectionUtils.isNotEmpty(frequencies)) { // if there are frequencies, then compute their weight Float frequencyWeight = 0f; - for (BenthosBatchFrequency frequency : frequencies) { + for (SpeciesBatchFrequency frequency : frequencies) { Float w = frequency.getWeight(); if (w == null) { @@ -593,7 +591,7 @@ public class WeightComputingService extends AbstractTuttiService { categoryValue, rowWeight, categoryWeight), - BenthosBatch.PROPERTY_WEIGHT, + SpeciesBatch.PROPERTY_WEIGHT, thisIndex); } else if (categoryWeight == null && frequencyWeight != null) { @@ -619,7 +617,7 @@ public class WeightComputingService extends AbstractTuttiService { categoryValue, frequencyWeight, categoryWeight), - BenthosBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); } else if (rowWeight == null) { @@ -634,7 +632,7 @@ public class WeightComputingService extends AbstractTuttiService { // compute number from frequencies Integer frequencyNumber = 0; - for (BenthosBatchFrequency frequency : frequencies) { + for (SpeciesBatchFrequency frequency : frequencies) { Integer c = frequency.getNumber(); frequencyNumber += c; } @@ -653,7 +651,7 @@ public class WeightComputingService extends AbstractTuttiService { species, categoryLabel, categoryValue), - BenthosBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostExportContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostExportContext.java index a822f01..caadec3 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostExportContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostExportContext.java @@ -31,8 +31,8 @@ import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.catches.multipost.csv.AccidentalCatchRow; @@ -192,7 +192,7 @@ public class MultiPostExportContext implements MultiPostConstants, Closeable { } } - public <B extends SpeciesAbleBatch> void addSpeciesOrBenthosBatch(String batchId, String parentId, B batch) { + public void addSpeciesOrBenthosBatch(String batchId, String parentId, SpeciesBatch batch) { CatchRow row = new CatchRow(); row.setId(batchId); @@ -213,9 +213,9 @@ public class MultiPostExportContext implements MultiPostConstants, Closeable { } - public <F extends SpeciesAbleBatchFrequency> void addFrequencies(String rowId, List<F> frequencies) { + public void addFrequencies(String rowId, List<SpeciesBatchFrequency> frequencies) { - for (F frequency : frequencies) { + for (SpeciesBatchFrequency frequency : frequencies) { CatchFrequencyRow frequencyRow = new CatchFrequencyRow(); frequencyRow.setBatchId(rowId); frequencyRow.setLengthStepCaracteristic(frequency.getLengthStepCaracteristic()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostExportService.java index 23ba72d..aa67b61 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostExportService.java @@ -26,8 +26,6 @@ import com.google.common.collect.Lists; import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; @@ -201,7 +199,7 @@ public class MultiPostExportService extends AbstractTuttiService implements Mult // Export frequencies if (exportFrequencies) { - addFrequencies(exportContext, speciesBatch); + addSpeciesFrequencies(exportContext, speciesBatch); exportContext.storeFrequencies(); } @@ -251,9 +249,9 @@ public class MultiPostExportService extends AbstractTuttiService implements Mult // Export benthos catch, frequencies and individual observations - BatchContainer<BenthosBatch> benthosBatchContainer = persistenceService.getRootBenthosBatch(operationId, false); + BatchContainer<SpeciesBatch> benthosBatchContainer = persistenceService.getRootBenthosBatch(operationId, false); - for (BenthosBatch batch : benthosBatchContainer.getChildren()) { + for (SpeciesBatch batch : benthosBatchContainer.getChildren()) { addBenthos(exportContext, batch, null, exportFrequencies); } @@ -364,7 +362,7 @@ public class MultiPostExportService extends AbstractTuttiService implements Mult exportContext.addSpeciesOrBenthosBatch(id, parentId, batch); if (addFrequencies) { - List<SpeciesBatchFrequency> frequencies = getFrequencies(batch); + List<SpeciesBatchFrequency> frequencies = getSpeciesFrequencies(batch); exportContext.addFrequencies(id, frequencies); } @@ -374,20 +372,20 @@ public class MultiPostExportService extends AbstractTuttiService implements Mult } - protected void addFrequencies(MultiPostExportContext exportContext, SpeciesBatch batch) { + protected void addSpeciesFrequencies(MultiPostExportContext exportContext, SpeciesBatch batch) { String id = context.generateId(CatchRow.class); - List<SpeciesBatchFrequency> frequencies = getFrequencies(batch); + List<SpeciesBatchFrequency> frequencies = getSpeciesFrequencies(batch); exportContext.addFrequencies(id, frequencies); for (SpeciesBatch child : batch.getChildBatchs()) { - addFrequencies(exportContext, child); + addSpeciesFrequencies(exportContext, child); } } - protected List<SpeciesBatchFrequency> getFrequencies(SpeciesBatch batch) { + protected List<SpeciesBatchFrequency> getSpeciesFrequencies(SpeciesBatch batch) { List<SpeciesBatchFrequency> frequencies = persistenceService.getAllSpeciesBatchFrequency(batch.getIdAsInt()); frequencies.forEach(speciesBatchFrequency -> speciesBatchFrequency.setBatch(batch)); @@ -395,25 +393,25 @@ public class MultiPostExportService extends AbstractTuttiService implements Mult } - protected void addBenthos(MultiPostExportContext exportContext, BenthosBatch batch, String parentId, boolean addFrequencies) { + protected void addBenthos(MultiPostExportContext exportContext, SpeciesBatch batch, String parentId, boolean addFrequencies) { String id = context.generateId(CatchRow.class); exportContext.addSpeciesOrBenthosBatch(id, parentId, batch); if (addFrequencies) { - List<BenthosBatchFrequency> frequencies = getFrequencies(batch); + List<SpeciesBatchFrequency> frequencies = getBenthosFrequencies(batch); exportContext.addFrequencies(id, frequencies); } - for (BenthosBatch child : batch.getChildBatchs()) { + for (SpeciesBatch child : batch.getChildBatchs()) { addBenthos(exportContext, child, id, addFrequencies); } } - protected List<BenthosBatchFrequency> getFrequencies(BenthosBatch batch) { + protected List<SpeciesBatchFrequency> getBenthosFrequencies(SpeciesBatch batch) { - List<BenthosBatchFrequency> frequencies = persistenceService.getAllBenthosBatchFrequency(batch.getIdAsInt()); + List<SpeciesBatchFrequency> frequencies = persistenceService.getAllBenthosBatchFrequency(batch.getIdAsInt()); frequencies.forEach(speciesBatchFrequency -> speciesBatchFrequency.setBatch(batch)); return frequencies; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostImportService.java index 1b2fd1c..cee399d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/MultiPostImportService.java @@ -34,11 +34,6 @@ import fr.ifremer.tutti.persistence.entities.data.AccidentalBatchs; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.Attachments; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequencys; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchs; -import fr.ifremer.tutti.persistence.entities.data.SampleEntity; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; @@ -47,8 +42,7 @@ import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatchs; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SampleEntity; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequencys; @@ -582,27 +576,27 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult importContext.checkSameOperation(WEIGHTS_FILE, weightsModel); Map<String, Object> notImportedData = new HashMap<>(); - Map<String, BenthosBatch> notImportedBatches = new LinkedHashMap<>(); + Map<String, SpeciesBatch> notImportedBatches = new LinkedHashMap<>(); - BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(operation.getIdAsInt(), false); + BatchContainer<SpeciesBatch> benthosBatches = persistenceService.getRootBenthosBatch(operation.getIdAsInt(), false); // Import batches // map containing the batches by their persistence id - Map<String, BenthosBatch> batches = importBenthosBatches(importContext, benthosBatches, notImportedBatches); + Map<String, SpeciesBatch> batches = importBenthosBatches(importContext, benthosBatches, notImportedBatches); // Import frequencies if (importFrequencies) { - ListMultimap<String, BenthosBatchFrequency> frequencyListMultimap = importFrequencies(importContext, + ListMultimap<String, SpeciesBatchFrequency> frequencyListMultimap = importFrequencies(importContext, batches, notImportedBatches, - BenthosBatchFrequencys::newBenthosBatchFrequency); + SpeciesBatchFrequencys::newBenthosBatchFrequency); for (String batchId : frequencyListMultimap.keySet()) { - List<BenthosBatchFrequency> frequencies = frequencyListMultimap.get(batchId); - BenthosBatch speciesBatch = batches.get(batchId); + List<SpeciesBatchFrequency> frequencies = frequencyListMultimap.get(batchId); + SpeciesBatch speciesBatch = batches.get(batchId); frequencies.forEach(speciesBatchFrequency -> speciesBatchFrequency.setBatch(speciesBatch)); persistenceService.saveBenthosBatchFrequency(speciesBatch.getIdAsInt(), frequencies); @@ -651,10 +645,10 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } - protected Map<String, BenthosBatch> importBenthosBatches(MultiPostImportContext importContext, - BatchContainer<BenthosBatch> benthosBatches, - Map<String, BenthosBatch> notImportedBatches) throws IOException { - Map<String, BenthosBatch> batches = new HashMap<>(); + protected Map<String, SpeciesBatch> importBenthosBatches(MultiPostImportContext importContext, + BatchContainer<SpeciesBatch> benthosBatches, + Map<String, SpeciesBatch> notImportedBatches) throws IOException { + Map<String, SpeciesBatch> batches = new HashMap<>(); try (Reader reader = importContext.newFileReader(BENTHOS_FILE)) { @@ -666,7 +660,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult for (CatchRow row : importer) { // create batch - BenthosBatch batch = BenthosBatchs.newBenthosBatch(); + SpeciesBatch batch = SpeciesBatchs.newBenthosBatch(); batch.setFishingOperation(operation); Species species = row.getSpecies(); @@ -687,14 +681,14 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult // get parent batch String parentId = row.getParentId(); Integer parentPersistedId = null; - BenthosBatch parent = null; + SpeciesBatch parent = null; if (StringUtils.isNotEmpty(parentId)) { parent = batches.get(parentId); parentPersistedId = parent.getIdAsInt(); } - BenthosBatch existingBatch = null; - List<BenthosBatch> batchesToBrowse; + SpeciesBatch existingBatch = null; + List<SpeciesBatch> batchesToBrowse; if (parent == null) { batchesToBrowse = benthosBatches.getChildren(); } else { @@ -704,7 +698,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult // check if the parent has already a batch with the caracteristic value // and if the children batch are categorized with the same caracterstic if (batchesToBrowse != null) { - for (BenthosBatch bb : batchesToBrowse) { + for (SpeciesBatch bb : batchesToBrowse) { if (bb.getSpecies().equals(species) && (!bb.getSampleCategoryId().equals(batch.getSampleCategoryId()) || bb.getSampleCategoryValue().equals(value))) { @@ -731,10 +725,10 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } // protected void importBenthosFrequencies(MultiPostImportContext importContext, -// Map<String, BenthosBatch> batches, -// Map<String, BenthosBatch> notImportedBatches) throws IOException { +// Map<String, SpeciesBatch> batches, +// Map<String, SpeciesBatch> notImportedBatches) throws IOException { // -// ListMultimap<Integer, BenthosBatchFrequency> frequencyMap = ArrayListMultimap.create(); +// ListMultimap<Integer, SpeciesBatchFrequency> frequencyMap = ArrayListMultimap.create(); // // try (Reader reader = importContext.newFileReader(FREQUENCIES_FILE)) { // @@ -744,9 +738,9 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult // // for (CatchFrequencyRow frequencyRow : importer) { // if (notImportedBatches.get(frequencyRow.getBatchId()) == null) { -// BenthosBatch batch = batches.get(frequencyRow.getBatchId()); +// SpeciesBatch batch = batches.get(frequencyRow.getBatchId()); // if (batch != null) { -// BenthosBatchFrequency frequency = BenthosBatchFrequencys.newBenthosBatchFrequency(); +// SpeciesBatchFrequency frequency = BenthosBatchFrequencys.newBenthosBatchFrequency(); // frequency.setLengthStepCaracteristic(frequencyRow.getLengthStepCaracteristic()); // frequency.setLengthStep(frequencyRow.getLengthStep()); // frequency.setNumber(frequencyRow.getNumber()); @@ -761,7 +755,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult // } // // for (Integer batchId : frequencyMap.keySet()) { -// List<BenthosBatchFrequency> frequencies = frequencyMap.get(batchId); +// List<SpeciesBatchFrequency> frequencies = frequencyMap.get(batchId); // persistenceService.saveBenthosBatchFrequency(batchId, frequencies); // } // @@ -1184,7 +1178,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } protected <B extends SampleEntity> void importCaracteristics(MultiPostImportContext importContext, - Map<String, B> batches) throws IOException { + Map<String, B> batches) throws IOException { try (Reader reader = importContext.newFileReader(CARACTERISTIC_FILE)) { @@ -1217,9 +1211,9 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } - protected <B extends SpeciesAbleBatch> Map<String, IndividualObservationBatch> importIndividualObservationBatches(MultiPostImportContext importContext, - Map<String, B> speciesOrBenthosBatches, - Map<String, B> notImportedBatches) throws IOException { + protected Map<String, IndividualObservationBatch> importIndividualObservationBatches(MultiPostImportContext importContext, + Map<String, SpeciesBatch> speciesOrBenthosBatches, + Map<String, SpeciesBatch> notImportedBatches) throws IOException { Map<String, IndividualObservationBatch> batches = new LinkedHashMap<>(); @@ -1241,7 +1235,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult // do not import these batch continue; } - B speciesOfBenthosBatch = speciesOrBenthosBatches.get(speciesBatchId); + SpeciesBatch speciesOfBenthosBatch = speciesOrBenthosBatches.get(speciesBatchId); if (speciesOfBenthosBatch == null) { // not found (FIXME Should ne an error) continue; @@ -1270,12 +1264,12 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } - protected <B extends SpeciesAbleBatch, F extends SpeciesAbleBatchFrequency> ListMultimap<String, F> importFrequencies(MultiPostImportContext importContext, - Map<String, B> batches, - Map<String, B> notImportedBatches, - Supplier<F> newFrequencySupplier) throws IOException { + protected ListMultimap<String, SpeciesBatchFrequency> importFrequencies(MultiPostImportContext importContext, + Map<String, SpeciesBatch> batches, + Map<String, SpeciesBatch> notImportedBatches, + Supplier<SpeciesBatchFrequency> newFrequencySupplier) throws IOException { - ListMultimap<String, F> frequencyMap = ArrayListMultimap.create(); + ListMultimap<String, SpeciesBatchFrequency> frequencyMap = ArrayListMultimap.create(); try (Reader reader = importContext.newFileReader(FREQUENCIES_FILE)) { @@ -1290,14 +1284,14 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult // not imported continue; } - B batch = batches.get(frequencyRowBatchId); + SpeciesBatch batch = batches.get(frequencyRowBatchId); if (batch == null) { // not imported (FIXME Should be an error ?) continue; } - F frequency = newFrequencySupplier.get(); + SpeciesBatchFrequency frequency = newFrequencySupplier.get(); frequency.setLengthStepCaracteristic(frequencyRow.getLengthStepCaracteristic()); frequency.setLengthStep(frequencyRow.getLengthStep()); frequency.setNumber(frequencyRow.getNumber()); @@ -1313,9 +1307,9 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } - protected <B extends SpeciesAbleBatch, F extends SpeciesAbleBatchFrequency> List<F> importFrequencies(MultiPostImportContext importContext, B speciesBatch, Supplier<F> newFrequencySupplier) throws IOException { + protected List<SpeciesBatchFrequency> importFrequencies(MultiPostImportContext importContext, SpeciesBatch speciesBatch, Supplier<SpeciesBatchFrequency> newFrequencySupplier) throws IOException { - List<F> frequenciesToSave = new LinkedList<>(); + List<SpeciesBatchFrequency> frequenciesToSave = new LinkedList<>(); try (Reader reader = importContext.newFileReader(FREQUENCIES_FILE)) { @@ -1338,7 +1332,7 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } - F frequency = newFrequencySupplier.get(); + SpeciesBatchFrequency frequency = newFrequencySupplier.get(); frequency.setLengthStepCaracteristic(frequencyRow.getLengthStepCaracteristic()); frequency.setLengthStep(frequencyRow.getLengthStep()); frequency.setNumber(frequencyRow.getNumber()); @@ -1355,8 +1349,8 @@ public class MultiPostImportService extends AbstractTuttiService implements Mult } - protected <B extends SpeciesAbleBatch> Map<String, IndividualObservationBatch> importIndividualObservationBatches(MultiPostImportContext importContext, - B speciesOfBenthosBatch) throws IOException { + protected Map<String, IndividualObservationBatch> importIndividualObservationBatches(MultiPostImportContext importContext, + SpeciesBatch speciesOfBenthosBatch) throws IOException { Map<String, IndividualObservationBatch> batches = new LinkedHashMap<>(); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportBatchEntry.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportBatchEntry.java index dec51ea..b6c9083 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportBatchEntry.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportBatchEntry.java @@ -22,7 +22,7 @@ package fr.ifremer.tutti.service.export; * #L% */ -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import org.apache.commons.lang3.mutable.MutableInt; import java.util.Map; @@ -36,7 +36,7 @@ import java.util.TreeMap; */ public class ExportBatchEntry { - protected final SpeciesAbleBatch batch; + protected final SpeciesBatch batch; protected float sortedWeight; @@ -51,12 +51,12 @@ public class ExportBatchEntry { */ protected Map<Float, MutableInt> frequencies; - public ExportBatchEntry(SpeciesAbleBatch batch) { + public ExportBatchEntry(SpeciesBatch batch) { this.batch = batch; this.frequencies = new TreeMap<>(); } - public SpeciesAbleBatch getBatch() { + public SpeciesBatch getBatch() { return batch; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java index d85ced5..dcfe7ce 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java @@ -27,13 +27,9 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -62,15 +58,15 @@ public class ExportCatchContext { final BatchContainer<SpeciesBatch> rootSpeciesBatch; - final BatchContainer<BenthosBatch> rootBenthosBatch; + final BatchContainer<SpeciesBatch> rootBenthosBatch; final BatchContainer<MarineLitterBatch> marineLitterBatches; final Multimap<Species, SpeciesBatchFrequency> speciesFrequencies; - final Multimap<Species, BenthosBatchFrequency> benthosFrequencies; + final Multimap<Species, SpeciesBatchFrequency> benthosFrequencies; - final Predicate<SpeciesAbleBatch> vracPredicate; + final Predicate<SpeciesBatch> vracPredicate; public static ExportCatchContext newExportContext(PersistenceService persistenceService, WeightComputingService weightComputingService, @@ -86,7 +82,7 @@ public class ExportCatchContext { BatchContainer<SpeciesBatch> rootSpeciesBatch = weightComputingService.getComputedSpeciesBatches(fishingOperationId); - BatchContainer<BenthosBatch> rootBenthosBatch = + BatchContainer<SpeciesBatch> rootBenthosBatch = weightComputingService.getComputedBenthosBatches(fishingOperationId); BatchContainer<MarineLitterBatch> marineLitterBatches = @@ -99,7 +95,7 @@ public class ExportCatchContext { marineLitterBatches); Multimap<Species, SpeciesBatchFrequency> speciesFrequencies; - Multimap<Species, BenthosBatchFrequency> benthosFrequencies; + Multimap<Species, SpeciesBatchFrequency> benthosFrequencies; if (loadFrequencies) { @@ -110,7 +106,7 @@ public class ExportCatchContext { benthosFrequencies = null; } - Predicate<SpeciesAbleBatch> vracPredicate = persistenceService.getVracBatchPredicate(); + Predicate<SpeciesBatch> vracPredicate = persistenceService.getVracBatchPredicate(); return new ExportCatchContext(vracPredicate, fishingOperation, @@ -123,13 +119,13 @@ public class ExportCatchContext { } - private ExportCatchContext(Predicate<SpeciesAbleBatch> vracPredicate, + private ExportCatchContext(Predicate<SpeciesBatch> vracPredicate, FishingOperation fishingOperation, CatchBatch catchBatch, BatchContainer<SpeciesBatch> rootSpeciesBatch, Multimap<Species, SpeciesBatchFrequency> speciesFrequencies, - BatchContainer<BenthosBatch> rootBenthosBatch, - Multimap<Species, BenthosBatchFrequency> benthosFrequencies, + BatchContainer<SpeciesBatch> rootBenthosBatch, + Multimap<Species, SpeciesBatchFrequency> benthosFrequencies, BatchContainer<MarineLitterBatch> marineLitterBatches) { this.vracPredicate = vracPredicate; this.fishingOperation = fishingOperation; @@ -153,9 +149,9 @@ public class ExportCatchContext { public float getCatchTotalSortedWeight() { return catchBatch.getSpeciesTotalSampleSortedComputedWeight() + - catchBatch.getBenthosTotalSampleSortedComputedWeight() + - catchBatch.getSpeciesTotalUnsortedComputedWeight() + - catchBatch.getBenthosTotalUnsortedComputedWeight(); + catchBatch.getBenthosTotalSampleSortedComputedWeight() + + catchBatch.getSpeciesTotalUnsortedComputedWeight() + + catchBatch.getBenthosTotalUnsortedComputedWeight(); } public float getSpeciesTotalSortedWeight() { @@ -169,7 +165,7 @@ public class ExportCatchContext { catchBatch.getBenthosTotalSortedWeight(), catchBatch.getBenthosTotalSortedComputedWeight()); } - + public boolean withSpeciesBatches() { return rootSpeciesBatch != null && !rootSpeciesBatch.isEmptyChildren(); } @@ -228,8 +224,8 @@ public class ExportCatchContext { // ratio total species weight / total sorted sampled species weight float rate = getBenthosElevationRate(); - List<BenthosBatch> batches = rootBenthosBatch.getChildren(); - for (BenthosBatch batch : batches) { + List<SpeciesBatch> batches = rootBenthosBatch.getChildren(); + for (SpeciesBatch batch : batches) { ExportBatchEntry aCatch = createExportBatchCatch( batch, @@ -293,7 +289,7 @@ public class ExportCatchContext { return result; } - public boolean isVracBatch(SpeciesAbleBatch batch) { + public boolean isVracBatch(SpeciesBatch batch) { return vracPredicate.apply(batch); } @@ -325,7 +321,7 @@ public class ExportCatchContext { return result; } - protected ExportBatchEntry createExportBatchCatch(SpeciesAbleBatch batch, + protected ExportBatchEntry createExportBatchCatch(SpeciesBatch batch, Map<Species, ExportBatchEntry> catches, float ratio, boolean computeNumber) { @@ -361,7 +357,7 @@ public class ExportCatchContext { return ktch; } - protected float computeNumber(SpeciesAbleBatch batch, float rf) { + protected float computeNumber(SpeciesBatch batch, float rf) { float result; float weight = Numbers.getValueOrComputedValue( @@ -397,7 +393,7 @@ public class ExportCatchContext { // get total weight of all childs float totalWeight = 0.f; - for (SpeciesAbleBatch child : batch.getChildBatchs()) { + for (SpeciesBatch child : batch.getChildBatchs()) { totalWeight += Numbers.getValueOrComputedValue( child.getSampleCategoryWeight(), child.getSampleCategoryComputedWeight()); @@ -407,7 +403,7 @@ public class ExportCatchContext { float rf2 = rf * weight / totalWeight; // sum result of each child - for (SpeciesAbleBatch child : batch.getChildBatchs()) { + for (SpeciesBatch child : batch.getChildBatchs()) { result += computeNumber(child, rf2); } @@ -416,8 +412,8 @@ public class ExportCatchContext { return result; } - protected <F extends SpeciesAbleBatchFrequency> void addFrequencies(ExportBatchEntry aCatch, - Multimap<Species, F> frequencies) { + protected <F extends SpeciesBatchFrequency> void addFrequencies(ExportBatchEntry aCatch, + Multimap<Species, F> frequencies) { Species species = aCatch.getBatch().getSpecies(); Collection<F> batchFrequencies = frequencies.get(species); if (CollectionUtils.isNotEmpty(batchFrequencies)) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java index d542760..1b7f8fc 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java @@ -25,7 +25,7 @@ package fr.ifremer.tutti.service.export.pdf; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.Speciess; import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; @@ -205,7 +205,7 @@ public class CatchesPdfExportService extends AbstractTuttiService { for (ExportBatchEntry entry : speciesBatchEntries) { - SpeciesAbleBatch batch = entry.getBatch(); + SpeciesBatch batch = entry.getBatch(); Species species = batch.getSpecies(); taxonCache.load(species); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationData.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationData.java index 5e8c1a2..1a93fa5 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationData.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationData.java @@ -24,7 +24,6 @@ package fr.ifremer.tutti.service.export.toconfirmreport; * #L% */ -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; @@ -70,7 +69,7 @@ public class ToConfirmReportFishingOperationData { List<SpeciesBatch> speciesBatchToConfirm = persistenceService.getAllSpeciesBatchToConfirm(fishingOperationId); - List<BenthosBatch> benthosBatchToConfirm = persistenceService.getAllBenthosBatchToConfirm(fishingOperationId); + List<SpeciesBatch> benthosBatchToConfirm = persistenceService.getAllBenthosBatchToConfirm(fishingOperationId); if (CollectionUtils.isEmpty(speciesBatchToConfirm) && CollectionUtils.isEmpty(benthosBatchToConfirm)) { @@ -102,7 +101,7 @@ public class ToConfirmReportFishingOperationData { final List<SpeciesBatch> speciesBatchToConfirm; - final List<BenthosBatch> benthosBatchToConfirm; + final List<SpeciesBatch> benthosBatchToConfirm; public FishingOperation getFishingOperation() { return fishingOperation; @@ -120,7 +119,7 @@ public class ToConfirmReportFishingOperationData { return CollectionUtils.isNotEmpty(speciesBatchToConfirm); } - public List<BenthosBatch> getBenthosBatchToConfirm() { + public List<SpeciesBatch> getBenthosBatchToConfirm() { return benthosBatchToConfirm; } @@ -131,7 +130,7 @@ public class ToConfirmReportFishingOperationData { private ToConfirmReportFishingOperationData(FishingOperation fishingOperation, CatchBatch catchBatch, List<SpeciesBatch> speciesBatchToConfirm, - List<BenthosBatch> benthosBatchToConfirm) { + List<SpeciesBatch> benthosBatchToConfirm) { this.fishingOperation = fishingOperation; this.catchBatch = catchBatch; this.speciesBatchToConfirm = speciesBatchToConfirm; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java index 303db0c..401519e 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java @@ -25,9 +25,7 @@ package fr.ifremer.tutti.service.export.toconfirmreport; */ import fr.ifremer.tutti.persistence.ProgressionModel; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -160,7 +158,7 @@ public class ToConfirmReportService extends AbstractTuttiService { if (fishingOperationData.isWithBenthosBatchToConfirm()) { - List<BenthosBatch> benthosBatchEntries = fishingOperationData.getBenthosBatchToConfirm(); + List<SpeciesBatch> benthosBatchEntries = fishingOperationData.getBenthosBatchToConfirm(); benthosCache.loadInBatches(benthosBatchEntries); benthosCatchList = createBatchBeans(benthosWeightUnit, benthosBatchEntries); @@ -175,11 +173,11 @@ public class ToConfirmReportService extends AbstractTuttiService { } - protected <A extends SpeciesAbleBatch> List<ToConfirmReportBatchEntryBean> createBatchBeans(WeightUnit weightUnit, List<A> batchEntries) { + protected List<ToConfirmReportBatchEntryBean> createBatchBeans(WeightUnit weightUnit, List<SpeciesBatch> batchEntries) { List<ToConfirmReportBatchEntryBean> catchList = new ArrayList<>(); - for (SpeciesAbleBatch batch : batchEntries) { + for (SpeciesBatch batch : batchEntries) { Species species = batch.getSpecies(); @@ -209,7 +207,7 @@ public class ToConfirmReportService extends AbstractTuttiService { return catchList; } - protected String getBatchDecoratedSampleCategoryValue(SpeciesAbleBatch batch) { + protected String getBatchDecoratedSampleCategoryValue(SpeciesBatch batch) { Serializable sampleCategoryValue = batch.getSampleCategoryValue(); return decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatCheckDataService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatCheckDataService.java index e0f9152..bab7eb0 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatCheckDataService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatCheckDataService.java @@ -27,7 +27,6 @@ package fr.ifremer.tutti.service.genericformat; import com.google.common.base.Preconditions; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -173,7 +172,7 @@ public class GenericFormatCheckDataService extends AbstractTuttiService { rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, false); } - BatchContainer<BenthosBatch> rootBenthosBatch; + BatchContainer<SpeciesBatch> rootBenthosBatch; try { rootBenthosBatch = weightComputingService.getComputedBenthosBatches(fishingOperationId); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatContextSupport.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatContextSupport.java index f6f8f98..8c0a9ff 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatContextSupport.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatContextSupport.java @@ -76,7 +76,6 @@ import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; -import java.util.List; import java.util.Map; import java.util.Set; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java index e08a469..e694318 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java @@ -26,15 +26,12 @@ package fr.ifremer.tutti.service.genericformat; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; @@ -75,7 +72,7 @@ public class GenericFormatExportOperationContext { private BatchContainer<SpeciesBatch> rootSpeciesBatch; - private BatchContainer<BenthosBatch> rootBenthosBatch; + private BatchContainer<SpeciesBatch> rootBenthosBatch; private List<IndividualObservationBatch> individualObservations; @@ -223,7 +220,7 @@ public class GenericFormatExportOperationContext { return rootSpeciesBatch; } - public BatchContainer<BenthosBatch> getRootBenthosBatch() { + public BatchContainer<SpeciesBatch> getRootBenthosBatch() { return rootBenthosBatch; } @@ -255,11 +252,11 @@ public class GenericFormatExportOperationContext { return accidentalBatches; } - public boolean isVracBatch(SpeciesAbleBatch batch) { + public boolean isVracBatch(SpeciesBatch batch) { return persistenceService.isVracBatch(batch); } - public List<BenthosBatchFrequency> getAllBenthosBatchFrequency(Integer id) { + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(Integer id) { return persistenceService.getAllBenthosBatchFrequency(id); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportOperationContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportOperationContext.java index 7a51135..bf65e20 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportOperationContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportOperationContext.java @@ -29,15 +29,13 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchs; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.model.OperationDataModel; @@ -85,13 +83,13 @@ public class GenericFormatImportOperationContext implements Closeable { private final ArrayListMultimap<Integer, SpeciesBatchFrequency> speciesFrequencies; - private final Map<Integer, BenthosBatch> vracBenthosBatches; + private final Map<Integer, SpeciesBatch> vracBenthosBatches; - private final Map<Integer, BenthosBatch> horsVracBenthosBatches; + private final Map<Integer, SpeciesBatch> horsVracBenthosBatches; private final Map<Integer, Integer> batchesObjectIds; - private final ArrayListMultimap<Integer, BenthosBatchFrequency> benthosFrequencies; + private final ArrayListMultimap<Integer, SpeciesBatchFrequency> benthosFrequencies; private final CaracteristicMap gearUseFeatures; @@ -186,7 +184,7 @@ public class GenericFormatImportOperationContext implements Closeable { return getSpeciesBatchMap(vrac).get(referenceTaxonId); } - public BenthosBatch getBenthosBatch(boolean vrac, Integer referenceTaxonId) { + public SpeciesBatch getBenthosBatch(boolean vrac, Integer referenceTaxonId) { return getBenthosBatchMap(vrac).get(referenceTaxonId); } @@ -214,7 +212,7 @@ public class GenericFormatImportOperationContext implements Closeable { getSpeciesBatchMap(vrac).put(speciesBatch.getSpecies().getReferenceTaxonId(), speciesBatch); } - public void addBenthosBatch(boolean vrac, BenthosBatch benthosBatch) { + public void addBenthosBatch(boolean vrac, SpeciesBatch benthosBatch) { getBenthosBatchMap(vrac).put(benthosBatch.getSpecies().getReferenceTaxonId(), benthosBatch); } @@ -222,7 +220,7 @@ public class GenericFormatImportOperationContext implements Closeable { speciesFrequencies.put(batch.getIdAsInt(), frequency); } - public void addBenthosFrequency(BenthosBatch batch, BenthosBatchFrequency frequency) { + public void addBenthosFrequency(SpeciesBatch batch, SpeciesBatchFrequency frequency) { benthosFrequencies.put(batch.getIdAsInt(), frequency); } @@ -242,17 +240,17 @@ public class GenericFormatImportOperationContext implements Closeable { return ImmutableList.copyOf(individualObservationBatchesById.values()); } - public int getNbSpeciesTaxon() { - Set<Species> speciesSet= new HashSet<>(); - SpeciesAbleBatchs.grabSpeciesChildBatchs(vracSpeciesBatches.values(), speciesSet); - SpeciesAbleBatchs.grabSpeciesChildBatchs(horsVracSpeciesBatches.values(), speciesSet); + public int getNbSpeciesTaxon() { + Set<Species> speciesSet = new HashSet<>(); + SpeciesBatchs.grabSpeciesChildBatchs(vracSpeciesBatches.values(), speciesSet); + SpeciesBatchs.grabSpeciesChildBatchs(horsVracSpeciesBatches.values(), speciesSet); return speciesSet.size(); } - public int getNbBenthosTaxon() { - Set<Species> speciesSet= new HashSet<>(); - SpeciesAbleBatchs.grabSpeciesChildBatchs(vracBenthosBatches.values(), speciesSet); - SpeciesAbleBatchs.grabSpeciesChildBatchs(horsVracBenthosBatches.values(), speciesSet); + public int getNbBenthosTaxon() { + Set<Species> speciesSet = new HashSet<>(); + SpeciesBatchs.grabSpeciesChildBatchs(vracBenthosBatches.values(), speciesSet); + SpeciesBatchs.grabSpeciesChildBatchs(horsVracBenthosBatches.values(), speciesSet); return speciesSet.size(); } @@ -260,11 +258,11 @@ public class GenericFormatImportOperationContext implements Closeable { return ImmutableList.copyOf(getSpeciesBatchMap(vrac).values()); } - public Collection<BenthosBatch> getBenthosBatches(boolean vrac) { + public Collection<SpeciesBatch> getBenthosBatches(boolean vrac) { return ImmutableList.copyOf(getBenthosBatchMap(vrac).values()); } - public List<BenthosBatchFrequency> getBenthosFrequencies(BenthosBatch benthosBatch) { + public List<SpeciesBatchFrequency> getBenthosFrequencies(SpeciesBatch benthosBatch) { return benthosFrequencies.get(benthosBatch.getIdAsInt()); } @@ -284,7 +282,7 @@ public class GenericFormatImportOperationContext implements Closeable { return vrac ? vracSpeciesBatches : horsVracSpeciesBatches; } - private Map<Integer, BenthosBatch> getBenthosBatchMap(boolean vrac) { + private Map<Integer, SpeciesBatch> getBenthosBatchMap(boolean vrac) { return vrac ? vracBenthosBatches : horsVracBenthosBatches; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericformatImportPersistenceHelper.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericformatImportPersistenceHelper.java index 26feeef..bee006e 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericformatImportPersistenceHelper.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericformatImportPersistenceHelper.java @@ -29,8 +29,6 @@ import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -183,18 +181,18 @@ public class GenericformatImportPersistenceHelper { } - public BenthosBatch createBenthosBatch(BenthosBatch batch, Integer parentId) { + public SpeciesBatch createBenthosBatch(SpeciesBatch batch, Integer parentId) { return persistenceService.createBenthosBatch(batch, parentId, false); } - public void saveBenthosBatchFrequency(Integer batchId, List<BenthosBatchFrequency> frequencies) { + public void saveBenthosBatchFrequency(Integer batchId, List<SpeciesBatchFrequency> frequencies) { persistenceService.saveBenthosBatchFrequency(batchId, frequencies); } public void deleteBenthosBatchForFishingOperation(Integer fishingOperationId) { - BatchContainer<BenthosBatch> rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, false); - for (BenthosBatch batch : rootBenthosBatch.getChildren()) { + BatchContainer<SpeciesBatch> rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, false); + for (SpeciesBatch batch : rootBenthosBatch.getChildren()) { persistenceService.deleteBenthosBatch(batch.getIdAsInt()); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java index 6f9ec6b..52a04e3 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java @@ -26,13 +26,7 @@ package fr.ifremer.tutti.service.genericformat.consumer; import com.google.common.base.Predicate; import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequencys; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchs; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; -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.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequencys; @@ -106,7 +100,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } - if (bean.getFrequencyWeight()!=null && Weights.isEqualWeight(bean.getFrequencyWeight(), 0f)) { + if (bean.getFrequencyWeight() != null && Weights.isEqualWeight(bean.getFrequencyWeight(), 0f)) { // Cant have a Weight 0.0 addCheckError(row, new FrequencyWeigthNullValueException(operationContext.getFishingOperation())); @@ -196,13 +190,13 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { Species species = bean.getSpecies(); boolean vrac = bean.isVrac(); - BenthosBatch batch = operationContext.getBenthosBatch(vrac, species.getReferenceTaxonId()); + SpeciesBatch batch = operationContext.getBenthosBatch(vrac, species.getReferenceTaxonId()); if (batch == null) { // create root batch - batch = BenthosBatchs.newBenthosBatch(); + batch = SpeciesBatchs.newBenthosBatch(); batch.setId(getNextBatchId()); batch.setSpecies(species); batch.setSpeciesToConfirm(bean.isSpeciesToConfirm()); @@ -220,7 +214,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { if (withFrequency) { - BenthosBatchFrequency frequency = BenthosBatchFrequencys.newBenthosBatchFrequency(); + SpeciesBatchFrequency frequency = SpeciesBatchFrequencys.newBenthosBatchFrequency(); frequency.setBatch(batch); frequency.setLengthStepCaracteristic(bean.getFrequencyLengthStepCaracteristic()); frequency.setLengthStep(bean.getFrequencyLengthStep()); @@ -241,7 +235,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } - protected <A extends SpeciesAbleBatch> A fillBatchCategories(GenericFormatImportOperationContext operationContext, A batch, CatchRow bean) { + protected SpeciesBatch fillBatchCategories(GenericFormatImportOperationContext operationContext, SpeciesBatch batch, CatchRow bean) { for (ExportSampleCategory exportSampleCategory : bean.getFilledSampleCategories()) { batch = fillBatchCategories(operationContext, batch, exportSampleCategory); @@ -251,9 +245,9 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } - protected <A extends SpeciesAbleBatch> A fillBatchCategories(GenericFormatImportOperationContext operationContext, A batch, ExportSampleCategory sampleCategory) { + protected SpeciesBatch fillBatchCategories(GenericFormatImportOperationContext operationContext, SpeciesBatch batch, ExportSampleCategory sampleCategory) { - A result = null; + SpeciesBatch result = null; if (batch.getSampleCategoryId() == null) { @@ -270,17 +264,17 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } else { if (batch.getSampleCategoryId().equals(sampleCategory.getCategoryId()) && - batch.getSampleCategoryValue().equals(sampleCategory.getCategoryValue())) { + batch.getSampleCategoryValue().equals(sampleCategory.getCategoryValue())) { result = batch; } else if (!batch.isChildBatchsEmpty()) { // got some childs, try to find a matching one - for (A childBatch : SpeciesAbleBatchs.getChildBatchs(batch)) { + for (SpeciesBatch childBatch : batch.getChildBatchs()) { if (childBatch.getSampleCategoryId().equals(sampleCategory.getCategoryId()) && - childBatch.getSampleCategoryValue().equals(sampleCategory.getCategoryValue())) { + childBatch.getSampleCategoryValue().equals(sampleCategory.getCategoryValue())) { // matching child result = childBatch; @@ -293,7 +287,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { if (result == null) { // add a child - result = SpeciesAbleBatchs.createNewChild(batch); + result = SpeciesBatchs.createNewChild(batch); result.setId(getNextBatchId()); result.setRankOrder(sampleCategory.getRankOrder()); result.setSampleCategoryId(sampleCategory.getCategoryId()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java index e9f4011..422a561 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java @@ -24,7 +24,7 @@ package fr.ifremer.tutti.service.genericformat.csv; import com.google.common.base.Preconditions; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -143,7 +143,7 @@ public class CatchRow extends RowWithOperationContextSupport { this.sampleCategory.set(order, sampleCategory); } - public void setFrequency(SpeciesAbleBatchFrequency frequency) { + public void setFrequency(SpeciesBatchFrequency frequency) { Preconditions.checkNotNull(frequency); setFrequencyLengthStepCaracteristic(frequency.getLengthStepCaracteristic()); setFrequencyLengthStep(frequency.getLengthStep()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateCatchBatchRowsAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateCatchBatchRowsAction.java index 5dda418..cb7004c 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateCatchBatchRowsAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateCatchBatchRowsAction.java @@ -27,7 +27,6 @@ package fr.ifremer.tutti.service.genericformat.exportactions; import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.service.PersistenceService; @@ -156,7 +155,7 @@ public class CreateCatchBatchRowsAction extends ExportFishingOperationActionSupp private void prepareBenthosBatches(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - BatchContainer<BenthosBatch> rootSpeciesBatch = operationContext.getRootBenthosBatch(); + BatchContainer<SpeciesBatch> rootSpeciesBatch = operationContext.getRootBenthosBatch(); // Warning! This will also add the survey code to batch species CsvProducerForSpecies producerForSpecies = exportContext.getProducerForSpecies(); @@ -168,7 +167,7 @@ public class CreateCatchBatchRowsAction extends ExportFishingOperationActionSupp List<AttachmentRow> attachmentRows = new ArrayList<>(); - for (BenthosBatch benthosBatch : rootSpeciesBatch.getChildren()) { + for (SpeciesBatch benthosBatch : rootSpeciesBatch.getChildren()) { List<Attachment> attachments = persistenceService.getAllAttachments(ObjectTypeCode.BATCH, benthosBatch.getIdAsInt()); producerForAttachment.addAttachments(attachments, attachmentRows); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportCatchAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportCatchAction.java index 55521a5..a6685c5 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportCatchAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportCatchAction.java @@ -26,8 +26,6 @@ package fr.ifremer.tutti.service.genericformat.importactions; import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.ProgressionModel; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; @@ -73,10 +71,10 @@ public class ImportCatchAction extends ImportActionSupport { @Override protected boolean canExecute() { return importContext.isTechnicalFilesValid() - && importContext.getSurveyFileResult().isValid() - && importContext.getOperationFileResult().isValid() - && (importContext.getImportRequest().isImportSpecies() || - importContext.getImportRequest().isImportBenthos()); + && importContext.getSurveyFileResult().isValid() + && importContext.getOperationFileResult().isValid() + && (importContext.getImportRequest().isImportSpecies() || + importContext.getImportRequest().isImportBenthos()); } @Override @@ -85,7 +83,7 @@ public class ImportCatchAction extends ImportActionSupport { importContext.increments(t("tutti.service.genericFormat.skip.import.catches")); if (!(importContext.getImportRequest().isImportSpecies() || - importContext.getImportRequest().isImportBenthos())) { + importContext.getImportRequest().isImportBenthos())) { GenericFormatCsvFileResult importFileResult = importContext.getCatchFileResult(); importFileResult.setSkipped(true); } @@ -121,7 +119,7 @@ public class ImportCatchAction extends ImportActionSupport { persistSpeciesBatches(); } - if(importContext.getImportRequest().isImportBenthos()) { + if (importContext.getImportRequest().isImportBenthos()) { persistBenthosBatches(); } @@ -251,7 +249,7 @@ public class ImportCatchAction extends ImportActionSupport { if (fishingOperationContext.withBenthosBatches(true)) { - Collection<BenthosBatch> batches = fishingOperationContext.getBenthosBatches(true); + Collection<SpeciesBatch> batches = fishingOperationContext.getBenthosBatches(true); if (log.isInfoEnabled()) { log.info("Persist " + batches.size() + " VRAC benthos batch(es) of " + operationStr + " for cruise: " + cruiseStr); } @@ -261,7 +259,7 @@ public class ImportCatchAction extends ImportActionSupport { if (fishingOperationContext.withBenthosBatches(false)) { - Collection<BenthosBatch> batches = fishingOperationContext.getBenthosBatches(false); + Collection<SpeciesBatch> batches = fishingOperationContext.getBenthosBatches(false); if (log.isInfoEnabled()) { log.info("Persist " + batches.size() + " HORS VRAC benthos batch(es) of " + operationStr + " for cruise: " + cruiseContext.getCruiseLabel()); } @@ -272,22 +270,22 @@ public class ImportCatchAction extends ImportActionSupport { } } - private void persistBenthosBatches(GenericFormatImportOperationContext fishingOperationContext, Collection<BenthosBatch> batches, Integer parentId) { + private void persistBenthosBatches(GenericFormatImportOperationContext fishingOperationContext, Collection<SpeciesBatch> batches, Integer parentId) { int rankOrder = 1; - for (BenthosBatch batch : batches) { + for (SpeciesBatch batch : batches) { batch.setRankOrder(rankOrder++); Integer batchObjectId = fishingOperationContext.getBatchObjectId(batch.getIdAsInt()); - List<BenthosBatchFrequency> frequencies = fishingOperationContext.getBenthosFrequencies(batch); + List<SpeciesBatchFrequency> frequencies = fishingOperationContext.getBenthosFrequencies(batch); // reset temporary id to persist batch batch.setId((Integer) null); - BenthosBatch createdBatch = persistenceHelper.createBenthosBatch(batch, parentId); + SpeciesBatch createdBatch = persistenceHelper.createBenthosBatch(batch, parentId); Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(ObjectTypeCode.BATCH, batchObjectId); persistenceHelper.persistAttachments(createdBatch.getIdAsInt(), attachmentRows); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java index 251b6f1..dba9f60 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java @@ -25,8 +25,6 @@ package fr.ifremer.tutti.service.genericformat.producer; */ import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; @@ -73,7 +71,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { BatchContainer<SpeciesBatch> rootSpeciesBatch = operationExportContext.getRootSpeciesBatch(); - BatchContainer<BenthosBatch> rootBenthosBatch = operationExportContext.getRootBenthosBatch(); + BatchContainer<SpeciesBatch> rootBenthosBatch = operationExportContext.getRootBenthosBatch(); Caracteristic weightMeasuredCaracteristic = operationExportContext.getWeightMeasuredCaracteristic(); String batchWeightUnit = weightMeasuredCaracteristic.getUnit(); @@ -102,7 +100,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { List<CatchRow> rows = new ArrayList<>(); - BatchContainer<BenthosBatch> rootBenthosBatch = operationExportContext.getRootBenthosBatch(); + BatchContainer<SpeciesBatch> rootBenthosBatch = operationExportContext.getRootBenthosBatch(); Caracteristic weightMeasuredCaracteristic = operationExportContext.getWeightMeasuredCaracteristic(); String batchWeightUnit = weightMeasuredCaracteristic.getUnit(); @@ -144,12 +142,12 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { } protected void addBenthosBatches(GenericFormatExportOperationContext operationExportContext, - BatchContainer<BenthosBatch> rootBenthosBatch, + BatchContainer<SpeciesBatch> rootBenthosBatch, Float benthosCatchRaisingFactor, String batchWeightUnit, List<CatchRow> rows) { - for (BenthosBatch benthosBatch : rootBenthosBatch.getChildren()) { + for (SpeciesBatch benthosBatch : rootBenthosBatch.getChildren()) { boolean vracBatch = operationExportContext.isVracBatch(benthosBatch); @@ -317,7 +315,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { // use concrete frequency weight referenceWeight = batchFrequency.getWeight(); - frequencyWeights+= referenceWeight; + frequencyWeights += referenceWeight; } setRaisingFactor(row, totalBatchWeight, referenceWeight); @@ -370,7 +368,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { protected void addBenthosBatch(GenericFormatExportOperationContext operationExportContext, CatchRow currentRow, List<CatchRow> rows, - BenthosBatch benthosBatch, + SpeciesBatch benthosBatch, float totalBatchWeight) { Integer number = Numbers.getValueOrComputedValue(benthosBatch.getNumber(), @@ -397,7 +395,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { // on a leaf, get frequencies - List<BenthosBatchFrequency> benthosBatchFrequency = + List<SpeciesBatchFrequency> benthosBatchFrequency = operationExportContext.getAllBenthosBatchFrequency(benthosBatch.getIdAsInt()); if (CollectionUtils.isEmpty(benthosBatchFrequency)) { @@ -446,7 +444,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { float frequencyWeights = 0f; Set<CatchRow> frequencyRows = new LinkedHashSet<>(); - for (BenthosBatchFrequency batchFrequency : benthosBatchFrequency) { + for (SpeciesBatchFrequency batchFrequency : benthosBatchFrequency) { CatchRow row = currentRow.copy(); row.setFrequency(batchFrequency); frequencyRows.add(row); @@ -456,7 +454,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { // use concrete frequency weight referenceWeight = batchFrequency.getWeight(); - frequencyWeights+=referenceWeight; + frequencyWeights += referenceWeight; } setRaisingFactor(row, totalBatchWeight, referenceWeight); @@ -476,7 +474,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { float sampleComputedWeight = 0f; - for (BenthosBatch childBatch : benthosBatch.getChildBatchs()) { + for (SpeciesBatch childBatch : benthosBatch.getChildBatchs()) { // always use a copy, otherwise sample categories can be shared by brothers CatchRow childRow = currentRow.copy(); addBenthosBatch(operationExportContext, diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForSpecies.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForSpecies.java index b0412fb..5f34473 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForSpecies.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForSpecies.java @@ -27,7 +27,6 @@ package fr.ifremer.tutti.service.genericformat.producer; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.csv.CsvProducer; @@ -66,9 +65,9 @@ public class CsvProducerForSpecies extends CsvProducer<SpeciesExportRow, Species } - public void prepareBenthosBatchRows(BatchContainer<BenthosBatch> rootBenthosBatch) { + public void prepareBenthosBatchRows(BatchContainer<SpeciesBatch> rootBenthosBatch) { - for (BenthosBatch benthosBatch : rootBenthosBatch.getChildren()) { + for (SpeciesBatch benthosBatch : rootBenthosBatch.getChildren()) { addSpecies(benthosBatch.getSpecies()); } diff --git a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/BenthosBatch-edit-error-validation.xml b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/BenthosBatch-edit-error-validation.xml deleted file mode 100644 index 6678a97..0000000 --- a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/BenthosBatch-edit-error-validation.xml +++ /dev/null @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - #%L - Tutti :: Service - $Id$ - $HeadURL$ - %% - Copyright (C) 2012 - 2014 Ifremer - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program. If not, see - <http://www.gnu.org/licenses/gpl-3.0.html>. - #L% - --> - -<!DOCTYPE validators PUBLIC - "-//Apache Struts//XWork Validator 1.0.3//EN" - "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> -<validators> - - <field name="species"> - <field-validator type="required" short-circuit="true"> - <message>tutti.validator.error.benthosBatch.species.required</message> - </field-validator> - </field> - - <field name="weight"> - <field-validator type="fieldexpression" short-circuit="true"> - <param name="expression"> - <![CDATA[ !(sampleCategoryWeight == null && weight != null) ]]> - </param> - <message>tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightCategory</message> - </field-validator> - - <field-validator type="fieldexpression" short-circuit="true"> - <param name="expression"> - <![CDATA[ weight == null || sampleCategoryWeight == null || weight <= sampleCategoryWeight ]]> - </param> - <message>tutti.service.operations.computeWeights.error.benthos.incoherentSampleWeight</message> - </field-validator> - </field> - -</validators> diff --git a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/BenthosBatch-validate-fatal-validation.xml b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/BenthosBatch-validate-fatal-validation.xml deleted file mode 100644 index 4ddb9a0..0000000 --- a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/BenthosBatch-validate-fatal-validation.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - #%L - Tutti :: Service - $Id:$ - $HeadURL:$ - %% - Copyright (C) 2012 - 2014 Ifremer - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program. If not, see - <http://www.gnu.org/licenses/gpl-3.0.html>. - #L% - --> - - -<!DOCTYPE validators PUBLIC - "-//Apache Struts//XWork Validator 1.0.3//EN" - "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> -<validators> - - <field name="species"> - <field-validator type="temporaryReferential" short-circuit="true"> - <message>tutti.validator.error.benthosBatch.species.temporary</message> - </field-validator> - </field> - -</validators> diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/BeanValidatorDetectorTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/BeanValidatorDetectorTest.java index 0f530b6..dee857c 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/BeanValidatorDetectorTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/BeanValidatorDetectorTest.java @@ -58,7 +58,6 @@ public class BeanValidatorDetectorTest extends AbstractValidatorDetectorTest { public static void setUpClass() throws Exception { ALL_TYPES = new Class[]{ AccidentalBatch.class, - BenthosBatch.class, CatchBatch.class, Cruise.class, FishingOperation.class, @@ -81,7 +80,7 @@ public class BeanValidatorDetectorTest extends AbstractValidatorDetectorTest { SortedSet<NuitonValidator<?>> validators = detectValidators(ALL_TYPES); assertFalse(validators.isEmpty()); - assertEquals(17, validators.size()); + assertEquals(15, validators.size()); } @Test @@ -106,7 +105,6 @@ public class BeanValidatorDetectorTest extends AbstractValidatorDetectorTest { assertValidatorSetWithSameContextName(validators, contextName, AccidentalBatch.class, - BenthosBatch.class, CatchBatch.class, Cruise.class, FishingOperation.class, @@ -126,7 +124,6 @@ public class BeanValidatorDetectorTest extends AbstractValidatorDetectorTest { assertValidatorSetWithSameContextName(validators, contextName, AccidentalBatch.class, - BenthosBatch.class, CatchBatch.class, Cruise.class, FishingOperation.class, diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/PersistenceServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/PersistenceServiceTest.java index 051686b..0d57edb 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/PersistenceServiceTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/PersistenceServiceTest.java @@ -28,8 +28,6 @@ import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; @@ -110,7 +108,7 @@ public class PersistenceServiceTest { Gear source = service.getGear(-4); Gear target = service.getGear(378); - service.replaceGear(source, target,false ); + service.replaceGear(source, target, false); } { @@ -211,7 +209,7 @@ public class PersistenceServiceTest { BatchContainer<SpeciesBatch> rootSpeciesBatch = service.getRootSpeciesBatch(0, false); assertSpeciesBatch(rootSpeciesBatch, "-1"); - BatchContainer<BenthosBatch> rootBenthosBatch = service.getRootBenthosBatch(0, false); + BatchContainer<SpeciesBatch> rootBenthosBatch = service.getRootBenthosBatch(0, false); assertBenthosBatch(rootBenthosBatch, "-2"); List<IndividualObservationBatch> allIndividualObservationBatch = service.getAllIndividualObservationBatchsForFishingOperation(0); @@ -232,7 +230,7 @@ public class PersistenceServiceTest { BatchContainer<SpeciesBatch> rootSpeciesBatch = service.getRootSpeciesBatch(0, false); assertSpeciesBatch(rootSpeciesBatch, "15461"); - BatchContainer<BenthosBatch> rootBenthosBatch = service.getRootBenthosBatch(0, false); + BatchContainer<SpeciesBatch> rootBenthosBatch = service.getRootBenthosBatch(0, false); assertBenthosBatch(rootBenthosBatch, "-2"); List<IndividualObservationBatch> allIndividualObservationBatch = service.getAllIndividualObservationBatchsForFishingOperation(0); @@ -246,14 +244,14 @@ public class PersistenceServiceTest { Species source = service.getSpeciesByReferenceTaxonId(-2); Species target = service.getSpeciesByReferenceTaxonId(2); - service.replaceSpecies(source, target,false ); + service.replaceSpecies(source, target, false); } { BatchContainer<SpeciesBatch> rootSpeciesBatch = service.getRootSpeciesBatch(0, false); assertSpeciesBatch(rootSpeciesBatch, "15461"); - BatchContainer<BenthosBatch> rootBenthosBatch = service.getRootBenthosBatch(0, false); + BatchContainer<SpeciesBatch> rootBenthosBatch = service.getRootBenthosBatch(0, false); assertBenthosBatch(rootBenthosBatch, "15462"); List<IndividualObservationBatch> allIndividualObservationBatch = service.getAllIndividualObservationBatchsForFishingOperation(0); @@ -273,7 +271,7 @@ public class PersistenceServiceTest { BatchContainer<SpeciesBatch> rootSpeciesBatch = service.getRootSpeciesBatch(0, false); assertSpeciesBatch(rootSpeciesBatch, "15461"); - BatchContainer<BenthosBatch> rootBenthosBatch = service.getRootBenthosBatch(0, false); + BatchContainer<SpeciesBatch> rootBenthosBatch = service.getRootBenthosBatch(0, false); assertBenthosBatch(rootBenthosBatch, "15462"); List<IndividualObservationBatch> allIndividualObservationBatch = service.getAllIndividualObservationBatchsForFishingOperation(0); @@ -373,14 +371,14 @@ public class PersistenceServiceTest { } } - protected void assertBenthosBatch(BatchContainer<BenthosBatch> rootSpeciesBatch, String expectedId) { + protected void assertBenthosBatch(BatchContainer<SpeciesBatch> rootSpeciesBatch, String expectedId) { Assert.assertNotNull(rootSpeciesBatch); Assert.assertNotNull(rootSpeciesBatch.getChildren()); Assert.assertFalse(rootSpeciesBatch.isEmptyChildren()); - for (BenthosBatch batch : rootSpeciesBatch.getChildren()) { + for (SpeciesBatch batch : rootSpeciesBatch.getChildren()) { assertContainsId(batch.getSpecies(), expectedId); - List<BenthosBatchFrequency> frequencies = service.getAllBenthosBatchFrequency(batch.getIdAsInt()); - for (BenthosBatchFrequency frequency : frequencies) { + List<SpeciesBatchFrequency> frequencies = service.getAllBenthosBatchFrequency(batch.getIdAsInt()); + for (SpeciesBatchFrequency frequency : frequencies) { assertContainsId(frequency.getBatch().getSpecies(), expectedId); } } 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 index 60e7631..b526b34 100644 --- 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 @@ -38,8 +38,6 @@ 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.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; @@ -88,7 +86,7 @@ public class BigfinImportService2Test { protected File dataDirectory; - protected Predicate<SpeciesAbleBatch> vracPredicate; + protected Predicate<SpeciesBatch> vracPredicate; public static final String PROGRAM_ID = "CAM-CGFS"; @@ -110,7 +108,7 @@ public class BigfinImportService2Test { dataContext = dbResource.loadContext(PROGRAM_ID); - vracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate(PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.VRAC.getValue()); + vracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate(PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.VRAC.getValue()); } @Test @@ -321,7 +319,7 @@ public class BigfinImportService2Test { Assert.assertEquals(5, rootSpeciesBatch.sizeChildren()); Set<Species> speciesSet = new LinkedHashSet<>(); - SpeciesAbleBatchs.grabSpeciesChildBatchs(rootSpeciesBatch.getChildren(), speciesSet); + SpeciesBatchs.grabSpeciesChildBatchs(rootSpeciesBatch.getChildren(), speciesSet); Assert.assertEquals(5, speciesSet.size()); Assert.assertTrue(speciesSet.contains(rajaClaSpecies)); Assert.assertTrue(speciesSet.contains(tracDraSpecies)); @@ -332,7 +330,7 @@ public class BigfinImportService2Test { for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { Set<Integer> sampleCategories = new LinkedHashSet<>(); - SpeciesAbleBatchs.grabSampleCategorieValuesChildBatchs(speciesBatch, sampleCategories); + SpeciesBatchs.grabSampleCategorieValuesChildBatchs(speciesBatch, sampleCategories); List<SpeciesBatchFrequency> allSpeciesBatchFrequency = persistenceService.getAllSpeciesBatchFrequency(speciesBatch.getIdAsInt()); if (rajaClaSpecies.equals(speciesBatch.getSpecies())) { diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/bigfin/BigfinImportServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/bigfin/BigfinImportServiceTest.java index ef3624e..e024da9 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/bigfin/BigfinImportServiceTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/bigfin/BigfinImportServiceTest.java @@ -30,9 +30,8 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; 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.data.SpeciesBatchs; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.ServiceDbResource; import fr.ifremer.tutti.service.TuttiServiceContext; @@ -74,7 +73,7 @@ public class BigfinImportServiceTest { protected File dataDirectory; - protected Predicate<SpeciesAbleBatch> vracPredicate; + protected Predicate<SpeciesBatch> vracPredicate; @Before public void setUp() throws Exception { @@ -92,7 +91,7 @@ public class BigfinImportServiceTest { dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 1, OPERATION_1_ID); - vracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate(PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.VRAC.getValue()); + vracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate(PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.VRAC.getValue()); } @Test diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/WeightComputingServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/WeightComputingServiceTest.java index 7ef3905..abcd9f6 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/WeightComputingServiceTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/WeightComputingServiceTest.java @@ -22,9 +22,7 @@ package fr.ifremer.tutti.service.catches; * #L% */ -import org.nuiton.jaxx.application.ApplicationBusinessException; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; @@ -37,6 +35,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.nuiton.jaxx.application.ApplicationBusinessException; import java.util.List; @@ -111,7 +110,7 @@ public class WeightComputingServiceTest { catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_3_ID); try { - BatchContainer<BenthosBatch> batches = persistenceService.getRootBenthosBatch(OPERATION_3_ID, false); + BatchContainer<SpeciesBatch> batches = persistenceService.getRootBenthosBatch(OPERATION_3_ID, false); weightComputingService.computeCatchBatchWeights(catchBatch, null, batches, null); Assert.fail(); @@ -138,7 +137,7 @@ public class WeightComputingServiceTest { catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_5_ID); try { BatchContainer<SpeciesBatch> speciesBatches = persistenceService.getRootSpeciesBatch(OPERATION_5_ID, false); - BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_5_ID, false); + BatchContainer<SpeciesBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_5_ID, false); weightComputingService.computeCatchBatchWeights(catchBatch, speciesBatches, benthosBatches, null); Assert.fail(); @@ -164,7 +163,7 @@ public class WeightComputingServiceTest { catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_7_ID); try { BatchContainer<SpeciesBatch> speciesBatches = persistenceService.getRootSpeciesBatch(OPERATION_7_ID, false); - BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_7_ID, false); + BatchContainer<SpeciesBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_7_ID, false); weightComputingService.computeCatchBatchWeights(catchBatch, speciesBatches, benthosBatches, null); if (log.isInfoEnabled()) { log.info("Weight computing worked on operation #7"); @@ -208,11 +207,11 @@ public class WeightComputingServiceTest { Assert.fail(); } - BatchContainer<BenthosBatch> benthosBatchContainer = persistenceService.getRootBenthosBatch(OPERATION_1_ID, false); - List<BenthosBatch> benthosBatches = benthosBatchContainer.getChildren(); + BatchContainer<SpeciesBatch> benthosBatchContainer = persistenceService.getRootBenthosBatch(OPERATION_1_ID, false); + List<SpeciesBatch> benthosBatches = benthosBatchContainer.getChildren(); for (int i = 0; i < benthosBatches.size() - 1; i++) { try { - BenthosBatch batch = benthosBatches.get(i); + SpeciesBatch batch = benthosBatches.get(i); weightComputingService.computeBenthosBatch(batch); //expected error on species batch #0 : Benthos - Le lot de ABLEHIA - Ablennes hians/V/HV - Vrac n'a pas de poids //expected error on species batch #1 : Benthos - Le lot de ABLU - Abludomelita/V/HV - Vrac n'a pas de poids @@ -228,7 +227,7 @@ public class WeightComputingServiceTest { } } } - BenthosBatch benthosBatch = benthosBatches.get(benthosBatches.size() - 1); + SpeciesBatch benthosBatch = benthosBatches.get(benthosBatches.size() - 1); try { weightComputingService.computeBenthosBatch(benthosBatch); if (log.isInfoEnabled()) { diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/psionimport/PsionImportServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/psionimport/PsionImportServiceTest.java index 73d5b9d..1e037e4 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/psionimport/PsionImportServiceTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/psionimport/PsionImportServiceTest.java @@ -30,9 +30,8 @@ import fr.ifremer.tutti.persistence.ProgressionModel; 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.data.SpeciesBatchs; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.ServiceDbResource; import fr.ifremer.tutti.service.TuttiServiceContext; @@ -82,7 +81,7 @@ public class PsionImportServiceTest { protected File dataDirectory; - protected Predicate<SpeciesAbleBatch> vracPredicate; + protected Predicate<SpeciesBatch> vracPredicate; @Before public void setUp() throws Exception { @@ -105,7 +104,7 @@ public class PsionImportServiceTest { dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 3, OPERATION_2_ID, OPERATION_1_ID, OPERATION_3_ID); - vracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate(PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.VRAC.getValue()); + vracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate(PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.VRAC.getValue()); } @Test diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6116Test.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6116Test.java index 08e044d..87c305a 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6116Test.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6116Test.java @@ -31,9 +31,8 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; 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.data.SpeciesBatchs; import fr.ifremer.tutti.persistence.entities.referential.Species; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; @@ -104,32 +103,32 @@ public class PupitriImportServiceEvo6116Test extends PupitryImportServiceTestSup ); - Predicate<SpeciesAbleBatch> batchVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> batchVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_VRAC.getValue()); - Predicate<SpeciesAbleBatch> batchHorsVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> batchHorsVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_HORS_VRAC.getValue()); - Predicate<SpeciesAbleBatch> bigPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> bigPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SIZE_CATEGORY.getValue(), QualitativeValueId.SIZE_BIG.getValue()); - Predicate<SpeciesAbleBatch> smallPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> smallPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SIZE_CATEGORY.getValue(), QualitativeValueId.SIZE_SMALL.getValue()); - Predicate<SpeciesAbleBatch> malePredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> malePredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SEX.getValue(), QualitativeValueId.SEX_MALE.getValue()); - Predicate<SpeciesAbleBatch> femalePredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> femalePredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SEX.getValue(), QualitativeValueId.SEX_FEMALE.getValue()); - Predicate<SpeciesAbleBatch> undefinedPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> undefinedPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SEX.getValue(), QualitativeValueId.SEX_UNDEFINED.getValue()); diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149Test.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149Test.java index 466bdd0..755c3ab 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149Test.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149Test.java @@ -31,9 +31,8 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; 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.data.SpeciesBatchs; import fr.ifremer.tutti.persistence.entities.referential.Species; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; @@ -104,20 +103,20 @@ public class PupitriImportServiceEvo6149Test extends PupitryImportServiceTestSup ); - Predicate<SpeciesAbleBatch> batchVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> batchVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_VRAC.getValue()); - Predicate<SpeciesAbleBatch> batchHorsVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> batchHorsVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_HORS_VRAC.getValue()); - Predicate<SpeciesAbleBatch> bigVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> bigVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SIZE_CATEGORY.getValue(), QualitativeValueId.SIZE_BIG.getValue()); - Predicate<SpeciesAbleBatch> smallVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> smallVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SIZE_CATEGORY.getValue(), QualitativeValueId.SIZE_SMALL.getValue()); diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6592Test.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6592Test.java index 5618b00..fb90dda 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6592Test.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6592Test.java @@ -31,9 +31,8 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; 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.data.SpeciesBatchs; import fr.ifremer.tutti.persistence.entities.referential.Species; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; @@ -107,20 +106,20 @@ public class PupitriImportServiceEvo6592Test extends PupitryImportServiceTestSup ); - Predicate<SpeciesAbleBatch> batchVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> batchVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_VRAC.getValue()); - Predicate<SpeciesAbleBatch> batchHorsVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> batchHorsVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SORTED_UNSORTED.getValue(), QualitativeValueId.SORTED_HORS_VRAC.getValue()); - Predicate<SpeciesAbleBatch> bigVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> bigVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SIZE_CATEGORY.getValue(), QualitativeValueId.SIZE_BIG.getValue()); - Predicate<SpeciesAbleBatch> smallVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( + Predicate<SpeciesBatch> smallVracPredicate = SpeciesBatchs.newSpeciesAbleBatchCategoryPredicate( PmfmId.SIZE_CATEGORY.getValue(), QualitativeValueId.SIZE_SMALL.getValue()); -- 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/merge_species_benthos in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit ddeea47392e1c59d79716c2eae9dc56f4d67b3e9 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 17 09:13:35 2016 +0100 suppression de BenthosBatch, BenthosBatchFrequency et des contrat SpeciesBatchAble et SpeciesFrequencyBatchAble dans le module swing --- .../src/main/filtered-resources/log4j.properties | 2 +- .../catches/SpeciesAbleBatchRowHelper.java | 24 ++++----- .../operation/catches/SpeciesBatchDecorator.java | 14 ++--- .../catches/SpeciesBatchDecoratorComparator.java | 6 +-- .../SpeciesBatchNaturalOrderComparator.java | 16 +++--- .../catches/actions/ComputeBatchWeightsAction.java | 11 ++-- .../catches/benthos/BenthosBatchRowModel.java | 60 +++++++++++++--------- .../catches/benthos/BenthosBatchUIHandler.java | 30 +++++------ .../actions/ImportMultiPostBenthosAction.java | 8 +-- .../frequency/BenthosFrequencyRowModel.java | 54 +++++++++++-------- .../catches/species/SpeciesBatchRowModel.java | 10 ++++ .../frequency/SpeciesFrequencyRowModel.java | 10 ++++ 12 files changed, 142 insertions(+), 103 deletions(-) diff --git a/tutti-ui-swing/src/main/filtered-resources/log4j.properties b/tutti-ui-swing/src/main/filtered-resources/log4j.properties index a8f69d0..4f2f96c 100644 --- a/tutti-ui-swing/src/main/filtered-resources/log4j.properties +++ b/tutti-ui-swing/src/main/filtered-resources/log4j.properties @@ -33,7 +33,7 @@ log4j.appender.stdout.layout.ConversionPattern=[%20t] %d{ISO8601} %5p (%c:%L) - log4j.logger.fr.ifremer=INFO log4j.logger.fr.ifremer.tutti.ui.swing.util.SoundUtil=DEBUG # Keep this one to Info to show batch tree -log4j.logger.fr.ifremer.tutti.persistence.service.util.BatchTreeHelper=INFO +log4j.logger.fr.ifremer.tutti.persistence.service.util.tree=INFO log4j.logger.fr.ifremer.tutti.service.toconfirmreport=DEBUG log4j.logger.fr.ifremer.tutti.persistence.service.util.SynchronizationStatusHelper=WARN diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesAbleBatchRowHelper.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesAbleBatchRowHelper.java index 358e53b..b43ca44 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesAbleBatchRowHelper.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesAbleBatchRowHelper.java @@ -25,8 +25,8 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches; import com.google.common.base.Joiner; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.TuttiDecorator; import jaxx.runtime.SwingUtil; @@ -74,10 +74,10 @@ public class SpeciesAbleBatchRowHelper { public static final String SPECIES_DECORATOR_INDEX = "decoratorIndex"; - public static <E extends SpeciesAbleBatch> int getIndexToInsert(List<E> rows, - E newRow, - SpeciesSortMode sortMode, - SpeciesBatchDecorator decorator) { + public static <E extends SpeciesBatch> int getIndexToInsert(List<E> rows, + E newRow, + SpeciesSortMode sortMode, + SpeciesBatchDecorator decorator) { int result; @@ -192,10 +192,10 @@ public class SpeciesAbleBatchRowHelper { } - public static <R extends SpeciesAbleBatch> void sortSpeciesRows(SpeciesBatchDecoratorComparator comparator, - SpeciesBatchDecorator decorator, - List<R> rows, - SpeciesSortMode speciesSortMode) { + public static <R extends SpeciesBatch> void sortSpeciesRows(SpeciesBatchDecoratorComparator<R> comparator, + SpeciesBatchDecorator decorator, + List<R> rows, + SpeciesSortMode speciesSortMode) { comparator.setSpeciesSortMode(speciesSortMode); comparator.init(decorator, rows); @@ -220,7 +220,7 @@ public class SpeciesAbleBatchRowHelper { * @return la somme des poids des mensurations * @since 3.10 */ - public static <F extends SpeciesAbleBatchFrequency> Float getFrequenciesTotalWeight(Collection<F> frequency) { + public static <F extends SpeciesBatchFrequency> Float getFrequenciesTotalWeight(Collection<F> frequency) { if (CollectionUtils.isEmpty(frequency)) { @@ -230,7 +230,7 @@ public class SpeciesAbleBatchRowHelper { } float frequencyTotalWeight = 0; - for (F aFrequency : frequency) { + for (SpeciesBatchFrequency aFrequency : frequency) { if (aFrequency.getWeight() == null) { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java index 2f1c304..533cc11 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecorator.java @@ -22,24 +22,24 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches; * #L% */ -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; import static org.nuiton.i18n.I18n.t; /** - * To decorate some {@link SpeciesAbleBatch} as a {@link Species}. + * To decorate some {@link SpeciesBatch} as a {@link Species}. * * Used to be able to keep the hole speciesBatch in the cell. * * @since 2.8 */ -public class SpeciesBatchDecorator<R extends SpeciesAbleBatch> extends DecoratorService.SpeciesFromProtocolDecorator { +public class SpeciesBatchDecorator<R extends SpeciesBatch> extends DecoratorService.SpeciesFromProtocolDecorator { private static final long serialVersionUID = 1L; - public static <R extends SpeciesAbleBatch> SpeciesBatchDecorator<R> newDecorator() { + public static <R extends SpeciesBatch> SpeciesBatchDecorator<R> newDecorator() { return new SpeciesBatchDecorator<>(); } @@ -55,14 +55,14 @@ public class SpeciesBatchDecorator<R extends SpeciesAbleBatch> extends Decorator TuttiDecoratorComparator comparator = (TuttiDecoratorComparator<?>) context.getComparator(0); originalComparators[i] = comparator; Context context = contexts[i]; - context.setComparator(new SpeciesBatchDecoratorComparator<R>(comparator.getExpression())); + context.setComparator(new SpeciesBatchDecoratorComparator<>(comparator.getExpression())); } } @Override public String toString(Object bean) { - if (bean instanceof SpeciesAbleBatch) { - bean = ((SpeciesAbleBatch) bean).getSpecies(); + if (bean instanceof SpeciesBatch) { + bean = ((SpeciesBatch) bean).getSpecies(); } return super.toString(bean); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java index fae8599..4d5a209 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchDecoratorComparator.java @@ -22,14 +22,14 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches; * #L% */ -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.service.TuttiDecorator; import org.nuiton.decorator.JXPathDecorator; import java.util.List; /** - * To decorate a {@link SpeciesAbleBatch} as a species + keeping the logic of batchs childs. + * To decorate a {@link SpeciesBatch} as a species + keeping the logic of batchs childs. * * first sort on species, then always keep the row index order. * @@ -38,7 +38,7 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 2.8 */ -public class SpeciesBatchDecoratorComparator<R extends SpeciesAbleBatch> extends TuttiDecorator.TuttiDecoratorComparator<R> { +public class SpeciesBatchDecoratorComparator<R extends SpeciesBatch> extends TuttiDecorator.TuttiDecoratorComparator<R> { class RowComparatorContext implements Comparable<RowComparatorContext> { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchNaturalOrderComparator.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchNaturalOrderComparator.java index 01a5759..6c9a926 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchNaturalOrderComparator.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SpeciesBatchNaturalOrderComparator.java @@ -24,7 +24,7 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches; * #L% */ -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import java.io.Serializable; import java.util.Collections; @@ -36,7 +36,7 @@ import java.util.Map; /** * To compare some rows on their natural order. Means the order the data were stored. * - * For this we use the {@link SpeciesAbleBatch#getRankOrder()} for the parents and keep using the + * For this we use the {@link SpeciesBatch#getRankOrder()} for the parents and keep using the * rowIndex for the children. * * Created on 8/30/14. @@ -44,11 +44,11 @@ import java.util.Map; * @author Tony Chemit - chemit@codelutin.com * @since 3.7 */ -public class SpeciesBatchNaturalOrderComparator<R extends SpeciesAbleBatch> implements Comparator<R>, Serializable { +public class SpeciesBatchNaturalOrderComparator<R extends SpeciesBatch> implements Comparator<R>, Serializable { private static final long serialVersionUID = 1L; - public static <R extends SpeciesAbleBatch> void sort(List<R> data) { + public static <R extends SpeciesBatch> void sort(List<R> data) { SpeciesBatchNaturalOrderComparator<R> comparator = new SpeciesBatchNaturalOrderComparator<>(data); Collections.sort(data, comparator); @@ -70,8 +70,8 @@ public class SpeciesBatchNaturalOrderComparator<R extends SpeciesAbleBatch> impl @Override public int compare(R o1, R o2) { - SpeciesAbleBatch o1ParentBatch = getRootBatch(o1); - SpeciesAbleBatch o2ParentBatch = getRootBatch(o2); + SpeciesBatch o1ParentBatch = getRootBatch(o1); + SpeciesBatch o2ParentBatch = getRootBatch(o2); int result = o1ParentBatch.getRankOrder() - o2ParentBatch.getRankOrder(); @@ -88,9 +88,9 @@ public class SpeciesBatchNaturalOrderComparator<R extends SpeciesAbleBatch> impl return result; } - protected SpeciesAbleBatch getRootBatch(SpeciesAbleBatch o) { + protected SpeciesBatch getRootBatch(SpeciesBatch o) { - SpeciesAbleBatch root; + SpeciesBatch root; if (o.getParentBatch() == null) { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java index e474cb9..f525224 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java @@ -25,7 +25,6 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.actions; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; @@ -35,7 +34,6 @@ import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.catches.TuttiWeightComputingException; import fr.ifremer.tutti.service.catches.WeightCleaningService; import fr.ifremer.tutti.service.catches.WeightComputingService; -import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; @@ -50,6 +48,7 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchR import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchTableModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; +import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport; import fr.ifremer.tutti.util.Numbers; import jaxx.runtime.swing.JTables; import org.jdesktop.swingx.JXTable; @@ -159,7 +158,7 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo // --------- Float totalBenthosSortedWeight; - BatchContainer<BenthosBatch> computedBenthosBatches; + BatchContainer<SpeciesBatch> computedBenthosBatches; try { computedBenthosBatches = weightComputingService.getComputedBenthosBatches(operationId); @@ -421,13 +420,13 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo return totalSortedWeight; } - protected Float computeBenthosBatches(PersistenceService persistenceService, BatchContainer<BenthosBatch> computedBenthosBatches) { + protected Float computeBenthosBatches(PersistenceService persistenceService, BatchContainer<SpeciesBatch> computedBenthosBatches) { Float totalSortedWeight = 0f; if (computedBenthosBatches != null) { benthosBatchRows = Lists.newArrayList(); - List<BenthosBatch> children = computedBenthosBatches.getChildren(); - for (BenthosBatch batch : children) { + List<SpeciesBatch> children = computedBenthosBatches.getChildren(); + for (SpeciesBatch batch : children) { BenthosBatchRowModel row = getUI().getBenthosTabContent().getHandler().loadBatch(batch, null, benthosBatchRows); if (persistenceService.isVracBatch(row)) { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java index 52d0df9..1fe6bec 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java @@ -26,13 +26,13 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchs; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryAble; @@ -60,7 +60,7 @@ import java.util.Set; * @author Tony Chemit - chemit@codelutin.com * @since 0.2 */ -public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, BenthosBatchRowModel> implements BenthosBatch, AttachmentModelAware, SampleCategoryAble<BenthosBatchRowModel> { +public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, BenthosBatchRowModel> implements SpeciesBatch, AttachmentModelAware, SampleCategoryAble<BenthosBatchRowModel> { private static final long serialVersionUID = 1L; @@ -101,7 +101,7 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, * * @since 1.3 */ - protected final BenthosBatch editObject = BenthosBatchs.newBenthosBatch(); + protected final SpeciesBatch editObject = SpeciesBatchs.newBenthosBatch(); /** * All categories(can not be null). @@ -162,13 +162,13 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, */ protected final WeightUnit weightUnit; - protected static final Binder<BenthosBatch, BenthosBatchRowModel> fromBeanBinder = - BinderFactory.newBinder(BenthosBatch.class, + protected static final Binder<SpeciesBatch, BenthosBatchRowModel> fromBeanBinder = + BinderFactory.newBinder(SpeciesBatch.class, BenthosBatchRowModel.class); - protected static final Binder<BenthosBatchRowModel, BenthosBatch> toBeanBinder = + protected static final Binder<BenthosBatchRowModel, SpeciesBatch> toBeanBinder = BinderFactory.newBinder(BenthosBatchRowModel.class, - BenthosBatch.class); + SpeciesBatch.class); public BenthosBatchRowModel(WeightUnit weightUnit, SampleCategoryModel sampleCategoryModel) { @@ -193,8 +193,8 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, public BenthosBatchRowModel(WeightUnit weightUnit, SampleCategoryModel sampleCategoryModel, - BenthosBatch entity, - List<BenthosBatchFrequency> frequencies) { + SpeciesBatch entity, + List<SpeciesBatchFrequency> frequencies) { this(weightUnit, sampleCategoryModel); fromEntity(entity); @@ -215,12 +215,12 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, //------------------------------------------------------------------------// @Override - protected BenthosBatch newEntity() { - return BenthosBatchs.newBenthosBatch(); + protected SpeciesBatch newEntity() { + return SpeciesBatchs.newBenthosBatch(); } @Override - public void fromEntity(BenthosBatch entity) { + public void fromEntity(SpeciesBatch entity) { super.fromEntity(entity); // convert weight @@ -229,8 +229,8 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, } @Override - public BenthosBatch toEntity() { - BenthosBatch result = super.toEntity(); + public SpeciesBatch toEntity() { + SpeciesBatch result = super.toEntity(); // convert weight result.setWeight(weightUnit.toEntity(getWeight())); @@ -327,7 +327,7 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, } @Override - public void setParentBatch(BenthosBatch parentBatch) { + public void setParentBatch(SpeciesBatch parentBatch) { Object oldValue = getParentBatch(); editObject.setParentBatch(parentBatch); firePropertyChange(PROPERTY_PARENT_BATCH, oldValue, parentBatch); @@ -391,7 +391,7 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, } @Override - public BenthosBatch getChildBatchs(int index) { + public SpeciesBatch getChildBatchs(int index) { return childBatch.get(index); } @@ -406,35 +406,35 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, } @Override - public void addChildBatchs(BenthosBatch childBatchs) { + public void addChildBatchs(SpeciesBatch childBatchs) { } @Override - public void addAllChildBatchs(Collection<BenthosBatch> childBatchs) { + public void addAllChildBatchs(Collection<SpeciesBatch> childBatchs) { } @Override - public boolean removeChildBatchs(BenthosBatch childBatchs) { + public boolean removeChildBatchs(SpeciesBatch childBatchs) { return false; } @Override - public boolean removeAllChildBatchs(Collection<BenthosBatch> childBatchs) { + public boolean removeAllChildBatchs(Collection<SpeciesBatch> childBatchs) { return false; } @Override - public boolean containsChildBatchs(BenthosBatch childBatchs) { + public boolean containsChildBatchs(SpeciesBatch childBatchs) { return false; } @Override - public boolean containsAllChildBatchs(Collection<BenthosBatch> childBatchs) { + public boolean containsAllChildBatchs(Collection<SpeciesBatch> childBatchs) { return false; } @Override - public List<BenthosBatch> getChildBatchs() { + public List<SpeciesBatch> getChildBatchs() { return null; } @@ -452,6 +452,16 @@ public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, editObject.setRankOrder(rankOrder); } + @Override + public boolean isBenthosBatch() { + return editObject.isBenthosBatch(); + } + + @Override + public void setBenthosBatch(boolean benthosBatch) { + // NEVER! + } + //------------------------------------------------------------------------// //-- SampleCategoryAble --// //------------------------------------------------------------------------// diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java index 545b927..b00fb96 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java @@ -29,8 +29,8 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; @@ -174,16 +174,16 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent if (!TuttiEntities.isNew(bean)) { // get all batch species root (says the one with only a species sample category) - BatchContainer<BenthosBatch> rootBenthosBatch = + BatchContainer<SpeciesBatch> rootBenthosBatch = getPersistenceService().getRootBenthosBatch( bean.getIdAsInt(), true); - List<BenthosBatch> catches = rootBenthosBatch.getChildren(); + List<SpeciesBatch> catches = rootBenthosBatch.getChildren(); // use first category from configuration Integer firstCategoryId = sampleCategoryModel.getFirstCategoryId(); - for (BenthosBatch aBatch : catches) { + for (SpeciesBatch aBatch : catches) { // root batch sample categroy is species Preconditions.checkState( @@ -232,7 +232,7 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent @Override protected boolean isRowValid(BenthosBatchRowModel row) { - BenthosBatch batch = convertRowToEntity(row, true); + SpeciesBatch batch = convertRowToEntity(row, true); NuitonValidatorResult validator = getValidationService().validateEditBenthosBatch(batch); boolean result = !validator.hasErrorMessagess(); @@ -240,7 +240,7 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent && ValidationService.VALIDATION_CONTEXT_VALIDATE.equals( getContext().getValidationContext()) && row.isBatchLeaf()) { - List<BenthosBatchFrequency> frequencies = + List<SpeciesBatchFrequency> frequencies = BenthosFrequencyRowModel.toEntity( row.getFrequency(), batch); @@ -1113,13 +1113,13 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent } } - public BenthosBatchRowModel loadBatch(BenthosBatch aBatch, + public BenthosBatchRowModel loadBatch(SpeciesBatch aBatch, BenthosBatchRowModel parentRow, List<BenthosBatchRowModel> rows) { Integer id = aBatch.getIdAsInt(); - List<BenthosBatchFrequency> frequencies = + List<SpeciesBatchFrequency> frequencies = getPersistenceService().getAllBenthosBatchFrequency(id); BenthosBatchRowModel newRow = @@ -1168,7 +1168,7 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent newArrayListWithCapacity(aBatch.sizeChildBatchs()); Float childrenWeights = 0f; - for (BenthosBatch childBatch : aBatch.getChildBatchs()) { + for (SpeciesBatch childBatch : aBatch.getChildBatchs()) { BenthosBatchRowModel childRow = loadBatch(childBatch, newRow, rows); if (childrenWeights != null) { Float weight = childRow.getFinestCategory().getNotNullWeight(); @@ -1227,7 +1227,7 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent Preconditions.checkNotNull(row.getFinestCategory().getCategoryId()); Preconditions.checkNotNull(row.getFinestCategory().getCategoryValue()); - BenthosBatch entityToSave = row.toEntity(); + SpeciesBatch entityToSave = row.toEntity(); entityToSave.setFishingOperation(fishingOperation); @@ -1264,7 +1264,7 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent List<BenthosFrequencyRowModel> frequencyRows = row.getFrequency(); - List<BenthosBatchFrequency> frequency = + List<SpeciesBatchFrequency> frequency = BenthosFrequencyRowModel.toEntity( frequencyRows, entityToSave); @@ -1398,13 +1398,13 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent model.setRootNumber(model.getRootNumber() + 1); } - protected BenthosBatch convertRowToEntity(BenthosBatchRowModel row, boolean convertParent) { + protected SpeciesBatch convertRowToEntity(BenthosBatchRowModel row, boolean convertParent) { SampleCategory<?> sampleCategory = row.getFinestCategory(); Preconditions.checkNotNull(sampleCategory); Preconditions.checkNotNull(sampleCategory.getCategoryId()); Preconditions.checkNotNull(sampleCategory.getCategoryValue()); - BenthosBatch catchBean = row.toEntity(); + SpeciesBatch catchBean = row.toEntity(); // convert weight Float weight = catchBean.getWeight(); @@ -1419,7 +1419,7 @@ public class BenthosBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Bent catchBean.setSampleCategoryWeight(weightUnit.toEntity(categoryWeight)); if (convertParent && row.getParentBatch() != null) { - BenthosBatch parent = convertRowToEntity(row.getParentBatch(), true); + SpeciesBatch parent = convertRowToEntity(row.getParentBatch(), true); catchBean.setParentBatch(parent); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/actions/ImportMultiPostBenthosAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/actions/ImportMultiPostBenthosAction.java index 19ff54f..3427a8a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/actions/ImportMultiPostBenthosAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/actions/ImportMultiPostBenthosAction.java @@ -22,7 +22,7 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.actions; * #L% */ -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.service.catches.multipost.MultiPostImportService; @@ -98,10 +98,10 @@ public class ImportMultiPostBenthosAction extends ImportMultiPostActionSupport<B (Float) notImportedData.get(CatchBatch.PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT); addNotImportedWeightToReport(builder, livingNotItemizedWeight, benthosWeightUnit, n("tutti.multiPostImportLog.livingNotItemizedWeight")); - Collection<BenthosBatch> notImportedBenthosBatches = - (Collection<BenthosBatch>) notImportedData.get(MultiPostImportService.BATCHES_KEY); + Collection<SpeciesBatch> notImportedBenthosBatches = + (Collection<SpeciesBatch>) notImportedData.get(MultiPostImportService.BATCHES_KEY); - for (BenthosBatch sb : notImportedBenthosBatches) { + for (SpeciesBatch sb : notImportedBenthosBatches) { builder.append("- ").append(decorate(sb.getSpecies())).append(" / ").append(decorate(sb.getSampleCategoryValue())).append("\n"); } return builder.toString(); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyRowModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyRowModel.java index 0ab08a0..85eeb3f 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyRowModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyRowModel.java @@ -24,9 +24,9 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency; import com.google.common.collect.Lists; import com.google.common.collect.Ordering; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequencys; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequencys; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; @@ -41,7 +41,7 @@ import java.util.List; * @author Tony Chemit - chemit@codelutin.com * @since 0.2 */ -public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBatchFrequency, BenthosFrequencyRowModel> implements Comparable<BenthosFrequencyRowModel>, BenthosBatchFrequency { +public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<SpeciesBatchFrequency, BenthosFrequencyRowModel> implements Comparable<BenthosFrequencyRowModel>, SpeciesBatchFrequency { private static final long serialVersionUID = 1L; @@ -88,13 +88,13 @@ public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBa */ protected final WeightUnit weightUnit; - protected static final Binder<BenthosBatchFrequency, BenthosFrequencyRowModel> fromBeanBinder = - BinderFactory.newBinder(BenthosBatchFrequency.class, + protected static final Binder<SpeciesBatchFrequency, BenthosFrequencyRowModel> fromBeanBinder = + BinderFactory.newBinder(SpeciesBatchFrequency.class, BenthosFrequencyRowModel.class); - protected static final Binder<BenthosFrequencyRowModel, BenthosBatchFrequency> toBeanBinder = + protected static final Binder<BenthosFrequencyRowModel, SpeciesBatchFrequency> toBeanBinder = BinderFactory.newBinder(BenthosFrequencyRowModel.class, - BenthosBatchFrequency.class); + SpeciesBatchFrequency.class); private static final Ordering<Float> ordering = Ordering.natural().nullsFirst(); @@ -103,9 +103,9 @@ public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBa //------------------------------------------------------------------------// public static List<BenthosFrequencyRowModel> fromEntity(WeightUnit weightUnit, - List<BenthosBatchFrequency> entities) { + List<SpeciesBatchFrequency> entities) { List<BenthosFrequencyRowModel> result = Lists.newArrayList(); - for (BenthosBatchFrequency entity : entities) { + for (SpeciesBatchFrequency entity : entities) { BenthosFrequencyRowModel row = new BenthosFrequencyRowModel(weightUnit); @@ -115,11 +115,11 @@ public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBa return result; } - public static List<BenthosBatchFrequency> toEntity(List<BenthosFrequencyRowModel> rows, - BenthosBatch batch) { - List<BenthosBatchFrequency> result = Lists.newArrayList(); + public static List<SpeciesBatchFrequency> toEntity(List<BenthosFrequencyRowModel> rows, + SpeciesBatch batch) { + List<SpeciesBatchFrequency> result = Lists.newArrayList(); for (BenthosFrequencyRowModel row : rows) { - BenthosBatchFrequency model = row.toEntity(); + SpeciesBatchFrequency model = row.toEntity(); model.setBatch(batch); result.add(model); @@ -137,12 +137,12 @@ public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBa //------------------------------------------------------------------------// @Override - protected BenthosBatchFrequency newEntity() { - return BenthosBatchFrequencys.newBenthosBatchFrequency(); + protected SpeciesBatchFrequency newEntity() { + return SpeciesBatchFrequencys.newBenthosBatchFrequency(); } @Override - public void fromEntity(BenthosBatchFrequency entity) { + public void fromEntity(SpeciesBatchFrequency entity) { super.fromEntity(entity); // convert weight @@ -150,8 +150,8 @@ public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBa } @Override - public BenthosBatchFrequency toEntity() { - BenthosBatchFrequency result = super.toEntity(); + public SpeciesBatchFrequency toEntity() { + SpeciesBatchFrequency result = super.toEntity(); // convert weight result.setWeight(weightUnit.toEntity(getWeight())); @@ -159,7 +159,7 @@ public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBa } //------------------------------------------------------------------------// - //-- BenthosBatchFrequency --// + //-- SpeciesBatchFrequency --// //------------------------------------------------------------------------// @Override @@ -211,12 +211,12 @@ public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBa } @Override - public BenthosBatch getBatch() { + public SpeciesBatch getBatch() { return null; } @Override - public void setBatch(BenthosBatch batch) { + public void setBatch(SpeciesBatch batch) { } @Override @@ -233,6 +233,16 @@ public class BenthosFrequencyRowModel extends AbstractTuttiBeanUIModel<BenthosBa public void setRankOrder(Integer rankOrder) { } + @Override + public boolean isBenthosFrequencyBatch() { + return true; + } + + @Override + public void setBenthosFrequencyBatch(boolean benthosFrequencyBatch) { + //NEVER! + } + public boolean isEmpty() { return lengthStep == null && (weight == null || number == null); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java index dd3876b..1a3654a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java @@ -474,6 +474,16 @@ public class SpeciesBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, editObject.setRankOrder(rankOrder); } + @Override + public boolean isBenthosBatch() { + return editObject.isBenthosBatch(); + } + + @Override + public void setBenthosBatch(boolean benthosBatch) { + //NEVER! + } + //------------------------------------------------------------------------// //-- SampleCategoryAble --// //------------------------------------------------------------------------// diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java index 51976ae..65d6e83 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java @@ -294,6 +294,16 @@ public class SpeciesFrequencyRowModel extends AbstractTuttiBeanUIModel<SpeciesBa public void setRankOrder(Integer rankOrder) { } + @Override + public boolean isBenthosFrequencyBatch() { + return false; + } + + @Override + public void setBenthosFrequencyBatch(boolean benthosFrequencyBatch) { + //Never! + } + public boolean isEmpty() { return lengthStep == null && (weight == null || number == null); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm