-
Notifications
You must be signed in to change notification settings - Fork 10
Implement Use Case for Deaccession Dataset #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ofahimIQSS
merged 5 commits into
develop
from
246-implement-use-case-for-deaccession-a-dataset
Feb 14, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export interface DatasetDeaccessionDTO { | ||
| deaccessionReason: string | ||
| deaccessionForwardURL?: string | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { IDatasetsRepository } from '../repositories/IDatasetsRepository' | ||
| import { DatasetDeaccessionDTO } from '../dtos/DatasetDeaccessionDTO' | ||
| import { DatasetNotNumberedVersion } from '../models/DatasetNotNumberedVersion' | ||
|
|
||
| export class DeaccessionDataset implements UseCase<void> { | ||
| private datasetsRepository: IDatasetsRepository | ||
|
|
||
| constructor(datasetsRepository: IDatasetsRepository) { | ||
| this.datasetsRepository = datasetsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Deaccession a dataset, given a dataset id, a dataset version id, and a DatasetDeaccessionDTO object. | ||
| * @param {number | string} [datasetId] - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers). | ||
| * @param {string | DatasetNotNumberedVersion} [datasetVersionId] - The dataset version identifier, which can be a version-specific numeric string (for example, 1.0) or a DatasetNotNumberedVersion enum value. | ||
| * @returns A promise that resolves when the dataset is deaccessioned | ||
| * @throws An error if the dataset could not be deaccessioned | ||
| */ | ||
| async execute( | ||
| datasetId: number | string, | ||
| datasetVersionId: string | DatasetNotNumberedVersion, | ||
| DatasetDeaccessionDTO: DatasetDeaccessionDTO | ||
| ): Promise<void> { | ||
| return await this.datasetsRepository.deaccessionDataset( | ||
| datasetId, | ||
| datasetVersionId, | ||
| DatasetDeaccessionDTO | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| import { | ||
| deaccessionDataset, | ||
| DatasetDeaccessionDTO, | ||
| createDataset, | ||
| publishDataset, | ||
| VersionUpdateType | ||
| } from '../../../src/datasets' | ||
| import { ApiConfig, WriteError } from '../../../src' | ||
| import { TestConstants } from '../../testHelpers/TestConstants' | ||
| import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' | ||
| import { | ||
| waitForNoLocks, | ||
| deletePublishedDatasetViaApi, | ||
| deleteUnpublishedDatasetViaApi | ||
| } from '../../testHelpers/datasets/datasetHelper' | ||
|
|
||
| const testDataset = { | ||
| license: { | ||
| name: 'CC0 1.0', | ||
| uri: 'http://creativecommons.org/publicdomain/zero/1.0', | ||
| iconUri: 'https://licensebuttons.net/p/zero/1.0/88x31.png' | ||
| }, | ||
| metadataBlockValues: [ | ||
| { | ||
| name: 'citation', | ||
| fields: { | ||
| title: 'Dataset created using the createDataset use case', | ||
| author: [ | ||
| { | ||
| authorName: 'Admin, Dataverse', | ||
| authorAffiliation: 'Dataverse.org' | ||
| }, | ||
| { | ||
| authorName: 'Owner, Dataverse', | ||
| authorAffiliation: 'Dataversedemo.org' | ||
| } | ||
| ], | ||
| datasetContact: [ | ||
| { | ||
| datasetContactEmail: '[email protected]', | ||
| datasetContactName: 'Finch, Fiona' | ||
| } | ||
| ], | ||
| dsDescription: [ | ||
| { | ||
| dsDescriptionValue: 'This is the description of the dataset.' | ||
| } | ||
| ], | ||
| subject: ['Medicine, Health and Life Sciences'] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| describe('execute', () => { | ||
| beforeEach(async () => { | ||
| ApiConfig.init( | ||
| TestConstants.TEST_API_URL, | ||
| DataverseApiAuthMechanism.API_KEY, | ||
| process.env.TEST_API_KEY | ||
| ) | ||
| }) | ||
|
|
||
| test('should deaccession a dataset when required fields are sent', async () => { | ||
| const createdDatasetIdentifiers = await createDataset.execute(testDataset) | ||
|
|
||
| const response = await publishDataset.execute( | ||
| createdDatasetIdentifiers.persistentId, | ||
| VersionUpdateType.MAJOR | ||
| ) | ||
| await waitForNoLocks(createdDatasetIdentifiers.numericId, 10) | ||
|
|
||
| expect(response).toBeUndefined() | ||
|
|
||
| const testDeaccessionDatasetDTO: DatasetDeaccessionDTO = { | ||
| deaccessionReason: 'Description of the deaccession reason.', | ||
| deaccessionForwardURL: 'https://demo.dataverse.org' | ||
| } | ||
|
|
||
| const actual = await deaccessionDataset.execute( | ||
| createdDatasetIdentifiers.numericId, | ||
| '1.0', | ||
| testDeaccessionDatasetDTO | ||
| ) | ||
|
|
||
| expect(actual).toBeUndefined() | ||
|
|
||
| await deletePublishedDatasetViaApi(createdDatasetIdentifiers.persistentId) | ||
| }) | ||
|
|
||
| test('should throw an error when the dataset id is incorrect', async () => { | ||
| const createdDatasetIdentifiers = await createDataset.execute(testDataset) | ||
|
|
||
| const testDeaccessionDatasetDTO: DatasetDeaccessionDTO = { | ||
| deaccessionReason: 'Description of the deaccession reason.', | ||
| deaccessionForwardURL: 'https://demo.dataverse.org' | ||
| } | ||
|
|
||
| await expect( | ||
| deaccessionDataset.execute( | ||
| createdDatasetIdentifiers.numericId, | ||
| ':latest-published', | ||
| testDeaccessionDatasetDTO | ||
| ) | ||
| ).rejects.toThrow(Error) | ||
|
|
||
| await deleteUnpublishedDatasetViaApi(createdDatasetIdentifiers.numericId) | ||
| }) | ||
|
|
||
| test('should not deaccession a dataset when it is not published', async () => { | ||
| const createdDatasetIdentifiers = await createDataset.execute(testDataset) | ||
| const testDeaccessionDatasetDTO: DatasetDeaccessionDTO = { | ||
| deaccessionReason: 'Description of the deaccession reason.' | ||
| } | ||
|
|
||
| await expect( | ||
| deaccessionDataset.execute( | ||
| createdDatasetIdentifiers.numericId, | ||
| ':latest-published', | ||
| testDeaccessionDatasetDTO | ||
| ) | ||
| ).rejects.toBeInstanceOf(WriteError) | ||
|
|
||
| await deleteUnpublishedDatasetViaApi(createdDatasetIdentifiers.numericId) | ||
| }) | ||
|
|
||
| test('should not deaccession a dataset when it is deaccessioned once', async () => { | ||
| const createdDatasetIdentifiers = await createDataset.execute(testDataset) | ||
|
|
||
| const response = await publishDataset.execute( | ||
| createdDatasetIdentifiers.persistentId, | ||
| VersionUpdateType.MAJOR | ||
| ) | ||
| await waitForNoLocks(createdDatasetIdentifiers.numericId, 10) | ||
|
|
||
| expect(response).toBeUndefined() | ||
|
|
||
| const testDeaccessionDatasetDTO: DatasetDeaccessionDTO = { | ||
| deaccessionReason: 'Description of the deaccession reason.', | ||
| deaccessionForwardURL: 'https://demo.dataverse.org' | ||
| } | ||
|
|
||
| const actual = await deaccessionDataset.execute( | ||
| createdDatasetIdentifiers.numericId, | ||
| '1.0', | ||
| testDeaccessionDatasetDTO | ||
| ) | ||
|
|
||
| expect(actual).toBeUndefined() | ||
|
|
||
| await expect( | ||
| deaccessionDataset.execute( | ||
| createdDatasetIdentifiers.numericId, | ||
| '1.0', | ||
| testDeaccessionDatasetDTO | ||
| ) | ||
| ).rejects.toThrow(Error) | ||
|
|
||
| await deletePublishedDatasetViaApi(createdDatasetIdentifiers.persistentId) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.