109807: Live Import - PubMed - support optional apiKey config

(cherry picked from commit c25433ee17)
This commit is contained in:
Marie Verdonck
2024-11-28 17:38:20 +01:00
committed by github-actions[bot]
parent 13f27bc0a8
commit 4ce1f73033
3 changed files with 28 additions and 1 deletions

View File

@@ -55,6 +55,7 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
private String urlFetch;
private String urlSearch;
private String apiKey;
private int attempt = 3;
@@ -210,6 +211,9 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
@Override
public Integer call() throws Exception {
URIBuilder uriBuilder = new URIBuilder(urlSearch);
if (StringUtils.isNotBlank(apiKey)) {
uriBuilder.addParameter("api_key", apiKey);
}
uriBuilder.addParameter("db", "pubmed");
uriBuilder.addParameter("term", query.getParameterAsClass("query", String.class));
Map<String, Map<String, String>> params = new HashMap<String, Map<String,String>>();
@@ -286,6 +290,9 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
List<ImportRecord> records = new LinkedList<ImportRecord>();
URIBuilder uriBuilder = new URIBuilder(urlSearch);
if (StringUtils.isNotBlank(apiKey)) {
uriBuilder.addParameter("api_key", apiKey);
}
uriBuilder.addParameter("db", "pubmed");
uriBuilder.addParameter("retstart", start.toString());
uriBuilder.addParameter("retmax", count.toString());
@@ -316,6 +323,9 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
String webEnv = getSingleElementValue(response, "WebEnv");
URIBuilder uriBuilder2 = new URIBuilder(urlFetch);
if (StringUtils.isNotBlank(apiKey)) {
uriBuilder2.addParameter("api_key", apiKey);
}
uriBuilder2.addParameter("db", "pubmed");
uriBuilder2.addParameter("retstart", start.toString());
uriBuilder2.addParameter("retmax", count.toString());
@@ -388,6 +398,9 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
public ImportRecord call() throws Exception {
URIBuilder uriBuilder = new URIBuilder(urlFetch);
if (StringUtils.isNotBlank(apiKey)) {
uriBuilder.addParameter("api_key", apiKey);
}
uriBuilder.addParameter("db", "pubmed");
uriBuilder.addParameter("retmode", "xml");
uriBuilder.addParameter("id", query.getParameterAsClass("id", String.class));
@@ -428,6 +441,9 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
public Collection<ImportRecord> call() throws Exception {
URIBuilder uriBuilder = new URIBuilder(urlSearch);
if (StringUtils.isNotBlank(apiKey)) {
uriBuilder.addParameter("api_key", apiKey);
}
uriBuilder.addParameter("db", "pubmed");
uriBuilder.addParameter("usehistory", "y");
uriBuilder.addParameter("term", query.getParameterAsClass("term", String.class));
@@ -457,6 +473,9 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
String queryKey = getSingleElementValue(response, "QueryKey");
URIBuilder uriBuilder2 = new URIBuilder(urlFetch);
if (StringUtils.isNotBlank(apiKey)) {
uriBuilder.addParameter("api_key", apiKey);
}
uriBuilder2.addParameter("db", "pubmed");
uriBuilder2.addParameter("retmode", "xml");
uriBuilder2.addParameter("WebEnv", webEnv);
@@ -532,4 +551,8 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
this.urlSearch = urlSearch;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
}

View File

@@ -70,6 +70,7 @@
<property name="metadataFieldMapping" ref="pubmedMetadataFieldMapping"/>
<property name="urlFetch" value="${pubmed.url.fetch}"/>
<property name="urlSearch" value="${pubmed.url.search}"/>
<property name="apiKey" value="${pubmed.apiKey}"/>
<property name="generateQueryForItem" ref="pubmedService"></property>
<property name="interRequestTime" value="500"/>
<property name="supportedExtensions">

View File

@@ -45,6 +45,9 @@ epo.searchUrl = https://ops.epo.org/rest-services/published-data/search
#################################################################
#---------------------- PubMed -----------------------------#
#---------------------------------------------------------------#
# If apiKey is set then it's used, if not set or blank then it's not
# Max amount of requests per ip per second with apiKey is 10; without 3
pubmed.apiKey =
pubmed.url.search = https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi
pubmed.url.fetch = https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi
#################################################################
@@ -96,4 +99,4 @@ datacite.timeout = 180000
#---------------------------------------------------------------#
ror.orgunit-import.api-url = https://api.ror.org/organizations
#################################################################
#################################################################