Skip to content

Commit d3cf079

Browse files
author
Mykhaylo Boychuk
committed
[DSC-2782] rename SherpaAuthority to OpenPolicyFinderAuthority and update related configurations
1 parent 12465f9 commit d3cf079

20 files changed

Lines changed: 249 additions & 274 deletions

dspace-api/src/main/java/org/dspace/app/openpolicyfinder/OpenPolicyFinderService.java

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
import org.apache.logging.log4j.LogManager;
2828
import org.apache.logging.log4j.Logger;
2929
import org.dspace.app.client.DSpaceHttpClientFactory;
30-
import org.dspace.app.sherpa.v2.SHERPAFormat;
30+
import org.dspace.app.openpolicyfinder.v2.OpenPolicyFinderFormat;
3131
import org.dspace.app.openpolicyfinder.v2.OpenPolicyFinderPublisherResponse;
3232
import org.dspace.app.openpolicyfinder.v2.OpenPolicyFinderResponse;
3333
import org.dspace.app.openpolicyfinder.v2.OpenPolicyFinderUtils;
34+
import org.dspace.external.provider.impl.OpenPolicyFinderJournalDataProvider;
35+
import org.dspace.external.provider.impl.OpenPolicyFinderPublisherDataProvider;
3436
import org.dspace.services.ConfigurationService;
3537
import org.springframework.beans.factory.annotation.Autowired;
3638
import org.springframework.cache.annotation.Cacheable;
@@ -41,21 +43,22 @@
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
*/
4850
public 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

dspace-api/src/main/java/org/dspace/app/openpolicyfinder/submit/OpenPolicyFinderSubmitService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import org.dspace.core.LogHelper;
2121

2222
/**
23-
* OpenPolicyFinderSubmitService is
24-
* @see
23+
* OpenPolicyFinderSubmitService is responsible for querying the Open Policy Finder API
24+
* during item submission to retrieve journal publishing policies by ISSN.
25+
*
2526
* @author Kim Shepherd
2627
*/
2728
public class OpenPolicyFinderSubmitService {

dspace-api/src/main/java/org/dspace/app/openpolicyfinder/v2/SHERPAFormat.java renamed to dspace-api/src/main/java/org/dspace/app/openpolicyfinder/v2/OpenPolicyFinderFormat.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
*
66
* http://www.dspace.org/license/
77
*/
8-
package org.dspace.app.sherpa.v2;
8+
package org.dspace.app.openpolicyfinder.v2;
99

1010
/**
11-
* Enum that list the supported format by Sherpa API.
11+
* Enum that list the supported format by Open Policy Finder API.
1212
*
1313
* @author Luca Giamminonni (luca.giamminonni at 4Science)
1414
*
1515
*/
16-
public enum SHERPAFormat {
16+
public enum OpenPolicyFinderFormat {
1717

1818
JSON("Json"),
1919
IDS("Ids");
2020

2121
private final String value;
2222

23-
private SHERPAFormat(String value) {
23+
private OpenPolicyFinderFormat(String value) {
2424
this.value = value;
2525
}
2626

dspace-api/src/main/java/org/dspace/app/openpolicyfinder/v2/OpenPolicyFinderJournal.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class OpenPolicyFinderJournal implements Serializable {
2727
private List<String> titles;
2828
private String url;
2929
private List<String> issns;
30-
private String romeoPub;
30+
private String publisherDisplay;
3131
private String zetoPub;
3232
private OpenPolicyFinderPublisher publisher;
3333
private List<OpenPolicyFinderPublisher> publishers;
@@ -62,12 +62,12 @@ public void setIssns(List<String> issns) {
6262
this.issns = issns;
6363
}
6464

65-
public String getRomeoPub() {
66-
return romeoPub;
65+
public String getPublisherDisplay() {
66+
return publisherDisplay;
6767
}
6868

69-
public void setRomeoPub(String romeoPub) {
70-
this.romeoPub = romeoPub;
69+
public void setPublisherDisplay(String publisherDisplay) {
70+
this.publisherDisplay = publisherDisplay;
7171
}
7272

7373
public String getZetoPub() {

dspace-api/src/main/java/org/dspace/app/openpolicyfinder/v2/OpenPolicyFinderResponse.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ public class OpenPolicyFinderResponse implements Serializable {
6161
@JsonIgnore
6262
private Date retrievalTime = new Date();
6363

64-
// Format enum - currently only JSON is supported
65-
public enum ResponseFormat {
66-
JSON, XML
67-
};
68-
6964
private static Logger log = LogManager.getLogger();
7065

7166
/**
@@ -74,8 +69,8 @@ public enum ResponseFormat {
7469
* @param format - requested format
7570
* @throws IOException
7671
*/
77-
public OpenPolicyFinderResponse(InputStream input, ResponseFormat format) throws IOException {
78-
if (format == ResponseFormat.JSON) {
72+
public OpenPolicyFinderResponse(InputStream input, OpenPolicyFinderFormat format) throws IOException {
73+
if (format == OpenPolicyFinderFormat.JSON) {
7974
parseJSON(input);
8075
}
8176
}
@@ -86,7 +81,7 @@ public OpenPolicyFinderResponse(InputStream input, ResponseFormat format) throws
8681
public OpenPolicyFinderResponse() {}
8782

8883
/**
89-
* Parse the Open Policy Finder API JSON and construct Romeo policy data for display
84+
* Parse the Open Policy Finder API JSON and construct publisher policy data for display
9085
* This method does not return a value, but rather populates the metadata and journals objects
9186
* with data parsed from the JSON.
9287
* @param jsonData - the JSON input stream from the API result response body
@@ -275,7 +270,7 @@ private OpenPolicyFinderJournal parseJournal(JSONObject item, String publisherNa
275270
journal.setTitles(titleList);
276271
if (titleList.size() > 0) {
277272
// Faking this a bit based on what I'd seen - not in the API v2 data
278-
journal.setRomeoPub(publisherName + ": "
273+
journal.setPublisherDisplay(publisherName + ": "
279274
+ titleList.get(0));
280275
journal.setZetoPub(publisherName + ": "
281276
+ titleList.get(0));

0 commit comments

Comments
 (0)