diff --git a/docs/useCases.md b/docs/useCases.md index 94b36731..60704c23 100644 --- a/docs/useCases.md +++ b/docs/useCases.md @@ -2012,6 +2012,8 @@ The `collectionIdOrAlias` is a generic collection identifier, which can be eithe There is a second optional parameter called `onlyDisplayedOnCreate` which indicates whether or not to return only the metadata blocks that are displayed on dataset creation. The default value is false. +There is a third optional parameter called `datasetType` which will include additional fields from metadata blocks linked to the provided type, if any. Before using this parameter, you will probably want to [list available dataset types](#get-dataset-available-dataset-types) for your installation. + ## Users ### Users read use cases diff --git a/src/metadataBlocks/domain/repositories/IMetadataBlocksRepository.ts b/src/metadataBlocks/domain/repositories/IMetadataBlocksRepository.ts index dd7a802d..7acc63db 100644 --- a/src/metadataBlocks/domain/repositories/IMetadataBlocksRepository.ts +++ b/src/metadataBlocks/domain/repositories/IMetadataBlocksRepository.ts @@ -5,7 +5,8 @@ export interface IMetadataBlocksRepository { getCollectionMetadataBlocks( collectionIdOrAlias: number | string, - onlyDisplayedOnCreate: boolean + onlyDisplayedOnCreate: boolean, + datasetType?: string ): Promise getAllMetadataBlocks(): Promise diff --git a/src/metadataBlocks/domain/useCases/GetCollectionMetadataBlocks.ts b/src/metadataBlocks/domain/useCases/GetCollectionMetadataBlocks.ts index c953c16a..1f71be22 100644 --- a/src/metadataBlocks/domain/useCases/GetCollectionMetadataBlocks.ts +++ b/src/metadataBlocks/domain/useCases/GetCollectionMetadataBlocks.ts @@ -16,15 +16,18 @@ export class GetCollectionMetadataBlocks implements UseCase { * @param {number | string} [collectionIdOrAlias = ':root'] - A generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId) * If this parameter is not set, the default value is: ':root' * @param {boolean} [onlyDisplayedOnCreate=false] - Indicates whether or not to return only the metadata blocks that are displayed on dataset creation. The default value is false. + * @param {string} [datasetType] - The name of the dataset type. If provided, additional fields from metadata blocks linked to this dataset type will be returned. * @returns {Promise} */ async execute( collectionIdOrAlias: number | string = ROOT_COLLECTION_ID, - onlyDisplayedOnCreate = false + onlyDisplayedOnCreate = false, + datasetType?: string ): Promise { return await this.metadataBlocksRepository.getCollectionMetadataBlocks( collectionIdOrAlias, - onlyDisplayedOnCreate + onlyDisplayedOnCreate, + datasetType ) } } diff --git a/src/metadataBlocks/infra/repositories/MetadataBlocksRepository.ts b/src/metadataBlocks/infra/repositories/MetadataBlocksRepository.ts index ab308240..6b4f0287 100644 --- a/src/metadataBlocks/infra/repositories/MetadataBlocksRepository.ts +++ b/src/metadataBlocks/infra/repositories/MetadataBlocksRepository.ts @@ -17,11 +17,13 @@ export class MetadataBlocksRepository extends ApiRepository implements IMetadata public async getCollectionMetadataBlocks( collectionIdOrAlias: string | number, - onlyDisplayedOnCreate: boolean + onlyDisplayedOnCreate: boolean, + datasetType?: string ): Promise { return this.doGet(`/dataverses/${collectionIdOrAlias}/metadatablocks`, true, { onlyDisplayedOnCreate: onlyDisplayedOnCreate, - returnDatasetFieldTypes: true + returnDatasetFieldTypes: true, + datasetType: datasetType }) .then((response) => transformMetadataBlocksResponseToMetadataBlocks(response)) .catch((error) => {