-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1138 from research-software-directory/1071-add-eu…
…rope-op-doi Support for Publications Office of the European Union
- Loading branch information
Showing
14 changed files
with
258 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 dv4all | ||
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
@@ -82,7 +83,7 @@ export default function ImportReportBody({initialResults,onCancel,onImport}: Bul | |
return 'DOI not found' | ||
case 'unsupportedRA': | ||
return 'Registration agent (RA) is not supported' | ||
case 'alredyImported': | ||
case 'alreadyImported': | ||
return 'This publication is already imported' | ||
default: | ||
return 'Unknown error' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// SPDX-FileCopyrightText: 2023 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 dv4all | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
@@ -23,9 +23,9 @@ import {DoiBulkImportReport, addMentions, linkMentionToEntity} from './apiImport | |
|
||
export type SearchResult = { | ||
doi: string | ||
status: 'valid' | 'invalidDoi' | 'doiNotFound' |'unsupportedRA' | 'alredyImported' | 'unknown', | ||
status: 'valid' | 'invalidDoi' | 'doiNotFound' |'unsupportedRA' | 'alreadyImported' | 'unknown', | ||
include: boolean | ||
source?: 'RSD' | 'Crossref' | 'DataCite', | ||
source?: 'RSD' | 'Crossref' | 'DataCite' | 'OpenAlex', | ||
mention?: MentionItemProps | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2022 dv4all | ||
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
@@ -42,7 +44,7 @@ export async function extractReturnMessage(resp: Response, dataId?: string) { | |
status: resp.status, | ||
message: ` | ||
${resp.statusText}. | ||
You might not have sufficient priveleges to edit this item. | ||
You might not have sufficient privileges to edit this item. | ||
Please contact site administrators. | ||
` | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2022 dv4all | ||
// | ||
|
@@ -142,7 +142,7 @@ export async function getCrossrefItemsByQuery(query: string) { | |
} | ||
} | ||
|
||
function crossrefToRsdType(type: string): MentionTypeKeys { | ||
export function crossrefToRsdType(type: string): MentionTypeKeys { | ||
if (!type) return 'other' | ||
switch (type.trim().toLowerCase()) { | ||
case 'book': | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
// SPDX-FileCopyrightText: 2022 - 2023 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2022 - 2023 dv4all | ||
// SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {MentionItemProps} from '~/types/Mention' | ||
import {crossrefItemToMentionItem, getCrossrefItemByDoi} from './getCrossref' | ||
import {dataCiteGraphQLItemToMentionItem, getDataciteItemByDoiGraphQL, getDataciteItemsByDoiGraphQL} from './getDataCite' | ||
import logger from './logger' | ||
import {getOpenalexItemByDoi, getOpenalexItemsByDoi, openalexItemToMentionItem} from '~/utils/getOpenalex' | ||
|
||
type DoiRA = { | ||
DOI: string, | ||
|
@@ -155,6 +156,30 @@ export async function getItemsFromDatacite(dois: string[]) { | |
return mentions | ||
} | ||
|
||
async function getItemFromOpenalex(doi: string) { | ||
const resp = await getOpenalexItemByDoi(doi) | ||
// debugger | ||
if (resp.status === 200) { | ||
const mention = openalexItemToMentionItem(resp.message) | ||
return { | ||
status: 200, | ||
message: mention | ||
} | ||
} | ||
// return error message | ||
return resp | ||
} | ||
|
||
export async function getItemsFromOpenAlex(dois: string[]): Promise<MentionItemProps[]> { | ||
if (dois.length === 0) { | ||
return [] | ||
} | ||
|
||
const response = await getOpenalexItemsByDoi(dois) | ||
|
||
return response.message.map((rawMention: any) => openalexItemToMentionItem(rawMention)) | ||
} | ||
|
||
export async function getMentionByDoi(doi: string) { | ||
// get RA first | ||
const doiRA = await getDoiRA(doi) | ||
|
@@ -167,6 +192,8 @@ export async function getMentionByDoi(doi: string) { | |
case 'datacite': | ||
// get from datacite | ||
return getItemFromDatacite(doi) | ||
case 'op': | ||
return getItemFromOpenalex(doi) | ||
default: | ||
return { | ||
status: 400, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import logger from '~/utils/logger' | ||
import {MentionItemProps} from '~/types/Mention' | ||
import {crossrefToRsdType} from '~/utils/getCrossref' | ||
|
||
export async function getOpenalexItemByDoi(doi: string) { | ||
try { | ||
const url = `https://api.openalex.org/works/https://doi.org/${doi}` | ||
|
||
const resp = await fetch(url) | ||
|
||
if (resp.status === 200) { | ||
const json = await resp.json() | ||
return ({ | ||
status: 200, | ||
message: json | ||
}) | ||
} | ||
else if (resp.status === 404) { | ||
return { | ||
status: 404, | ||
message: 'DOI not found' | ||
} | ||
} | ||
else { | ||
return ({ | ||
status: resp.status, | ||
message: 'unexpected response from OpenAlex' | ||
}) | ||
} | ||
} catch (e:any) { | ||
logger(`getOpenalexItemByDoi: ${e?.message}`, 'error') | ||
return { | ||
status: 500, | ||
message: e?.message | ||
} | ||
} | ||
} | ||
|
||
export async function getOpenalexItemsByDoi(dois: string[]) { | ||
try { | ||
const url = `https://api.openalex.org/works?filter=doi:${dois.join('|')}` | ||
|
||
const resp = await fetch(url) | ||
|
||
if (resp.status === 200) { | ||
const json = await resp.json() | ||
return ({ | ||
status: 200, | ||
message: json.results | ||
}) | ||
} | ||
else { | ||
return ({ | ||
status: resp.status, | ||
message: 'unexpected response from OpenAlex' | ||
}) | ||
} | ||
} catch (e:any) { | ||
logger(`getOpenalexItemByDoi: ${e?.message}`, 'error') | ||
return { | ||
status: 500, | ||
message: e?.message | ||
} | ||
} | ||
} | ||
|
||
export function openalexItemToMentionItem(json: any): MentionItemProps { | ||
return ({ | ||
id: null, | ||
doi: json.doi.substring('https://doi.org/'.length), | ||
url: json.doi, | ||
title: json.title, | ||
authors: extractAuthors(json), | ||
publisher: null, | ||
publication_year: json.publication_year, | ||
journal: null, | ||
page: null, | ||
// url to external image | ||
image_url: null, | ||
// is_featured?: boolean | ||
mention_type: crossrefToRsdType(json.type_crossref), | ||
source: 'OpenAlex', | ||
note: null | ||
}) | ||
} | ||
|
||
function extractAuthors(json: any): string { | ||
return json.authorships.map((authorship: any) => authorship.raw_author_name as string).join(', ') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
@@ -10,16 +10,15 @@ | |
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import nl.esciencecenter.rsd.scraper.Utils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DataCiteReleaseRepository { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DataCiteReleaseRepository.class); | ||
|
@@ -41,7 +40,9 @@ public class DataCiteReleaseRepository { | |
"""; | ||
|
||
public Map<String, Collection<MentionRecord>> getVersionedDois(Collection<String> conceptDois) { | ||
if (conceptDois.isEmpty()) return Collections.EMPTY_MAP; | ||
if (conceptDois.isEmpty()) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
String query = QUERY_UNFORMATTED.formatted(DataciteMentionRepository.joinCollection(conceptDois)); | ||
JsonObject body = new JsonObject(); | ||
|
Oops, something went wrong.