Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/useCases.md
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,9 @@ getDatasetVersionsSummaries

_See [use case](../src/datasets/domain/useCases/GetDatasetVersionsSummaries.ts) implementation_.

The `datasetId` parameter can be a string, for persistent identifiers, or a number, for numeric identifiers.
- The `datasetId` parameter can be a string, for persistent identifiers, or a number, for numeric identifiers.
- **limit**: (number) Limit for pagination.
- **offset**: (number) Offset for pagination.

#### Get Dataset Linked Collections

Expand Down Expand Up @@ -1984,6 +1986,9 @@ getFileVersionSummaries.execute(fileId).then((fileVersionSummaries: fileVersionS

_See [use case](../src/files/domain/useCases/GetFileVersionSummaries.ts) implementation_.

- **limit**: (number) Limit for pagination.
- **offset**: (number) Offset for pagination.

## Metadata Blocks

### Metadata Blocks read use cases
Expand Down
6 changes: 5 additions & 1 deletion src/datasets/domain/repositories/IDatasetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export interface IDatasetsRepository {
datasetId: number | string,
includeMDC?: boolean
): Promise<DatasetDownloadCount>
getDatasetVersionsSummaries(datasetId: number | string): Promise<DatasetVersionSummaryInfo[]>
getDatasetVersionsSummaries(
datasetId: number | string,
limit?: number,
offset?: number
): Promise<DatasetVersionSummaryInfo[]>
deleteDatasetDraft(datasetId: number | string): Promise<void>
linkDataset(datasetId: number | string, collectionIdOrAlias: number | string): Promise<void>
unlinkDataset(datasetId: number | string, collectionIdOrAlias: number | string): Promise<void>
Expand Down
10 changes: 8 additions & 2 deletions src/datasets/domain/useCases/GetDatasetVersionsSummaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ export class GetDatasetVersionsSummaries implements UseCase<DatasetVersionSummar
* Draft versions will only be available to users who have permission to view unpublished drafts.
*
* @param {number | string} [datasetId] - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers).
* @param {number} [limit] - Limit for pagination (optional).
* @param {number} [offset] - Offset for pagination (optional).
* @returns {Promise<DatasetVersionSummaryInfo[]>} - An array of DatasetVersionSummaryInfo.
*/
async execute(datasetId: number | string): Promise<DatasetVersionSummaryInfo[]> {
return await this.datasetsRepository.getDatasetVersionsSummaries(datasetId)
async execute(
datasetId: number | string,
limit?: number,
offset?: number
): Promise<DatasetVersionSummaryInfo[]> {
return await this.datasetsRepository.getDatasetVersionsSummaries(datasetId, limit, offset)
}
}
12 changes: 10 additions & 2 deletions src/datasets/infra/repositories/DatasetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,19 @@ export class DatasetsRepository extends ApiRepository implements IDatasetsReposi
}

