From 44dccbd5c8c0c17fe054d5f78793eaafbcdc3240 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Mon, 6 Nov 2023 16:07:06 +0100 Subject: [PATCH] feat(IntegrationDatasetLocks): add integration with getDatasetLocks use case --- src/dataset/domain/models/Dataset.ts | 15 +++++------ .../infrastructure/mappers/JSDatasetMapper.ts | 19 ++++++++++--- .../DatasetJSDataverseRepository.ts | 27 ++++++++++++++----- .../DatasetJSDataverseRepository.spec.ts | 2 +- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/dataset/domain/models/Dataset.ts b/src/dataset/domain/models/Dataset.ts index 409a7ab5e..497947c21 100644 --- a/src/dataset/domain/models/Dataset.ts +++ b/src/dataset/domain/models/Dataset.ts @@ -264,15 +264,14 @@ export interface DatasetLock { } export enum DatasetLockReason { - INGEST = 'ingest', - WORKFLOW = 'workflow', - IN_REVIEW = 'inReview', - DCM_UPLOAD = 'dcmUpload', - GLOBUS_UPLOAD = 'globusUpload', + INGEST = 'Ingest', + WORKFLOW = 'Workflow', + IN_REVIEW = 'InReview', + DCM_UPLOAD = 'DcmUpload', + GLOBUS_UPLOAD = 'GlobusUpload', FINALIZE_PUBLICATION = 'finalizePublication', - - EDIT_IN_PROGRESS = 'editInProgress', - FILE_VALIDATION_FAILED = 'fileValidationFailed' + EDIT_IN_PROGRESS = 'EditInProgress', + FILE_VALIDATION_FAILED = 'FileValidationFailed' } export interface PrivateUrl { diff --git a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts index 77a8c3031..049055037 100644 --- a/src/dataset/infrastructure/mappers/JSDatasetMapper.ts +++ b/src/dataset/infrastructure/mappers/JSDatasetMapper.ts @@ -3,7 +3,8 @@ import { DatasetMetadataBlock as JSDatasetMetadataBlock, DatasetMetadataBlocks as JSDatasetMetadataBlocks, DatasetMetadataFields as JSDatasetMetadataFields, - DatasetVersionInfo as JSDatasetVersionInfo + DatasetVersionInfo as JSDatasetVersionInfo, + DatasetLock as JSDatasetLock } from '@iqss/dataverse-client-javascript' import { DatasetVersionState as JSDatasetVersionState } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset' import { @@ -14,7 +15,9 @@ import { DatasetMetadataFields, DatasetVersion, MetadataBlockName, - PrivateUrl + PrivateUrl, + DatasetLock, + DatasetLockReason } from '../../domain/models/Dataset' export class JSDatasetMapper { @@ -22,6 +25,7 @@ export class JSDatasetMapper { jsDataset: JSDataset, citation: string, summaryFieldsNames: string[], + jsDatasetLocks: JSDatasetLock[], requestedVersion?: string, privateUrl?: PrivateUrl ): Dataset { @@ -45,7 +49,7 @@ export class JSDatasetMapper { canManageFilesPermissions: true, canDeleteDataset: true }, // TODO Connect with dataset permissions - [], // TODO Connect with dataset locks + JSDatasetMapper.toLocks(jsDatasetLocks), true, // TODO Connect with dataset hasValidTermsOfAccess true, // TODO Connect with dataset isValid jsDataset.versionInfo.releaseTime !== undefined && @@ -185,4 +189,13 @@ export class JSDatasetMapper { return extraFields } + + static toLocks(jsDatasetLocks: JSDatasetLock[]): DatasetLock[] { + return jsDatasetLocks.map((jsDatasetLock) => { + return { + id: 0, + reason: jsDatasetLock.lockType as unknown as DatasetLockReason + } + }) + } } diff --git a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts index c3fc7fbf0..239724296 100644 --- a/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts +++ b/src/dataset/infrastructure/repositories/DatasetJSDataverseRepository.ts @@ -7,7 +7,9 @@ import { Dataset as JSDataset, getPrivateUrlDataset, getPrivateUrlDatasetCitation, - ReadError + ReadError, + getDatasetLocks, + DatasetLock as JSDatasetLock } from '@iqss/dataverse-client-javascript' import { JSDatasetMapper } from '../mappers/JSDatasetMapper' @@ -23,11 +25,24 @@ export class DatasetJSDataverseRepository implements DatasetRepository { Promise.all([ jsDataset, getDatasetSummaryFieldNames.execute(), - getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)) + getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)), + getDatasetLocks.execute(jsDataset.id) ]) ) - .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => - JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, requestedVersion) + .then( + ([jsDataset, summaryFieldsNames, citation, jsDatasetLocks]: [ + JSDataset, + string[], + string, + JSDatasetLock[] + ]) => + JSDatasetMapper.toDataset( + jsDataset, + citation, + summaryFieldsNames, + jsDatasetLocks, + requestedVersion + ) ) .catch((error: ReadError) => { if (!version) { @@ -42,9 +57,9 @@ export class DatasetJSDataverseRepository implements DatasetRepository { getPrivateUrlDataset.execute(privateUrlToken), getDatasetSummaryFieldNames.execute(), getPrivateUrlDatasetCitation.execute(privateUrlToken) - ]) + ]) // TODO - Add getDatasetLocks.execute(privateUrlToken) when it is available in js-dataverse .then(([jsDataset, summaryFieldsNames, citation]: [JSDataset, string[], string]) => - JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, undefined) + JSDatasetMapper.toDataset(jsDataset, citation, summaryFieldsNames, []) ) .catch((error: ReadError) => { throw new Error(error.message) diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index 99a2b163b..ae8ee219f 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -196,7 +196,7 @@ describe('Dataset JSDataverse Repository', () => { }) }) - it('gets the dataset when is locked', async () => { + it('gets the dataset by persistentId when is locked', async () => { const datasetResponse = await DatasetHelper.create() await DatasetHelper.lock(datasetResponse.id, DatasetLockReason.FINALIZE_PUBLICATION)