mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
DS-3699 add support for regex validation, page heading and mandatory flag
This commit is contained in:

committed by
Luigi Andrea Pascarelli

parent
2594415db7
commit
d026d72017
@@ -74,6 +74,9 @@ public class DCInput
|
||||
/** is the entry closed to vocabulary terms? */
|
||||
private boolean closedVocabulary = false;
|
||||
|
||||
/** the regex to comply with, null if nothing */
|
||||
private String regex = null;
|
||||
|
||||
/** allowed document types */
|
||||
private List<String> typeBind = null;
|
||||
|
||||
@@ -137,6 +140,7 @@ public class DCInput
|
||||
visibility = fieldMap.get("visibility");
|
||||
readOnly = fieldMap.get("readonly");
|
||||
vocabulary = fieldMap.get("vocabulary");
|
||||
regex = fieldMap.get("regex");
|
||||
String closedVocabularyStr = fieldMap.get("closedVocabulary");
|
||||
closedVocabulary = "true".equalsIgnoreCase(closedVocabularyStr)
|
||||
|| "yes".equalsIgnoreCase(closedVocabularyStr);
|
||||
@@ -441,5 +445,13 @@ public class DCInput
|
||||
|
||||
return typeBind.contains(typeName);
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
public String getRegex() {
|
||||
return regex;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,6 +11,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
||||
/**
|
||||
* Class representing all DC inputs required for a submission, organized into pages
|
||||
*
|
||||
@@ -20,24 +22,46 @@ import java.util.Map;
|
||||
|
||||
public class DCInputSet
|
||||
{
|
||||
/** true if it is the default configuration */
|
||||
private boolean defaultConf;
|
||||
/** name of the input set */
|
||||
private String formName = null;
|
||||
/** the inputs ordered by page and row position */
|
||||
private DCInput[][] inputPages = null;
|
||||
|
||||
/** constructor
|
||||
* @param formName form name
|
||||
* @param pages pages
|
||||
* @param listMap map
|
||||
*/
|
||||
public DCInputSet(String formName, List<List<Map<String, String>>> pages, Map<String, List<String>> listMap)
|
||||
/** the heading of each page */
|
||||
private String[] headings;
|
||||
|
||||
/** the mandatory flag for each page */
|
||||
private boolean[] mandatoryFlags;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param formName
|
||||
* form name
|
||||
* @param headings
|
||||
* @param mandatoryFlags
|
||||
* @param pages
|
||||
* pages
|
||||
* @param listMap
|
||||
* map
|
||||
*/
|
||||
public DCInputSet(boolean defaultConf, String formName, List<String> headingsList, List<Boolean> mandatoryFlagsList,
|
||||
List<List<Map<String, String>>> pages, Map<String, List<String>> listMap)
|
||||
{
|
||||
this.defaultConf = defaultConf;
|
||||
this.formName = formName;
|
||||
inputPages = new DCInput[pages.size()][];
|
||||
headings = new String[pages.size()];
|
||||
mandatoryFlags = new boolean[pages.size()];
|
||||
for ( int i = 0; i < inputPages.length; i++ )
|
||||
{
|
||||
List<Map<String, String>> page = pages.get(i);
|
||||
inputPages[i] = new DCInput[page.size()];
|
||||
inputPages[i] = new DCInput[page.size()];
|
||||
headings[i] = headingsList.get(i);
|
||||
mandatoryFlags[i] = BooleanUtils.toBooleanDefaultIfNull(mandatoryFlagsList.get(i), true);
|
||||
|
||||
for ( int j = 0; j < inputPages[i].length; j++ )
|
||||
{
|
||||
inputPages[i][j] = new DCInput(page.get(j), listMap);
|
||||
@@ -196,4 +220,16 @@ public class DCInputSet
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isPageMandatory(int idx) {
|
||||
return mandatoryFlags[idx];
|
||||
}
|
||||
|
||||
public String getPageHeading(int idx) {
|
||||
return headings[idx];
|
||||
}
|
||||
|
||||
public boolean isDefaultConf() {
|
||||
return defaultConf;
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,8 @@ import org.xml.sax.SAXException;
|
||||
import org.w3c.dom.*;
|
||||
import javax.xml.parsers.*;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.content.MetadataSchema;
|
||||
|
||||
/**
|
||||
@@ -65,6 +67,18 @@ public class DCInputsReader
|
||||
*/
|
||||
private Map<String, List<List<Map<String, String>>>> formDefns = null;
|
||||
|
||||
/**
|
||||
* Reference to the forms page headings, computed from the forms
|
||||
* definition file
|
||||
*/
|
||||
private Map<String, List<String>> formPageHeadings = null;
|
||||
|
||||
/**
|
||||
* Reference to the forms mandatory flags, computed from the forms
|
||||
* definition file
|
||||
*/
|
||||
private Map<String, List<Boolean>> formMandatoryFlags = null;
|
||||
|
||||
/**
|
||||
* Reference to the value-pairs map, computed from the forms definition file
|
||||
*/
|
||||
@@ -110,7 +124,9 @@ public class DCInputsReader
|
||||
whichForms = new HashMap<String, String>();
|
||||
formDefns = new HashMap<String, List<List<Map<String, String>>>>();
|
||||
valuePairs = new HashMap<String, List<String>>();
|
||||
|
||||
formMandatoryFlags = new HashMap<String, List<Boolean>>();
|
||||
formPageHeadings = new HashMap<String, List<String>>();
|
||||
|
||||
String uri = "file:" + new File(fileName).getAbsolutePath();
|
||||
|
||||
try
|
||||
@@ -193,7 +209,8 @@ public class DCInputsReader
|
||||
{
|
||||
throw new DCInputsReaderException("Missing the " + formName + " form");
|
||||
}
|
||||
lastInputSet = new DCInputSet(formName, pages, valuePairs);
|
||||
lastInputSet = new DCInputSet(StringUtils.equals(whichForms.get(DEFAULT_COLLECTION), formName), formName,
|
||||
formPageHeadings.get(formName), formMandatoryFlags.get(formName), pages, valuePairs);
|
||||
return lastInputSet;
|
||||
}
|
||||
|
||||
@@ -365,7 +382,11 @@ public class DCInputsReader
|
||||
throw new SAXException("form element has no name attribute");
|
||||
}
|
||||
List<List<Map<String, String>>> pages = new ArrayList<List<Map<String, String>>>(); // the form contains pages
|
||||
List<String> pageHeadings = new ArrayList<String>();
|
||||
List<Boolean> mandatoryFlags = new ArrayList<Boolean>();
|
||||
formDefns.put(formName, pages);
|
||||
formPageHeadings.put(formName, pageHeadings);
|
||||
formMandatoryFlags.put(formName, mandatoryFlags);
|
||||
NodeList pl = nd.getChildNodes();
|
||||
int lenpg = pl.getLength();
|
||||
for (int j = 0; j < lenpg; j++)
|
||||
@@ -379,6 +400,8 @@ public class DCInputsReader
|
||||
{
|
||||
throw new SAXException("Form " + formName + " has no identified pages");
|
||||
}
|
||||
pageHeadings.add(getAttribute(npg, "heading"));
|
||||
mandatoryFlags.add(BooleanUtils.toBoolean(getAttribute(npg, "mandatory")));
|
||||
List<Map<String, String>> page = new ArrayList<Map<String, String>>();
|
||||
pages.add(page);
|
||||
NodeList flds = npg.getChildNodes();
|
||||
|
@@ -13,8 +13,11 @@
|
||||
<!ELEMENT form (page)+ >
|
||||
<!ATTLIST form name NMTOKEN #REQUIRED>
|
||||
<!ELEMENT page (field)+ >
|
||||
<!ATTLIST page number NMTOKEN #REQUIRED>
|
||||
<!ELEMENT field (dc-schema, dc-element, dc-qualifier?, language?, repeatable?, label, type-bind?, input-type, hint, required?, vocabulary?, visibility?) >
|
||||
<!ATTLIST page
|
||||
number NMTOKEN #REQUIRED
|
||||
heading NMTOKEN #IMPLIED
|
||||
mandatory NMTOKEN #IMPLIED>
|
||||
<!ELEMENT field (dc-schema, dc-element, dc-qualifier?, language?, repeatable?, label, type-bind?, input-type, hint, required?, regex?, vocabulary?, visibility?) >
|
||||
<!ELEMENT dc-schema (#PCDATA) >
|
||||
<!ELEMENT dc-element (#PCDATA) >
|
||||
<!ELEMENT dc-qualifier (#PCDATA) >
|
||||
@@ -27,6 +30,7 @@
|
||||
|
||||
<!ELEMENT hint (#PCDATA) >
|
||||
<!ELEMENT required (#PCDATA)>
|
||||
<!ELEMENT regex (#PCDATA) >
|
||||
|
||||
<!ELEMENT form-value-pairs (value-pairs)* >
|
||||
<!ELEMENT value-pairs (pair)+ >
|
||||
|
Reference in New Issue
Block a user