Skip to content

Commit 89ea19b

Browse files
authored
Merge pull request DSpace#11653 from 4Science/task/main/DSC-2444
feat(ror): Adds client-id in ROR requests if provided by config
2 parents fd5072d + 6a368ca commit 89ea19b

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

dspace-api/src/main/java/org/dspace/importer/external/ror/service/RorImportMetadataSourceServiceImpl.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
package org.dspace.importer.external.ror.service;
99

10+
import static org.dspace.importer.external.liveimportclient.service.LiveImportClientImpl.HEADER_PARAMETERS;
11+
1012
import java.net.URISyntaxException;
1113
import java.util.ArrayList;
1214
import java.util.Collection;
@@ -32,6 +34,7 @@
3234
import org.dspace.importer.external.liveimportclient.service.LiveImportClient;
3335
import org.dspace.importer.external.service.AbstractImportMetadataSourceService;
3436
import org.dspace.importer.external.service.components.QuerySource;
37+
import org.dspace.services.factory.DSpaceServicesFactory;
3538
import org.springframework.beans.factory.annotation.Autowired;
3639

3740
/**
@@ -44,6 +47,8 @@ public class RorImportMetadataSourceServiceImpl extends AbstractImportMetadataSo
4447

4548
private final static Logger log = LogManager.getLogger();
4649
protected static final String ROR_IDENTIFIER_PREFIX = "https://ror.org/";
50+
protected static final String ROR_CLIENT_ID_HEADER = "Client-Id";
51+
protected static final String ROR_CLIENT_ID_PROP = "ror.client-id";
4752

4853
private String url;
4954

@@ -161,7 +166,7 @@ public List<ImportRecord> call() throws Exception {
161166
* ROR query. This Callable uses as query value to ROR the string queryString
162167
* passed to constructor. If the object will be construct through {@code Query}
163168
* instance, the value of the Query's map with the key "query" will be used.
164-
*
169+
*
165170
* @author Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
166171
*/
167172
private class CountByQueryCallable implements Callable<Integer> {
@@ -190,7 +195,7 @@ public Integer call() throws Exception {
190195
*/
191196
public Integer count(String query) {
192197
try {
193-
Map<String, Map<String, String>> params = new HashMap<String, Map<String, String>>();
198+
Map<String, Map<String, String>> params = getBaseParams();
194199

195200
URIBuilder uriBuilder = new URIBuilder(this.url);
196201
uriBuilder.addParameter("query", query);
@@ -214,7 +219,7 @@ private List<ImportRecord> searchById(String id) {
214219
id = Strings.CS.removeStart(id, ROR_IDENTIFIER_PREFIX);
215220

216221
try {
217-
Map<String, Map<String, String>> params = new HashMap<String, Map<String, String>>();
222+
Map<String, Map<String, String>> params = getBaseParams();
218223

219224
URIBuilder uriBuilder = new URIBuilder(this.url + "/" + id);
220225

@@ -235,7 +240,7 @@ private List<ImportRecord> searchById(String id) {
235240
private List<ImportRecord> search(String query) {
236241
List<ImportRecord> importResults = new ArrayList<>();
237242
try {
238-
Map<String, Map<String, String>> params = new HashMap<String, Map<String, String>>();
243+
Map<String, Map<String, String>> params = getBaseParams();
239244

240245
URIBuilder uriBuilder = new URIBuilder(this.url);
241246
uriBuilder.addParameter("query", query);
@@ -262,6 +267,16 @@ private List<ImportRecord> search(String query) {
262267
return importResults;
263268
}
264269

270+
protected Map<String, Map<String, String>> getBaseParams() {
271+
Map<String, Map<String, String>> params = new HashMap<>();
272+
String rorClientId =
273+
DSpaceServicesFactory.getInstance().getConfigurationService().getProperty(ROR_CLIENT_ID_PROP);
274+
if (StringUtils.isNotEmpty(rorClientId)) {
275+
params.put(HEADER_PARAMETERS, Map.of(ROR_CLIENT_ID_HEADER, rorClientId));
276+
}
277+
return params;
278+
}
279+
265280
private JsonNode convertStringJsonToJsonNode(String json) {
266281
try {
267282
return new ObjectMapper().readTree(json);

dspace/config/modules/external-providers.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ datacite.projectimport.entityfilterquery = AND ((types.resourceTypeGeneral:Proje
103103
#---------------------------------------------------------------#
104104

105105
ror.orgunit-import.api-url = https://api.ror.org/v2/organizations
106+
# This client-id must be set inside local.cfg you can find details on how to generate it here:
107+
# https://ror.readme.io/docs/client-id#how-to-register-a-client-id
108+
# ror.client-id =
106109
#################################################################
107110
#------------------------- OpenAlex ----------------------------#
108111
#---------------------------------------------------------------#

0 commit comments

Comments
 (0)