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 2799e7d7c..aaceb69f7 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 @@ -1931,6 +1931,13 @@ public class PlanServiceImpl implements PlanService { persist.setDescriptionTemplates(this.xmlPlanDescriptionTemplatesToPersist(planXml)); //TODO maybe we should create templates if not exists persist.setBlueprint(this.xmlPlanBlueprintToPersist(planXml)); + 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)); @@ -1938,7 +1945,11 @@ public class PlanServiceImpl implements PlanService { if (!this.conventionService.isListNullOrEmpty(planXml.getDescriptions())){ for (DescriptionImportExport description: planXml.getDescriptions()){ - this.descriptionService.importXml(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.importXml(description, plan.getId(), fields != null ? fields.extractPrefixed(this.conventionService.asPrefix(Plan._description)) : null); + } + } } } diff --git a/frontend/src/app/ui/description/editor/description-editor.component.ts b/frontend/src/app/ui/description/editor/description-editor.component.ts index 5cf384710..8c60d627a 100644 --- a/frontend/src/app/ui/description/editor/description-editor.component.ts +++ b/frontend/src/app/ui/description/editor/description-editor.component.ts @@ -220,7 +220,7 @@ export class DescriptionEditorComponent extends BaseEditor 0 && data.plan?.descriptions?.length > 0) { const section = data.plan?.blueprint?.definition?.sections.find(x => x.id == data.planDescriptionTemplate?.sectionId); - if (section.hasTemplates) { + if (section?.hasTemplates) { const notAvailableDescriptionTemplates = this.calculateMultiplicityRejectedPlanDescriptionTemplates(section, data.plan.descriptions.filter(x => x.isActive == IsActive.Active)); this.item.plan.planDescriptionTemplates = data.plan.planDescriptionTemplates.filter(x => !notAvailableDescriptionTemplates.map(y => y.id).includes(x.id)) } diff --git a/frontend/src/app/ui/description/editor/description-editor.model.ts b/frontend/src/app/ui/description/editor/description-editor.model.ts index 42881913e..131fb7308 100644 --- a/frontend/src/app/ui/description/editor/description-editor.model.ts +++ b/frontend/src/app/ui/description/editor/description-editor.model.ts @@ -380,7 +380,11 @@ export class DescriptionPropertyDefinitionFieldSetItemEditorModel implements Des if (item.fields instanceof Map) new Map(item.fields)?.forEach((value, key) => this.fields.set(key, new DescriptionFieldEditorModel(this.validationErrorModel).fromModel(value, item.ordinal, definitionFieldSet?.fields?.find(x => x.id == key), descriptionReferences))); else - Object.keys(item.fields)?.forEach((key) => this.fields.set(key, new DescriptionFieldEditorModel(this.validationErrorModel).fromModel(item.fields[key], item.ordinal, definitionFieldSet?.fields?.find(x => x.id == key), descriptionReferences))); + Object.keys(item.fields)?.forEach((key) => { + if ( definitionFieldSet?.fields?.find(x => x.id == key) != null){ + this.fields.set(key, new DescriptionFieldEditorModel(this.validationErrorModel).fromModel(item.fields[key], item.ordinal, definitionFieldSet?.fields?.find(x => x.id == key), descriptionReferences)) + } + }); } } return this; @@ -509,7 +513,7 @@ export class DescriptionFieldEditorModel implements DescriptionFieldPersist { sourceType: x.reference.sourceType } }); - if (descriptionTemplateField.data.multipleSelect == true) { + if (descriptionTemplateField?.data?.multipleSelect == true) { this.references = references; } else { if (references?.length == 1) this.reference = references[0];