Skip to content

Commit

Permalink
109807: Live Import - PubMed - support optional apiKey config
Browse files Browse the repository at this point in the history
  • Loading branch information
MarieVerdonck authored and Jens Vannerum committed Jan 30, 2025
1 parent ca7851f commit c25433e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class PubmedImportMetadataSourceServiceImpl extends AbstractImportMetadat

private String urlFetch;
private String urlSearch;
private String apiKey;

private int attempt = 3;

Expand Down Expand Up @@ -209,6 +210,9 @@ public GetNbRecords(Query query) {
@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>>();
Expand Down Expand Up @@ -282,6 +286,9 @@ public Collection<ImportRecord> call() throws Exception {
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());
Expand Down Expand Up @@ -312,6 +319,9 @@ public Collection<ImportRecord> call() throws Exception {
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());
Expand Down Expand Up @@ -386,6 +396,9 @@ public GetRecord(Query q) {
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));
Expand Down Expand Up @@ -426,6 +439,9 @@ public FindMatchingRecords(Query q) {
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));
Expand Down Expand Up @@ -455,6 +471,9 @@ public Collection<ImportRecord> call() throws Exception {
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);
Expand Down Expand Up @@ -530,4 +549,8 @@ public void setUrlSearch(String urlSearch) {
this.urlSearch = urlSearch;
}

public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
5 changes: 4 additions & 1 deletion dspace/config/modules/external-providers.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
#################################################################
Expand Down Expand Up @@ -96,4 +99,4 @@ datacite.timeout = 180000
#---------------------------------------------------------------#

ror.orgunit-import.api-url = https://api.ror.org/organizations
#################################################################
#################################################################

0 comments on commit c25433e

Please sign in to comment.