Skip to content

Commit

Permalink
Merge pull request #215 from IQSS/feat/214-extend-get-collection
Browse files Browse the repository at this point in the history
Extend get collection use case
  • Loading branch information
ofahimIQSS authored Nov 22, 2024
2 parents 67d3b0e + 7d31a70 commit d48324a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 18 deletions.
14 changes: 2 additions & 12 deletions src/collections/domain/dtos/CollectionDTO.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CollectionType } from '../models/CollectionType'

export interface CollectionDTO {
alias: string
name: string
Expand All @@ -15,15 +17,3 @@ export interface CollectionInputLevelDTO {
include: boolean
required: boolean
}

export enum CollectionType {
RESEARCHERS = 'RESEARCHERS',
RESEARCH_PROJECTS = 'RESEARCH_PROJECTS',
JOURNALS = 'JOURNALS',
ORGANIZATIONS_INSTITUTIONS = 'ORGANIZATIONS_INSTITUTIONS',
TEACHING_COURSES = 'TEACHING_COURSES',
UNCATEGORIZED = 'UNCATEGORIZED',
LABORATORY = 'LABORATORY',
RESEARCH_GROUP = 'RESEARCH_GROUP',
DEPARTMENT = 'DEPARTMENT'
}
6 changes: 6 additions & 0 deletions src/collections/domain/models/Collection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { DvObjectOwnerNode } from '../../../core'
import { CollectionContact } from './CollectionContact'
import { CollectionType } from './CollectionType'

export interface Collection {
id: number
Expand All @@ -9,6 +11,10 @@ export interface Collection {
description?: string
isPartOf: DvObjectOwnerNode
inputLevels?: CollectionInputLevel[]
type: CollectionType
contacts?: CollectionContact[]
isMetadataBlockRoot: boolean
isFacetRoot: boolean
}

export interface CollectionInputLevel {
Expand Down
4 changes: 4 additions & 0 deletions src/collections/domain/models/CollectionContact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface CollectionContact {
email: string
displayOrder: number
}
11 changes: 11 additions & 0 deletions src/collections/domain/models/CollectionType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum CollectionType {
RESEARCHERS = 'RESEARCHERS',
RESEARCH_PROJECTS = 'RESEARCH_PROJECTS',
JOURNALS = 'JOURNALS',
ORGANIZATIONS_INSTITUTIONS = 'ORGANIZATIONS_INSTITUTIONS',
TEACHING_COURSES = 'TEACHING_COURSES',
UNCATEGORIZED = 'UNCATEGORIZED',
LABORATORY = 'LABORATORY',
RESEARCH_GROUP = 'RESEARCH_GROUP',
DEPARTMENT = 'DEPARTMENT'
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ export interface CollectionPayload {
description?: string
isPartOf: OwnerNodePayload
inputLevels?: CollectionInputLevelPayload[]
dataverseContacts?: CollectionContactPayload[]
dataverseType: string
isMetadataBlockRoot: boolean
isFacetRoot: boolean
}

export interface CollectionInputLevelPayload {
datasetFieldTypeName: string
required: boolean
include: boolean
}

export interface CollectionContactPayload {
contactEmail: string
displayOrder: number
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Collection, CollectionInputLevel } from '../../../domain/models/Collection'
import { AxiosResponse } from 'axios'
import { CollectionInputLevelPayload, CollectionPayload } from './CollectionPayload'
import {
CollectionContactPayload,
CollectionInputLevelPayload,
CollectionPayload
} from './CollectionPayload'
import { transformPayloadToOwnerNode } from '../../../../core/infra/repositories/transformers/dvObjectOwnerNodeTransformer'
import { transformHtmlToMarkdown } from '../../../../datasets/infra/repositories/transformers/datasetTransformers'
import { CollectionFacet } from '../../../domain/models/CollectionFacet'
Expand All @@ -15,6 +19,8 @@ import { transformFilePreviewPayloadToFilePreview } from '../../../../files/infr
import { transformCollectionPreviewPayloadToCollectionPreview } from './collectionPreviewsTransformers'
import { CollectionPreviewPayload } from './CollectionPreviewPayload'
import { CollectionPreview } from '../../../domain/models/CollectionPreview'
import { CollectionContact } from '../../../domain/models/CollectionContact'
import { CollectionType } from '../../../domain/models/CollectionType'

export const transformCollectionResponseToCollection = (response: AxiosResponse): Collection => {
const collectionPayload = response.data.data
Expand All @@ -39,6 +45,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
name: collectionPayload.name,
isReleased: collectionPayload.isReleased,
affiliation: collectionPayload.affiliation,
type: collectionPayload.dataverseType as CollectionType,
isMetadataBlockRoot: collectionPayload.isMetadataBlockRoot,
isFacetRoot: collectionPayload.isFacetRoot,
...(collectionPayload.description && {
description: transformHtmlToMarkdown(collectionPayload.description)
}),
Expand All @@ -47,6 +56,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col
}),
...(collectionPayload.inputLevels && {
inputLevels: transformInputLevelsPayloadToInputLevels(collectionPayload.inputLevels)
}),
...(collectionPayload.dataverseContacts && {
contacts: transformContactsPayloadToContacts(collectionPayload.dataverseContacts)
})
}
return collectionModel
Expand Down Expand Up @@ -90,3 +102,12 @@ export const transformCollectionItemsResponseToCollectionItemSubset = (
totalItemCount: responseDataPayload.total_count
}
}

const transformContactsPayloadToContacts = (
contactsPayload: CollectionContactPayload[]
): CollectionContact[] => {
return contactsPayload.map((contactPayload) => ({
email: contactPayload.contactEmail,
displayOrder: contactPayload.displayOrder
}))
}
4 changes: 2 additions & 2 deletions test/environment/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
POSTGRES_VERSION=13
DATAVERSE_DB_USER=dataverse
SOLR_VERSION=9.3.0
DATAVERSE_IMAGE_REGISTRY=ghcr.io
DATAVERSE_IMAGE_TAG=10904-edit-dataverse-collection
DATAVERSE_IMAGE_REGISTRY=docker.io
DATAVERSE_IMAGE_TAG=unstable
DATAVERSE_BOOTSTRAP_TIMEOUT=5m
5 changes: 5 additions & 0 deletions test/integration/collections/CollectionsRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { CollectionPayload } from '../../../src/collections/infra/repositories/t
import { uploadFileViaApi } from '../../testHelpers/files/filesHelper'
import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper'
import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus'
import { CollectionType } from '../../../src/collections/domain/models/CollectionType'

describe('CollectionsRepository', () => {
const testCollectionAlias = 'collectionsRepositoryTestCollection'
Expand Down Expand Up @@ -61,6 +62,10 @@ describe('CollectionsRepository', () => {
expect(actual.affiliation).toBe(undefined)
expect(actual.description).toBe('The root dataverse.')
expect(actual.inputLevels).toBe(undefined)
expect(actual.type).toBe(CollectionType.UNCATEGORIZED)
expect(actual.contacts).toEqual([{ email: '[email protected]', displayOrder: 0 }])
expect(actual.isMetadataBlockRoot).toBe(true)
expect(actual.isFacetRoot).toBe(true)
})

test('should return isReleased is true for root collection', async () => {
Expand Down
25 changes: 22 additions & 3 deletions test/testHelpers/collections/collectionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { DvObjectType } from '../../../src'
import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
import { TestConstants } from '../TestConstants'
import axios from 'axios'
import { CollectionDTO, CollectionType } from '../../../src/collections/domain/dtos/CollectionDTO'
import { CollectionDTO } from '../../../src/collections/domain/dtos/CollectionDTO'
import { NewCollectionRequestPayload } from '../../../src/collections/infra/repositories/CollectionsRepository'
import { CollectionFacetPayload } from '../../../src/collections/infra/repositories/transformers/CollectionFacetPayload'
import { CollectionType } from '../../../src/collections/domain/models/CollectionType'

const COLLECTION_ID = 11111
const COLLECTION_IS_RELEASED = true
Expand Down Expand Up @@ -35,7 +36,16 @@ export const createCollectionModel = (): Collection => {
required: true,
include: true
}
]
],
type: CollectionType.UNCATEGORIZED,
contacts: [
{
email: '[email protected]',
displayOrder: 0
}
],
isMetadataBlockRoot: true,
isFacetRoot: true
}
return collectionModel
}
Expand All @@ -55,7 +65,16 @@ export const createCollectionPayload = (): CollectionPayload => {
required: true,
include: true
}
]
],
dataverseType: CollectionType.UNCATEGORIZED,
dataverseContacts: [
{
contactEmail: '[email protected]',
displayOrder: 0
}
],
isMetadataBlockRoot: true,
isFacetRoot: true
}
return collectionPayload
}
Expand Down

0 comments on commit d48324a

Please sign in to comment.