-
Notifications
You must be signed in to change notification settings - Fork 8
/
CreateDataset.ts
36 lines (34 loc) · 1.94 KB
/
CreateDataset.ts
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
import { IDatasetsRepository } from '../repositories/IDatasetsRepository'
import { DatasetDTO } from '../dtos/DatasetDTO'
import { ResourceValidator } from '../../../core/domain/useCases/validators/ResourceValidator'
import { IMetadataBlocksRepository } from '../../../metadataBlocks/domain/repositories/IMetadataBlocksRepository'
import { CreatedDatasetIdentifiers } from '../models/CreatedDatasetIdentifiers'
import { ROOT_COLLECTION_ID } from '../../../collections/domain/models/Collection'
import { DatasetWriteUseCase } from './DatasetWriteUseCase'
export class CreateDataset extends DatasetWriteUseCase<CreatedDatasetIdentifiers> {
constructor(
datasetsRepository: IDatasetsRepository,
metadataBlocksRepository: IMetadataBlocksRepository,
newDatasetValidator: ResourceValidator
) {
super(datasetsRepository, metadataBlocksRepository, newDatasetValidator)
}
/**
* Creates a new Dataset in a collection, given a DatasetDTO object and an optional collection identifier, which defaults to :root.
*
* @param {DatasetDTO} [newDataset] - DatasetDTO object including the new dataset metadata field values for each metadata block.
* @param {string} [collectionId] - Specifies the collection identifier where the new dataset should be created (optional, defaults to :root).
* @returns {Promise<CreatedDatasetIdentifiers>}
* @throws {ResourceValidationError} - If there are validation errors related to the provided information.
* @throws {ReadError} - If there are errors while reading data.
* @throws {WriteError} - If there are errors while writing data.
*/
async execute(
newDataset: DatasetDTO,
collectionId = ROOT_COLLECTION_ID
): Promise<CreatedDatasetIdentifiers> {
const metadataBlocks = await this.getNewDatasetMetadataBlocks(newDataset)
this.getNewDatasetValidator().validate(newDataset, metadataBlocks)
return this.getDatasetsRepository().createDataset(newDataset, metadataBlocks, collectionId)
}
}