branch develop updated (1012fd7 -> aa9e693)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See http://git.codelutin.com/tutti.git from 1012fd7 fix launcher version new 730f20d ajout de l'objet TaxonCache new 2f8a884 centralisation des méthodes utiles sur le protocol new 653c2f8 -mproduire une erreur si le code espèce n'existe pas new d9ebd30 utilisation des méthodes utilitaire du protocol new 1f32a0c suppression SpeciesMap (remplacé par TaxonCache) new adc517f utilisation des méthodes utilitaires du protocol new d5580b6 utilisation de TaxonCache dans les handler d'ui new bf3128e utilisation TaxonCache dans les services new aa9e693 fixes #6677 [TECH] Assainissement de l'utilisation des codes campagnes dans les taxons Merge branch 'feature/6677' into develop The 9 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 aa9e69329444b67f0ced7a9b0d55ffd6d59c7682 Merge: 1012fd7 bf3128e Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:53:36 2015 +0100 fixes #6677 [TECH] Assainissement de l'utilisation des codes campagnes dans les taxons Merge branch 'feature/6677' into develop commit bf3128ec0c789a547ba14f4392657ccc9727cffd Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:50:58 2015 +0100 utilisation TaxonCache dans les services commit d5580b6d1ec38fe5d8b235ef85aa9f5735aadc8f Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:50:19 2015 +0100 utilisation de TaxonCache dans les handler d'ui commit adc517ffc3eb6be7893d52448fbe528d295b2bd8 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:49:55 2015 +0100 utilisation des méthodes utilitaires du protocol commit 1f32a0cfc0eafbdc57fdc2051882cbf7fd543809 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:48:25 2015 +0100 suppression SpeciesMap (remplacé par TaxonCache) commit d9ebd307154b8d0029f722d9f19d642edaf943cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:44:59 2015 +0100 utilisation des méthodes utilitaire du protocol commit 653c2f88cb1df90b3ab7a5641a41037db274ad31 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:44:16 2015 +0100 -mproduire une erreur si le code espèce n'existe pas 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 commit 730f20da6b2e8ba8b6c6b620afa8e24b987b6c89 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:42:54 2015 +0100 ajout de l'objet TaxonCache Summary of changes: .../tutti/persistence/TuttiPersistenceImpl.java | 39 +---- .../entities/protocol/TuttiProtocols.java | 140 +++++++++++++---- .../persistence/entities/referential/Speciess.java | 12 ++ .../entities/referential/TaxonCache.java | 101 ++++++++++++ .../entities/referential/TaxonCaches.java | 105 +++++++++++++ .../i18n/tutti-persistence_en_GB.properties | 1 + .../i18n/tutti-persistence_fr_FR.properties | 1 + .../ifremer/tutti/service/PersistenceService.java | 174 +-------------------- .../java/fr/ifremer/tutti/service/SpeciesMap.java | 147 ----------------- .../fr/ifremer/tutti/service/TuttiDataContext.java | 12 +- .../export/pdf/CatchesPdfExportService.java | 163 +++++++------------ .../sumatra/CatchesSumatraExportService.java | 96 +++++++++--- .../toconfirmreport/ToConfirmReportService.java | 18 ++- .../service/psionimport/PsionImportService.java | 10 +- .../service/pupitri/PupitriImportService.java | 73 +++------ .../ui/swing/action/ImportProtocolAction.java | 65 +++----- .../frequency/BenthosFrequencyUIHandler.java | 30 ++-- .../CreateIndividualObservationBatchUIHandler.java | 18 +-- .../frequency/SpeciesFrequencyUIHandler.java | 43 ++--- 19 files changed, 568 insertions(+), 680 deletions(-) create mode 100644 tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCache.java create mode 100644 tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/TaxonCaches.java delete mode 100644 tutti-service/src/main/java/fr/ifremer/tutti/service/SpeciesMap.java -- 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 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>.
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>.
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 653c2f88cb1df90b3ab7a5641a41037db274ad31 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:44:16 2015 +0100 -mproduire une erreur si le code espèce n'existe pas --- .../tutti/persistence/entities/referential/Speciess.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/Speciess.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/Speciess.java index 959f61b..c31adbb 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/Speciess.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/referential/Speciess.java @@ -32,6 +32,8 @@ import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.collect.Sets; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.jaxx.application.ApplicationBusinessException; import java.util.Collections; import java.util.Comparator; @@ -39,6 +41,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static org.nuiton.i18n.I18n.t; + public class Speciess extends AbstractSpeciess { public static final Predicate<Species> IS_TEMPORARY = new Predicate<Species>() { @@ -167,6 +171,14 @@ public class Speciess extends AbstractSpeciess { // use refTaxCode code = species.getRefTaxCode(); } + + if (StringUtils.isEmpty(code)) { + + + throw new ApplicationBusinessException(t("tutti.persistence.error.species.withNoSurveyCodeOrRefTaxCode", species.getReferenceTaxonId(), species.getName())); + + } + return code; } } //Speciess -- 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 develop in repository tutti. See http://git.codelutin.com/tutti.git commit d9ebd307154b8d0029f722d9f19d642edaf943cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:44:59 2015 +0100 utilisation des méthodes utilitaire du protocol --- .../tutti/persistence/TuttiPersistenceImpl.java | 39 ++++------------------ .../i18n/tutti-persistence_en_GB.properties | 1 + .../i18n/tutti-persistence_fr_FR.properties | 1 + 3 files changed, 9 insertions(+), 32 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 7f6b4b8..c8664f9 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 @@ -51,7 +51,6 @@ import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.ObjectType; import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.entities.referential.Speciess; import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.persistence.entities.referential.TuttiReferentialEntity; import fr.ifremer.tutti.persistence.entities.referential.Vessel; @@ -87,7 +86,6 @@ import java.io.File; import java.io.IOException; import java.sql.SQLException; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; @@ -881,38 +879,15 @@ public class TuttiPersistenceImpl implements TuttiPersistence { // sanity it (remove all bad species and benthos) // see http://forge.codelutin.com/issues/4154 + List<Species> allReferentSpecies = getAllReferentSpecies(); - Map<String, Species> map = Speciess.splitReferenceSpeciesByReferenceTaxonId(allReferentSpecies); - - if (!protocol.isSpeciesEmpty()) { - Iterator<SpeciesProtocol> iterator = protocol.getSpecies().iterator(); - while (iterator.hasNext()) { - SpeciesProtocol speciesProtocol = iterator.next(); - String taxonId = String.valueOf(speciesProtocol.getSpeciesReferenceTaxonId()); - Species species = map.get(taxonId); - if (species == null) { - if (log.isWarnEnabled()) { - log.warn("Could not find protocol species " + taxonId + " (" + speciesProtocol.getSpeciesSurveyCode() + ") in referential."); - } - iterator.remove(); - } - } - } - if (!protocol.isBenthosEmpty()) { - Iterator<SpeciesProtocol> iterator = protocol.getBenthos().iterator(); - while (iterator.hasNext()) { - SpeciesProtocol speciesProtocol = iterator.next(); - String taxonId = String.valueOf(speciesProtocol.getSpeciesReferenceTaxonId()); - Species species = map.get(taxonId); - if (species == null) { - if (log.isWarnEnabled()) { - log.warn("Could not find protocol benthos " + taxonId + " (" + speciesProtocol.getSpeciesSurveyCode() + ") in referential."); - } - iterator.remove(); - } - } - } + Map<Integer, String> missingSpecies = TuttiProtocols.detectMissingSpecies(protocol, allReferentSpecies); + TuttiProtocols.removeBadSpecies(protocol, missingSpecies); + + Map<Integer, String> missingBenthos = TuttiProtocols.detectMissingBenthos(protocol, allReferentSpecies); + TuttiProtocols.removeBadBenthos(protocol, missingBenthos); + return protocol; } diff --git a/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties b/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties index 71533a6..373d386 100644 --- a/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties +++ b/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties @@ -110,6 +110,7 @@ tutti.persistence.error.no.convertor= tutti.persistence.error.protocol.benthos.not.found= tutti.persistence.error.protocol.categories.not.compatible= tutti.persistence.error.protocol.species.not.found= +tutti.persistence.error.species.withNoSurveyCodeOrRefTaxCode= tutti.persistence.loader.error= tutti.persistence.protocol.delete.error= tutti.persistence.protocol.fromFile.error= diff --git a/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties b/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties index ecd60d9..166aafc 100644 --- a/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties +++ b/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties @@ -106,6 +106,7 @@ tutti.persistence.error.no.convertor=Impossible de convertir en modèle de caté tutti.persistence.error.protocol.benthos.not.found=Le protocole utilise des benthos non connus dans le référentiel \: <ul>%s</ul> tutti.persistence.error.protocol.categories.not.compatible=Le protocole utilise des catégories non connues par la configuration des catégorisations \: <ul>%s</ul> tutti.persistence.error.protocol.species.not.found=Le protocole utilise des espèces non connues dans le référentiel \: <ul>%s</ul> +tutti.persistence.error.species.withNoSurveyCodeOrRefTaxCode=Une espèce (referenceId %s, nom scientifique %s) n'a ni code campagne, ni code refTax. tutti.persistence.loader.error=Erreur de conversion du dossier %s en URL tutti.persistence.protocol.delete.error=Erreur lors de la suppression du protocole %1s (fichier %2s) tutti.persistence.protocol.fromFile.error=Erreur lors de l'import du protocole du fichier %s -- 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 develop in repository tutti. See http://git.codelutin.com/tutti.git commit 1f32a0cfc0eafbdc57fdc2051882cbf7fd543809 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:48:25 2015 +0100 suppression SpeciesMap (remplacé par TaxonCache) --- .../java/fr/ifremer/tutti/service/SpeciesMap.java | 147 --------------------- 1 file changed, 147 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/SpeciesMap.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/SpeciesMap.java deleted file mode 100644 index 3018753..0000000 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/SpeciesMap.java +++ /dev/null @@ -1,147 +0,0 @@ -package fr.ifremer.tutti.service; - -/* - * #%L - * Tutti :: Service - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 - 2015 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.tutti.persistence.entities.data.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; -import fr.ifremer.tutti.persistence.entities.referential.Species; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * Created on 2/9/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 3.13 - */ -public class SpeciesMap { - - public static SpeciesMap create(TuttiDataContext dataContext, PersistenceService persistenceService) { - - boolean protocolFilled = dataContext.isProtocolFilled(); - - Map<Integer, SpeciesProtocol> speciesProtocolMap; - Map<Integer, SpeciesProtocol> benthosProtocolMap; - - if (protocolFilled) { - - speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); - benthosProtocolMap = persistenceService.toBenthosProtocolMap(); - - } else { - - speciesProtocolMap = new HashMap<>(); - benthosProtocolMap = new HashMap<>(); - } - - SpeciesMap speciesMap = new SpeciesMap(persistenceService, speciesProtocolMap, benthosProtocolMap); - return speciesMap; - - } - - protected final Map<Integer, SpeciesProtocol> speciesProtocolMap; - - protected final Map<Integer, SpeciesProtocol> benthosProtocolMap; - - protected final Map<Integer, Species> speciesByReferenceTaxonId = new TreeMap<>(); - - protected final PersistenceService persistenceService; - - public <A extends SpeciesAbleBatch> void loadSpecies(List<A> speciesAbleBatches) { - - for (A speciesAbleBatch : speciesAbleBatches) { - loadSpecies(speciesAbleBatch.getSpecies()); - } - - } - - public <A extends SpeciesAbleBatch> void loadBenthos(List<A> speciesAbleBatches) { - - for (A speciesAbleBatch : speciesAbleBatches) { - loadBenthos(speciesAbleBatch.getSpecies()); - } - - } - - public void loadSpecies(Species species) { - - load(species, speciesProtocolMap); - - } - - public void loadBenthos(Species species) { - - load(species, benthosProtocolMap); - - } - - protected SpeciesMap(PersistenceService persistenceService, - Map<Integer, SpeciesProtocol> speciesProtocolMap, - Map<Integer, SpeciesProtocol> benthosProtocolMap) { - - this.speciesProtocolMap = speciesProtocolMap; - this.benthosProtocolMap = benthosProtocolMap; - this.persistenceService = persistenceService; - - } - - protected void load(Species species, Map<Integer, SpeciesProtocol> protocolMap) { - - Integer referenceTaxonId = species.getReferenceTaxonId(); - - Species speciesLoaded = speciesByReferenceTaxonId.get(referenceTaxonId); - - if (speciesLoaded == null) { - - 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()); - - } - - - } - - -} -- 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 develop in repository tutti. See http://git.codelutin.com/tutti.git commit adc517ffc3eb6be7893d52448fbe528d295b2bd8 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:49:55 2015 +0100 utilisation des méthodes utilitaires du protocol --- .../ui/swing/action/ImportProtocolAction.java | 65 ++++++++-------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportProtocolAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportProtocolAction.java index 5692280..7d30df3 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportProtocolAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportProtocolAction.java @@ -23,15 +23,12 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; -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 fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.entities.referential.Speciess; import fr.ifremer.tutti.service.protocol.ProtocolImportExportService; import fr.ifremer.tutti.ui.swing.TuttiScreen; import fr.ifremer.tutti.ui.swing.content.MainUIHandler; @@ -118,16 +115,15 @@ public class ImportProtocolAction extends AbstractChangeScreenAction { if (doAction) { - List<Species> referentSpecies = getDataContext().getReferentSpecies(); - Map<String, Species> allReferentSpeciesByTaxonId = Speciess.splitReferenceSpeciesByReferenceTaxonId(referentSpecies); + List<Species> allReferentSpecies = getContext().getPersistenceService().getAllReferentSpecies(); // clean species - doAction = cleanSpecies(allReferentSpeciesByTaxonId, protocol); + doAction = cleanSpecies(allReferentSpecies, protocol); if (doAction) { // clean benthos - doAction = cleanBenthos(allReferentSpeciesByTaxonId, protocol); + doAction = cleanBenthos(allReferentSpecies, protocol); } } @@ -191,8 +187,7 @@ public class ImportProtocolAction extends AbstractChangeScreenAction { if (log.isInfoEnabled()) { log.info("Clean and Import"); } - TuttiProtocols.removeBadCategories(sampleCategoryModel, - protocol); + TuttiProtocols.removeBadCategories(sampleCategoryModel, protocol); break; case 1: if (log.isInfoEnabled()) { @@ -209,27 +204,20 @@ public class ImportProtocolAction extends AbstractChangeScreenAction { } - protected boolean cleanSpecies(Map<String, Species> allReferentSpeciesByTaxonId, TuttiProtocol protocol) { + protected boolean cleanSpecies(List<Species> allReferentSpecies, TuttiProtocol protocol) { boolean doAction = true; - Map<Integer, String> badSpecies = Maps.newLinkedHashMap(); + Map<Integer, String> missingSpecies = TuttiProtocols.detectMissingSpecies(protocol, allReferentSpecies); + boolean withBadSpecies = !missingSpecies.isEmpty(); - for (SpeciesProtocol speciesProtocol : protocol.getSpecies()) { - Integer taxonId = speciesProtocol.getSpeciesReferenceTaxonId(); - if (!allReferentSpeciesByTaxonId.containsKey(String.valueOf(taxonId))) { - - badSpecies.put(taxonId, speciesProtocol.getSpeciesSurveyCode()); - } - } - - if (!badSpecies.isEmpty()) { + if (withBadSpecies) { if (log.isWarnEnabled()) { - log.warn("There is some bad species: " + badSpecies); + log.warn("There is some bad species to remove."); } - String message = TuttiProtocols.getBadSpeciesMessage(badSpecies); + String message = TuttiProtocols.getBadSpeciesMessage(missingSpecies); String htmlMessage = String.format( AbstractTuttiUIHandler.CONFIRMATION_FORMAT, @@ -244,8 +232,7 @@ public class ImportProtocolAction extends AbstractChangeScreenAction { JOptionPane.WARNING_MESSAGE, UIManager.getIcon("warning"), new Object[]{t("tutti.option.cleanAndImport"), t("tutti.option.cancel")}, - t("tutti.option.cancel") - ); + t("tutti.option.cancel")); switch (response) { case 0: @@ -253,8 +240,8 @@ public class ImportProtocolAction extends AbstractChangeScreenAction { if (log.isInfoEnabled()) { log.info("Clean species and Import"); } - TuttiProtocols.removeBadSpecies(badSpecies.keySet(), - protocol.getSpecies()); + TuttiProtocols.removeBadSpecies(protocol, missingSpecies); + break; default: @@ -265,27 +252,19 @@ public class ImportProtocolAction extends AbstractChangeScreenAction { return doAction; } - protected boolean cleanBenthos(Map<String, Species> allReferentSpeciesByTaxonId, TuttiProtocol protocol) { + protected boolean cleanBenthos(List<Species> allReferentSpecies, TuttiProtocol protocol) { boolean doAction = true; - Map<Integer, String> badBenthos = Maps.newLinkedHashMap(); - - for (SpeciesProtocol speciesProtocol : protocol.getBenthos()) { - Integer taxonId = speciesProtocol.getSpeciesReferenceTaxonId(); - if (!allReferentSpeciesByTaxonId.containsKey(String.valueOf(taxonId))) { - - badBenthos.put(taxonId, speciesProtocol.getSpeciesSurveyCode()); - } - } - - if (!badBenthos.isEmpty()) { + Map<Integer, String> missingBenthos = TuttiProtocols.detectMissingBenthos(protocol, allReferentSpecies); + boolean withBadBenthos = !missingBenthos.isEmpty(); + if (withBadBenthos) { if (log.isWarnEnabled()) { - log.warn("There is some bad benthos: " + badBenthos); + log.warn("There is some bad benthos to remove."); } - String message = TuttiProtocols.getBadBenthosMessage(badBenthos); + String message = TuttiProtocols.getBadBenthosMessage(missingBenthos); String htmlMessage = String.format( AbstractTuttiUIHandler.CONFIRMATION_FORMAT, @@ -300,8 +279,7 @@ public class ImportProtocolAction extends AbstractChangeScreenAction { JOptionPane.WARNING_MESSAGE, UIManager.getIcon("warning"), new Object[]{t("tutti.option.cleanAndImport"), t("tutti.option.cancel")}, - t("tutti.option.cancel") - ); + t("tutti.option.cancel")); switch (response) { case 0: @@ -309,7 +287,8 @@ public class ImportProtocolAction extends AbstractChangeScreenAction { if (log.isInfoEnabled()) { log.info("Clean benthos and Import"); } - TuttiProtocols.removeBadSpecies(badBenthos.keySet(), protocol.getBenthos()); + TuttiProtocols.removeBadBenthos(protocol, missingBenthos); + break; default: -- 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 develop in repository tutti. See http://git.codelutin.com/tutti.git commit d5580b6d1ec38fe5d8b235ef85aa9f5735aadc8f Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:50:19 2015 +0100 utilisation de TaxonCache dans les handler d'ui --- .../frequency/BenthosFrequencyUIHandler.java | 30 +++++---------- .../CreateIndividualObservationBatchUIHandler.java | 18 ++++----- .../frequency/SpeciesFrequencyUIHandler.java | 43 ++++++---------------- 3 files changed, 30 insertions(+), 61 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java index b9e15de..63f95f0 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java @@ -23,12 +23,12 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency; */ import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; @@ -85,8 +85,6 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth private BenthosFrequencyCellComponent.FrequencyCellEditor frequencyEditor; - private Map<Integer, SpeciesProtocol> speciesProtocol; - private Map<String, Caracteristic> lengthStepCaracteristics; private JFreeChart chart; @@ -100,6 +98,8 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth protected ApplyBenthosFrequencyRafaleAction applyBenthosFrequencyRafaleAction; + private TaxonCache taxonCache; + public BenthosFrequencyUIHandler() { super(BenthosFrequencyRowModel.PROPERTY_LENGTH_STEP, BenthosFrequencyRowModel.PROPERTY_NUMBER, @@ -207,14 +207,7 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth BenthosFrequencyUIModel model = getModel(); - if (getContext().isProtocolFilled()) { - - // FIXME 20130128 kmorin: the species have no technical id - speciesProtocol = getPersistenceService().toBenthosProtocolMap(); - - } else { - speciesProtocol = Maps.newHashMap(); - } + taxonCache = TaxonCaches.createBenthosCacheWithoutVernacularCode(getPersistenceService(), getDataContext().getProtocol()); Caracteristic modelCaracteristic = model.getLengthStepCaracteristic(); initBeanFilterableComboBox(ui.getLengthStepCaracteristicComboBox(), @@ -526,14 +519,12 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth Species species = speciesBatch.getSpecies(); - SpeciesProtocol sProtocol = speciesProtocol.get(species.getReferenceTaxonId()); - - if (sProtocol != null) { + String lengthStepPmfmId = taxonCache.getLengthStepPmfmId(species); - String lengthStepPmfmId = sProtocol.getLengthStepPmfmId(); + if (lengthStepPmfmId != null) { lengthStepCaracteristic = lengthStepCaracteristics.get(lengthStepPmfmId); - lengthStep = sProtocol.getLengthStep(); + lengthStep = taxonCache.getLengthStep(species); if (log.isInfoEnabled()) { log.info("Use existing from protocol lengthStep " + @@ -551,9 +542,8 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth FrequencyConfigurationMode mode = FrequencyConfigurationMode.AUTO_GEN; if (lengthStepCaracteristic == null) { - Integer taxonId = speciesBatch.getSpecies().getReferenceTaxonId(); - SpeciesProtocol speciesProtocol = this.speciesProtocol.get(taxonId); - if (speciesProtocol == null || speciesProtocol.getLengthStepPmfmId() == null) { + String lengthStepPmfmId = taxonCache.getLengthStepPmfmId(speciesBatch.getSpecies()); + if (lengthStepPmfmId == null) { mode = FrequencyConfigurationMode.SIMPLE_COUNTING; } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIHandler.java index cdd7cb0..8a03c1b 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/create/CreateIndividualObservationBatchUIHandler.java @@ -27,10 +27,11 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; @@ -42,15 +43,15 @@ import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.util.TuttiUI; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.Table; -import org.nuiton.jaxx.application.bean.JavaBeanObjectUtil; -import org.nuiton.jaxx.widgets.number.NumberEditor; import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; +import org.nuiton.jaxx.application.bean.JavaBeanObjectUtil; import org.nuiton.jaxx.application.swing.util.Cancelable; +import org.nuiton.jaxx.widgets.number.NumberEditor; import javax.swing.JComponent; import javax.swing.JLabel; @@ -118,20 +119,19 @@ public class CreateIndividualObservationBatchUIHandler extends AbstractTuttiUIHa if (getDataContext().isProtocolFilled()) { - final Map<Integer, SpeciesProtocol> speciesProtocolMap = - getContext().getPersistenceService().toSpeciesProtocolMap(); - final Map<String, Caracteristic> lengthStepCaracteristicMap = TuttiEntities.splitById(lengthStepCaracteristics); + final TaxonCache taxonCache = TaxonCaches.createSpeciesCacheWithoutVernacularCode(getPersistenceService(), getDataContext().getProtocol()); + getModel().addPropertyChangeListener(IndividualObservationBatch.PROPERTY_SPECIES, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { Species species = (Species) evt.getNewValue(); if (species != null) { - SpeciesProtocol speciesProtocol = speciesProtocolMap.get(species.getReferenceTaxonId()); - if (speciesProtocol != null) { - String lengthStepPmfmId = speciesProtocol.getLengthStepPmfmId(); + + String lengthStepPmfmId = taxonCache.getLengthStepPmfmId(species); + if (lengthStepPmfmId != null) { Caracteristic lengthStepCaracteristic = lengthStepCaracteristicMap.get(lengthStepPmfmId); getModel().setLengthStepCaracteristic(lengthStepCaracteristic); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java index 4a4a574..60c44cc 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java @@ -23,15 +23,15 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; */ import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import fr.ifremer.tutti.ichtyometer.feed.event.FeedReaderEvent; import fr.ifremer.tutti.ichtyometer.feed.event.FeedReaderListener; import fr.ifremer.tutti.ichtyometer.feed.record.FeedReaderMeasureRecord; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; @@ -90,7 +90,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci private FrequencyCellEditor frequencyEditor; - private Map<Integer, SpeciesProtocol> speciesProtocol; + private TaxonCache taxonCache; private Map<String, Caracteristic> lengthStepCaracteristics; @@ -262,14 +262,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci SpeciesFrequencyUIModel model = getModel(); - if (getContext().isProtocolFilled()) { - - // FIXME 20130128 kmorin: the species have no technical id - speciesProtocol = getPersistenceService().toSpeciesProtocolMap(); - - } else { - speciesProtocol = Maps.newHashMap(); - } + taxonCache = TaxonCaches.createSpeciesCacheWithoutVernacularCode(getPersistenceService(), getDataContext().getProtocol()); final Caracteristic modelCaracteristic = model.getLengthStepCaracteristic(); initBeanFilterableComboBox(this.ui.getLengthStepCaracteristicComboBox(), @@ -368,19 +361,6 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci } }); -// getContext().addPropertyChangeListener(TuttiUIContext.PROPERTY_ICHTYOMETER_CONNECTED, new PropertyChangeListener() { -// @Override -// public void propertyChange(PropertyChangeEvent evt) { -// SwingUtilities.invokeLater( -// new Runnable() { -// @Override -// public void run() { -// updateLogVisibility(); -// } -// }); -// } -// }); - // init histogram chart = ChartFactory.createXYBarChart(null, @@ -598,14 +578,12 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci Species species = speciesBatch.getSpecies(); - SpeciesProtocol sProtocol = speciesProtocol.get(species.getReferenceTaxonId()); - - if (sProtocol != null) { + String lengthStepPmfmId = taxonCache.getLengthStepPmfmId(species); - String lengthStepPmfmId = sProtocol.getLengthStepPmfmId(); + if (lengthStepPmfmId != null) { lengthStepCaracteristic = lengthStepCaracteristics.get(lengthStepPmfmId); - lengthStep = sProtocol.getLengthStep(); + lengthStep = taxonCache.getLengthStep(species); if (log.isInfoEnabled()) { log.info("Use existing from protocol lengthStep " + @@ -613,7 +591,9 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci decorate(lengthStepCaracteristic) + " / " + lengthStep); } + } + } if (getContext().isIchtyometerConnected()) { @@ -630,9 +610,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci FrequencyConfigurationMode mode = FrequencyConfigurationMode.AUTO_GEN; if (lengthStepCaracteristic == null) { - Integer taxonId = speciesBatch.getSpecies().getReferenceTaxonId(); - SpeciesProtocol speciesProtocol = this.speciesProtocol.get(taxonId); - if (speciesProtocol == null || speciesProtocol.getLengthStepPmfmId() == null) { + String speciesLengthStepPmfmId = taxonCache.getLengthStepPmfmId(speciesBatch.getSpecies()); + if (speciesLengthStepPmfmId == null) { mode = FrequencyConfigurationMode.SIMPLE_COUNTING; } } -- 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 develop in repository tutti. See http://git.codelutin.com/tutti.git commit bf3128ec0c789a547ba14f4392657ccc9727cffd Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:50:58 2015 +0100 utilisation TaxonCache dans les services --- .../ifremer/tutti/service/PersistenceService.java | 174 +-------------------- .../fr/ifremer/tutti/service/TuttiDataContext.java | 12 +- .../export/pdf/CatchesPdfExportService.java | 163 +++++++------------ .../sumatra/CatchesSumatraExportService.java | 96 +++++++++--- .../toconfirmreport/ToConfirmReportService.java | 18 ++- .../service/psionimport/PsionImportService.java | 10 +- .../service/pupitri/PupitriImportService.java | 73 +++------ 7 files changed, 179 insertions(+), 367 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 2f4c512..67c3413 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 @@ -26,7 +26,6 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; 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; import fr.ifremer.tutti.TuttiConfiguration; @@ -53,6 +52,7 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; 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 fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Gears; @@ -69,7 +69,6 @@ import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; import fr.ifremer.tutti.persistence.service.UpdateSchemaContextSupport; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.AllFileSelector; @@ -89,11 +88,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; import java.util.concurrent.Callable; import static org.nuiton.i18n.I18n.t; @@ -529,96 +526,6 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer return result; } - public List<Species> getReferentSpeciesWithSurveyCode(List<Species> referentSpecies) { - - List<Species> result; - TuttiProtocol protocol = getProtocol(); - - if (protocol != null) { - // fill available species from protocol - result = Lists.newArrayList(); - if (!protocol.isSpeciesEmpty()) { - - // split by taxonId - Map<String, Species> map = Speciess.splitReferenceSpeciesByReferenceTaxonId(referentSpecies); - - for (SpeciesProtocol protocolSpecy : protocol.getSpecies()) { - String taxonId = String.valueOf(protocolSpecy.getSpeciesReferenceTaxonId()); - Species species = map.get(taxonId); - species.setSurveyCode(protocolSpecy.getSpeciesSurveyCode()); - result.add(species); - } - } - - } else { - - // no protocol, use default values - result = Lists.newArrayList(referentSpecies); - } - - result = Collections.unmodifiableList(result); - - return result; - } - - public List<Species> getReferentBenthosWithSurveyCode(List<Species> referentSpecies) { - List<Species> result; - - TuttiProtocol protocol = getProtocol(); - - if (protocol != null) { - - // fill available species from protocol - - result = Lists.newArrayList(); - if (!protocol.isBenthosEmpty()) { - - // split by taxonId - Map<String, Species> map = Speciess.splitReferenceSpeciesByReferenceTaxonId(referentSpecies); - - for (SpeciesProtocol protocolSpecy : protocol.getBenthos()) { - String taxonId = String.valueOf(protocolSpecy.getSpeciesReferenceTaxonId()); - Species species = map.get(taxonId); - species.setSurveyCode(protocolSpecy.getSpeciesSurveyCode()); - result.add(species); - } - } - - } else { - - // no protocol, use default values - result = Lists.newArrayList(referentSpecies); - } - - result = Collections.unmodifiableList(result); - - return result; - } - - public Map<Integer, SpeciesProtocol> toSpeciesProtocolMap() { - TuttiProtocol protocol = getProtocol(); - Preconditions.checkNotNull(protocol, - "Could not find protocol in ui context"); - - final Map<Integer, SpeciesProtocol> result = Maps.newHashMap(); - for (SpeciesProtocol sp : protocol.getSpecies()) { - result.put(sp.getSpeciesReferenceTaxonId(), sp); - } - return result; - } - - public Map<Integer, SpeciesProtocol> toBenthosProtocolMap() { - TuttiProtocol protocol = getProtocol(); - Preconditions.checkNotNull(protocol, - "Could not find protocol in ui context"); - - final Map<Integer, SpeciesProtocol> result = Maps.newHashMap(); - for (SpeciesProtocol sp : protocol.getBenthos()) { - result.put(sp.getSpeciesReferenceTaxonId(), sp); - } - return result; - } - /** * Return the speciesProtocol corresponding to the species of the given protocol. * @@ -627,7 +534,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer * @since 2.6 */ public SpeciesProtocol getSpeciesProtocol(Species species) { - return getSpeciesProtocol(species, getProtocol().getSpecies()); + return TuttiProtocols.getSpeciesProtocol(species, getProtocol().getSpecies()); } /** @@ -638,82 +545,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer * @since 2.6 */ public SpeciesProtocol getBenthosProtocol(Species species) { - return getSpeciesProtocol(species, getProtocol().getBenthos()); - } - - /** - * Return all the speciesprotocol corresponding to the species of the batch - * - * @param species species to test - * @param speciesProtocols list of species protocol to filter - * @return all the speciesprotocol corresponding to the species of the batch - * @since 2.6 - */ - public SpeciesProtocol getSpeciesProtocol(Species species, - List<SpeciesProtocol> speciesProtocols) { - for (SpeciesProtocol speciesProtocol : speciesProtocols) { - if (species.getReferenceTaxonId().equals( - speciesProtocol.getSpeciesReferenceTaxonId())) { - return speciesProtocol; - } - } - return null; - } - - public Set<String> fillSpeciesSurveyCode(Collection<Species> speciesList) { - - TuttiProtocol protocol = getProtocol(); - - Set<String> badSpecies = new LinkedHashSet<>(); - - if (protocol != null) { - // fill available species from protocol - if (!protocol.isSpeciesEmpty()) { - - Map<Integer, SpeciesProtocol> protocolMap = toSpeciesProtocolMap(); - - for (Species species : speciesList) { - SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); - if (speciesProtocol == null || - StringUtils.isEmpty(speciesProtocol.getSpeciesSurveyCode())) { - badSpecies.add(species.getName()); - continue; - } - species.setSurveyCode(speciesProtocol.getSpeciesSurveyCode()); - } - } - } - - return badSpecies; - } - - public Set<String> fillBenthosSurveyCode(Collection<Species> benthosList) { - - TuttiProtocol protocol = getProtocol(); - - Set<String> badSpecies = new LinkedHashSet<>(); - - if (protocol != null) { - - - // fill available benthos from protocol - if (!protocol.isBenthosEmpty()) { - - Map<Integer, SpeciesProtocol> protocolMap = toBenthosProtocolMap(); - - for (Species species : benthosList) { - SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); - if (speciesProtocol == null || - StringUtils.isEmpty(speciesProtocol.getSpeciesSurveyCode())) { - badSpecies.add(species.getName()); - continue; - } - species.setSurveyCode(speciesProtocol.getSpeciesSurveyCode()); - } - } - } - - return badSpecies; + return TuttiProtocols.getSpeciesProtocol(species, getProtocol().getBenthos()); } public static final TimeLog TIME_LOG = new TimeLog(PersistenceService.class); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java index 9a3a1bc..98d416f 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java @@ -37,6 +37,8 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativ import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.util.Weights; import org.apache.commons.lang3.StringUtils; @@ -48,6 +50,7 @@ import org.nuiton.util.DateUtil; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Closeable; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -716,7 +719,9 @@ public class TuttiDataContext extends AbstractBean implements Closeable { log.info("Loading referentSpecies"); } - referentSpeciesWithSurveyCode = service.getReferentSpeciesWithSurveyCode(getReferentSpecies()); + TaxonCache taxonCache = TaxonCaches.createSpeciesCacheWithoutVernacularCode(service, getProtocol()); + referentSpeciesWithSurveyCode = new ArrayList<>(getReferentSpecies()); + taxonCache.load(referentSpeciesWithSurveyCode); } return referentSpeciesWithSurveyCode; } @@ -728,8 +733,9 @@ public class TuttiDataContext extends AbstractBean implements Closeable { if (log.isInfoEnabled()) { log.info("Loading referentBenthos"); } - - referentBenthosWithSurveyCode = service.getReferentBenthosWithSurveyCode(getReferentSpecies()); + TaxonCache taxonCache = TaxonCaches.createBenthosCacheWithoutVernacularCode(service, getProtocol()); + referentBenthosWithSurveyCode = new ArrayList<>(getReferentSpecies()); + taxonCache.load(referentBenthosWithSurveyCode); } return referentBenthosWithSurveyCode; } 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 ce31737..89955da 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 @@ -26,8 +26,10 @@ 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.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.Speciess; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PdfGeneratorService; import fr.ifremer.tutti.service.PersistenceService; @@ -35,10 +37,8 @@ import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.service.export.ExportBatchEntry; import fr.ifremer.tutti.service.export.ExportCatchContext; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.ApplicationBusinessException; import java.io.File; import java.util.List; @@ -118,8 +118,7 @@ public class CatchesPdfExportService extends AbstractTuttiService { generatePdf(targetFile, locale, operations); } - protected void prepareOperation(String fishingOperationId, - List<Map<String, Object>> operations) { + protected void prepareOperation(String fishingOperationId, List<Map<String, Object>> operations) { // get operation and catch data boolean withCatchBatch = @@ -153,84 +152,15 @@ public class CatchesPdfExportService extends AbstractTuttiService { // Species if (exportContext.withSpeciesBatches()) { - List<ExportBatchEntry> speciesBatchEntries = - exportContext.getSpeciesBatchEntry(false); + prepareOperationSpecies(exportContext, totalWeight, catchList); - - boolean protocolFilled = context.getDataContext().isProtocolFilled(); - - Map<Integer, SpeciesProtocol> speciesProtocolMap = null; - - if (protocolFilled) { - - speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); - - } - - for (ExportBatchEntry entry : speciesBatchEntries) { - - SpeciesAbleBatch batch = entry.getBatch(); - Species species = batch.getSpecies(); - - Species speciesWithVerncularCode = - persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(species.getReferenceTaxonId()); - - String code; - - - // if the protocol is set and the species is in the protocol - if (protocolFilled && speciesProtocolMap.containsKey(species.getReferenceTaxonId())) { - - // use surveyCode from protocol - SpeciesProtocol speciesProtocol = speciesProtocolMap.get(species.getReferenceTaxonId()); - - code = speciesProtocol.getSpeciesSurveyCode(); - - } else { - - // use refTaxCode - code = species.getRefTaxCode(); - - } - - if (StringUtils.isEmpty(code)) { - - - throw new ApplicationBusinessException(t("tutti.pdf.export.missing.species.code", species.getReferenceTaxonId(), species.getName())); - } - - PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry(code, - species.getName(), - speciesWithVerncularCode.getVernacularCode(), - entry.getSortedWeight(), - entry.getTotalWeight(), - totalWeight); - catchList.add(pdfEntry); - } } // Benthos if (exportContext.withBenthosBatches()) { - List<ExportBatchEntry> benthosBatchEntries = - exportContext.getBenthosBatchEntry(false); - - float sortedWeight = 0f; - float benthosTotalWeight = 0f; + prepareOperationBenthos(exportContext, totalWeight, catchList); - for (ExportBatchEntry entry : benthosBatchEntries) { - sortedWeight += entry.getSortedWeight(); - benthosTotalWeight += entry.getTotalWeight(); - } - - PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry( - t("tutti.service.operations.exportCatchesReport.specialRows.benthos.code"), - "", - t("tutti.service.operations.exportCatchesReport.specialRows.benthos.name"), - sortedWeight, - benthosTotalWeight, - totalWeight); - catchList.add(pdfEntry); } // Inert and living not itemized @@ -266,6 +196,54 @@ public class CatchesPdfExportService extends AbstractTuttiService { operations.add(op); } + protected void prepareOperationSpecies(ExportCatchContext exportContext, float totalWeight, List<PdfExportBatchEntry> catchList) { + + List<ExportBatchEntry> speciesBatchEntries = exportContext.getSpeciesBatchEntry(false); + + TaxonCache taxonCache = TaxonCaches.createSpeciesCache(persistenceService, context.getDataContext().getProtocol()); + + for (ExportBatchEntry entry : speciesBatchEntries) { + + SpeciesAbleBatch batch = entry.getBatch(); + Species species = batch.getSpecies(); + + taxonCache.load(species); + + String code = Speciess.getSurveyCodeOrRefTaxCode(species); + + PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry(code, + species.getName(), + species.getVernacularCode(), + entry.getSortedWeight(), + entry.getTotalWeight(), + totalWeight); + catchList.add(pdfEntry); + } + } + + protected void prepareOperationBenthos(ExportCatchContext exportContext, float totalWeight, List<PdfExportBatchEntry> catchList) { + + List<ExportBatchEntry> benthosBatchEntries = exportContext.getBenthosBatchEntry(false); + + float sortedWeight = 0f; + float benthosTotalWeight = 0f; + + for (ExportBatchEntry entry : benthosBatchEntries) { + sortedWeight += entry.getSortedWeight(); + benthosTotalWeight += entry.getTotalWeight(); + } + + PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry( + t("tutti.service.operations.exportCatchesReport.specialRows.benthos.code"), + "", + t("tutti.service.operations.exportCatchesReport.specialRows.benthos.name"), + sortedWeight, + benthosTotalWeight, + totalWeight); + catchList.add(pdfEntry); + + } + protected void generatePdf(File targetFile, Locale locale, List<Map<String, Object>> operations) { Map<String, Object> data = Maps.newHashMap(); @@ -275,39 +253,6 @@ public class CatchesPdfExportService extends AbstractTuttiService { } - - // protected void generatePdf(File targetFile, Locale locale, List<Map<String, Object>> operations) { -// -// Map<String, Object> data = Maps.newHashMap(); -// data.put("operations", operations); -// // generate the report -// OutputStream os = null; -// try { -// -// // render freemarker template -// Template mapTemplate = freemarkerConfiguration.getTemplate("catchesReport.ftl", locale); -// -// Writer out = new StringWriter(); -// mapTemplate.process(data, out); -// out.flush(); -// -// // render template output as pdf -// os = new FileOutputStream(targetFile); -// -// ITextRenderer renderer = new ITextRenderer(); -// renderer.setDocumentFromString(out.toString()); -// renderer.layout(); -// renderer.createPDF(os); -// -// os.close(); -// -// } catch (Exception ex) { -// throw new ApplicationTechnicalException(t("tutti.service.operations.exportCatchesReport.error"), ex); -// } finally { -// IOUtils.closeQuietly(os); -// } -// } -// protected Map<String, Object> createOperation(FishingOperation fishingOperation) { Map<String, Object> op = Maps.newHashMap(); op.put("number", fishingOperation.getFishingOperationNumber()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java index 34cd9d1..7116322 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java @@ -29,7 +29,10 @@ import com.google.common.io.Files; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; @@ -37,6 +40,7 @@ import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.service.export.ExportBatchEntry; import fr.ifremer.tutti.service.export.ExportCatchContext; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Export; @@ -160,6 +164,12 @@ public class CatchesSumatraExportService extends AbstractTuttiService { new CatchRowModel(context.getConfig().getCsvSeparator()); if (operations != null) { + + TuttiProtocol protocol = context.getDataContext().getProtocol(); + + TaxonCache speciesCache = TaxonCaches.createSpeciesCacheWithoutVernacularCode(persistenceService, protocol); + TaxonCache benthosCache = TaxonCaches.createBenthosCacheWithoutVernacularCode(persistenceService, protocol); + for (String operationId : operations) { progressionModel.increments(t("tutti.service.sumatra.export.step.load.fishingOperation", operationId)); @@ -171,7 +181,8 @@ public class CatchesSumatraExportService extends AbstractTuttiService { break; } - prepareFishingOperation(csvModel, rows, operationId, result); + prepareFishingOperation(speciesCache, benthosCache, csvModel, rows, operationId, result); + } } @@ -191,7 +202,9 @@ public class CatchesSumatraExportService extends AbstractTuttiService { } } - protected void prepareFishingOperation(CatchRowModel csvModel, + protected void prepareFishingOperation(TaxonCache speciesCache, + TaxonCache benthosCache, + CatchRowModel csvModel, List<CatchRow> rows, String operationId, SumatraExportResult result) { @@ -207,46 +220,77 @@ public class CatchesSumatraExportService extends AbstractTuttiService { // Species if (exportContext.withSpeciesBatches()) { - Set<Species> allspecies = new HashSet<>(); + List<ExportBatchEntry> entries = exportContext.getSpeciesBatchEntry(true); + Set<String> badSpecies = prepareFishingOperationSpecies(speciesCache, entries, csvModel, rows, operation); + result.setBadSpecies(badSpecies); + + } + + // Benthos + if (exportContext.withBenthosBatches()) { + + List<ExportBatchEntry> entries = exportContext.getBenthosBatchEntry(true); + Set<String> badBenthos = prepareFishingOperationBenthos(benthosCache, entries, csvModel, rows, operation); + result.setBadBenthos(badBenthos); + + } + } - List<ExportBatchEntry> entries = - exportContext.getSpeciesBatchEntry(true); + protected Set<String> prepareFishingOperationSpecies(TaxonCache taxonCache, + List<ExportBatchEntry> entries, + CatchRowModel csvModel, + List<CatchRow> rows, + FishingOperation operation) { - for (ExportBatchEntry entry : entries) { + Set<String> badSpecies = new HashSet<>(); - // get species campaign code from protocol + for (ExportBatchEntry entry : entries) { - allspecies.add(entry.getBatch().getSpecies()); + Species species = entry.getBatch().getSpecies(); - CatchRow row = csvModel.newRow(operation, entry); - row.getSpecies(); - rows.add(row); + // load species codes + taxonCache.load(species); + + if (StringUtils.isBlank(species.getSurveyCode())) { + badSpecies.add(species.getName()); } - // fill survey code in species - Set<String> badSpecies = persistenceService.fillSpeciesSurveyCode(allspecies); - result.setBadSpecies(badSpecies); + CatchRow row = csvModel.newRow(operation, entry); + + rows.add(row); } - // Benthos - if (exportContext.withBenthosBatches()) { + return badSpecies; + + } - Set<Species> allspecies = new HashSet<>(); + protected Set<String> prepareFishingOperationBenthos(TaxonCache taxonCache, + List<ExportBatchEntry> entries, + CatchRowModel csvModel, + List<CatchRow> rows, + FishingOperation operation) { - List<ExportBatchEntry> entries = - exportContext.getBenthosBatchEntry(true); + Set<String> badBenthos = new HashSet<>(); - for (ExportBatchEntry entry : entries) { + for (ExportBatchEntry entry : entries) { - CatchRow row = csvModel.newRow(operation, entry); - allspecies.add(entry.getBatch().getSpecies()); - rows.add(row); + Species species = entry.getBatch().getSpecies(); + + // load species codes + taxonCache.load(species); + if (StringUtils.isBlank(species.getSurveyCode())) { + badBenthos.add(species.getName()); } - // fill survey code in benthos - Set<String> badBenthos = persistenceService.fillBenthosSurveyCode(allspecies); - result.setBadBenthos(badBenthos); + CatchRow row = csvModel.newRow(operation, entry); + rows.add(row); + } + + return badBenthos; + } + + } 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 58117b9..02dc8e1 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 @@ -29,12 +29,14 @@ 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; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PdfGeneratorService; import fr.ifremer.tutti.service.PersistenceService; -import fr.ifremer.tutti.service.SpeciesMap; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.type.WeightUnit; @@ -100,7 +102,10 @@ public class ToConfirmReportService extends AbstractTuttiService { progressionModel.increments(t("tutti.toconfirmReport.loading.protocol")); - SpeciesMap speciesMap = SpeciesMap.create(context.getDataContext(), persistenceService); + TuttiProtocol protocol = context.getDataContext().getProtocol(); + + TaxonCache speciesCache = TaxonCaches.createSpeciesCache(persistenceService, protocol); + TaxonCache benthosCache = TaxonCaches.createBenthosCache(persistenceService, protocol); List<String> allFishingOperation = persistenceService.getAllFishingOperationIds(cruiseId); @@ -118,7 +123,7 @@ public class ToConfirmReportService extends AbstractTuttiService { if (fishingOperationData != null) { - ToConfirmReportFishingOperationBean operationBean = createOperationBean(fishingOperationData, speciesMap); + ToConfirmReportFishingOperationBean operationBean = createOperationBean(fishingOperationData, speciesCache, benthosCache); reportBean.addOperation(operationBean); } @@ -131,7 +136,8 @@ public class ToConfirmReportService extends AbstractTuttiService { } protected ToConfirmReportFishingOperationBean createOperationBean(ToConfirmReportFishingOperationData fishingOperationData, - SpeciesMap speciesMap) { + TaxonCache speciesCache, + TaxonCache benthosCache) { // Species @@ -140,7 +146,7 @@ public class ToConfirmReportService extends AbstractTuttiService { if (fishingOperationData.isWithSpeciesBatchToConfirm()) { List<SpeciesBatch> speciesBatchEntries = fishingOperationData.getSpeciesBatchToConfirm(); - speciesMap.loadSpecies(speciesBatchEntries); + speciesCache.loadInBatches(speciesBatchEntries); speciesCatchList = createBatchBeans(speciesWeightUnit, speciesBatchEntries); } else { @@ -155,7 +161,7 @@ public class ToConfirmReportService extends AbstractTuttiService { if (fishingOperationData.isWithBenthosBatchToConfirm()) { List<BenthosBatch> benthosBatchEntries = fishingOperationData.getBenthosBatchToConfirm(); - speciesMap.loadBenthos(benthosBatchEntries); + benthosCache.loadInBatches(benthosBatchEntries); benthosCatchList = createBatchBeans(benthosWeightUnit, benthosBatchEntries); } else { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java index a786fa5..de78272 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java @@ -50,6 +50,8 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValues; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; @@ -71,6 +73,7 @@ import java.io.Serializable; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -209,9 +212,10 @@ public class PsionImportService extends AbstractTuttiService { throw new ApplicationBusinessException(t("tutti.service.psionimport.error.no.protocol")); } - List<Species> allReferentSpecies = persistenceService.getAllReferentSpecies(); - List<Species> allSpeciesWithSurveyCode = persistenceService.getReferentSpeciesWithSurveyCode( - allReferentSpecies); + List<Species> allSpeciesWithSurveyCode = new ArrayList<>(persistenceService.getAllReferentSpecies()); + + TaxonCache speciesMap = TaxonCaches.createSpeciesCacheWithoutVernacularCode(persistenceService, protocol); + speciesMap.load(allSpeciesWithSurveyCode); Map<String, Species> speciesBySurveyCode = Maps.newTreeMap(); for (Species species : allSpeciesWithSurveyCode) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java index 4979838..a5de739 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java @@ -35,12 +35,13 @@ import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValues; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.Speciess; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PdfGeneratorService; @@ -62,7 +63,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Import; import org.nuiton.decorator.Decorator; -import org.nuiton.jaxx.application.ApplicationBusinessException; import org.nuiton.jaxx.application.ApplicationIOUtil; import org.nuiton.jaxx.application.ApplicationTechnicalException; @@ -193,74 +193,49 @@ public class PupitriImportService extends AbstractTuttiService { //FIXME Check how to deal with Melag meta species and species involed in melag protected File generatePupitriReport(FishingOperation operation, PupitriImportResult result) { - boolean protocolFilled = context.getDataContext().isProtocolFilled(); - - Map<Integer, SpeciesProtocol> speciesProtocolMap = null; - - if (protocolFilled) { - - speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); - - } + TaxonCache taxonCache = TaxonCaches.createSpeciesCache(persistenceService, context.getDataContext().getProtocol()); PupitriImportReportModel reportModel = new PupitriImportReportModel(operation, result); for (PupitriSpeciesContext aCatch : result.getCatches()) { - Species species = aCatch.getSpecies(); - - Species speciesWithVerncularCode = - persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(species.getReferenceTaxonId()); - - String code; + addCatchEntry(taxonCache, aCatch, reportModel); - // if the protocol is set and the species is in the protocol - if (protocolFilled && speciesProtocolMap.containsKey(species.getReferenceTaxonId())) { + } - // use surveyCode from protocol - SpeciesProtocol speciesProtocol = speciesProtocolMap.get(species.getReferenceTaxonId()); + reportModel.sortRows(); - code = speciesProtocol.getSpeciesSurveyCode(); + File reportFile = context.getConfig().newTempFile("puputri-report", ".pdf"); + Locale locale = context.getConfig().getI18nLocale(); - } else { + pdfGeneratorService.generatePdf(reportFile, locale, "pupitriReport.ftl", reportModel); - // use refTaxCode - code = species.getRefTaxCode(); + return reportFile; - } + } - String name = species.getName(); - if (StringUtils.isEmpty(code)) { + protected void addCatchEntry(TaxonCache taxonCache, PupitriSpeciesContext aCatch, PupitriImportReportModel reportModel) { - throw new ApplicationBusinessException(t("tutti.pdf.export.missing.species.code", species.getReferenceTaxonId(), name)); + Species species = aCatch.getSpecies(); + taxonCache.load(species); - } + String code = Speciess.getSurveyCodeOrRefTaxCode(species); - String vernacularCode = speciesWithVerncularCode.getVernacularCode(); + String name = species.getName(); - for (Signs signs : aCatch.getSigns()) { + String vernacularCode = species.getVernacularCode(); - PupitriImportReportRow reportCatch = PupitriImportReportRow.newRow(code, - name, - vernacularCode, - aCatch.isSorted(), - aCatch.getSignContext(signs)); + for (Signs signs : aCatch.getSigns()) { - reportModel.addRow(reportCatch); + PupitriImportReportRow reportCatch = PupitriImportReportRow.newRow(code, + name, + vernacularCode, + aCatch.isSorted(), + aCatch.getSignContext(signs)); - } + reportModel.addRow(reportCatch); } - - reportModel.sortRows(); - - File reportFile = context.getConfig().newTempFile("puputri-report", ".pdf"); - Locale locale = context.getConfig().getI18nLocale(); - - pdfGeneratorService.generatePdf(reportFile, locale, "pupitriReport.ftl", reportModel); - - return reportFile; - } protected String addFileAsAttachment(File f, CatchBatch catchBatch) { -- 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 develop in repository tutti. See http://git.codelutin.com/tutti.git commit aa9e69329444b67f0ced7a9b0d55ffd6d59c7682 Merge: 1012fd7 bf3128e Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:53:36 2015 +0100 fixes #6677 [TECH] Assainissement de l'utilisation des codes campagnes dans les taxons Merge branch 'feature/6677' into develop .../tutti/persistence/TuttiPersistenceImpl.java | 39 +---- .../entities/protocol/TuttiProtocols.java | 140 +++++++++++++---- .../persistence/entities/referential/Speciess.java | 12 ++ .../entities/referential/TaxonCache.java | 101 ++++++++++++ .../entities/referential/TaxonCaches.java | 105 +++++++++++++ .../i18n/tutti-persistence_en_GB.properties | 1 + .../i18n/tutti-persistence_fr_FR.properties | 1 + .../ifremer/tutti/service/PersistenceService.java | 174 +-------------------- .../java/fr/ifremer/tutti/service/SpeciesMap.java | 147 ----------------- .../fr/ifremer/tutti/service/TuttiDataContext.java | 12 +- .../export/pdf/CatchesPdfExportService.java | 163 +++++++------------ .../sumatra/CatchesSumatraExportService.java | 96 +++++++++--- .../toconfirmreport/ToConfirmReportService.java | 18 ++- .../service/psionimport/PsionImportService.java | 10 +- .../service/pupitri/PupitriImportService.java | 73 +++------ .../ui/swing/action/ImportProtocolAction.java | 65 +++----- .../frequency/BenthosFrequencyUIHandler.java | 30 ++-- .../CreateIndividualObservationBatchUIHandler.java | 18 +-- .../frequency/SpeciesFrequencyUIHandler.java | 43 ++--- 19 files changed, 568 insertions(+), 680 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm