NIHVIVO-646 More work on addAuthorsToInformationResource custom form. Create edit submission preprocessing mechanism to make automated modifications to the form submission (e.g., creating a label from first, last, and middle name entries).
This commit is contained in:
parent
3f88b02315
commit
5a1b1b2d80
7 changed files with 128 additions and 11 deletions
|
@ -0,0 +1,15 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||
|
||||
public abstract class BaseEditSubmissionPreprocessor implements
|
||||
EditSubmissionPreprocessor {
|
||||
|
||||
protected EditConfiguration editConfiguration;
|
||||
|
||||
public BaseEditSubmissionPreprocessor(EditConfiguration editConfig) {
|
||||
editConfiguration = editConfig;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
||||
public class CreateLabelFromNameFields extends BaseEditSubmissionPreprocessor {
|
||||
|
||||
private static final Log log = LogFactory.getLog(CreateLabelFromNameFields.class.getName());
|
||||
|
||||
public CreateLabelFromNameFields(EditConfiguration editConfig) {
|
||||
super(editConfig);
|
||||
}
|
||||
|
||||
// Create label by concatenating first name, middle name, and last name fields as
|
||||
// "<last name>, <first name> <middle name>". First name and last name are required;
|
||||
// middle name is optional.
|
||||
// rjy7 Using all hard-coded field names for now. If we want to control these, pass in
|
||||
// a map of field names when creating the preprocessor object.
|
||||
public void preprocess(EditSubmission editSubmission) {
|
||||
Map<String, Literal> literalsFromForm = editSubmission.getLiteralsFromForm();
|
||||
try {
|
||||
// Create the label string
|
||||
|
||||
// Assuming last name and first name fields will be on the form
|
||||
String lastName = literalsFromForm.get("lastName").getLexicalForm();
|
||||
String firstName = literalsFromForm.get("firstName").getLexicalForm();
|
||||
|
||||
// The form may or may not have a middle name field
|
||||
String middleName = "";
|
||||
Literal middleNameLiteral = literalsFromForm.get("middleName");
|
||||
if (middleNameLiteral != null) {
|
||||
middleName = middleNameLiteral.getLexicalForm();
|
||||
}
|
||||
|
||||
String label = lastName + ", " + firstName;
|
||||
if (!StringUtils.isEmpty(middleName)) {
|
||||
label += " " + middleName;
|
||||
}
|
||||
|
||||
// Add the label to the form literals
|
||||
Field labelField = editConfiguration.getField("label");
|
||||
String rangeDatatypeUri = labelField.getRangeDatatypeUri();
|
||||
if (StringUtils.isEmpty(rangeDatatypeUri)) {
|
||||
rangeDatatypeUri = XSD.xstring.toString();
|
||||
}
|
||||
String rangeLang = labelField.getRangeLang();
|
||||
// RY Had to change createLiteral method to protected - check w/Brian
|
||||
Literal labelLiteral = editSubmission.createLiteral(label, rangeDatatypeUri, rangeLang);
|
||||
literalsFromForm.put("label", labelLiteral);
|
||||
editSubmission.setLiteralsFromForm(literalsFromForm);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error retrieving name values from edit submission.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -91,6 +91,8 @@ public class EditConfiguration {
|
|||
|
||||
private List<ModelChangePreprocessor> modelChangePreprocessors;
|
||||
|
||||
private List<EditSubmissionPreprocessor> editSubmissionPreprocessors = null;
|
||||
|
||||
/**
|
||||
* If true, then any dependent resources that are unlinked should be
|
||||
* removed using DependentResourceDelete.
|
||||
|
@ -919,4 +921,14 @@ public class EditConfiguration {
|
|||
this.validators = new ArrayList<N3Validator>();
|
||||
this.validators.add(validator);
|
||||
}
|
||||
|
||||
public void addEditSubmissionPreprocessor( EditSubmissionPreprocessor preprocessor){
|
||||
if( editSubmissionPreprocessors == null )
|
||||
editSubmissionPreprocessors = new ArrayList<EditSubmissionPreprocessor>();
|
||||
editSubmissionPreprocessors.add(preprocessor);
|
||||
}
|
||||
|
||||
public List<EditSubmissionPreprocessor> getEditSubmissionPreprocessors() {
|
||||
return editSubmissionPreprocessors;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.hp.hpl.jena.vocabulary.XSD;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||
|
||||
public class EditSubmission {
|
||||
public class EditSubmission implements Cloneable {
|
||||
private String editKey;
|
||||
|
||||
private Map<String,Literal> literalsFromForm ;
|
||||
|
@ -145,7 +145,7 @@ public class EditSubmission {
|
|||
validationErrors.putAll(this.basicValidation.validateFiles( fileItems ) );
|
||||
}
|
||||
|
||||
private Literal createLiteral(String value, String datatypeUri, String lang){
|
||||
protected Literal createLiteral(String value, String datatypeUri, String lang){
|
||||
if( datatypeUri != null ){
|
||||
if( "http://www.w3.org/2001/XMLSchema:anyURI".equals(datatypeUri) ){
|
||||
try {
|
||||
|
@ -404,7 +404,6 @@ public class EditSubmission {
|
|||
sess.removeAttribute("editSubmission");
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, String[]> convertParams(
|
||||
Map<String, List<String>> queryParameters) {
|
||||
HashMap<String,String[]> out = new HashMap<String,String[]>();
|
||||
|
@ -415,5 +414,15 @@ public class EditSubmission {
|
|||
return out;
|
||||
}
|
||||
|
||||
public EditSubmission clone() {
|
||||
try {
|
||||
return (EditSubmission) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
log.error("Error cloning EditSubmission object: CloneNotSupported exception");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Log log = LogFactory.getLog(EditSubmission.class);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||
|
||||
public interface EditSubmissionPreprocessor {
|
||||
public void preprocess(EditSubmission editSubmission);
|
||||
}
|
|
@ -18,7 +18,11 @@
|
|||
<script type="text/javascript" src="<c:url value="/js/jquery_plugins/jquery.bgiframe.pack.js"/>"></script>
|
||||
<script type="text/javascript" src="<c:url value="/js/jquery_plugins/thickbox/thickbox-compressed.js"/>"></script>
|
||||
<!-- <script type="text/javascript" src="<c:url value="/js/jquery_plugins/ui.datepicker.js"/>"></script> -->
|
||||
|
||||
<% String useAutoComplete = (useAutoComplete=request.getParameter("useAutoComplete")) != null && !(useAutoComplete.equals("")) ? useAutoComplete : "false";
|
||||
if (useAutoComplete.equalsIgnoreCase("true")) { %>
|
||||
<script type="text/javascript" src="<c:url value="/js/jquery_plugins/jquery-autocomplete/jquery.autocomplete.pack.js"/>"></script>
|
||||
<% } %>
|
||||
|
||||
<c:forEach var="jsFile" items="${customJs}">
|
||||
<script type="text/javascript" src="<c:url value="${jsFile}"/>"></script>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3Generator" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmissionPreprocessor" %>
|
||||
<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field" %>
|
||||
<%@ page import="java.io.StringReader" %>
|
||||
<%@ page import="java.util.*" %>
|
||||
|
@ -87,6 +88,12 @@ are well formed.
|
|||
EditN3Generator n3Subber = editConfig.getN3Generator();
|
||||
EditSubmission submission = new EditSubmission(queryParameters,editConfig);
|
||||
|
||||
// Preprocess the form submission
|
||||
EditSubmission processedSubmission = submission.clone();
|
||||
for (EditSubmissionPreprocessor preprocessor : editConfig.getEditSubmissionPreprocessors()) {
|
||||
preprocessor.preprocess(processedSubmission);
|
||||
}
|
||||
|
||||
/* entity to return to may be a variable */
|
||||
List<String> entToReturnTo = new ArrayList<String>(1);
|
||||
if( editConfig.getEntityToReturnTo() != null ){
|
||||
|
@ -122,9 +129,9 @@ are well formed.
|
|||
Map<String,List<String>> fieldRetractions= fieldsToRetractionMap(editConfig.getFields());
|
||||
|
||||
/* ********** URIs and Literals on Form/Parameters *********** */
|
||||
fieldAssertions = n3Subber.substituteIntoValues( submission.getUrisFromForm(), submission.getLiteralsFromForm(), fieldAssertions);
|
||||
fieldAssertions = n3Subber.substituteIntoValues( processedSubmission.getUrisFromForm(), processedSubmission.getLiteralsFromForm(), fieldAssertions);
|
||||
if(log.isDebugEnabled()) logAddRetract("substituted in literals from form",fieldAssertions,fieldRetractions);
|
||||
entToReturnTo = n3Subber.subInUris(submission.getUrisFromForm(),entToReturnTo);
|
||||
entToReturnTo = n3Subber.subInUris(processedSubmission.getUrisFromForm(),entToReturnTo);
|
||||
//fieldRetractions does NOT get values from form.
|
||||
|
||||
/* ****************** URIs and Literals in Scope ************** */
|
||||
|
@ -204,14 +211,14 @@ are well formed.
|
|||
|
||||
/* ********** URIs and Literals on Form/Parameters *********** */
|
||||
//sub in resource uris off form
|
||||
n3Required = n3Subber.subInUris(submission.getUrisFromForm(), n3Required);
|
||||
n3Optional = n3Subber.subInUris(submission.getUrisFromForm(), n3Optional);
|
||||
n3Required = n3Subber.subInUris(processedSubmission.getUrisFromForm(), n3Required);
|
||||
n3Optional = n3Subber.subInUris(processedSubmission.getUrisFromForm(), n3Optional);
|
||||
if(log.isDebugEnabled()) logRequiredOpt("substituted in URIs off from ",n3Required,n3Optional);
|
||||
entToReturnTo = n3Subber.subInUris(submission.getUrisFromForm(), entToReturnTo);
|
||||
entToReturnTo = n3Subber.subInUris(processedSubmission.getUrisFromForm(), entToReturnTo);
|
||||
|
||||
//sub in literals from form
|
||||
n3Required = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Required);
|
||||
n3Optional = n3Subber.subInLiterals(submission.getLiteralsFromForm(), n3Optional);
|
||||
n3Required = n3Subber.subInLiterals(processedSubmission.getLiteralsFromForm(), n3Required);
|
||||
n3Optional = n3Subber.subInLiterals(processedSubmission.getLiteralsFromForm(), n3Optional);
|
||||
if(log.isDebugEnabled()) logRequiredOpt("substituted in literals off from ",n3Required,n3Optional);
|
||||
|
||||
/* ****************** URIs and Literals in Scope ************** */
|
||||
|
|
Loading…
Add table
Reference in a new issue