Skip to content

Commit 00501a2

Browse files
kosarkokuchtiak-ufalCopilot
authored
[Port to dtq-dev] Issue ufal#1351 simple ror authority (#1349)
* Issue ufal#1351 simple ror authority (ufal#1352) * Issue 1351: SimpleRORAuthority * integration test * code cleanup * add debug messages to find test failure * Revert "add debug messages to find test failure" This reverts commit 286fde4. * test failures * Revert "test failures" This reverts commit 8808f5e. * resolve Copilot comments * resolve PR comments, add ROR lookup to Publisher field * rollback changes in VocabularyEntryLinkRepository * fixing failing tests * implement PR Comments * implementation improvement * resolve PR comments (O.Kosarko) * Address review nits: shared ObjectMapper, commons-lang3, IT cleanup - Reuse a single static ObjectMapper in SimpleRORAuthority instead of constructing one per call. - Switch to the non-deprecated org.apache.commons.lang3.LocaleUtils. - Reset the ChoiceAuthority plugin configuration in @afterclass so VocabularyEntryLinkRepositoryIT no longer leaks the SimpleRORAuthority registration into other integration tests. * implement cache for gertLabel() * resolve PR Comments --------- Co-authored-by: Ondrej Kosarko <kosarko@ufal.mff.cuni.cz> (cherry picked from commit 25a5a25) * fix potential NPE Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix possible NPE in getBestMatch * fix possible NPE and some typos * add license header * Don't cache the fallback * resolved CodeRabbit comment --------- Co-authored-by: Milan Kuchtiak <kuchtiak@ufal.mff.cuni.cz> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent e9392ae commit 00501a2

15 files changed

Lines changed: 3539 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)