r748 - trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service
Author: tchemit Date: 2013-04-08 12:06:53 +0200 (Mon, 08 Apr 2013) New Revision: 748 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/748 Log: fixes #2235: [ESPECE] suppression d'un lot fils puis tentative de suppression du p?\195?\168re : erreur Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 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-08 10:00:00 UTC (rev 747) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-08 10:06:53 UTC (rev 748) @@ -36,6 +36,7 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.service.batch.BatchPersistenceHelper; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.FlushMode; @@ -202,7 +203,47 @@ @Override public void deleteSpeciesSubBatch(String id) { Preconditions.checkNotNull(id); - deleteSpeciesBatch(id); + + getCurrentSession().setFlushMode(FlushMode.COMMIT); + + Integer speciesBatchId = Integer.valueOf(id); + + // get catch batch + Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(speciesBatchId); + + Preconditions.checkNotNull( + catchBatchId, + "Could not find catchBatch for speciesBatch: " + speciesBatchId); + + CatchBatch catchBatch = + catchBatchDao.loadFullTree(catchBatchId); + + // get species batch + SortingBatch sortingBatch = catchBatchDao.getSortingBatchById( + catchBatch, speciesBatchId); + + // get his children + Collection<Batch> childBatchs = sortingBatch.getChildBatchs(); + + if (CollectionUtils.isNotEmpty(childBatchs)) { + + for (Batch childBatch : childBatchs) { + + // delete this child and all his children + Integer childBatchId = childBatch.getId(); + + if (log.isInfoEnabled()) { + log.info("Delete child [" + childBatchId + "] of species batch: " + id); + } + catchBatchDao.removeWithChildren(childBatchId); + + // delete his attachment (if any) + attachmentPersistenceService.deleteAllAttachment(childBatchId); + } + } + + + getCurrentSession().flush(); } @Override
participants (1)
-
tchemit@users.forge.codelutin.com