From 8a490c6125e998a6e8c637fb502104577de81ec7 Mon Sep 17 00:00:00 2001 From: hudajkhan Date: Tue, 10 Dec 2013 15:41:45 -0500 Subject: [PATCH] vivo 638 fixing query for existing interval value to utilize variable for object so editing works correctly --- .../VTwo/DateTimeWithPrecisionVTwo.java | 76 +++++++++++-------- .../DateTimeIntervalFormGenerator.java | 19 ++--- .../DateTimeValueFormGenerator.java | 22 ++---- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeWithPrecisionVTwo.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeWithPrecisionVTwo.java index 2c3fa5587..d4dbc8669 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeWithPrecisionVTwo.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/VTwo/DateTimeWithPrecisionVTwo.java @@ -167,40 +167,50 @@ public class DateTimeWithPrecisionVTwo extends BaseEditElementVTwo { DateTime value = getTimeValue(editConfig,editSub); /* This is the case where there is a precision so there should be a datetime */ - if( value == null ) - log.debug("Field " + getFieldName() + " has precision " + precisionUri - + " but the date time is " + value); - - /* only put the values in the map for ones which are significant based on the precision */ - if( existingPrec.ordinal() >= VitroVocabulary.Precision.SECOND.ordinal() ) - map.put("second", Integer.toString(value.getSecondOfMinute() )) ; - else - map.put("second", ""); - - if( existingPrec.ordinal() >= VitroVocabulary.Precision.MINUTE.ordinal() ) - map.put("minute", Integer.toString(value.getMinuteOfHour()) ); - else - map.put("minute", ""); - - if( existingPrec.ordinal() >= VitroVocabulary.Precision.HOUR.ordinal() ) - map.put("hour", Integer.toString(value.getHourOfDay()) ); - else - map.put("hour", ""); - - if( existingPrec.ordinal() >= VitroVocabulary.Precision.DAY.ordinal() ) - map.put("day", Integer.toString(value.getDayOfMonth()) ); - else - map.put("day", ""); - - if( existingPrec.ordinal() >= VitroVocabulary.Precision.MONTH.ordinal() ) - map.put("month", Integer.toString(value.getMonthOfYear())); - else - map.put("month", ""); - - if( existingPrec.ordinal() >= VitroVocabulary.Precision.YEAR.ordinal() ) - map.put("year", Integer.toString(value.getYear())); - else + if( value == null ) { + //If there is no value, then this is an error condition + log.error("Field " + getFieldName() + " has precision " + precisionUri + + " but the date time value is null "); map.put("year", ""); + map.put("month", ""); + map.put("day", ""); + map.put("hour", ""); + map.put("minute", ""); + map.put("second", "") ; + + } else { + + /* only put the values in the map for ones which are significant based on the precision */ + if( existingPrec.ordinal() >= VitroVocabulary.Precision.SECOND.ordinal() ) + map.put("second", Integer.toString(value.getSecondOfMinute() )) ; + else + map.put("second", ""); + + if( existingPrec.ordinal() >= VitroVocabulary.Precision.MINUTE.ordinal() ) + map.put("minute", Integer.toString(value.getMinuteOfHour()) ); + else + map.put("minute", ""); + + if( existingPrec.ordinal() >= VitroVocabulary.Precision.HOUR.ordinal() ) + map.put("hour", Integer.toString(value.getHourOfDay()) ); + else + map.put("hour", ""); + + if( existingPrec.ordinal() >= VitroVocabulary.Precision.DAY.ordinal() ) + map.put("day", Integer.toString(value.getDayOfMonth()) ); + else + map.put("day", ""); + + if( existingPrec.ordinal() >= VitroVocabulary.Precision.MONTH.ordinal() ) + map.put("month", Integer.toString(value.getMonthOfYear())); + else + map.put("month", ""); + + if( existingPrec.ordinal() >= VitroVocabulary.Precision.YEAR.ordinal() ) + map.put("year", Integer.toString(value.getYear())); + else + map.put("year", ""); + } } return map; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeIntervalFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeIntervalFormGenerator.java index 7daa9743c..9cb4033f9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeIntervalFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeIntervalFormGenerator.java @@ -70,8 +70,7 @@ public class DateTimeIntervalFormGenerator extends "startField-value", existingStartDateQuery); conf.addSparqlForExistingLiteral( "endField-value", existingEndDateQuery); - conf.addSparqlForExistingUris( - getNodeVar(), existingIntervalNodeQuery); + conf.addSparqlForExistingUris("startNode", existingStartNodeQuery); conf.addSparqlForExistingUris("endNode", existingEndNodeQuery); conf.addSparqlForExistingUris( @@ -115,7 +114,7 @@ public class DateTimeIntervalFormGenerator extends final String existingStartDateQuery = "SELECT ?existingDateStart WHERE { \n" + - "?subject <" + getToDateTimeIntervalPredicate() + "> ?existingIntervalNode . \n" + + "?subject <" + getToDateTimeIntervalPredicate() + "> " + getNodeN3Var() + " . \n" + getNodeN3Var() + " a <" + intervalType + "> . \n" + getNodeN3Var() + " <" + intervalToStart + "> ?startNode . \n" + "?startNode a <" + dateTimeValueType + "> . \n" + @@ -123,34 +122,30 @@ public class DateTimeIntervalFormGenerator extends final String existingEndDateQuery = "SELECT ?existingEndDate WHERE { \n" + - "?subject <" + getToDateTimeIntervalPredicate() + "> ?existingIntervalNode . \n" + + "?subject <" + getToDateTimeIntervalPredicate() + "> " + getNodeN3Var() + " . \n" + getNodeN3Var() + " a <" + intervalType + "> . \n" + getNodeN3Var() + " <" + intervalToEnd + "> ?endNode . \n" + "?endNode a <" + dateTimeValueType + "> . \n " + "?endNode <" + dateTimeValue + "> ?existingEndDate . }"; - final String existingIntervalNodeQuery = - "SELECT ?existingIntervalNode WHERE { \n" + - "?subject <" + getToDateTimeIntervalPredicate() + "> ?existingIntervalNode . \n" + - "?existingIntervalNode a <" + intervalType + "> . }"; final String existingStartNodeQuery = "SELECT ?existingStartNode WHERE { \n" + - "?subject <" + getToDateTimeIntervalPredicate() + "> ?existingIntervalNode . \n" + + "?subject <" + getToDateTimeIntervalPredicate() + "> " + getNodeN3Var() + " . \n" + getNodeN3Var() + " a <" + intervalType + "> . \n" + getNodeN3Var() + " <" + intervalToStart + "> ?existingStartNode . \n" + "?existingStartNode a <" + dateTimeValueType + "> .} "; final String existingEndNodeQuery = "SELECT ?existingEndNode WHERE { \n" + - "?subject <" + getToDateTimeIntervalPredicate() + "> ?existingIntervalNode . \n" + + "?subject <" + getToDateTimeIntervalPredicate() + "> " + getNodeN3Var() + " . \n" + getNodeN3Var() + " a <" + intervalType + "> . \n" + getNodeN3Var() + " <" + intervalToEnd + "> ?existingEndNode . \n" + "?existingEndNode a <" + dateTimeValueType + "> .} "; final String existingStartPrecisionQuery = "SELECT ?existingStartPrecision WHERE { \n" + - "?subject <" + getToDateTimeIntervalPredicate() + "> ?existingIntervalNode . \n" + + "?subject <" + getToDateTimeIntervalPredicate() + "> " + getNodeN3Var() + " . \n" + getNodeN3Var() + " a <" + intervalType + "> . \n" + getNodeN3Var() + " <" + intervalToStart + "> ?startNode . \n" + "?startNode a <" + dateTimeValueType + "> . \n" + @@ -158,7 +153,7 @@ public class DateTimeIntervalFormGenerator extends final String existingEndPrecisionQuery = "SELECT ?existingEndPrecision WHERE { \n" + - "?subject <" + getToDateTimeIntervalPredicate() + "> ?existingIntervalNode . \n" + + "?subject <" + getToDateTimeIntervalPredicate() + "> " + getNodeN3Var() + " . \n" + getNodeN3Var() + " a <" + intervalType + "> . \n" + getNodeN3Var() + " <" + intervalToEnd + "> ?endNode . \n" + "?endNode a <" + dateTimeValueType + "> . \n" + diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeValueFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeValueFormGenerator.java index 7ecf1695e..360d47cb6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeValueFormGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DateTimeValueFormGenerator.java @@ -46,7 +46,7 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator conf.setVarNameForSubject("subject"); conf.setVarNameForPredicate("toDateTimeValue"); conf.setVarNameForObject("valueNode"); - + //Value node value will be in scope if we have an object uri that exists for editing conf.setN3Optional(Arrays.asList(getN3ForValue())); conf.addNewResource("valueNode", DEFAULT_NS_FOR_NEW_RESOURCE); @@ -55,7 +55,6 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator "dateTimeField-value", getExistingDateTimeValueQuery()); conf.addSparqlForExistingUris( "dateTimeField-precision", getExistingPrecisionQuery()); - conf.addSparqlForExistingUris("valueNode", getExistingNodeQuery()); FieldVTwo dateTimeField = new FieldVTwo().setName(this.getDateTimeFieldName()); dateTimeField.setEditElement(new DateTimeWithPrecisionVTwo(dateTimeField, @@ -84,23 +83,18 @@ public class DateTimeValueFormGenerator extends BaseEditConfigurationGenerator protected String getExistingDateTimeValueQuery () { return "SELECT ?existingDateTimeValue WHERE { \n" + - "?subject <" + this.getToDateTimeValuePredicate() + "> ?existingValueNode . \n" + - "?existingValueNode a <" + valueType + "> . \n" + - "?existingValueNode <" + dateTimeValue + "> ?existingDateTimeValue }"; + "?subject <" + this.getToDateTimeValuePredicate() + "> ?valueNode . \n" + + "?valueNode a <" + valueType + "> . \n" + + "?valueNode <" + dateTimeValue + "> ?existingDateTimeValue }"; } protected String getExistingPrecisionQuery() { return "SELECT ?existingPrecision WHERE { \n" + - "?subject <" + this.getToDateTimeValuePredicate() + "> ?existingValueNode . \n" + - "?existingValueNode a <" + valueType + "> . \n" + - "?existingValueNode <" + dateTimePrecision + "> ?existingPrecision }"; - } - protected String getExistingNodeQuery() { - return "SELECT ?existingNode WHERE { \n" + - "?subject <" + this.getToDateTimeValuePredicate() + "> ?existingNode . \n" + - "?existingNode a <" + valueType + "> }"; - + "?subject <" + this.getToDateTimeValuePredicate() + "> ?valueNode . \n" + + "?valueNode a <" + valueType + "> . \n" + + "?valueNode <" + dateTimePrecision + "> ?existingPrecision }"; } + public static String getNodeVar() { return "valueNode"; }