109807: Live Import - PubMed - support optional apiKey config

This commit is contained in:
Marie Verdonck
2024-11-28 17:38:20 +01:00
committed by Tim Donohue
parent 3cb5deed39
commit da5b92a9dc
3 changed files with 27 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
private String urlFetch;
private String urlSearch;
private String apiKey;
private int attempt = 3;
@@ -211,6 +212,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>>();
@@ -287,6 +291,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());
@@ -317,6 +324,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());
@@ -389,6 +399,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));
@@ -429,6 +442,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));
@@ -458,6 +474,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);
@@ -533,4 +552,8 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat
this.urlSearch = urlSearch;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
}

View File

@@ -80,6 +80,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
#################################################################