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>.