Moved form validators that are specific to vivo out of vitro and into vivo.
This commit is contained in:
parent
81e40b0fef
commit
1a9e853a4d
3 changed files with 0 additions and 168 deletions
|
@ -1,51 +0,0 @@
|
||||||
/* $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 {
|
|
||||||
|
|
||||||
private static String DUPLICATE_ERROR = "Must select an existing organization or create a new one, not both.";
|
|
||||||
private static String MISSING_ORG_ERROR = "Must either select an existing organization or create a new one.";
|
|
||||||
private static String MISSING_ORG_TYPE_ERROR = "Must select a type for the new organization.";
|
|
||||||
private static String MISSING_ORG_NAME_ERROR = "Must specify a name for the new organization.";
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
Map<String,String> errors = new HashMap<String,String>();
|
|
||||||
if( organizationUri != null && (newOrgName != null || newOrgType != null) ){
|
|
||||||
errors.put("newOrgName", DUPLICATE_ERROR);
|
|
||||||
errors.put("organizationUri", DUPLICATE_ERROR);
|
|
||||||
} else if ( organizationUri == null && newOrgName == null && newOrgType == null) {
|
|
||||||
errors.put("newOrgName", MISSING_ORG_ERROR);
|
|
||||||
errors.put("organizationUri", MISSING_ORG_ERROR);
|
|
||||||
}else if( organizationUri == null && newOrgName != null && newOrgType == null) {
|
|
||||||
errors.put("newOrgType", MISSING_ORG_TYPE_ERROR);
|
|
||||||
}else if( organizationUri == null && newOrgName == null && newOrgType != null) {
|
|
||||||
errors.put("newOrgName", MISSING_ORG_NAME_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( errors.size() != 0 )
|
|
||||||
return errors;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
/* $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;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
|
||||||
|
|
||||||
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
|
|
||||||
public Map<String, String> validate(EditConfiguration editConfig,
|
|
||||||
EditSubmission editSub) {
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
/* $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 PublicationHasAuthorValidator implements N3Validator {
|
|
||||||
|
|
||||||
private static String MISSING_AUTHOR_ERROR = "Must specify a new or existing author.";
|
|
||||||
private static String MISSING_FIRST_NAME_ERROR = "Must specify the author's first name.";
|
|
||||||
private static String MISSING_LAST_NAME_ERROR = "Must specify the author's last name.";
|
|
||||||
private static String MALFORMED_LAST_NAME_ERROR = "Last name may not contain a comma. Please enter first name in first name field.";
|
|
||||||
;
|
|
||||||
@Override
|
|
||||||
public Map<String, String> validate(EditConfiguration editConfig,
|
|
||||||
EditSubmission editSub) {
|
|
||||||
Map<String,String> urisFromForm = editSub.getUrisFromForm();
|
|
||||||
Map<String,Literal> literalsFromForm = editSub.getLiteralsFromForm();
|
|
||||||
|
|
||||||
Map<String,String> errors = new HashMap<String,String>();
|
|
||||||
|
|
||||||
String personUri = urisFromForm.get("personUri");
|
|
||||||
if ("".equals(personUri)) {
|
|
||||||
personUri = null;
|
|
||||||
}
|
|
||||||
// If there's a personUri, then we're done. The firstName and lastName fields are
|
|
||||||
// disabled and so don't get submitted.
|
|
||||||
if (personUri != null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Literal firstName = literalsFromForm.get("firstName");
|
|
||||||
if( firstName != null && firstName.getLexicalForm() != null && "".equals(firstName.getLexicalForm()) )
|
|
||||||
firstName = null;
|
|
||||||
|
|
||||||
Literal lastName = literalsFromForm.get("lastName");
|
|
||||||
String lastNameValue = "";
|
|
||||||
if (lastName != null) {
|
|
||||||
lastNameValue = lastName.getLexicalForm();
|
|
||||||
if( "".equals(lastNameValue) ) {
|
|
||||||
lastName = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastName == null) {
|
|
||||||
errors.put("lastName", MISSING_LAST_NAME_ERROR);
|
|
||||||
// Don't reject space in the last name: de Vries, etc.
|
|
||||||
} else if (lastNameValue.contains(",")) {
|
|
||||||
errors.put("lastName", MALFORMED_LAST_NAME_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstName == null) {
|
|
||||||
errors.put("firstName", MISSING_FIRST_NAME_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors.size() != 0 ? errors : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue