-
Notifications
You must be signed in to change notification settings - Fork 11
Add linkCollection, unlinkCollection and getCollectionLinks use cases #346
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
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f199086
add linkCollection and unlinkCollection use cases
ekraffmiller 548ca2c
add functional tests
ekraffmiller 9db4c47
use consistent names for UnlinkCollection
ekraffmiller 380dedc
fix import
ekraffmiller ed2ebf3
fix roles test data
ekraffmiller 2f24d32
add GetCollectionLinks use case
ekraffmiller c2564a1
remove console.log()
ekraffmiller 1d78fbb
remove .DS_Store
ekraffmiller 3a969cb
Remove remaining .DS_Store file
ekraffmiller c439f93
add GetCollectionLinks to index.ts
ekraffmiller 8d47d04
fix string for API url, update unit UnlinkCollection test
ekraffmiller b9d0422
Update LinkCollection.test.ts
ekraffmiller 14e7968
fix test description
ekraffmiller eb2925b
resolve merge conflicts
ekraffmiller 396c348
fix integrations
ekraffmiller 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { CollectionSummary } from './CollectionSummary' | ||
| import { DatasetSummary } from '../../../datasets/domain/models/DatasetSummary' | ||
|
|
||
| export interface CollectionLinks { | ||
| linkedCollections: CollectionSummary[] | ||
| collectionsLinkingToThis: CollectionSummary[] | ||
| linkedDatasets: DatasetSummary[] | ||
| } |
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,5 @@ | ||
| export interface CollectionSummary { | ||
|
g-saracca marked this conversation as resolved.
|
||
| id: number | ||
| alias: string | ||
| displayName: 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,22 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { ICollectionsRepository } from '../repositories/ICollectionsRepository' | ||
| import { CollectionLinks } from '../models/CollectionLinks' | ||
|
|
||
| export class GetCollectionItems implements UseCase<CollectionLinks> { | ||
| private collectionsRepository: ICollectionsRepository | ||
|
|
||
| constructor(collectionsRepository: ICollectionsRepository) { | ||
| this.collectionsRepository = collectionsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Returns a CollectionLinks object containing other collections this collection is linked to, the other collections linking to this collection, and datasets linked to this collection, given the collection identifier or alias. | ||
| * | ||
| * @param {number | string} [collectionIdOrAlias] - A generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId) | ||
| * If this parameter is not set, the default value is: ':root' | ||
| * @returns {Promise<CollectionLinks>} | ||
| */ | ||
| async execute(collectionId: number | string): Promise<CollectionLinks> { | ||
| return await this.collectionsRepository.getCollectionLinks(collectionId) | ||
| } | ||
| } |
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,27 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { ICollectionsRepository } from '../repositories/ICollectionsRepository' | ||
|
|
||
| export class LinkCollection implements UseCase<void> { | ||
| private collectionsRepository: ICollectionsRepository | ||
|
|
||
| constructor(collectionsRepository: ICollectionsRepository) { | ||
| this.collectionsRepository = collectionsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Deletes the Dataverse collection whose database ID or alias is given: | ||
|
g-saracca marked this conversation as resolved.
Outdated
|
||
| * | ||
| * @param {number| string} [linkedCollectionIdOrAlias] - The collection to be linked. Can be either a string (collection alias), or a number (collection id) | ||
| * @param { number | string} [linkingCollectionIdOrAlias] - The collection that will be linking to the linked collection. Can be either a string (collection alias), or a number (collection id) | ||
| * @returns {Promise<void>} -This method does not return anything upon successful completion. | ||
| */ | ||
| async execute( | ||
| linkedCollectionIdOrAlias: number | string, | ||
| linkingCollectionIdOrAlias: number | string | ||
| ): Promise<void> { | ||
| return await this.collectionsRepository.linkCollection( | ||
| linkedCollectionIdOrAlias, | ||
| linkingCollectionIdOrAlias | ||
| ) | ||
| } | ||
| } | ||
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,27 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { ICollectionsRepository } from '../repositories/ICollectionsRepository' | ||
|
|
||
| export class UnlinkCollection implements UseCase<void> { | ||
| private collectionsRepository: ICollectionsRepository | ||
|
|
||
| constructor(collectionsRepository: ICollectionsRepository) { | ||
| this.collectionsRepository = collectionsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Unlinks a collection from the collection that links to it | ||
| * | ||
| * @param {number| string} [linkedCollectionIdOrAlias] - The collection that is linked. Can be either a string (collection alias), or a number (collection id) | ||
| * @param { number | string} [linkingCollectionIdOrAlias] - The collection that links to the linked collection. Can be either a string (collection alias), or a number (collection id) | ||
| * @returns {Promise<void>} -This method does not return anything upon successful completion. | ||
| */ | ||
| async execute( | ||
| linkedCollectionIdOrAlias: number | string, | ||
| linkingCollectionIdOrAlias: number | string | ||
| ): Promise<void> { | ||
| return await this.collectionsRepository.unlinkCollection( | ||
| linkedCollectionIdOrAlias, | ||
| linkingCollectionIdOrAlias | ||
| ) | ||
| } | ||
| } |
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
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 DatasetSummary { | ||
| persistentId: string | ||
| title: string | ||
| } |
|
g-saracca marked this conversation as resolved.
Outdated
|
Binary file not shown.
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| POSTGRES_VERSION=17 | ||
| DATAVERSE_DB_USER=dataverse | ||
| SOLR_VERSION=9.8.0 | ||
| DATAVERSE_IMAGE_REGISTRY=docker.io | ||
| DATAVERSE_IMAGE_TAG=unstable | ||
| DATAVERSE_IMAGE_REGISTRY=ghcr.io | ||
|
g-saracca marked this conversation as resolved.
Outdated
|
||
| DATAVERSE_IMAGE_TAG=11724-extend-list-dataverse-collection-links | ||
| DATAVERSE_BOOTSTRAP_TIMEOUT=5m | ||
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,79 @@ | ||
| import { | ||
| ApiConfig, | ||
| WriteError, | ||
| createCollection, | ||
| getCollection, | ||
| linkCollection, | ||
| deleteCollection, | ||
| getCollectionItems | ||
| } from '../../../src' | ||
| import { TestConstants } from '../../testHelpers/TestConstants' | ||
| import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' | ||
| import { createCollectionDTO } from '../../testHelpers/collections/collectionHelper' | ||
|
|
||
| describe('execute', () => { | ||
| const firstCollectionAlias = 'linkCollection-functional-test-first' | ||
| const secondCollectionAlias = 'linkCollection-functional-test-second' | ||
|
|
||
| beforeEach(async () => { | ||
| ApiConfig.init( | ||
| TestConstants.TEST_API_URL, | ||
| DataverseApiAuthMechanism.API_KEY, | ||
| process.env.TEST_API_KEY | ||
| ) | ||
| const firstCollection = createCollectionDTO(firstCollectionAlias) | ||
| const secondCollection = createCollectionDTO(secondCollectionAlias) | ||
| await createCollection.execute(firstCollection) | ||
| await createCollection.execute(secondCollection) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all([ | ||
|
g-saracca marked this conversation as resolved.
|
||
| getCollection | ||
| .execute(firstCollectionAlias) | ||
| .then((collection) => | ||
| collection && collection.id ? deleteCollection.execute(collection.id) : null | ||
| ), | ||
| getCollection | ||
| .execute(secondCollectionAlias) | ||
| .then((collection) => | ||
| collection && collection.id ? deleteCollection.execute(collection.id) : null | ||
| ) | ||
| ]) | ||
| }) | ||
|
|
||
| test('should successfully link two collections', async () => { | ||
| const firstCollection = await getCollection.execute(firstCollectionAlias) | ||
| const secondCollection = await getCollection.execute(secondCollectionAlias) | ||
| expect.assertions(1) | ||
| try { | ||
| await linkCollection.execute(secondCollection.alias, firstCollection.alias) | ||
| } catch (error) { | ||
| throw new Error('Collections should be linked successfully') | ||
| } finally { | ||
| await new Promise((resolve) => setTimeout(resolve, 5000)) | ||
|
g-saracca marked this conversation as resolved.
|
||
| const collectionItemSubset = await getCollectionItems.execute(firstCollectionAlias) | ||
|
|
||
| expect(collectionItemSubset.items.length).toBe(1) | ||
| } | ||
| }) | ||
|
|
||
| test('should throw an error when linking a non-existent collection', async () => { | ||
| const invalidCollectionId = 99999 | ||
| const firstCollection = await getCollection.execute(firstCollectionAlias) | ||
|
|
||
| expect.assertions(2) | ||
| let writeError: WriteError | undefined = undefined | ||
| try { | ||
| await linkCollection.execute(invalidCollectionId, firstCollection.id) | ||
| throw new Error('Use case should throw an error') | ||
| } catch (error) { | ||
| writeError = error as WriteError | ||
| } finally { | ||
| expect(writeError).toBeInstanceOf(WriteError) | ||
| expect(writeError?.message).toEqual( | ||
| `There was an error when writing the resource. Reason was: [404] Can't find dataverse with identifier='${invalidCollectionId}'` | ||
| ) | ||
| } | ||
| }) | ||
| }) | ||
Oops, something went wrong.
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.