Tony CHEMIT pushed to branch develop-9.0.x at ultreiaio / ird-observe Commits: 49d90e71 by Tony Chemit at 2023-01-04T17:03:48+01:00 Mauvaise persistence des lots au niveau des sondages - closes #2591 - - - - - 1 changed file: - core/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/localmarket/SurveySpi.java Changes: ===================================== core/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/localmarket/SurveySpi.java ===================================== @@ -65,19 +65,19 @@ public class SurveySpi extends GeneratedSurveySpi { // Get all batch ids associated to this survey Set<String> newBatchIds = dto.getBatches().stream().map(BatchReference::getId).collect(Collectors.toSet()); - Collection<Batch> oldLocalmarketBatch = parent.getLocalmarketBatch(); - // If no more associated to this survey, remove association - oldLocalmarketBatch.stream().filter(b -> newBatchIds.contains(b.getTopiaId())).forEach(b -> b.setSurvey(null)); - if (newBatchIds.isEmpty() && dto.isPersisted()) { - // may be some have been removed ? - oldLocalmarketBatch.stream().filter(b -> b.getSurvey() != null && dto.getId().equals(b.getSurvey().getTopiaId())).forEach(b -> b.setSurvey(null)); + Collection<Batch> localmarketBatches = parent.getLocalmarketBatch(); + if (dto.isPersisted()) { + // Remove from batches survey if equals to this one + String surveyId = dto.getId(); + localmarketBatches.stream() + .filter(b -> b.getSurvey() != null && surveyId.equals(b.getSurvey().getTopiaId())) + .forEach(b -> b.setSurvey(null)); } if (needCopy) { fromDto(context, entity, dto); } // Set new association on batches associated to this survey - Collection<Batch> newLocalmarketBatch = parent.getLocalmarketBatch(); - newLocalmarketBatch.stream().filter(b -> newBatchIds.contains(b.getTopiaId())).forEach(b -> b.setSurvey(entity)); + localmarketBatches.stream().filter(b -> newBatchIds.contains(b.getTopiaId())).forEach(b -> b.setSurvey(entity)); super.onSave(context, parent, entity, dto, false); } // View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/49d90e71d88b41f2fcac5c9a93... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/49d90e71d88b41f2fcac5c9a93... You're receiving this email because of your account on gitlab.com.