Skip to content
Merged
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
19 changes: 19 additions & 0 deletions api/src/core/adapters/hal/HalAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import { HAL } from "./types/HAL";

const HAL_API_TIMEOUT = 60000;

type HALID = Pick<HAL.API.Software, "docid">;

export type HALAPIGateway = {
software: {
getById: (halDocid: string) => Promise<HAL.API.Software | undefined>;
getAll: (params: {
queryString?: string | undefined;
SWHFilter?: boolean | undefined;
}) => Promise<HAL.API.Software[]>;
getAllIds: (params: { queryString?: string | undefined; SWHFilter?: boolean | undefined }) => Promise<HALID[]>;
getCodemetaByUrl: (urlSoftwareDoc: string) => Promise<HAL.SoftwareApplication | undefined>;
};
domain: {
Expand Down Expand Up @@ -115,6 +118,22 @@ export const makeHalAPIGateway = (source?: Source): HALAPIGateway => {
const json = await getHalApiRequest<HAL.API.Software>(url);
return json?.response?.docs ?? [];
},
getAllIds: async (params: { queryString?: string; SWHFilter?: boolean }) => {
const { queryString, SWHFilter } = params;
let url = `https://api.archives-ouvertes.fr/search/?fq=docType_s:SOFTWARE&rows=10000&fl:docid`;

if (queryString) {
url = url + `&q=${encodeURIComponent(queryString)}`;
}

// Filter only software who have an swhidId to filter clean data on https://hal.science, TODO remove and set it as an option to be generic
if (SWHFilter) {
url = url + `&fq=swhidId_s:["" TO *]`;
}

const json = await getHalApiRequest<HAL.API.Software>(url);
return json?.response?.docs ?? [];
},
getCodemetaByUrl: (urlSoftwareDoc: string) => {
const url = `${urlSoftwareDoc}/codemeta`;
return getHalRequest<HAL.SoftwareApplication>(url);
Expand Down
2 changes: 1 addition & 1 deletion api/src/core/usecases/importFromSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const resolveAllIdsAccordingToSource = async (source: Source): Promise<string[]>
switch (source.kind) {
case "HAL":
const halAPIGateway = makeHalAPIGateway(source);
return (await halAPIGateway.software.getAll({ SWHFilter: true })).map(doc => doc.docid);
return (await halAPIGateway.software.getAllIds({ SWHFilter: true })).map(doc => doc.docid);
case "Zenodo":
const zenodoAPI = makeZenodoApi(source);
return (await zenodoAPI.records.getAllSoftware()).hits.hits.map(item => item.id.toString());
Expand Down
Loading