NIHVIVO-647 Server-side validation of publication form. Javascript event listeners.
This commit is contained in:
parent
e5fcb73ad2
commit
b98db24a65
1 changed files with 41 additions and 2 deletions
|
@ -2,15 +2,54 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||||
|
|
||||||
public class PersonHasPublicationValidator implements N3Validator {
|
public class PersonHasPublicationValidator implements N3Validator {
|
||||||
|
|
||||||
|
private static String MISSING_PUB_TYPE_ERROR = "Must specify a publication type.";
|
||||||
|
private static String MISSING_PUB_TITLE_ERROR = "Must specify a publication title.";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> validate(EditConfiguration editConfig,
|
public Map<String, String> validate(EditConfiguration editConfig,
|
||||||
EditSubmission editSub) {
|
EditSubmission editSub) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
Map<String,String> urisFromForm = editSub.getUrisFromForm();
|
||||||
|
Map<String,Literal> literalsFromForm = editSub.getLiteralsFromForm();
|
||||||
|
|
||||||
|
Map<String,String> errors = new HashMap<String,String>();
|
||||||
|
|
||||||
|
// If there's a pubUri, then we're done. The other fields are disabled and so don't get submitted.
|
||||||
|
String pubUri = urisFromForm.get("pubUri");
|
||||||
|
if (!StringUtils.isEmpty(pubUri)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String pubType = urisFromForm.get("pubType");
|
||||||
|
if ("".equals(pubType)) {
|
||||||
|
pubType = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Literal title = literalsFromForm.get("title");
|
||||||
|
if (title != null) {
|
||||||
|
String titleValue = title.getLexicalForm();
|
||||||
|
if (StringUtils.isEmpty(titleValue)) {
|
||||||
|
title = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pubType == null) {
|
||||||
|
errors.put("pubType", MISSING_PUB_TYPE_ERROR);
|
||||||
|
}
|
||||||
|
if (title == null) {
|
||||||
|
errors.put("title", MISSING_PUB_TITLE_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.size() != 0 ? errors : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue