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 aaceb69f7..3ec5f7b5b 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 @@ -2216,13 +2216,24 @@ public class PlanServiceImpl implements PlanService { persist.setDescriptionTemplates(this.commonModelPlanDescriptionTemplatesToPersist(model)); //TODO maybe we should create templates if not exists persist.setProperties(this.commonModelPlanPropertiesToPersist(model)); + org.opencdmp.commons.types.planblueprint.DefinitionEntity definition = null; + if (persist.getBlueprint() != null) { + PlanBlueprintEntity planBlueprintEntity = this.queryFactory.query(PlanBlueprintQuery.class).disableTracking().ids(persist.getBlueprint()).first(); + definition = this.xmlHandlingService.fromXmlSafe(org.opencdmp.commons.types.planblueprint.DefinitionEntity.class, planBlueprintEntity.getDefinition()); + if (definition == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{persist.getBlueprint(), org.opencdmp.commons.types.planblueprint.DefinitionEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); + } + this.validatorFactory.validator(PlanPersist.PlanPersistValidator.class).validateForce(persist); Plan plan = this.persist(persist, BaseFieldSet.build(fields, Plan._id, Plan._hash)); if (plan == null) throw new MyApplicationException("Error creating plan"); if (!this.conventionService.isListNullOrEmpty(model.getDescriptions())){ for (DescriptionModel description: model.getDescriptions()){ - this.descriptionService.importCommonModel(description, plan.getId(), fields != null ? fields.extractPrefixed(this.conventionService.asPrefix(Plan._description)) : null); + if (definition != null && description.getSectionId() != null && !this.conventionService.isListNullOrEmpty(definition.getSections())) { + if (definition.getSections().stream().filter(x -> x.getId().equals(description.getSectionId()) && x.getHasTemplates()).findFirst().orElse(null) != null) { + this.descriptionService.importCommonModel(description, plan.getId(), fields != null ? fields.extractPrefixed(this.conventionService.asPrefix(Plan._description)) : null); + } + } } }