This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit 1570b716704a461a3e54891324a980ef6e6bb33f Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 10 09:58:19 2015 +0100 fixes #6631 --- .../tutti/persistence/TuttiPersistenceImpl.java | 51 +++++++++++++++------- .../entities/protocol/TuttiProtocols.java | 33 ++++++++++++++ 2 files changed, 69 insertions(+), 15 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 79d1478..0ea0a93 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 @@ -23,6 +23,7 @@ package fr.ifremer.tutti.persistence; */ import com.google.common.base.Predicate; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; @@ -542,34 +543,54 @@ public class TuttiPersistenceImpl implements TuttiPersistence { getSpeciesService().replaceSpecies(source, target, delete); + if (delete) { + removeSpeciesFromProtocol(Lists.newArrayList(source.getReferenceTaxonId())); + } + + } + + @Override + public void deleteTemporarySpecies(Integer referenceTaxonId) { + + getSpeciesService().deleteTemporarySpecies(referenceTaxonId); + removeSpeciesFromProtocol(Lists.newArrayList(referenceTaxonId)); + + } + + @Override + public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds) { + + getSpeciesService().deleteTemporarySpecies(referenceTaxonIds); + + removeSpeciesFromProtocol(referenceTaxonIds); + + } + + protected void removeSpeciesFromProtocol(Collection<Integer> referenceTaxonIds) { + TuttiProtocol protocol = getProtocol(); if (protocol != null) { - SpeciesProtocol speciesProtocol = TuttiProtocols.getSpeciesOrBenthosProtocol(protocol, source.getReferenceTaxonId()); + boolean wasRemoved = false; - if (speciesProtocol != null) { + for (Integer referenceTaxonId : referenceTaxonIds) { + + wasRemoved |= TuttiProtocols.removeSpeciesOrBenthosProtocol(protocol, referenceTaxonId); + + } + + if (wasRemoved) { if (log.isInfoEnabled()) { - log.info("Change referenceTaxonId " + source.getReferenceTaxonId() + " to " + target.getReferenceTaxonId() + " in protocol."); + log.info("Save protocol (some species or benthos were removed from it.)"); } - speciesProtocol.setSpeciesReferenceTaxonId(target.getReferenceTaxonId()); - saveProtocol(protocol); } - } - - } - @Override - public void deleteTemporarySpecies(Integer referenceTaxonId) { - getSpeciesService().deleteTemporarySpecies(referenceTaxonId); - } + } - @Override - public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds) { - getSpeciesService().deleteTemporarySpecies(referenceTaxonIds); } //------------------------------------------------------------------------// diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java index 8d3baeb..608f623 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java @@ -405,6 +405,39 @@ public class TuttiProtocols extends AbstractTuttiProtocols { return speciesProtocol; } + public static boolean removeSpeciesOrBenthosProtocol(TuttiProtocol protocol, Integer speciesReferenceTaxonId) { + + boolean wasRemoved = false; + + SpeciesProtocol speciesProtocol = getSpeciesProtocol(protocol, speciesReferenceTaxonId); + if (speciesProtocol != null) { + + if (log.isInfoEnabled()) { + log.info("Remove referenceTaxonId " + speciesReferenceTaxonId + " from species protocol " + speciesProtocol.getSpeciesSurveyCode()); + } + protocol.getSpecies().remove(speciesProtocol); + wasRemoved = true; + + } else { + + SpeciesProtocol benthosProtocol = getBenthosProtocol(protocol, speciesReferenceTaxonId); + + if (benthosProtocol != null) { + + if (log.isInfoEnabled()) { + log.info("Remove referenceTaxonId " + speciesReferenceTaxonId + " from benthos protocol " + benthosProtocol.getSpeciesSurveyCode()); + } + protocol.getBenthos().remove(benthosProtocol); + wasRemoved = true; + + } + + } + + return wasRemoved; + + } + /** * Return the species Protocol corresponding to the species of the given protocol. * -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.