Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 115 additions & 5 deletions docs/useCases.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The different use cases currently available in the package are classified below,
- [Collections](#Collections)
- [Collections read use cases](#collections-read-use-cases)
- [Get a Collection](#get-a-collection)
- [Get Collection Storage Driver](#get-collection-storage-driver)
- [Get Allowed Collection Storage Drivers](#get-allowed-collection-storage-drivers)
- [Get Collection Facets](#get-collection-facets)
- [Get User Permissions on a Collection](#get-user-permissions-on-a-collection)
- [List All Collection Items](#list-all-collection-items)
Expand All @@ -19,6 +21,8 @@ The different use cases currently available in the package are classified below,
- [Get Collections for Linking](#get-collections-for-linking)
- [Collections write use cases](#collections-write-use-cases)
- [Create a Collection](#create-a-collection)
- [Set Collection Storage Driver](#set-collection-storage-driver)
- [Delete Collection Storage Driver](#delete-collection-storage-driver)
- [Update a Collection](#update-a-collection)
- [Publish a Collection](#publish-a-collection)
- [Delete a Collection](#delete-a-collection)
Expand Down Expand Up @@ -172,6 +176,65 @@ The `collectionIdOrAlias` is a generic collection identifier, which can be eithe

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.

#### Get Collection Storage Driver

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

##### Example call:

```typescript
import { getCollectionStorageDriver } from '@iqss/dataverse-client-javascript'

/* ... */

const collectionIdOrAlias = 'classicLiterature'

getCollectionStorageDriver.execute(collectionIdOrAlias).then((storageDriver: StorageDriver) => {
/* ... */
})

// Pass true to resolve the effective driver after inheritance/default fallback
getCollectionStorageDriver
.execute(collectionIdOrAlias, true)
.then((storageDriver: StorageDriver) => {
/* ... */
})

/* ... */
```

_See [use case](../src/collections/domain/useCases/GetCollectionStorageDriver.ts) implementation_.

The `collectionIdOrAlias` is a generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId).

The optional `getEffective` parameter defaults to `false`. Set it to `true` to retrieve the effective storage driver after inheritance/default resolution.

#### Get Allowed Collection Storage Drivers

Returns an [AllowedStorageDrivers](../src/collections/domain/models/AllowedStorageDrivers.ts) object whose keys are driver labels and whose values are storage driver ids.

##### Example call:

```typescript
import { getAllowedCollectionStorageDrivers } from '@iqss/dataverse-client-javascript'

/* ... */

const collectionIdOrAlias = 'classicLiterature'

getAllowedCollectionStorageDrivers
.execute(collectionIdOrAlias)
.then((storageDrivers: AllowedStorageDrivers) => {
/* ... */
})

/* ... */
```

_See [use case](../src/collections/domain/useCases/GetAllowedCollectionStorageDrivers.ts) implementation_.

The `collectionIdOrAlias` is a generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId).

#### Get Collection Facets

Returns a [CollectionFacet](../src/collections/domain/models/CollectionFacet.ts) array containing the facets of the requested collection, given the collection identifier or alias.
Expand Down Expand Up @@ -442,6 +505,57 @@ The above example creates the new collection in the root collection since no col

The use case returns a number, which is the identifier of the created collection.

#### Set Collection Storage Driver

Assigns a storage driver to a collection by driver label and returns the backend success message.

##### Example call:

```typescript
import { setCollectionStorageDriver } from '@iqss/dataverse-client-javascript'

/* ... */

const collectionIdOrAlias = 'classicLiterature'
const driverLabel = 'Local Storage'

setCollectionStorageDriver.execute(collectionIdOrAlias, driverLabel).then((message: string) => {
/* ... */
})

/* ... */
```

_See [use case](../src/collections/domain/useCases/SetCollectionStorageDriver.ts) implementation_.

The `collectionIdOrAlias` is a generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId).

The `driverLabel` parameter must match the storage driver's label, not its id.

#### Delete Collection Storage Driver

Clears the directly assigned storage driver from a collection so it falls back to inherited/default storage, and returns the backend success message.

##### Example call:

```typescript
import { deleteCollectionStorageDriver } from '@iqss/dataverse-client-javascript'

/* ... */

const collectionIdOrAlias = 'classicLiterature'

deleteCollectionStorageDriver.execute(collectionIdOrAlias).then((message: string) => {
/* ... */
})

/* ... */
```

_See [use case](../src/collections/domain/useCases/DeleteCollectionStorageDriver.ts) implementation_.

The `collectionIdOrAlias` is a generic collection identifier, which can be either a string (for queries by CollectionAlias), or a number (for queries by CollectionId).

#### Update a Collection

Updates an existing collection, given a collection identifier and a [CollectionDTO](../src/collections/domain/dtos/CollectionDTO.ts) including the updated collection data.
Expand Down Expand Up @@ -1398,8 +1512,6 @@ _See [use case](../src/datasets/domain/useCases/GetDatasetAvailableCategories.ts

The `datasetId` parameter is a number for numeric identifiers or string for persistent identifiers.

# <<<<<<< HEAD

#### Get Dataset Templates

Returns a [DatasetTemplate](../src/datasets/domain/models/DatasetTemplate.ts) array containing the dataset templates of the requested collection, given the collection identifier or alias.
Expand All @@ -1420,7 +1532,7 @@ _See [use case](../src/datasets/domain/useCases/GetDatasetTemplates.ts)_ definit

#### Get Dataset Storage Driver

Returns a [StorageDriver](../src/datasets/domain/models/StorageDriver.ts) instance with storage driver configuration for a dataset, including properties like name, type, label, and upload/download capabilities.
Returns a [StorageDriver](../src/core/domain/models/StorageDriver.ts) instance with storage driver configuration for a dataset, including properties like name, type, label, and upload/download capabilities.

##### Example call:

Expand All @@ -1442,8 +1554,6 @@ _See [use case](../src/datasets/domain/useCases/GetDatasetStorageDriver.ts) impl

The `datasetId` parameter can be a string, for persistent identifiers, or a number, for numeric identifiers.

> > > > > > > develop

#### Add a Dataset Type

Adds a dataset types that can be used at dataset creation.
Expand Down
1 change: 1 addition & 0 deletions src/collections/domain/models/AllowedStorageDrivers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type AllowedStorageDrivers = Record<string, string>
14 changes: 14 additions & 0 deletions src/collections/domain/repositories/ICollectionsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,24 @@ import { PublicationStatus } from '../../../core/domain/models/PublicationStatus
import { CollectionItemType } from '../../../collections/domain/models/CollectionItemType'
import { CollectionLinks } from '../models/CollectionLinks'
import { CollectionSummary } from '../models/CollectionSummary'
import { AllowedStorageDrivers } from '../models/AllowedStorageDrivers'
import { StorageDriver } from '../../../core/domain/models/StorageDriver'
import { LinkingObjectType } from '../useCases/GetCollectionsForLinking'

export interface ICollectionsRepository {
getCollection(collectionIdOrAlias: number | string): Promise<Collection>
getCollectionStorageDriver(
collectionIdOrAlias: number | string,
getEffective?: boolean
): Promise<StorageDriver>
setCollectionStorageDriver(
collectionIdOrAlias: number | string,
driverLabel: string
): Promise<string>
deleteCollectionStorageDriver(collectionIdOrAlias: number | string): Promise<string>
getAllowedCollectionStorageDrivers(
collectionIdOrAlias: number | string
): Promise<AllowedStorageDrivers>
createCollection(
collectionDTO: CollectionDTO,
parentCollectionId: number | string
Expand Down
14 changes: 14 additions & 0 deletions src/collections/domain/useCases/DeleteCollectionStorageDriver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { UseCase } from '../../../core/domain/useCases/UseCase'
import { ICollectionsRepository } from '../repositories/ICollectionsRepository'

export class DeleteCollectionStorageDriver implements UseCase<string> {
private collectionsRepository: ICollectionsRepository

constructor(collectionsRepository: ICollectionsRepository) {
this.collectionsRepository = collectionsRepository
}

async execute(collectionIdOrAlias: number | string): Promise<string> {
return this.collectionsRepository.deleteCollectionStorageDriver(collectionIdOrAlias)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { UseCase } from '../../../core/domain/useCases/UseCase'
import { ICollectionsRepository } from '../repositories/ICollectionsRepository'
import { AllowedStorageDrivers } from '../models/AllowedStorageDrivers'

export class GetAllowedCollectionStorageDrivers implements UseCase<AllowedStorageDrivers> {
private collectionsRepository: ICollectionsRepository

constructor(collectionsRepository: ICollectionsRepository) {
this.collectionsRepository = collectionsRepository
}

async execute(collectionIdOrAlias: number | string): Promise<AllowedStorageDrivers> {
return this.collectionsRepository.getAllowedCollectionStorageDrivers(collectionIdOrAlias)
}
}
18 changes: 18 additions & 0 deletions src/collections/domain/useCases/GetCollectionStorageDriver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { UseCase } from '../../../core/domain/useCases/UseCase'
import { StorageDriver } from '../../../core/domain/models/StorageDriver'
import { ICollectionsRepository } from '../repositories/ICollectionsRepository'

export class GetCollectionStorageDriver implements UseCase<StorageDriver> {
private collectionsRepository: ICollectionsRepository

constructor(collectionsRepository: ICollectionsRepository) {
this.collectionsRepository = collectionsRepository
}

async execute(
collectionIdOrAlias: number | string,
getEffective = false
): Promise<StorageDriver> {
return this.collectionsRepository.getCollectionStorageDriver(collectionIdOrAlias, getEffective)
}
}
14 changes: 14 additions & 0 deletions src/collections/domain/useCases/SetCollectionStorageDriver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { UseCase } from '../../../core/domain/useCases/UseCase'
import { ICollectionsRepository } from '../repositories/ICollectionsRepository'

export class SetCollectionStorageDriver implements UseCase<string> {
private collectionsRepository: ICollectionsRepository

constructor(collectionsRepository: ICollectionsRepository) {
this.collectionsRepository = collectionsRepository
}

async execute(collectionIdOrAlias: number | string, driverLabel: string): Promise<string> {
return this.collectionsRepository.setCollectionStorageDriver(collectionIdOrAlias, driverLabel)
}
}
18 changes: 17 additions & 1 deletion src/collections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { GetCollection } from './domain/useCases/GetCollection'
import { GetCollectionFacets } from './domain/useCases/GetCollectionFacets'
import { GetCollectionUserPermissions } from './domain/useCases/GetCollectionUserPermissions'
import { GetCollectionItems } from './domain/useCases/GetCollectionItems'
import { GetCollectionStorageDriver } from './domain/useCases/GetCollectionStorageDriver'
import { PublishCollection } from './domain/useCases/PublishCollection'
import { UpdateCollection } from './domain/useCases/UpdateCollection'
import { GetCollectionFeaturedItems } from './domain/useCases/GetCollectionFeaturedItems'
Expand All @@ -16,10 +17,14 @@ import { LinkCollection } from './domain/useCases/LinkCollection'
import { UnlinkCollection } from './domain/useCases/UnlinkCollection'
import { GetCollectionLinks } from './domain/useCases/GetCollectionLinks'
import { GetCollectionsForLinking } from './domain/useCases/GetCollectionsForLinking'
import { SetCollectionStorageDriver } from './domain/useCases/SetCollectionStorageDriver'
import { DeleteCollectionStorageDriver } from './domain/useCases/DeleteCollectionStorageDriver'
import { GetAllowedCollectionStorageDrivers } from './domain/useCases/GetAllowedCollectionStorageDrivers'

const collectionsRepository = new CollectionsRepository()

const getCollection = new GetCollection(collectionsRepository)
const getCollectionStorageDriver = new GetCollectionStorageDriver(collectionsRepository)
const createCollection = new CreateCollection(collectionsRepository)
const getCollectionFacets = new GetCollectionFacets(collectionsRepository)
const getCollectionUserPermissions = new GetCollectionUserPermissions(collectionsRepository)
Expand All @@ -36,9 +41,15 @@ const linkCollection = new LinkCollection(collectionsRepository)
const unlinkCollection = new UnlinkCollection(collectionsRepository)
const getCollectionLinks = new GetCollectionLinks(collectionsRepository)
const getCollectionsForLinking = new GetCollectionsForLinking(collectionsRepository)
const setCollectionStorageDriver = new SetCollectionStorageDriver(collectionsRepository)
const deleteCollectionStorageDriver = new DeleteCollectionStorageDriver(collectionsRepository)
const getAllowedCollectionStorageDrivers = new GetAllowedCollectionStorageDrivers(
collectionsRepository
)

export {
getCollection,
getCollectionStorageDriver,
createCollection,
getCollectionFacets,
getCollectionUserPermissions,
Expand All @@ -54,7 +65,10 @@ export {
linkCollection,
unlinkCollection,
getCollectionLinks,
getCollectionsForLinking
getCollectionsForLinking,
setCollectionStorageDriver,
deleteCollectionStorageDriver,
getAllowedCollectionStorageDrivers
}
export { Collection, CollectionInputLevel } from './domain/models/Collection'
export { CollectionFacet } from './domain/models/CollectionFacet'
Expand All @@ -66,3 +80,5 @@ export { CollectionSearchCriteria } from './domain/models/CollectionSearchCriter
export { FeaturedItem } from './domain/models/FeaturedItem'
export { FeaturedItemsDTO } from './domain/dtos/FeaturedItemsDTO'
export { CollectionSummary } from './domain/models/CollectionSummary'
export { AllowedStorageDrivers } from './domain/models/AllowedStorageDrivers'
export { StorageDriver } from '../core/domain/models/StorageDriver'
58 changes: 58 additions & 0 deletions src/collections/infra/repositories/CollectionsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import { PublicationStatus } from '../../../core/domain/models/PublicationStatus
import { ReadError } from '../../../core/domain/repositories/ReadError'
import { CollectionLinks } from '../../domain/models/CollectionLinks'
import { CollectionSummary } from '../../domain/models/CollectionSummary'
import { AllowedStorageDrivers } from '../../domain/models/AllowedStorageDrivers'
import { StorageDriver } from '../../../core/domain/models/StorageDriver'
import { LinkingObjectType } from '../../domain/useCases/GetCollectionsForLinking'

export interface NewCollectionRequestPayload {
Expand Down Expand Up @@ -108,6 +110,62 @@ export class CollectionsRepository extends ApiRepository implements ICollections
})
}

public async getCollectionStorageDriver(
collectionIdOrAlias: number | string,
getEffective = false
): Promise<StorageDriver> {
return this.doGet(
`/${this.collectionsResourceName}/${collectionIdOrAlias}/storageDriver`,
true,
{
getEffective
}
)
.then((response) => response.data.data as StorageDriver)
.catch((error) => {
throw error
})
}

public async setCollectionStorageDriver(
collectionIdOrAlias: number | string,
driverLabel: string
): Promise<string> {
return this.doPut(
`/${this.collectionsResourceName}/${collectionIdOrAlias}/storageDriver`,
driverLabel,
undefined,
ApiConstants.CONTENT_TYPE_TEXT_PLAIN
)
.then((response) => response.data.data.message)
.catch((error) => {
throw error
})
}

public async deleteCollectionStorageDriver(
collectionIdOrAlias: number | string
): Promise<string> {
return this.doDelete(`/${this.collectionsResourceName}/${collectionIdOrAlias}/storageDriver`)
.then((response) => response.data.data.message)
.catch((error) => {
throw error
})
}

public async getAllowedCollectionStorageDrivers(
collectionIdOrAlias: number | string
): Promise<AllowedStorageDrivers> {
return this.doGet(
`/${this.collectionsResourceName}/${collectionIdOrAlias}/allowedStorageDrivers`,
true
)
.then((response) => response.data.data as AllowedStorageDrivers)
.catch((error) => {
throw error
})
}

public async createCollection(
collectionDTO: CollectionDTO,
parentCollectionId: number | string = ROOT_COLLECTION_ID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface StorageDriver {
name: string
type: string
label: string
type?: string
label?: string
directUpload: boolean
directDownload: boolean
uploadOutOfBand: boolean
Expand Down
Loading
Loading