Skip to content

Commit

Permalink
Merge pull request #2239 from 4Science/inputform-rows
Browse files Browse the repository at this point in the history
DS-3937 Add support for styling and rows in the submission-forms.xml
  • Loading branch information
tdonohue committed Oct 23, 2018
2 parents cb1a35a + d55189a commit bd9bd23
Show file tree
Hide file tree
Showing 25 changed files with 1,121 additions and 649 deletions.
31 changes: 23 additions & 8 deletions dspace-api/src/main/java/org/dspace/app/util/DCInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public class DCInput {
*/
private String label = null;

/**
* a style instruction to apply to the input. The exact way to use the style value is UI depending that receive the
* value from the REST API as is
*/
private String style = null;

/**
* the input type
*/
Expand Down Expand Up @@ -199,7 +205,7 @@ public DCInput(Map<String, String> fieldMap, Map<String, List<String>> listMap)
typeBind.add(type.trim());
}
}

style = fieldMap.get("style");
}

/**
Expand Down Expand Up @@ -262,7 +268,7 @@ public String getInputType() {
}

/**
* Get the DC element for this form row.
* Get the DC element for this form field.
*
* @return the DC element
*/
Expand All @@ -271,7 +277,7 @@ public String getElement() {
}

/**
* Get the DC namespace prefix for this form row.
* Get the DC namespace prefix for this form field.
*
* @return the DC namespace prefix
*/
Expand All @@ -290,7 +296,7 @@ public String getWarning() {
}

/**
* Is there a required string for this form row?
* Is there a required string for this form field?
*
* @return true if a required string is set
*/
Expand All @@ -299,7 +305,7 @@ public boolean isRequired() {
}

/**
* Get the DC qualifier for this form row.
* Get the DC qualifier for this form field.
*
* @return the DC qualifier
*/
Expand All @@ -308,7 +314,7 @@ public String getQualifier() {
}

/**
* Get the language for this form row.
* Get the language for this form field.
*
* @return the language state
*/
Expand All @@ -317,7 +323,7 @@ public boolean getLanguage() {
}

/**
* Get the hint for this form row, formatted for an HTML table
* Get the hint for this form field
*
* @return the hints
*/
Expand All @@ -326,14 +332,23 @@ public String getHints() {
}

/**
* Get the label for this form row.
* Get the label for this form field.
*
* @return the label
*/
public String getLabel() {
return label;
}

/**
* Get the style for this form field
*
* @return the style
*/
public String getStyle() {
return style;
}

/**
* Get the name of the pairs type
*
Expand Down
43 changes: 24 additions & 19 deletions dspace-api/src/main/java/org/dspace/app/util/DCInputSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@ public class DCInputSet {
/**
* the inputs ordered by row position
*/
private DCInput[] inputs = null;
private DCInput[][] inputs = null;

