This is an automated email from the git hooks/post-receive script. New commit to branch feature/8145-2 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 364af86b567dbca3862c7b366b7698dd0c90f8fb Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Mar 20 22:16:01 2016 +0100 Gestion du nettoyage du cache avant la suppresion de lot ou de trait --- .../ifremer/tutti/service/PersistenceService.java | 51 +++++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java index 2362184..4312a55 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java @@ -65,6 +65,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Vessels; import fr.ifremer.tutti.persistence.model.ProgramDataModel; import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; import fr.ifremer.tutti.persistence.service.UpdateSchemaContextSupport; +import fr.ifremer.tutti.service.samplingCache.CruiseSamplingCache; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; @@ -86,9 +87,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.concurrent.Callable; @@ -1083,8 +1086,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer //------------------------------------------------------------------------// @Override - public List<Attachment> getAllAttachments(ObjectTypeCode objectType, - Integer objectId) { + public List<Attachment> getAllAttachments(ObjectTypeCode objectType, Integer objectId) { return driver.getAllAttachments(objectType, objectId); } @@ -1282,7 +1284,6 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer @Override public FishingOperation getFishingOperation(Integer id) { - FishingOperation bean = driver.getFishingOperation(id); // see http://forge.codelutin.com/issues/2014 if (bean.getGearShootingEndDate() == null) { @@ -1303,7 +1304,9 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer if (Objects.equals(bean.getGearShootingStartDate(), bean.getGearShootingEndDate())) { bean.setGearShootingEndDate(null); } - return driver.createFishingOperation(bean); + FishingOperation fishingOperation = driver.createFishingOperation(bean); + //FIXME Update samplingCache + return fishingOperation; } @Override @@ -1312,16 +1315,25 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer if (Objects.equals(bean.getGearShootingStartDate(), bean.getGearShootingEndDate())) { bean.setGearShootingEndDate(null); } - return driver.saveFishingOperation(bean); + FishingOperation fishingOperation = driver.saveFishingOperation(bean); + //FIXME Update samplingCache + return fishingOperation; } @Override public Collection<FishingOperation> saveFishingOperations(Collection<FishingOperation> beans) { - return driver.saveFishingOperations(beans); + Collection<FishingOperation> fishingOperations = driver.saveFishingOperations(beans); + //FIXME Update samplingCache + return fishingOperations; } @Override public void deleteFishingOperation(Integer id) { + Optional<CruiseSamplingCache> optionalCruiseSamplingCache = context.getDataContext().getOptionalCruiseSamplingCache(); + if (optionalCruiseSamplingCache.isPresent()) { + FishingOperation fishingOperation = getFishingOperation(id); + optionalCruiseSamplingCache.get().removeFishingOperation(fishingOperation); + } driver.deleteFishingOperation(id); } @@ -1370,6 +1382,11 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } @Override + public Set<Integer> getBatchChildIds(Integer id) { + return driver.getBatchChildIds(id); + } + + @Override public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) { return driver.createSpeciesBatch(bean, parentBatchId, computeRankOrder); } @@ -1386,11 +1403,13 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer @Override public void deleteSpeciesBatch(Integer id) { + beforeDeleteBatch(id, true); driver.deleteSpeciesBatch(id); } @Override public void deleteSpeciesSubBatch(Integer id) { + beforeDeleteBatch(id, false); driver.deleteSpeciesSubBatch(id); } @@ -1446,11 +1465,13 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer @Override public void deleteBenthosBatch(Integer id) { + beforeDeleteBatch(id, true); driver.deleteBenthosBatch(id); } @Override public void deleteBenthosSubBatch(Integer id) { + beforeDeleteBatch(id, false); driver.deleteBenthosSubBatch(id); } @@ -1583,4 +1604,22 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer driver.deleteAllIndividualObservationsForBatch(speciesBatchId); } + protected void beforeDeleteBatch(Integer id, boolean addBatchId) { + Optional<CruiseSamplingCache> optionalCruiseSamplingCache = context.getDataContext().getOptionalCruiseSamplingCache(); + if (optionalCruiseSamplingCache.isPresent()) { + FishingOperation fishingOperation = context.getDataContext().getFishingOperation(); + CruiseSamplingCache cruiseSamplingCache = optionalCruiseSamplingCache.get(); + Set<Integer> batchIds = new LinkedHashSet<>(); + if (addBatchId) { + batchIds.add(id); + } + batchIds.addAll(getBatchChildIds(id)); + batchIds.forEach(speciesBatchId -> { + List<IndividualObservationBatch> allIndividualObservationBatchsForBatch = getAllIndividualObservationBatchsForBatch(id); + cruiseSamplingCache.removeIndividualObservations(fishingOperation, allIndividualObservationBatchsForBatch); + }); + + } + } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.