Skip to content

Commit

Permalink
Merge pull request #256 from IQSS/feature/244-integration-download-al…
Browse files Browse the repository at this point in the history
…l-files

244 - Integration download dataset
  • Loading branch information
GPortas authored Dec 15, 2023
2 parents b46bdad + ac81d82 commit 48c2521
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 170 deletions.
9 changes: 6 additions & 3 deletions public/locales/en/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@
},
"accessDataset": {
"title": "Access Dataset",
"downloadZip": "Download ZIP",
"downloadOriginalZip": "Original Format ZIP",
"downloadArchiveZip": "Archive Format (.tab) ZIP"
"downloadOptions": {
"header": "Download Options",
"zip": "Download ZIP",
"originalZip": "Original Format ZIP",
"archivalZip": "Archival Format (.tab) ZIP"
}
},
"uploadFiles": "Upload Files"
},
Expand Down
12 changes: 6 additions & 6 deletions src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ export class Dataset {
public readonly isValid: boolean,
public readonly isReleased: boolean,
public readonly downloadUrls: DatasetDownloadUrls,
public readonly fileDownloadSizes: FileDownloadSize[],
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl,
public readonly fileDownloadSizes?: FileDownloadSize[]
public readonly privateUrl?: PrivateUrl
) {}

public getTitle(): string {
Expand Down Expand Up @@ -372,9 +372,9 @@ export class Dataset {
public readonly isValid: boolean,
public readonly isReleased: boolean,
public readonly downloadUrls: DatasetDownloadUrls,
public readonly fileDownloadSizes: FileDownloadSize[],
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl,
public readonly fileDownloadSizes?: FileDownloadSize[]
public readonly privateUrl?: PrivateUrl
) {
this.withLabels()
this.withAlerts()
Expand Down Expand Up @@ -483,9 +483,9 @@ export class Dataset {
this.isValid,
this.isReleased,
this.downloadUrls,
this.fileDownloadSizes,
this.thumbnail,
this.privateUrl,
this.fileDownloadSizes
this.privateUrl
)
}
}
Expand Down
63 changes: 44 additions & 19 deletions src/dataset/infrastructure/mappers/JSDatasetMapper.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import {
Dataset as JSDataset,
DatasetLock as JSDatasetLock,
DatasetMetadataBlock as JSDatasetMetadataBlock,
DatasetMetadataBlocks as JSDatasetMetadataBlocks,
DatasetMetadataFields as JSDatasetMetadataFields,
DatasetVersionInfo as JSDatasetVersionInfo,
DatasetUserPermissions as JSDatasetPermissions,
DatasetLock as JSDatasetLock
DatasetVersionInfo as JSDatasetVersionInfo
} from '@iqss/dataverse-client-javascript'
import { DatasetVersionState as JSDatasetVersionState } from '@iqss/dataverse-client-javascript/dist/datasets/domain/models/Dataset'
import {
Dataset,
DatasetPublishingStatus,
DatasetDownloadUrls,
DatasetLock,
DatasetLockReason,
DatasetMetadataBlock,
DatasetMetadataBlocks,
DatasetMetadataFields,
DatasetPermissions,
DatasetPublishingStatus,
DatasetVersion,
MetadataBlockName,
PrivateUrl,
DatasetDownloadUrls,
DatasetPermissions,
DatasetLock,
DatasetLockReason
PrivateUrl
} from '../../domain/models/Dataset'
import { FileDownloadMode, FileDownloadSize, FileSizeUnit } from '../../../files/domain/models/File'

export class JSDatasetMapper {
static toDataset(
Expand All @@ -30,6 +31,8 @@ export class JSDatasetMapper {
summaryFieldsNames: string[],
jsDatasetPermissions: JSDatasetPermissions,
jsDatasetLocks: JSDatasetLock[],
jsDatasetFilesTotalOriginalDownloadSize: number,
jsDatasetFilesTotalArchivalDownloadSize: number,
requestedVersion?: string,
privateUrl?: PrivateUrl
): Dataset {
Expand Down Expand Up @@ -57,9 +60,12 @@ export class JSDatasetMapper {
true, // TODO Connect with dataset isValid
JSDatasetMapper.toIsReleased(jsDataset.versionInfo),
JSDatasetMapper.toDownloadUrls(jsDataset.persistentId, version),
JSDatasetMapper.toFileDownloadSizes(
jsDatasetFilesTotalOriginalDownloadSize,
jsDatasetFilesTotalArchivalDownloadSize
),
undefined, // TODO: get dataset thumbnail from Dataverse https://github.com/IQSS/dataverse-frontend/issues/203
privateUrl,
[] // TODO: Connect with file download use case
privateUrl
).build()
}

Expand Down Expand Up @@ -194,15 +200,6 @@ export class JSDatasetMapper {
return extraFields
}

static toDownloadUrls(
jsDatasetPersistentId: string,
version: DatasetVersion
): DatasetDownloadUrls {
return {
original: `/api/access/dataset/:persistentId/versions/${version.toString()}?persistentId=${jsDatasetPersistentId}&format=original`,
archival: `/api/access/dataset/:persistentId/versions/${version.toString()}?persistentId=${jsDatasetPersistentId}`
}
}
static toIsReleased(jsDatasetVersionInfo: JSDatasetVersionInfo): boolean {
return (
jsDatasetVersionInfo.releaseTime !== undefined &&
Expand All @@ -228,4 +225,32 @@ export class JSDatasetMapper {
}
})
}

static toDownloadUrls(
jsDatasetPersistentId: string,
version: DatasetVersion
): DatasetDownloadUrls {
return {
original: `/api/access/dataset/:persistentId/versions/${version.toString()}?persistentId=${jsDatasetPersistentId}&format=original`,
archival: `/api/access/dataset/:persistentId/versions/${version.toString()}?persistentId=${jsDatasetPersistentId}`
}
}

static toFileDownloadSizes(
jsDatasetFilesTotalOriginalDownloadSize: number,
jsDatasetFilesTotalArchivalDownloadSize: number
): FileDownloadSize[] {
return [
new FileDownloadSize(
jsDatasetFilesTotalOriginalDownloadSize,
FileSizeUnit.BYTES,
FileDownloadMode.ORIGINAL
),
new FileDownloadSize(
jsDatasetFilesTotalArchivalDownloadSize,
FileSizeUnit.BYTES,
FileDownloadMode.ARCHIVAL
)
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
getDatasetUserPermissions,
ReadError,
getDatasetLocks,
DatasetLock as JSDatasetLock
DatasetLock as JSDatasetLock,
getDatasetFilesTotalDownloadSize,
FileDownloadSizeMode
} from '@iqss/dataverse-client-javascript'
import { JSDatasetMapper } from '../mappers/JSDatasetMapper'

const includeDeaccessioned = true

export class DatasetJSDataverseRepository implements DatasetRepository {
getByPersistentId(
persistentId: string,
Expand All @@ -31,23 +32,41 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
getDatasetSummaryFieldNames.execute(),
getDatasetCitation.execute(jsDataset.id, this.versionToVersionId(version)),
getDatasetUserPermissions.execute(jsDataset.id),
getDatasetLocks.execute(jsDataset.id)
getDatasetLocks.execute(jsDataset.id),
getDatasetFilesTotalDownloadSize.execute(
persistentId,
this.versionToVersionId(version),
FileDownloadSizeMode.ORIGINAL,
undefined,
includeDeaccessioned
),
getDatasetFilesTotalDownloadSize.execute(
persistentId,
this.versionToVersionId(version),
FileDownloadSizeMode.ARCHIVAL,
undefined,
includeDeaccessioned
)
])
)
.then(
([jsDataset, summaryFieldsNames, citation, jsDatasetPermissions, jsDatasetLocks]: [
JSDataset,
string[],
string,
JSDatasetPermissions,
JSDatasetLock[]
]) =>
([
jsDataset,
summaryFieldsNames,
citation,
jsDatasetPermissions,
jsDatasetLocks,
jsDatasetFilesTotalOriginalDownloadSize,
jsDatasetFilesTotalArchivalDownloadSize
]: [JSDataset, string[], string, JSDatasetPermissions, JSDatasetLock[], number, number]) =>
JSDatasetMapper.toDataset(
jsDataset,
citation,
summaryFieldsNames,
jsDatasetPermissions,
jsDatasetLocks,
jsDatasetFilesTotalOriginalDownloadSize,
jsDatasetFilesTotalArchivalDownloadSize,
requestedVersion
)
)
Expand Down Expand Up @@ -76,10 +95,12 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
canManageDatasetPermissions: true,
canDeleteDatasetDraft: true,
canViewUnpublishedDataset: true
},
[]
}, // TODO Connect with JS dataset permissions for privateUrl when it is available in js-dataverse
[], // TODO Connect with JS dataset locks for privateUrl when it is available in js-dataverse
0, // TODO Connect with JS dataset filesTotalDownloadSize for privateUrl when it is available in js-dataverse
0 // TODO Connect with JS dataset filesTotalDownloadSize for privateUrl when it is available in js-dataverse
)
) // TODO Connect with JS dataset permissions and getDatasetLocks.execute(privateUrlToken) when it is available in js-dataverse
)
.catch((error: ReadError) => {
throw new Error(error.message)
})
Expand Down
17 changes: 9 additions & 8 deletions src/files/domain/models/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FileSize {
}

constructor(readonly value: number, readonly unit: FileSizeUnit) {
;[this.value, this.unit] = this.convertToLargestUnit(value, unit)
;[this.value, this.unit] = FileSize.convertToLargestUnit(value, unit)
}

toString(): string {
Expand All @@ -33,7 +33,7 @@ export class FileSize {
return this.value * FileSize.multiplier[this.unit]
}

private convertToLargestUnit(value: number, unit: FileSizeUnit): [number, FileSizeUnit] {
static convertToLargestUnit(value: number, unit: FileSizeUnit): [number, FileSizeUnit] {
let convertedValue = value
let convertedUnit = unit

Expand All @@ -45,7 +45,7 @@ export class FileSize {
return [convertedValue, convertedUnit]
}

private getNextUnit(unit: FileSizeUnit): FileSizeUnit {
static getNextUnit(unit: FileSizeUnit): FileSizeUnit {
switch (unit) {
case FileSizeUnit.BYTES:
return FileSizeUnit.KILOBYTES
Expand All @@ -63,13 +63,19 @@ export class FileSize {
}
}

export enum FileDownloadMode {
ORIGINAL = 'original',
ARCHIVAL = 'archival'
}

export class FileDownloadSize extends FileSize {
constructor(
readonly value: number,
readonly unit: FileSizeUnit,
readonly mode: FileDownloadMode
) {
super(value, unit)
;[this.value, this.unit] = FileDownloadSize.convertToLargestUnit(value, unit)
}
}

Expand Down Expand Up @@ -121,11 +127,6 @@ export interface FileTabularData {
unf?: string
}

export enum FileDownloadMode {
ARCHIVAL = 'archival',
ORIGINAL = 'original'
}

export enum FileLabelType {
CATEGORY = 'category',
TAG = 'tag'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function DatasetActionButtons({ dataset }: DatasetActionButtonsProps) {
permissions={dataset.permissions}
hasOneTabularFileAtLeast={dataset.hasOneTabularFileAtLeast}
fileDownloadSizes={dataset.fileDownloadSizes}
downloadUrls={dataset.downloadUrls}
/>
<PublishDatasetMenu dataset={dataset} />
<SubmitForReviewButton dataset={dataset} />
Expand Down
Loading

0 comments on commit 48c2521

Please sign in to comment.