From 2a00fe7ec1a7242234a1bea9ebadcbdf45f66831 Mon Sep 17 00:00:00 2001 From: amentis Date: Mon, 11 Dec 2023 18:55:20 +0200 Subject: [PATCH] change lock service --- .../app/core/services/lock/lock.service.ts | 8 ++++---- .../dataset-wizard.component.ts | 6 +++--- .../dataset-listing-item.component.ts | 3 ++- .../overview/dataset-overview.component.ts | 3 ++- .../description-listing-item.component.ts | 2 +- .../dmp-editor-blueprint.component.ts | 20 ++++++++++++------- .../app/ui/dmp/editor/dmp-editor.component.ts | 4 ++-- .../dmp-listing-item.component.ts | 2 +- .../ui/dmp/overview/dmp-overview.component.ts | 2 +- 9 files changed, 29 insertions(+), 21 deletions(-) diff --git a/dmp-frontend/src/app/core/services/lock/lock.service.ts b/dmp-frontend/src/app/core/services/lock/lock.service.ts index e939cb1ce..42b5d16d2 100644 --- a/dmp-frontend/src/app/core/services/lock/lock.service.ts +++ b/dmp-frontend/src/app/core/services/lock/lock.service.ts @@ -51,13 +51,13 @@ export class LockService { } //ToDo change Parameters - checkLockStatus(id: string): Observable { - return this.http.get(`${this.apiBase}/target/status/${id}`, { headers: this.headers }); + checkLockStatus(targetId: Guid): Observable { + return this.http.get(`${this.apiBase}/target/status/${targetId}`, { headers: this.headers }); } //ToDo change Parameters - unlockTarget(id: string): Observable { - return this.http.delete(`${this.apiBase}/target/unlock/${id}`, { headers: this.headers }); + unlockTarget(targetId: Guid): Observable { + return this.http.delete(`${this.apiBase}/target/unlock/${targetId}`, { headers: this.headers }); } getSingleWithTarget(targetId: Guid, reqFields: string[] = []): Observable { diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index baec1c2d3..0bc56e515 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -197,7 +197,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme this.datasetWizardService.getSingle(this.itemId) .pipe(takeUntil(this._destroyed)) .subscribe(data => { - this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { + this.lockService.checkLockStatus(Guid.parse(data.id)).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { this.lockStatus = lockStatus; this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); this.dmpSectionIndex = this.datasetWizardModel.dmpSectionIndex; @@ -343,7 +343,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme this.datasetWizardService.getSingle(this.itemId) .pipe(takeUntil(this._destroyed)) .subscribe(data => { - this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { + this.lockService.checkLockStatus(Guid.parse(data.id)).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { this.lockStatus = lockStatus; this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data); this.dmpSectionIndex = this.datasetWizardModel.dmpSectionIndex; @@ -610,7 +610,7 @@ export class DatasetWizardComponent extends CheckDeactivateBaseComponent impleme public cancel(): void { if (!isNullOrUndefined(this.lock)) { - this.lockService.unlockTarget(this.datasetWizardModel.id).pipe(takeUntil(this._destroyed)).subscribe( + this.lockService.unlockTarget(Guid.parse(this.datasetWizardModel.id)).pipe(takeUntil(this._destroyed)).subscribe( complete => { this.publicMode ? this.router.navigate(['/explore-descriptions']) : this.router.navigate(['/datasets']); }, diff --git a/dmp-frontend/src/app/ui/dataset/listing/listing-item/dataset-listing-item.component.ts b/dmp-frontend/src/app/ui/dataset/listing/listing-item/dataset-listing-item.component.ts index da184bdb4..2b3aded48 100644 --- a/dmp-frontend/src/app/ui/dataset/listing/listing-item/dataset-listing-item.component.ts +++ b/dmp-frontend/src/app/ui/dataset/listing/listing-item/dataset-listing-item.component.ts @@ -21,6 +21,7 @@ import { takeUntil } from 'rxjs/operators'; import { DatasetStatus } from '../../../../core/common/enum/dataset-status'; import { DatasetListingModel } from '../../../../core/model/dataset/dataset-listing'; import { DatasetCopyDialogueComponent } from '../../dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component'; +import { Guid } from '@common/types/guid'; @Component({ selector: 'app-dataset-listing-item-component', @@ -168,7 +169,7 @@ export class DatasetListingItemComponent extends BaseComponent implements OnInit } deleteClicked(id: string) { - this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed)) + this.lockService.checkLockStatus(Guid.parse(id)).pipe(takeUntil(this._destroyed)) .subscribe(lockStatus => { if (!lockStatus) { this.openDeleteDialog(id); diff --git a/dmp-frontend/src/app/ui/dataset/overview/dataset-overview.component.ts b/dmp-frontend/src/app/ui/dataset/overview/dataset-overview.component.ts index 9c372d3ab..5fcb6c281 100644 --- a/dmp-frontend/src/app/ui/dataset/overview/dataset-overview.component.ts +++ b/dmp-frontend/src/app/ui/dataset/overview/dataset-overview.component.ts @@ -32,6 +32,7 @@ import { TranslateService } from '@ngx-translate/core'; import * as FileSaver from 'file-saver'; import { filter, takeUntil } from 'rxjs/operators'; import { DatasetCopyDialogueComponent } from '../dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component'; +import { Guid } from '@common/types/guid'; @Component({ @@ -137,7 +138,7 @@ export class DatasetOverviewComponent extends BaseComponent implements OnInit { } checkLockStatus(id: string) { - this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed)) + this.lockService.checkLockStatus(Guid.parse(id)).pipe(takeUntil(this._destroyed)) .subscribe(lockStatus => { this.lockStatus = lockStatus if (lockStatus) { diff --git a/dmp-frontend/src/app/ui/description/listing/listing-item/description-listing-item.component.ts b/dmp-frontend/src/app/ui/description/listing/listing-item/description-listing-item.component.ts index 96ad20b29..68dfe4c74 100644 --- a/dmp-frontend/src/app/ui/description/listing/listing-item/description-listing-item.component.ts +++ b/dmp-frontend/src/app/ui/description/listing/listing-item/description-listing-item.component.ts @@ -181,7 +181,7 @@ export class DescriptionListingItemComponent extends BaseComponent implements On } deleteClicked(id: Guid) { - this.lockService.checkLockStatus(id.toString()).pipe(takeUntil(this._destroyed)) + this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed)) .subscribe(lockStatus => { if (!lockStatus) { this.openDeleteDialog(id); diff --git a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.ts b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.ts index 550e9ad5d..d0c6b6c0a 100644 --- a/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.ts +++ b/dmp-frontend/src/app/ui/dmp/dmp-editor-blueprint/dmp-editor-blueprint.component.ts @@ -16,7 +16,7 @@ import { DmpDatasetProfile } from '@app/core/model/dmp/dmp-dataset-profile/dmp-d import { DmpDatasetProfileSectionsFormModel } from '@app/core/model/dmp/dmp-dataset-profile/dmp-dataset-profile-sections-form.model'; import { ExternalSourceItemModel } from '@app/core/model/external-sources/external-source-item'; import { LanguageInfo } from '@app/core/model/language-info'; -import { LockModel } from '@app/core/model/lock/lock.model'; +import { Lock, LockPersist } from '@app/core/model/lock/lock.model'; import { UserModel } from '@app/core/model/user/user'; import { UserInfoListingModel } from '@app/core/model/user/user-info-listing'; import { DatasetProfileCriteria } from '@app/core/query/dataset-profile/dataset-profile-criteria'; @@ -58,6 +58,7 @@ import { ProjectFormModel } from '../editor/grant-tab/project-form-model'; import { ReferenceSearchDefinitionLookup, ReferenceSearchLookup } from '@app/core/query/reference-search.lookup'; import { Reference } from '@app/core/model/reference/reference'; import { ReferenceTypeEditorResolver } from '@app/ui/admin/reference-type/editor/reference-type-editor.resolver'; +import { LockTargetType } from '@app/core/common/enum/lock-target-type'; interface Visible { value: boolean; @@ -99,7 +100,8 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im associatedUsers: Array; people: Array; - lock: LockModel; + lock: Lock; + lockPersist: LockPersist; lockStatus: Boolean = false; step: number = 0; @@ -181,7 +183,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im this.dmpService.getSingle(itemId).pipe(map(data => data as DmpModel)) .pipe(takeUntil(this._destroyed)) .subscribe(async data => { - this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { + this.lockService.checkLockStatus(Guid.parse(data.id)).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { this.lockStatus = lockStatus; this.dmp = new DmpEditorModel(); @@ -228,10 +230,14 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im if (this.authService.currentAccountIsAuthenticated()) { if (!lockStatus) { - this.lock = new LockModel(data.id, this.getUserFromDMP()); + const persist : LockPersist = null; + persist.target = Guid.parse(data.id); + persist.targetType = LockTargetType.Dmp; + persist.lockedBy = this.getUserFromDMP(); + // this.lock = new LockModel(data.id, this.getUserFromDMP()); - this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => { - this.lock.id = Guid.parse(result); + this.lockService.persist(persist).pipe(takeUntil(this._destroyed)).subscribe(async result => { + this.lock = result; interval(this.configurationService.lockInterval).pipe(takeUntil(this._destroyed)).subscribe(() => this.pumpLock()); }); } @@ -351,7 +357,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im private pumpLock() { this.lock.touchedAt = new Date(); - this.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => this.lock.id = Guid.parse(result)); + //his.lockService.createOrUpdate(this.lock).pipe(takeUntil(this._destroyed)).subscribe(async result => this.lock.id = Guid.parse(result)); } public isDirty(): boolean { diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts index 2027b0c2c..26e39daba 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts @@ -159,7 +159,7 @@ export class DmpEditorComponent extends CheckDeactivateBaseComponent implements this.dmpService.getSingle(itemId).pipe(map(data => data as DmpModel)) .pipe(takeUntil(this._destroyed)) .subscribe(async data => { - this.lockService.checkLockStatus(data.id).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { + this.lockService.checkLockStatus(Guid.parse(data.id)).pipe(takeUntil(this._destroyed)).subscribe(lockStatus => { this.lockStatus = lockStatus; this.dmpModel = data; @@ -591,7 +591,7 @@ export class DmpEditorComponent extends CheckDeactivateBaseComponent implements public cancel(id: String): void { if (id != null) { - this.lockService.unlockTarget(this.dmp.id).pipe(takeUntil(this._destroyed)).subscribe( + this.lockService.unlockTarget(Guid.parse(this.dmp.id)).pipe(takeUntil(this._destroyed)).subscribe( complete => { this.router.navigate(['/plans/overview/' + id]); }, diff --git a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts index 626781a5b..1e1a282ae 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts @@ -237,7 +237,7 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { // } deleteClicked(id: Guid) { - this.lockService.checkLockStatus(id.toString()).pipe(takeUntil(this._destroyed)) + this.lockService.checkLockStatus(Guid.parse(id.toString())).pipe(takeUntil(this._destroyed)) .subscribe(lockStatus => { if (!lockStatus) { this.openDeleteDialog(id); diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts index b19a74a90..7e64784ac 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts @@ -695,7 +695,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { } checkLockStatus(id: Guid) { - this.lockService.checkLockStatus(id.toString()).pipe(takeUntil(this._destroyed)) + this.lockService.checkLockStatus(Guid.parse(id.toString())).pipe(takeUntil(this._destroyed)) .subscribe(lockStatus => { this.lockStatus = lockStatus if (lockStatus) {