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
1 changed file:
Changes:
| ... | ... | @@ -65,19 +65,19 @@ public class SurveySpi extends GeneratedSurveySpi { |
| 65 | 65 | |
| 66 | 66 | // Get all batch ids associated to this survey
|
| 67 | 67 | Set<String> newBatchIds = dto.getBatches().stream().map(BatchReference::getId).collect(Collectors.toSet());
|
| 68 | - Collection<Batch> oldLocalmarketBatch = parent.getLocalmarketBatch();
|
|
| 69 | - // If no more associated to this survey, remove association
|
|
| 70 | - oldLocalmarketBatch.stream().filter(b -> newBatchIds.contains(b.getTopiaId())).forEach(b -> b.setSurvey(null));
|
|
| 71 | - if (newBatchIds.isEmpty() && dto.isPersisted()) {
|
|
| 72 | - // may be some have been removed ?
|
|
| 73 | - oldLocalmarketBatch.stream().filter(b -> b.getSurvey() != null && dto.getId().equals(b.getSurvey().getTopiaId())).forEach(b -> b.setSurvey(null));
|
|
| 68 | + Collection<Batch> localmarketBatches = parent.getLocalmarketBatch();
|
|
| 69 | + if (dto.isPersisted()) {
|
|
| 70 | + // Remove from batches survey if equals to this one
|
|
| 71 | + String surveyId = dto.getId();
|
|
| 72 | + localmarketBatches.stream()
|
|
| 73 | + .filter(b -> b.getSurvey() != null && surveyId.equals(b.getSurvey().getTopiaId()))
|
|
| 74 | + .forEach(b -> b.setSurvey(null));
|
|
| 74 | 75 | }
|
| 75 | 76 | if (needCopy) {
|
| 76 | 77 | fromDto(context, entity, dto);
|
| 77 | 78 | }
|
| 78 | 79 | // Set new association on batches associated to this survey
|
| 79 | - Collection<Batch> newLocalmarketBatch = parent.getLocalmarketBatch();
|
|
| 80 | - newLocalmarketBatch.stream().filter(b -> newBatchIds.contains(b.getTopiaId())).forEach(b -> b.setSurvey(entity));
|
|
| 80 | + localmarketBatches.stream().filter(b -> newBatchIds.contains(b.getTopiaId())).forEach(b -> b.setSurvey(entity));
|
|
| 81 | 81 | super.onSave(context, parent, entity, dto, false);
|
| 82 | 82 | }
|
| 83 | 83 | //
|