Author: tchemit Date: 2014-01-19 13:57:12 +0100 (Sun, 19 Jan 2014) New Revision: 1509 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1509 Log: fixes #4154: [REFERENTIEL] Probl?\195?\168me si des esp?\195?\168ces sont supprim?\195?\169s Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2014-01-18 23:08:52 UTC (rev 1508) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2014-01-19 12:57:12 UTC (rev 1509) @@ -84,6 +84,7 @@ import java.io.File; import java.io.IOException; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; @@ -168,8 +169,6 @@ try { V result = call.call(); return result; - } catch (ApplicationTechnicalException e) { - throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { @@ -644,7 +643,39 @@ @Override public TuttiProtocol getProtocol(String id) { - return protocolService.getProtocol(id); + TuttiProtocol protocol = protocolService.getProtocol(id); + + // sanity it (remove all bad species and benthos) + // see http://forge.codelutin.com/issues/4154 + List<Species> allReferentSpecies = getAllReferentSpecies(); + + Map<String, Species> map = TuttiEntities.splitByTaxonId(allReferentSpecies); + + 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(); + } + } + 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(); + } + } + return protocol; } //------------------------------------------------------------------------//