public async getDatasetVersionsSummaries(
datasetId: string | number
datasetId: string | number,
limit?: number,
offset?: number
): Promise<DatasetVersionSummaryInfo[]> {
const queryParams: { limit?: string; offset?: string } = {
limit: limit?.toString(),
offset: offset?.toString()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can follow same approach as here for limit and offset, using URLSearchParams

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the api returns totalCount but I didn't add it to use case. I modified the code to apply totalCount, please review again. Thank you! @g-saracca


return this.doGet(
this.buildApiEndpoint(this.datasetsResourceName, 'versions/compareSummary', datasetId),
true
true,
queryParams
)
.then((response) => response.data.data)
.catch((error) => {
Expand Down
6 changes: 5 additions & 1 deletion src/files/domain/repositories/IFilesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ export interface IFilesRepository {
replace?: boolean
): Promise<void>

getFileVersionSummaries(fileId: number | string): Promise<FileVersionSummaryInfo[]>
getFileVersionSummaries(
fileId: number | string,
limit?: number,
offset?: number
): Promise<FileVersionSummaryInfo[]>

isFileDeleted(fileId: number | string): Promise<boolean>
}
10 changes: 8 additions & 2 deletions src/files/domain/useCases/GetFileVersionSummaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ export class GetFileVersionSummaries implements UseCase<FileVersionSummaryInfo[]
* Returns a list of versions for a given file including a summary of differences between consecutive versions
*
* @param {number | string} [fileId] - The file identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers).
* @param {number} [limit] - Limit for pagination (optional).
* @param {number} [offset] - Offset for pagination (optional).
* @returns {Promise<FileVersionSummaryInfo[]>} - An array of FileVersionSummaryInfo.
*/
async execute(fileId: number | string): Promise<FileVersionSummaryInfo[]> {
return await this.filesRepository.getFileVersionSummaries(fileId)
async execute(
fileId: number | string,
limit?: number,
offset?: number
): Promise<FileVersionSummaryInfo[]> {
return await this.filesRepository.getFileVersionSummaries(fileId, limit, offset)
}
}
14 changes: 12 additions & 2 deletions src/files/infra/repositories/FilesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,20 @@ export class FilesRepository extends ApiRepository implements IFilesRepository {
})
}

