77 */
88package org .dspace .importer .external .ror .service ;
99
10+ import static org .dspace .importer .external .liveimportclient .service .LiveImportClientImpl .HEADER_PARAMETERS ;
11+
1012import java .net .URISyntaxException ;
1113import java .util .ArrayList ;
1214import java .util .Collection ;
3234import org .dspace .importer .external .liveimportclient .service .LiveImportClient ;
3335import org .dspace .importer .external .service .AbstractImportMetadataSourceService ;
3436import org .dspace .importer .external .service .components .QuerySource ;
37+ import org .dspace .services .factory .DSpaceServicesFactory ;
3538import 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 );
0 commit comments