diff --git a/backend/core/src/main/java/org/opencdmp/commons/types/planblueprint/importexport/BlueprintDescriptionTemplateImportExport.java b/backend/core/src/main/java/org/opencdmp/commons/types/planblueprint/importexport/BlueprintDescriptionTemplateImportExport.java index c58563429..0a8aeb852 100644 --- a/backend/core/src/main/java/org/opencdmp/commons/types/planblueprint/importexport/BlueprintDescriptionTemplateImportExport.java +++ b/backend/core/src/main/java/org/opencdmp/commons/types/planblueprint/importexport/BlueprintDescriptionTemplateImportExport.java @@ -11,6 +11,8 @@ import java.util.UUID; public class BlueprintDescriptionTemplateImportExport { @XmlElement(name = "descriptionTemplateGroupId") private UUID descriptionTemplateGroupId; + @XmlElement(name = "descriptionTemplateCode") + private String descriptionTemplateCode; @XmlElement(name = "label") private String label; @XmlAttribute(name = "minMultiplicity") @@ -26,6 +28,14 @@ public class BlueprintDescriptionTemplateImportExport { this.descriptionTemplateGroupId = descriptionTemplateGroupId; } + public String getDescriptionTemplateCode() { + return descriptionTemplateCode; + } + + public void setDescriptionTemplateCode(String descriptionTemplateCode) { + this.descriptionTemplateCode = descriptionTemplateCode; + } + public String getLabel() { return this.label; } diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/planblueprintdefinition/DescriptionTemplatePersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/planblueprintdefinition/DescriptionTemplatePersist.java index b4ec7816b..2a8afcac9 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/planblueprintdefinition/DescriptionTemplatePersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/planblueprintdefinition/DescriptionTemplatePersist.java @@ -20,6 +20,10 @@ public class DescriptionTemplatePersist { public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId"; + private String descriptionTemplateCode; + public static final String _descriptionTemplateCode = "descriptionTemplateCode"; + + private String label; public static final String _label = "label"; diff --git a/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java index 76252426f..1fdb4d7ff 100644 --- a/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/planblueprint/PlanBlueprintServiceImpl.java @@ -581,7 +581,7 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService { List planBlueprintDescriptionTemplates = new LinkedList<>(); if (!this.conventionService.isListNullOrEmpty(entity.getDescriptionTemplates())) { for (DescriptionTemplateEntity descriptionTemplate : entity.getDescriptionTemplates()) { - planBlueprintDescriptionTemplates.add(this.prefillingSourceXmlToExport(descriptionTemplate)); + planBlueprintDescriptionTemplates.add(this.blueprintDescriptionTemplateXmlToExport(descriptionTemplate)); } } xml.setDescriptionTemplates(planBlueprintDescriptionTemplates); @@ -596,8 +596,11 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService { return xml; } - private BlueprintDescriptionTemplateImportExport prefillingSourceXmlToExport(DescriptionTemplateEntity entity) { + private BlueprintDescriptionTemplateImportExport blueprintDescriptionTemplateXmlToExport(DescriptionTemplateEntity entity) { BlueprintDescriptionTemplateImportExport xml = new BlueprintDescriptionTemplateImportExport(); + org.opencdmp.data.DescriptionTemplateEntity data = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(entity.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(org.opencdmp.data.DescriptionTemplateEntity._code)); + + if (data != null) xml.setDescriptionTemplateCode(data.getCode()); xml.setDescriptionTemplateGroupId(entity.getDescriptionTemplateGroupId()); xml.setLabel(entity.getLabel()); if (entity.getMinMultiplicity() != null ) xml.setMinMultiplicity(entity.getMinMultiplicity()); @@ -797,11 +800,20 @@ public class PlanBlueprintServiceImpl implements PlanBlueprintService { } private DescriptionTemplatePersist xmlDescriptionTemplateToPersist(BlueprintDescriptionTemplateImportExport importXml) { - org.opencdmp.data.DescriptionTemplateEntity data = importXml.getDescriptionTemplateGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(importXml.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._groupId)) : null; - if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{importXml.getDescriptionTemplateGroupId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); - DescriptionTemplatePersist persist = new DescriptionTemplatePersist(); - persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId()); + + org.opencdmp.data.DescriptionTemplateEntity data = importXml.getDescriptionTemplateGroupId() != null ? this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().groupIds(importXml.getDescriptionTemplateGroupId()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._groupId)) : null; + if (data != null ) { + persist.setDescriptionTemplateGroupId(importXml.getDescriptionTemplateGroupId()); + } else { + if (!this.conventionService.isNullOrEmpty(importXml.getDescriptionTemplateCode())) { + data = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(importXml.getDescriptionTemplateCode()).disableTracking().firstAs(new BaseFieldSet().ensure(DescriptionTemplate._code).ensure(DescriptionTemplate._groupId)); + if (data != null) persist.setDescriptionTemplateGroupId(data.getGroupId()); + } + } + + if (data == null) throw new MyValidationException(this.errors.getDescriptionTemplateImportNotFound().getCode(), !this.conventionService.isNullOrEmpty(importXml.getDescriptionTemplateCode()) ? importXml.getDescriptionTemplateCode() : importXml.getDescriptionTemplateGroupId().toString()); + persist.setLabel(importXml.getLabel()); persist.setMinMultiplicity(importXml.getMinMultiplicity()); persist.setMaxMultiplicity(importXml.getMaxMultiplicity());