From 5523ca2fe12261b6eac6fb8b615ceb42abca6d02 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Tue, 9 Apr 2024 13:19:32 +0300 Subject: [PATCH] description template update --- .../description/DescriptionServiceImpl.java | 4 ++-- .../description-template.ts | 2 ++ ...escription-base-fields-editor.component.ts | 19 +++++++++++++------ .../editor/description-editor.resolver.ts | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java index a8ba4aea7..cafc6e353 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/description/DescriptionServiceImpl.java @@ -262,8 +262,8 @@ public class DescriptionServiceImpl implements DescriptionService { throw new MyValidationException("New version not found"); if (latestVersionDescriptionTemplates.size() > 1) throw new MyValidationException("Multiple template found"); - if (!latestVersionDescriptionTemplates.getFirst().getVersion().equals(oldDescriptionTemplateEntity.getVersion())) - throw new MyValidationException(this.errors.getDescriptionTemplateNewVersionConflict().getCode(), this.errors.getDescriptionTemplateNewVersionConflict().getMessage()); + if (latestVersionDescriptionTemplates.getFirst().getVersion().equals(oldDescriptionTemplateEntity.getVersion())) + throw new MyValidationException("Description already upgraded"); data.setDescriptionTemplateId(latestVersionDescriptionTemplates.getFirst().getId()); diff --git a/dmp-frontend/src/app/core/model/description-template/description-template.ts b/dmp-frontend/src/app/core/model/description-template/description-template.ts index 5ee58d1d5..09204149f 100644 --- a/dmp-frontend/src/app/core/model/description-template/description-template.ts +++ b/dmp-frontend/src/app/core/model/description-template/description-template.ts @@ -9,6 +9,7 @@ import { DescriptionTemplateType } from "../description-template-type/descriptio import { ReferenceType } from "../reference-type/reference-type"; import { User } from "../user/user"; import { Reference } from "../reference/reference"; +import { DescriptionTemplateVersionStatus } from "@app/core/common/enum/description-template-version-status"; export interface DescriptionTemplate extends BaseEntity { @@ -21,6 +22,7 @@ export interface DescriptionTemplate extends BaseEntity { status?: DescriptionTemplateStatus; definition?: DescriptionTemplateDefinition; users?: UserDescriptionTemplate[]; + versionStatus?: DescriptionTemplateVersionStatus; } export interface UserDescriptionTemplate extends BaseEntity { diff --git a/dmp-frontend/src/app/ui/description/editor/description-base-fields-editor/description-base-fields-editor.component.ts b/dmp-frontend/src/app/ui/description/editor/description-base-fields-editor/description-base-fields-editor.component.ts index f165eff8c..00de84df9 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-base-fields-editor/description-base-fields-editor.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-base-fields-editor/description-base-fields-editor.component.ts @@ -12,6 +12,8 @@ import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.servic import { BaseComponent } from '@common/base/base.component'; import { takeUntil } from 'rxjs/operators'; import { DeprecatedDescriptionTemplateDialog } from './dialog-description-template/deprecated-description-template-dialog.component'; +import { DescriptionTemplateVersionStatus } from '@app/core/common/enum/description-template-version-status'; +import { DescriptionStatus } from '@app/core/common/enum/description-status'; @Component({ selector: 'app-description-base-fields-editor-component', @@ -41,17 +43,22 @@ export class DescriptionBaseFieldsEditorComponent extends BaseComponent { } private loadDescriptionTemplates(): void { - const dmpDescriptionTemplates: DmpDescriptionTemplate[] = this.description.dmp.dmpDescriptionTemplates.filter(x => x.sectionId == this.description.dmpDescriptionTemplate.sectionId && x.isActive == IsActive.Active); - const currentVersionsOfDescriptionTemplates = dmpDescriptionTemplates.map(x => x.currentDescriptionTemplate); - //Check if the used tempalte in included in the current list. If not add it. - if (this.description.descriptionTemplate && currentVersionsOfDescriptionTemplates.find(x => x.id == this.description?.descriptionTemplate?.id) == null) { - if (this.description.status === 0) { + const isPreviousVersion: boolean = this.description.descriptionTemplate.versionStatus === DescriptionTemplateVersionStatus.Previous; + if (isPreviousVersion === true) { + if (this.description.status === DescriptionStatus.Draft) { this.openDeprecatedDescriptionTemplateDialog(); } else { this.availableDescriptionTemplates.push(this.description.descriptionTemplate); } + } else { + this.availableDescriptionTemplates.push(this.description.descriptionTemplate); } - this.availableDescriptionTemplates.push(...currentVersionsOfDescriptionTemplates); + + + // const dmpDescriptionTemplates: DmpDescriptionTemplate[] = this.description.dmp.dmpDescriptionTemplates.filter(x => x.sectionId == this.description.dmpDescriptionTemplate.sectionId && x.isActive == IsActive.Active); + // // const currentVersionsOfDescriptionTemplates = dmpDescriptionTemplates.map(x => x.currentDescriptionTemplate); + // //Check if the used tempalte in included in the current list. If not add it. + // this.availableDescriptionTemplates.push(...currentVersionsOfDescriptionTemplates); } private openDeprecatedDescriptionTemplateDialog(): void { diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts index 64e8c0459..1f976230b 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.resolver.ts @@ -95,6 +95,7 @@ export class DescriptionEditorResolver extends BaseEditorResolver { (prefix ? prefix + '.' : '') + [nameof(x => x.id)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.label)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.version)].join('.'), + (prefix ? prefix + '.' : '') + [nameof(x => x.versionStatus)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.groupId)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.isActive)].join('.'), (prefix ? prefix + '.' : '') + [nameof(x => x.definition), nameof(x => x.pages), nameof(x => x.id)].join('.'),