Skip to content

Commit 2b58ce3

Browse files
authored
Merge pull request #441 from IQSS/add_metadata_block
Addition of AllowedDatasetTypes to Collection
2 parents dc2cd4e + 6ec0b23 commit 2b58ce3

7 files changed

Lines changed: 68 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel
88

99
### Added
1010

11+
- Collections: Added `allowedDatasetTypes` field to the [Collection](./src/collections/domain/models/Collection.ts) model. This field is optional and only populated the feature is enabled on the installation and configured on the collection.
12+
1113
### Changed
1214

1315
### Fixed

docs/useCases.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ The `collectionIdOrAlias` is a generic collection identifier, which can be eithe
197197

198198
If no collection identifier is specified, the default collection identifier; `:root` will be used. If you want to search for a different collection, you must add the collection identifier as a parameter in the use case call.
199199

200+
##### Collection Allowed Dataset Types
201+
202+
Collections can optionally restrict which [DatasetType](../src/datasets/domain/models/DatasetType.ts) objects can be created within them. The `allowedDatasetTypes` field contains an array of dataset types allowed on the collection when configured. If not configured on the collection, this field will be `undefined`.
203+
204+
```typescript
205+
getCollection.execute('myCollection').then((collection: Collection) => {
206+
if (collection.allowedDatasetTypes) {
207+
collection.allowedDatasetTypes.forEach((datasetType) => {
208+
console.log(`Allowed type: ${datasetType.displayName}`)
209+
})
210+
}
211+
})
212+
```
213+
200214
#### Get Collection Storage Driver
201215

202216
Returns a [StorageDriver](../src/core/domain/models/StorageDriver.ts) instance describing the collection's assigned storage driver.

src/collections/domain/models/Collection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DvObjectOwnerNode } from '../../../core'
22
import { CollectionContact } from './CollectionContact'
33
import { CollectionType } from './CollectionType'
4+
import { DatasetType } from '../../../datasets'
45

56
export interface Collection {
67
id: number
@@ -13,6 +14,7 @@ export interface Collection {
1314
inputLevels?: CollectionInputLevel[]
1415
type: CollectionType
1516
contacts?: CollectionContact[]
17+
allowedDatasetTypes?: DatasetType[]
1618
isMetadataBlockRoot: boolean
1719
isFacetRoot: boolean
1820
childCount: number

src/collections/infra/repositories/transformers/CollectionPayload.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface CollectionPayload {
1010
isPartOf: OwnerNodePayload
1111
inputLevels?: CollectionInputLevelPayload[]
1212
dataverseContacts?: CollectionContactPayload[]
13+
allowedDatasetTypes?: AllowedDatasetTypePayload[]
1314
dataverseType: string
1415
isMetadataBlockRoot: boolean
1516
isFacetRoot: boolean
@@ -26,3 +27,10 @@ export interface CollectionContactPayload {
2627
contactEmail: string
2728
displayOrder: number
2829
}
30+
31+
export interface AllowedDatasetTypePayload {
32+
id: number
33+
name: string
34+
displayName: string
35+
description?: string
36+
}

src/collections/infra/repositories/transformers/collectionTransformers.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { AxiosResponse } from 'axios'
33
import {
44
CollectionContactPayload,
55
CollectionInputLevelPayload,
6-
CollectionPayload
6+
CollectionPayload,
7+
AllowedDatasetTypePayload
78
} from './CollectionPayload'
89
import { transformPayloadToOwnerNode } from '../../../../core/infra/repositories/transformers/dvObjectOwnerNodeTransformer'
910
import { CollectionFacet } from '../../../domain/models/CollectionFacet'
@@ -13,7 +14,7 @@ import {
1314
CollectionItemSubset,
1415
CountPerObjectType
1516
} from '../../../domain/models/CollectionItemSubset'
16-
import { DatasetPreview } from '../../../../datasets'
17+
import { DatasetPreview, DatasetType } from '../../../../datasets'
1718
import { FilePreview } from '../../../../files'
1819
import { DatasetPreviewPayload } from '../../../../datasets/infra/repositories/transformers/DatasetPreviewPayload'
1920
import { FilePreviewPayload } from '../../../../files/infra/repositories/transformers/FilePreviewPayload'
@@ -82,6 +83,11 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
8283
}),
8384
...(collectionPayload.dataverseContacts && {
8485
contacts: transformContactsPayloadToContacts(collectionPayload.dataverseContacts)
86+
}),
87+
...(collectionPayload.allowedDatasetTypes && {
88+
allowedDatasetTypes: transformAllowedDatasetTypesPayloadToAllowedDatasetTypes(
89+
collectionPayload.allowedDatasetTypes
90+
)
8591
})
8692
}
8793
return collectionModel
@@ -252,3 +258,14 @@ const transformContactsPayloadToContacts = (
252258
displayOrder: contactPayload.displayOrder
253259
}))
254260
}
261+
262+
const transformAllowedDatasetTypesPayloadToAllowedDatasetTypes = (
263+
allowedDatasetTypesPayload: AllowedDatasetTypePayload[]
264+
): DatasetType[] => {
265+
return allowedDatasetTypesPayload.map((allowedDatasetType) => ({
266+
id: allowedDatasetType.id,
267+
name: allowedDatasetType.name,
268+
displayName: allowedDatasetType.displayName,
269+
description: allowedDatasetType.description
270+
}))
271+
}

test/integration/collections/CollectionsRepository.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ describe('CollectionsRepository', () => {
176176
expect(actualAfterDatasetDeletion.childCount).toBe(0)
177177
await deleteCollectionViaApi(parentCollectionAlias)
178178
})
179+
180+
test('should transform allowedDatasetTypes correctly when retrieving a collection', async () => {
181+
const actual = await sut.getCollection(testCollectionAlias)
182+
expect(
183+
actual.allowedDatasetTypes === undefined || Array.isArray(actual.allowedDatasetTypes)
184+
).toBe(true)
185+
})
179186
})
180187

181188
describe('publishCollection', () => {

test/testHelpers/collections/collectionHelper.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export const createCollectionModel = (): Collection => {
4545
displayOrder: 0
4646
}
4747
],
48+
allowedDatasetTypes: [
49+
{
50+
id: 1,
51+
name: 'review',
52+
displayName: 'Review',
53+
description: 'A review of a dataset compiled by the expert community.'
54+
}
55+
],
4856
isMetadataBlockRoot: true,
4957
isFacetRoot: true,
5058
childCount: 0
@@ -75,6 +83,14 @@ export const createCollectionPayload = (): CollectionPayload => {
7583
displayOrder: 0
7684
}
7785
],
86+
allowedDatasetTypes: [
87+
{
88+
id: 1,
89+
name: 'review',
90+
displayName: 'Review',
91+
description: 'A review of a dataset compiled by the expert community.'
92+
}
93+
],
7894
isMetadataBlockRoot: true,
7995
isFacetRoot: true,
8096
childCount: 0

0 commit comments

Comments
 (0)