From 6b4bdbcc0b0a6fe48e01a08163b02feecf424453 Mon Sep 17 00:00:00 2001 From: MellyGray Date: Thu, 22 Feb 2024 10:21:52 +0100 Subject: [PATCH] fix(Owners): rename owner to isPartOf --- src/datasets/domain/models/Dataset.ts | 4 ++-- src/datasets/domain/useCases/CreateDataset.ts | 4 ++-- .../infra/repositories/DatasetsRepository.ts | 4 +++- .../repositories/transformers/DatasetPayload.ts | 4 ++-- .../transformers/datasetTransformers.ts | 4 ++-- .../transformers/newDatasetTransformers.ts | 6 +++--- .../{DvObjectOwner.ts => DvObjectOwnerNode.ts} | 4 ++-- .../repositories/transformers/OwnerNodePayload.ts | 6 ++++++ .../repositories/transformers/OwnerPayload.ts | 6 ------ .../transformers/dvObjectOwnerNodeTransformer.ts | 11 +++++++++++ .../transformers/dvObjectOwnerTransformer.ts | 11 ----------- src/files/domain/models/File.ts | 4 ++-- .../infra/repositories/transformers/FilePayload.ts | 4 ++-- .../repositories/transformers/fileTransformers.ts | 4 ++-- test/testHelpers/datasets/datasetHelper.ts | 6 +++--- test/testHelpers/files/filesHelper.ts | 14 +++++++------- test/unit/datasets/DatasetsRepository.test.ts | 8 ++++++-- 17 files changed, 55 insertions(+), 49 deletions(-) rename src/dv-object/domain/models/{DvObjectOwner.ts => DvObjectOwnerNode.ts} (70%) create mode 100644 src/dv-object/infra/repositories/transformers/OwnerNodePayload.ts delete mode 100644 src/dv-object/infra/repositories/transformers/OwnerPayload.ts create mode 100644 src/dv-object/infra/repositories/transformers/dvObjectOwnerNodeTransformer.ts delete mode 100644 src/dv-object/infra/repositories/transformers/dvObjectOwnerTransformer.ts diff --git a/src/datasets/domain/models/Dataset.ts b/src/datasets/domain/models/Dataset.ts index 2a7460db..3fdcbb40 100644 --- a/src/datasets/domain/models/Dataset.ts +++ b/src/datasets/domain/models/Dataset.ts @@ -1,4 +1,4 @@ -import { DvObjectOwner } from '../../../dv-object/domain/models/DvObjectOwner'; +import { DvObjectOwnerNode } from '../../../dv-object/domain/models/DvObjectOwnerNode'; export interface Dataset { id: number; @@ -10,7 +10,7 @@ export interface Dataset { publicationDate?: string; citationDate?: string; metadataBlocks: DatasetMetadataBlocks; - owner: DvObjectOwner; + isPartOf: DvObjectOwnerNode; } export interface DatasetVersionInfo { diff --git a/src/datasets/domain/useCases/CreateDataset.ts b/src/datasets/domain/useCases/CreateDataset.ts index ca352d82..1ca28b12 100644 --- a/src/datasets/domain/useCases/CreateDataset.ts +++ b/src/datasets/domain/useCases/CreateDataset.ts @@ -21,14 +21,14 @@ export class CreateDataset implements UseCase { this.newDatasetValidator = newDatasetValidator; } - async execute(newDataset: NewDatasetDTO, collectionId: string = 'root'): Promise { + async execute(newDataset: NewDatasetDTO, collectionId = 'root'): Promise { const metadataBlocks = await this.getNewDatasetMetadataBlocks(newDataset); this.newDatasetValidator.validate(newDataset, metadataBlocks); return this.datasetsRepository.createDataset(newDataset, metadataBlocks, collectionId); } async getNewDatasetMetadataBlocks(newDataset: NewDatasetDTO): Promise { - let metadataBlocks: MetadataBlock[] = []; + const metadataBlocks: MetadataBlock[] = []; await Promise.all( newDataset.metadataBlockValues.map(async (metadataBlockValue: NewDatasetMetadataBlockValuesDTO) => { metadataBlocks.push(await this.metadataBlocksRepository.getMetadataBlockByName(metadataBlockValue.name)); diff --git a/src/datasets/infra/repositories/DatasetsRepository.ts b/src/datasets/infra/repositories/DatasetsRepository.ts index 8560a32a..7ef4f6d1 100644 --- a/src/datasets/infra/repositories/DatasetsRepository.ts +++ b/src/datasets/infra/repositories/DatasetsRepository.ts @@ -30,7 +30,9 @@ export class DatasetsRepository extends ApiRepository implements IDatasetsReposi } public async getPrivateUrlDataset(token: string): Promise { - return this.doGet(this.buildApiEndpoint(this.datasetsResourceName, `privateUrlDatasetVersion/${token}`)) + return this.doGet(this.buildApiEndpoint(this.datasetsResourceName, `privateUrlDatasetVersion/${token}`), false, { + returnOwners: true, + }) .then((response) => transformVersionResponseToDataset(response)) .catch((error) => { throw error; diff --git a/src/datasets/infra/repositories/transformers/DatasetPayload.ts b/src/datasets/infra/repositories/transformers/DatasetPayload.ts index 072e06a5..0eaf0f6c 100644 --- a/src/datasets/infra/repositories/transformers/DatasetPayload.ts +++ b/src/datasets/infra/repositories/transformers/DatasetPayload.ts @@ -1,5 +1,5 @@ import { FilePayload } from '../../../../files/infra/repositories/transformers/FilePayload'; -import { OwnerPayload } from '../../../../dv-object/infra/repositories/transformers/OwnerPayload'; +import { OwnerNodePayload } from '../../../../dv-object/infra/repositories/transformers/OwnerNodePayload'; export interface DatasetPayload { datasetId: number; @@ -17,7 +17,7 @@ export interface DatasetPayload { publicationDate?: string; citationDate?: string; files: FilePayload[]; - owner: OwnerPayload; + isPartOf: OwnerNodePayload; } export interface LicensePayload { diff --git a/src/datasets/infra/repositories/transformers/datasetTransformers.ts b/src/datasets/infra/repositories/transformers/datasetTransformers.ts index 869e23c5..c53f58cb 100644 --- a/src/datasets/infra/repositories/transformers/datasetTransformers.ts +++ b/src/datasets/infra/repositories/transformers/datasetTransformers.ts @@ -18,7 +18,7 @@ import { MetadataFieldPayload, MetadataFieldValuePayload, } from './DatasetPayload'; -import { transformOwnerPayloadToOwner } from '../../../../dv-object/infra/repositories/transformers/dvObjectOwnerTransformer'; +import { transformPayloadToOwnerNode } from '../../../../dv-object/infra/repositories/transformers/dvObjectOwnerNodeTransformer'; const turndownService = new TurndownService(); @@ -41,7 +41,7 @@ const transformVersionPayloadToDataset = (versionPayload: DatasetPayload): Datas releaseTime: new Date(versionPayload.releaseTime), }, metadataBlocks: transformPayloadToDatasetMetadataBlocks(versionPayload.metadataBlocks), - owner: transformOwnerPayloadToOwner(versionPayload.owner), + isPartOf: transformPayloadToOwnerNode(versionPayload.isPartOf), }; if ('license' in versionPayload) { datasetModel.license = transformPayloadToDatasetLicense(versionPayload.license); diff --git a/src/datasets/infra/repositories/transformers/newDatasetTransformers.ts b/src/datasets/infra/repositories/transformers/newDatasetTransformers.ts index 5ae104b5..f69b994c 100644 --- a/src/datasets/infra/repositories/transformers/newDatasetTransformers.ts +++ b/src/datasets/infra/repositories/transformers/newDatasetTransformers.ts @@ -49,7 +49,7 @@ export const transformMetadataBlockModelsToRequestPayload = ( newDatasetMetadataBlocksValues: NewDatasetMetadataBlockValuesDTO[], metadataBlocks: MetadataBlock[], ): Record => { - let metadataBlocksRequestPayload: Record = {}; + const metadataBlocksRequestPayload: Record = {}; newDatasetMetadataBlocksValues.forEach(function (newDatasetMetadataBlockValues: NewDatasetMetadataBlockValuesDTO) { const metadataBlock: MetadataBlock = metadataBlocks.find( (metadataBlock) => metadataBlock.name == newDatasetMetadataBlockValues.name, @@ -69,7 +69,7 @@ export const transformMetadataFieldModelsToRequestPayload = ( newDatasetMetadataFields: NewDatasetMetadataFieldsDTO, metadataBlockFields: Record, ): MetadataFieldRequestPayload[] => { - let metadataFieldsRequestPayload: MetadataFieldRequestPayload[] = []; + const metadataFieldsRequestPayload: MetadataFieldRequestPayload[] = []; for (const metadataFieldKey of Object.keys(newDatasetMetadataFields)) { const newDatasetMetadataChildFieldValue: NewDatasetMetadataFieldValueDTO = newDatasetMetadataFields[metadataFieldKey]; @@ -124,7 +124,7 @@ export const transformMetadataChildFieldValueToRequestPayload = ( newDatasetMetadataChildFieldValue: NewDatasetMetadataChildFieldValueDTO, metadataBlockFieldInfo: MetadataFieldInfo, ): Record => { - let metadataChildFieldRequestPayload: Record = {}; + const metadataChildFieldRequestPayload: Record = {}; for (const metadataChildFieldKey of Object.keys(newDatasetMetadataChildFieldValue)) { const childMetadataFieldInfo: MetadataFieldInfo = metadataBlockFieldInfo.childMetadataFields[metadataChildFieldKey]; const value: string = newDatasetMetadataChildFieldValue[metadataChildFieldKey] as unknown as string; diff --git a/src/dv-object/domain/models/DvObjectOwner.ts b/src/dv-object/domain/models/DvObjectOwnerNode.ts similarity index 70% rename from src/dv-object/domain/models/DvObjectOwner.ts rename to src/dv-object/domain/models/DvObjectOwnerNode.ts index 648e2b88..40a33c26 100644 --- a/src/dv-object/domain/models/DvObjectOwner.ts +++ b/src/dv-object/domain/models/DvObjectOwnerNode.ts @@ -1,8 +1,8 @@ -export interface DvObjectOwner { +export interface DvObjectOwnerNode { type: DvObjectType; identifier: string; displayName: string; - owner?: DvObjectOwner; + isPartOf?: DvObjectOwnerNode; } export enum DvObjectType { diff --git a/src/dv-object/infra/repositories/transformers/OwnerNodePayload.ts b/src/dv-object/infra/repositories/transformers/OwnerNodePayload.ts new file mode 100644 index 00000000..882c7bf9 --- /dev/null +++ b/src/dv-object/infra/repositories/transformers/OwnerNodePayload.ts @@ -0,0 +1,6 @@ +export interface OwnerNodePayload { + type: string; + identifier: string; + displayName: string; + isPartOf?: OwnerNodePayload; +} diff --git a/src/dv-object/infra/repositories/transformers/OwnerPayload.ts b/src/dv-object/infra/repositories/transformers/OwnerPayload.ts deleted file mode 100644 index 502e5783..00000000 --- a/src/dv-object/infra/repositories/transformers/OwnerPayload.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface OwnerPayload { - type: string; - identifier: string; - displayName: string; - owner?: OwnerPayload; -} diff --git a/src/dv-object/infra/repositories/transformers/dvObjectOwnerNodeTransformer.ts b/src/dv-object/infra/repositories/transformers/dvObjectOwnerNodeTransformer.ts new file mode 100644 index 00000000..c96cebd8 --- /dev/null +++ b/src/dv-object/infra/repositories/transformers/dvObjectOwnerNodeTransformer.ts @@ -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) }), + }; +}; diff --git a/src/dv-object/infra/repositories/transformers/dvObjectOwnerTransformer.ts b/src/dv-object/infra/repositories/transformers/dvObjectOwnerTransformer.ts deleted file mode 100644 index 0b694598..00000000 --- a/src/dv-object/infra/repositories/transformers/dvObjectOwnerTransformer.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { OwnerPayload } from '../../../../dv-object/infra/repositories/transformers/OwnerPayload'; -import { DvObjectOwner, DvObjectType } from '../../../domain/models/DvObjectOwner'; - -export const transformOwnerPayloadToOwner = (ownerPayload: OwnerPayload): DvObjectOwner => { - return { - type: ownerPayload.type as DvObjectType, - identifier: ownerPayload.identifier, - displayName: ownerPayload.displayName, - ...(ownerPayload.owner && { owner: transformOwnerPayloadToOwner(ownerPayload.owner) }), - }; -}; diff --git a/src/files/domain/models/File.ts b/src/files/domain/models/File.ts index d9d01f04..eb2d791e 100644 --- a/src/files/domain/models/File.ts +++ b/src/files/domain/models/File.ts @@ -1,4 +1,4 @@ -import { DvObjectOwner } from '../../../dv-object/domain/models/DvObjectOwner'; +import { DvObjectOwnerNode } from '../../../dv-object/domain/models/DvObjectOwnerNode'; export interface File { id: number; @@ -33,7 +33,7 @@ export interface File { deleted: boolean; tabularData: boolean; fileAccessRequest?: boolean; - owner?: DvObjectOwner; + isPartOf?: DvObjectOwnerNode; } export interface FileEmbargo { diff --git a/src/files/infra/repositories/transformers/FilePayload.ts b/src/files/infra/repositories/transformers/FilePayload.ts index 5b4ddc23..f457d205 100644 --- a/src/files/infra/repositories/transformers/FilePayload.ts +++ b/src/files/infra/repositories/transformers/FilePayload.ts @@ -1,4 +1,4 @@ -import { OwnerPayload } from '../../../../dv-object/infra/repositories/transformers/OwnerPayload'; +import { OwnerNodePayload } from '../../../../dv-object/infra/repositories/transformers/OwnerNodePayload'; export interface FilePayload { dataFile: { @@ -33,7 +33,7 @@ export interface FilePayload { deleted: boolean; tabularData: boolean; fileAccessRequest?: boolean; - owner?: OwnerPayload; + isPartOf?: OwnerNodePayload; }; version: number; restricted: boolean; diff --git a/src/files/infra/repositories/transformers/fileTransformers.ts b/src/files/infra/repositories/transformers/fileTransformers.ts index 50c1a59e..50169e1d 100644 --- a/src/files/infra/repositories/transformers/fileTransformers.ts +++ b/src/files/infra/repositories/transformers/fileTransformers.ts @@ -2,7 +2,7 @@ import { File, FileEmbargo, FileChecksum } from '../../../domain/models/File'; import { AxiosResponse } from 'axios'; import { FilesSubset } from '../../../domain/models/FilesSubset'; import { ChecksumPayload, EmbargoPayload, FilePayload } from './FilePayload'; -import { transformOwnerPayloadToOwner } from '../../../../dv-object/infra/repositories/transformers/dvObjectOwnerTransformer'; +import { transformPayloadToOwnerNode } from '../../../../dv-object/infra/repositories/transformers/dvObjectOwnerNodeTransformer'; export const transformFilesResponseToFilesSubset = (response: AxiosResponse): FilesSubset => { const filesPayload = response.data.data; @@ -58,7 +58,7 @@ const transformFilePayloadToFile = (filePayload: FilePayload): File => { deleted: filePayload.dataFile.deleted, tabularData: filePayload.dataFile.tabularData, ...(filePayload.dataFile.fileAccessRequest && { fileAccessRequest: filePayload.dataFile.fileAccessRequest }), - ...(filePayload.dataFile.owner && { owner: transformOwnerPayloadToOwner(filePayload.dataFile.owner) }), + ...(filePayload.dataFile.isPartOf && { isPartOf: transformPayloadToOwnerNode(filePayload.dataFile.isPartOf) }), }; }; diff --git a/test/testHelpers/datasets/datasetHelper.ts b/test/testHelpers/datasets/datasetHelper.ts index af398ced..6e2ddf1a 100644 --- a/test/testHelpers/datasets/datasetHelper.ts +++ b/test/testHelpers/datasets/datasetHelper.ts @@ -3,7 +3,7 @@ import TurndownService from 'turndown'; import axios, { AxiosResponse } from 'axios'; import { TestConstants } from '../TestConstants'; import { DatasetPayload } from '../../../src/datasets/infra/repositories/transformers/DatasetPayload'; -import { DvObjectType } from '../../../src/dv-object/domain/models/DvObjectOwner'; +import { DvObjectType } from '../../../src/dv-object/domain/models/DvObjectOwnerNode'; const turndownService = new TurndownService(); @@ -64,7 +64,7 @@ export const createDatasetModel = (license?: DatasetLicense): Dataset => { }, }, ], - owner: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }, + isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }, }; if (license !== undefined) { datasetModel.license = license; @@ -180,7 +180,7 @@ export const createDatasetVersionPayload = (license?: DatasetLicense): DatasetPa }, }, files: [], - owner: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }, + isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }, }; if (license !== undefined) { datasetPayload.license = license; diff --git a/test/testHelpers/files/filesHelper.ts b/test/testHelpers/files/filesHelper.ts index 37159cb2..92d4d8b8 100644 --- a/test/testHelpers/files/filesHelper.ts +++ b/test/testHelpers/files/filesHelper.ts @@ -3,7 +3,7 @@ import axios, { AxiosResponse } from 'axios'; import { TestConstants } from '../TestConstants'; import { readFile } from 'fs/promises'; import { FilesSubset } from '../../../src/files/domain/models/FilesSubset'; -import { DvObjectType } from '../../../src/dv-object/domain/models/DvObjectOwner'; +import { DvObjectType } from '../../../src/dv-object/domain/models/DvObjectOwnerNode'; import { FilePayload } from '../../../src/files/infra/repositories/transformers/FilePayload'; interface FileMetadata { @@ -38,11 +38,11 @@ export const createFileModel = (): File => { deleted: false, tabularData: false, fileAccessRequest: true, - owner: { + isPartOf: { type: DvObjectType.DATASET, - identifier: 'doi:10.5072/FK2/WTBMGC', + identifier: 'doi:10.5072/FK2/HEGZLV&version=DRAFT', displayName: 'First Dataset', - owner: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }, + isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }, }, }; }; @@ -90,11 +90,11 @@ export const createFilePayload = (): FilePayload => { deleted: false, tabularData: false, fileAccessRequest: true, - owner: { + isPartOf: { type: DvObjectType.DATASET, - identifier: 'doi:10.5072/FK2/WTBMGC', + identifier: 'doi:10.5072/FK2/HEGZLV&version=DRAFT', displayName: 'First Dataset', - owner: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }, + isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' }, }, }, }; diff --git a/test/unit/datasets/DatasetsRepository.test.ts b/test/unit/datasets/DatasetsRepository.test.ts index 55698b7f..ff3125a8 100644 --- a/test/unit/datasets/DatasetsRepository.test.ts +++ b/test/unit/datasets/DatasetsRepository.test.ts @@ -213,6 +213,10 @@ describe('DatasetsRepository', () => { }); describe('getPrivateUrlDataset', () => { + const expectedRequestConfig = { + params: { returnOwners: true }, + headers: TestConstants.TEST_EXPECTED_UNAUTHENTICATED_REQUEST_CONFIG.headers, + }; test('should return Dataset when response is successful', async () => { const axiosGetStub = sandbox.stub(axios, 'get').resolves(testDatasetVersionSuccessfulResponse); @@ -221,7 +225,7 @@ describe('DatasetsRepository', () => { assert.calledWithExactly( axiosGetStub, `${TestConstants.TEST_API_URL}/datasets/privateUrlDatasetVersion/${testPrivateUrlToken}`, - TestConstants.TEST_EXPECTED_UNAUTHENTICATED_REQUEST_CONFIG, + expectedRequestConfig, ); assert.match(actual, testDatasetModel); }); @@ -235,7 +239,7 @@ describe('DatasetsRepository', () => { assert.calledWithExactly( axiosGetStub, `${TestConstants.TEST_API_URL}/datasets/privateUrlDatasetVersion/${testPrivateUrlToken}`, - TestConstants.TEST_EXPECTED_UNAUTHENTICATED_REQUEST_CONFIG, + expectedRequestConfig, ); expect(error).to.be.instanceOf(Error); });