mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Avoid to expose the authority where not needed
This commit is contained in:
@@ -18,8 +18,6 @@ import java.util.Map;
|
||||
* @see Choices
|
||||
*/
|
||||
public class Choice {
|
||||
public boolean storeAuthority = true;
|
||||
|
||||
/**
|
||||
* Authority key for this value
|
||||
*/
|
||||
|
@@ -471,4 +471,10 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService
|
||||
}
|
||||
return ma;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storeAuthority(String fieldKey, Collection collection) {
|
||||
// currently only named authority can eventually provide real authority
|
||||
return controller.containsKey(fieldKey);
|
||||
}
|
||||
}
|
||||
|
@@ -108,18 +108,17 @@ public class DCInputAuthority extends SelfNamedPlugin implements ChoiceAuthority
|
||||
init();
|
||||
|
||||
int dflt = -1;
|
||||
int index = 0;
|
||||
Choice v[] = new Choice[values.length];
|
||||
List<Choice> v = new ArrayList<Choice>();
|
||||
for (int i = 0; i < values.length; ++i) {
|
||||
if (query == null || StringUtils.containsIgnoreCase(values[i], query)) {
|
||||
v[index] = new Choice(values[i], values[i], labels[i]);
|
||||
index++;
|
||||
v.add(new Choice(null, values[i], labels[i]));
|
||||
}
|
||||
if (values[i].equalsIgnoreCase(query)) {
|
||||
dflt = i;
|
||||
}
|
||||
}
|
||||
return new Choices(v, 0, index, Choices.CF_AMBIGUOUS, false, dflt);
|
||||
Choice[] vArray = new Choice[v.size()];
|
||||
return new Choices(v.toArray(vArray), 0, v.size(), Choices.CF_AMBIGUOUS, false, dflt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -171,4 +171,13 @@ public interface ChoiceAuthorityService {
|
||||
*/
|
||||
public void clearCache();
|
||||
|
||||
/**
|
||||
* Should we store the authority key (if any) for such field key and collection?
|
||||
*
|
||||
* @param fieldKey single string identifying metadata field
|
||||
* @param collection Collection owner of Item or where the item is submitted to
|
||||
* @return true if the configuration allows to store the authority value
|
||||
*/
|
||||
public boolean storeAuthority(String fieldKey, Collection collection);
|
||||
|
||||
}
|
||||
|
@@ -85,10 +85,9 @@ public class VocabularyEntryLinkRepository extends AbstractDSpaceRestRepository
|
||||
String fieldKey = org.dspace.core.Utils.standardize(tokens[0], tokens[1], tokens[2], "_");
|
||||
Choices choices = cas.getMatches(fieldKey, filter, collection, Math.toIntExact(pageable.getOffset()),
|
||||
pageable.getPageSize(), context.getCurrentLocale().toString());
|
||||
boolean storeAuthority = cas.storeAuthority(fieldKey, collection);
|
||||
for (Choice value : choices.values) {
|
||||
if (value != null) {
|
||||
results.add(authorityUtils.convertEntry(value, name, projection));
|
||||
}
|
||||
results.add(authorityUtils.convertEntry(value, name, storeAuthority, projection));
|
||||
}
|
||||
return new PageImpl<>(results, pageable, results.size());
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.app.rest.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.app.rest.converter.ConverterService;
|
||||
import org.dspace.app.rest.model.VocabularyEntryDetailsRest;
|
||||
import org.dspace.app.rest.model.VocabularyEntryRest;
|
||||
@@ -70,13 +71,16 @@ public class AuthorityUtils {
|
||||
return entry;
|
||||
}
|
||||
|
||||
public VocabularyEntryRest convertEntry(Choice choice, String authorityName, Projection projection) {
|
||||
public VocabularyEntryRest convertEntry(Choice choice, String authorityName, boolean storeAuthority,
|
||||
Projection projection) {
|
||||
VocabularyEntryRest entry = new VocabularyEntryRest();
|
||||
entry.setDisplay(choice.label);
|
||||
entry.setValue(choice.value);
|
||||
entry.setOtherInformation(choice.extras);
|
||||
entry.setAuthority(choice.authority);
|
||||
if (choice.storeAuthority) {
|
||||
if (storeAuthority) {
|
||||
entry.setAuthority(choice.authority);
|
||||
}
|
||||
if (StringUtils.isNotBlank(choice.authority)) {
|
||||
entry.setVocabularyEntryDetailsRest(converter.toRest(choice, projection));
|
||||
}
|
||||
return entry;
|
||||
|
Reference in New Issue
Block a user