mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +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 {
|
try {
|
||||||
DCInputsReader dcInputsReader = new DCInputsReader();
|
DCInputsReader dcInputsReader = new DCInputsReader();
|
||||||
for (DCInputSet dcinputSet : dcInputsReader.getAllInputs(Integer.MAX_VALUE, 0)) {
|
for (DCInputSet dcinputSet : dcInputsReader.getAllInputs(Integer.MAX_VALUE, 0)) {
|
||||||
DCInput[] dcinputs = dcinputSet.getFields();
|
DCInput[] dcinputs = dcinputSet.getFields();
|
||||||
for (DCInput dcinput : dcinputs) {
|
for (DCInput dcinput : dcinputs) {
|
||||||
if (dcinput.getPairsType() != null
|
if (StringUtils.isNotBlank(dcinput.getPairsType())
|
||||||
&& !StringUtils.equals(dcinput.getInputType(), "qualdrop_value")) {
|
|| 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(),
|
String fieldKey = makeFieldKey(dcinput.getSchema(), dcinput.getElement(),
|
||||||
dcinput.getQualifier());
|
dcinput.getQualifier());
|
||||||
String authorityName = "inputForm" + fieldKey;
|
|
||||||
ChoiceAuthority ca = controller.get(authorityName);
|
ChoiceAuthority ca = controller.get(authorityName);
|
||||||
if (ca == null) {
|
if (ca == null) {
|
||||||
InputFormSelfRegisterWrapperAuthority ifa = new InputFormSelfRegisterWrapperAuthority();
|
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);
|
controller.put(fieldKey, ifa);
|
||||||
} else {
|
} else {
|
||||||
ca = (InputFormSelfRegisterWrapperAuthority)ca;
|
ca = (InputFormSelfRegisterWrapperAuthority) ca;
|
||||||
controller.put(fieldKey, ca);
|
controller.put(fieldKey, ca);
|
||||||
}
|
}
|
||||||
|
if (!authorities.containsKey(authorityName)) {
|
||||||
authorityNames.add(authorityName);
|
authorityNames.add(authorityName);
|
||||||
|
authorities.put(authorityName, fieldKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (DCInputsReaderException e) {
|
} catch (DCInputsReaderException e) {
|
||||||
throw new IllegalStateException(e.getMessage(), e);
|
throw new IllegalStateException(e.getMessage(), e);
|
||||||
|
@@ -11,48 +11,42 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.core.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This authority is registered automatically by the ChoiceAuthorityService for
|
* 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
|
* 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)
|
* @author Andrea Bollini (andrea.bollini at 4science.it)
|
||||||
*/
|
*/
|
||||||
public class InputFormSelfRegisterWrapperAuthority implements ChoiceAuthority
|
public class InputFormSelfRegisterWrapperAuthority implements ChoiceAuthority
|
||||||
{
|
{
|
||||||
private Map<String, ChoiceAuthority> delegates = new HashMap<String, ChoiceAuthority>();
|
private ChoiceAuthority delegate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Choices getMatches(String field, String query, Collection collection, int start, int limit, String locale)
|
public Choices getMatches(String field, String query, Collection collection, int start, int limit, String locale)
|
||||||
{
|
{
|
||||||
String formName = null; //Utils.getInputFormName(collection);
|
return delegate.getMatches(field, query, collection, start, limit, locale);
|
||||||
return delegates.get(formName).getMatches(field, query, collection, start, limit, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Choices getBestMatch(String field, String text, Collection collection, String locale)
|
public Choices getBestMatch(String field, String text, Collection collection, String locale)
|
||||||
{
|
{
|
||||||
String formName = null; //Utils.getInputFormName(collection);
|
return delegate.getBestMatch(field, text, collection, locale);
|
||||||
return delegates.get(formName).getBestMatch(field, text, collection, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLabel(String field, String key, String locale)
|
public String getLabel(String field, String key, String locale)
|
||||||
{
|
{
|
||||||
String formName = null; //Utils.getInputFormName(collection);
|
return delegate.getLabel(field, key, locale);
|
||||||
return delegates.get(formName).getLabel(field, key, locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, ChoiceAuthority> getDelegates() {
|
public ChoiceAuthority getDelegate() {
|
||||||
return delegates;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDelegates(Map<String, ChoiceAuthority> delegates) {
|
public void setDelegate(ChoiceAuthority delegate) {
|
||||||
this.delegates = delegates;
|
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
|
## An example using "srsc" can be found later in this section
|
||||||
|
|
||||||
#plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \
|
plugin.selfnamed.org.dspace.content.authority.ChoiceAuthority = \
|
||||||
# org.dspace.content.authority.DCInputAuthority, \
|
org.dspace.content.authority.DCInputAuthority, \
|
||||||
# org.dspace.content.authority.DSpaceControlledVocabulary
|
org.dspace.content.authority.DSpaceControlledVocabulary
|
||||||
|
|
||||||
## configure LC Names plugin
|
## configure LC Names plugin
|
||||||
#lcname.url = http://alcme.oclc.org/srw/search/lcnaf
|
#lcname.url = http://alcme.oclc.org/srw/search/lcnaf
|
||||||
@@ -1501,8 +1501,6 @@ authority.minconfidence = ambiguous
|
|||||||
## demo: subject code autocomplete, using srsc as authority
|
## demo: subject code autocomplete, using srsc as authority
|
||||||
## (DSpaceControlledVocabulary plugin must be enabled)
|
## (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.
|
## 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.store = true
|
||||||
#vocabulary.plugin.srsc.hierarchy.suggest = true
|
#vocabulary.plugin.srsc.hierarchy.suggest = true
|
||||||
#vocabulary.plugin.srsc.delimiter = "::"
|
#vocabulary.plugin.srsc.delimiter = "::"
|
||||||
@@ -1516,14 +1514,6 @@ authority.minconfidence = ambiguous
|
|||||||
#choices.presentation.dc.title.alternative = suggest
|
#choices.presentation.dc.title.alternative = suggest
|
||||||
#authority.controlled.dc.title.alternative = true
|
#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
|
# Change number of choices shown in the select in Choices lookup popup
|
||||||
#xmlui.lookup.select.size = 12
|
#xmlui.lookup.select.size = 12
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user