-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
122 - Extend dataset and file models to contain owner information #127
Changes from 5 commits
d7d36e9
6317a48
b41e007
6b4bdbc
93136da
44ad250
ca4a9bc
d195dd3
8f8a1eb
31499d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { FilePayload } from '../../../../files/infra/repositories/transformers/FilePayload'; | ||
import { OwnerNodePayload } from '../../../../dv-object/infra/repositories/transformers/OwnerNodePayload'; | ||
|
||
export interface DatasetPayload { | ||
datasetId: number; | ||
datasetPersistentId: string; | ||
id: number; | ||
versionNumber: number; | ||
versionMinorNumber: number; | ||
versionState: string; | ||
createTime: string; | ||
lastUpdateTime: string; | ||
releaseTime: string; | ||
metadataBlocks: MetadataBlocksPayload; | ||
license?: LicensePayload; | ||
alternativePersistentId?: string; | ||
publicationDate?: string; | ||
citationDate?: string; | ||
files: FilePayload[]; | ||
isPartOf: OwnerNodePayload; | ||
} | ||
|
||
export interface LicensePayload { | ||
name: string; | ||
uri: string; | ||
iconUri?: string; | ||
} | ||
|
||
export interface MetadataBlocksPayload { | ||
[blockName: string]: MetadataBlockPayload; | ||
} | ||
|
||
export interface MetadataBlockPayload { | ||
name: string; | ||
fields: MetadataFieldPayload[]; | ||
} | ||
|
||
export interface MetadataFieldPayload { | ||
typeName: string; | ||
value: MetadataFieldValuePayload; | ||
typeClass: string; | ||
multiple: boolean; | ||
} | ||
|
||
export type MetadataFieldValuePayload = | ||
| string | ||
| string[] | ||
| MetadataSubfieldValuePayload | ||
| MetadataSubfieldValuePayload[]; | ||
|
||
export interface MetadataSubfieldValuePayload { | ||
[key: string]: { value: string; typeName: string; multiple: boolean; typeClass: string }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,28 @@ import { | |
DatasetMetadataFieldValue, | ||
DatasetLicense, | ||
DatasetMetadataBlocks, | ||
ANONYMIZED_FIELD_VALUE, | ||
} from '../../../domain/models/Dataset'; | ||
import { AxiosResponse } from 'axios'; | ||
import TurndownService from 'turndown'; | ||
import { | ||
DatasetPayload, | ||
LicensePayload, | ||
MetadataBlocksPayload, | ||
MetadataSubfieldValuePayload, | ||
MetadataFieldPayload, | ||
MetadataFieldValuePayload, | ||
} from './DatasetPayload'; | ||
import { transformPayloadToOwnerNode } from '../../../../dv-object/infra/repositories/transformers/dvObjectOwnerNodeTransformer'; | ||
|
||
const turndownService = new TurndownService(); | ||
|
||
export const transformVersionResponseToDataset = (response: AxiosResponse): Dataset => { | ||
const versionPayload = response.data.data; | ||
return transformVersionPayloadToDataset(versionPayload); | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const transformVersionPayloadToDataset = (versionPayload: any): Dataset => { | ||
|
||
const transformVersionPayloadToDataset = (versionPayload: DatasetPayload): Dataset => { | ||
const datasetModel: Dataset = { | ||
id: versionPayload.datasetId, | ||
persistentId: versionPayload.datasetPersistentId, | ||
|
@@ -31,6 +41,7 @@ const transformVersionPayloadToDataset = (versionPayload: any): Dataset => { | |
releaseTime: new Date(versionPayload.releaseTime), | ||
}, | ||
metadataBlocks: transformPayloadToDatasetMetadataBlocks(versionPayload.metadataBlocks), | ||
isPartOf: transformPayloadToOwnerNode(versionPayload.isPartOf), | ||
}; | ||
if ('license' in versionPayload) { | ||
datasetModel.license = transformPayloadToDatasetLicense(versionPayload.license); | ||
|
@@ -46,8 +57,8 @@ const transformVersionPayloadToDataset = (versionPayload: any): Dataset => { | |
} | ||
return datasetModel; | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const transformPayloadToDatasetLicense = (licensePayload: any): DatasetLicense => { | ||
|
||
const transformPayloadToDatasetLicense = (licensePayload: LicensePayload): DatasetLicense => { | ||
const datasetLicense: DatasetLicense = { | ||
name: licensePayload.name, | ||
uri: licensePayload.uri, | ||
|
@@ -58,49 +69,64 @@ const transformPayloadToDatasetLicense = (licensePayload: any): DatasetLicense = | |
} | ||
return datasetLicense; | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const transformPayloadToDatasetMetadataBlocks = (metadataBlocksPayload: any): DatasetMetadataBlocks => { | ||
|
||
const transformPayloadToDatasetMetadataBlocks = ( | ||
metadataBlocksPayload: MetadataBlocksPayload, | ||
): DatasetMetadataBlocks => { | ||
return Object.keys(metadataBlocksPayload).map((metadataBlockKey) => { | ||
const metadataBlock = metadataBlocksPayload[metadataBlockKey]; | ||
return { | ||
name: metadataBlockKey, | ||
fields: transformPayloadToDatasetMetadataFields(metadataBlocksPayload[metadataBlockKey].fields), | ||
name: metadataBlock.name, | ||
fields: transformPayloadToDatasetMetadataFields(metadataBlock.fields), | ||
}; | ||
}) as DatasetMetadataBlocks; | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const transformPayloadToDatasetMetadataFields = (metadataFieldsPayload: any): DatasetMetadataFields => { | ||
const metadataFieldKeys = Object.keys(metadataFieldsPayload); | ||
const metadataFields: DatasetMetadataFields = {}; | ||
for (const metadataFieldKey of metadataFieldKeys) { | ||
const metadataField = metadataFieldsPayload[metadataFieldKey]; | ||
const metadataFieldTypeName = metadataField.typeName; | ||
metadataFields[metadataFieldTypeName] = transformPayloadToDatasetMetadataFieldValue(metadataField.value); | ||
} | ||
return metadataFields; | ||
|
||
const transformPayloadToDatasetMetadataFields = ( | ||
metadataFieldsPayload: MetadataFieldPayload[], | ||
): DatasetMetadataFields => { | ||
return metadataFieldsPayload.reduce((acc: DatasetMetadataFields, field: MetadataFieldPayload) => { | ||
acc[field.typeName] = transformPayloadToDatasetMetadataFieldValue(field.value, field.typeClass); | ||
return acc; | ||
}, {}); | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const transformPayloadToDatasetMetadataFieldValue = (metadataFieldValuePayload: any): DatasetMetadataFieldValue => { | ||
let metadataFieldValue: DatasetMetadataFieldValue; | ||
if (Array.isArray(metadataFieldValuePayload)) { | ||
const isArrayOfObjects = typeof metadataFieldValuePayload[0] === 'object'; | ||
if (!isArrayOfObjects) { | ||
metadataFieldValue = metadataFieldValuePayload.map(transformHtmlToMarkdown); | ||
|
||
const transformPayloadToDatasetMetadataFieldValue = ( | ||
metadataFieldValuePayload: MetadataFieldValuePayload, | ||
typeClass: string, | ||
): DatasetMetadataFieldValue => { | ||
function isArrayOfSubfieldValue( | ||
array: (string | MetadataSubfieldValuePayload)[], | ||
): array is MetadataSubfieldValuePayload[] { | ||
return array.length > 0 && typeof array[0] !== 'string'; | ||
} | ||
|
||
if (typeClass === 'anonymized') { | ||
return ANONYMIZED_FIELD_VALUE; | ||
} | ||
|
||
if (typeof metadataFieldValuePayload === 'string') { | ||
return transformHtmlToMarkdown(metadataFieldValuePayload); | ||
} else if (Array.isArray(metadataFieldValuePayload)) { | ||
if (isArrayOfSubfieldValue(metadataFieldValuePayload)) { | ||
return metadataFieldValuePayload.map((v) => transformPayloadToDatasetMetadataSubfieldValue(v)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor detail - Can we rename "v" to something more understandable? |
||
} else { | ||
const datasetMetadataSubfields: DatasetMetadataSubField[] = []; | ||
metadataFieldValuePayload.forEach(function (metadataSubFieldValuePayload) { | ||
const subFieldKeys = Object.keys(metadataSubFieldValuePayload); | ||
const record: DatasetMetadataSubField = {}; | ||
for (const subFieldKey of subFieldKeys) { | ||
record[subFieldKey] = transformHtmlToMarkdown(metadataSubFieldValuePayload[subFieldKey].value); | ||
} | ||
datasetMetadataSubfields.push(record); | ||
}); | ||
metadataFieldValue = datasetMetadataSubfields; | ||
return metadataFieldValuePayload.map(transformHtmlToMarkdown); | ||
} | ||
} else { | ||
metadataFieldValue = transformHtmlToMarkdown(metadataFieldValuePayload); | ||
return transformPayloadToDatasetMetadataSubfieldValue(metadataFieldValuePayload as MetadataSubfieldValuePayload); | ||
} | ||
return metadataFieldValue; | ||
}; | ||
|
||
const transformPayloadToDatasetMetadataSubfieldValue = ( | ||
metadataSubfieldValuePayload: MetadataSubfieldValuePayload, | ||
): DatasetMetadataSubField => { | ||
const result: DatasetMetadataSubField = {}; | ||
Object.keys(metadataSubfieldValuePayload).forEach((key) => { | ||
const subFieldValue = metadataSubfieldValuePayload[key].value; | ||
result[key] = transformHtmlToMarkdown(subFieldValue); | ||
}); | ||
return result; | ||
}; | ||
|
||
const transformHtmlToMarkdown = (source: string): string => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface DvObjectOwnerNode { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think dv-object should be considered as a sub-domain in the package. I would place this file and any other dvObject related file in the core subdomain, as the dvObject is a concept shared across the different subdomains (collections, files and datasets). |
||
type: DvObjectType; | ||
identifier: string; | ||
displayName: string; | ||
isPartOf?: DvObjectOwnerNode; | ||
} | ||
|
||
export enum DvObjectType { | ||
DATAVERSE = 'DATAVERSE', | ||
DATASET = 'DATASET', | ||
FILE = 'FILE', | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { DvObjectOwnerNode } from './domain/models/DvObjectOwnerNode'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface OwnerNodePayload { | ||
type: string; | ||
identifier: string; | ||
displayName: string; | ||
isPartOf?: OwnerNodePayload; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { OwnerNodePayload } from './OwnerNodePayload'; | ||
import { DvObjectOwnerNode, DvObjectType } from '../../../domain/models/DvObjectOwnerNode'; | ||
|
||
export const transformPayloadToOwnerNode = (ownerNodePayload: OwnerNodePayload): DvObjectOwnerNode => { | ||
return { | ||
type: ownerNodePayload.type as DvObjectType, | ||
identifier: ownerNodePayload.identifier, | ||
displayName: ownerNodePayload.displayName, | ||
...(ownerNodePayload.isPartOf && { isPartOf: transformPayloadToOwnerNode(ownerNodePayload.isPartOf) }), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { OwnerNodePayload } from '../../../../dv-object/infra/repositories/transformers/OwnerNodePayload'; | ||
|
||
export interface FilePayload { | ||
dataFile: { | ||
id: number; | ||
persistentId: string; | ||
filename: string; | ||
pidURL?: string; | ||
filesize: number; | ||
version: number; | ||
description?: string; | ||
restricted: boolean; | ||
directoryLabel?: string; | ||
datasetVersionId?: number; | ||
categories?: string[]; | ||
contentType: string; | ||
friendlyType: string; | ||
embargo?: EmbargoPayload; | ||
storageIdentifier?: string; | ||
originalFormat?: string; | ||
originalFormatLabel?: string; | ||
originalSize?: number; | ||
originalName?: string; | ||
UNF?: string; | ||
rootDataFileId?: number; | ||
previousDataFileId?: number; | ||
md5?: string; | ||
checksum?: ChecksumPayload; | ||
fileMetadataId?: number; | ||
tabularTags?: string[]; | ||
creationDate?: string; | ||
publicationDate?: string; | ||
deleted: boolean; | ||
tabularData: boolean; | ||
fileAccessRequest?: boolean; | ||
isPartOf?: OwnerNodePayload; | ||
}; | ||
version: number; | ||
restricted: boolean; | ||
label: string; | ||
datasetVersionId: number; | ||
} | ||
|
||
export interface EmbargoPayload { | ||
dateAvailable: string; | ||
reason?: string; | ||
} | ||
|
||
export interface ChecksumPayload { | ||
type: string; | ||
value: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor detail - Can we rename "acc" to something more understandable? Like
datasetMetadataFieldsResult
or simplyresult
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like
result
because it means finished, but the variable in this case is the accumulator so it's not really the result until the reduce it's finished, I rename it todatasetMetadataFieldsMap
, hope that's ok