-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDataset.ts
More file actions
615 lines (546 loc) · 18.2 KB
/
Dataset.ts
File metadata and controls
615 lines (546 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
import { Alert, AlertMessageKey } from '../../../alert/domain/models/Alert'
import { UpwardHierarchyNode } from '../../../shared/hierarchy/domain/models/UpwardHierarchyNode'
import { FileDownloadSize } from '../../../files/domain/models/FileMetadata'
import { License } from '@/licenses/domain/models/License'
export enum DatasetLabelSemanticMeaning {
DATASET = 'dataset',
FILE = 'file',
SUCCESS = 'success',
INFO = 'info',
WARNING = 'warning',
DANGER = 'danger'
}
export enum DatasetLabelValue {
DRAFT = 'Draft',
UNPUBLISHED = 'Unpublished',
DEACCESSIONED = 'Deaccessioned',
EMBARGOED = 'Embargoed',
IN_REVIEW = 'In Review'
}
export class DatasetLabel {
constructor(
public readonly semanticMeaning: DatasetLabelSemanticMeaning,
public readonly value: DatasetLabelValue | `Version ${string}`
) {}
}
// Only for testing purposes and checking the existence of the citation block in some parts of the code
export enum MetadataBlockName {
CITATION = 'citation',
GEOSPATIAL = 'geospatial',
ASTROPHYSICS = 'astrophysics',
BIOMEDICAL = 'biomedical',
CODE_META = 'codeMeta20',
COMPUTATIONAL_WORKFLOW = 'computationalworkflow',
JOURNAL = 'journal',
SOCIAL_SCIENCE = 'socialscience'
}
export type DatasetMetadataBlocks = [CitationMetadataBlock, ...DatasetMetadataBlock[]]
export interface DatasetMetadataBlock {
name: string
fields: DatasetMetadataFields
}
export type DatasetMetadataFields = Record<string, DatasetMetadataFieldValue>
export const ANONYMIZED_FIELD_VALUE = 'withheld'
type AnonymizedField = typeof ANONYMIZED_FIELD_VALUE
export type DatasetMetadataFieldValue =
| string
| string[]
| DatasetMetadataSubField
| DatasetMetadataSubField[]
| AnonymizedField
export type DatasetMetadataSubField = Record<string, string | undefined>
export interface CitationMetadataBlock extends DatasetMetadataBlock {
name: string // 'citation'
fields: {
alternativePersistentId?: string
publicationDate?: string
citationDate?: string
title: string
author: Author[] | AnonymizedField
datasetContact: DatasetContact[] | AnonymizedField
dsDescription: DatasetDescription[] | AnonymizedField
subject: string[] | AnonymizedField
subtitle?: string
alternativeTitle?: string
alternativeURL?: string
otherId?: OtherId[] | AnonymizedField
keyword?: Keyword[] | AnonymizedField
topicClassification?: TopicClassification[] | AnonymizedField
publication?: Publication[] | AnonymizedField
notesText?: string
language?: string[] | AnonymizedField
producer?: Producer[] | AnonymizedField
productionDate?: string
productionPlace?: string[] | AnonymizedField
contributor?: Contributor[] | AnonymizedField
grantNumber?: GrantNumber[] | AnonymizedField
distributor?: Distributor[] | AnonymizedField
distributionDate?: string
depositor?: string
dateOfDeposit?: string
timePeriodCovered?: TimePeriodCovered[] | AnonymizedField
dateOfCollection?: DateOfCollection[] | AnonymizedField
kindOfData?: string[] | AnonymizedField
series?: Series[] | AnonymizedField
software?: Software[] | AnonymizedField
relatedMaterial?: string[] | AnonymizedField
relatedDatasets?: string[] | AnonymizedField
otherReferences?: string[] | AnonymizedField
dataSources?: string[] | AnonymizedField
originOfSources?: string
characteristicOfSources?: string
accessToSources?: string
}
}
interface OtherId extends DatasetMetadataSubField {
otherIdAgency?: string
otherIdValue?: string
}
export interface Author extends DatasetMetadataSubField {
authorName: string
authorAffiliation: string
authorIdentifierScheme?: string
authorIdentifier?: string
}
export interface DatasetContact extends DatasetMetadataSubField {
datasetContactName: string
datasetContactEmail: string
datasetContactAffiliation?: string
}
export interface DatasetDescription extends DatasetMetadataSubField {
dsDescriptionValue: string
dsDescriptionDate?: string
}
interface Keyword extends DatasetMetadataSubField {
keywordValue?: string
keywordVocabulary?: string
keywordVocabularyURI?: string
}
interface TopicClassification extends DatasetMetadataSubField {
topicClassValue?: string
topicClassVocab?: string
topicClassVocabURI?: string
}
interface Publication extends DatasetMetadataSubField {
publicationCitation?: string
publicationIDType?: string
publicationIDNumber?: string
publicationURL?: string
}
interface Producer extends DatasetMetadataSubField {
producerName?: string
producerAffiliation?: string
producerAbbreviation?: string
producerURL?: string
producerLogoURL?: string
}
interface Contributor extends DatasetMetadataSubField {
contributorType?: string
contributorName?: string
}
interface GrantNumber extends DatasetMetadataSubField {
grantNumberAgency?: string
grantNumberValue?: string
}
interface Distributor extends DatasetMetadataSubField {
distributorName?: string
distributorAffiliation?: string
distributorAbbreviation?: string
distributorURL?: string
distributorLogoURL?: string
}
interface TimePeriodCovered extends DatasetMetadataSubField {
timePeriodCoveredStart?: string
timePeriodCoveredEnd?: string
}
interface DateOfCollection extends DatasetMetadataSubField {
dateOfCollectionStart?: string
dateOfCollectionEnd?: string
}
interface Series extends DatasetMetadataSubField {
seriesName?: string
seriesInformation?: string
}
interface Software extends DatasetMetadataSubField {
softwareName?: string
softwareVersion?: string
}
export type DatasetLicense = Pick<License, 'name' | 'uri' | 'iconUri'>
export const defaultLicense: DatasetLicense = {
name: 'CC0 1.0',
uri: 'https://creativecommons.org/publicdomain/zero/1.0',
iconUri: 'https://licensebuttons.net/p/zero/1.0/88x31.png'
}
export enum DatasetPublishingStatus {
RELEASED = 'released',
DRAFT = 'draft',
DEACCESSIONED = 'deaccessioned',
EMBARGOED = 'embargoed'
}
export enum DatasetNonNumericVersion {
LATEST = ':latest',
DRAFT = ':draft',
LATEST_PUBLISHED = ':latest-published'
}
export enum DatasetNonNumericVersionSearchParam {
DRAFT = 'DRAFT'
}
export enum DatasetVersionState {
DRAFT = 'DRAFT',
RELEASED = 'RELEASED',
ARCHIVED = 'ARCHIVED',
DEACCESSIONED = 'DEACCESSIONED'
}
export class DatasetVersionNumber {
constructor(public readonly majorNumber?: number, public readonly minorNumber?: number) {}
toString(): string | DatasetNonNumericVersion {
if (this.majorNumber === undefined || this.minorNumber === undefined) {
return DatasetNonNumericVersion.DRAFT
}
return `${this.majorNumber}.${this.minorNumber}`
}
toSearchParam(): string {
if (this.majorNumber === undefined || this.minorNumber === undefined) {
return DatasetNonNumericVersionSearchParam.DRAFT
}
return this.toString()
}
}
export class DatasetVersion {
constructor(
public readonly id: number,
public readonly title: string,
public readonly number: DatasetVersionNumber,
public readonly publishingStatus: DatasetPublishingStatus,
public readonly citation: string,
public readonly labels: DatasetLabel[],
public readonly isLatest: boolean,
public readonly isInReview: boolean,
public readonly latestVersionPublishingStatus: DatasetPublishingStatus,
public readonly someDatasetVersionHasBeenReleased: boolean,
/**
* The timestamp of the last update to this dataset version.
* Format: ISO 8601 string (e.g., "2023-06-01T12:34:56Z").
* Used for optimistic concurrency control to detect concurrent updates.
*/
public readonly lastUpdateTime: string,
public readonly termsOfAccess?: TermsOfAccess,
public readonly deaccessionNote?: string
) {}
static Builder = class {
public readonly labels: DatasetLabel[] = []
constructor(
public readonly id: number,
public readonly title: string,
public readonly number: DatasetVersionNumber,
public readonly publishingStatus: DatasetPublishingStatus,
public readonly citation: string,
public readonly isLatest: boolean,
public readonly isInReview: boolean,
public readonly latestVersionPublishingStatus: DatasetPublishingStatus,
public readonly someDatasetVersionHasBeenReleased: boolean,
public readonly lastUpdateTime: string,
public readonly termsOfAccess?: TermsOfAccess,
public readonly deaccessionNote?: string
) {
this.createLabels()
}
createLabels() {
const statusLabels = this.createStatusLabels()
const versionLabels = this.createVersionNumberLabel()
this.labels.push(...statusLabels, ...versionLabels)
}
createStatusLabels(): DatasetLabel[] {
const labels: DatasetLabel[] = []
if (this.publishingStatus === DatasetPublishingStatus.DRAFT) {
labels.push(new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.DRAFT))
}
if (!this.someDatasetVersionHasBeenReleased) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.WARNING, DatasetLabelValue.UNPUBLISHED)
)
}
if (this.publishingStatus === DatasetPublishingStatus.DEACCESSIONED) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DANGER, DatasetLabelValue.DEACCESSIONED)
)
}
if (this.publishingStatus === DatasetPublishingStatus.EMBARGOED) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.DATASET, DatasetLabelValue.EMBARGOED)
)
}
if (this.isInReview) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.SUCCESS, DatasetLabelValue.IN_REVIEW)
)
}
return labels
}
createVersionNumberLabel(): DatasetLabel[] {
const labels: DatasetLabel[] = []
if (this.publishingStatus === DatasetPublishingStatus.RELEASED) {
labels.push(
new DatasetLabel(DatasetLabelSemanticMeaning.FILE, `Version ${this.number.toString()}`)
)
}
return labels
}
build(): DatasetVersion {
return new DatasetVersion(
this.id,
this.title,
this.number,
this.publishingStatus,
this.citation,
this.labels,
this.isLatest,
this.isInReview,
this.latestVersionPublishingStatus,
this.someDatasetVersionHasBeenReleased,
this.lastUpdateTime,
this.termsOfAccess,
this.deaccessionNote
)
}
}
}
export interface DatasetPermissions {
canDownloadFiles: boolean
canUpdateDataset: boolean
canPublishDataset: boolean
canManageDatasetPermissions: boolean
canManageFilesPermissions: boolean
canDeleteDataset: boolean
}
export interface DatasetLock {
userPersistentId: string
reason: DatasetLockReason
}
export enum DatasetLockReason {
INGEST = 'Ingest',
WORKFLOW = 'Workflow',
IN_REVIEW = 'InReview',
DCM_UPLOAD = 'DcmUpload',
GLOBUS_UPLOAD = 'GlobusUpload',
FINALIZE_PUBLICATION = 'finalizePublication',
EDIT_IN_PROGRESS = 'EditInProgress',
FILE_VALIDATION_FAILED = 'FileValidationFailed'
}
export interface PrivateUrl {
token: string
urlSnippet: string
}
export interface DatasetDownloadUrls {
original: string
archival: string
}
export interface TermsOfAccess {
fileAccessRequest: boolean
termsOfAccessForRestrictedFiles?: string
dataAccessPlace?: string
originalArchive?: string
availabilityStatus?: string
contactForAccess?: string
sizeOfCollection?: string
studyCompletion?: string
}
export interface CustomTerms {
termsOfUse: string
confidentialityDeclaration?: string
specialPermissions?: string
restrictions?: string
citationRequirements?: string
depositorRequirements?: string
conditions?: string
disclaimer?: string
}
export interface DatasetTermsOfUse {
termsOfAccess: TermsOfAccess
customTerms?: CustomTerms
}
export class Dataset {
constructor(
public readonly id: number,
public readonly persistentId: string,
public readonly version: DatasetVersion,
public readonly internalVersionNumber: number,
public readonly alerts: Alert[],
public readonly summaryFields: DatasetMetadataBlock[],
public readonly termsOfUse: DatasetTermsOfUse,
public readonly metadataBlocks: DatasetMetadataBlocks,
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly hasOneTabularFileAtLeast: boolean,
public readonly isValid: boolean,
public readonly downloadUrls: DatasetDownloadUrls,
public readonly fileDownloadSizes: FileDownloadSize[],
public readonly hierarchy: UpwardHierarchyNode,
public readonly license?: DatasetLicense,
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl, // will be set if the user requested a version that did not exist
public readonly requestedVersion?: string,
public readonly publicationDate?: string,
public readonly nextMajorVersion?: string,
public readonly nextMinorVersion?: string,
public readonly requiresMajorVersionUpdate?: boolean,
public readonly fileStore?: string,
public readonly datasetType?: string
) {}
public checkIsLockedFromPublishing(userPersistentId: string): boolean {
return this.checkIsLockedFromEdits(userPersistentId)
}
public get isLocked(): boolean {
return this.locks.length > 0
}
public get isLockedInWorkflow(): boolean {
return this.locks.some((lock) => lock.reason === DatasetLockReason.WORKFLOW)
}
public get parentCollectionNode(): UpwardHierarchyNode {
return this.hierarchy
.toArray()
.filter((item) => item.type === 'collection')
.at(-1) as UpwardHierarchyNode
}
public checkIsLockedFromEdits(userPersistentId: string): boolean {
const lockedReasonIsInReview = this.locks.some(
(lock) => lock.reason === DatasetLockReason.IN_REVIEW
)
if (
this.locks.some(
(lock) =>
lock.reason === DatasetLockReason.WORKFLOW && lock.userPersistentId === userPersistentId
)
) {
return false
}
return this.isLocked && !(lockedReasonIsInReview && this.permissions.canPublishDataset)
}
public get isLockedFromFileDownload(): boolean {
if (!this.isLocked) {
return false
}
if (
this.locks.some((lock) =>
[
DatasetLockReason.FINALIZE_PUBLICATION,
DatasetLockReason.DCM_UPLOAD,
DatasetLockReason.INGEST
].includes(lock.reason)
)
) {
return true
}
if (
this.locks.some((lock) => lock.reason === DatasetLockReason.IN_REVIEW) &&
!this.permissions.canUpdateDataset
) {
return true
}
// If the lock reason is workflow and the workflow userId is different than the current user, then is locked
// TODO - Ask how we want to manage pending workflows
return false
}
static Builder = class {
public readonly alerts: Alert[] = []
constructor(
public readonly id: number,
public readonly persistentId: string,
public readonly version: DatasetVersion,
public readonly internalVersionNumber: number,
public readonly summaryFields: DatasetMetadataBlock[],
public readonly termsOfUse: DatasetTermsOfUse,
public readonly metadataBlocks: DatasetMetadataBlocks,
public readonly permissions: DatasetPermissions,
public readonly locks: DatasetLock[],
public readonly hasValidTermsOfAccess: boolean,
public readonly hasOneTabularFileAtLeast: boolean,
public readonly isValid: boolean,
public readonly downloadUrls: DatasetDownloadUrls,
public readonly fileDownloadSizes: FileDownloadSize[],
public readonly hierarchy: UpwardHierarchyNode,
public readonly license?: DatasetLicense,
public readonly thumbnail?: string,
public readonly privateUrl?: PrivateUrl, // will be set if the user requested a version that did not exist
public readonly requestedVersion?: string,
public readonly nextMajorVersionNumber?: string,
public readonly nextMinorVersionNumber?: string,
public readonly requiresMajorVersionUpdate?: boolean,
public readonly fileStore?: string,
public readonly datasetType?: string
) {
this.withAlerts()
}
private withAlerts(): void {
if (
this.version.publishingStatus === DatasetPublishingStatus.DRAFT &&
this.permissions.canPublishDataset
) {
this.alerts.push(new Alert('warning', AlertMessageKey.DRAFT_VERSION))
}
if (this.requestedVersion) {
if (this.version.latestVersionPublishingStatus == DatasetPublishingStatus.RELEASED) {
const dynamicFields = {
requestedVersion: this.requestedVersion,
returnedVersion: `${this.version.number.toString()}`
}
this.alerts.push(
new Alert('warning', AlertMessageKey.REQUESTED_VERSION_NOT_FOUND, dynamicFields)
)
} else {
const dynamicFields = {
requestedVersion: this.requestedVersion
}
this.alerts.push(
new Alert(
'warning',
AlertMessageKey.REQUESTED_VERSION_NOT_FOUND_SHOW_DRAFT,
dynamicFields
)
)
}
}
if (this.privateUrl) {
if (this.permissions.canPublishDataset) {
const dynamicFields = { privateUrl: this.privateUrl.urlSnippet + this.privateUrl.token }
this.alerts.push(
new Alert('info', AlertMessageKey.SHARE_UNPUBLISHED_DATASET, dynamicFields)
)
} else {
this.alerts.push(new Alert('warning', AlertMessageKey.UNPUBLISHED_DATASET))
}
}
}
build(): Dataset {
return new Dataset(
this.id,
this.persistentId,
this.version,
this.internalVersionNumber,
this.alerts,
this.summaryFields,
this.termsOfUse,
this.metadataBlocks,
this.permissions,
this.locks,
this.hasValidTermsOfAccess,
this.hasOneTabularFileAtLeast,
this.isValid,
this.downloadUrls,
this.fileDownloadSizes,
this.hierarchy,
this.license,
this.thumbnail,
this.privateUrl,
this.requestedVersion,
undefined,
this.nextMajorVersionNumber,
this.nextMinorVersionNumber,
this.requiresMajorVersionUpdate,
this.fileStore,
this.datasetType
)
}
}
}