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 730f20da6b2e8ba8b6c6b620afa8e24b987b6c89 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:42:54 2015 +0100 ajout de l'objet TaxonCache --- .../entities/referential/TaxonCache.java | 101 ++++++++++++++++++++ .../entities/referential/TaxonCaches.java | 105 +++++++++++++++++++++ 2 files changed, 206 insertions(+) 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 new file mode 100644 index 0000000..a911ce2 --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCache.java @@ -0,0 +1,101 @@ +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.protocol.SpeciesProtocol; + +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** +* Created on 2/17/15. +* +* @author Tony Chemit - chemit@codelutin.com +* @since 3.14 +*/ +public class TaxonCache { + + protected final boolean loadVernacularCode; + + protected final TuttiPersistence persistenceService; + + protected final Map<Integer, SpeciesProtocol> protocolMap; + + protected final Map<Integer, Species> speciesByReferenceTaxonId; + + TaxonCache(boolean loadVernacularCode, TuttiPersistence persistenceService, Map<Integer, SpeciesProtocol> protocolMap) { + this.loadVernacularCode = loadVernacularCode; + this.persistenceService = persistenceService; + this.protocolMap = protocolMap; + this.speciesByReferenceTaxonId = new TreeMap<>(); + } + + public String getLengthStepPmfmId(Species species) { + + SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); + String lengthStepPmfmId = speciesProtocol == null ? null : speciesProtocol.getLengthStepPmfmId(); + return lengthStepPmfmId; + + } + + public Float getLengthStep(Species species) { + + SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); + Float lengthStep = speciesProtocol == null ? null : speciesProtocol.getLengthStep(); + return lengthStep; + + } + + public void load(List<Species> speciesList) { + + for (Species species : speciesList) { + load(species); + } + + } + + public <A extends SpeciesAbleBatch> void loadInBatches(List<A> speciesAbleBatches) { + + for (A speciesAbleBatch : speciesAbleBatches) { + load(speciesAbleBatch.getSpecies()); + } + + } + + public void load(Species species) { + + Integer referenceTaxonId = species.getReferenceTaxonId(); + + Species speciesLoaded = speciesByReferenceTaxonId.get(referenceTaxonId); + + if (speciesLoaded == null) { + + if (loadVernacularCode) { + + Species speciesWithVerncularCode = + persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(referenceTaxonId); + species.setVernacularCode(speciesWithVerncularCode.getVernacularCode()); + + } + + if (protocolMap.containsKey(species.getReferenceTaxonId())) { + + SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); + String surveyCode = speciesProtocol.getSpeciesSurveyCode(); + species.setSurveyCode(surveyCode); + + } + + speciesByReferenceTaxonId.put(species.getReferenceTaxonId(), species); + + } else { + + species.setVernacularCode(speciesLoaded.getVernacularCode()); + species.setSurveyCode(speciesLoaded.getSurveyCode()); + + } + + } + +} diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCaches.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCaches.java new file mode 100644 index 0000000..dcb10f8 --- /dev/null +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCaches.java @@ -0,0 +1,105 @@ +package fr.ifremer.tutti.persistence.entities.referential; + +import fr.ifremer.tutti.persistence.TuttiPersistence; +import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocols; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created on 2/17/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class TaxonCaches { + + public static TaxonCache createSpeciesCacheWithoutVernacularCode(TuttiPersistence persistenceService, TuttiProtocol protocol) { + + boolean noProtocol = protocol == null; + + Map<Integer, SpeciesProtocol> protocolMap; + + if (noProtocol) { + + protocolMap = new HashMap<>(); + + } else { + + protocolMap = TuttiProtocols.toSpeciesProtocolMap(protocol); + + } + + + TaxonCache taxonCache = new TaxonCache(false, persistenceService, protocolMap); + return taxonCache; + + } + + public static TaxonCache createSpeciesCache(TuttiPersistence persistenceService, TuttiProtocol protocol) { + + boolean noProtocol = protocol == null; + + Map<Integer, SpeciesProtocol> protocolMap; + + if (noProtocol) { + + protocolMap = new HashMap<>(); + + } else { + + protocolMap = TuttiProtocols.toSpeciesProtocolMap(protocol); + + } + + TaxonCache taxonCache = new TaxonCache(true, persistenceService, protocolMap); + return taxonCache; + + } + + public static TaxonCache createBenthosCacheWithoutVernacularCode(TuttiPersistence persistenceService, TuttiProtocol protocol) { + + boolean noProtocol = protocol == null; + + Map<Integer, SpeciesProtocol> protocolMap; + + if (noProtocol) { + + protocolMap = new HashMap<>(); + + } else { + + protocolMap = TuttiProtocols.toBenthosProtocolMap(protocol); + + } + + + TaxonCache taxonCache = new TaxonCache(false, persistenceService, protocolMap); + return taxonCache; + + } + + public static TaxonCache createBenthosCache(TuttiPersistence persistenceService, TuttiProtocol protocol) { + + boolean noProtocol = protocol == null; + + Map<Integer, SpeciesProtocol> protocolMap; + + if (noProtocol) { + + protocolMap = new HashMap<>(); + + } else { + + protocolMap = TuttiProtocols.toBenthosProtocolMap(protocol); + + } + + TaxonCache taxonCache = new TaxonCache(true, persistenceService, protocolMap); + return taxonCache; + + } + +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.