From b52832208d016c89e0e800b1c2ad692355f7394c Mon Sep 17 00:00:00 2001 From: bdc34 Date: Tue, 11 Jan 2011 23:12:02 +0000 Subject: [PATCH] Fixing addRoleToPersonTwoStage so that it can remove an end date of a date time interval. NIHVIVO-1656 --- .../edit/elements/DateTimeWithPrecision.java | 22 +++++++++++++++---- .../elements/DateTimeWithPrecisionTest.java | 5 +++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java index 2f4c4b7d4..4f0839153 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java @@ -64,7 +64,9 @@ public class DateTimeWithPrecision extends BaseEditElement { VitroVocabulary.Precision DEFAULT_MIN_PRECISION = VitroVocabulary.Precision.DAY; VitroVocabulary.Precision DEFAULT_DISPLAY_LEVEL = VitroVocabulary.Precision.DAY; VitroVocabulary.Precision[] precisions = VitroVocabulary.Precision.values(); - + + protected static final String BLANK_SENTINEL = ">SUBMITTED VALUE WAS BLANK<"; + public DateTimeWithPrecision(Field field) { super(field); fieldName = field.getName(); @@ -247,7 +249,17 @@ public class DateTimeWithPrecision extends BaseEditElement { return literalMap; } - protected Literal getDateTime( Map queryParameters ) { + protected Literal getDateTime( Map queryParameters ) { + String submittedPrec = BLANK_SENTINEL; + try { + submittedPrec = getSubmittedPrecision( queryParameters); + } catch (Exception e) { + log.error("could not get submitted precsion",e); + } + + if( BLANK_SENTINEL.equals( submittedPrec ) ) + return null; + Integer year = parseToInt(fieldName+".year", queryParameters); //this is the case where date has not been filled out at all. @@ -305,7 +317,8 @@ public class DateTimeWithPrecision extends BaseEditElement { return Collections.emptyMap(); } Map uriMap = new HashMap(); - uriMap.put(fieldName+".precision", precisionUri); + if( precisionUri != null ) + uriMap.put(fieldName+".precision", precisionUri); return uriMap; } @@ -335,7 +348,8 @@ public class DateTimeWithPrecision extends BaseEditElement { /* the field wasn't filled out at all */ if( indexOfFirstNull == 0 ) - return VitroVocabulary.Precision.NONE.uri(); + //return VitroVocabulary.Precision.NONE.uri(); + return BLANK_SENTINEL; /* if they all had values then we have seconds precision */ if( indexOfFirstNull == -1 ) diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java index 5e4399d4c..c924b0618 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java @@ -225,10 +225,11 @@ public class DateTimeWithPrecisionTest { Assert.assertTrue(validationMsgs.size() == 0 ); String precisionURI = null; + precisionURI = dtwp.getSubmittedPrecision( queryParameters ); - Assert.assertNotNull(precisionURI); - Assert.assertEquals(VitroVocabulary.Precision.NONE.uri(), precisionURI); + Assert.assertNotNull(precisionURI); + Assert.assertEquals(dtwp.BLANK_SENTINEL, precisionURI); Literal date = dtwp.getDateTime( queryParameters); Assert.assertNull(date);