Skip to content

Commit 4ce6b26

Browse files
committed
feat: new use case for licenses
1 parent bfb640a commit 4ce6b26

File tree

12 files changed

+270
-0
lines changed

12 files changed

+270
-0
lines changed

docs/useCases.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ The different use cases currently available in the package are classified below,
8989
- [Get Maximum Embargo Duration In Months](#get-maximum-embargo-duration-in-months)
9090
- [Get ZIP Download Limit](#get-zip-download-limit)
9191
- [Get Application Terms of Use](#get-application-terms-of-use)
92+
- [Licenses](#Licenses)
93+
- [Get Available Standard License Terms](#get-available-standard-license-terms)
9294
- [Contact](#Contact)
9395
- [Send Feedback to Object Contacts](#send-feedback-to-object-contacts)
9496
- [Search](#Search)
@@ -2084,6 +2086,26 @@ getApplicationTermsOfUse.execute().then((termsOfUse: string) => {
20842086

20852087
_See [use case](../src/info/domain/useCases/GetApplicationTermsOfUse.ts) implementation_.
20862088

2089+
## Licenses
2090+
2091+
### Get Available Standard License Terms
2092+
2093+
Returns a list of available standard licenses that can be selected for a dataset.
2094+
2095+
##### Example call:
2096+
2097+
```typescript
2098+
import { getAvailableStandardLicenses, License } from '@iqss/dataverse-client-javascript'
2099+
2100+
/* ... */
2101+
2102+
getAvailableStandardLicenses.execute().then((licenses: License[]) => {
2103+
/* ... */
2104+
})
2105+
```
2106+
2107+
_See [use case](../src/licenses/domain/useCases/GetAvailableStandardLicenses.ts) implementation_.
2108+
20872109
## Contact
20882110

20892111
#### Send Feedback to Object Contacts

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './metadataBlocks'
99
export * from './files'
1010
export * from './contactInfo'
1111
export * from './search'
12+
export * from './licenses'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface License {
2+
id: number
3+
name: string
4+
uri: string
5+
iconUrl: string
6+
active: boolean
7+
isDefault: boolean
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { License } from '../models/License'
2+
3+
export interface ILicensesRepository {
4+
getAvailableStandardLicenses(): Promise<License[]>
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export interface LicensePayload {
2+
id: number
3+
name: string
4+
shortDescription: string
5+
uri: string
6+
iconUrl: string
7+
active: boolean
8+
isDefault: boolean
9+
sortOrder: number
10+
rightsIdentifier: string
11+
rightsIdentifierScheme: string
12+
schemeUri: string
13+
languageCode: string
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { AxiosResponse } from 'axios'
2+
import { License } from '../../models/License'
3+
import { LicensePayload } from './LicensePayload'
4+
5+
export const transformLicensesResponseToLicenses = (response: AxiosResponse): License[] => {
6+
const payload = response.data.data as LicensePayload[]
7+
return payload.map((license: LicensePayload) => ({
8+
id: license.id,
9+
name: license.name,
10+
uri: license.uri,
11+
iconUrl: license.iconUrl,
12+
active: license.active,
13+
isDefault: license.isDefault
14+
}))
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { UseCase } from '../../../core/domain/useCases/UseCase'
2+
import { License } from '../models/License'
3+
import { ILicensesRepository } from '../repositories/ILicensesRepository'
4+
5+
export class GetAvailableStandardLicenses implements UseCase<License[]> {
6+
private licensesRepository: ILicensesRepository
7+
8+
constructor(licensesRepository: ILicensesRepository) {
9+
this.licensesRepository = licensesRepository
10+
}
11+
12+
/**
13+
* Returns the list of available standard license terms that can be selected for a dataset.
14+
*
15+
* @returns {Promise<License[]>}
16+
*/
17+
async execute(): Promise<License[]> {
18+
return await this.licensesRepository.getAvailableStandardLicenses()
19+
}
20+
}

src/licenses/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { LicensesRepository } from './infra/repositories/LicensesRepository'
2+
import { GetAvailableStandardLicenses } from './domain/useCases/GetAvailableStandardLicenses'
3+
4+
const licensesRepository = new LicensesRepository()
5+
6+
const getAvailableStandardLicenses = new GetAvailableStandardLicenses(licensesRepository)
7+
8+
export { getAvailableStandardLicenses }
9+
10+
export { License } from './domain/models/License'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ApiRepository } from '../../../core/infra/repositories/ApiRepository'
2+
import { ILicensesRepository } from '../../domain/repositories/ILicensesRepository'
3+
import { License } from '../../domain/models/License'
4+
5+
export class LicensesRepository extends ApiRepository implements ILicensesRepository {
6+
private readonly licensesResourceName: string = 'licenses'
7+
8+
public async getAvailableStandardLicenses(): Promise<License[]> {
9+
return this.doGet(this.buildApiEndpoint(this.licensesResourceName))
10+
.then((response) => response.data.data)
11+
.catch((error) => {
12+
throw error
13+
})
14+
}
15+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { ApiConfig, getAvailableStandardLicenses, License } from '../../../src'
2+
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
3+
import { TestConstants } from '../../testHelpers/TestConstants'
4+
5+
describe('getAvailableStandardLicenses', () => {
6+
describe('execute', () => {
7+
beforeAll(async () => {
8+
ApiConfig.init(
9+
TestConstants.TEST_API_URL,
10+
DataverseApiAuthMechanism.API_KEY,
11+
process.env.TEST_API_KEY
12+
)
13+
})
14+
15+
test('should return available standard license terms', async () => {
16+
const actualLicenses: License[] = await getAvailableStandardLicenses.execute()
17+
const expectedLicenses = [
18+
{
19+
id: 1,
20+
name: 'CC0 1.0',
21+
shortDescription: 'Creative Commons CC0 1.0 Universal Public Domain Dedication.',
22+
uri: 'http://creativecommons.org/publicdomain/zero/1.0',
23+
iconUrl: 'https://licensebuttons.net/p/zero/1.0/88x31.png',
24+
active: true,
25+
isDefault: true,
26+
sortOrder: 0,
27+
rightsIdentifier: 'CC0-1.0',
28+
rightsIdentifierScheme: 'SPDX',
29+
schemeUri: 'https://spdx.org/licenses/',
30+
languageCode: 'en'
31+
},
32+
{
33+
id: 2,
34+
name: 'CC BY 4.0',
35+
shortDescription: 'Creative Commons Attribution 4.0 International License.',
36+
uri: 'http://creativecommons.org/licenses/by/4.0',
37+
iconUrl: 'https://licensebuttons.net/l/by/4.0/88x31.png',
38+
active: true,
39+
isDefault: false,
40+
sortOrder: 2,
41+
rightsIdentifier: 'CC-BY-4.0',
42+
rightsIdentifierScheme: 'SPDX',
43+
schemeUri: 'https://spdx.org/licenses/',
44+
languageCode: 'en'
45+
}
46+
]
47+
48+
expect(actualLicenses).toEqual(expectedLicenses)
49+
})
50+
})
51+
})

0 commit comments

Comments
 (0)