public async getFileVersionSummaries(fileId: number | string): Promise<FileVersionSummaryInfo[]> {
public async getFileVersionSummaries(
fileId: number | string,
limit?: number,
offset?: number
): Promise<FileVersionSummaryInfo[]> {
const queryParams: { limit?: string; offset?: string } = {
limit: limit?.toString(),
offset: offset?.toString()
}

return this.doGet(
this.buildApiEndpoint(this.filesResourceName, 'versionDifferences', fileId),
true
true,
queryParams
)
.then((response) => transformFileVersionSummaryInfoResponseToFileVersionSummaryInfo(response))
.catch((error) => {
Expand Down
59 changes: 59 additions & 0 deletions test/integration/datasets/DatasetsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,65 @@ describe('DatasetsRepository', () => {
expectedError
)
})

test('should return dataset versions summaries with pagination', async () => {
const testDatasetIds = await createDataset.execute(
TestConstants.TEST_NEW_DATASET_DTO,
testDatasetVersionsCollectionAlias
)

await publishDataset.execute(testDatasetIds.numericId, VersionUpdateType.MAJOR)
await waitForNoLocks(testDatasetIds.numericId, 10)

const metadataBlocksRepository = new MetadataBlocksRepository()
const citationMetadataBlock = await metadataBlocksRepository.getMetadataBlockByName(
'citation'
)

for (let i = 1; i <= 21; i++) {
await sut.updateDataset(
testDatasetIds.numericId,
{
metadataBlockValues: [
{
name: 'citation',
fields: {
title: `Updated Dataset Title - Version ${i}`
}
}
]
},
[citationMetadataBlock]
)

await publishDataset.execute(testDatasetIds.numericId, VersionUpdateType.MINOR)
await waitForNoLocks(testDatasetIds.numericId, 10)
}

const firstPage = await sut.getDatasetVersionsSummaries(testDatasetIds.numericId, 5, 0)

expect(firstPage.length).toBe(5)
expect(firstPage[0].versionNumber).toBe('1.21')
expect(firstPage[4].versionNumber).toBe('1.17')

// Test pagination with limit=5, offset=5 (second page)
const secondPage = await sut.getDatasetVersionsSummaries(testDatasetIds.numericId, 5, 5)
expect(secondPage.length).toBe(5)
expect(secondPage[0].versionNumber).toBe('1.16')
expect(secondPage[4].versionNumber).toBe('1.12')

// Test pagination with limit=5, offset=10 (third page)
const thirdPage = await sut.getDatasetVersionsSummaries(testDatasetIds.numericId, 5, 10)
expect(thirdPage.length).toBe(5)
expect(thirdPage[0].versionNumber).toBe('1.11')
expect(thirdPage[4].versionNumber).toBe('1.7')

// Test that all versions are returned without pagination
const allVersions = await sut.getDatasetVersionsSummaries(testDatasetIds.numericId)
expect(allVersions.length).toBe(22) // 1 initial + 21 updates

await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
}, 180000)
})

describe('getDatasetDownloadCount', () => {
Expand Down
56 changes: 55 additions & 1 deletion test/integration/files/FilesRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@ describe('FilesRepository', () => {
contributors: 'Dataverse Admin',
datafileId: testFile.id,
persistentId: testFile.persistentId,
publishedDate: '',
versionNote: undefined,
fileDifferenceSummary: { file: 'Added' }
}

Expand Down Expand Up @@ -1022,7 +1024,7 @@ describe('FilesRepository', () => {
contributors: 'Dataverse Admin',
datafileId: testFile.id,
persistentId: testFile.persistentId,
publishedDate: actual[0].publishedDate,
publishedDate: '',
versionNote: undefined,
fileDifferenceSummary: {
fileMetadata: [
Expand All @@ -1047,6 +1049,58 @@ describe('FilesRepository', () => {
deletePublishedDatasetViaApi(fileTestDatasetIds.persistentId)
})

test('should return file version summaries with pagination', async () => {
// Create a new dataset and upload a file
const paginationTestDatasetIds = await createDataset.execute(
TestConstants.TEST_NEW_DATASET_DTO
)
await uploadFileViaApi(paginationTestDatasetIds.numericId, testTextFile1Name)

// Publish initial version (creates version 1.0)
await publishDatasetViaApi(paginationTestDatasetIds.numericId)
await waitForNoLocks(paginationTestDatasetIds.numericId, 10)

// Get the file ID
const datasetFiles = await sut.getDatasetFiles(
paginationTestDatasetIds.numericId,
latestDatasetVersionId,
false,
FileOrderCriteria.NAME_AZ
)
const paginationTestFile = datasetFiles.files[0]

for (let i = 1; i <= 21; i++) {
await sut.updateFileMetadata(paginationTestFile.id, {
description: `File description update ${i}`,
label: `updated-file-${i}.txt`
})

await publishDatasetViaApi(paginationTestDatasetIds.numericId)
await waitForNoLocks(paginationTestDatasetIds.numericId, 10)
}

const firstPage = await sut.getFileVersionSummaries(paginationTestFile.id, 5, 0)

expect(firstPage.length).toBe(5)
expect(firstPage[0].datasetVersion).toBe('22.0')
expect(firstPage[4].datasetVersion).toBe('18.0')

const secondPage = await sut.getFileVersionSummaries(paginationTestFile.id, 5, 5)
expect(secondPage.length).toBe(5)
expect(secondPage[0].datasetVersion).toBe('17.0')
expect(secondPage[4].datasetVersion).toBe('13.0')

const thirdPage = await sut.getFileVersionSummaries(paginationTestFile.id, 5, 10)
expect(thirdPage.length).toBe(5)
expect(thirdPage[0].datasetVersion).toBe('12.0')
expect(thirdPage[4].datasetVersion).toBe('8.0')

const allVersions = await sut.getFileVersionSummaries(paginationTestFile.id)
expect(allVersions.length).toBe(22)

await deletePublishedDatasetViaApi(paginationTestDatasetIds.persistentId)
}, 180000)

test('should return error when file does not exist', async () => {
const expectedError = new ReadError(`[404] File with ID ${nonExistentFiledId} not found.`)

Expand Down
6 changes: 5 additions & 1 deletion test/unit/datasets/GetDatasetVersionsSummaries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ describe('execute', () => {
const actual = await sut.execute(testDatasetId)

expect(actual).toEqual(testDatasetVersionsSummaries)
expect(datasetsRepositoryStub.getDatasetVersionsSummaries).toHaveBeenCalledWith(testDatasetId)
expect(datasetsRepositoryStub.getDatasetVersionsSummaries).toHaveBeenCalledWith(
testDatasetId,
undefined,
undefined
)
})

test('should return error result on repository error', async () => {
Expand Down
Loading