Skip to content

Commit 198903b

Browse files
CLARIN-DSpace9.3/SimpleRORAuthority: ROR v2 API ChoiceAuthority lookup for dc.publisher (#1345) (#1381)
(cherry picked from commit 00501a2 on dtq-dev) v9 adaptations: - RorRestConnector.java + MockRorRestConnector.java: javax.ws.rs.* -> jakarta.ws.rs.* (vanilla 9.3 dspace-api is jakarta-only; jersey-client jakarta variant already a dep). MockResponse keeps the OutboundJaxrsResponse subclass approach (readEntity override is load-bearing; plain outbound Response.readEntity throws IllegalStateException). - dspace/config/ehcache.xml: conflict resolved by taking origin/dtq-dev HEAD content wholesale = this commit's ror-default template + ror-labels alias PLUS the B-13 orcid-default template + orcid-labels alias co-port (CLARIN_V9_PARITY_BACKLOG.md B-13) — also fixes the pre-existing live bug @Cacheable("orcid-labels") with no defined cache on v9-base (wiring-dropped pattern). orcid CacheLogger class verified present on v9-base. - enable-ror.cfg stays a NON-included opt-in feature file (local.cfg include), NOT wired into dspace.cfg, per the deployment-override rule. Fulfils CLARIN_V9_POST_SNAPSHOT_SYNC_ACCEPTANCE.md §5 / 00501a2 (BE-3, Vlna 2). Co-authored-by: Ondřej Košarko <ko_ok@centrum.cz>
1 parent 36d8a5d commit 198903b

15 files changed

Lines changed: 3560 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
package org.dspace.content.authority;
9+
10+
import org.dspace.external.RorRestConnector;
11+
import org.dspace.utils.DSpace;
12+
13+
/**
14+
* ChoiceAuthority using the ROR API.
15+
*
16+
* @author Milan Kuchtiak
17+
*/
18+
public class SimpleRORAuthority implements ChoiceAuthority {
19+
20+
private String pluginInstanceName;
21+
22+
private final RorRestConnector rorRestConnector = new DSpace().getServiceManager().getServiceByName(
23+
"RorRestConnector", RorRestConnector.class);
24+
25+
/**
26+
* Get all values from the authority that match the preferred value.
27+
* Note that the offering was entered by the user and may contain
28+
* mixed/incorrect case, whitespace, etc so the plugin should be careful
29+
* to clean up user data before making comparisons.
30+
* <p>
31+
* Value of a "Name" field will be in canonical DSpace person name format,
32+
* which is "Lastname, Firstname(s)", e.g. "Smith, John Q.".
33+
* <p>
34+
* Some authorities with a small set of values may simply return the whole
35+
* set for any sample value, although it's a good idea to set the
36+
* defaultSelected index in the Choices instance to the choice, if any,
37+
* that matches the value.
38+
*
39+
* @param text user's value to match
40+
* @param start choice at which to start, 0 is first.
41+
* @param limit maximum number of choices to return, 0 for no limit.
42+
* @param locale explicit localization key if available, or null
43+
* @return a Choices object (never null).
44+
*/
45+
@Override
46+
public Choices getMatches(String text, int start, int limit, String locale) {
47+
return rorRestConnector.getMatches(text, start, limit, locale);
48+
}
49+
50+
/**
51+
* Get the single "best" match (if any) of a value in the authority
52+
* to the given user value. The "confidence" element of Choices is
53+
* expected to be set to a meaningful value about the circumstances of
54+
* this match.
55+
* <p>
56+
* This call is typically used in non-interactive metadata ingest
57+
* where there is no interactive agent to choose from among options.
58+
*
59+
* @param text user's value to match
60+
* @param locale explicit localization key if available, or null
61+
* @return a Choices object (never null) with 1 or 0 values.
62+
*/
63+
@Override
64+
public Choices getBestMatch(String text, String locale) {
65+
return rorRestConnector.getBestMatch(text, locale);
66+
}
67+
68+
@Override
69+
public Choice getChoice(String authKey, String locale) {
70+
return rorRestConnector.getChoice(authKey, locale);
71+
}
72+
73+
/**
74+
* Get the canonical user-visible "label" (i.e. short descriptive text)
75+
* for a key in the authority. Can be localized given the implicit
76+
* or explicit locale specification.
77+
* <p>
78+
* This may get called many times while populating a Web page so it should
79+
* be implemented as efficiently as possible.
80+
*
81+
* @param key authority key known to this authority.
82+
* @param locale explicit localization key if available, or null
83+
* @return descriptive label - should always return something, never null.
84+
*/
85+
@Override
86+
public String getLabel(String key, String locale) {
87+
return rorRestConnector.getLabel(key, locale);
88+
}
89+
90+
/**
91+
* Get the instance's particular name.
92+
* Returns the name by which the class was chosen when
93+
* this instance was created. Only works for instances created
94+
* by <code>PluginService</code>, or if someone remembers to call <code>setPluginName.</code>
95+
* <p>
96+
* Useful when the implementation class wants to be configured differently
97+
* when it is invoked under different names.
98+
*
99+
* @return name or null if not available.
100+
*/
101+
@Override
102+
public String getPluginInstanceName() {
103+
return pluginInstanceName;
104+
}
105+
106+
/**
107+
* Set the name under which this plugin was instantiated.
108+
* Not to be invoked by application code, it is
109+
* called automatically by <code>PluginService.getNamedPlugin()</code>
110+
* when the plugin is instantiated.
111+
*
112+
* @param name -- name used to select this class.
113+
*/
114+
@Override
115+
public void setPluginInstanceName(String name) {
116+
this.pluginInstanceName = name;
117+
}
118+
119+
}

0 commit comments

Comments
 (0)