-
Notifications
You must be signed in to change notification settings - Fork 11
Use Case for File Citation Formats #446
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
ekraffmiller
merged 12 commits into
develop
from
436-use-cases-of-get-file-citation-in-other-formats
Jun 9, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6ed4802
feat: fileCitationFile use case
ChengShi-1 7f43508
fix: useCases.md
ChengShi-1 4b3c456
Update test/environment/.env
ChengShi-1 2424be9
update collectionHelper.ts
ChengShi-1 56b9609
Merge branch '436-use-cases-of-get-file-citation-in-other-formats' of…
ChengShi-1 9720559
Merge branch 'develop' into 436-use-cases-of-get-file-citation-in-oth…
ChengShi-1 a787da9
update tests for the MyData api fix
ChengShi-1 083719a
Revert "update tests for the MyData api fix"
ChengShi-1 8428aae
Merge branch 'develop' into 436-use-cases-of-get-file-citation-in-oth…
ChengShi-1 faf2b42
fix: add a test of using pId
ChengShi-1 71555f6
fix: npm lint
ChengShi-1 5b2ee6c
Update docs/useCases.md
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
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,7 @@ | ||
| export enum FileCitationFormat { | ||
| ENDNOTE = 'EndNote', | ||
| RIS = 'RIS', | ||
| BIBTEX = 'BibTeX', | ||
| CSL = 'CSL', | ||
| INTERNAL = 'Internal' | ||
| } |
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 { IFilesRepository } from '../repositories/IFilesRepository' | ||
| import { FileCitationFormat } from '../models/FileCitationFormat' | ||
|
|
||
| export class GetFileCitationByFormat implements UseCase<string> { | ||
| private filesRepository: IFilesRepository | ||
|
|
||
| constructor(filesRepository: IFilesRepository) { | ||
| this.filesRepository = filesRepository | ||
| } | ||
|
|
||
| /** | ||
| * Returns the File citation in the requested format (EndNote XML, RIS, BibTeX, CSL JSON, or Internal HTML). | ||
| * | ||
| * @param {number | string} [fileId] - The File identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers). | ||
| * @param {FileCitationFormat} [format] - The citation format to return. | ||
| * @returns {Promise<string>} | ||
| */ | ||
| async execute(fileId: number | string, format: FileCitationFormat): Promise<string> { | ||
| return await this.filesRepository.getFileCitationByFormat(fileId, format) | ||
| } | ||
| } |
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,123 @@ | ||
| import { | ||
| ApiConfig, | ||
| createDataset, | ||
| CreatedDatasetIdentifiers, | ||
| FileCitationFormat, | ||
| getDatasetFiles, | ||
| getFileCitationByFormat, | ||
| ReadError | ||
| } from '../../../src' | ||
| import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' | ||
| import { | ||
| createCollectionViaApi, | ||
| deleteCollectionViaApi | ||
| } from '../../testHelpers/collections/collectionHelper' | ||
| import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper' | ||
| import { uploadFileViaApi } from '../../testHelpers/files/filesHelper' | ||
| import { TestConstants } from '../../testHelpers/TestConstants' | ||
|
|
||
| describe('execute', () => { | ||
| const testCollectionAlias = 'getFileCitationByFormatFunctionalTest' | ||
| const testTextFile1Name = 'test-file-1.txt' | ||
| let testDatasetIds: CreatedDatasetIdentifiers | ||
|
|
||
| beforeAll(async () => { | ||
| ApiConfig.init( | ||
| TestConstants.TEST_API_URL, | ||
| DataverseApiAuthMechanism.API_KEY, | ||
| process.env.TEST_API_KEY | ||
| ) | ||
| await createCollectionViaApi(testCollectionAlias) | ||
|
|
||
| try { | ||
| testDatasetIds = await createDataset.execute( | ||
| TestConstants.TEST_NEW_DATASET_DTO, | ||
| testCollectionAlias | ||
| ) | ||
| } catch (error) { | ||
| throw new Error('Tests beforeAll(): Error while creating test dataset') | ||
| } | ||
|
|
||
| await uploadFileViaApi(testDatasetIds.numericId, testTextFile1Name).catch(() => { | ||
| throw new Error(`Tests beforeAll(): Error while uploading file ${testTextFile1Name}`) | ||
| }) | ||
| }) | ||
|
|
||
| afterAll(async () => { | ||
| try { | ||
| await deleteUnpublishedDatasetViaApi(testDatasetIds.numericId) | ||
| } catch (error) { | ||
| throw new Error('Tests afterAll(): Error while deleting test dataset') | ||
| } | ||
|
|
||
| try { | ||
| await deleteCollectionViaApi(testCollectionAlias) | ||
| } catch (error) { | ||
| throw new Error('Tests afterAll(): Error while deleting test collection') | ||
| } | ||
| }) | ||
|
|
||
| const getTestFileId = async (): Promise<number> => { | ||
| const datasetFiles = await getDatasetFiles.execute(testDatasetIds.numericId) | ||
| return datasetFiles.files[0].id | ||
| } | ||
|
|
||
| test('should successfully get file citation in EndNote (XML) format', async () => { | ||
| const fileId = await getTestFileId() | ||
|
|
||
| const citation = await getFileCitationByFormat.execute(fileId, FileCitationFormat.ENDNOTE) | ||
|
|
||
| expect(typeof citation).toBe('string') | ||
| expect(citation.trimStart()).toMatch(/^<\?xml/) | ||
| }) | ||
|
|
||
| test('should successfully get file citation in RIS (plain text) format', async () => { | ||
| const fileId = await getTestFileId() | ||
|
|
||
| const citation = await getFileCitationByFormat.execute(fileId, FileCitationFormat.RIS) | ||
|
|
||
| expect(typeof citation).toBe('string') | ||
| // RIS records use TY (type) and ER (end of record) tags | ||
| expect(citation).toMatch(/TY\s+-/) | ||
| expect(citation).toMatch(/ER\s+-/) | ||
| }) | ||
|
|
||
| test('should successfully get file citation in BibTeX (plain text) format', async () => { | ||
| const fileId = await getTestFileId() | ||
|
|
||
| const citation = await getFileCitationByFormat.execute(fileId, FileCitationFormat.BIBTEX) | ||
|
|
||
| expect(typeof citation).toBe('string') | ||
| // BibTeX entries start with @<entry-type>{ | ||
| expect(citation.trimStart()).toMatch(/^@\w+\{/) | ||
| }) | ||
|
|
||
| test('should successfully get file citation in CSL (JSON) format', async () => { | ||
| const fileId = await getTestFileId() | ||
|
|
||
| const citation = await getFileCitationByFormat.execute(fileId, FileCitationFormat.CSL) | ||
|
|
||
| expect(typeof citation).toBe('string') | ||
| const parsed = JSON.parse(citation) | ||
| expect(typeof parsed).toBe('object') | ||
| expect(parsed).not.toBeNull() | ||
| }) | ||
|
|
||
| test('should successfully get file citation in Internal (HTML) format', async () => { | ||
| const fileId = await getTestFileId() | ||
|
|
||
| const citation = await getFileCitationByFormat.execute(fileId, FileCitationFormat.INTERNAL) | ||
|
|
||
| expect(typeof citation).toBe('string') | ||
| // Internal HTML format includes anchor tags linking to the dataset | ||
| expect(citation).toMatch(/<a\s+href=/i) | ||
| }) | ||
|
|
||
| test('should throw an error when the file id does not exist', async () => { | ||
| const nonExistentFileId = 5 | ||
|
|
||
| await expect( | ||
| getFileCitationByFormat.execute(nonExistentFileId, FileCitationFormat.BIBTEX) | ||
| ).rejects.toThrow(ReadError) | ||
| }) | ||
| }) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this use case takes a fileId or a persistentId, can you add a test that uses persistentId?