Skip to content

Commit 4a6055a

Browse files
committed
Merge branch 'develop' into feat/361-get-available-dataset-metadata-export-formats
2 parents 4235db5 + 57c98de commit 4a6055a

File tree

12 files changed

+293
-0
lines changed

12 files changed

+293
-0
lines changed

docs/useCases.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ The different use cases currently available in the package are classified below,
9090
- [Get ZIP Download Limit](#get-zip-download-limit)
9191
- [Get Application Terms of Use](#get-application-terms-of-use)
9292
- [Get Available Dataset Metadata Export Formats](#get-available-dataset-metadata-export-formats)
93+
- [Licenses](#Licenses)
94+
- [Get Available Standard License Terms](#get-available-standard-license-terms)
9395
- [Contact](#Contact)
9496
- [Send Feedback to Object Contacts](#send-feedback-to-object-contacts)
9597
- [Notifications](#Notifications)
@@ -2115,6 +2117,26 @@ getAvailableDatasetMetadataExportFormats
21152117

21162118
_See [use case](../src/info/domain/useCases/GetAvailableDatasetMetadataExportFormats.ts) implementation_.
21172119

2120+
## Licenses
2121+
2122+
### Get Available Standard License Terms
2123+
2124+
Returns a list of available standard licenses that can be selected for a dataset.
2125+
2126+
##### Example call:
2127+
2128+
```typescript
2129+
import { getAvailableStandardLicenses, License } from '@iqss/dataverse-client-javascript'
2130+
2131+
/* ... */
2132+
2133+
getAvailableStandardLicenses.execute().then((licenses: License[]) => {
2134+
/* ... */
2135+
})
2136+
```
2137+
2138+
_See [use case](../src/licenses/domain/useCases/GetAvailableStandardLicenses.ts) implementation_.
2139+
21182140
## Contact
21192141

21202142
#### Send Feedback to Object Contacts

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ export * from './files'
1010
export * from './contactInfo'
1111
export * from './notifications'
1212
export * from './search'
13+
export * from './licenses'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export interface License {
2+
id: number
3+
name: string
4+
shortDescription?: string
5+
uri: string
6+
iconUri?: 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: 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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { AxiosResponse } from 'axios'
2+
import { License } from '../../models/License'
3+
import { LicensePayload } from './LicensePayload'
4+
5+
export const transformPayloadToLicense = (response: AxiosResponse): License[] => {
6+
const payload = response.data.data as LicensePayload[]
7+
8+
return payload.map((license: LicensePayload) => ({
9+
id: license.id,
10+
name: license.name,
11+
shortDescription: license.shortDescription,
12+
uri: license.uri,
13+
iconUri: license.iconUrl, // in payload, it is called iconUrl, but iconUri is the name matching everywhere else
14+
active: license.active,
15+
isDefault: license.isDefault,
16+
sortOrder: license.sortOrder,
17+
rightsIdentifier: license.rightsIdentifier,
18+
rightsIdentifierScheme: license.rightsIdentifierScheme,
19+
schemeUri: license.schemeUri,
20+
languageCode: license.languageCode
21+
}))
22+
}
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)