/**
* constructor
*
* @param formName form name
* @param headings
* @param mandatoryFlags
* @param fields fields
* @param rows the rows
* @param listMap map
*/
public DCInputSet(String formName,
List<Map<String, String>> fields, Map<String, List<String>> listMap) {
public DCInputSet(String formName, List<List<Map<String, String>>> rows, Map<String, List<String>> listMap) {
this.formName = formName;
this.inputs = new DCInput[fields.size()];
this.inputs = new DCInput[rows.size()][];
for (int i = 0; i < inputs.length; i++) {
Map<String, String> field = fields.get(i);
inputs[i] = new DCInput(field, listMap);

List<Map<String, String>> fields = rows.get(i);
inputs[i] = new DCInput[fields.size()];
for (int j = 0; j < inputs[i].length; j++) {
Map<String, String> field = rows.get(i).get(j);
inputs[i][j] = new DCInput(field, listMap);
}
}
}

Expand Down Expand Up @@ -71,7 +72,7 @@ public int getNumberFields() {
* @return an array containing the fields
*/

public DCInput[] getFields() {
public DCInput[][] getFields() {
return inputs;
}

Expand Down Expand Up @@ -104,10 +105,12 @@ public boolean isDefinedPubBefore() {
*/
public boolean isFieldPresent(String fieldName) {
for (int i = 0; i < inputs.length; i++) {
DCInput field = inputs[i];
String fullName = field.getFieldName();
if (fullName.equals(fieldName)) {
return true;
for (int j = 0; j < inputs[i].length; j++) {
DCInput field = inputs[i][j];
String fullName = field.getFieldName();
if (fullName.equals(fieldName)) {
return true;
}
}
}
return false;
Expand All @@ -127,11 +130,13 @@ public boolean isFieldPresent(String fieldName, String documentType) {
documentType = "";
}
for (int i = 0; i < inputs.length; i++) {
DCInput field = inputs[i];
String fullName = field.getFieldName();
if (fullName.equals(fieldName)) {
if (field.isAllowedFor(documentType)) {
return true;
for (int j = 0; j < inputs[i].length; j++) {
DCInput field = inputs[i][j];
String fullName = field.getFieldName();
if (fullName.equals(fieldName)) {
if (field.isAllowedFor(documentType)) {
return true;
}
}
}
}
Expand Down
116 changes: 80 additions & 36 deletions dspace-api/src/main/java/org/dspace/app/util/DCInputsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class DCInputsReader {
* Reference to the forms definitions map, computed from the forms
* definition file
*/
private Map<String, List<Map<String, String>>> formDefns = null;
private Map<String, List<List<Map<String, String>>>> formDefns = null;

/**
* Reference to the value-pairs map, computed from the forms definition file
Expand Down Expand Up @@ -115,7 +115,7 @@ public DCInputsReader(String fileName)

private void buildInputs(String fileName)
throws DCInputsReaderException {
formDefns = new HashMap<String, List<Map<String, String>>>();
formDefns = new HashMap<String, List<List<Map<String, String>>>>();
valuePairs = new HashMap<String, List<String>>();

String uri = "file:" + new File(fileName).getAbsolutePath();
Expand Down Expand Up @@ -212,7 +212,7 @@ public DCInputSet getInputsByFormName(String formName)
return lastInputSet;
}
// cache miss - construct new DCInputSet
List<Map<String, String>> pages = formDefns.get(formName);
List<List<Map<String, String>>> pages = formDefns.get(formName);
if (pages == null) {
throw new DCInputsReaderException("Missing the " + formName + " form");
}
Expand Down Expand Up @@ -292,8 +292,8 @@ private void doNodes(Node n)

/**
* Process the form-definitions section of the XML file. Each element is
* formed thusly: <form name="formname">...pages...</form> Each pages
* subsection is formed: <page number="#"> ...fields... </page> Each field
* formed thusly: <form name="formname">...row...</form> Each rows
* subsection is formed: <row> ...fields... </row> Each field
* is formed from: dc-element, dc-qualifier, label, hint, input-type name,
* required text, and repeatable flag.
*/
Expand All @@ -311,26 +311,24 @@ private void processDefinition(Node e)
if (formName == null) {
throw new SAXException("form element has no name attribute");
}
List<Map<String, String>> fields = new ArrayList<Map<String, String>>(); // the form contains fields
formDefns.put(formName, fields);
List<List<Map<String, String>>> rows = new ArrayList<List<Map<String, String>>>(); // the form
// contains rows of fields
formDefns.put(formName, rows);
NodeList pl = nd.getChildNodes();
int lenpg = pl.getLength();
for (int j = 0; j < lenpg; j++) {
Node npg = pl.item(j);

if (npg.getNodeName().equals("field")) {
// process each field definition
Map<String, String> field = new HashMap<String, String>();
processField(formName, npg, field);
fields.add(field);
// we omit the duplicate validation, allowing multiple
// fields definition for
// the same metadata and different visibility/type-bind
if (npg.getNodeName().equals("row")) {
List<Map<String, String>> fields = new ArrayList<Map<String, String>>(); // the fields in the
// row
// process each row definition
processRow(formName, j, npg, fields);
rows.add(fields);
}
}
// sanity check number of fields
if (fields.size() < 1) {
throw new DCInputsReaderException("Form " + formName + " has no fields");
if (rows.size() < 1) {
throw new DCInputsReaderException("Form " + formName + " has no rows");
}
}
}
Expand All @@ -339,6 +337,48 @@ private void processDefinition(Node e)
}
}

/**
* Process parts of a row
*/
private void processRow(String formName, int rowIdx, Node n, List<Map<String, String>> fields)
throws SAXException, DCInputsReaderException {

NodeList pl = n.getChildNodes();
int lenpg = pl.getLength();
for (int j = 0; j < lenpg; j++) {
Node npg = pl.item(j);

if (npg.getNodeName().equals("field")) {
// process each field definition
Map<String, String> field = new HashMap<String, String>();
processField(formName, npg, field);
fields.add(field);
String key = field.get(PAIR_TYPE_NAME);
if (StringUtils
.isNotBlank(key)) {
String schema = field.get("dc-schema");
String element = field.get("dc-element");
String qualifier = field
.get("dc-qualifier");
String metadataField = schema + "."
+ element;
if (StringUtils.isNotBlank(qualifier)) {
metadataField += "." + qualifier;
}
}

// we omit the duplicate validation, allowing multiple
// fields definition for
// the same metadata and different visibility/type-bind
}
}
// sanity check number of fields
if (fields.size() < 1) {
throw new DCInputsReaderException("Form " + formName + "row " + rowIdx + " has no fields");
}
}


/**
* Process parts of a field
* At the end, make sure that input-types 'qualdrop_value' and
Expand Down Expand Up @@ -537,26 +577,29 @@ private void checkValues()
Iterator<String> ki = formDefns.keySet().iterator();
while (ki.hasNext()) {
String idName = ki.next();
List<Map<String, String>> fields = formDefns.get(idName);
for (int i = 0; i < fields.size(); i++) {
Map<String, String> fld = fields.get(i);
// verify reference in certain input types
String type = fld.get("input-type");
if (type.equals("dropdown")
|| type.equals("qualdrop_value")
|| type.equals("list")) {
String pairsName = fld.get(PAIR_TYPE_NAME);
List<String> v = valuePairs.get(pairsName);
if (v == null) {
String errString = "Cannot find value pairs for " + pairsName;
throw new DCInputsReaderException(errString);
List<List<Map<String, String>>> rows = formDefns.get(idName);
for (int j = 0; j < rows.size(); j++) {
List<Map<String, String>> fields = rows.get(j);
for (int i = 0; i < fields.size(); i++) {
Map<String, String> fld = fields.get(i);
// verify reference in certain input types
String type = fld.get("input-type");
if (type.equals("dropdown")
|| type.equals("qualdrop_value")
|| type.equals("list")) {
String pairsName = fld.get(PAIR_TYPE_NAME);
List<String> v = valuePairs.get(pairsName);
if (v == null) {
String errString = "Cannot find value pairs for " + pairsName;
throw new DCInputsReaderException(errString);
}
}
}

// we omit the "required" and "visibility" validation, provided this must be checked in the
// processing class
// only when it makes sense (if the field isn't visible means that it is not applicable, therefore it
// can't be required)
// we omit the "required" and "visibility" validation, provided this must be checked in the
// processing class
// only when it makes sense (if the field isn't visible means that it is not applicable,
// therefore it can't be required)
}
}
}
}
Expand Down Expand Up @@ -639,4 +682,5 @@ public String getInputFormNameByCollectionAndField(Collection collection, String
}
throw new DCInputsReaderException("No field configuration found!");
}

}

0 comments on commit bd9bd23

Please sign in to comment.