Author: kmorin Date: 2013-03-01 12:56:41 +0100 (Fri, 01 Mar 2013) New Revision: 509 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/509 Log: debug npe Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-03-01 10:53:27 UTC (rev 508) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-03-01 11:56:41 UTC (rev 509) @@ -10,15 +10,15 @@ * %% * 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 + * 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 + * + * 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% @@ -178,7 +178,7 @@ SortingBatch benthosBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); - if (benthosBatch == null) { + if (benthosBatch != null) { result.setBenthosTotalUnsortedWeight(benthosBatch.getWeight()); } @@ -435,14 +435,20 @@ Preconditions.checkNotNull(speciesBatchId); Preconditions.checkNotNull(frequencies); + List<SpeciesBatchFrequency> notNullFrequencies = Lists.newArrayList(); + // Check that all frequencies have the same length PMFM (before doing any db call) + // and remove null frequencies String pmfmId = null; for (SpeciesBatchFrequency source : frequencies) { - if (pmfmId == null) { - pmfmId = source.getLengthStepCaracteristic().getId(); - } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { - throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); + if (source.getLengthStepCaracteristic() != null) { + if (pmfmId == null) { + pmfmId = source.getLengthStepCaracteristic().getId(); + } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { + throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); + } + notNullFrequencies.add(source); } } @@ -452,7 +458,7 @@ fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); if (catchBatch == null) { - return frequencies; + return notNullFrequencies; } // Retrieve parent @@ -467,7 +473,7 @@ short rankOrder = 0; List<SortingBatch> batchsToUpdate = Lists.newArrayList(); - for (SpeciesBatchFrequency source : frequencies) { + for (SpeciesBatchFrequency source : notNullFrequencies) { rankOrder++; // Not existing batch @@ -510,7 +516,7 @@ getCurrentSession().flush(); - return frequencies; + return notNullFrequencies; } //------------------------------------------------------------------------// @@ -1282,7 +1288,7 @@ copyIfNull); inertBatch.setRankOrder((short) 2); } - + // ----------------------------------------------------------------------------- // Sorted Vrac > Benthos // ----------------------------------------------------------------------------- @@ -1298,9 +1304,9 @@ copyIfNull); benthosBatch.setRankOrder((short) 2); } - + // TODO plancton, macro déchet... - } + } } // ----------------------------------------------------------------------------- @@ -1341,7 +1347,7 @@ copyIfNull); speciesBatch.setRankOrder((short) 1); } - + // ----------------------------------------------------------------------------- // Hors Vrac > Benthos : // -----------------------------------------------------------------------------