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);
|
||||
|
||||
static String literalVar = "literal";
|
||||
static String literalPlaceholder = "?"+literalVar;
|
||||
static final String literalVar = "literal";
|
||||
static final String literalPlaceholder = "?"+literalVar;
|
||||
static final String dataPropN3 = "?subject ?predicate " + literalPlaceholder + " . " ;
|
||||
|
||||
@Override
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||
String command = vreq.getParameter("cmd");
|
||||
|
||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||
String subjectUri = vreq.getParameter("subjectUri");
|
||||
Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri);
|
||||
if( subject == null )
|
||||
|
@ -58,32 +57,42 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
|||
rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, dataproperty);
|
||||
}
|
||||
|
||||
Integer dataHash = EditConfigurationUtils.getDataHash(vreq);
|
||||
boolean update = ( dataHash != null );
|
||||
|
||||
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
||||
|
||||
editConfiguration.setTemplate("defaultDataPropertyForm.ftl");
|
||||
initBasics(editConfiguration, vreq);
|
||||
initPropertyParameters(vreq, session, editConfiguration);
|
||||
|
||||
editConfiguration.setN3Required(Arrays.asList( "?subject ?predicate " + literalPlaceholder + " . "));
|
||||
|
||||
editConfiguration.setDatapropKey( EditConfigurationUtils.getDataHash(vreq) );
|
||||
editConfiguration.setTemplate("defaultDataPropertyForm.ftl");
|
||||
|
||||
editConfiguration.setDatapropKey( dataHash );
|
||||
|
||||
editConfiguration.setVarNameForSubject("subject");
|
||||
editConfiguration.setSubjectUri(subjectUri);
|
||||
editConfiguration.setEntityToReturnTo( subjectUri );
|
||||
|
||||
editConfiguration.setVarNameForPredicate("predicate");
|
||||
editConfiguration.setPredicateUri(predicateUri);
|
||||
|
||||
editConfiguration.setVarNameForSubject("subject");
|
||||
editConfiguration.setVarNameForPredicate("predicate");
|
||||
editConfiguration.setVarNameForObject( literalVar );
|
||||
|
||||
editConfiguration.setLiteralsOnForm( Arrays.asList( literalVar ));
|
||||
|
||||
editConfiguration.addField( new FieldVTwo()
|
||||
.setName( literalVar )
|
||||
.setPredicateUri(predicateUri)
|
||||
.setRangeDatatypeUri(rangeDatatypeUri));
|
||||
|
||||
//deal with empty field
|
||||
editConfiguration.addModelChangePreprocessor( new DefaultDataPropEmptyField() );
|
||||
FieldVTwo literalField = new FieldVTwo()
|
||||
.setName( literalVar )
|
||||
.setPredicateUri(predicateUri)
|
||||
.setRangeDatatypeUri(rangeDatatypeUri);
|
||||
|
||||
editConfiguration.addField( literalField );
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
@ -124,7 +133,6 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
|||
|
||||
}
|
||||
|
||||
|
||||
private static void dataTypeDebug(DataPropertyStatement dps,
|
||||
DataProperty dataproperty) {
|
||||
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
|
||||
// textarea and saving it to invoke a delete. see Issue VITRO-432
|
||||
if (configuration.getFields().size() == 1) {
|
||||
String onlyField = configuration.getFields().keySet().iterator()
|
||||
.next();
|
||||
String onlyField = configuration.getFields().keySet().iterator().next();
|
||||
List<Literal> value = submission.getLiteralsFromForm().get(onlyField);
|
||||
if( value == null || value.size() == 0){
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue