2727import org .apache .logging .log4j .LogManager ;
2828import org .apache .logging .log4j .Logger ;
2929import org .dspace .app .client .DSpaceHttpClientFactory ;
30- import org .dspace .app .sherpa .v2 .SHERPAFormat ;
30+ import org .dspace .app .openpolicyfinder .v2 .OpenPolicyFinderFormat ;
3131import org .dspace .app .openpolicyfinder .v2 .OpenPolicyFinderPublisherResponse ;
3232import org .dspace .app .openpolicyfinder .v2 .OpenPolicyFinderResponse ;
3333import org .dspace .app .openpolicyfinder .v2 .OpenPolicyFinderUtils ;
34+ import org .dspace .external .provider .impl .OpenPolicyFinderJournalDataProvider ;
35+ import org .dspace .external .provider .impl .OpenPolicyFinderPublisherDataProvider ;
3436import org .dspace .services .ConfigurationService ;
3537import org .springframework .beans .factory .annotation .Autowired ;
3638import org .springframework .cache .annotation .Cacheable ;
4143 * Note, this service is ported from DSpace 6 for the ability to search policies by ISSN
4244 * There are also new DataProvider implementations provided for use as 'external sources'
4345 * of journal and publisher data
44- * @see org.dspace.external.provider.impl. OpenPolicyFinderJournalDataProvider
45- * @see org.dspace.external.provider.impl. OpenPolicyFinderPublisherDataProvider
46+ * @see OpenPolicyFinderJournalDataProvider
47+ * @see OpenPolicyFinderPublisherDataProvider
4648 * @author Kim Shepherd
4749 */
4850public class OpenPolicyFinderService {
4951
52+ private static final Logger log = LogManager .getLogger (OpenPolicyFinderService .class );
53+
54+ public static final String OPEN_POLICY_FINDER_URL = "https://api.openpolicyfinder.jisc.ac.uk/retrieve" ;
55+
5056 private int maxNumberOfTries ;
5157 private long sleepBetweenTimeouts ;
5258 private int timeout = 5000 ;
5359 private String endpoint = null ;
5460 private String apiKey = null ;
5561
56- /** log4j category */
57- private static final Logger log = LogManager .getLogger (OpenPolicyFinderService .class );
58-
5962 @ Autowired
6063 ConfigurationService configurationService ;
6164
@@ -68,14 +71,15 @@ private void init() {
6871 // Get endpoint and API key from configuration, with fallback to legacy property names
6972 String newUrl = configurationService .getProperty ("openpolicyfinder.url" );
7073 String legacyUrl = configurationService .getProperty ("sherpa.romeo.url" );
71- if (newUrl != null ) {
74+ if (newUrl != null ) {
7275 endpoint = newUrl ;
7376 } else if (legacyUrl != null ) {
7477 endpoint = legacyUrl ;
75- log .warn ("Configuration property 'sherpa.romeo.url' is deprecated. "
76- + "Please use 'openpolicyfinder.url' instead." );
78+ log .warn ("Configuration property 'sherpa.romeo.url' is deprecated. " +
79+ "If it points to v2.sherpa.ac.uk, that endpoint is being retired in April 2026." +
80+ "Please set 'openpolicyfinder.url =" + OPEN_POLICY_FINDER_URL );
7781 } else {
78- endpoint = "https://api.openpolicyfinder.jisc.ac.uk/retrieve" ;
82+ endpoint = OPEN_POLICY_FINDER_URL ;
7983 }
8084
8185 String newApiKey = configurationService .getProperty ("openpolicyfinder.apikey" );
@@ -116,9 +120,8 @@ public OpenPolicyFinderResponse searchByJournalISSN(String query) {
116120 * @param limit maximum search results to return
117121 * @return OpenPolicyFinderPublisherResponse object
118122 */
119- public OpenPolicyFinderPublisherResponse performPublisherRequest (
120- String type , String field , String predicate , String value ,
121- int start , int limit ) {
123+ public OpenPolicyFinderPublisherResponse performPublisherRequest (String type , String field , String predicate ,
124+ String value , int start , int limit ) {
122125 // API Key is *required* for API calls
123126 if (null == apiKey ) {
124127 log .error ("Open Policy Finder API Key missing: "
@@ -133,9 +136,8 @@ public OpenPolicyFinderPublisherResponse performPublisherRequest(
133136 while (numberOfTries < maxNumberOfTries && opfResponse == null ) {
134137 numberOfTries ++;
135138
136- log .debug (String .format (
137- "Trying to contact Open Policy Finder - attempt %d of %d; timeout is %d; "
138- + "sleep between timeouts is %d" ,
139+ log .debug (String .format ("Trying to contact Open Policy Finder - attempt %d of %d; timeout is %d; "
140+ + "sleep between timeouts is %d" ,
139141 numberOfTries ,
140142 maxNumberOfTries ,
141143 timeout ,
@@ -151,13 +153,11 @@ public OpenPolicyFinderPublisherResponse performPublisherRequest(
151153 try (CloseableHttpResponse response = client .execute (method )) {
152154 int statusCode = response .getStatusLine ().getStatusCode ();
153155
154- log .debug (response .getStatusLine ().getStatusCode () + ": "
155- + response .getStatusLine ().getReasonPhrase ());
156+ log .debug (statusCode + ": " + response .getStatusLine ().getReasonPhrase ());
156157
157158 if (statusCode != HttpStatus .SC_OK ) {
158- opfResponse = new OpenPolicyFinderPublisherResponse (
159- "Open Policy Finder return not OK status: "
160- + statusCode );
159+ opfResponse = new OpenPolicyFinderPublisherResponse ("Open Policy Finder return not OK status: "
160+ + statusCode );
161161 String errorBody = IOUtils .toString (response .getEntity ().getContent (), StandardCharsets .UTF_8 );
162162 log .error ("Error from Open Policy Finder HTTP request: " + errorBody );
163163 }
@@ -208,8 +208,7 @@ public OpenPolicyFinderPublisherResponse performPublisherRequest(
208208
209209 if (opfResponse == null ) {
210210 log .debug ("Response is still null" );
211- opfResponse = new OpenPolicyFinderPublisherResponse (
212- "Error processing the Open Policy Finder answer" );
211+ opfResponse = new OpenPolicyFinderPublisherResponse ("Error processing the Open Policy Finder answer" );
213212 }
214213
215214 // Return the final response
@@ -265,9 +264,8 @@ public OpenPolicyFinderResponse performRequest(String type, String field, String
265264 + response .getStatusLine ().getReasonPhrase ());
266265
267266 if (statusCode != HttpStatus .SC_OK ) {
268- opfResponse = new OpenPolicyFinderResponse (
269- "Open Policy Finder return not OK status: "
270- + statusCode );
267+ opfResponse = new OpenPolicyFinderResponse ("Open Policy Finder return not OK status: "
268+ + statusCode );
271269 String errorBody = IOUtils .toString (response .getEntity ().getContent (), StandardCharsets .UTF_8 );
272270 log .error ("Error from Open Policy Finder HTTP request: " + errorBody );
273271 }
@@ -280,8 +278,7 @@ public OpenPolicyFinderResponse performRequest(String type, String field, String
280278 InputStream content = null ;
281279 try {
282280 content = responseBody .getContent ();
283- opfResponse = new OpenPolicyFinderResponse (
284- content , OpenPolicyFinderResponse .ResponseFormat .JSON );
281+ opfResponse = new OpenPolicyFinderResponse (content , OpenPolicyFinderFormat .JSON );
285282 } catch (IOException e ) {
286283 log .error ("Encountered exception while contacting Open Policy Finder: "
287284 + e .getMessage (), e );
@@ -316,16 +313,15 @@ public OpenPolicyFinderResponse performRequest(String type, String field, String
316313
317314 if (opfResponse == null ) {
318315 log .debug ("Response is still null" );
319- opfResponse = new OpenPolicyFinderResponse (
320- "Error processing the Open Policy Finder answer" );
316+ opfResponse = new OpenPolicyFinderResponse ("Error processing the Open Policy Finder answer" );
321317 }
322318
323319 // Return the final response
324320 return opfResponse ;
325321 }
326322
327323 /**
328- * Perform an API request to the SHERPA v2 API to count the results related to the given parameters.
324+ * Perform an API request to the Open Policy Finder API to count the results related to the given parameters.
329325 *
330326 * @param type entity type eg "publication" or "publisher"
331327 * @param field field eg "issn" or "title"
@@ -334,47 +330,45 @@ public OpenPolicyFinderResponse performRequest(String type, String field, String
334330 * @return the count
335331 */
336332 public int performCountRequest (String type , String field , String predicate , String value ) {
337-
338333 // API Key is *required* for v2 API calls
339334 if (null == apiKey ) {
340- log .error ("SHERPA ROMeO API Key missing: please register for an API key and set sherpa.romeo.apikey" );
335+ log .error ("Open Policy Finder API Key missing: " +
336+ "please register for an API key and set openpolicyfinder.apikey" );
341337 return 0 ;
342338 }
343339
344340 HttpGet method = null ;
345-
346341 try (CloseableHttpClient client = DSpaceHttpClientFactory .getInstance ().buildWithoutAutomaticRetries (5 )) {
347342 Thread .sleep (sleepBetweenTimeouts );
348343
349- method = constructHttpGet (type , field , predicate , value , SHERPAFormat .IDS , 0 , 0 );
344+ method = constructHttpGet (type , field , predicate , value , OpenPolicyFinderFormat .IDS , 0 , 0 );
350345
351346 HttpResponse response = client .execute (method );
352347 int statusCode = response .getStatusLine ().getStatusCode ();
353348
354349 if (statusCode != HttpStatus .SC_OK ) {
355350 String errorBody = IOUtils .toString (response .getEntity ().getContent (), StandardCharsets .UTF_8 );
356- log .error ("Error from SHERPA HTTP request: " + errorBody );
351+ log .error ("Error from OpenPolicyFinder HTTP request: " + errorBody );
357352 return 0 ;
358353 }
359354
360355 HttpEntity responseBody = response .getEntity ();
361356 if (responseBody == null ) {
362- log .debug ("Empty SHERPA response body for query on " + value );
357+ log .debug ("Empty OpenPolicyFinder response body for query on " + value );
363358 return 0 ;
364359 }
365360
366361 String responseContent = IOUtils .toString (responseBody .getContent (), StandardCharsets .UTF_8 );
367362 return (int ) responseContent .lines ().count ();
368363
369364 } catch (Exception ex ) {
370- log .error ("An error occurs counting the SHERPA entries" , ex );
365+ log .error ("An error occurs counting the OpenPolicyFinder entries" , ex );
371366 return 0 ;
372367 } finally {
373368 if (method != null ) {
374369 method .releaseConnection ();
375370 }
376371 }
377-
378372 }
379373
380374 /**
@@ -404,7 +398,7 @@ public HttpGet constructHttpGet(String type, String field, String predicate, Str
404398 */
405399 public HttpGet constructHttpGet (String type , String field , String predicate , String value , int start , int limit )
406400 throws URISyntaxException {
407- return constructHttpGet (type , field , predicate , value , SHERPAFormat .JSON , start , limit );
401+ return constructHttpGet (type , field , predicate , value , OpenPolicyFinderFormat .JSON , start , limit );
408402 }
409403
410404 /**
@@ -419,9 +413,8 @@ public HttpGet constructHttpGet(String type, String field, String predicate, Str
419413 * @return HttpGet object to be executed by the client
420414 * @throws URISyntaxException
421415 */
422- public HttpGet constructHttpGet (String type , String field , String predicate , String value , SHERPAFormat format ,
423- int start , int limit ) throws URISyntaxException {
424-
416+ public HttpGet constructHttpGet (String type , String field , String predicate , String value ,
417+ OpenPolicyFinderFormat format ,int start , int limit ) throws URISyntaxException {
425418 // Sanitise query string (strip some characters) field, predicate and value
426419 if (null == type ) {
427420 type = "publication" ;
@@ -455,13 +448,11 @@ public HttpGet constructHttpGet(String type, String field, String predicate, Str
455448 }
456449
457450 // Set connection parameters
458- int timeout = 5000 ;
459451 method .setConfig (RequestConfig .custom ()
460- .setConnectionRequestTimeout (timeout )
461- .setConnectTimeout (timeout )
462- .setSocketTimeout (timeout )
452+ .setConnectionRequestTimeout (this . timeout )
453+ .setConnectTimeout (this . timeout )
454+ .setSocketTimeout (this . timeout )
463455 .build ());
464-
465456 return method ;
466457 }
467458
@@ -489,7 +480,7 @@ public URI prepareQuery(String query, String endpoint, String apiKey) throws URI
489480 log .warn ("No ISSN supplied as query string for Open Policy Finder service search" );
490481 }
491482 uriBuilder .addParameter ("filter" , "[[\" issn\" ,\" equals\" ,\" " + query + "\" ]]" );
492- uriBuilder .addParameter ("format" , SHERPAFormat .JSON .getValue ());
483+ uriBuilder .addParameter ("format" , OpenPolicyFinderFormat .JSON .getValue ());
493484 log .debug ("Would search Open Policy Finder endpoint with " + uriBuilder .toString ());
494485
495486 // Return final built URI
0 commit comments