Skip to content

Commit

Permalink
fix(Owners): rename owner to isPartOf
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Feb 22, 2024
1 parent b41e007 commit 6b4bdbc
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/datasets/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +10,7 @@ export interface Dataset {
publicationDate?: string;
citationDate?: string;
metadataBlocks: DatasetMetadataBlocks;
owner: DvObjectOwner;
isPartOf: DvObjectOwnerNode;
}

export interface DatasetVersionInfo {
Expand Down
4 changes: 2 additions & 2 deletions src/datasets/domain/useCases/CreateDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export class CreateDataset implements UseCase<CreatedDatasetIdentifiers> {
this.newDatasetValidator = newDatasetValidator;
}

async execute(newDataset: NewDatasetDTO, collectionId: string = 'root'): Promise<CreatedDatasetIdentifiers> {
async execute(newDataset: NewDatasetDTO, collectionId = 'root'): Promise<CreatedDatasetIdentifiers> {
const metadataBlocks = await this.getNewDatasetMetadataBlocks(newDataset);
this.newDatasetValidator.validate(newDataset, metadataBlocks);
return this.datasetsRepository.createDataset(newDataset, metadataBlocks, collectionId);
}

async getNewDatasetMetadataBlocks(newDataset: NewDatasetDTO): Promise<MetadataBlock[]> {
let metadataBlocks: MetadataBlock[] = [];
const metadataBlocks: MetadataBlock[] = [];
await Promise.all(
newDataset.metadataBlockValues.map(async (metadataBlockValue: NewDatasetMetadataBlockValuesDTO) => {
metadataBlocks.push(await this.metadataBlocksRepository.getMetadataBlockByName(metadataBlockValue.name));
Expand Down
4 changes: 3 additions & 1 deletion src/datasets/infra/repositories/DatasetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class DatasetsRepository extends ApiRepository implements IDatasetsReposi
}

public async getPrivateUrlDataset(token: string): Promise<Dataset> {
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +17,7 @@ export interface DatasetPayload {
publicationDate?: string;
citationDate?: string;
files: FilePayload[];
owner: OwnerPayload;
isPartOf: OwnerNodePayload;
}

export interface LicensePayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const transformMetadataBlockModelsToRequestPayload = (
newDatasetMetadataBlocksValues: NewDatasetMetadataBlockValuesDTO[],
metadataBlocks: MetadataBlock[],
): Record<string, MetadataBlockRequestPayload> => {
let metadataBlocksRequestPayload: Record<string, MetadataBlockRequestPayload> = {};
const metadataBlocksRequestPayload: Record<string, MetadataBlockRequestPayload> = {};
newDatasetMetadataBlocksValues.forEach(function (newDatasetMetadataBlockValues: NewDatasetMetadataBlockValuesDTO) {
const metadataBlock: MetadataBlock = metadataBlocks.find(
(metadataBlock) => metadataBlock.name == newDatasetMetadataBlockValues.name,
Expand All @@ -69,7 +69,7 @@ export const transformMetadataFieldModelsToRequestPayload = (
newDatasetMetadataFields: NewDatasetMetadataFieldsDTO,
metadataBlockFields: Record<string, MetadataFieldInfo>,
): MetadataFieldRequestPayload[] => {
let metadataFieldsRequestPayload: MetadataFieldRequestPayload[] = [];
const metadataFieldsRequestPayload: MetadataFieldRequestPayload[] = [];
for (const metadataFieldKey of Object.keys(newDatasetMetadataFields)) {
const newDatasetMetadataChildFieldValue: NewDatasetMetadataFieldValueDTO =
newDatasetMetadataFields[metadataFieldKey];
Expand Down Expand Up @@ -124,7 +124,7 @@ export const transformMetadataChildFieldValueToRequestPayload = (
newDatasetMetadataChildFieldValue: NewDatasetMetadataChildFieldValueDTO,
metadataBlockFieldInfo: MetadataFieldInfo,
): Record<string, MetadataFieldRequestPayload> => {
let metadataChildFieldRequestPayload: Record<string, MetadataFieldRequestPayload> = {};
const metadataChildFieldRequestPayload: Record<string, MetadataFieldRequestPayload> = {};
for (const metadataChildFieldKey of Object.keys(newDatasetMetadataChildFieldValue)) {
const childMetadataFieldInfo: MetadataFieldInfo = metadataBlockFieldInfo.childMetadataFields[metadataChildFieldKey];
const value: string = newDatasetMetadataChildFieldValue[metadataChildFieldKey] as unknown as string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface DvObjectOwner {
export interface DvObjectOwnerNode {
type: DvObjectType;
identifier: string;
displayName: string;
owner?: DvObjectOwner;
isPartOf?: DvObjectOwnerNode;
}

export enum DvObjectType {
Expand Down
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;
}
6 changes: 0 additions & 6 deletions src/dv-object/infra/repositories/transformers/OwnerPayload.ts

This file was deleted.

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) }),
};
};

This file was deleted.

4 changes: 2 additions & 2 deletions src/files/domain/models/File.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,7 +33,7 @@ export interface File {
deleted: boolean;
tabularData: boolean;
fileAccessRequest?: boolean;
owner?: DvObjectOwner;
isPartOf?: DvObjectOwnerNode;
}

export interface FileEmbargo {
Expand Down
4 changes: 2 additions & 2 deletions src/files/infra/repositories/transformers/FilePayload.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -33,7 +33,7 @@ export interface FilePayload {
deleted: boolean;
tabularData: boolean;
fileAccessRequest?: boolean;
owner?: OwnerPayload;
isPartOf?: OwnerNodePayload;
};
version: number;
restricted: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/files/infra/repositories/transformers/fileTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) }),
};
};

Expand Down
6 changes: 3 additions & 3 deletions test/testHelpers/datasets/datasetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions test/testHelpers/files/filesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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' },
},
};
};
Expand Down Expand Up @@ -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' },
},
},
};
Expand Down
8 changes: 6 additions & 2 deletions test/unit/datasets/DatasetsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down

0 comments on commit 6b4bdbc

Please sign in to comment.