Author: tchemit Date: 2013-04-04 21:01:21 +0200 (Thu, 04 Apr 2013) New Revision: 735 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/735 Log: fixes #2248: [TECH] Pi?\195?\168ces-jointes non supprim?\195?\169es Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceImpl.java 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/AccidentalBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceImpl.java 2013-04-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceImpl.java 2013-04-04 19:01:21 UTC (rev 735) @@ -24,10 +24,12 @@ * #L% */ +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @@ -43,6 +45,9 @@ private static final Log log = LogFactory.getLog(AccidentalBatchPersistenceServiceImpl.class); + @Autowired + protected AttachmentPersistenceService attachmentPersistenceService; + @Override public List<AccidentalBatch> getAllAccidentalBatch(String fishingOperationId) { List<AccidentalBatch> result = Lists.newArrayList(); @@ -68,5 +73,7 @@ @Override public void deleteAccidentalBatch(String id) { + Preconditions.checkNotNull(id); + attachmentPersistenceService.deleteAllAttachment(Integer.valueOf(id)); } } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceService.java 2013-04-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceService.java 2013-04-04 19:01:21 UTC (rev 735) @@ -85,4 +85,12 @@ @Transactional(readOnly = false) void deleteAttachment(String attachmentId); + /** + * Deletes all attachments of the given object id. + * + * @param objectId id of the object + */ + @Transactional(readOnly = false) + void deleteAllAttachment(Integer objectId); + } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java 2013-04-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java 2013-04-04 19:01:21 UTC (rev 735) @@ -236,12 +236,17 @@ Attachment target = TuttiBeanFactory.newAttachment(); loadAttachment(source, target); - measurementFileDao.remove(id); + delete(target); + getCurrentSession().flush(); + } - File file = getFile(target); - //TODO Hum we do not have a transaction manager for file :( - TuttiIOUtil.deleteFile(file, "Could not delete attachement file " + file); + @Override + public void deleteAllAttachment(Integer objectId) { + List<Attachment> attachments = getAllAttachments(objectId); + for (Attachment attachment : attachments) { + delete(attachment); + } } //------------------------------------------------------------------------// @@ -269,4 +274,13 @@ File result = new File(dbAttachmentDirectory, attachment.getPath()); return result; } + + protected void delete(Attachment target) { + + measurementFileDao.remove(target.getObjectId()); + + File file = getFile(target); + TuttiIOUtil.deleteFile(file, "Could not delete attachement file " + file); + + } } 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-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-04-04 19:01:21 UTC (rev 735) @@ -39,6 +39,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.FlushMode; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; @@ -61,9 +62,12 @@ private static final Log log = LogFactory.getLog(BenthosBatchPersistenceServiceImpl.class); - @Resource(name = "referentialPersistenceService") + @Autowired protected ReferentialPersistenceService referentialService; + @Autowired + protected AttachmentPersistenceService attachmentPersistenceService; + @Resource(name = "catchBatchDao") protected CatchBatchExtendDao catchBatchDao; @@ -188,8 +192,11 @@ getCurrentSession().setFlushMode(FlushMode.COMMIT); - catchBatchDao.removeWithChildren(Integer.valueOf(id)); + Integer batchId = Integer.valueOf(id); + catchBatchDao.removeWithChildren(batchId); + attachmentPersistenceService.deleteAllAttachment(batchId); + getCurrentSession().flush(); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-04-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-04-04 19:01:21 UTC (rev 735) @@ -46,6 +46,7 @@ import org.apache.commons.logging.LogFactory; import org.hibernate.FlushMode; import org.hibernate.type.IntegerType; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataRetrievalFailureException; import org.springframework.stereotype.Service; @@ -63,9 +64,12 @@ private static final Log log = LogFactory.getLog(CatchBatchPersistenceServiceImpl.class); - @Resource(name = "referentialPersistenceService") + @Autowired protected ReferentialPersistenceService referentialService; + @Autowired + protected AttachmentPersistenceService attachmentPersistenceService; + @Resource(name = "catchBatchDao") protected CatchBatchExtendDao catchBatchDao; Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceService.java 2013-04-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceService.java 2013-04-04 19:01:21 UTC (rev 735) @@ -48,4 +48,7 @@ @Transactional(readOnly = false) FishingOperation saveFishingOperation(FishingOperation bean); + + @Transactional(readOnly = false) + void deleteFishingOperation(String id); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-04-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-04-04 19:01:21 UTC (rev 735) @@ -103,6 +103,9 @@ @Autowired protected ReferentialPersistenceService referentialService; + @Autowired + protected AttachmentPersistenceService attachmentPersistenceService; + @Resource(name = "scientificCruiseDao") protected ScientificCruiseDao scientificCruiseDao; @@ -391,6 +394,13 @@ return bean; } + @Override + public void deleteFishingOperation(String id) { + Preconditions.checkNotNull(id); + + attachmentPersistenceService.deleteAllAttachment(Integer.valueOf(id)); + } + //------------------------------------------------------------------------// //-- Internal methods --// //------------------------------------------------------------------------// Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java 2013-04-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java 2013-04-04 19:01:21 UTC (rev 735) @@ -45,6 +45,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.FlushMode; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; @@ -64,9 +65,12 @@ private static final Log log = LogFactory.getLog(MarineLitterBatchPersistenceServiceImpl.class); - @Resource(name = "referentialPersistenceService") + @Autowired protected ReferentialPersistenceService referentialService; + @Autowired + protected AttachmentPersistenceService attachmentPersistenceService; + @Resource(name = "catchBatchDao") protected CatchBatchExtendDao catchBatchDao; @@ -186,8 +190,11 @@ getCurrentSession().setFlushMode(FlushMode.COMMIT); - catchBatchDao.removeWithChildren(Integer.valueOf(id)); + Integer batchId = Integer.valueOf(id); + catchBatchDao.removeWithChildren(batchId); + attachmentPersistenceService.deleteAllAttachment(batchId); + getCurrentSession().flush(); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceImpl.java 2013-04-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/PlanktonBatchPersistenceServiceImpl.java 2013-04-04 19:01:21 UTC (rev 735) @@ -24,10 +24,12 @@ * #L% */ +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.data.PlanktonBatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @@ -43,6 +45,9 @@ private static final Log log = LogFactory.getLog(PlanktonBatchPersistenceServiceImpl.class); + @Autowired + protected AttachmentPersistenceService attachmentPersistenceService; + @Override public List<PlanktonBatch> getAllPlanktonBatch(String fishingOperationId) { List<PlanktonBatch> result = Lists.newArrayList(); @@ -69,5 +74,7 @@ @Override public void deletePlanktonBatch(String id) { + Preconditions.checkNotNull(id); + attachmentPersistenceService.deleteAllAttachment(Integer.valueOf(id)); } } 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-04 11:29:07 UTC (rev 734) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-04 19:01:21 UTC (rev 735) @@ -39,6 +39,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.FlushMode; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; @@ -61,6 +62,9 @@ private static final Log log = LogFactory.getLog(SpeciesBatchPersistenceServiceImpl.class); + @Autowired + protected AttachmentPersistenceService attachmentPersistenceService; + @Resource(name = "catchBatchDao") protected CatchBatchExtendDao catchBatchDao; @@ -187,8 +191,11 @@ getCurrentSession().setFlushMode(FlushMode.COMMIT); - catchBatchDao.removeWithChildren(Integer.valueOf(id)); + Integer batchId = Integer.valueOf(id); + catchBatchDao.removeWithChildren(batchId); + attachmentPersistenceService.deleteAllAttachment(batchId); + getCurrentSession().flush(); }