Skip to content

Commit

Permalink
Merge pull request #204 from IQSS/feature/200-integration-total-datas…
Browse files Browse the repository at this point in the history
…et-files-size-with-search-criteria

200 - Integration total dataset files size with search criteria
  • Loading branch information
GPortas authored Nov 3, 2023
2 parents 3bb4f17 + df407d8 commit 563f95d
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: ./run-env.sh "$E2E_DATAVERSE_IMAGE_TAG"

- name: Wait for containers to be ready
run: timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done'
run: timeout 600s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done'

- name: Run e2e tests
run: npm run test:e2e
Expand Down
2 changes: 1 addition & 1 deletion dev-env/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POSTGRES_VERSION=13
DATAVERSE_DB_USER=dataverse
SOLR_VERSION=9.3.0
REGISTRY=ghcr.io
REGISTRY=docker.io
2 changes: 1 addition & 1 deletion dev-env/run-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export DATAVERSE_IMAGE_TAG=$1
export COMPOSE_HTTP_TIMEOUT=200

# Timeout for Dataverse bootstrap configbaker
export DATAVERSE_BOOTSTRAP_TIMEOUT="5m"
export DATAVERSE_BOOTSTRAP_TIMEOUT="10m"

echo "INFO - Setting up Dataverse on image tag ${DATAVERSE_IMAGE_TAG}..."

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@faker-js/faker": "7.6.0",
"@iqss/dataverse-client-javascript": "2.0.0-pr93.8996380",
"@iqss/dataverse-client-javascript": "2.0.0-pr97.418bf5e",
"@iqss/dataverse-design-system": "*",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tanstack/react-table": "8.9.2",
Expand Down
3 changes: 2 additions & 1 deletion src/files/domain/repositories/FileRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export interface FileRepository {
) => Promise<FilesCountInfo>
getFilesTotalDownloadSizeByDatasetPersistentId: (
datasetPersistentId: string,
datasetVersion: DatasetVersion
datasetVersion: DatasetVersion,
criteria?: FileCriteria
) => Promise<number>
getUserPermissionsById: (id: number) => Promise<FileUserPermissions>
}
6 changes: 4 additions & 2 deletions src/files/domain/useCases/getFilesTotalDownloadSize.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { FileRepository } from '../repositories/FileRepository'
import { DatasetVersion } from '../../../dataset/domain/models/Dataset'
import { FileCriteria } from '../models/FileCriteria'

export async function getFilesTotalDownloadSize(
fileRepository: FileRepository,
datasetPersistentId: string,
datasetVersion: DatasetVersion
datasetVersion: DatasetVersion,
criteria?: FileCriteria
): Promise<number> {
return fileRepository
.getFilesTotalDownloadSizeByDatasetPersistentId(datasetPersistentId, datasetVersion)
.getFilesTotalDownloadSizeByDatasetPersistentId(datasetPersistentId, datasetVersion, criteria)
.catch((error: Error) => {
throw new Error(error.message)
})
Expand Down
11 changes: 9 additions & 2 deletions src/files/infrastructure/FileJSDataverseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ export class FileJSDataverseRepository implements FileRepository {

getFilesTotalDownloadSizeByDatasetPersistentId(
datasetPersistentId: string,
datasetVersion: DatasetVersion
datasetVersion: DatasetVersion,
criteria: FileCriteria = new FileCriteria()
): Promise<number> {
return getDatasetFilesTotalDownloadSize
.execute(datasetPersistentId, datasetVersion.toString(), FileDownloadSizeMode.ARCHIVAL)
.execute(
datasetPersistentId,
datasetVersion.toString(),
FileDownloadSizeMode.ARCHIVAL,
DomainFileMapper.toJSFileSearchCriteria(criteria),
includeDeaccessioned
)
.catch((error: ReadError) => {
throw new Error(error.message)
})
Expand Down
4 changes: 2 additions & 2 deletions src/sections/dataset/dataset-files/useFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ export function useFiles(
])

useEffect(() => {
getFilesTotalDownloadSize(filesRepository, datasetPersistentId, datasetVersion)
getFilesTotalDownloadSize(filesRepository, datasetPersistentId, datasetVersion, criteria)
.then((filesTotalDownloadSize: number) => {
setFilesTotalDownloadSize(filesTotalDownloadSize)
})
.catch((error) => {
console.error('There was an error getting the files total download size', error)
})
}, [filesRepository, datasetPersistentId, datasetVersion])
}, [filesRepository, datasetPersistentId, datasetVersion, criteria])

