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 2f8a884e515abe1dd24810acf52d75f99c6d02d9 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:43:51 2015 +0100 centralisation des méthodes utiles sur le protocol --- .../entities/protocol/TuttiProtocols.java | 140 ++++++++++++++++----- 1 file changed, 110 insertions(+), 30 deletions(-) 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 43f6564..a3ba922 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 @@ -32,6 +32,8 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; import com.google.common.io.Files; import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; import fr.ifremer.tutti.persistence.TuttiPersistence; @@ -44,6 +46,7 @@ import fr.ifremer.tutti.persistence.entities.protocol.v2.TuttiProtocol2; import fr.ifremer.tutti.persistence.entities.protocol.v2.TuttiProtocolBean2; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.Speciess; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; @@ -58,10 +61,12 @@ import java.io.File; import java.io.Reader; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeMap; import static org.nuiton.i18n.I18n.t; @@ -265,16 +270,6 @@ public class TuttiProtocols extends AbstractTuttiProtocols { } } - public static void removeBadSpecies(Set<Integer> speciesIds, List<SpeciesProtocol> protocol) { - Iterator<SpeciesProtocol> iterator = protocol.iterator(); - while (iterator.hasNext()) { - SpeciesProtocol next = iterator.next(); - if (speciesIds.contains(next.getSpeciesReferenceTaxonId())) { - iterator.remove(); - } - } - } - public static String getBadCategoriesMessage(Set<Integer> badCategories, Decorator<Caracteristic> decorator, TuttiPersistence persistenceService) { @@ -297,26 +292,6 @@ public class TuttiProtocols extends AbstractTuttiProtocols { return message; } - public static String getBadSpeciesMessage(Map<Integer, String> badSpecies) { - List<String> badCategoriesStr = Lists.newArrayList(); - - for (Map.Entry<Integer, String> id : badSpecies.entrySet()) { - badCategoriesStr.add("<li>" + id.getKey() + " : " + (id.getValue() == null ? "" : id.getValue()) + "</li>"); - } - String message = t("tutti.persistence.error.protocol.species.not.found", Joiner.on("").join(badCategoriesStr)); - return message; - } - - public static String getBadBenthosMessage(Map<Integer, String> badSpecies) { - List<String> badCategoriesStr = Lists.newArrayList(); - - for (Map.Entry<Integer, String> id : badSpecies.entrySet()) { - badCategoriesStr.add("<li>" + id.getKey() + " : " + (id.getValue() == null ? "" : id.getValue()) + "</li>"); - } - String message = t("tutti.persistence.error.protocol.benthos.not.found", Joiner.on("").join(badCategoriesStr)); - return message; - } - protected static TuttiProtocol2 fromTuttiProtocol1(TuttiProtocol1 tuttiProtocol1) { TuttiProtocol2 result = new TuttiProtocolBean2(); Binder<TuttiProtocol1, TuttiProtocol2> binder = BinderFactory.newBinder(TuttiProtocol1.class, TuttiProtocol2.class); @@ -569,4 +544,109 @@ public class TuttiProtocols extends AbstractTuttiProtocols { } + public static Map<Integer, SpeciesProtocol> toSpeciesProtocolMap(TuttiProtocol protocol) { + final Map<Integer, SpeciesProtocol> result = Maps.newHashMap(); + for (SpeciesProtocol sp : protocol.getSpecies()) { + result.put(sp.getSpeciesReferenceTaxonId(), sp); + } + return result; + } + + public static Map<Integer, SpeciesProtocol> toBenthosProtocolMap(TuttiProtocol protocol) { + final Map<Integer, SpeciesProtocol> result = Maps.newHashMap(); + for (SpeciesProtocol sp : protocol.getBenthos()) { + result.put(sp.getSpeciesReferenceTaxonId(), sp); + } + return result; + } + + public static Map<Integer, String> detectMissingSpecies(TuttiProtocol protocol, List<Species> species) { + + return TuttiProtocols.detectMissingSpecies(species, toSpeciesProtocolMap(protocol)); + + } + + public static Map<Integer, String> detectMissingBenthos(TuttiProtocol protocol, List<Species> species) { + + return TuttiProtocols.detectMissingSpecies(species, toBenthosProtocolMap(protocol)); + + } + + public static void removeBadSpecies(TuttiProtocol protocol, Map<Integer, String> speciesProtocolNotFound) { + + if (!speciesProtocolNotFound.isEmpty()) { + + Iterator<SpeciesProtocol> iterator = protocol.getSpecies().iterator(); + while (iterator.hasNext()) { + SpeciesProtocol speciesProtocol = iterator.next(); + Integer taxonId = speciesProtocol.getSpeciesReferenceTaxonId(); + boolean containsSpecies = speciesProtocolNotFound.containsKey(taxonId); + if (containsSpecies) { + if (log.isWarnEnabled()) { + log.warn("Could not find protocol species " + taxonId + " (" + speciesProtocol.getSpeciesSurveyCode() + ") in referential."); + } + iterator.remove(); + } + } + + } + + } + + public static void removeBadBenthos(TuttiProtocol protocol, Map<Integer, String> benthosProtocolNotFound) { + + if (!benthosProtocolNotFound.isEmpty()) { + + Iterator<SpeciesProtocol> iterator = protocol.getBenthos().iterator(); + while (iterator.hasNext()) { + SpeciesProtocol speciesProtocol = iterator.next(); + Integer taxonId = speciesProtocol.getSpeciesReferenceTaxonId(); + boolean containsSpecies = benthosProtocolNotFound.containsKey(taxonId); + if (containsSpecies) { + if (log.isWarnEnabled()) { + log.warn("Could not find protocol benthos " + taxonId + " (" + speciesProtocol.getSpeciesSurveyCode() + ") in referential."); + } + iterator.remove(); + } + } + + } + + } + + protected static Map<Integer, String> detectMissingSpecies(List<Species> species, Map<Integer, SpeciesProtocol> speciesProtocolMap) { + + Multimap<String, Species> speciesByRefTaxonId = Speciess.splitByReferenceTaxonId(species); + Map<Integer, String> badSpecies = new TreeMap<>(); + for (SpeciesProtocol speciesProtocol : speciesProtocolMap.values()) { + Integer referenceTaxonId = speciesProtocol.getSpeciesReferenceTaxonId(); + if (!speciesByRefTaxonId.containsKey(referenceTaxonId)) { + badSpecies.put(referenceTaxonId, speciesProtocol.getSpeciesSurveyCode()); + } + } + return Collections.unmodifiableMap(badSpecies); + + } + + public static String getBadSpeciesMessage(Map<Integer, String> speciesProtocolNotFound) { + + List<String> badCategoriesStr = Lists.newArrayList(); + for (Map.Entry<Integer, String> id : speciesProtocolNotFound.entrySet()) { + badCategoriesStr.add("<li>" + id.getKey() + " : " + (id.getValue() == null ? "" : id.getValue()) + "</li>"); + } + String message = t("tutti.persistence.error.protocol.species.not.found", Joiner.on("").join(badCategoriesStr)); + return message; + + } + + public static String getBadBenthosMessage(Map<Integer, String> benthosProtocolNotFound) { + + List<String> badCategoriesStr = Lists.newArrayList(); + for (Map.Entry<Integer, String> id : benthosProtocolNotFound.entrySet()) { + badCategoriesStr.add("<li>" + id.getKey() + " : " + (id.getValue() == null ? "" : id.getValue()) + "</li>"); + } + String message = t("tutti.persistence.error.protocol.benthos.not.found", Joiner.on("").join(badCategoriesStr)); + return message; + + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.