Merge revisions 4740 and 4744 to the trunk. For bdc34 and jeb228.
This commit is contained in:
parent
b88ed19ed0
commit
e1ceb15339
5 changed files with 145 additions and 8 deletions
|
@ -3,13 +3,12 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
|
@ -24,6 +23,7 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
@ -32,11 +32,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleFactory;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.UserToIndIdentifierFactory;
|
import edu.cornell.mannlib.vitro.webapp.auth.identifier.UserToIndIdentifierFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
|
||||||
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
|
|
||||||
import com.hp.hpl.jena.datatypes.BaseDatatype;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a set of fields on a form and how parameters from a from
|
* Represents a set of fields on a form and how parameters from a from
|
||||||
|
@ -88,7 +84,9 @@ public class EditConfiguration {
|
||||||
String formUrl;
|
String formUrl;
|
||||||
String editKey;
|
String editKey;
|
||||||
|
|
||||||
EditN3Generator n3generator;
|
List<N3Validator> validators;
|
||||||
|
|
||||||
|
EditN3Generator n3generator;
|
||||||
private String originalJson;
|
private String originalJson;
|
||||||
|
|
||||||
private List<ModelChangePreprocessor> modelChangePreprocessors;
|
private List<ModelChangePreprocessor> modelChangePreprocessors;
|
||||||
|
@ -963,5 +961,15 @@ public class EditConfiguration {
|
||||||
public void setResourceModelSelector(ModelSelector resourceModelSelector) {
|
public void setResourceModelSelector(ModelSelector resourceModelSelector) {
|
||||||
if( resourceModelSelector != null )
|
if( resourceModelSelector != null )
|
||||||
this.resourceModelSelector = resourceModelSelector;
|
this.resourceModelSelector = resourceModelSelector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<N3Validator> getValidators() {
|
||||||
|
return validators;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addValidator( N3Validator validator){
|
||||||
|
if( this.validators == null )
|
||||||
|
this.validators = new ArrayList<N3Validator>();
|
||||||
|
this.validators.add(validator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,15 @@ public class EditSubmission {
|
||||||
validationErrors.putAll( errors);
|
validationErrors.putAll( errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(editConfig.getValidators() != null ){
|
||||||
|
for( N3Validator validator : editConfig.getValidators()){
|
||||||
|
if( validator != null ){
|
||||||
|
errors = validator.validate(editConfig, this);
|
||||||
|
if ( errors != null )
|
||||||
|
validationErrors.putAll(errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface N3Validator {
|
||||||
|
public Map<String,String> validate(EditConfiguration editConfig, EditSubmission editSub);
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
|
||||||
|
public class PersonHasPositionValidator implements N3Validator {
|
||||||
|
|
||||||
|
public Map<String,String> validate(EditConfiguration editConfig, EditSubmission editSub){
|
||||||
|
// Map<String,String> existingUris = editConfig.getUrisInScope();
|
||||||
|
// Map<String,Literal> existingLiterals = editConfig.getLiteralsInScope();
|
||||||
|
Map<String,String> urisFromForm = editSub.getUrisFromForm();
|
||||||
|
Map<String,Literal> literalsFromForm = editSub.getLiteralsFromForm();
|
||||||
|
|
||||||
|
Literal newOrgName = literalsFromForm.get("newOrgName");
|
||||||
|
if( newOrgName.getLexicalForm() != null && "".equals(newOrgName.getLexicalForm()) )
|
||||||
|
newOrgName = null;
|
||||||
|
String newOrgType = urisFromForm.get("newOrgType");
|
||||||
|
if( "".equals(newOrgType ) )
|
||||||
|
newOrgType = null;
|
||||||
|
String organizationUri = urisFromForm.get("organizationUri");
|
||||||
|
if( "".equals(organizationUri))
|
||||||
|
organizationUri = null;
|
||||||
|
|
||||||
|
System.out.println("newOrgName " + newOrgName);
|
||||||
|
System.out.println("newOrgType " + newOrgType);
|
||||||
|
System.out.println("organizationUri " + organizationUri);
|
||||||
|
|
||||||
|
Map<String,String> errors = new HashMap<String,String>();
|
||||||
|
if( organizationUri != null && (newOrgName != null || newOrgType != null) ){
|
||||||
|
errors.put("newOrgName", "Must choose from an existing orginization or create a new one, not both.");
|
||||||
|
errors.put("organizationUri", "Must choose from an existing orginizations or create a new one, not both.");
|
||||||
|
}else if( organizationUri == null && newOrgName != null && newOrgType == null) {
|
||||||
|
errors.put("newOrgType", "Must select a type for the new organization");
|
||||||
|
}else if( organizationUri == null && newOrgName == null && newOrgType != null) {
|
||||||
|
errors.put("newOrgName", "Must select a name for the new organization");
|
||||||
|
}
|
||||||
|
|
||||||
|
if( errors.size() != 0 )
|
||||||
|
return errors;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
|
||||||
|
public class StartYearBeforeEndYear implements N3Validator {
|
||||||
|
private String startFieldName;
|
||||||
|
private String endFieldName;
|
||||||
|
|
||||||
|
public StartYearBeforeEndYear(String startFieldName, String endFieldName){
|
||||||
|
this.startFieldName = startFieldName;
|
||||||
|
this.endFieldName = endFieldName;
|
||||||
|
}
|
||||||
|
public Map<String, String> validate(EditConfiguration editConfig,
|
||||||
|
EditSubmission editSub) {
|
||||||
|
Map<String, Literal> existingLiterals = editConfig.getLiteralsInScope();
|
||||||
|
Literal existingStartYear = existingLiterals.get(startFieldName);
|
||||||
|
Literal existingEndYear = existingLiterals.get(endFieldName);
|
||||||
|
|
||||||
|
Map<String, Literal> literalsFromForm = editSub.getLiteralsFromForm();
|
||||||
|
Literal formStartYear = literalsFromForm.get(startFieldName);
|
||||||
|
Literal formEndYear = literalsFromForm.get(endFieldName);
|
||||||
|
|
||||||
|
Map<String, String> errors = new HashMap<String, String>();
|
||||||
|
|
||||||
|
if (formStartYear != null && formEndYear != null) {
|
||||||
|
errors.putAll(checkDateLiterals(formStartYear, formEndYear));
|
||||||
|
} else if (formStartYear != null && existingEndYear != null) {
|
||||||
|
errors.putAll(checkDateLiterals(formStartYear, existingEndYear));
|
||||||
|
} else if (existingStartYear != null && formEndYear != null) {
|
||||||
|
errors.putAll(checkDateLiterals(existingStartYear, formEndYear));
|
||||||
|
} else if (existingStartYear != null && existingEndYear != null) {
|
||||||
|
errors
|
||||||
|
.putAll(checkDateLiterals(existingStartYear,
|
||||||
|
existingEndYear));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.size() != 0)
|
||||||
|
return errors;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> checkDateLiterals(Literal startLit,
|
||||||
|
Literal endLit) {
|
||||||
|
Map<String, String> errors = new HashMap<String, String>();
|
||||||
|
try {
|
||||||
|
int start = Integer.parseInt(startLit.getLexicalForm());
|
||||||
|
int end = Integer.parseInt(endLit.getLexicalForm());
|
||||||
|
if (end < start) {
|
||||||
|
errors.put(startFieldName, "Start year must be before end year");
|
||||||
|
errors.put(endFieldName, "End year must be after start year");
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue