Skip to content

Commit

Permalink
feat(IntegrationDatasetLocks): add integration with getDatasetLocks u…
Browse files Browse the repository at this point in the history
…se case
  • Loading branch information
MellyGray committed Nov 6, 2023
1 parent 971a32e commit 44dccbd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
15 changes: 7 additions & 8 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 16 additions & 3 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,14 +15,17 @@ import {
DatasetMetadataFields,
DatasetVersion,
MetadataBlockName,
PrivateUrl
PrivateUrl,
DatasetLock,
DatasetLockReason
} from '../../domain/models/Dataset'

export class JSDatasetMapper {
static toDataset(
jsDataset: JSDataset,
citation: string,
summaryFieldsNames: string[],
jsDatasetLocks: JSDatasetLock[],
requestedVersion?: string,
privateUrl?: PrivateUrl
): Dataset {
Expand All @@ -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 &&
Expand Down Expand Up @@ -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
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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) {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 44dccbd

Please sign in to comment.