From 481b129111f575826804f0669271ecd2de2f610e Mon Sep 17 00:00:00 2001 From: "CITE\\spapacharalampous" Date: Fri, 19 Jul 2024 16:32:18 +0300 Subject: [PATCH] fix on plan-new-version --- .../opencdmp/service/plan/PlanServiceImpl.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java index dc7af9319..803c82a3c 100644 --- a/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/plan/PlanServiceImpl.java @@ -479,7 +479,6 @@ public class PlanServiceImpl implements PlanService { this.entityManager.flush(); - if (model.getDescriptions() != null){ PlanBlueprintEntity blueprintEntity = this.entityManager.find(PlanBlueprintEntity.class, model.getBlueprintId(), true); if (blueprintEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getBlueprintId(), PlanBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -491,7 +490,7 @@ public class PlanServiceImpl implements PlanService { List models = this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.AllExceptPublic).build(fieldSet, descriptionEntities); - if (!this.conventionService.isListNullOrEmpty(models)){ + if (!this.conventionService.isListNullOrEmpty(models) && !this.conventionService.isListNullOrEmpty(model.getDescriptions())){ for (NewVersionPlanDescriptionPersist newVersionPlanDescriptionPersist : model.getDescriptions()) { Description description = models.stream().filter(x -> x.getId().equals(newVersionPlanDescriptionPersist.getDescriptionId())).findFirst().orElse(null); if (description != null){ @@ -520,12 +519,19 @@ public class PlanServiceImpl implements PlanService { if (!oldPlanEntity.getBlueprintId().equals(blueprintEntity.getId())){ // add description templates if exists in new blueprint List sections = definition.getSections().stream().filter(SectionEntity::getHasTemplates).collect(Collectors.toList()); - if (!this.conventionService.isListNullOrEmpty(sections) && !this.conventionService.isListNullOrEmpty(newPlanDescriptionTemplateEntities)){ + if (!this.conventionService.isListNullOrEmpty(sections)){ for (SectionEntity section: sections) { if (!this.conventionService.isListNullOrEmpty(section.getDescriptionTemplates())){ for (DescriptionTemplateEntity blueprintDescriptionTemplate: section.getDescriptionTemplates()) { - PlanDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = newPlanDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(blueprintDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null); - if (existingBlueprintDescriptionTemplateEntity == null){ + + boolean isDescriptionTemplateAlreadyInPlan = false; + + if (!this.conventionService.isListNullOrEmpty(newPlanDescriptionTemplateEntities)) { + PlanDescriptionTemplateEntity existingBlueprintDescriptionTemplateEntity = newPlanDescriptionTemplateEntities.stream().filter(x -> x.getSectionId().equals(section.getId()) && x.getDescriptionTemplateGroupId().equals(blueprintDescriptionTemplate.getDescriptionTemplateGroupId())).findFirst().orElse(null); + isDescriptionTemplateAlreadyInPlan = existingBlueprintDescriptionTemplateEntity != null; + } + + if (!isDescriptionTemplateAlreadyInPlan){ PlanDescriptionTemplateEntity newTemplate = new PlanDescriptionTemplateEntity(); newTemplate.setId(UUID.randomUUID()); newTemplate.setPlanId(newPlan.getId()); @@ -557,7 +563,6 @@ public class PlanServiceImpl implements PlanService { } } } - } this.entityManager.flush();