return {
files,
Expand Down
4 changes: 3 additions & 1 deletion src/stories/files/FileMockLoadingRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export class FileMockLoadingRepository implements FileRepository {
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
datasetVersion: DatasetVersion
datasetVersion: DatasetVersion,
// eslint-disable-next-line unused-imports/no-unused-vars
criteria?: FileCriteria
): Promise<number> {
return new Promise((resolve) => {
setTimeout(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/stories/files/FileMockNoDataRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FilesCountInfoMother } from '../../../tests/component/files/domain/mode
import { FileUserPermissions } from '../../files/domain/models/FileUserPermissions'
import { FileUserPermissionsMother } from '../../../tests/component/files/domain/models/FileUserPermissionsMother'
import { DatasetVersion } from '../../dataset/domain/models/Dataset'
import { FileCriteria } from '../../files/domain/models/FileCriteria'

export class FileMockNoDataRepository implements FileRepository {
getAllByDatasetPersistentId(
Expand Down Expand Up @@ -37,7 +38,9 @@ export class FileMockNoDataRepository implements FileRepository {
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
datasetVersion: DatasetVersion
datasetVersion: DatasetVersion,
// eslint-disable-next-line unused-imports/no-unused-vars
criteria?: FileCriteria
): Promise<number> {
return new Promise((resolve) => {
setTimeout(() => {
Expand Down
4 changes: 3 additions & 1 deletion src/stories/files/FileMockNoFiltersRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class FileMockNoFiltersRepository implements FileRepository {
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
datasetVersion: DatasetVersion
datasetVersion: DatasetVersion,
// eslint-disable-next-line unused-imports/no-unused-vars
criteria?: FileCriteria
): Promise<number> {
return new Promise((resolve) => {
setTimeout(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/stories/files/FileMockRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FilePaginationInfo } from '../../files/domain/models/FilePaginationInfo
import { FileUserPermissionsMother } from '../../../tests/component/files/domain/models/FileUserPermissionsMother'
import { FileUserPermissions } from '../../files/domain/models/FileUserPermissions'
import { DatasetVersion } from '../../dataset/domain/models/Dataset'
import { FileCriteria } from '../../files/domain/models/FileCriteria'

export class FileMockRepository implements FileRepository {
// eslint-disable-next-line unused-imports/no-unused-vars
Expand Down Expand Up @@ -39,7 +40,9 @@ export class FileMockRepository implements FileRepository {
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
datasetVersion: DatasetVersion
datasetVersion: DatasetVersion,
// eslint-disable-next-line unused-imports/no-unused-vars
criteria?: FileCriteria
): Promise<number> {
return new Promise((resolve) => {
setTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,32 @@ describe('DatasetFiles', () => {
new FilePaginationInfo(5, 10, 200)
)
})

it('calls getFilesTotalDownloadSizeByDatasetPersistentId with the correct parameters when applying search file criteria', () => {
cy.customMount(
<SettingsProvider repository={settingsRepository}>
<DatasetFiles
filesRepository={fileRepository}
datasetPersistentId={datasetPersistentId}
datasetVersion={datasetVersion}
/>
</SettingsProvider>
)

cy.findByRole('button', { name: 'File Type: All' }).click()
cy.findByText('Image (485)').should('exist').click()
cy.get('table > thead > tr > th > input[type=checkbox]').click()
cy.findByRole('button', { name: 'Select all 200 files in this dataset.' }).click()
cy.findByText(
'The overall size of the files selected (19.4 KB) for download exceeds the zip limit of 1.0 B. Please unselect some files to continue.'
).should('exist')

cy.wrap(fileRepository.getFilesTotalDownloadSizeByDatasetPersistentId).should(
'be.calledWith',
datasetPersistentId,
datasetVersion,
new FileCriteria().withFilterByType('image')
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -688,5 +688,52 @@ describe('File JSDataverse Repository', () => {
expect(totalDownloadSize).to.deep.equal(expectedTotalDownloadSize)
})
})

it('gets the total download size of all files in a dataset when passing files criteria', async () => {
const files = [
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
restrict: 'true',
tabIngest: 'false'
}),
FileHelper.create('txt', {
description: 'Some description',
tabIngest: 'false'
}),
FileHelper.create('txt', {
description: 'Some description',
categories: ['category_1']
})
]
const dataset = await DatasetHelper.createWithFiles(files).then((datasetResponse) =>
datasetRepository.getByPersistentId(datasetResponse.persistentId)
)
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,
new FilePaginationInfo(1, 10, 3),
new FileCriteria().withFilterByType('csv')
)
.then((files) => {
return files.reduce((totalDownloadSize, file) => {
return totalDownloadSize + file.size.toBytes()
}, 0)
})
await fileRepository
.getFilesTotalDownloadSizeByDatasetPersistentId(
dataset.persistentId,
dataset.version,
new FileCriteria().withFilterByType('csv')
)
.then((totalDownloadSize) => {
expect(totalDownloadSize).to.deep.equal(expectedTotalDownloadSize)
})
})
})
})

0 comments on commit 563f95d

Please sign in to comment.