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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue