diff --git a/backend/core/src/main/java/org/opencdmp/model/persist/DescriptionTemplatePersist.java b/backend/core/src/main/java/org/opencdmp/model/persist/DescriptionTemplatePersist.java index a90c9209b..07f30dbb6 100644 --- a/backend/core/src/main/java/org/opencdmp/model/persist/DescriptionTemplatePersist.java +++ b/backend/core/src/main/java/org/opencdmp/model/persist/DescriptionTemplatePersist.java @@ -180,7 +180,6 @@ public class DescriptionTemplatePersist { .must(() -> this.lessEqualLength(item.getLabel(), DescriptionTemplateEntity._labelLength)) .failOn(DescriptionTemplatePersist._label).failWith(this.messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())), this.spec() - .iff(() -> item.getStatus() == DescriptionTemplateStatus.Finalized) .must(() -> !this.isEmpty(item.getCode())) .failOn(DescriptionTemplatePersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplatePersist._code}, LocaleContextHolder.getLocale())), this.spec() diff --git a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index b2d2f2a11..8f86e88ad 100644 --- a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -763,6 +763,13 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic .groupIds(groupId) .count() : 0; + if (activeDescriptionTemplatesForTheGroup == 0 && !this.conventionService.isNullOrEmpty(importXml.getCode())) { + activeDescriptionTemplatesForTheGroup = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking() + .isActive(IsActive.Active) + .codes(importXml.getCode()) + .count(); + } + if (activeDescriptionTemplatesForTheGroup == 0) { DescriptionTemplatePersist persist = new DescriptionTemplatePersist(); persist.setLabel(label); @@ -775,12 +782,23 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.validatorFactory.validator(DescriptionTemplatePersist.DescriptionTemplatePersistValidator.class).validateForce(persist); return this.persist(persist, groupId, fields); } else { - DescriptionTemplateEntity latestVersionDescriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking() - .versionStatuses(DescriptionTemplateVersionStatus.Current) - .isActive(IsActive.Active) - .statuses(DescriptionTemplateStatus.Finalized) - .groupIds(groupId) - .first(); + DescriptionTemplateEntity latestVersionDescriptionTemplate = null; + if (groupId != null) { + latestVersionDescriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking() + .versionStatuses(DescriptionTemplateVersionStatus.Current) + .isActive(IsActive.Active) + .statuses(DescriptionTemplateStatus.Finalized) + .groupIds(groupId) + .first(); + } + if (latestVersionDescriptionTemplate == null && !this.conventionService.isNullOrEmpty(importXml.getCode())) { + latestVersionDescriptionTemplate = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking() + .versionStatuses(DescriptionTemplateVersionStatus.Current) + .isActive(IsActive.Active) + .statuses(DescriptionTemplateStatus.Finalized) + .codes(importXml.getCode()) + .first(); + } if (latestVersionDescriptionTemplate == null) throw new MyValidationException(this.errors.getDescriptionTemplateIsNotFinalized().getCode(), this.errors.getDescriptionTemplateIsNotFinalized().getMessage()); NewVersionDescriptionTemplatePersist persist = new NewVersionDescriptionTemplatePersist();