Author: tchemit Date: 2013-04-16 01:10:19 +0200 (Tue, 16 Apr 2013) New Revision: 786 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/786 Log: fixes #2293: [BENTHOS] Erreur lors de la cr?\195?\169ation de lots Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-04-15 20:48:35 UTC (rev 785) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-04-15 23:10:19 UTC (rev 786) @@ -233,22 +233,28 @@ @Override public List<BenthosBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) { + Preconditions.checkNotNull(benthosBatchId); + +// List<BenthosBatchFrequency> results = Lists.newArrayList(); +// +// Integer sortingBatchId = Integer.valueOf(benthosBatchId); +// Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(sortingBatchId); +// Preconditions.checkNotNull( +// catchBatchId, +// "Could not find catchBatch for benthosBatch: " + benthosBatchId); +// +// CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); +// +// SortingBatch sortingBatch = catchBatchDao.getSortingBatchById( +// catchBatch, sortingBatchId); +// +// List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(sortingBatch); + List<SortingBatch> frequencyChilds = batchHelper.getFrequencies(benthosBatchId); List<BenthosBatchFrequency> results = Lists.newArrayList(); - - Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(benthosBatchId)); - if (catchBatchId == null) { - return results; - } - - CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); - - SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(benthosBatchId)); - - for (Batch batch : sortingBatch.getChildBatchs()) { - SortingBatch source = (SortingBatch) batch; + for (SortingBatch child : frequencyChilds) { BenthosBatchFrequency target = TuttiBeanFactory.newBenthosBatchFrequency(); - entityToBenthosBatchFrequency(source, target); + entityToBenthosBatchFrequency(child, target); results.add(target); } return Collections.unmodifiableList(results); @@ -286,10 +292,14 @@ // Remember child ids, to remove unchanged item (see at bottom in this method) List<Integer> notUpdatedChildIds = Lists.newArrayList(); - for (Batch batch : parentBatch.getChildBatchs()) { - SortingBatch sortingBatch = (SortingBatch) batch; - notUpdatedChildIds.add(sortingBatch.getId()); + List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(parentBatch); + for (SortingBatch child : frequencyChilds) { + notUpdatedChildIds.add(child.getId()); } +// for (Batch batch : parentBatch.getChildBatchs()) { +// SortingBatch sortingBatch = (SortingBatch) batch; +// notUpdatedChildIds.add(sortingBatch.getId()); +// } short rankOrder = 0; List<SortingBatch> batchsToUpdate = Lists.newArrayList(); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-15 20:48:35 UTC (rev 785) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-15 23:10:19 UTC (rev 786) @@ -279,21 +279,22 @@ String speciesBatchId) { Preconditions.checkNotNull(speciesBatchId); +// List<SpeciesBatchFrequency> results = Lists.newArrayList(); +// +// Integer sortingBatchId = Integer.valueOf(speciesBatchId); +// Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(sortingBatchId); +// Preconditions.checkNotNull( +// catchBatchId, +// "Could not find catchBatch for speciesBatch: " + speciesBatchId); +// +// CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); +// +// SortingBatch sortingBatch = catchBatchDao.getSortingBatchById( +// catchBatch, sortingBatchId); +// +// List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(sortingBatch); + List<SortingBatch> frequencyChilds = batchHelper.getFrequencies(speciesBatchId); List<SpeciesBatchFrequency> results = Lists.newArrayList(); - - Integer sortingBatchId = Integer.valueOf(speciesBatchId); - Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(sortingBatchId); - Preconditions.checkNotNull( - catchBatchId, - "Could not find catchBatch for speciesBatch: " + speciesBatchId); - - CatchBatch catchBatch = - catchBatchDao.loadFullTree(catchBatchId); - - SortingBatch sortingBatch = catchBatchDao.getSortingBatchById( - catchBatch, sortingBatchId); - - List<SortingBatch> frequencyChilds = batchHelper.getFrequencyChilds(sortingBatch); for (SortingBatch child : frequencyChilds) { SpeciesBatchFrequency target = TuttiBeanFactory.newSpeciesBatchFrequency(); @@ -421,7 +422,6 @@ //-- Internal methods --// //------------------------------------------------------------------------// - protected SpeciesBatch entityToSpeciesBatch(SortingBatch source, SpeciesBatch target) { Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-04-15 20:48:35 UTC (rev 785) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-04-15 23:10:19 UTC (rev 786) @@ -27,6 +27,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.adagio.core.dao.data.batch.Batch; +import fr.ifremer.adagio.core.dao.data.batch.CatchBatch; import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; import fr.ifremer.adagio.core.dao.data.measure.Measurement; @@ -40,8 +41,6 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.service.AbstractPersistenceService; import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Component; @@ -59,9 +58,9 @@ @Component("batchPersistenceHelper") public class BatchPersistenceHelper extends AbstractPersistenceService { - /** Logger. */ - private static final Log log = - LogFactory.getLog(BatchPersistenceHelper.class); +// /** Logger. */ +// private static final Log log = +// LogFactory.getLog(BatchPersistenceHelper.class); public static final String BATCH_PMFM_ID = "pmfmId"; @@ -83,16 +82,33 @@ return result; } - public List<SortingBatch> getNotFrequencyChilds(SortingBatch sortingBatch) { - List<SortingBatch> result = Lists.newArrayList(); +// public List<SortingBatch> getNotFrequencyChilds(SortingBatch sortingBatch) { +// List<SortingBatch> result = Lists.newArrayList(); +// +// for (Batch batch : sortingBatch.getChildBatchs()) { +// SortingBatch child = (SortingBatch) batch; +// if (isFrequencyBatch(child)) { +// result.add(child); +// } +// } +// return result; +// } - for (Batch batch : sortingBatch.getChildBatchs()) { - SortingBatch child = (SortingBatch) batch; - if (isFrequencyBatch(child)) { - result.add(child); - } - } - return result; + public List<SortingBatch> getFrequencies(String batchId) { + Preconditions.checkNotNull(batchId); + Integer sortingBatchId = Integer.valueOf(batchId); + Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(sortingBatchId); + Preconditions.checkNotNull( + catchBatchId, + "Could not find catchBatch for batch: " + batchId); + + CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + + SortingBatch sortingBatch = catchBatchDao.getSortingBatchById( + catchBatch, sortingBatchId); + + List<SortingBatch> frequencyChilds = getFrequencyChilds(sortingBatch); + return frequencyChilds; } /**
participants (1)
-
tchemit@users.forge.codelutin.com