diff --git a/productMods/templates/freemarker/edit/forms/addGrantRoleToPerson.ftl b/productMods/templates/freemarker/edit/forms/addGrantRoleToPerson.ftl index 201debd4..5f39ce47 100644 --- a/productMods/templates/freemarker/edit/forms/addGrantRoleToPerson.ftl +++ b/productMods/templates/freemarker/edit/forms/addGrantRoleToPerson.ftl @@ -1,7 +1,6 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- Template for adding a grant role, such as principal investigator, to a foaf:Persons --> -<#import "lib-vivo-form.ftl" as lvf> <#--Retrieve certain edit configuration information--> <#assign editMode = editConfiguration.pageData.editMode /> <#assign literalValues = editConfiguration.existingLiteralValues /> @@ -40,10 +39,8 @@ <#--Get selected activity type value if it exists, this is alternative to below--> -<#assign grantLabel = ""/> -<#if literalValues?keys?seq_contains("grantLabel") && (literalValues.grantLabel?size > 0)> - <#assign grantLabel = literalValues.grantLabel[0] /> -#if> +<#assign grantLabel = lvf.getFormFieldValue(editSubmission, editConfiguration, "grantLabel")/> + <#--Get existing grant label value--> <#assign existingGrantLabel = "" /> diff --git a/productMods/templates/freemarker/edit/forms/addRoleToPersonTwoStage.ftl b/productMods/templates/freemarker/edit/forms/addRoleToPersonTwoStage.ftl index 65b7bf9a..3dfe661a 100644 --- a/productMods/templates/freemarker/edit/forms/addRoleToPersonTwoStage.ftl +++ b/productMods/templates/freemarker/edit/forms/addRoleToPersonTwoStage.ftl @@ -1,4 +1,5 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> +<#import "lib-vivo-form.ftl" as lvf> <#--Retrieve certain edit configuration information--> <#assign editMode = editConfiguration.pageData.editMode /> @@ -6,6 +7,10 @@ <#assign uriValues = editConfiguration.existingUriValues /> <#assign htmlForElements = editConfiguration.pageData.htmlForElements /> <#assign showRoleLabelField = editConfiguration.pageData.showRoleLabelField /> +<#--If edit submission exists, then retrieve validation errors if they exist--> +<#if editSubmission?has_content && editSubmission.submissionExists = true && editSubmission.validationErrors?has_content> + <#assign submissionErrors = editSubmission.validationErrors/> +#if> <#--Freemarker variables with default values that can be overridden by specific forms--> @@ -44,22 +49,15 @@ <#--Get selected activity type value if it exists, this is alternative to below--> -<#assign activityTypeValue = ""/> -<#if uriValues?keys?seq_contains("roleActivityType") && (uriValues.roleActivityType?size > 0)> - <#assign activityTypeValue = uriValues.roleActivityType[0] /> -#if> +<#assign activityTypeValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "roleActivityType")/> <#--Get activity label value--> -<#assign activityLabelValue = "" /> -<#if literalValues?keys?seq_contains("activityLabel") && (literalValues.activityLabel?size > 0)> - <#assign activityLabelValue = literalValues.activityLabel[0] /> -#if> +<#assign activityLabelValue = lvf.getFormFieldValue(editSubmission, editConfiguration, "activityLabel") /> + <#--Get role label--> -<#assign roleLabel = "" /> -<#if literalValues?keys?seq_contains("roleLabel") && (literalValues.roleLabel?size > 0) > - <#assign roleLabel = literalValues.roleLabel[0] /> -#if> +<#assign roleLabel = lvf.getFormFieldValue(editSubmission, editConfiguration, "roleLabel") /> + <#assign requiredHint = " *" /> <#assign yearHint = "(YYYY)" /> @@ -67,18 +65,26 @@
${errorMessage}
+
+ <#--below shows examples of both printing out all error messages and checking the error message for a specific field-->
+ <#list submissionErrors?keys as errorFieldName>
+ ${errorFieldName}: ${submissionErrors[errorFieldName]}
+
+ #list>
+ <#--Checking if role field is empty-->
+ <#if lvf.submissionErrorExists(editSubmission, "roleLabel")>
+ Specify a role for this activity.
+ #if>
+ <#if lvf.submissionErrorExists(editSubmission, "activityLabel")>
+ Enter a name for the activity.
+ #if>
+
+
diff --git a/productMods/templates/freemarker/lib/lib-vivo-form.ftl b/productMods/templates/freemarker/lib/lib-vivo-form.ftl index 8ab155bc..c7602750 100644 --- a/productMods/templates/freemarker/lib/lib-vivo-form.ftl +++ b/productMods/templates/freemarker/lib/lib-vivo-form.ftl @@ -55,7 +55,7 @@ return - returns empty string if no value found--> #function> -<#--Given edit submission object find values-> +<#--Given edit submission object find values--> <#function getEditSubmissionLiteralValue submission varName> <#local literalValues = submission.literalsFromForm > <#if (literalValues?keys?seq_contains(varName)) && (literalValues[varName]?size > 0)> @@ -79,7 +79,7 @@ return - returns empty string if no value found--> <#local returnValue = getEditSubmissionUriValue(submission, varName) /> <#if (returnValue?length = 0)> <#local returnValue = getEditSubmissionLiteralValue(submission, varName) /> - #if> + #if> <#return returnValue> #function> @@ -93,3 +93,13 @@ return - returns empty string if no value found--> #if> <#return returnValue> #function> + +<#--Check if submission error exists for a field name--> +<#function submissionErrorExists editSubmission fieldName> + <#if editSubmission?has_content && editSubmission.submissionExists = true && editSubmission.validationErrors?has_content> + <#if editSubmission.validationErrors?keys?seq_contains(fieldName)> + <#return true> + #if> + #if> + <#return false> +#function> diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddGrantRoleToPersonGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddGrantRoleToPersonGenerator.java index 47e6dd1b..b5199a23 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddGrantRoleToPersonGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddGrantRoleToPersonGenerator.java @@ -129,7 +129,7 @@ public class AddGrantRoleToPersonGenerator implements EditConfigurationGenerator //There will be specialized parameters as well, we may include them here or in a //separate method private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) { - String formUrl = EditConfigurationUtils.getFormUrl(vreq); + String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq); subjectUri = EditConfigurationUtils.getSubjectUri(vreq); predicateUri = EditConfigurationUtils.getPredicateUri(vreq); diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddRoleToPersonTwoStageGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddRoleToPersonTwoStageGenerator.java index 2888c573..ba9334ae 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddRoleToPersonTwoStageGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddRoleToPersonTwoStageGenerator.java @@ -172,7 +172,7 @@ public abstract class AddRoleToPersonTwoStageGenerator extends BaseEditConfigura } private void initProcessParameters(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) { - editConfiguration.setFormUrl(EditConfigurationUtils.getFormUrl(vreq)); + editConfiguration.setFormUrl(EditConfigurationUtils.getFormUrlWithoutContext(vreq)); editConfiguration.setEntityToReturnTo(EditConfigurationUtils.getSubjectUri(vreq)); } @@ -438,7 +438,7 @@ public abstract class AddRoleToPersonTwoStageGenerator extends BaseEditConfigura //Replacement should only happen when we have an actual predicate String replaceRoleToActivityPredicate = getRoleToActivityPredicate(vreq); - activityTypeQuery = QueryUtils.subUriForQueryVar(activityTypeQuery, "predicate", replaceRoleToActivityPredicate); + activityTypeQuery = QueryUtils.replaceQueryVar(activityTypeQuery, "predicate", getRoleToActivityPlaceholderName()); log.debug("Activity type query: " + activityTypeQuery); return activityTypeQuery; @@ -886,9 +886,14 @@ public abstract class AddRoleToPersonTwoStageGenerator extends BaseEditConfigura } private String getRoleToActivityPlaceholder() { - return "?roleToActivityPredicate"; + return "?" + getRoleToActivityPlaceholderName(); } + private String getRoleToActivityPlaceholderName() { + return "roleToActivityPredicate"; + } + + private String getActivityToRolePlaceholder() { return "?activityToRolePredicate"; } diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java index 31eab031..dccde22f 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java @@ -61,7 +61,7 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i //This combines the first and last name into the rdfs:label config.addModelChangePreprocessor(new FoafNameToRdfsLabelPreprocessor()); - String formUrl = EditConfigurationUtils.getFormUrl(vreq); + String formUrl = EditConfigurationUtils.getFormUrlWithoutContext(vreq); config.setFormUrl(formUrl); //Note, the spaces are important - they were added by ProcessRdfFormController earlier diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/PersonHasEducationalTraining.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/PersonHasEducationalTraining.java index 1593f3cd..b9a88bc5 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/PersonHasEducationalTraining.java +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/PersonHasEducationalTraining.java @@ -10,6 +10,7 @@ import com.hp.hpl.jena.vocabulary.XSD; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo; @@ -102,6 +103,8 @@ public class PersonHasEducationalTraining extends VivoBaseGenerator implements conf.addSparqlForExistingLiteral("dept", deptQuery); conf.addSparqlForExistingLiteral("info", infoQuery); conf.addSparqlForExistingLiteral("startField-value", existingStartDateQuery); + conf.addSparqlForExistingLiteral("endField-value", existingEndDateQuery); + conf.addSparqlForExistingUris("org",orgQuery); conf.addSparqlForExistingUris("orgType",orgTypeQuery); @@ -148,20 +151,23 @@ public class PersonHasEducationalTraining extends VivoBaseGenerator implements setName("info"). setRangeDatatypeUri( XSD.xstring.toString() )); - conf.addField(new FieldVTwo(). - setName("startField"). + FieldVTwo startField = new FieldVTwo(). + setName("startField"); + conf.addField(startField. setEditElement( - new DateTimeWithPrecisionVTwo(null, + new DateTimeWithPrecisionVTwo(startField, VitroVocabulary.Precision.YEAR.uri(), VitroVocabulary.Precision.NONE.uri()))); - - conf.addField( new FieldVTwo(). - setName("endField"). + + FieldVTwo endField = new FieldVTwo(). + setName("endField"); + conf.addField( endField. setEditElement( - new DateTimeWithPrecisionVTwo(null, + new DateTimeWithPrecisionVTwo(endField, VitroVocabulary.Precision.YEAR.uri(), VitroVocabulary.Precision.NONE.uri()))); - + //Add validator + conf.addValidator(new DateTimeIntervalValidationVTwo("startField","endField")); return conf; }