From 7980579decff40feb83c655163e2bb77c1017640 Mon Sep 17 00:00:00 2001 From: "CITE\\amentis" Date: Wed, 31 Jul 2024 10:42:21 +0300 Subject: [PATCH] make editable description template type code --- .../DescriptionTemplateTypeServiceImpl.java | 6 +++--- .../editor/description-template-type-editor.component.ts | 4 ++-- .../editor/description-template-type-editor.model.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java index 9030f5fb7..f41516b8c 100644 --- a/backend/core/src/main/java/org/opencdmp/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java @@ -103,8 +103,6 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy data = this.entityManager.find(DescriptionTemplateTypeEntity.class, model.getId()); if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale())); if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); - if (!data.getCode().equals(model.getCode())) - throw new MyForbiddenException("Code can not change"); } else { this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT); data = new DescriptionTemplateTypeEntity(); @@ -118,10 +116,12 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy data.setStatus(model.getStatus()); data.setUpdatedAt(Instant.now()); + Long descriptionTemplateTypeCodes = this.queryFactory.query(DescriptionTemplateTypeQuery.class).disableTracking().codes(model.getCode()).count(); + if (isUpdate) { + if (descriptionTemplateTypeCodes > 1) throw new MyValidationException(this.errors.getDescriptionTemplateTypeCodeExists().getCode(), this.errors.getDescriptionTemplateTypeCodeExists().getMessage()); this.entityManager.merge(data); } else { - Long descriptionTemplateTypeCodes = this.queryFactory.query(DescriptionTemplateTypeQuery.class).disableTracking().codes(model.getCode()).count(); if (descriptionTemplateTypeCodes > 0) throw new MyValidationException(this.errors.getDescriptionTemplateTypeCodeExists().getCode(), this.errors.getDescriptionTemplateTypeCodeExists().getMessage()); this.entityManager.persist(data); this.accountingService.increase(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_TYPE_COUNT.getValue()); diff --git a/frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.component.ts b/frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.component.ts index affafd115..a7dcb70ef 100644 --- a/frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.component.ts +++ b/frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.component.ts @@ -118,7 +118,7 @@ export class DescriptionTemplateTypeEditorComponent extends BaseEditor void): void { - const formData = this.formGroup.getRawValue() as DescriptionTemplateTypePersist; + const formData = this.formService.getValue(this.formGroup.value) as DescriptionTemplateTypePersist; this.descriptionTemplateTypeService.persist(formData) .pipe(takeUntil(this._destroyed)).subscribe( diff --git a/frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.model.ts b/frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.model.ts index 775ec0daf..20ddc61c0 100644 --- a/frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.model.ts +++ b/frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.model.ts @@ -32,13 +32,13 @@ export class DescriptionTemplateTypeEditorModel extends BaseEditorModel implemen return this; } - buildForm(context: ValidationContext = null, disabled: boolean = false, isNew: boolean = false): UntypedFormGroup { + buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup { if (context == null) { context = this.createValidationContext(); } return this.formBuilder.group({ id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators], name: [{ value: this.name, disabled: disabled }, context.getValidation('name').validators], - code: [{ value: this.code, disabled: !isNew }, context.getValidation('code').validators], + code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators], status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators], hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators] });