mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
DS-3699 auto register choice plugin for value-pairs and controlled vocabulary
This commit is contained in:
@@ -302,27 +302,40 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService
|
||||
try {
|
||||
DCInputsReader dcInputsReader = new DCInputsReader();
|
||||
for (DCInputSet dcinputSet : dcInputsReader.getAllInputs(Integer.MAX_VALUE, 0)) {
|
||||
DCInput[] dcinputs = dcinputSet.getFields();
|
||||
for (DCInput dcinput : dcinputs) {
|
||||
if (dcinput.getPairsType() != null
|
||||
&& !StringUtils.equals(dcinput.getInputType(), "qualdrop_value")) {
|
||||
DCInput[] dcinputs = dcinputSet.getFields();
|
||||
for (DCInput dcinput : dcinputs) {
|
||||
if (StringUtils.isNotBlank(dcinput.getPairsType())
|
||||
|| StringUtils.isNotBlank(dcinput.getVocabulary())) {
|
||||
String authorityName = dcinput.getPairsType();
|
||||
if(StringUtils.isBlank(authorityName)) {
|
||||
authorityName = dcinput.getVocabulary();
|
||||
}
|
||||
if (!StringUtils.equals(dcinput.getInputType(), "qualdrop_value")) {
|
||||
String fieldKey = makeFieldKey(dcinput.getSchema(), dcinput.getElement(),
|
||||
dcinput.getQualifier());
|
||||
String authorityName = "inputForm" + fieldKey;
|
||||
ChoiceAuthority ca = controller.get(authorityName);
|
||||
if (ca == null) {
|
||||
InputFormSelfRegisterWrapperAuthority ifa = new InputFormSelfRegisterWrapperAuthority();
|
||||
ifa.getDelegates().put(authorityName, ca);
|
||||
ChoiceAuthority ma = (ChoiceAuthority)pluginService.getNamedPlugin(ChoiceAuthority.class, authorityName);
|
||||
if (ma == null) {
|
||||
log.warn("Skipping invalid configuration for " + fieldKey
|
||||
+ " because named plugin not found: " + authorityName);
|
||||
continue;
|
||||
}
|
||||
ifa.setDelegate(ma);
|
||||
controller.put(fieldKey, ifa);
|
||||
} else {
|
||||
ca = (InputFormSelfRegisterWrapperAuthority)ca;
|
||||
ca = (InputFormSelfRegisterWrapperAuthority) ca;
|
||||
controller.put(fieldKey, ca);
|
||||
}
|
||||
|
||||
authorityNames.add(authorityName);
|
||||
|
||||
}
|
||||
}
|
||||
if (!authorities.containsKey(authorityName)) {
|
||||
authorityNames.add(authorityName);
|
||||
authorities.put(authorityName, fieldKey);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DCInputsReaderException e) {
|
||||
throw new IllegalStateException(e.getMessage(), e);
|
||||
|
@@ -11,48 +11,42 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.core.Utils;
|
||||
|
||||
/**
|
||||
* This authority is registered automatically by the ChoiceAuthorityService for
|
||||
* all the metadata that use a value-pair or a vocabulary in the input-form.xml
|
||||
*
|
||||
* It keeps a map of form-name vs ChoiceAuthority to delegate the execution of
|
||||
* the method to the specific ChoiceAuthority configured for the collection when
|
||||
* the same metadata have different vocabulary or value-pair on a collection
|
||||
* basis
|
||||
*
|
||||
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||
*/
|
||||
public class InputFormSelfRegisterWrapperAuthority implements ChoiceAuthority
|
||||
{
|
||||
private Map<String, ChoiceAuthority> delegates = new HashMap<String, ChoiceAuthority>();
|
||||
private ChoiceAuthority delegate;
|
||||
|
||||
@Override
|
||||
public Choices getMatches(String field, String query, Collection collection, int start, int limit, String locale)
|
||||
{
|
||||
String formName = null; //Utils.getInputFormName(collection);
|
||||
return delegates.get(formName).getMatches(field, query, collection, start, limit, locale);
|
||||
return delegate.getMatches(field, query, collection, start, limit, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Choices getBestMatch(String field, String text, Collection collection, String locale)
|
||||
{
|
||||
String formName = null; //Utils.getInputFormName(collection);
|
||||
return delegates.get(formName).getBestMatch(field, text, collection, locale);
|
||||
return delegate.getBestMatch(field, text, collection, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel(String field, String key, String locale)
|
||||
{
|
||||
String formName = null; //Utils.getInputFormName(collection);
|
||||
return delegates.get(formName).getLabel(field, key, locale);
|
||||
return delegate.getLabel(field, key, locale);
|
||||
}
|
||||
|
||||
public Map<String, ChoiceAuthority> getDelegates() {
|
||||
return delegates;
|
||||
public ChoiceAuthority getDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public void setDelegates(Map<String, ChoiceAuthority> delegates) {
|
||||
this.delegates = delegates;
|
||||
public void setDelegate(ChoiceAuthority delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1458,9 +1458,9 @@ sherpa.romeo.url = http://www.sherpa.ac.uk/romeo/api29.php
|
||||
##
|
||||
## An example using "srsc" can be found later in this section
|
||||
|
||||
#plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \
|
||||
# org.dspace.content.authority.DCInputAuthority, \
|
||||
# org.dspace.content.authority.DSpaceControlledVocabulary
|
||||
plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \
|
||||
org.dspace.content.authority.DCInputAuthority, \
|
||||
org.dspace.content.authority.DSpaceControlledVocabulary
|
||||
|
||||
## configure LC Names plugin
|
||||
#lcname.url = http://alcme.oclc.org/srw/search/lcnaf
|
||||
@@ -1501,8 +1501,6 @@ authority.minconfidence = ambiguous
|
||||
## demo: subject code autocomplete, using srsc as authority
|
||||
## (DSpaceControlledVocabulary plugin must be enabled)
|
||||
## Warning: when enabling this feature any controlled vocabulary configuration in the input-forms.xml for the metadata field will be overridden.
|
||||
#choices.plugin.dc.subject = srsc
|
||||
#choices.presentation.dc.subject = select
|
||||
#vocabulary.plugin.srsc.hierarchy.store = true
|
||||
#vocabulary.plugin.srsc.hierarchy.suggest = true
|
||||
#vocabulary.plugin.srsc.delimiter = "::"
|
||||
@@ -1516,14 +1514,6 @@ authority.minconfidence = ambiguous
|
||||
#choices.presentation.dc.title.alternative = suggest
|
||||
#authority.controlled.dc.title.alternative = true
|
||||
|
||||
## demo: use choice authority (without authority-control) to restrict dc.type on EditItemMetadata page
|
||||
#choices.plugin.dc.type = common_types
|
||||
#choices.presentation.dc.type = select
|
||||
|
||||
## demo: same idea for dc.language.iso
|
||||
#choices.plugin.dc.language.iso = common_iso_languages
|
||||
#choices.presentation.dc.language.iso = select
|
||||
|
||||
# Change number of choices shown in the select in Choices lookup popup
|
||||
#xmlui.lookup.select.size = 12
|
||||
|
||||
|
Reference in New Issue
Block a user