Added support for Type-based submission

(see https://jira.duraspace.org/browse/DS-1127)
This commit is contained in:
Nestor Oviedo
2012-08-08 16:36:30 -03:00
parent e634c6edf5
commit c1e4c58a0d
4 changed files with 71 additions and 17 deletions

View File

@@ -7,6 +7,7 @@
*/
package org.dspace.app.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -65,6 +66,9 @@ public class DCInput
/** is the entry closed to vocabulary terms? */
private boolean closedVocabulary = false;
/** allowed document types */
private List<String> typeBind = null;
/**
* The scope of the input sets, this restricts hidden metadata fields from
* view during workflow processing.
@@ -118,6 +122,17 @@ public class DCInput
String closedVocabularyStr = fieldMap.get("closedVocabulary");
closedVocabulary = "true".equalsIgnoreCase(closedVocabularyStr)
|| "yes".equalsIgnoreCase(closedVocabularyStr);
// parsing of the <type-bind> element (using the colon as split separator)
typeBind = new ArrayList<String>();
String typeBindDef = fieldMap.get("type-bind");
if(typeBindDef != null && typeBindDef.trim().length() > 0) {
String[] types = typeBindDef.split(",");
for(String type : types) {
typeBind.add( type.trim() );
}
}
}
/**
@@ -376,4 +391,16 @@ public class DCInput
return closedVocabulary;
}
/**
* Decides if this field is valid for the document type
* @param typeName Document type name
* @return true when there is no type restriction or typeName is allowed
*/
public boolean isAllowedFor(String typeName) {
if(typeBind.size() == 0)
return true;
return typeBind.contains(typeName);
}
}

View File

@@ -333,11 +333,10 @@ public class DCInputsReader
Map<String, String> field = new HashMap<String, String>();
page.add(field);
processPageParts(formName, pgNum, nfld, field);
String error = checkForDups(formName, field, pages);
if (error != null)
{
throw new SAXException(error);
}
// we omit the duplicate validation, allowing multiple fields definition for
// the same metadata and different visibility/type-bind
}
}
} // ignore any child that is not a 'page'
@@ -605,18 +604,10 @@ public class DCInputsReader
throw new DCInputsReaderException(errString);
}
}
// if visibility restricted, make sure field is not required
String visibility = fld.get("visibility");
if (visibility != null && visibility.length() > 0 )
{
String required = fld.get("required");
if (required != null && required.length() > 0)
{
String errString = "Field '" + fld.get("label") +
"' is required but invisible";
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)
}
}
}

View File

@@ -139,10 +139,20 @@ public class DescribeStep extends AbstractProcessingStep
throw new ServletException(e);
}
// Fetch the document type (dc.type)
String documentType = "";
if( (item.getMetadata("dc.type") != null) && (item.getMetadata("dc.type").length >0) )
{
documentType = item.getMetadata("dc.type")[0].value;
}
// Step 1:
// clear out all item metadata defined on this page
for (int i = 0; i < inputs.length; i++)
{
// Allow the clearing out of the metadata defined for other document types, provided it can change anytime
if (!inputs[i]
.isVisible(subInfo.isInWorkflow() ? DCInput.WORKFLOW_SCOPE
: DCInput.SUBMISSION_SCOPE))
@@ -169,6 +179,12 @@ public class DescribeStep extends AbstractProcessingStep
boolean moreInput = false;
for (int j = 0; j < inputs.length; j++)
{
// Omit fields not allowed for this document type
if(!inputs[j].isAllowedFor(documentType))
{
continue;
}
if (!inputs[j]
.isVisible(subInfo.isInWorkflow() ? DCInput.WORKFLOW_SCOPE
: DCInput.SUBMISSION_SCOPE))
@@ -284,6 +300,13 @@ public class DescribeStep extends AbstractProcessingStep
{
for (int i = 0; i < inputs.length; i++)
{
// Do not check the required attribute if it is not visible or not allowed for the document type
String scope = subInfo.isInWorkflow() ? DCInput.WORKFLOW_SCOPE : DCInput.SUBMISSION_SCOPE;
if ( !( inputs[i].isVisible(scope) && inputs[i].isAllowedFor(documentType) ) )
{
continue;
}
DCValue[] values = item.getMetadata(inputs[i].getSchema(),
inputs[i].getElement(), inputs[i].getQualifier(), Item.ANY);