Updates to DateTimeValueGenerator to allow it to be extended into subclasses for other predicates
This commit is contained in:
parent
11a83c4c1c
commit
eea4681c60
1 changed files with 43 additions and 24 deletions
|
@ -27,7 +27,7 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
implements EditConfigurationGenerator {
|
||||
|
||||
final static String vivoCore = "http://vivoweb.org/ontology/core#";
|
||||
final static String toDateTimeValue = vivoCore + "dateTimeValue";
|
||||
final String toDateTimeValue = vivoCore + "dateTimeValue";
|
||||
final static String valueType = vivoCore + "DateTimeValue";
|
||||
final static String dateTimeValue = vivoCore + "dateTime";
|
||||
final static String dateTimePrecision = vivoCore + "dateTimePrecision";
|
||||
|
@ -41,23 +41,23 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
initPropertyParameters(vreq, session, conf);
|
||||
initObjectPropForm(conf, vreq);
|
||||
|
||||
conf.setTemplate("dateTimeValueForm.ftl");
|
||||
conf.setTemplate(this.getTemplate());
|
||||
|
||||
conf.setVarNameForSubject("subject");
|
||||
conf.setVarNameForPredicate("toDateTimeValue");
|
||||
conf.setVarNameForObject("valueNode");
|
||||
|
||||
conf.setN3Optional(Arrays.asList(n3ForValue));
|
||||
conf.setN3Optional(Arrays.asList(getN3ForValue()));
|
||||
|
||||
conf.addNewResource("valueNode", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||
|
||||
conf.addSparqlForExistingLiteral(
|
||||
"dateTimeField-value", existingDateTimeValueQuery);
|
||||
"dateTimeField-value", getExistingDateTimeValueQuery());
|
||||
conf.addSparqlForExistingUris(
|
||||
"dateTimeField-precision", existingPrecisionQuery);
|
||||
conf.addSparqlForExistingUris("valueNode", existingNodeQuery);
|
||||
"dateTimeField-precision", getExistingPrecisionQuery());
|
||||
conf.addSparqlForExistingUris("valueNode", getExistingNodeQuery());
|
||||
|
||||
FieldVTwo dateTimeField = new FieldVTwo().setName("dateTimeField");
|
||||
FieldVTwo dateTimeField = new FieldVTwo().setName(this.getDateTimeFieldName());
|
||||
dateTimeField.setEditElement(new DateTimeWithPrecisionVTwo(dateTimeField,
|
||||
VitroVocabulary.Precision.SECOND.uri(),
|
||||
VitroVocabulary.Precision.NONE.uri()));
|
||||
|
@ -67,34 +67,40 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
//Adding additional data, specifically edit mode
|
||||
addFormSpecificData(conf, vreq);
|
||||
//prepare
|
||||
prepare(vreq, conf);
|
||||
return conf;
|
||||
}
|
||||
prepare(vreq, conf);
|
||||
return conf;
|
||||
}
|
||||
|
||||
final static String n3ForValue =
|
||||
"?subject <" + toDateTimeValue + "> ?valueNode . \n" +
|
||||
|
||||
//Writing these as methods instead of static strings allows the method getToDateTimeValuePredicate
|
||||
//to be called after the class has been initialized - this is important for subclasses of this generator
|
||||
//that rely on vreq for predicate
|
||||
protected String getN3ForValue() {
|
||||
return "?subject <" + this.getToDateTimeValuePredicate() + "> ?valueNode . \n" +
|
||||
"?valueNode a <" + valueType + "> . \n" +
|
||||
"?valueNode <" + dateTimeValue + "> ?dateTimeField-value . \n" +
|
||||
"?valueNode <" + dateTimePrecision + "> ?dateTimeField-precision .";
|
||||
"?valueNode <" + dateTimePrecision + "> ?dateTimeField-precision .";
|
||||
}
|
||||
|
||||
final static String existingDateTimeValueQuery =
|
||||
"SELECT ?existingDateTimeValue WHERE { \n" +
|
||||
"?subject <" + toDateTimeValue + "> ?existingValueNode . \n" +
|
||||
protected String getExistingDateTimeValueQuery () {
|
||||
return "SELECT ?existingDateTimeValue WHERE { \n" +
|
||||
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingValueNode . \n" +
|
||||
"?existingValueNode a <" + valueType + "> . \n" +
|
||||
"?existingValueNode <" + dateTimeValue + "> ?existingDateTimeValue }";
|
||||
}
|
||||
|
||||
final static String existingPrecisionQuery =
|
||||
"SELECT ?existingPrecision WHERE { \n" +
|
||||
"?subject <" + toDateTimeValue + "> ?existingValueNode . \n" +
|
||||
protected String getExistingPrecisionQuery() {
|
||||
return "SELECT ?existingPrecision WHERE { \n" +
|
||||
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingValueNode . \n" +
|
||||
"?existingValueNode a <" + valueType + "> . \n" +
|
||||
"?existingValueNode <" + dateTimePrecision + "> ?existingPrecision }";
|
||||
|
||||
final static String existingNodeQuery =
|
||||
"SELECT ?existingNode WHERE { \n" +
|
||||
"?subject <" + toDateTimeValue + "> ?existingNode . \n" +
|
||||
}
|
||||
protected String getExistingNodeQuery() {
|
||||
return "SELECT ?existingNode WHERE { \n" +
|
||||
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingNode . \n" +
|
||||
"?existingNode a <" + valueType + "> }";
|
||||
|
||||
|
||||
}
|
||||
public static String getNodeVar() {
|
||||
return "valueNode";
|
||||
}
|
||||
|
@ -103,6 +109,19 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
|||
return "?" + getNodeVar();
|
||||
}
|
||||
|
||||
//isolating the predicate in this fashion allows this class to be subclassed for other date time value
|
||||
//properties
|
||||
protected String getToDateTimeValuePredicate() {
|
||||
return this.toDateTimeValue;
|
||||
}
|
||||
|
||||
protected String getDateTimeFieldName() {
|
||||
return "dateTimeField";
|
||||
}
|
||||
|
||||
protected String getTemplate() {
|
||||
return "dateTimeValueForm.ftl";
|
||||
}
|
||||
//Adding form specific data such as edit mode
|
||||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||
|
|
Loading…
Add table
Reference in a new issue