-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from IQSS/refactor/263-extract-file-metadata
Refactor extract File Metadata to its own model
- Loading branch information
Showing
130 changed files
with
2,731 additions
and
1,993 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,37 +1,18 @@ | ||
import { DatasetVersion } from '../../../dataset/domain/models/Dataset' | ||
import { | ||
FileChecksum, | ||
FileDownloadUrls, | ||
FileEmbargo, | ||
FileLabel, | ||
FileSize, | ||
FileTabularData, | ||
FileType, | ||
FileVersion | ||
} from './FilePreview' | ||
|
||
export interface FilePermissions { | ||
canDownloadFile: boolean | ||
} | ||
import { FileMetadata } from './FileMetadata' | ||
import { FileVersion } from './FileVersion' | ||
import { FileAccess } from './FileAccess' | ||
import { FileUserPermissions } from './FileUserPermissions' | ||
import { FileIngest } from './FileIngest' | ||
|
||
export interface File { | ||
name: string | ||
id: number | ||
version: FileVersion | ||
name: string | ||
access: FileAccess | ||
datasetVersion: DatasetVersion | ||
type: FileType | ||
size: FileSize | ||
citation: string | ||
restricted: boolean | ||
permissions: FilePermissions | ||
labels: FileLabel[] | ||
downloadUrls: FileDownloadUrls | ||
depositDate: Date | ||
publicationDate?: Date | ||
persistentId?: string | ||
thumbnail?: string | ||
directory?: string | ||
tabularData?: FileTabularData | ||
description?: string | ||
checksum?: FileChecksum | ||
embargo?: FileEmbargo | ||
permissions: FileUserPermissions | ||
metadata: FileMetadata | ||
ingest: FileIngest | ||
} |
This file contains 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,6 @@ | ||
export interface FileAccess { | ||
restricted: boolean | ||
latestVersionRestricted: boolean | ||
canBeRequested: boolean | ||
requested: boolean | ||
} |
This file contains 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 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,14 @@ | ||
export enum FileIngestStatus { | ||
NONE = 'none', | ||
IN_PROGRESS = 'inProgress', | ||
SCHEDULED = 'scheduled', | ||
ERROR = 'error' | ||
} | ||
|
||
export class FileIngest { | ||
constructor(readonly status: FileIngestStatus, readonly message?: string) {} | ||
|
||
get isInProgress(): boolean { | ||
return this.status === FileIngestStatus.IN_PROGRESS | ||
} | ||
} |
This file contains 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,174 @@ | ||
import FileTypeToFriendlyTypeMap from './FileTypeToFriendlyTypeMap' | ||
|
||
export enum FileSizeUnit { | ||
BYTES = 'B', | ||
KILOBYTES = 'KB', | ||
MEGABYTES = 'MB', | ||
GIGABYTES = 'GB', | ||
TERABYTES = 'TB', | ||
PETABYTES = 'PB' | ||
} | ||
|
||
export class FileSize { | ||
static readonly multiplier = { | ||
[FileSizeUnit.BYTES]: 1, | ||
[FileSizeUnit.KILOBYTES]: 1024, | ||
[FileSizeUnit.MEGABYTES]: 1024 ** 2, | ||
[FileSizeUnit.GIGABYTES]: 1024 ** 3, | ||
[FileSizeUnit.TERABYTES]: 1024 ** 4, | ||
[FileSizeUnit.PETABYTES]: 1024 ** 5 | ||
} | ||
|
||
constructor(readonly value: number, readonly unit: FileSizeUnit) { | ||
;[this.value, this.unit] = FileSize.convertToLargestUnit(value, unit) | ||
} | ||
|
||
toString(): string { | ||
const formattedValue = | ||
this.value % 1 === 0 ? this.value.toFixed(0) : (Math.round(this.value * 10) / 10).toString() | ||
return `${formattedValue} ${this.unit}` | ||
} | ||
|
||
toBytes(): number { | ||
return this.value * FileSize.multiplier[this.unit] | ||
} | ||
|
||
static convertToLargestUnit(value: number, unit: FileSizeUnit): [number, FileSizeUnit] { | ||
let convertedValue = value | ||
let convertedUnit = unit | ||
|
||
while (convertedValue >= 1024 && convertedUnit !== FileSizeUnit.PETABYTES) { | ||
convertedValue /= 1024 | ||
convertedUnit = this.getNextUnit(convertedUnit) | ||
} | ||
|
||
return [convertedValue, convertedUnit] | ||
} | ||
|
||
static getNextUnit(unit: FileSizeUnit): FileSizeUnit { | ||
switch (unit) { | ||
case FileSizeUnit.BYTES: | ||
return FileSizeUnit.KILOBYTES | ||
case FileSizeUnit.KILOBYTES: | ||
return FileSizeUnit.MEGABYTES | ||
case FileSizeUnit.MEGABYTES: | ||
return FileSizeUnit.GIGABYTES | ||
case FileSizeUnit.GIGABYTES: | ||
return FileSizeUnit.TERABYTES | ||
case FileSizeUnit.TERABYTES: | ||
return FileSizeUnit.PETABYTES | ||
default: | ||
return unit | ||
} | ||
} | ||
} | ||
|
||
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) | ||
} | ||
} | ||
|
||
export enum FileDateType { | ||
METADATA_RELEASED = 'metadataReleased', | ||
PUBLISHED = 'published', | ||
DEPOSITED = 'deposited' | ||
} | ||
|
||
export interface FileDate { | ||
type: FileDateType | ||
date: Date | ||
} | ||
|
||
export class FileEmbargo { | ||
constructor(readonly dateAvailable: Date, readonly reason?: string) {} | ||
|
||
get isActive(): boolean { | ||
return this.dateAvailable > new Date() | ||
} | ||
} | ||
|
||
export interface FileTabularData { | ||
variablesCount: number | ||
observationsCount: number | ||
unf?: string | ||
} | ||
|
||
export enum FileLabelType { | ||
CATEGORY = 'category', | ||
TAG = 'tag' | ||
} | ||
|
||
export interface FileLabel { | ||
type: FileLabelType | ||
value: string | ||
} | ||
|
||
export class FileType { | ||
constructor(readonly value: string, readonly original?: string) {} | ||
|
||
toDisplayFormat(): string { | ||
return FileTypeToFriendlyTypeMap[this.value] || FileTypeToFriendlyTypeMap.unknown | ||
} | ||
|
||
get displayFormatIsUnknown(): boolean { | ||
return this.toDisplayFormat() === FileTypeToFriendlyTypeMap.unknown | ||
} | ||
|
||
get originalFormatIsUnknown(): boolean { | ||
return this.original === undefined || this.original === FileTypeToFriendlyTypeMap.unknown | ||
} | ||
} | ||
|
||
export interface FileChecksum { | ||
algorithm: string | ||
value: string | ||
} | ||
|
||
export interface FileDownloadUrls { | ||
original: string | ||
tabular?: string | ||
rData?: string | ||
} | ||
|
||
export class FileMetadata { | ||
constructor( | ||
readonly type: FileType, | ||
readonly size: FileSize, | ||
readonly date: FileDate, | ||
readonly downloadCount: number, | ||
readonly labels: FileLabel[], | ||
public readonly isDeleted: boolean, | ||
public readonly downloadUrls: FileDownloadUrls, | ||
readonly depositDate: Date, | ||
readonly publicationDate?: Date, | ||
public thumbnail?: string, | ||
readonly directory?: string, | ||
readonly embargo?: FileEmbargo, | ||
readonly tabularData?: FileTabularData, | ||
readonly description?: string, | ||
readonly checksum?: FileChecksum, | ||
readonly persistentId?: string | ||
) {} | ||
|
||
get isActivelyEmbargoed(): boolean { | ||
if (this.embargo) { | ||
return this.embargo.isActive | ||
} | ||
return false | ||
} | ||
|
||
get isTabular(): boolean { | ||
return this.tabularData !== undefined | ||
} | ||
} |
Oops, something went wrong.