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 {
|
implements EditConfigurationGenerator {
|
||||||
|
|
||||||
final static String vivoCore = "http://vivoweb.org/ontology/core#";
|
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 valueType = vivoCore + "DateTimeValue";
|
||||||
final static String dateTimeValue = vivoCore + "dateTime";
|
final static String dateTimeValue = vivoCore + "dateTime";
|
||||||
final static String dateTimePrecision = vivoCore + "dateTimePrecision";
|
final static String dateTimePrecision = vivoCore + "dateTimePrecision";
|
||||||
|
@ -41,23 +41,23 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
||||||
initPropertyParameters(vreq, session, conf);
|
initPropertyParameters(vreq, session, conf);
|
||||||
initObjectPropForm(conf, vreq);
|
initObjectPropForm(conf, vreq);
|
||||||
|
|
||||||
conf.setTemplate("dateTimeValueForm.ftl");
|
conf.setTemplate(this.getTemplate());
|
||||||
|
|
||||||
conf.setVarNameForSubject("subject");
|
conf.setVarNameForSubject("subject");
|
||||||
conf.setVarNameForPredicate("toDateTimeValue");
|
conf.setVarNameForPredicate("toDateTimeValue");
|
||||||
conf.setVarNameForObject("valueNode");
|
conf.setVarNameForObject("valueNode");
|
||||||
|
|
||||||
conf.setN3Optional(Arrays.asList(n3ForValue));
|
conf.setN3Optional(Arrays.asList(getN3ForValue()));
|
||||||
|
|
||||||
conf.addNewResource("valueNode", DEFAULT_NS_FOR_NEW_RESOURCE);
|
conf.addNewResource("valueNode", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||||
|
|
||||||
conf.addSparqlForExistingLiteral(
|
conf.addSparqlForExistingLiteral(
|
||||||
"dateTimeField-value", existingDateTimeValueQuery);
|
"dateTimeField-value", getExistingDateTimeValueQuery());
|
||||||
conf.addSparqlForExistingUris(
|
conf.addSparqlForExistingUris(
|
||||||
"dateTimeField-precision", existingPrecisionQuery);
|
"dateTimeField-precision", getExistingPrecisionQuery());
|
||||||
conf.addSparqlForExistingUris("valueNode", existingNodeQuery);
|
conf.addSparqlForExistingUris("valueNode", getExistingNodeQuery());
|
||||||
|
|
||||||
FieldVTwo dateTimeField = new FieldVTwo().setName("dateTimeField");
|
FieldVTwo dateTimeField = new FieldVTwo().setName(this.getDateTimeFieldName());
|
||||||
dateTimeField.setEditElement(new DateTimeWithPrecisionVTwo(dateTimeField,
|
dateTimeField.setEditElement(new DateTimeWithPrecisionVTwo(dateTimeField,
|
||||||
VitroVocabulary.Precision.SECOND.uri(),
|
VitroVocabulary.Precision.SECOND.uri(),
|
||||||
VitroVocabulary.Precision.NONE.uri()));
|
VitroVocabulary.Precision.NONE.uri()));
|
||||||
|
@ -71,30 +71,36 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
||||||
return 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 a <" + valueType + "> . \n" +
|
||||||
"?valueNode <" + dateTimeValue + "> ?dateTimeField-value . \n" +
|
"?valueNode <" + dateTimeValue + "> ?dateTimeField-value . \n" +
|
||||||
"?valueNode <" + dateTimePrecision + "> ?dateTimeField-precision .";
|
"?valueNode <" + dateTimePrecision + "> ?dateTimeField-precision .";
|
||||||
|
}
|
||||||
|
|
||||||
final static String existingDateTimeValueQuery =
|
protected String getExistingDateTimeValueQuery () {
|
||||||
"SELECT ?existingDateTimeValue WHERE { \n" +
|
return "SELECT ?existingDateTimeValue WHERE { \n" +
|
||||||
"?subject <" + toDateTimeValue + "> ?existingValueNode . \n" +
|
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingValueNode . \n" +
|
||||||
"?existingValueNode a <" + valueType + "> . \n" +
|
"?existingValueNode a <" + valueType + "> . \n" +
|
||||||
"?existingValueNode <" + dateTimeValue + "> ?existingDateTimeValue }";
|
"?existingValueNode <" + dateTimeValue + "> ?existingDateTimeValue }";
|
||||||
|
}
|
||||||
|
|
||||||
final static String existingPrecisionQuery =
|
protected String getExistingPrecisionQuery() {
|
||||||
"SELECT ?existingPrecision WHERE { \n" +
|
return "SELECT ?existingPrecision WHERE { \n" +
|
||||||
"?subject <" + toDateTimeValue + "> ?existingValueNode . \n" +
|
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingValueNode . \n" +
|
||||||
"?existingValueNode a <" + valueType + "> . \n" +
|
"?existingValueNode a <" + valueType + "> . \n" +
|
||||||
"?existingValueNode <" + dateTimePrecision + "> ?existingPrecision }";
|
"?existingValueNode <" + dateTimePrecision + "> ?existingPrecision }";
|
||||||
|
}
|
||||||
final static String existingNodeQuery =
|
protected String getExistingNodeQuery() {
|
||||||
"SELECT ?existingNode WHERE { \n" +
|
return "SELECT ?existingNode WHERE { \n" +
|
||||||
"?subject <" + toDateTimeValue + "> ?existingNode . \n" +
|
"?subject <" + this.getToDateTimeValuePredicate() + "> ?existingNode . \n" +
|
||||||
"?existingNode a <" + valueType + "> }";
|
"?existingNode a <" + valueType + "> }";
|
||||||
|
|
||||||
|
}
|
||||||
public static String getNodeVar() {
|
public static String getNodeVar() {
|
||||||
return "valueNode";
|
return "valueNode";
|
||||||
}
|
}
|
||||||
|
@ -103,6 +109,19 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator
|
||||||
return "?" + getNodeVar();
|
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
|
//Adding form specific data such as edit mode
|
||||||
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||||
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
|
||||||
|
|
Loading…
Add table
Reference in a new issue