Skip to content

Commit 6418858

Browse files
committed
feat(api): add identifier on hal and fix test
1 parent 51e1333 commit 6418858

File tree

6 files changed

+148
-77
lines changed

6 files changed

+148
-77
lines changed

api/src/core/adapters/dbApi/kysely/pgDbApi.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe("pgDbApi", () => {
178178
authors: softwareExternalData.developers.map(dev => ({
179179
"@type": "Person" as const,
180180
name: dev.name,
181-
url: `https://www.wikidata.org/wiki/${dev.identifiers}`
181+
url: dev.url
182182
})),
183183
codeRepositoryUrl: softwareExternalData.sourceUrl,
184184
comptoirDuLibreId: undefined,

api/src/core/adapters/hal/getHalSoftware.test.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ describe("HAL", () => {
2929
"identifiers": [
3030
{
3131
value: "0000-0002-9777-5560",
32-
"@type": "PropertyValue"
32+
"@type": "PropertyValue",
33+
"additionalType": "Person",
34+
"subjectOf": {
35+
"@type": "Website",
36+
"additionalType": "ORCID",
37+
"name": "Open Researcher and Contributor ID",
38+
"url": new URL("https://orcid.org/")
39+
},
40+
"url": "https://orcid.org/0000-0002-9777-5560"
3341
}
3442
],
35-
"name": "Morane Gruenpeter",
36-
"url": "https://orcid.org/0000-0002-9777-5560"
43+
"name": "Morane Gruenpeter"
3744
}
3845
],
3946
"documentationUrl": undefined,
@@ -56,26 +63,26 @@ describe("HAL", () => {
5663
"identifiers": [
5764
{
5865
"@type": "PropertyValue",
66+
"additionalType": "Software",
5967
"subjectOf": {
6068
"@type": "Website",
6169
"additionalType": "HAL",
62-
"name": "HAL instance",
70+
"name": "HAL main instance",
6371
"url": new URL("https://hal.science/")
6472
},
65-
"url": new URL("https://hal.science/hal-01715545"),
73+
"url": "https://hal.science/hal-01715545",
6674
"value": "hal-01715545"
6775
},
6876
{
6977
"@type": "PropertyValue",
78+
"additionalType": "Software",
7079
"subjectOf": {
7180
"@type": "Website",
7281
"additionalType": "SWH",
7382
"name": "Software Heritage instance",
7483
"url": new URL("https://www.softwareheritage.org/")
7584
},
76-
"url": new URL(
77-
"https://archive.softwareheritage.org/swh:1:dir:424f2533fe51aa8a49d891f8413dd089995cc851;origin=https://hal.archives-ouvertes.fr/hal-01715545;visit=swh:1:snp:9f3237e88d818d975a63da2d5e04d9ad38b42581;anchor=swh:1:rev:8b71800feca2e28cc0f7f78d248e49244b554875;path=/"
78-
),
85+
"url": "https://archive.softwareheritage.org/swh:1:dir:424f2533fe51aa8a49d891f8413dd089995cc851;origin=https://hal.archives-ouvertes.fr/hal-01715545;visit=swh:1:snp:9f3237e88d818d975a63da2d5e04d9ad38b42581;anchor=swh:1:rev:8b71800feca2e28cc0f7f78d248e49244b554875;path=/",
7986
"value":
8087
"swh:1:dir:424f2533fe51aa8a49d891f8413dd089995cc851;origin=https://hal.archives-ouvertes.fr/hal-01715545;visit=swh:1:snp:9f3237e88d818d975a63da2d5e04d9ad38b42581;anchor=swh:1:rev:8b71800feca2e28cc0f7f78d248e49244b554875;path=/"
8188
}

api/src/core/adapters/hal/getHalSoftwareExternalData.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
112112
const base: SchemaPerson = {
113113
"@type": "Person",
114114
name: `${author.givenName} ${author.familyName}`,
115-
identifiers: [
116-
{
117-
"@type": "PropertyValue",
118-
value: id,
119-
additionalType: "Person",
120-
name: ""
121-
}
122-
],
123115
affiliations: [] as SchemaOrganization[]
124116
};
125117

@@ -147,16 +139,34 @@ export const getHalSoftwareExternalData: GetSoftwareExternalData = memoize(
147139
}
148140

149141
if (id?.split("-")?.length === 4 && id?.length === 19) {
150-
return { ...base, "url": `https://orcid.org/${id}` };
142+
return {
143+
...base,
144+
identifiers: [identifersUtils.makeOrcidIdentifer({ orcidId: id, additionalType: "Person" })]
145+
};
151146
}
152147

153148
if (id) {
154-
return { ...base, "url": `${source.url}/search/index/q/*/authIdHal_s/${id}` };
149+
return {
150+
...base,
151+
identifiers: [
152+
identifersUtils.makeHALIdentifier({
153+
halId: id,
154+
additionalType: "Person",
155+
url: `${source.url}/search/index/q/*/authIdHal_s/${id}`
156+
})
157+
]
158+
};
155159
}
156160

157161
return {
158162
...base,
159-
"url": `${source.url}/search/index/q/*/authFullName_s/${author.givenName}+${author.familyName}`
163+
identifiers: [
164+
identifersUtils.makeHALIdentifier({
165+
halId: id,
166+
additionalType: "Person",
167+
url: `${source.url}/search/index/q/*/authFullName_s/${author.givenName}+${author.familyName}`
168+
})
169+
]
160170
};
161171
})
162172
);

api/src/core/usecases/refreshExternalData.test.ts

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ describe("fetches software extra data (from different providers)", () => {
223223

224224
const updatedSoftwareExternalDatas = await dbApi.softwareExternalData.getAll();
225225

226-
expectToEqual(updatedSoftwareExternalDatas, [
226+
expectToMatchObject(updatedSoftwareExternalDatas, [
227227
emptyExternalDataCleaned({
228228
"externalId": "Q2822666",
229229
"softwareId": 2,
@@ -251,7 +251,21 @@ describe("fetches software extra data (from different providers)", () => {
251251
websiteUrl: "https://create-react-app.dev/",
252252
programmingLanguages: [],
253253
referencePublications: undefined,
254-
identifiers: [],
254+
identifiers: [
255+
{
256+
"@type": "PropertyValue",
257+
"additionalType": "Software",
258+
"name": "ID on Wikidata",
259+
"subjectOf": {
260+
"@type": "Website",
261+
"additionalType": "wikidata",
262+
"name": "Wikidata",
263+
"url": new URL("https://www.wikidata.org/")
264+
},
265+
"url": "https://www.wikidata.org/wiki/Q118629387",
266+
"value": "Q118629387"
267+
}
268+
],
255269
softwareVersion: "5.0.1",
256270
publicationTime: new Date("2022-04-12T00:00:00.000Z"),
257271
lastDataFetchAt: expect.any(Number),
@@ -287,7 +301,21 @@ describe("fetches software extra data (from different providers)", () => {
287301
websiteUrl: "https://vitejs.dev/",
288302
programmingLanguages: ["JavaScript"],
289303
referencePublications: undefined,
290-
identifiers: [],
304+
identifiers: [
305+
{
306+
"@type": "PropertyValue",
307+
"additionalType": "Software",
308+
"name": "ID on Wikidata",
309+
"subjectOf": {
310+
"@type": "Website",
311+
"additionalType": "wikidata",
312+
"name": "Wikidata",
313+
"url": new URL("https://www.wikidata.org/")
314+
},
315+
"url": "https://www.wikidata.org/wiki/Q111590996",
316+
"value": "Q111590996"
317+
}
318+
],
291319
softwareVersion: expect.any(String),
292320
publicationTime: expect.any(Date),
293321
lastDataFetchAt: expect.any(Number),
@@ -333,7 +361,7 @@ describe("fetches software extra data (from different providers)", () => {
333361
await fetchAndSaveSoftwareExtraDataBySoftwareId({ softwareId: apacheSoftwareId });
334362

335363
const updatedSoftwareExternalDatas = await dbApi.softwareExternalData.getAll();
336-
expectToEqual(updatedSoftwareExternalDatas, [
364+
expectToMatchObject(updatedSoftwareExternalDatas, [
337365
emptyExternalDataCleaned({
338366
"externalId": "Q2822666",
339367
"softwareId": 2,
@@ -351,6 +379,15 @@ describe("fetches software extra data (from different providers)", () => {
351379
identifiers: [
352380
{
353381
value: "Q489709",
382+
"additionalType": "Organization",
383+
"name": "ID on Wikidata",
384+
"subjectOf": {
385+
"@type": "Website",
386+
"additionalType": "wikidata",
387+
"name": "Wikidata",
388+
"url": new URL("https://www.wikidata.org/")
389+
},
390+
"url": "https://www.wikidata.org/wiki/Q489709",
354391
"@type": "PropertyValue"
355392
}
356393
],
@@ -371,7 +408,21 @@ describe("fetches software extra data (from different providers)", () => {
371408
sourceUrl: "https://github.com/apache/httpd",
372409
websiteUrl: "https://httpd.apache.org/",
373410
referencePublications: undefined,
374-
identifiers: [],
411+
identifiers: [
412+
{
413+
"@type": "PropertyValue",
414+
"additionalType": "Software",
415+
"name": "ID on Wikidata",
416+
"subjectOf": {
417+
"@type": "Website",
418+
"additionalType": "wikidata",
419+
"name": "Wikidata",
420+
"url": new URL("https://www.wikidata.org/")
421+
},
422+
"url": "https://www.wikidata.org/wiki/Q11354",
423+
"value": "Q11354"
424+
}
425+
],
375426
programmingLanguages: ["C"],
376427
softwareVersion: "2.5.0-alpha",
377428
publicationTime: new Date("2017-11-08T00:00:00.000Z"),

api/src/core/utils.ts

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ export const sWHSource: WebSite = {
5151
additionalType: "SWH"
5252
};
5353

54+
export const orcidSource: WebSite = {
55+
"@type": "Website" as const,
56+
name: "Open Researcher and Contributor ID",
57+
url: new URL("https://orcid.org/"),
58+
additionalType: "ORCID"
59+
};
60+
5461
export const identifersUtils = {
5562
makeGenericIdentifier: (params: { value: string; url?: string | URL }): SchemaIdentifier => {
5663
const { value, url } = params;
@@ -67,17 +74,15 @@ export const identifersUtils = {
6774
}): SchemaIdentifier => {
6875
const { framaLibreId, additionalType, url } = params;
6976
return {
70-
...{
71-
"@type": "PropertyValue" as const,
72-
name: "ID on FramaLibre",
73-
value: framaLibreId,
74-
url: url
75-
? url
76-
: framaLibreId.includes("https")
77-
? new URL(framaLibreId)
78-
: new URL(`https://framalibre.org/notices/${framaLibreId}`),
79-
subjectOf: framaLibreSource
80-
},
77+
"@type": "PropertyValue" as const,
78+
name: "ID on FramaLibre",
79+
value: framaLibreId,
80+
url: url
81+
? url
82+
: framaLibreId.includes("https")
83+
? new URL(framaLibreId)
84+
: new URL(`https://framalibre.org/notices/${framaLibreId}`),
85+
subjectOf: framaLibreSource,
8186
...(additionalType ? { additionalType: additionalType } : {})
8287
};
8388
},
@@ -88,51 +93,43 @@ export const identifersUtils = {
8893
}): SchemaIdentifier => {
8994
const { wikidataId, additionalType, url } = params;
9095
return {
91-
...{
92-
value: wikidataId,
93-
"@type": "PropertyValue" as const,
94-
url: url ? url : `https://www.wikidata.org/wiki/${wikidataId}`,
95-
subjectOf: wikidataSource,
96-
name: "ID on Wikidata"
97-
},
96+
value: wikidataId,
97+
"@type": "PropertyValue" as const,
98+
url: url ? url : `https://www.wikidata.org/wiki/${wikidataId}`,
99+
subjectOf: wikidataSource,
100+
name: "ID on Wikidata",
98101
...(additionalType ? { additionalType: additionalType } : {})
99102
};
100103
},
101104
makeCDLIdentifier: (params: { cdlId: string; url: string | URL; additionalType?: string }): SchemaIdentifier => {
102105
const { cdlId, url, additionalType } = params;
103106
return {
104-
...{
105-
"@type": "PropertyValue" as const,
106-
additionalType: "Organization",
107-
value: cdlId,
108-
url: url,
109-
subjectOf: cDLSource
110-
},
107+
"@type": "PropertyValue" as const,
108+
additionalType: "Organization",
109+
value: cdlId,
110+
url: url,
111+
subjectOf: cDLSource,
111112
...(additionalType ? { additionalType: additionalType } : {})
112113
};
113114
},
114115
makeCNLLIdentifier: (params: { cNNLId: string; url: string; additionalType?: string }): SchemaIdentifier => {
115116
const { cNNLId, url, additionalType } = params;
116117
return {
117-
...{
118-
"@type": "PropertyValue" as const,
119-
value: cNNLId,
120-
url: url,
121-
subjectOf: cNNLSource
122-
},
118+
"@type": "PropertyValue" as const,
119+
value: cNNLId,
120+
url: url,
121+
subjectOf: cNNLSource,
123122
...(additionalType ? { additionalType: additionalType } : {})
124123
};
125124
},
126125
makeDOIIdentifier: (params: { doi: string; additionalType?: string }): SchemaIdentifier => {
127126
const { doi, additionalType } = params;
128127
return {
129-
...{
130-
"@type": "PropertyValue",
131-
name: "DOI id",
132-
url: new URL(`https://doi.org/${doi}`),
133-
value: doi,
134-
subjectOf: doiSource
135-
},
128+
"@type": "PropertyValue",
129+
name: "DOI id",
130+
url: new URL(`https://doi.org/${doi}`),
131+
value: doi,
132+
subjectOf: doiSource,
136133
...(additionalType ? { additionalType: additionalType } : {})
137134
};
138135
},
@@ -142,12 +139,10 @@ export const identifersUtils = {
142139
makeHALIdentifier: (params: { halId: string; additionalType?: string; url?: string }): SchemaIdentifier => {
143140
const { halId, additionalType, url } = params;
144141
return {
145-
...{
146-
"@type": "PropertyValue" as const,
147-
value: halId,
148-
url: url ? url : `https://hal.science/hal-0${halId}`,
149-
subjectOf: halSource
150-
},
142+
"@type": "PropertyValue" as const,
143+
value: halId,
144+
url: url ? url : `https://hal.science/hal-0${halId}`,
145+
subjectOf: halSource,
151146
...(additionalType ? { additionalType: additionalType } : {})
152147
};
153148
},
@@ -157,12 +152,20 @@ export const identifersUtils = {
157152
makeSWHIdentifier: (params: { swhId: string; additionalType?: string; url: string }): SchemaIdentifier => {
158153
const { swhId, additionalType, url } = params;
159154
return {
160-
...{
161-
"@type": "PropertyValue" as const,
162-
value: swhId,
163-
url: url,
164-
subjectOf: sWHSource
165-
},
155+
"@type": "PropertyValue" as const,
156+
value: swhId,
157+
url: url,
158+
subjectOf: sWHSource,
159+
...(additionalType ? { additionalType: additionalType } : {})
160+
};
161+
},
162+
makeOrcidIdentifer: (params: { orcidId: string; additionalType?: string }): SchemaIdentifier => {
163+
const { orcidId, additionalType } = params;
164+
return {
165+
"@type": "PropertyValue" as const,
166+
value: orcidId,
167+
url: `https://orcid.org/${orcidId}`,
168+
subjectOf: orcidSource,
166169
...(additionalType ? { additionalType: additionalType } : {})
167170
};
168171
}

api/src/tools/test.helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const emptyExternalData = (params: { softwareId?: number; externalId: str
9797
sourceSlug,
9898
softwareId,
9999
lastDataFetchAt: null,
100-
providers: []
100+
providers: null
101101
};
102102
};
103103

@@ -124,7 +124,7 @@ export const emptyExternalDataCleaned = (params: { softwareId?: number; external
124124
sourceSlug,
125125
softwareId,
126126
lastDataFetchAt: undefined,
127-
providers: []
127+
providers: undefined
128128
};
129129
};
130130

0 commit comments

Comments
 (0)