enable description template code only on new and clone state
This commit is contained in:
parent
77d0fb6295
commit
03a567bf34
|
@ -6,7 +6,6 @@ import gr.cite.tools.validation.ValidatorFactory;
|
|||
import gr.cite.tools.validation.specification.Specification;
|
||||
import org.opencdmp.convention.ConventionService;
|
||||
import org.opencdmp.data.DescriptionTemplateEntity;
|
||||
import org.opencdmp.data.DescriptionTemplateTypeEntity;
|
||||
import org.opencdmp.errorcode.ErrorThesaurusProperties;
|
||||
import org.opencdmp.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -27,10 +26,6 @@ public class NewVersionDescriptionTemplatePersist {
|
|||
|
||||
public static final String _label = "label";
|
||||
|
||||
private String code = null;
|
||||
|
||||
public static final String _code = "code";
|
||||
|
||||
private String description = null;
|
||||
|
||||
public static final String _description = "description";
|
||||
|
@ -75,14 +70,6 @@ public class NewVersionDescriptionTemplatePersist {
|
|||
this.label = label;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
@ -174,14 +161,6 @@ public class NewVersionDescriptionTemplatePersist {
|
|||
.iff(() -> !this.isEmpty(item.getLabel()))
|
||||
.must(() -> this.lessEqualLength(item.getLabel(), DescriptionTemplateEntity._labelLength))
|
||||
.failOn(NewVersionDescriptionTemplatePersist._label).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{NewVersionDescriptionTemplatePersist._label}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(() -> item.getStatus() == DescriptionTemplateStatus.Finalized)
|
||||
.must(() -> !this.isEmpty(item.getCode()))
|
||||
.failOn(NewVersionDescriptionTemplatePersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._code}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.iff(() -> !this.isEmpty(item.getCode()))
|
||||
.must(() -> this.lessEqualLength(item.getCode(), DescriptionTemplateTypeEntity._codeLength))
|
||||
.failOn(NewVersionDescriptionTemplatePersist._code).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{NewVersionDescriptionTemplatePersist._code}, LocaleContextHolder.getLocale())),
|
||||
this.spec()
|
||||
.must(() -> !this.isEmpty(item.getDescription()))
|
||||
.failOn(NewVersionDescriptionTemplatePersist._description).failWith(messageSource.getMessage("Validation_Required", new Object[]{NewVersionDescriptionTemplatePersist._description}, LocaleContextHolder.getLocale())),
|
||||
|
|
|
@ -181,6 +181,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
|||
throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
||||
if (data.getStatus().equals(DescriptionTemplateStatus.Finalized))
|
||||
throw new MyForbiddenException("Can not update finalized template");
|
||||
if (!data.getCode().equals(model.getCode()))
|
||||
throw new MyForbiddenException("Code can not change");
|
||||
} else {
|
||||
this.usageLimitService.checkIncrease(UsageLimitTargetMetric.DESCRIPTION_TEMPLATE_COUNT);
|
||||
|
||||
|
@ -212,10 +214,10 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
|||
data.setUpdatedAt(Instant.now());
|
||||
data.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(model.getDefinition())));
|
||||
|
||||
Long descriptionTemplateCodes = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(model.getCode()).count();
|
||||
Long descriptionTemplateCodes = 0L;
|
||||
if (model.getCode() != null) descriptionTemplateCodes = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(model.getCode()).count();
|
||||
|
||||
if (isUpdate) {
|
||||
if (descriptionTemplateCodes > 1) throw new MyValidationException(this.errors.getDescriptionTemplateCodeExists().getCode(), this.errors.getDescriptionTemplateCodeExists().getMessage());
|
||||
this.entityManager.merge(data);
|
||||
} else {
|
||||
if (descriptionTemplateCodes > 0) throw new MyValidationException(this.errors.getDescriptionTemplateCodeExists().getCode(), this.errors.getDescriptionTemplateCodeExists().getMessage());
|
||||
|
@ -722,14 +724,12 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
|||
data.setVersion((short) (oldDescriptionTemplateEntity.getVersion() + 1));
|
||||
data.setDescription(model.getDescription());
|
||||
data.setLabel(model.getLabel());
|
||||
data.setCode(model.getCode());
|
||||
data.setCode(oldDescriptionTemplateEntity.getCode());
|
||||
data.setTypeId(model.getType());
|
||||
data.setLanguage(model.getLanguage());
|
||||
data.setStatus(model.getStatus());
|
||||
data.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(model.getDefinition())));
|
||||
|
||||
Long descriptionTemplateCodes = this.queryFactory.query(DescriptionTemplateQuery.class).disableTracking().codes(model.getCode()).count();
|
||||
if (descriptionTemplateCodes > 0) throw new MyValidationException(this.errors.getDescriptionTemplateCodeExists().getCode(), this.errors.getDescriptionTemplateCodeExists().getMessage());
|
||||
this.entityManager.persist(data);
|
||||
|
||||
this.persistUsers(data.getId(), model.getUsers());
|
||||
|
@ -786,7 +786,6 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic
|
|||
NewVersionDescriptionTemplatePersist persist = new NewVersionDescriptionTemplatePersist();
|
||||
persist.setId(latestVersionDescriptionTemplate.getId());
|
||||
persist.setLabel(label);
|
||||
persist.setCode(importXml.getCode());
|
||||
persist.setStatus(DescriptionTemplateStatus.Draft);
|
||||
persist.setDescription(importXml.getDescription());
|
||||
persist.setLanguage(importXml.getLanguage());
|
||||
|
|
|
@ -158,9 +158,9 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
|
|||
|
||||
ngOnInit(): void {
|
||||
this.analyticsService.trackPageView(AnalyticsService.DescriptionTemplateEditor);
|
||||
this.initModelFlags(this.route.snapshot.data['action']);
|
||||
super.ngOnInit();
|
||||
this.singleAutocompleteDescriptionTemplateTypeConfiguration = this.descriptionTemplateTypeService.getSingleAutocompleteConfiguration([DescriptionTemplateTypeStatus.Finalized]);
|
||||
this.initModelFlags(this.route.snapshot.data['action']);
|
||||
this.referenceTypeService.query(ReferenceTypeService.DefaultReferenceTypeLookup()).subscribe(referenceTypes => this.availableReferenceTypes = referenceTypes.items as ReferenceType[]); }
|
||||
|
||||
private initModelFlags(action: string): void {
|
||||
|
@ -211,7 +211,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
|
|||
}
|
||||
|
||||
buildForm() {
|
||||
this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !(this.authService.hasPermission(AppPermission.EditDescriptionTemplate) || this.item?.authorizationFlags?.some(x => x === AppPermission.EditDescriptionTemplate)));
|
||||
this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !(this.authService.hasPermission(AppPermission.EditDescriptionTemplate) || this.item?.authorizationFlags?.some(x => x === AppPermission.EditDescriptionTemplate)), (this.isNew || this.isClone));
|
||||
this.descriptionTemplateEditorService.setValidationErrorModel(this.editorModel.validationErrorModel);
|
||||
this.isFinalized = this.editorModel.status == DescriptionTemplateStatus.Finalized;
|
||||
if (this.isFinalized || this.isDeleted) {
|
||||
|
@ -220,6 +220,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
|
|||
const action = this.route.snapshot.data['action'];
|
||||
if (action && action == 'new-version') {
|
||||
this.formGroup.enable();
|
||||
this.formGroup.get('code').disable();
|
||||
this.formGroup.get('status').setValue(DescriptionTemplateStatus.Draft);
|
||||
}
|
||||
}
|
||||
|
@ -247,6 +248,7 @@ export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTe
|
|||
persistEntity(onSuccess?: (response) => void): void {
|
||||
if (this.isNewVersion == false) {
|
||||
const formData = this.formService.getValue(this.formGroup.value) as DescriptionTemplatePersist;
|
||||
formData.code = this.formGroup.get('code').getRawValue();
|
||||
|
||||
this.descriptionTemplateService.persist(formData)
|
||||
.pipe(takeUntil(this._destroyed)).subscribe(
|
||||
|
|
|
@ -45,13 +45,13 @@ export class DescriptionTemplateEditorModel extends BaseEditorModel implements D
|
|||
return this;
|
||||
}
|
||||
|
||||
buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup {
|
||||
buildForm(context: ValidationContext = null, disabled: boolean = false, isNewOrClone: boolean = false): UntypedFormGroup {
|
||||
if (context == null) { context = this.createValidationContext(); }
|
||||
|
||||
return this.formBuilder.group({
|
||||
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
|
||||
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
|
||||
code: [{ value: this.code, disabled: disabled }, context.getValidation('code').validators],
|
||||
code: [{ value: this.code, disabled: !isNewOrClone }, context.getValidation('code').validators],
|
||||
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
|
||||
language: [{ value: this.language, disabled: disabled }, context.getValidation('language').validators],
|
||||
type: [{ value: this.type, disabled: disabled }, context.getValidation('type').validators],
|
||||
|
|
Loading…
Reference in New Issue