Skip to content

Commit

Permalink
Merge pull request DSpace#9631 from tdonohue/fix_9501
Browse files Browse the repository at this point in the history
Fix OpenAIRE import from external source
  • Loading branch information
tdonohue authored Jun 18, 2024
2 parents f1059b4 + 9e63a44 commit 075e51d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ public String getQueryParam() {
public void init() throws Exception {
Client client = ClientBuilder.newClient();
if (baseAddress == null) {
baseAddress = configurationService.getProperty("openaire.base.url");
baseAddress = configurationService.getProperty("openaire.search.url",
"https://api.openaire.eu/search/publications");
}
if (queryParam == null) {
queryParam = "title";
Expand Down Expand Up @@ -252,10 +253,10 @@ public Integer call() throws Exception {
Document document = saxBuilder.build(new StringReader(responseString));
Element root = document.getRootElement();

XPathExpression<Element> xpath = XPathFactory.instance().compile("/header/total",
XPathExpression<Element> xpath = XPathFactory.instance().compile("//header/total",
Filters.element(), null);

Element totalItem = (Element) xpath.evaluateFirst(root);
Element totalItem = xpath.evaluateFirst(root);
return totalItem != null ? Integer.parseInt(totalItem.getText()) : null;

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ protected <T> T retry(Callable<T> callable) throws MetadataSourceException {
} catch (Exception e) {
throwSourceException(retry, e, operationId);
}
log.info("operation " + operationId + " started");
log.debug("Operation {} started. Calling {}", operationId, callable.getClass().getName());
T response = callable.call();
log.info("operation " + operationId + " successful");
log.debug("Operation {} successful", operationId);
return response;
} catch (Exception e) {
this.error = e;
Expand All @@ -180,7 +180,8 @@ protected <T> T retry(Callable<T> callable) throws MetadataSourceException {

// No MetadataSourceException has interrupted the loop
retry++;
log.warn("Error in trying operation " + operationId + " " + retry + " " + warning + ", retrying !", e);
log.warn("Error in calling {} in operation {} {} {}, retrying!", callable.getClass().getName(),
operationId, retry, warning, e);

} finally {
this.lastRequest = System.currentTimeMillis();
Expand Down
4 changes: 3 additions & 1 deletion dspace/config/modules/openaire-client.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ openaire.token.clientSecret = CLIENT_SECRET_HERE
# URL of Openaire Rest API
openaire.api.url = https://api.openaire.eu

openaire.base.url = http://api.openaire.eu/search/publications
# OpenAIRE Search API to use for metadata import via external sources
# (e.g. importing metadata from OpenAIRE via submission)
openaire.search.url = https://api.openaire.eu/search/publications
12 changes: 12 additions & 0 deletions dspace/config/spring/api/external-services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,24 @@
<property name="metadataSource" ref="openaireImportServiceByAuthor"/>
<property name="sourceIdentifier" value="openaire"/>
<property name="recordIdMetadata" value="dc.identifier.other"/>
<property name="supportedEntityTypes">
<list>
<value>Publication</value>
<value>none</value>
</list>
</property>
</bean>

<bean id="openaireLiveImportDataProviderByTitle" class="org.dspace.external.provider.impl.LiveImportDataProvider">
<property name="metadataSource" ref="openaireImportServiceByTitle"/>
<property name="sourceIdentifier" value="openaireTitle"/>
<property name="recordIdMetadata" value="dc.identifier.other"/>
<property name="supportedEntityTypes">
<list>
<value>Publication</value>
<value>none</value>
</list>
</property>
</bean>

<bean id="pubmedLiveImportDataProvider" class="org.dspace.external.provider.impl.LiveImportDataProvider">
Expand Down

0 comments on commit 075e51d

Please sign in to comment.