Setting up DefaultDataPropertyForm to handle empty strings NIHVIVO-3353 VITRO-432
This commit is contained in:
parent
5f2db5f824
commit
a990f44ffc
3 changed files with 53 additions and 26 deletions
|
@ -29,13 +29,12 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DefaultDataPropertyFormGenerator.class);
|
private static Log log = LogFactory.getLog(DefaultDataPropertyFormGenerator.class);
|
||||||
|
|
||||||
static String literalVar = "literal";
|
static final String literalVar = "literal";
|
||||||
static String literalPlaceholder = "?"+literalVar;
|
static final String literalPlaceholder = "?"+literalVar;
|
||||||
|
static final String dataPropN3 = "?subject ?predicate " + literalPlaceholder + " . " ;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||||
String command = vreq.getParameter("cmd");
|
|
||||||
|
|
||||||
String subjectUri = vreq.getParameter("subjectUri");
|
String subjectUri = vreq.getParameter("subjectUri");
|
||||||
Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri);
|
Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri);
|
||||||
if( subject == null )
|
if( subject == null )
|
||||||
|
@ -58,32 +57,42 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
||||||
rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, dataproperty);
|
rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, dataproperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Integer dataHash = EditConfigurationUtils.getDataHash(vreq);
|
||||||
|
boolean update = ( dataHash != null );
|
||||||
|
|
||||||
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
||||||
|
|
||||||
editConfiguration.setTemplate("defaultDataPropertyForm.ftl");
|
initBasics(editConfiguration, vreq);
|
||||||
|
initPropertyParameters(vreq, session, editConfiguration);
|
||||||
|
|
||||||
editConfiguration.setN3Required(Arrays.asList( "?subject ?predicate " + literalPlaceholder + " . "));
|
editConfiguration.setTemplate("defaultDataPropertyForm.ftl");
|
||||||
|
|
||||||
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
editConfiguration.setDatapropKey( dataHash );
|
||||||
|
|
||||||
editConfiguration.setVarNameForSubject("subject");
|
editConfiguration.setVarNameForSubject("subject");
|
||||||
editConfiguration.setSubjectUri(subjectUri);
|
editConfiguration.setVarNameForPredicate("predicate");
|
||||||
editConfiguration.setEntityToReturnTo( subjectUri );
|
|
||||||
|
|
||||||
editConfiguration.setVarNameForPredicate("predicate");
|
|
||||||
editConfiguration.setPredicateUri(predicateUri);
|
|
||||||
|
|
||||||
editConfiguration.setVarNameForObject( literalVar );
|
editConfiguration.setVarNameForObject( literalVar );
|
||||||
|
|
||||||
editConfiguration.setLiteralsOnForm( Arrays.asList( literalVar ));
|
editConfiguration.setLiteralsOnForm( Arrays.asList( literalVar ));
|
||||||
|
|
||||||
editConfiguration.addField( new FieldVTwo()
|
FieldVTwo literalField = new FieldVTwo()
|
||||||
.setName( literalVar )
|
.setName( literalVar )
|
||||||
.setPredicateUri(predicateUri)
|
.setPredicateUri(predicateUri)
|
||||||
.setRangeDatatypeUri(rangeDatatypeUri));
|
.setRangeDatatypeUri(rangeDatatypeUri);
|
||||||
|
|
||||||
//deal with empty field
|
editConfiguration.addField( literalField );
|
||||||
editConfiguration.addModelChangePreprocessor( new DefaultDataPropEmptyField() );
|
|
||||||
|
// An empty field on an update gets special treatment
|
||||||
|
if( update ) {
|
||||||
|
// on update, allow an empty field and deal with it in DefaultDataPropEmptyField
|
||||||
|
// see comments in DefaultDataPropEmptyField and VITRO-432
|
||||||
|
editConfiguration.addModelChangePreprocessor( new DefaultDataPropEmptyField() );
|
||||||
|
editConfiguration.setN3Optional(Arrays.asList( dataPropN3 ));
|
||||||
|
}else{
|
||||||
|
//on new, don't allow an empty field
|
||||||
|
literalField.setValidators(list( "nonempty" ));
|
||||||
|
editConfiguration.setN3Required(Arrays.asList( dataPropN3 ));
|
||||||
|
}
|
||||||
|
|
||||||
return editConfiguration;
|
return editConfiguration;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +133,6 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void dataTypeDebug(DataPropertyStatement dps,
|
private static void dataTypeDebug(DataPropertyStatement dps,
|
||||||
DataProperty dataproperty) {
|
DataProperty dataproperty) {
|
||||||
if( dps == null )
|
if( dps == null )
|
||||||
|
|
|
@ -49,8 +49,7 @@ public class DefaultDataPropEmptyField implements ModelChangePreprocessor{
|
||||||
// Our editors have gotten into the habit of clearing the text from the
|
// Our editors have gotten into the habit of clearing the text from the
|
||||||
// textarea and saving it to invoke a delete. see Issue VITRO-432
|
// textarea and saving it to invoke a delete. see Issue VITRO-432
|
||||||
if (configuration.getFields().size() == 1) {
|
if (configuration.getFields().size() == 1) {
|
||||||
String onlyField = configuration.getFields().keySet().iterator()
|
String onlyField = configuration.getFields().keySet().iterator().next();
|
||||||
.next();
|
|
||||||
List<Literal> value = submission.getLiteralsFromForm().get(onlyField);
|
List<Literal> value = submission.getLiteralsFromForm().get(onlyField);
|
||||||
if( value == null || value.size() == 0){
|
if( value == null || value.size() == 0){
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,7 +1,27 @@
|
||||||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#--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>
|
||||||
|
|
||||||
|
|
||||||
<h2>${editConfiguration.formTitle}</h2>
|
<h2>${editConfiguration.formTitle}</h2>
|
||||||
|
|
||||||
|
<#--Display error messages if any-->
|
||||||
|
<#if submissionErrors?has_content>
|
||||||
|
<section id="error-alert" role="alert">
|
||||||
|
<img src="${urls.images}/iconAlert.png" width="24" height="24" alert="Error alert icon" />
|
||||||
|
<p>
|
||||||
|
|
||||||
|
<#list submissionErrors?keys as errorFieldName>
|
||||||
|
${submissionErrors[errorFieldName]}
|
||||||
|
</#list>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</#if>
|
||||||
|
|
||||||
<#assign literalValues = "${editConfiguration.dataLiteralValuesAsString}" />
|
<#assign literalValues = "${editConfiguration.dataLiteralValuesAsString}" />
|
||||||
|
|
||||||
<form class="editForm" action = "${submitUrl}" method="post">
|
<form class="editForm" action = "${submitUrl}" method="post">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue