[DS-3699] finalizing refactoring; improved authority endpoint;

This commit is contained in:
Luigi Andrea Pascarelli
2017-10-20 15:53:39 +02:00
parent 94cf2bd1f0
commit 74539f3458
37 changed files with 788 additions and 456 deletions

View File

@@ -154,23 +154,54 @@ public class DCInputsReader
* if no default set defined * if no default set defined
* @throws ServletException * @throws ServletException
*/ */
public DCInputSet getInputsByCollectionHandle(String collectionHandle) public List<DCInputSet> getInputsByCollectionHandle(String collectionHandle)
throws DCInputsReaderException throws DCInputsReaderException
{ {
SubmissionConfig config; SubmissionConfig config;
try { try {
config = new SubmissionConfigReader().getSubmissionConfigByName(collectionHandle); config = new SubmissionConfigReader().getSubmissionConfigByCollection(collectionHandle);
String formName = config.getSubmissionName(); String formName = config.getSubmissionName();
if (formName == null) if (formName == null)
{ {
throw new DCInputsReaderException("No form designated as default"); throw new DCInputsReaderException("No form designated as default");
} }
return getInputsByFormName(formName); List<DCInputSet> results = new ArrayList<DCInputSet>();
for (int idx = 0; idx < config.getNumberOfSteps(); idx++) {
SubmissionStepConfig step = config.getStep(idx);
if(SubmissionStepConfig.INPUT_FORM_STEP_NAME.equals(step.getType())) {
results.add(getInputsByFormName(step.getId()));
}
}
return results;
} catch (ServletException e) { } catch (ServletException e) {
throw new DCInputsReaderException("No form designated as default"); throw new DCInputsReaderException("No form designated as default");
} }
} }
public List<DCInputSet> getInputsBySubmissionName(String name)
throws DCInputsReaderException
{
SubmissionConfig config;
try {
config = new SubmissionConfigReader().getSubmissionConfigByName(name);
String formName = config.getSubmissionName();
if (formName == null)
{
throw new DCInputsReaderException("No form designated as default");
}
List<DCInputSet> results = new ArrayList<DCInputSet>();
for (int idx = 0; idx < config.getNumberOfSteps(); idx++) {
SubmissionStepConfig step = config.getStep(idx);
if(SubmissionStepConfig.INPUT_FORM_STEP_NAME.equals(step.getType())) {
results.add(getInputsByFormName(step.getId()));
}
}
return results;
} catch (ServletException e) {
throw new DCInputsReaderException("No form designated as default");
}
}
/** /**
* Returns the set of DC inputs used for a particular input form * Returns the set of DC inputs used for a particular input form
* *

View File

@@ -30,6 +30,9 @@ import java.io.Serializable;
*/ */
public class SubmissionStepConfig implements Serializable public class SubmissionStepConfig implements Serializable
{ {
public static final String INPUT_FORM_STEP_NAME = "input-form";
/* /*
* The identifier for the Select Collection step * The identifier for the Select Collection step
*/ */

View File

@@ -489,66 +489,57 @@ public class Util {
// Read the input form file for the specific collection // Read the input form file for the specific collection
DCInputsReader inputsReader = new DCInputsReader(formFileName); DCInputsReader inputsReader = new DCInputsReader(formFileName);
DCInputSet inputSet = inputsReader.getInputsByCollectionHandle(col_handle); List<DCInputSet> inputSets = inputsReader.getInputsByCollectionHandle(col_handle);
// Replace the values of Metadatum[] with the correct ones in case of for (DCInputSet inputSet : inputSets) {
// controlled vocabularies // Replace the values of Metadatum[] with the correct ones in case
String currentField = schema + "." + element // of
+ (qualifier == null ? "" : "." + qualifier); // controlled vocabularies
String currentField = schema + "." + element + (qualifier == null ? "" : "." + qualifier);
if (inputSet != null) if (inputSet != null) {
{
int fieldsNums = inputSet.getNumberFields(); int fieldsNums = inputSet.getNumberFields();
for (int p = 0; p < fieldsNums; p++) for (int p = 0; p < fieldsNums; p++) {
{
DCInput[] inputs = inputSet.getFields(); DCInput[] inputs = inputSet.getFields();
if (inputs != null) if (inputs != null) {
{
for (int i = 0; i < inputs.length; i++) for (int i = 0; i < inputs.length; i++) {
{ String inputField = inputs[i].getSchema() + "." + inputs[i].getElement()
String inputField = inputs[i].getSchema() + (inputs[i].getQualifier() == null ? "" : "." + inputs[i].getQualifier());
+ "." if (currentField.equals(inputField)) {
+ inputs[i].getElement()
+ (inputs[i].getQualifier() == null ? "" : "."
+ inputs[i].getQualifier());
if (currentField.equals(inputField))
{
myInputs = inputs[i]; myInputs = inputs[i];
myInputsFound = true; myInputsFound = true;
break; break;
} }
} }
} }
if (myInputsFound) if (myInputsFound)
break; break;
} }
} }
if (myInputsFound) if (myInputsFound) {
{
for (MetadataValue value : values) { for (MetadataValue value : values) {
String pairsName = myInputs.getPairsType(); String pairsName = myInputs.getPairsType();
String stored_value = value.getValue(); String stored_value = value.getValue();
String displayVal = myInputs.getDisplayString(pairsName, String displayVal = myInputs.getDisplayString(pairsName, stored_value);
stored_value);
if (displayVal != null && !"".equals(displayVal)) { if (displayVal != null && !"".equals(displayVal)) {
toReturn.add(displayVal); toReturn.add(displayVal);
} }
}
}
}
}
}
return toReturn; return toReturn;
} }
} }

View File

@@ -7,6 +7,7 @@
*/ */
package org.dspace.content.authority; package org.dspace.content.authority;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@@ -27,7 +28,7 @@ public class Choice
/** The canonical text value to insert into MetadataValue's text field */ /** The canonical text value to insert into MetadataValue's text field */
public String value = null; public String value = null;
public Map<String, String> extras = null; public Map<String, String> extras = new HashMap<String, String>();
public Choice() public Choice()
{ {

View File

@@ -75,15 +75,15 @@ public interface ChoiceAuthority
*/ */
public String getLabel(String field, String key, String locale); public String getLabel(String field, String key, String locale);
default public boolean isHierarchical() { default boolean isHierarchical() {
return false; return false;
} }
default public boolean isScrollable() { default boolean isScrollable() {
return false; return false;
} }
default public boolean hasIdentifier() { default boolean hasIdentifier() {
return true; return true;
} }
@@ -94,4 +94,5 @@ public interface ChoiceAuthority
result.value = getLabel(fieldKey, authKey, locale); result.value = getLabel(fieldKey, authKey, locale);
return result; return result;
} }
} }

View File

@@ -206,32 +206,17 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService
return null; return null;
} }
@Override
public boolean isHierarchical(String schema, String element, String qualifier) {
String fieldKey = makeFieldKey(schema, element, qualifier);
ChoiceAuthority ma = getChoiceAuthorityMap().get(fieldKey);
if (ma == null)
{
// throw new IllegalArgumentException("No choices plugin was configured for field \"" + fieldKey + "\".");
return false;
}
return ma.isHierarchical();
}
@Override
public boolean isScrollable(String schema, String element, String qualifier) {
String fieldKey = makeFieldKey(schema, element, qualifier);
ChoiceAuthority ma = getChoiceAuthorityMap().get(fieldKey);
if (ma == null)
{
// throw new IllegalArgumentException("No choices plugin was configured for field \"" + fieldKey + "\".");
return false;
}
return ma.isScrollable();
}
@Override @Override
public String getChoiceAuthorityName(String schema, String element, String qualifier) { public String getChoiceAuthorityName(String schema, String element, String qualifier) {
String makeFieldKey = makeFieldKey(schema, element, qualifier);
if(getChoiceAuthorityMap().containsKey(makeFieldKey)) {
for(String key : this.authorities.keySet()) {
if(this.authorities.get(key).equals(makeFieldKey)) {
return key;
}
}
}
return configurationService.getProperty( return configurationService.getProperty(
CHOICES_PLUGIN_PREFIX + schema + "." + element + (qualifier != null ? "." + qualifier : "")); CHOICES_PLUGIN_PREFIX + schema + "." + element + (qualifier != null ? "." + qualifier : ""));
} }
@@ -316,18 +301,20 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService
ChoiceAuthority ca = controller.get(authorityName); ChoiceAuthority ca = controller.get(authorityName);
if (ca == null) { if (ca == null) {
InputFormSelfRegisterWrapperAuthority ifa = new InputFormSelfRegisterWrapperAuthority(); InputFormSelfRegisterWrapperAuthority ifa = new InputFormSelfRegisterWrapperAuthority();
if(controller.containsKey(fieldKey)) {
ifa = (InputFormSelfRegisterWrapperAuthority)controller.get(fieldKey);
}
ChoiceAuthority ma = (ChoiceAuthority)pluginService.getNamedPlugin(ChoiceAuthority.class, authorityName); ChoiceAuthority ma = (ChoiceAuthority)pluginService.getNamedPlugin(ChoiceAuthority.class, authorityName);
if (ma == null) { if (ma == null) {
log.warn("Skipping invalid configuration for " + fieldKey log.warn("Skipping invalid configuration for " + fieldKey
+ " because named plugin not found: " + authorityName); + " because named plugin not found: " + authorityName);
continue; continue;
} }
ifa.setDelegate(ma); ifa.getDelegates().put(dcinputSet.getFormName(), ma);
controller.put(fieldKey, ifa); controller.put(fieldKey, ifa);
} else { }
ca = (InputFormSelfRegisterWrapperAuthority) ca;
controller.put(fieldKey, ca);
}
if (!authorities.containsKey(authorityName)) { if (!authorities.containsKey(authorityName)) {
authorityNames.add(authorityName); authorityNames.add(authorityName);
authorities.put(authorityName, fieldKey); authorities.put(authorityName, fieldKey);
@@ -421,11 +408,15 @@ public final class ChoiceAuthorityServiceImpl implements ChoiceAuthorityService
} }
@Override @Override
public boolean hasIdentifier(String schema, String element, String qualifier) { public ChoiceAuthority getChoiceAuthorityByAuthorityName(String authorityName) {
ChoiceAuthority ma = getChoiceAuthorityMap().get(makeFieldKey(schema, element, qualifier)); ChoiceAuthority ma = (ChoiceAuthority)
if(ma == null) { pluginService.getNamedPlugin(ChoiceAuthority.class, authorityName);
return false; if (ma == null)
} {
return ma.hasIdentifier(); throw new IllegalArgumentException(
"No choices plugin was configured for authorityName \"" + authorityName
+ "\".");
}
return ma;
} }
} }

View File

@@ -7,27 +7,26 @@
*/ */
package org.dspace.content.authority; package org.dspace.content.authority;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.io.File;
import org.apache.commons.lang.ArrayUtils;
import org.dspace.content.Collection;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.xpath.XPath; import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactory;
import org.xml.sax.InputSource; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.content.Collection;
import org.dspace.core.SelfNamedPlugin; import org.dspace.core.SelfNamedPlugin;
import org.dspace.services.ConfigurationService; import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
/** /**
* ChoiceAuthority source that reads the JSPUI-style hierarchical vocabularies * ChoiceAuthority source that reads the JSPUI-style hierarchical vocabularies
@@ -63,6 +62,7 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
private static Logger log = Logger.getLogger(DSpaceControlledVocabulary.class); private static Logger log = Logger.getLogger(DSpaceControlledVocabulary.class);
protected static String xpathTemplate = "//node[contains(translate(@label,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'%s')]"; protected static String xpathTemplate = "//node[contains(translate(@label,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'%s')]";
protected static String idTemplate = "//node[@id = '%s']"; protected static String idTemplate = "//node[@id = '%s']";
protected static String idParentTemplate = "//node[@id = '%s']/parent::isComposedBy";
protected static String pluginNames[] = null; protected static String pluginNames[] = null;
protected String vocabularyName = null; protected String vocabularyName = null;
@@ -177,29 +177,12 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
String[] authorities = new String[results.getLength()]; String[] authorities = new String[results.getLength()];
String[] values = new String[results.getLength()]; String[] values = new String[results.getLength()];
String[] labels = new String[results.getLength()]; String[] labels = new String[results.getLength()];
String[] parent = new String[results.getLength()];
String[] notes = new String[results.getLength()];
for (int i = 0; i < results.getLength(); i++) for (int i = 0; i < results.getLength(); i++)
{ {
Node node = results.item(i); Node node = results.item(i);
String hierarchy = this.buildString(node); readNode(authorities, values, labels, parent, notes, i, node);
if (this.suggestHierarchy)
{
labels[i] = hierarchy;
}
else
{
labels[i] = node.getAttributes().getNamedItem("label").getNodeValue();
}
if (this.storeHierarchy)
{
values[i] = hierarchy;
}
else
{
values[i] = node.getAttributes().getNamedItem("label").getNodeValue();
}
Node idAttr = node.getAttributes().getNamedItem("id");
if (null != idAttr) // 'id' is optional
authorities[i] = idAttr.getNodeValue();
} }
int resultCount = labels.length - start; int resultCount = labels.length - start;
if ((limit > 0) && (resultCount > limit)) // limit = 0 means no limit if ((limit > 0) && (resultCount > limit)) // limit = 0 means no limit
@@ -211,6 +194,12 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
{ {
choices[i] = new Choice(authorities[start + i], values[start choices[i] = new Choice(authorities[start + i], values[start
+ i], labels[start + i]); + i], labels[start + i]);
if(StringUtils.isNotBlank(parent[i])) {
choices[i].extras.put("parent", parent[i]);
}
if(StringUtils.isNotBlank(notes[i])) {
choices[i].extras.put("note", notes[i]);
}
} }
} }
} catch(XPathExpressionException e) { } catch(XPathExpressionException e) {
@@ -219,6 +208,7 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false); return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false);
} }
@Override @Override
public Choices getBestMatch(String field, String text, Collection collection, String locale) public Choices getBestMatch(String field, String text, Collection collection, String locale)
{ {
@@ -240,4 +230,96 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Choic
return(""); return("");
} }
} }
@Override
public boolean isHierarchical() {
return true;
}
@Override
public Choice getChoice(String fieldKey, String authKey, String locale) {
init();
log.debug("Getting matches for '" + authKey + "'");
String xpathExpression = String.format(idTemplate, authKey);
XPath xpath = XPathFactory.newInstance().newXPath();
try {
Node node = (Node) xpath.evaluate(xpathExpression, vocabulary, XPathConstants.NODE);
if (node != null) {
String[] authorities = new String[1];
String[] values = new String[1];
String[] labels = new String[1];
String[] parent = new String[1];
String[] note = new String[1];
readNode(authorities, values, labels, parent, note, 0, node);
if (values.length > 0) {
Choice choice = new Choice(authorities[0], values[0], labels[0]);
if (StringUtils.isNotBlank(parent[0])) {
choice.extras.put("parent", parent[0]);
}
if(StringUtils.isNotBlank(note[0])) {
choice.extras.put("note", note[0]);
}
return choice;
}
}
} catch (XPathExpressionException e) {
log.warn(e.getMessage(), e);
}
return new Choice("", "", "");
}
private void readNode(String[] authorities, String[] values, String[] labels, String[] parent, String[] notes, int i, Node node) {
String hierarchy = this.buildString(node);
if (this.suggestHierarchy)
{
labels[i] = hierarchy;
}
else
{
labels[i] = node.getAttributes().getNamedItem("label").getNodeValue();
}
if (this.storeHierarchy)
{
values[i] = hierarchy;
}
else
{
values[i] = node.getAttributes().getNamedItem("label").getNodeValue();
}
NodeList childNodes = node.getChildNodes();
for (int ci = 0; ci < childNodes.getLength(); ci++)
{
Node firstChild = childNodes.item(ci);
if(firstChild!=null && "hasNote".equals(firstChild.getNodeName())) {
String nodeValue = firstChild.getTextContent();
if(StringUtils.isNotBlank(nodeValue)) {
notes[i] = nodeValue;
}
}
}
Node idAttr = node.getAttributes().getNamedItem("id");
if (null != idAttr) { // 'id' is optional
authorities[i] = idAttr.getNodeValue();
if(isHierarchical()) {
Node parentN = node.getParentNode();
if(parentN != null) {
parentN = parentN.getParentNode();
if (parentN != null) {
Node parentIdAttr = parentN.getAttributes().getNamedItem("id");
if (null != parentIdAttr) {
parent[i] = parentIdAttr.getNodeValue();
}
}
}
}
}
else {
authorities[i] = null;
parent[i] = null;
}
}
} }

View File

@@ -10,6 +10,8 @@ package org.dspace.content.authority;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.dspace.app.util.DCInputsReaderException;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.core.Utils; import org.dspace.core.Utils;
@@ -17,36 +19,95 @@ 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 ChoiceAuthority delegate;
@Override private Map<String, ChoiceAuthority> delegates = new HashMap<String, ChoiceAuthority>();
public Choices getMatches(String field, String query, Collection collection, int start, int limit, String locale)
{
return delegate.getMatches(field, query, collection, start, limit, locale);
}
@Override @Override
public Choices getBestMatch(String field, String text, Collection collection, String locale) public Choices getMatches(String field, String query, Collection collection, int start, int limit, String locale) {
{ String formName;
return delegate.getBestMatch(field, text, collection, locale); try {
} formName = Utils.getInputFormNameByCollectionAndField(collection, field);
return delegates.get(formName).getMatches(field, query, collection, start, limit, locale);
@Override } catch (DCInputsReaderException e) {
public String getLabel(String field, String key, String locale) // TODO Auto-generated catch block
{ e.printStackTrace();
return delegate.getLabel(field, key, locale); }
} return null;
public ChoiceAuthority getDelegate() {
return delegate;
} }
public void setDelegate(ChoiceAuthority delegate) { @Override
this.delegate = delegate; public Choices getBestMatch(String field, String text, Collection collection, String locale) {
String formName;
try {
formName = Utils.getInputFormNameByCollectionAndField(collection, field);
return delegates.get(formName).getBestMatch(field, text, collection, locale);
} catch (DCInputsReaderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} }
@Override
public String getLabel(String field, String key, String locale) {
// TODO we need to manage REALLY the authority
// WRONG BEHAVIOUR: now in each delegates can exists the same key with
// different value
for (ChoiceAuthority delegate : delegates.values()) {
String label = delegate.getLabel(field, key, locale);
if (StringUtils.isNotBlank(label)) {
return label;
}
}
return "UNKNOWN KEY " + key;
}
@Override
public boolean isHierarchical() {
// TODO we need to manage REALLY the authority
// WRONG BEHAVIOUR: now in each delegates can exists the same key with
// different value
for (ChoiceAuthority delegate : delegates.values()) {
return delegate.isHierarchical();
}
return false;
}
@Override
public boolean isScrollable() {
// TODO we need to manage REALLY the authority
// WRONG BEHAVIOUR: now in each delegates can exists the same key with
// different value
for (ChoiceAuthority delegate : delegates.values()) {
return delegate.isScrollable();
}
return false;
}
@Override
public boolean hasIdentifier() {
// TODO we need to manage REALLY the authority
// WRONG BEHAVIOUR: now in each delegates can exists the same key with
// different value
for (ChoiceAuthority delegate : delegates.values()) {
return delegate.hasIdentifier();
}
return false;
}
public Map<String, ChoiceAuthority> getDelegates() {
return delegates;
}
public void setDelegates(Map<String, ChoiceAuthority> delegates) {
this.delegates = delegates;
}
} }

View File

@@ -37,6 +37,7 @@ import org.dspace.content.authority.Choices;
*/ */
public interface ChoiceAuthorityService public interface ChoiceAuthorityService
{ {
/** /**
* *
* @return the names of all the defined choice authorities * @return the names of all the defined choice authorities
@@ -53,30 +54,6 @@ public interface ChoiceAuthorityService
* *
*/ */
public String getChoiceAuthorityName(String schema, String element, String qualifier); public String getChoiceAuthorityName(String schema, String element, String qualifier);
/**
* Wrapper that calls isHierachical method of the plugin corresponding to
* the metadata field defined by schema,element,qualifier.
*
* @see org.dspace.content.authority.ChoiceAuthority#isHierachical()
* @param schema schema of metadata field
* @param element element of metadata field
* @param qualifier qualifier of metadata field
* @return true if the authority structure is hierachical
*/
public boolean isHierarchical(String schema, String element, String qualifier);
/**
* Wrapper that calls isScrollable method of the plugin corresponding to
* the metadata field defined by schema,element,qualifier.
*
* @see org.dspace.content.authority.ChoiceAuthority#isScrollable()
* @param schema schema of metadata field
* @param element element of metadata field
* @param qualifier qualifier of metadata field
* @return true if the authority can be scrolled other than searched
*/
public boolean isScrollable(String schema, String element, String qualifier);
/** /**
* Wrapper that calls getMatches method of the plugin corresponding to * Wrapper that calls getMatches method of the plugin corresponding to
@@ -181,6 +158,7 @@ public interface ChoiceAuthorityService
public String getChoiceMetadatabyAuthorityName(String name); public String getChoiceMetadatabyAuthorityName(String name);
public Choice getChoice(String fieldKey, String authKey, String locale); public Choice getChoice(String fieldKey, String authKey, String locale);
public boolean hasIdentifier(String schema, String element, String qualifier); public ChoiceAuthority getChoiceAuthorityByAuthorityName(String authorityName);
} }

View File

@@ -16,14 +16,28 @@ import java.math.BigInteger;
import java.rmi.dgc.VMID; import java.rmi.dgc.VMID;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.*; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.text.SimpleDateFormat;
import java.text.ParseException; import org.apache.commons.lang3.StringUtils;
import com.coverity.security.Escape;
import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.app.util.DCInput;
import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.DCInputsReaderException;
import org.dspace.content.Collection;
import com.coverity.security.Escape;
/** /**
* Utility functions for DSpace. * Utility functions for DSpace.
@@ -411,7 +425,50 @@ public final class Utils
return result.substring(0, rl-2) + ":" + result.substring(rl-2); return result.substring(0, rl-2) + ":" + result.substring(rl-2);
} }
public static <E> Collection<E> emptyIfNull(Collection<E> collection) { public static <E> java.util.Collection<E> emptyIfNull(java.util.Collection<E> collection) {
return collection == null ? Collections.<E>emptyList() : collection; return collection == null ? Collections.<E>emptyList() : collection;
} }
public static String getInputFormNameByCollectionAndField(Collection collection, String field) throws DCInputsReaderException {
DCInputsReader dcInputsReader = new DCInputsReader();
List<DCInputSet> inputSets = dcInputsReader.getInputsByCollectionHandle(collection.getHandle());
for (DCInputSet inputSet : inputSets) {
String[] tokenized = tokenize(field);
String element = tokenized[1];
String qualifier = tokenized[2];
if(StringUtils.isBlank(qualifier)) {
qualifier = null;
}
if (inputSet.isFieldPresent(element+"."+qualifier)) {
return inputSet.getFormName();
}
}
throw new DCInputsReaderException("No field configuration found!");
}
public static String[] tokenize(String metadata) {
String separator = metadata.contains("_") ? "_" : ".";
StringTokenizer dcf = new StringTokenizer(metadata, separator);
String[] tokens = { "", "", "" };
int i = 0;
while (dcf.hasMoreTokens()) {
tokens[i] = dcf.nextToken().trim();
i++;
}
// Tokens contains:
// schema = tokens[0];
// element = tokens[1];
// qualifier = tokens[2];
return tokens;
}
public static String standardize(String schema, String element, String qualifier, String separator) {
if (StringUtils.isBlank(qualifier)) {
return schema + separator + element;
} else {
return schema + separator + element + separator + qualifier;
}
}
} }

View File

@@ -117,24 +117,23 @@ public class RequiredMetadata extends AbstractCurationTask
if (reqList == null) if (reqList == null)
{ {
reqList = new ArrayList<String>(); reqList = new ArrayList<String>();
DCInputSet inputs = reader.getInputsByCollectionHandle(handle); List<DCInputSet> inputSet = reader.getInputsByCollectionHandle(handle);
for (DCInput input : inputs.getFields()) for (DCInputSet inputs : inputSet) {
{ for (DCInput input : inputs.getFields()) {
if (input.isRequired()) if (input.isRequired()) {
{ StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(); sb.append(input.getSchema()).append(".");
sb.append(input.getSchema()).append("."); sb.append(input.getElement()).append(".");
sb.append(input.getElement()).append("."); String qual = input.getQualifier();
String qual = input.getQualifier(); if (qual == null) {
if (qual == null) qual = "";
{ }
qual = ""; sb.append(qual);
} reqList.add(sb.toString());
sb.append(qual); }
reqList.add(sb.toString()); }
} reqMap.put(inputs.getFormName(), reqList);
} }
reqMap.put(inputs.getFormName(), reqList);
} }
return reqList; return reqList;
} }

View File

@@ -332,7 +332,8 @@ public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator
protected DCInput getDCInput(String formName, String schema, String element, protected DCInput getDCInput(String formName, String schema, String element,
String qualifier) throws DCInputsReaderException String qualifier) throws DCInputsReaderException
{ {
DCInputSet dcinputset = new DCInputsReader().getInputsByCollectionHandle(formName); List<DCInputSet> dcinputsets = new DCInputsReader().getInputsBySubmissionName(formName);
for(DCInputSet dcinputset : dcinputsets) {
for (DCInput dcinput : dcinputset.getFields()) for (DCInput dcinput : dcinputset.getFields())
{ {
if (dcinput.getSchema().equals(schema) if (dcinput.getSchema().equals(schema)
@@ -344,6 +345,7 @@ public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator
return dcinput; return dcinput;
} }
} }
}
return null; return null;
} }

View File

@@ -24,8 +24,11 @@ import org.apache.log4j.Logger;
import org.dspace.app.util.DCInputsReader; import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.DCInputsReaderException; import org.dspace.app.util.DCInputsReaderException;
import org.dspace.app.util.SubmissionConfigReader;
import org.dspace.app.util.DCInput; import org.dspace.app.util.DCInput;
import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.SubmissionInfo; import org.dspace.app.util.SubmissionInfo;
import org.dspace.app.util.SubmissionStepConfig;
import org.dspace.app.util.Util; import org.dspace.app.util.Util;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.content.*; import org.dspace.content.*;
@@ -62,7 +65,8 @@ public class DescribeStep extends AbstractProcessingStep
/** hash of all submission forms details */ /** hash of all submission forms details */
private static DCInputsReader inputsReader = null; private static DCInputsReader inputsReader = null;
private static SubmissionConfigReader submissionConfigReader = null;
/*************************************************************************** /***************************************************************************
* STATUS / ERROR FLAGS (returned by doProcessing() if an error occurs or * STATUS / ERROR FLAGS (returned by doProcessing() if an error occurs or
* additional user interaction may be required) * additional user interaction may be required)
@@ -93,6 +97,7 @@ public class DescribeStep extends AbstractProcessingStep
{ {
//load the DCInputsReader //load the DCInputsReader
getInputsReader(); getInputsReader();
submissionConfigReader = new SubmissionConfigReader();
metadataAuthorityService = ContentAuthorityServiceFactory.getInstance().getMetadataAuthorityService(); metadataAuthorityService = ContentAuthorityServiceFactory.getInstance().getMetadataAuthorityService();
choiceAuthorityService = ContentAuthorityServiceFactory.getInstance().getChoiceAuthorityService(); choiceAuthorityService = ContentAuthorityServiceFactory.getInstance().getChoiceAuthorityService();
} }
@@ -152,7 +157,13 @@ public class DescribeStep extends AbstractProcessingStep
DCInput[] inputs = null; DCInput[] inputs = null;
try try
{ {
inputs = inputsReader.getInputsByCollectionHandle(c.getHandle()).getFields(); List<DCInputSet> inputsByCollectionHandle = inputsReader.getInputsByCollectionHandle(c.getHandle());
for(DCInputSet iset : inputsByCollectionHandle) {
SubmissionStepConfig step = submissionConfigReader.getStepConfig(iset.getFormName());
if(step.getStepNumber()==currentPage) {
inputs = iset.getFields();
}
}
} }
catch (DCInputsReaderException e) catch (DCInputsReaderException e)
{ {

View File

@@ -28,7 +28,10 @@ import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.app.util.DCInputSet; import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.DCInputsReader; import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.SubmissionConfig;
import org.dspace.app.util.SubmissionConfigReader;
import org.dspace.app.util.SubmissionInfo; import org.dspace.app.util.SubmissionInfo;
import org.dspace.app.util.SubmissionStepConfig;
import org.dspace.app.util.Util; import org.dspace.app.util.Util;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection; import org.dspace.content.Collection;
@@ -171,10 +174,10 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
else else
{ {
// create our new Workspace Item // create our new Workspace Item
DCInputSet inputSet = null; SubmissionConfig stepConfig = null;
try try
{ {
inputSet = new DCInputsReader().getInputsByCollectionHandle(col.getHandle()); stepConfig = new SubmissionConfigReader().getSubmissionConfigByCollection(col.getHandle());
} }
catch (Exception e) catch (Exception e)
{ {
@@ -245,7 +248,7 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
.getOutputGenerator(); .getOutputGenerator();
outputGenerator.setCollection(col); outputGenerator.setCollection(col);
outputGenerator.setContext(context); outputGenerator.setContext(context);
outputGenerator.setFormName(inputSet.getFormName()); outputGenerator.setFormName(stepConfig.getSubmissionName());
outputGenerator.setDto(dto.get(0)); outputGenerator.setDto(dto.get(0));
try try

View File

@@ -164,16 +164,16 @@ public class RestResourceController implements InitializingBean {
LinkRest linkRest = utils.getLinkRest(rel, domainClass); LinkRest linkRest = utils.getLinkRest(rel, domainClass);
if (linkRest != null) { if (linkRest != null) {
LinkRestRepository linkRepository = utils.getLinkResourceRepository(apiCategory, model, linkRest.name()); LinkRestRepository linkRepository = utils.getLinkResourceRepository(apiCategory, model, linkRest.name());
Method linkMethod = repositoryUtils.getLinkMethod("getKey", linkRepository); Method linkMethod = repositoryUtils.getLinkMethod("getResource", linkRepository);
try { try {
Page<? extends Serializable> pageResult = (Page<? extends RestModel>) linkMethod Object object = linkMethod.invoke(linkRepository, request, id, relid, page, projection);
.invoke(linkRepository, request, id, relid, page, projection);
Link link = linkTo(this.getClass(), apiCategory, English.plural(model)).slash(id) Link link = linkTo(this.getClass(), apiCategory, English.plural(model)).slash(id)
.slash(rel).withSelfRel(); .slash(rel).withSelfRel();
PagedResources<? extends ResourceSupport> result = assembler List result = new ArrayList();
.toResource(pageResult.map(linkRepository::wrapResource), link); result.add(object);
return result; PageImpl<RestModel> pageResult = new PageImpl(result, page, 1);
return assembler.toResource(pageResult.map(linkRepository::wrapResource),link);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);
} }

View File

@@ -0,0 +1,41 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.converter;
import org.apache.commons.lang.NotImplementedException;
import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.utils.AuthorityUtils;
import org.dspace.content.authority.Choice;
import org.springframework.stereotype.Component;
/**
* This is the converter from/to the Choice in the DSpace API data
* model and the REST data model.
*
* TODO please do not use this convert but use the wrapper {@link AuthorityUtils#convertEntry(Choice, String)}}
*
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
*/
@Component
public class AuthorityEntryRestConverter extends DSpaceConverter<Choice, AuthorityEntryRest> {
@Override
public AuthorityEntryRest fromModel(Choice choice) {
AuthorityEntryRest entry = new AuthorityEntryRest();
entry.setValue(choice.value);
entry.setDisplay(choice.label);
entry.setId(choice.authority);
entry.setOtherInformation(choice.extras);
return entry;
}
@Override
public Choice toModel(AuthorityEntryRest obj) {
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,41 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.converter;
import org.apache.commons.lang.NotImplementedException;
import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.utils.AuthorityUtils;
import org.dspace.content.authority.Choice;
import org.dspace.content.authority.ChoiceAuthority;
import org.springframework.stereotype.Component;
/**
* This is the converter from/to the ChoiceAuthority in the DSpace API data
* model and the REST data model
*
* TODO please do not use this convert but use the wrapper {@link AuthorityUtils#convertAuthority(ChoiceAuthority, String)}
*
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
*/
@Component
public class AuthorityRestConverter extends DSpaceConverter<ChoiceAuthority, AuthorityRest> {
@Override
public AuthorityRest fromModel(ChoiceAuthority step) {
AuthorityRest authorityRest = new AuthorityRest();
authorityRest.setHierarchical(step.isHierarchical());
authorityRest.setScrollable(step.isScrollable());
authorityRest.setIdentifier(step.hasIdentifier());
return authorityRest;
}
@Override
public ChoiceAuthority toModel(AuthorityRest obj) {
throw new NotImplementedException();
}
}

View File

@@ -12,7 +12,7 @@ import java.util.List;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
import org.dspace.app.rest.model.SubmissionDefinitionRest; import org.dspace.app.rest.model.SubmissionDefinitionRest;
import org.dspace.app.rest.model.SubmissionPanelRest; import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.util.SubmissionConfig; import org.dspace.app.util.SubmissionConfig;
import org.dspace.app.util.SubmissionStepConfig; import org.dspace.app.util.SubmissionStepConfig;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -28,18 +28,18 @@ import org.springframework.stereotype.Component;
public class SubmissionDefinitionConverter extends DSpaceConverter<SubmissionConfig, SubmissionDefinitionRest> { public class SubmissionDefinitionConverter extends DSpaceConverter<SubmissionConfig, SubmissionDefinitionRest> {
@Autowired @Autowired
private SubmissionPanelConverter panelConverter; private SubmissionSectionConverter panelConverter;
@Override @Override
public SubmissionDefinitionRest fromModel(SubmissionConfig obj) { public SubmissionDefinitionRest fromModel(SubmissionConfig obj) {
SubmissionDefinitionRest sd = new SubmissionDefinitionRest(); SubmissionDefinitionRest sd = new SubmissionDefinitionRest();
sd.setName(obj.getSubmissionName()); sd.setName(obj.getSubmissionName());
sd.setDefaultConf(obj.isDefaultConf()); sd.setDefaultConf(obj.isDefaultConf());
List<SubmissionPanelRest> panels = new LinkedList<SubmissionPanelRest>(); List<SubmissionSectionRest> panels = new LinkedList<SubmissionSectionRest>();
for (int idx = 0; idx < obj.getNumberOfSteps(); idx++) { for (int idx = 0; idx < obj.getNumberOfSteps(); idx++) {
SubmissionStepConfig step = obj.getStep(idx); SubmissionStepConfig step = obj.getStep(idx);
if (step.isVisible()) { if (step.isVisible()) {
SubmissionPanelRest sp = panelConverter.convert(step); SubmissionSectionRest sp = panelConverter.convert(step);
panels.add(sp); panels.add(sp);
} }
} }

View File

@@ -13,10 +13,10 @@ import java.util.List;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.model.InputFormFieldRest; import org.dspace.app.rest.model.SubmissionFormFieldRest;
import org.dspace.app.rest.model.InputFormInputTypeRest; import org.dspace.app.rest.model.SubmissionFormInputTypeRest;
import org.dspace.app.rest.model.InputFormPageRest; import org.dspace.app.rest.model.SubmissionFormPageRest;
import org.dspace.app.rest.model.InputFormRest; import org.dspace.app.rest.model.SubmissionFormRest;
import org.dspace.app.rest.model.ScopeEnum; import org.dspace.app.rest.model.ScopeEnum;
import org.dspace.app.rest.model.SelectableMetadata; import org.dspace.app.rest.model.SelectableMetadata;
import org.dspace.app.rest.model.SubmissionVisibilityRest; import org.dspace.app.rest.model.SubmissionVisibilityRest;
@@ -35,7 +35,7 @@ import org.springframework.stereotype.Component;
* @author Andrea Bollini (andrea.bollini at 4science.it) * @author Andrea Bollini (andrea.bollini at 4science.it)
*/ */
@Component @Component
public class InputFormConverter extends DSpaceConverter<DCInputSet, InputFormRest> { public class SubmissionFormConverter extends DSpaceConverter<DCInputSet, SubmissionFormRest> {
private static final String INPUT_TYPE_ONEBOX = "onebox"; private static final String INPUT_TYPE_ONEBOX = "onebox";
private static final String INPUT_TYPE_NAME = "name"; private static final String INPUT_TYPE_NAME = "name";
@@ -49,20 +49,20 @@ public class InputFormConverter extends DSpaceConverter<DCInputSet, InputFormRes
private AuthorityUtils authorityUtils; private AuthorityUtils authorityUtils;
@Override @Override
public InputFormRest fromModel(DCInputSet obj) { public SubmissionFormRest fromModel(DCInputSet obj) {
InputFormRest sd = new InputFormRest(); SubmissionFormRest sd = new SubmissionFormRest();
sd.setName(obj.getFormName()); sd.setName(obj.getFormName());
List<InputFormPageRest> pages = new LinkedList<InputFormPageRest>(); List<SubmissionFormPageRest> pages = new LinkedList<SubmissionFormPageRest>();
DCInput[] step = obj.getFields(); DCInput[] step = obj.getFields();
InputFormPageRest sp = getPage(step); SubmissionFormPageRest sp = getPage(step);
pages.add(sp); pages.add(sp);
sd.setPages(pages); sd.setPages(pages);
return sd; return sd;
} }
private InputFormPageRest getPage(DCInput[] page) { private SubmissionFormPageRest getPage(DCInput[] page) {
InputFormPageRest ifPage = new InputFormPageRest(); SubmissionFormPageRest ifPage = new SubmissionFormPageRest();
List<InputFormFieldRest> fields = new LinkedList<InputFormFieldRest>(); List<SubmissionFormFieldRest> fields = new LinkedList<SubmissionFormFieldRest>();
for (DCInput dcinput : page) { for (DCInput dcinput : page) {
fields.add(getField(dcinput)); fields.add(getField(dcinput));
} }
@@ -70,11 +70,10 @@ public class InputFormConverter extends DSpaceConverter<DCInputSet, InputFormRes
return ifPage; return ifPage;
} }
private InputFormFieldRest getField(DCInput dcinput) { private SubmissionFormFieldRest getField(DCInput dcinput) {
InputFormFieldRest inputField = new InputFormFieldRest(); SubmissionFormFieldRest inputField = new SubmissionFormFieldRest();
List<SelectableMetadata> selectableMetadata = new ArrayList<SelectableMetadata>(); List<SelectableMetadata> selectableMetadata = new ArrayList<SelectableMetadata>();
inputField.setSelectableMetadata(selectableMetadata);
inputField.setLabel(dcinput.getLabel()); inputField.setLabel(dcinput.getLabel());
inputField.setHints(dcinput.getHints()); inputField.setHints(dcinput.getHints());
inputField.setMandatoryMessage(dcinput.getWarning()); inputField.setMandatoryMessage(dcinput.getWarning());
@@ -85,11 +84,11 @@ public class InputFormConverter extends DSpaceConverter<DCInputSet, InputFormRes
VisibilityEnum.fromString(dcinput.isReadOnly("workflow")?"read-only":null))); VisibilityEnum.fromString(dcinput.isReadOnly("workflow")?"read-only":null)));
inputField.setRepeatable(dcinput.isRepeatable()); inputField.setRepeatable(dcinput.isRepeatable());
InputFormInputTypeRest inputRest = new InputFormInputTypeRest(); SubmissionFormInputTypeRest inputRest = new SubmissionFormInputTypeRest();
inputRest.setRegex(dcinput.getRegex()); inputRest.setRegex(dcinput.getRegex());
if (!StringUtils.equalsIgnoreCase(inputRest.getType(), "qualdrop_value")) { if (!StringUtils.equalsIgnoreCase(dcinput.getInputType(), "qualdrop_value")) {
// value-pair and vocabulary are a special kind of authorities // value-pair and vocabulary are a special kind of authorities
String inputType = dcinput.getInputType(); String inputType = dcinput.getInputType();
@@ -98,7 +97,7 @@ public class InputFormConverter extends DSpaceConverter<DCInputSet, InputFormRes
inputRest.setType(getPresentation(dcinput.getSchema(), dcinput.getElement(), dcinput.getQualifier(), inputType)); inputRest.setType(getPresentation(dcinput.getSchema(), dcinput.getElement(), dcinput.getQualifier(), inputType));
selMd.setAuthority( selMd.setAuthority(
authorityUtils.getAuthorityName(dcinput.getSchema(), dcinput.getElement(), dcinput.getQualifier())); authorityUtils.getAuthorityName(dcinput.getSchema(), dcinput.getElement(), dcinput.getQualifier()));
selMd.setClosed(authorityUtils.isClosed(dcinput.getSchema(), dcinput.getElement(), dcinput.getQualifier())); selMd.setClosed(authorityUtils.isClosed(dcinput.getSchema(), dcinput.getElement(), dcinput.getQualifier()));
} }
else { else {
inputRest.setType(inputType); inputRest.setType(inputType);
@@ -120,8 +119,9 @@ public class InputFormConverter extends DSpaceConverter<DCInputSet, InputFormRes
} }
selectableMetadata.add(selMd); selectableMetadata.add(selMd);
} }
} }
inputField.setInput(inputRest); inputField.setInput(inputRest);
inputField.setSelectableMetadata(selectableMetadata);
return inputField; return inputField;
} }
@@ -147,7 +147,7 @@ public class InputFormConverter extends DSpaceConverter<DCInputSet, InputFormRes
} }
@Override @Override
public DCInputSet toModel(InputFormRest obj) { public DCInputSet toModel(SubmissionFormRest obj) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }

View File

@@ -8,7 +8,7 @@
package org.dspace.app.rest.converter; package org.dspace.app.rest.converter;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
import org.dspace.app.rest.model.SubmissionPanelRest; import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.rest.model.SubmissionVisibilityRest; import org.dspace.app.rest.model.SubmissionVisibilityRest;
import org.dspace.app.rest.model.VisibilityEnum; import org.dspace.app.rest.model.VisibilityEnum;
import org.dspace.app.util.SubmissionStepConfig; import org.dspace.app.util.SubmissionStepConfig;
@@ -21,14 +21,14 @@ import org.springframework.stereotype.Component;
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it) * @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
*/ */
@Component @Component
public class SubmissionPanelConverter extends DSpaceConverter<SubmissionStepConfig, SubmissionPanelRest> { public class SubmissionSectionConverter extends DSpaceConverter<SubmissionStepConfig, SubmissionSectionRest> {
@Override @Override
public SubmissionPanelRest fromModel(SubmissionStepConfig step) { public SubmissionSectionRest fromModel(SubmissionStepConfig step) {
SubmissionPanelRest sp = new SubmissionPanelRest(); SubmissionSectionRest sp = new SubmissionSectionRest();
sp.setMandatory(step.isMandatory()); sp.setMandatory(step.isMandatory());
sp.setHeader(step.getHeading()); sp.setHeader(step.getHeading());
sp.setPanelType(step.getType()); sp.setSectionType(step.getType());
sp.setId(step.getId()); sp.setId(step.getId());
sp.setVisibility(new SubmissionVisibilityRest(VisibilityEnum.fromString(step.getVisibility()), sp.setVisibility(new SubmissionVisibilityRest(VisibilityEnum.fromString(step.getVisibility()),
VisibilityEnum.fromString(step.getVisibilityOutside()))); VisibilityEnum.fromString(step.getVisibilityOutside())));
@@ -36,7 +36,7 @@ public class SubmissionPanelConverter extends DSpaceConverter<SubmissionStepConf
} }
@Override @Override
public SubmissionStepConfig toModel(SubmissionPanelRest obj) { public SubmissionStepConfig toModel(SubmissionSectionRest obj) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }

View File

@@ -7,24 +7,27 @@
*/ */
package org.dspace.app.rest.model; package org.dspace.app.rest.model;
import java.io.Serializable;
import java.util.Map; import java.util.Map;
import org.dspace.app.rest.RestResourceController;
import com.fasterxml.jackson.annotation.JsonIgnore;
/** /**
* The Authority Entry REST Resource * The Authority Entry REST Resource
* *
* @author Andrea Bollini (andrea.bollini at 4science.it) * @author Andrea Bollini (andrea.bollini at 4science.it)
* *
*/ */
public class AuthorityEntryRest implements Serializable { public class AuthorityEntryRest implements RestModel {
public static final String NAME = "authorityEntry"; public static final String NAME = "authorityEntry";
private String id; private String id;
private String display; private String display;
private String value; private String value;
private long count;
private Map<String, String> otherInformation; private Map<String, String> otherInformation;
private AuthorityEntryRest parent;
@JsonIgnore
private String authorityName;
public String getId() { public String getId() {
return id; return id;
@@ -32,39 +35,44 @@ public class AuthorityEntryRest implements Serializable {
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
public String getDisplay() { public String getDisplay() {
return display; return display;
} }
public void setDisplay(String value) { public void setDisplay(String value) {
this.display = value; this.display = value;
} }
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
public Map<String, String> getOtherInformation() { public Map<String, String> getOtherInformation() {
return otherInformation; return otherInformation;
} }
public void setOtherInformation(Map<String, String> otherInformation) { public void setOtherInformation(Map<String, String> otherInformation) {
this.otherInformation = otherInformation; this.otherInformation = otherInformation;
} }
public AuthorityEntryRest getParent() {
return parent;
}
public void setParent(AuthorityEntryRest parent) {
this.parent = parent;
}
public static String getName() {
return NAME;
}
public String getValue() { public String getValue() {
return value; return value;
} }
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
public static String getName() {
return NAME;
}
public String getAuthorityName() {
return authorityName;
}
public void setAuthorityName(String authorityName) {
this.authorityName = authorityName;
}
@Override
public String getCategory() {
return AuthorityRest.CATEGORY;
}
@Override
public String getType() {
return AuthorityRest.NAME;
}
@Override
public Class getController() {
return RestResourceController.class;
}
} }

View File

@@ -16,15 +16,15 @@ import org.dspace.app.rest.RestResourceController;
* *
*/ */
@LinksRest(links = { @LinksRest(links = {
@LinkRest(name = AuthorityRest.ENTRIES, linkClass = AuthorityEntryRest.class, method = "listAuthorityEntries", optional = true), @LinkRest(name = AuthorityRest.ENTRIES, linkClass = AuthorityEntryRest.class, method = "query", optional = true),
@LinkRest(name = AuthorityRest.ENTRY, linkClass = AuthorityEntryRest.class, method = "listAuthorityEntry", optional = true) @LinkRest(name = AuthorityRest.ENTRY, linkClass = AuthorityEntryRest.class, method = "getResource", optional = true)
}) })
public class AuthorityRest extends BaseObjectRest<String> { public class AuthorityRest extends BaseObjectRest<String> {
public static final String NAME = "authority"; public static final String NAME = "authority";
public static final String CATEGORY = RestModel.INTEGRATION; public static final String CATEGORY = RestModel.INTEGRATION;
public static final String ENTRIES = "entries"; public static final String ENTRIES = "entries";
public static final String ENTRY = "entry"; public static final String ENTRY = "entryValues";
private String name; private String name;

View File

@@ -31,7 +31,7 @@ public class SubmissionDefinitionRest extends BaseObjectRest<String> {
@JsonProperty(value="isDefault") @JsonProperty(value="isDefault")
private boolean defaultConf; private boolean defaultConf;
private List<SubmissionPanelRest> panels; private List<SubmissionSectionRest> panels;
@Override @Override
public String getId() { public String getId() {
@@ -46,13 +46,13 @@ public class SubmissionDefinitionRest extends BaseObjectRest<String> {
return name; return name;
} }
public void setPanels(List<SubmissionPanelRest> panels) { public void setPanels(List<SubmissionSectionRest> panels) {
this.panels = panels; this.panels = panels;
} }
@LinkRest(name=SubmissionPanelRest.NAME, linkClass = SubmissionPanelRest.class) @LinkRest(name=SubmissionSectionRest.NAME, linkClass = SubmissionSectionRest.class)
@JsonIgnore @JsonIgnore
public List<SubmissionPanelRest> getPanels() { public List<SubmissionSectionRest> getPanels() {
return panels; return panels;
} }

View File

@@ -21,13 +21,13 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
* *
*/ */
@JsonInclude(value = Include.NON_NULL) @JsonInclude(value = Include.NON_NULL)
public class InputFormFieldRest { public class SubmissionFormFieldRest {
private String label; private String label;
private boolean mandatory; private boolean mandatory;
private boolean repeatable; private boolean repeatable;
private String mandatoryMessage; private String mandatoryMessage;
private String hints; private String hints;
private InputFormInputTypeRest input; private SubmissionFormInputTypeRest input;
private ScopeEnum scope; private ScopeEnum scope;
private SubmissionVisibilityRest visibility; private SubmissionVisibilityRest visibility;
private List<SelectableMetadata> selectableMetadata; private List<SelectableMetadata> selectableMetadata;
@@ -80,11 +80,11 @@ public class InputFormFieldRest {
this.hints = hints; this.hints = hints;
} }
public InputFormInputTypeRest getInput() { public SubmissionFormInputTypeRest getInput() {
return input; return input;
} }
public void setInput(InputFormInputTypeRest input) { public void setInput(SubmissionFormInputTypeRest input) {
this.input = input; this.input = input;
} }

View File

@@ -19,7 +19,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
* *
*/ */
@JsonInclude(value = Include.NON_NULL) @JsonInclude(value = Include.NON_NULL)
public class InputFormInputTypeRest { public class SubmissionFormInputTypeRest {
private String type; private String type;
private String regex; private String regex;
private AuthorityRest authority; private AuthorityRest authority;

View File

@@ -25,10 +25,10 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
* *
*/ */
@JsonInclude(value=Include.NON_NULL) @JsonInclude(value=Include.NON_NULL)
public class InputFormPageRest { public class SubmissionFormPageRest {
private String header; private String header;
private boolean mandatory; private boolean mandatory;
private List<InputFormFieldRest> fields; private List<SubmissionFormFieldRest> fields;
public String getHeader() { public String getHeader() {
return header; return header;
@@ -46,18 +46,18 @@ public class InputFormPageRest {
this.mandatory = mandatory; this.mandatory = mandatory;
} }
public List<InputFormFieldRest> getFields() { public List<SubmissionFormFieldRest> getFields() {
return fields; return fields;
} }
public void setFields(List<InputFormFieldRest> fields) { public void setFields(List<SubmissionFormFieldRest> fields) {
this.fields = fields; this.fields = fields;
} }
@JsonIgnore @JsonIgnore
public ScopeEnum getScope() { public ScopeEnum getScope() {
ScopeEnum scope = fields.get(0).getScope(); ScopeEnum scope = fields.get(0).getScope();
for (InputFormFieldRest field : fields) { for (SubmissionFormFieldRest field : fields) {
if (!Objects.equals(field.getScope(), scope)) { if (!Objects.equals(field.getScope(), scope)) {
return null; return null;
} }
@@ -69,7 +69,7 @@ public class InputFormPageRest {
@JsonIgnore @JsonIgnore
public SubmissionVisibilityRest getVisibility() { public SubmissionVisibilityRest getVisibility() {
SubmissionVisibilityRest visibility = fields.get(0).getVisibility(); SubmissionVisibilityRest visibility = fields.get(0).getVisibility();
for (InputFormFieldRest field : fields) { for (SubmissionFormFieldRest field : fields) {
if (!Objects.equals(field.getVisibility(), visibility)) { if (!Objects.equals(field.getVisibility(), visibility)) {
return null; return null;
} }

View File

@@ -19,14 +19,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* @author Andrea Bollini (andrea.bollini at 4science.it) * @author Andrea Bollini (andrea.bollini at 4science.it)
* *
*/ */
public class InputFormRest extends BaseObjectRest<String> { public class SubmissionFormRest extends BaseObjectRest<String> {
public static final String NAME = "submission-form"; public static final String NAME = "submission-form";
public static final String NAME_LINK_ON_PANEL = RestModel.CONFIGURATION; public static final String NAME_LINK_ON_PANEL = RestModel.CONFIGURATION;
public static final String CATEGORY = RestModel.CONFIGURATION; public static final String CATEGORY = RestModel.CONFIGURATION;
private String name; private String name;
private List<InputFormPageRest> pages; private List<SubmissionFormPageRest> pages;
@Override @Override
public String getId() { public String getId() {
@@ -41,11 +41,11 @@ public class InputFormRest extends BaseObjectRest<String> {
return name; return name;
} }
public void setPages(List<InputFormPageRest> pages) { public void setPages(List<SubmissionFormPageRest> pages) {
this.pages = pages; this.pages = pages;
} }
public List<InputFormPageRest> getPages() { public List<SubmissionFormPageRest> getPages() {
return pages; return pages;
} }

View File

@@ -23,12 +23,12 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
* *
*/ */
@JsonInclude(value=Include.NON_NULL) @JsonInclude(value=Include.NON_NULL)
public class SubmissionPanelRest extends BaseObjectRest<String> { public class SubmissionSectionRest extends BaseObjectRest<String> {
public static final String NAME = "submission-panel"; public static final String NAME = "submission-section";
private String header; private String header;
private boolean mandatory; private boolean mandatory;
private String panelType; private String sectionType;
private ScopeEnum scope; private ScopeEnum scope;
private SubmissionVisibilityRest visibility; private SubmissionVisibilityRest visibility;
@@ -49,7 +49,7 @@ public class SubmissionPanelRest extends BaseObjectRest<String> {
} }
public String getType() { public String getType() {
return "submission-panel"; return NAME;
} }
public ScopeEnum getScope() { public ScopeEnum getScope() {
@@ -80,12 +80,12 @@ public class SubmissionPanelRest extends BaseObjectRest<String> {
return RestResourceController.class; return RestResourceController.class;
} }
public String getPanelType() { public String getSectionType() {
return panelType; return sectionType;
} }
public void setPanelType(String panelType) { public void setSectionType(String panelType) {
this.panelType = panelType; this.sectionType = panelType;
} }
} }

View File

@@ -7,29 +7,49 @@
*/ */
package org.dspace.app.rest.model.hateoas; package org.dspace.app.rest.model.hateoas;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.AuthorityEntryRest; import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource; import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.AuthorityUtils;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.ResourceSupport; import org.springframework.hateoas.ResourceSupport;
import org.springframework.web.util.UriComponentsBuilder;
import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.annotation.JsonUnwrapped;
/** /**
* Authority Rest HAL Resource. The HAL Resource wraps the REST Resource * Authority Rest HAL Resource. The HAL Resource wraps the REST Resource adding
* adding support for the links and embedded resources * support for the links and embedded resources
* *
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it) * @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
* *
*/ */
@RelNameDSpaceResource(AuthorityEntryRest.NAME) @RelNameDSpaceResource(AuthorityEntryRest.NAME)
public class AuthorityEntryResource extends ResourceSupport { public class AuthorityEntryResource extends ResourceSupport {
@JsonUnwrapped @JsonUnwrapped
private final AuthorityEntryRest data; private final AuthorityEntryRest data;
public AuthorityEntryResource(AuthorityEntryRest entry) { public AuthorityEntryResource(AuthorityEntryRest entry) {
this.data = entry; this.data = entry;
if (entry.getOtherInformation() != null) {
if (entry.getOtherInformation().containsKey(AuthorityUtils.RESERVED_KEYMAP_PARENT)) {
RestResourceController methodOn = methodOn(RestResourceController.class, AuthorityRest.CATEGORY,
AuthorityRest.NAME);
UriComponentsBuilder uriComponentsBuilder = linkTo(methodOn.findRel(null, AuthorityRest.CATEGORY,
English.plural(AuthorityRest.NAME), entry.getAuthorityName() + "/" + AuthorityRest.ENTRY,
entry.getOtherInformation().get(AuthorityUtils.RESERVED_KEYMAP_PARENT), null, null, null)).toUriComponentsBuilder();
Link link = new Link(uriComponentsBuilder.build().toString(), AuthorityUtils.RESERVED_KEYMAP_PARENT);
add(link);
}
}
} }
public AuthorityEntryRest getData() { public AuthorityEntryRest getData() {
return data; return data;
} }

View File

@@ -7,7 +7,7 @@
*/ */
package org.dspace.app.rest.model.hateoas; package org.dspace.app.rest.model.hateoas;
import org.dspace.app.rest.model.InputFormRest; import org.dspace.app.rest.model.SubmissionFormRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource; import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils; import org.dspace.app.rest.utils.Utils;
@@ -18,9 +18,9 @@ import org.dspace.app.rest.utils.Utils;
* @author Andrea Bollini (andrea.bollini at 4science.it) * @author Andrea Bollini (andrea.bollini at 4science.it)
* *
*/ */
@RelNameDSpaceResource(InputFormRest.NAME) @RelNameDSpaceResource(SubmissionFormRest.NAME)
public class InputFormResource extends DSpaceResource<InputFormRest> { public class SubmissionFormResource extends DSpaceResource<SubmissionFormRest> {
public InputFormResource(InputFormRest sd, Utils utils, String... rels) { public SubmissionFormResource(SubmissionFormRest sd, Utils utils, String... rels) {
super(sd, utils, rels); super(sd, utils, rels);
} }
} }

View File

@@ -12,8 +12,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import org.atteo.evo.inflector.English; import org.atteo.evo.inflector.English;
import org.dspace.app.rest.RestResourceController; import org.dspace.app.rest.RestResourceController;
import org.dspace.app.rest.model.InputFormRest; import org.dspace.app.rest.model.SubmissionFormRest;
import org.dspace.app.rest.model.SubmissionPanelRest; import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource; import org.dspace.app.rest.model.hateoas.annotations.RelNameDSpaceResource;
import org.dspace.app.rest.utils.Utils; import org.dspace.app.rest.utils.Utils;
import org.springframework.hateoas.Link; import org.springframework.hateoas.Link;
@@ -26,18 +26,18 @@ import org.springframework.web.util.UriComponentsBuilder;
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it) * @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
* *
*/ */
@RelNameDSpaceResource(SubmissionPanelRest.NAME) @RelNameDSpaceResource(SubmissionSectionRest.NAME)
public class SubmissionPanelResource extends DSpaceResource<SubmissionPanelRest> { public class SubmissionSectionResource extends DSpaceResource<SubmissionSectionRest> {
public SubmissionPanelResource(SubmissionPanelRest sd, Utils utils, String... rels) { public SubmissionSectionResource(SubmissionSectionRest sd, Utils utils, String... rels) {
super(sd, utils, rels); super(sd, utils, rels);
if("input-form".equals(sd.getPanelType())) { if("input-form".equals(sd.getSectionType())) {
RestResourceController methodOn = methodOn(RestResourceController.class, InputFormRest.CATEGORY, InputFormRest.NAME); RestResourceController methodOn = methodOn(RestResourceController.class, SubmissionFormRest.CATEGORY, SubmissionFormRest.NAME);
UriComponentsBuilder uriComponentsBuilder = linkTo(methodOn UriComponentsBuilder uriComponentsBuilder = linkTo(methodOn
.findRel(null, InputFormRest.CATEGORY, English.plural(InputFormRest.NAME), sd.getId(), "", null, null, null)) .findRel(null, SubmissionFormRest.CATEGORY, English.plural(SubmissionFormRest.NAME), sd.getId(), "", null, null, null))
.toUriComponentsBuilder(); .toUriComponentsBuilder();
String uribuilder = uriComponentsBuilder.build().toString(); String uribuilder = uriComponentsBuilder.build().toString();
Link link = new Link(uribuilder.substring(0, uribuilder.lastIndexOf("/")), InputFormRest.NAME_LINK_ON_PANEL); Link link = new Link(uribuilder.substring(0, uribuilder.lastIndexOf("/")), SubmissionFormRest.NAME_LINK_ON_PANEL);
add(link); add(link);
} }
} }

View File

@@ -8,18 +8,22 @@
package org.dspace.app.rest.repository; package org.dspace.app.rest.repository;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.dspace.app.rest.converter.AuthorityEntryRestConverter;
import org.dspace.app.rest.model.AuthorityEntryRest; import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.model.AuthorityRest; import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.hateoas.AuthorityEntryResource; import org.dspace.app.rest.model.hateoas.AuthorityEntryResource;
import org.dspace.app.rest.utils.AuthorityUtils; import org.dspace.app.rest.utils.AuthorityUtils;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.authority.Choice;
import org.dspace.content.authority.Choices;
import org.dspace.content.authority.service.ChoiceAuthorityService;
import org.dspace.content.service.CollectionService; import org.dspace.content.service.CollectionService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -39,17 +43,21 @@ import org.springframework.stereotype.Component;
public class AuthorityEntryLinkRepository extends AbstractDSpaceRestRepository public class AuthorityEntryLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository<AuthorityEntryRest> { implements LinkRestRepository<AuthorityEntryRest> {
@Autowired
private ChoiceAuthorityService cas;
@Autowired
private CollectionService cs;
@Autowired @Autowired
private AuthorityUtils authorityUtils; private AuthorityUtils authorityUtils;
CollectionService cs = ContentServiceFactory.getInstance().getCollectionService();
@Override @Override
public ResourceSupport wrapResource(AuthorityEntryRest model, String... rels) { public ResourceSupport wrapResource(AuthorityEntryRest model, String... rels) {
return new AuthorityEntryResource(model); return new AuthorityEntryResource(model);
} }
public Page<AuthorityEntryRest> listAuthorityEntries(HttpServletRequest request, String name, public Page<AuthorityEntryRest> query(HttpServletRequest request, String name,
Pageable pageable, String projection) { Pageable pageable, String projection) {
Context context = obtainContext(); Context context = obtainContext();
String query = request.getParameter("query"); String query = request.getParameter("query");
@@ -62,18 +70,17 @@ public class AuthorityEntryLinkRepository extends AbstractDSpaceRestRepository
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}
List<AuthorityEntryRest> results = new ArrayList<AuthorityEntryRest>();
if(StringUtils.isNotBlank(metadata)) {
String[] tokens = org.dspace.core.Utils.tokenize(metadata);
String fieldKey = org.dspace.core.Utils.standardize(tokens[0], tokens[1], tokens[2], "_");
Choices choices = cas.getMatches(fieldKey, query, collection, pageable.getOffset(), pageable.getPageSize(), context.getCurrentLocale().toString());
for (Choice value : choices.values) {
results.add(authorityUtils.convertEntry(value, name));
}
} }
List<AuthorityEntryRest> authorities = authorityUtils.query(metadata, query, collection, pageable.getOffset(), pageable.getPageSize(), context.getCurrentLocale()); return new PageImpl<AuthorityEntryRest>(results, pageable, results.size());
return new PageImpl<AuthorityEntryRest>(authorities, pageable, authorities.size());
}
public AuthorityEntryRest listAuthorityEntry(HttpServletRequest request, String name,
Pageable pageable, String projection) {
Context context = obtainContext();
String metadata = request.getParameter("metadata");
String authKey = request.getParameter("key");
return authorityUtils.get(metadata, authKey, context.getCurrentLocale().toString());
} }
} }

View File

@@ -0,0 +1,55 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.rest.repository;
import javax.servlet.http.HttpServletRequest;
import org.dspace.app.rest.converter.AuthorityEntryRestConverter;
import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.hateoas.AuthorityEntryResource;
import org.dspace.app.rest.utils.AuthorityUtils;
import org.dspace.content.authority.Choice;
import org.dspace.content.authority.ChoiceAuthority;
import org.dspace.content.authority.service.ChoiceAuthorityService;
import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.stereotype.Component;
/**
* Controller for exposition of authority services
*
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
*
*/
@Component(AuthorityRest.CATEGORY + "." + AuthorityRest.NAME + "." + AuthorityRest.ENTRY)
public class AuthorityEntryValueLinkRepository extends AbstractDSpaceRestRepository
implements LinkRestRepository<AuthorityEntryRest> {
@Autowired
private ChoiceAuthorityService cas;
@Autowired
private AuthorityUtils authorityUtils;
@Override
public ResourceSupport wrapResource(AuthorityEntryRest model, String... rels) {
return new AuthorityEntryResource(model);
}
public AuthorityEntryRest getResource(HttpServletRequest request, String name, String relId,
Pageable pageable, String projection) {
Context context = obtainContext();
ChoiceAuthority choiceAuthority = cas.getChoiceAuthorityByAuthorityName(name);
Choice choice = choiceAuthority.getChoice(null, relId, context.getCurrentLocale().toString());
return authorityUtils.convertEntry(choice, name);
}
}

View File

@@ -7,11 +7,17 @@
*/ */
package org.dspace.app.rest.repository; package org.dspace.app.rest.repository;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import org.dspace.app.rest.converter.AuthorityRestConverter;
import org.dspace.app.rest.model.AuthorityRest; import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.app.rest.model.hateoas.AuthorityResource; import org.dspace.app.rest.model.hateoas.AuthorityResource;
import org.dspace.app.rest.utils.AuthorityUtils; import org.dspace.app.rest.utils.AuthorityUtils;
import org.dspace.content.authority.Choice;
import org.dspace.content.authority.ChoiceAuthority;
import org.dspace.content.authority.service.ChoiceAuthorityService;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -27,23 +33,30 @@ import org.springframework.stereotype.Component;
*/ */
@Component(AuthorityRest.CATEGORY + "." + AuthorityRest.NAME) @Component(AuthorityRest.CATEGORY + "." + AuthorityRest.NAME)
public class AuthorityRestRepository extends DSpaceRestRepository<AuthorityRest, String> { public class AuthorityRestRepository extends DSpaceRestRepository<AuthorityRest, String> {
@Autowired
private ChoiceAuthorityService cas;
@Autowired @Autowired
private AuthorityUtils authorityUtils; private AuthorityUtils authorityUtils;
@Override @Override
public AuthorityRest findOne(Context context, String name) { public AuthorityRest findOne(Context context, String name) {
AuthorityRest authorityRest = authorityUtils.getAuthority(name); ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(name);
if(authorityRest == null) { AuthorityRest result = authorityUtils.convertAuthority(source, name);
return null; return result;
}
return authorityRest;
} }
@Override @Override
public Page<AuthorityRest> findAll(Context context, Pageable pageable) { public Page<AuthorityRest> findAll(Context context, Pageable pageable) {
List<AuthorityRest> authorities = authorityUtils.getAuthorities(); Set<String> authoritiesName = cas.getChoiceAuthoritiesNames();
return new PageImpl<AuthorityRest>(authorities, pageable, authorities.size()); List<AuthorityRest> results = new ArrayList<AuthorityRest>();
for(String authorityName : authoritiesName) {
ChoiceAuthority source = cas.getChoiceAuthorityByAuthorityName(authorityName);
AuthorityRest result = authorityUtils.convertAuthority(source, authorityName);
results.add(result);
}
return new PageImpl<AuthorityRest>(results, pageable, results.size());
} }
@Override @Override

View File

@@ -10,9 +10,9 @@ package org.dspace.app.rest.repository;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.dspace.app.rest.converter.InputFormConverter; import org.dspace.app.rest.converter.SubmissionFormConverter;
import org.dspace.app.rest.model.InputFormRest; import org.dspace.app.rest.model.SubmissionFormRest;
import org.dspace.app.rest.model.hateoas.InputFormResource; import org.dspace.app.rest.model.hateoas.SubmissionFormResource;
import org.dspace.app.util.DCInputSet; import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.DCInputsReader; import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.DCInputsReaderException; import org.dspace.app.util.DCInputsReaderException;
@@ -29,20 +29,20 @@ import org.springframework.stereotype.Component;
* @author Andrea Bollini (andrea.bollini at 4science.it) * @author Andrea Bollini (andrea.bollini at 4science.it)
* *
*/ */
@Component(InputFormRest.CATEGORY + "." + InputFormRest.NAME) @Component(SubmissionFormRest.CATEGORY + "." + SubmissionFormRest.NAME)
public class InputFormRestRepository extends DSpaceRestRepository<InputFormRest, String> implements LinkRestRepository<InputFormRest> { public class SubmissionFormRestRepository extends DSpaceRestRepository<SubmissionFormRest, String> implements LinkRestRepository<SubmissionFormRest> {
private DCInputsReader inputReader; private DCInputsReader inputReader;
@Autowired @Autowired
private InputFormConverter converter; private SubmissionFormConverter converter;
public InputFormRestRepository() throws DCInputsReaderException { public SubmissionFormRestRepository() throws DCInputsReaderException {
inputReader = new DCInputsReader(); inputReader = new DCInputsReader();
} }
@Override @Override
public InputFormRest findOne(Context context, String submitName) { public SubmissionFormRest findOne(Context context, String submitName) {
DCInputSet inputConfig; DCInputSet inputConfig;
try { try {
inputConfig = inputReader.getInputsByFormName(submitName); inputConfig = inputReader.getInputsByFormName(submitName);
@@ -56,7 +56,7 @@ public class InputFormRestRepository extends DSpaceRestRepository<InputFormRest,
} }
@Override @Override
public Page<InputFormRest> findAll(Context context, Pageable pageable) { public Page<SubmissionFormRest> findAll(Context context, Pageable pageable) {
List<DCInputSet> subConfs = new ArrayList<DCInputSet>(); List<DCInputSet> subConfs = new ArrayList<DCInputSet>();
int total = inputReader.countInputs(); int total = inputReader.countInputs();
try { try {
@@ -64,17 +64,17 @@ public class InputFormRestRepository extends DSpaceRestRepository<InputFormRest,
} catch (DCInputsReaderException e) { } catch (DCInputsReaderException e) {
throw new IllegalStateException(e.getMessage(), e); throw new IllegalStateException(e.getMessage(), e);
} }
Page<InputFormRest> page = new PageImpl<DCInputSet>(subConfs, pageable, total).map(converter); Page<SubmissionFormRest> page = new PageImpl<DCInputSet>(subConfs, pageable, total).map(converter);
return page; return page;
} }
@Override @Override
public Class<InputFormRest> getDomainClass() { public Class<SubmissionFormRest> getDomainClass() {
return InputFormRest.class; return SubmissionFormRest.class;
} }
@Override @Override
public InputFormResource wrapResource(InputFormRest sd, String... rels) { public SubmissionFormResource wrapResource(SubmissionFormRest sd, String... rels) {
return new InputFormResource(sd, utils, rels); return new SubmissionFormResource(sd, utils, rels);
} }
} }

View File

@@ -12,10 +12,10 @@ import java.util.List;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import org.dspace.app.rest.converter.SubmissionPanelConverter; import org.dspace.app.rest.converter.SubmissionSectionConverter;
import org.dspace.app.rest.model.SubmissionDefinitionRest; import org.dspace.app.rest.model.SubmissionDefinitionRest;
import org.dspace.app.rest.model.SubmissionPanelRest; import org.dspace.app.rest.model.SubmissionSectionRest;
import org.dspace.app.rest.model.hateoas.SubmissionPanelResource; import org.dspace.app.rest.model.hateoas.SubmissionSectionResource;
import org.dspace.app.util.SubmissionConfig; import org.dspace.app.util.SubmissionConfig;
import org.dspace.app.util.SubmissionConfigReader; import org.dspace.app.util.SubmissionConfigReader;
import org.dspace.app.util.SubmissionStepConfig; import org.dspace.app.util.SubmissionStepConfig;
@@ -32,20 +32,20 @@ import org.springframework.stereotype.Component;
* @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it) * @author Luigi Andrea Pascarelli (luigiandrea.pascarelli at 4science.it)
* *
*/ */
@Component(SubmissionDefinitionRest.CATEGORY + "." + SubmissionPanelRest.NAME) @Component(SubmissionDefinitionRest.CATEGORY + "." + SubmissionSectionRest.NAME)
public class SubmissionPanelRestRepository extends DSpaceRestRepository<SubmissionPanelRest, String> { public class SubmissionPanelRestRepository extends DSpaceRestRepository<SubmissionSectionRest, String> {
private SubmissionConfigReader submissionConfigReader; private SubmissionConfigReader submissionConfigReader;
@Autowired @Autowired
private SubmissionPanelConverter converter; private SubmissionSectionConverter converter;
public SubmissionPanelRestRepository() throws ServletException { public SubmissionPanelRestRepository() throws ServletException {
submissionConfigReader = new SubmissionConfigReader(); submissionConfigReader = new SubmissionConfigReader();
} }
@Override @Override
public SubmissionPanelRest findOne(Context context, String id) { public SubmissionSectionRest findOne(Context context, String id) {
try { try {
SubmissionStepConfig step = submissionConfigReader.getStepConfig(id); SubmissionStepConfig step = submissionConfigReader.getStepConfig(id);
return converter.convert(step); return converter.convert(step);
@@ -56,7 +56,7 @@ public class SubmissionPanelRestRepository extends DSpaceRestRepository<Submissi
} }
@Override @Override
public Page<SubmissionPanelRest> findAll(Context context, Pageable pageable) { public Page<SubmissionSectionRest> findAll(Context context, Pageable pageable) {
List<SubmissionConfig> subConfs = new ArrayList<SubmissionConfig>(); List<SubmissionConfig> subConfs = new ArrayList<SubmissionConfig>();
subConfs = submissionConfigReader.getAllSubmissionConfigs(pageable.getPageSize(), pageable.getOffset()); subConfs = submissionConfigReader.getAllSubmissionConfigs(pageable.getPageSize(), pageable.getOffset());
int total = 0; int total = 0;
@@ -68,18 +68,18 @@ public class SubmissionPanelRestRepository extends DSpaceRestRepository<Submissi
stepConfs.add(step); stepConfs.add(step);
} }
} }
Page<SubmissionPanelRest> page = new PageImpl<SubmissionStepConfig>(stepConfs, pageable, total).map(converter); Page<SubmissionSectionRest> page = new PageImpl<SubmissionStepConfig>(stepConfs, pageable, total).map(converter);
return page; return page;
} }
@Override @Override
public Class<SubmissionPanelRest> getDomainClass() { public Class<SubmissionSectionRest> getDomainClass() {
return SubmissionPanelRest.class; return SubmissionSectionRest.class;
} }
@Override @Override
public SubmissionPanelResource wrapResource(SubmissionPanelRest model, String... rels) { public SubmissionSectionResource wrapResource(SubmissionSectionRest model, String... rels) {
return new SubmissionPanelResource(model, utils, rels); return new SubmissionSectionResource(model, utils, rels);
} }
} }

View File

@@ -7,20 +7,13 @@
*/ */
package org.dspace.app.rest.utils; package org.dspace.app.rest.utils;
import java.util.ArrayList; import org.dspace.app.rest.converter.AuthorityEntryRestConverter;
import java.util.List; import org.dspace.app.rest.converter.AuthorityRestConverter;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.AuthorityEntryRest; import org.dspace.app.rest.model.AuthorityEntryRest;
import org.dspace.app.rest.model.AuthorityRest; import org.dspace.app.rest.model.AuthorityRest;
import org.dspace.content.Collection;
import org.dspace.content.authority.Choice; import org.dspace.content.authority.Choice;
import org.dspace.content.authority.Choices; import org.dspace.content.authority.ChoiceAuthority;
import org.dspace.content.authority.service.ChoiceAuthorityService; import org.dspace.content.authority.service.ChoiceAuthorityService;
import org.dspace.content.authority.service.MetadataAuthorityService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -36,104 +29,21 @@ public class AuthorityUtils {
public static final String PRESENTATION_TYPE_LOOKUP = "lookup"; public static final String PRESENTATION_TYPE_LOOKUP = "lookup";
public static final String PRESENTATION_TYPE_SUGGEST = "suggest"; public static final String PRESENTATION_TYPE_SUGGEST = "suggest";
public static final String RESERVED_KEYMAP_PARENT = "parent";
@Autowired @Autowired
private ChoiceAuthorityService cas; private ChoiceAuthorityService cas;
public AuthorityRest getAuthority(String schema, String element, String qualifier) {
return buildAuthorityRest(cas.getChoiceAuthorityName(schema, element, qualifier), schema, element, qualifier);
}
public AuthorityRest getAuthority(String name) {
String metadata = cas.getChoiceMetadatabyAuthorityName(name);
if (StringUtils.isNotBlank(metadata)) {
String[] tokens = tokenize(metadata);
String schema = tokens[0];
String element = tokens[1];
String qualifier = tokens[2];
return buildAuthorityRest(name, schema, element, qualifier);
}
return new AuthorityRest();
}
private AuthorityRest buildAuthorityRest(String name, String schema, String element, String qualifier) {
AuthorityRest authorityRest = new AuthorityRest();
authorityRest.setName(name);
authorityRest.setHierarchical(cas.isHierarchical(schema, element, qualifier));
authorityRest.setScrollable(cas.isScrollable(schema, element, qualifier));
authorityRest.setIdentifier(cas.hasIdentifier(schema, element, qualifier));
return authorityRest;
}
public List<AuthorityRest> getAuthorities() {
Set<String> names = cas.getChoiceAuthoritiesNames();
List<AuthorityRest> authorities = new ArrayList<AuthorityRest>();
for (String name : names) {
authorities.add(getAuthority(name));
}
return authorities;
}
private String[] tokenize(String metadata) {
String separator = metadata.contains("_") ? "_" : ".";
StringTokenizer dcf = new StringTokenizer(metadata, separator);
String[] tokens = { "", "", "" };
int i = 0;
while (dcf.hasMoreTokens()) {
tokens[i] = dcf.nextToken().trim();
i++;
}
// Tokens contains:
// schema = tokens[0];
// element = tokens[1];
// qualifier = tokens[2];
return tokens;
}
private String standardize(String schema, String element, String qualifier, String separator) {
if (StringUtils.isBlank(qualifier)) {
return schema + separator + element;
} else {
return schema + separator + element + separator + qualifier;
}
}
public List<AuthorityEntryRest> query(String metadata, String query, Collection collection, int start, int limit,
Locale locale) {
List<AuthorityEntryRest> result = new ArrayList<AuthorityEntryRest>();
if(StringUtils.isNotBlank(metadata)) {
String[] tokens = tokenize(metadata);
Choices choice = cas.getMatches(standardize(tokens[0], tokens[1], tokens[2], "_"), query, collection, start,
limit, locale.toString());
for (Choice value : choice.values) {
AuthorityEntryRest rr = buildEntry(value);
result.add(rr);
}
}
return result;
}
public AuthorityEntryRest get(String metadata, String authKey, String currentLocale) {
Choice value = cas.getChoice(metadata, authKey, currentLocale);
AuthorityEntryRest rr = buildEntry(value);
return rr;
}
private AuthorityEntryRest buildEntry(Choice value) { @Autowired
AuthorityEntryRest rr = new AuthorityEntryRest(); private AuthorityEntryRestConverter entryConverter;
rr.setId(value.authority);
rr.setValue(value.value); @Autowired
rr.setDisplay(value.label); private AuthorityRestConverter authorityConverter;
//TODO
rr.setCount(0);
rr.setOtherInformation(value.extras);
return rr;
}
public boolean isChoice(String schema, String element, String qualifier) { public boolean isChoice(String schema, String element, String qualifier) {
return cas.isChoicesConfigured(standardize(schema, element, qualifier, "_")); return cas.isChoicesConfigured(org.dspace.core.Utils.standardize(schema, element, qualifier, "_"));
} }
public String getAuthorityName(String schema, String element, String qualifier) { public String getAuthorityName(String schema, String element, String qualifier) {
@@ -141,10 +51,36 @@ public class AuthorityUtils {
} }
public boolean isClosed(String schema, String element, String qualifier) { public boolean isClosed(String schema, String element, String qualifier) {
return cas.isClosed(standardize(schema, element, qualifier, "_")); return cas.isClosed(org.dspace.core.Utils.standardize(schema, element, qualifier, "_"));
} }
public String getPresentation(String schema, String element, String qualifier) { public String getPresentation(String schema, String element, String qualifier) {
return cas.getPresentation(standardize(schema, element, qualifier, "_")); return cas.getPresentation(org.dspace.core.Utils.standardize(schema, element, qualifier, "_"));
}
/**
* TODO the authorityName MUST be a part of Choice model
*
* @param choice
* @param authorityName
* @return
*/
public AuthorityEntryRest convertEntry(Choice choice, String authorityName) {
AuthorityEntryRest entry = entryConverter.convert(choice);
entry.setAuthorityName(authorityName);
return entry;
}
/**
* TODO the authorityName MUST be a part of ChoiceAuthority model
*
* @param source
* @param name
* @return
*/
public AuthorityRest convertAuthority(ChoiceAuthority source, String authorityName) {
AuthorityRest result = authorityConverter.convert(source);
result.setName(authorityName);
return result;
} }
} }