Updates for freemarker conversion, specifically for validation
This commit is contained in:
parent
9c860f22bb
commit
1446b9c039
13 changed files with 95 additions and 38 deletions
|
@ -109,6 +109,11 @@ public class QueryUtils {
|
||||||
return queryString.replaceAll("\\?" + varName + "\\b", "<" + uri + ">");
|
return queryString.replaceAll("\\?" + varName + "\\b", "<" + uri + ">");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Replace one variable name with another**/
|
||||||
|
public static String replaceQueryVar(String queryString, String varName, String newVarName) {
|
||||||
|
return queryString.replaceAll("\\?" + varName + "\\b", "?" + newVarName);
|
||||||
|
}
|
||||||
|
|
||||||
public static ResultSet getQueryResults(String queryStr, VitroRequest vreq) {
|
public static ResultSet getQueryResults(String queryStr, VitroRequest vreq) {
|
||||||
|
|
||||||
Dataset dataset = vreq.getDataset();
|
Dataset dataset = vreq.getDataset();
|
||||||
|
|
|
@ -93,31 +93,40 @@ public class BasicValidationVTwo {
|
||||||
for( String validationType : validations){
|
for( String validationType : validations){
|
||||||
String value = null;
|
String value = null;
|
||||||
String validateMsg = null;
|
String validateMsg = null;
|
||||||
for(Literal literal: literals) {
|
//If no literals and this field was required, this is an error message
|
||||||
try{
|
//and can return
|
||||||
if( literal != null ){
|
if((literals == null || literals.size() == 0) && isRequiredField) {
|
||||||
value = literal.getString();
|
errors.put(name, REQUIRED_FIELD_EMPTY_MSG);
|
||||||
}
|
break;
|
||||||
}catch(Throwable th){
|
}
|
||||||
log.debug("could not convert literal to string" , th);
|
//Loop through literals if literals exist
|
||||||
|
if(literals != null) {
|
||||||
|
for(Literal literal: literals) {
|
||||||
|
try{
|
||||||
|
if( literal != null ){
|
||||||
|
value = literal.getString();
|
||||||
|
}
|
||||||
|
}catch(Throwable th){
|
||||||
|
log.debug("could not convert literal to string" , th);
|
||||||
|
}
|
||||||
|
// Empty field: if required, include only the empty field
|
||||||
|
// error message, not a format validation message. If non-required,
|
||||||
|
// don't do format validation, since that is both unnecessary and may
|
||||||
|
// incorrectly generate errors.
|
||||||
|
if (isEmpty(value)) {
|
||||||
|
if (isRequiredField) {
|
||||||
|
errors.put(name, REQUIRED_FIELD_EMPTY_MSG);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
String thisValidateMsg = validate(validationType,value);
|
||||||
|
if(validateMsg != null && thisValidateMsg != null) {
|
||||||
|
validateMsg += ", " + thisValidateMsg;
|
||||||
|
} else {
|
||||||
|
validateMsg = thisValidateMsg;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Empty field: if required, include only the empty field
|
|
||||||
// error message, not a format validation message. If non-required,
|
|
||||||
// don't do format validation, since that is both unnecessary and may
|
|
||||||
// incorrectly generate errors.
|
|
||||||
if (isEmpty(value)) {
|
|
||||||
if (isRequiredField) {
|
|
||||||
errors.put(name, REQUIRED_FIELD_EMPTY_MSG);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
String thisValidateMsg = validate(validationType,value);
|
|
||||||
if(validateMsg != null && thisValidateMsg != null) {
|
|
||||||
validateMsg += ", " + thisValidateMsg;
|
|
||||||
} else {
|
|
||||||
validateMsg = thisValidateMsg;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if( validateMsg != null) {
|
if( validateMsg != null) {
|
||||||
errors.put(name,validateMsg);
|
errors.put(name,validateMsg);
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo {
|
||||||
|
|
||||||
//Assuming form start year and form end year are working in conjunction with multiple values
|
//Assuming form start year and form end year are working in conjunction with multiple values
|
||||||
int index;
|
int index;
|
||||||
if (formStartYear != null && formEndYear != null) {
|
if (!literalListIsNull(formStartYear) && !literalListIsNull(formEndYear)) {
|
||||||
int numberStartYears = formStartYear.size();
|
int numberStartYears = formStartYear.size();
|
||||||
int numberEndYears = formEndYear.size();
|
int numberEndYears = formEndYear.size();
|
||||||
if(numberStartYears > 1 && numberEndYears > 1) {
|
if(numberStartYears > 1 && numberEndYears > 1) {
|
||||||
|
@ -81,7 +81,7 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo {
|
||||||
if(numberStartYears > 0 && numberEndYears > 0) {
|
if(numberStartYears > 0 && numberEndYears > 0) {
|
||||||
errors.putAll(checkDateLiterals(formStartYear.get(0), formEndYear.get(0), startPrecision, endPrecision));
|
errors.putAll(checkDateLiterals(formStartYear.get(0), formEndYear.get(0), startPrecision, endPrecision));
|
||||||
}
|
}
|
||||||
} else if (formStartYear != null && existingEndYear != null) {
|
} else if (!literalListIsNull(formStartYear) && !literalListIsNull(existingEndYear)) {
|
||||||
int numberStartYears = formStartYear.size();
|
int numberStartYears = formStartYear.size();
|
||||||
int numberEndYears = existingEndYear.size();
|
int numberEndYears = existingEndYear.size();
|
||||||
if(numberStartYears > 1 && numberEndYears > 1) {
|
if(numberStartYears > 1 && numberEndYears > 1) {
|
||||||
|
@ -92,7 +92,8 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo {
|
||||||
if(numberStartYears > 0 && numberEndYears > 0) {
|
if(numberStartYears > 0 && numberEndYears > 0) {
|
||||||
errors.putAll(checkDateLiterals(formStartYear.get(0), existingEndYear.get(0), startPrecision, endPrecision));
|
errors.putAll(checkDateLiterals(formStartYear.get(0), existingEndYear.get(0), startPrecision, endPrecision));
|
||||||
}
|
}
|
||||||
} else if (existingStartYear != null && formEndYear != null) {
|
} else if (!literalListIsNull(existingStartYear) && !literalListIsNull(formEndYear)) {
|
||||||
|
|
||||||
int numberStartYears = existingStartYear.size();
|
int numberStartYears = existingStartYear.size();
|
||||||
int numberEndYears = formEndYear.size();
|
int numberEndYears = formEndYear.size();
|
||||||
if(numberStartYears > 1 && numberEndYears > 1) {
|
if(numberStartYears > 1 && numberEndYears > 1) {
|
||||||
|
@ -103,7 +104,7 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo {
|
||||||
if(numberStartYears > 0 && numberEndYears > 0) {
|
if(numberStartYears > 0 && numberEndYears > 0) {
|
||||||
errors.putAll(checkDateLiterals(existingStartYear.get(0), formEndYear.get(0), startPrecision, endPrecision));
|
errors.putAll(checkDateLiterals(existingStartYear.get(0), formEndYear.get(0), startPrecision, endPrecision));
|
||||||
}
|
}
|
||||||
} else if (existingStartYear != null && existingEndYear != null) {
|
} else if (!literalListIsNull(existingStartYear) && !literalListIsNull(existingEndYear)) {
|
||||||
int numberStartYears = existingStartYear.size();
|
int numberStartYears = existingStartYear.size();
|
||||||
int numberEndYears = existingEndYear.size();
|
int numberEndYears = existingEndYear.size();
|
||||||
if(numberStartYears > 1 && numberEndYears > 1) {
|
if(numberStartYears > 1 && numberEndYears > 1) {
|
||||||
|
@ -213,4 +214,16 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo {
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MEthod that checks whether list of literals is null or contains only null
|
||||||
|
private boolean literalListIsNull(List<Literal> literalList) {
|
||||||
|
if(literalList == null)
|
||||||
|
return true;
|
||||||
|
boolean allNulls = true;
|
||||||
|
for(Literal l: literalList) {
|
||||||
|
if(l != null)
|
||||||
|
allNulls = false;
|
||||||
|
}
|
||||||
|
return allNulls;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,12 +116,20 @@ public class EditConfigurationUtils {
|
||||||
return dataProp;
|
return dataProp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get url without context - used for edit configuration object
|
||||||
|
public static String getFormUrlWithoutContext(VitroRequest vreq) {
|
||||||
|
return getEditUrlWithoutContext(vreq) + "?" + vreq.getQueryString();
|
||||||
|
}
|
||||||
public static String getFormUrl(VitroRequest vreq) {
|
public static String getFormUrl(VitroRequest vreq) {
|
||||||
return getEditUrl(vreq) + "?" + vreq.getQueryString();
|
return getEditUrl(vreq) + "?" + vreq.getQueryString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getEditUrl(VitroRequest vreq) {
|
public static String getEditUrl(VitroRequest vreq) {
|
||||||
return vreq.getContextPath() + "/editRequestDispatch";
|
return vreq.getContextPath() + getEditUrlWithoutContext(vreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getEditUrlWithoutContext(VitroRequest vreq) {
|
||||||
|
return "/editRequestDispatch";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCancelUrlBase(VitroRequest vreq) {
|
public static String getCancelUrlBase(VitroRequest vreq) {
|
||||||
|
|
|
@ -131,8 +131,14 @@ public class MultiValueEditSubmission {
|
||||||
|
|
||||||
processEditElementFields(editConfig,queryParameters);
|
processEditElementFields(editConfig,queryParameters);
|
||||||
//Incorporating basic validation
|
//Incorporating basic validation
|
||||||
|
//Validate URIS
|
||||||
this.basicValidation = new BasicValidationVTwo(editConfig, this);
|
this.basicValidation = new BasicValidationVTwo(editConfig, this);
|
||||||
Map<String,String> errors = basicValidation.validateUris( urisFromForm );
|
Map<String,String> errors = basicValidation.validateUris( urisFromForm );
|
||||||
|
//Validate literals
|
||||||
|
errors = basicValidation.validateLiterals( literalsFromForm );
|
||||||
|
if( errors != null ) {
|
||||||
|
validationErrors.putAll( errors);
|
||||||
|
}
|
||||||
|
|
||||||
if(editConfig.getValidators() != null ){
|
if(editConfig.getValidators() != null ){
|
||||||
for( N3ValidatorVTwo validator : editConfig.getValidators()){
|
for( N3ValidatorVTwo validator : editConfig.getValidators()){
|
||||||
|
|
|
@ -24,7 +24,7 @@ public abstract class BaseEditConfigurationGenerator implements EditConfiguratio
|
||||||
String editKey = EditConfigurationUtils.getEditKey(vreq);
|
String editKey = EditConfigurationUtils.getEditKey(vreq);
|
||||||
editConf.setEditKey(editKey);
|
editConf.setEditKey(editKey);
|
||||||
|
|
||||||
String formUrl = EditConfigurationUtils.getFormUrl(vreq);
|
String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq);
|
||||||
editConf.setFormUrl(formUrl);
|
editConf.setFormUrl(formUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
|
||||||
//Initialize setup: process parameters
|
//Initialize setup: process parameters
|
||||||
//Doesn't look like we need to set up separate processing for data property form
|
//Doesn't look like we need to set up separate processing for data property form
|
||||||
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
String formUrl = EditConfigurationUtils.getFormUrl(vreq);
|
String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq);
|
||||||
|
|
||||||
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
||||||
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
|
|
||||||
//Initialize setup: process parameters
|
//Initialize setup: process parameters
|
||||||
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
String formUrl = EditConfigurationUtils.getFormUrl(vreq);
|
String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq);
|
||||||
|
|
||||||
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
||||||
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class NewIndividualFormGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
//Initialize setup: process parameters
|
//Initialize setup: process parameters
|
||||||
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
String formUrl = EditConfigurationUtils.getFormUrl(vreq);
|
String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq);
|
||||||
|
|
||||||
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
||||||
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
||||||
//Initialize setup: process parameters
|
//Initialize setup: process parameters
|
||||||
//As this is a data property, don't require any additional processing for object properties
|
//As this is a data property, don't require any additional processing for object properties
|
||||||
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
String formUrl = EditConfigurationUtils.getFormUrl(vreq);
|
String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq);
|
||||||
|
|
||||||
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
subjectUri = EditConfigurationUtils.getSubjectUri(vreq);
|
||||||
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
|
|
|
@ -163,9 +163,13 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{
|
||||||
if(errors != null && !errors.isEmpty()){
|
if(errors != null && !errors.isEmpty()){
|
||||||
String form = editConfiguration.getFormUrl();
|
String form = editConfiguration.getFormUrl();
|
||||||
vreq.setAttribute("formUrl", form);
|
vreq.setAttribute("formUrl", form);
|
||||||
vreq.setAttribute("view", vreq.getParameter("view"));
|
vreq.setAttribute("view", vreq.getParameter("view"));
|
||||||
|
//Need to ensure that edit key is set so that the correct
|
||||||
return new RedirectResponseValues(editConfiguration.getFormUrl());
|
//edit configuration and edit submission are retrieved
|
||||||
|
//This can also be set as a parameter instead
|
||||||
|
String formUrl = editConfiguration.getFormUrl();
|
||||||
|
formUrl += "&editKey=" + editConfiguration.getEditKey();
|
||||||
|
return new RedirectResponseValues(formUrl);
|
||||||
}
|
}
|
||||||
return null; //no errors
|
return null; //no errors
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,20 @@ public class EditSubmissionTemplateModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Literal> getLiteralsFromForm() {
|
public Map<String, Literal> getLiteralsFromForm() {
|
||||||
|
if(editSub == null)
|
||||||
|
return null;
|
||||||
return editSub.getLiteralsFromForm();
|
return editSub.getLiteralsFromForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getValidationErrors() {
|
public Map<String, String> getValidationErrors() {
|
||||||
|
if(editSub == null)
|
||||||
|
return null;
|
||||||
return editSub.getValidationErrors();
|
return editSub.getValidationErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getUrisFromForm() {
|
public Map<String, String> getUrisFromForm() {
|
||||||
|
if(editSub == null)
|
||||||
|
return null;
|
||||||
return editSub.getUrisFromForm();
|
return editSub.getUrisFromForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,15 +17,21 @@ public class MultiValueEditSubmissionTemplateModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<Literal>> getLiteralsFromForm() {
|
public Map<String, List<Literal>> getLiteralsFromForm() {
|
||||||
|
if(editSub == null)
|
||||||
|
return null;
|
||||||
return editSub.getLiteralsFromForm();
|
return editSub.getLiteralsFromForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, String> getValidationErrors() {
|
public Map<String, String> getValidationErrors() {
|
||||||
|
if(editSub == null)
|
||||||
|
return null;
|
||||||
return editSub.getValidationErrors();
|
return editSub.getValidationErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<String>> getUrisFromForm() {
|
public Map<String, List<String>> getUrisFromForm() {
|
||||||
|
if(editSub == null)
|
||||||
|
return null;
|
||||||
return editSub.getUrisFromForm();
|
return editSub.getUrisFromForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue