diff --git a/package-lock.json b/package-lock.json index 1284be569..f6231d9f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-pr88.9d7ced6", + "@iqss/dataverse-client-javascript": "2.0.0-pr92.3fbf381", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", @@ -3588,9 +3588,9 @@ }, "node_modules/@iqss/dataverse-client-javascript": { "name": "@IQSS/dataverse-client-javascript", - "version": "2.0.0-pr88.9d7ced6", - "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr88.9d7ced6/829cd0eefdf14c3911cc5b02a7fca9eed303587c", - "integrity": "sha512-Wjut9iCGif6cKGPZkMAyFgvR3L8ssdRHab0owXw4IJQZU8Cm4+nNvQaCFlO2cxC95zbJh0GUEUc07oqb7AOlpA==", + "version": "2.0.0-pr92.3fbf381", + "resolved": "https://npm.pkg.github.com/download/@IQSS/dataverse-client-javascript/2.0.0-pr92.3fbf381/c65e21a842363935d5ca632de9077063382f8800", + "integrity": "sha512-eexOP5sAKyaJc3Lj1xw8qFpYAh7R0de85VPRKoG8pPkON0LjMAql7heVGMP/MO1gvy159XSSdl2WCrtl/qLuJQ==", "license": "MIT", "dependencies": { "@types/node": "^18.15.11", diff --git a/package.json b/package.json index bde8dd17e..454d1ddd1 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@faker-js/faker": "7.6.0", - "@iqss/dataverse-client-javascript": "2.0.0-pr88.9d7ced6", + "@iqss/dataverse-client-javascript": "2.0.0-pr92.3fbf381", "@iqss/dataverse-design-system": "*", "@istanbuljs/nyc-config-typescript": "1.0.2", "@tanstack/react-table": "8.9.2", diff --git a/src/files/infrastructure/FileJSDataverseRepository.ts b/src/files/infrastructure/FileJSDataverseRepository.ts index e0cd8baef..d98b5d241 100644 --- a/src/files/infrastructure/FileJSDataverseRepository.ts +++ b/src/files/infrastructure/FileJSDataverseRepository.ts @@ -4,8 +4,10 @@ import { FilesCountInfo } from '../domain/models/FilesCountInfo' import { FilePaginationInfo } from '../domain/models/FilePaginationInfo' import { FileUserPermissions } from '../domain/models/FileUserPermissions' import { + FileDownloadSizeMode, getDatasetFileCounts, getDatasetFiles, + getDatasetFilesTotalDownloadSize, getFileDownloadCount, getFileUserPermissions, WriteError @@ -15,6 +17,8 @@ import { DomainFileMapper } from './mappers/DomainFileMapper' import { JSFileMapper } from './mappers/JSFileMapper' import { DatasetVersion } from '../../dataset/domain/models/Dataset' +const includeDeaccessioned = true + export class FileJSDataverseRepository implements FileRepository { getAllByDatasetPersistentId( datasetPersistentId: string, @@ -28,6 +32,7 @@ export class FileJSDataverseRepository implements FileRepository { .execute( datasetPersistentId, datasetVersion.toString(), + includeDeaccessioned, jsPagination.limit, jsPagination.offset, DomainFileMapper.toJSFileCriteria(criteria) @@ -68,7 +73,7 @@ export class FileJSDataverseRepository implements FileRepository { ): Promise { // TODO - Take into account the FileCriteria https://github.com/IQSS/dataverse-frontend/issues/172 return getDatasetFileCounts - .execute(datasetPersistentId, datasetVersion.toString()) + .execute(datasetPersistentId, datasetVersion.toString(), includeDeaccessioned) .then((jsFilesCountInfo) => { return JSFileMapper.toFilesCountInfo(jsFilesCountInfo) }) @@ -78,12 +83,14 @@ export class FileJSDataverseRepository implements FileRepository { } getFilesTotalDownloadSizeByDatasetPersistentId( - // eslint-disable-next-line unused-imports/no-unused-vars datasetPersistentId: string, - // eslint-disable-next-line unused-imports/no-unused-vars datasetVersion: DatasetVersion ): Promise { - return Promise.resolve(0) + return getDatasetFilesTotalDownloadSize + .execute(datasetPersistentId, datasetVersion.toString(), FileDownloadSizeMode.ARCHIVAL) + .catch((error: WriteError) => { + throw new Error(error.message) + }) } getUserPermissionsById(id: number): Promise { diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 2ba35377a..16f569f9b 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -569,26 +569,9 @@ describe('File JSDataverse Repository', () => { description: 'Some description', tabIngest: 'false' }), - FileHelper.create('csv', { - description: 'Some description', - categories: ['category'], - tabIngest: 'false' - }), FileHelper.create('txt', { description: 'Some description', categories: ['category_1'] - }), - FileHelper.create('csv', { - description: 'Some description', - categories: ['category_1'], - restrict: 'true', - tabIngest: 'false' - }), - FileHelper.create('txt', { - description: 'Some description', - categories: ['category'], - restrict: 'true', - tabIngest: 'false' }) ] const dataset = await DatasetHelper.createWithFiles(files).then((datasetResponse) => @@ -596,10 +579,19 @@ describe('File JSDataverse Repository', () => { ) if (!dataset) throw new Error('Dataset not found') + await TestsUtils.wait(2500) // wait for the files to be ingested + + const expectedTotalDownloadSize = await fileRepository + .getAllByDatasetPersistentId(dataset.persistentId, dataset.version) + .then((files) => { + return files.reduce((totalDownloadSize, file) => { + return totalDownloadSize + file.size.toBytes() + }, 0) + }) await fileRepository .getFilesTotalDownloadSizeByDatasetPersistentId(dataset.persistentId, dataset.version) .then((totalDownloadSize) => { - expect(totalDownloadSize).to.deep.equal(3037) + expect(totalDownloadSize).to.deep.equal(expectedTotalDownloadSize) }) }) })