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 a4f660c17..3425e8296 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 @@ -153,6 +153,11 @@ public class DateTimeWithPrecision extends BaseEditElement { protected Literal getDateTime( Map queryParameters ) { Integer year = parseToInt(fieldName+".year", queryParameters); + + //this is the case where date has not been filled out at all. + if( year == null ) + return null; + Integer month = parseToInt(fieldName+".month", queryParameters); if( month == null || month == 0 ) month = 1; @@ -232,6 +237,10 @@ public class DateTimeWithPrecision extends BaseEditElement { } } + /* the field wasn't filled out at all */ + if( indexOfFirstNull == 0 ) + return VitroVocabulary.Precision.NONE.uri(); + /* if they all had values then we have seconds precision */ if( indexOfFirstNull == -1 ) return VitroVocabulary.Precision.SECOND.uri(); @@ -247,7 +256,7 @@ public class DateTimeWithPrecision extends BaseEditElement { } } if( nonNullAfterFirstNull ) - throw new Exception("cannot determine precision, there were filledout values after the first un-filledout value, "); + throw new Exception("cannot determine precision, there were filled out values after the first un-filledout value, "); else{ return precisions[ indexOfFirstNull ].uri(); } 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 1f2c26b91..3c335723c 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 @@ -182,6 +182,37 @@ public class DateTimeWithPrecisionTest { Assert.assertEquals(VitroVocabulary.Precision.YEAR.uri(), precisionURI); } + @Test + public void precisionNoValueTest() throws Exception{ + String FIELDNAME = "testfield"; + Field field = new Field(); + field.setName(FIELDNAME); + DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field); + + Map queryParameters = new HashMap(); + //field is not filled out at all + //no year + //no months + //no days + //no hours + //no minutes + //no seconds + + EditConfiguration editConfig=null; + Map validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters); + Assert.assertNotNull(validationMsgs); + Assert.assertTrue(validationMsgs.size() == 0 ); + + String precisionURI = null; + precisionURI = dtwp.getSubmittedPrecision( queryParameters ); + + Assert.assertNotNull(precisionURI); + Assert.assertEquals(VitroVocabulary.Precision.NONE.uri(), precisionURI); + + Literal date = dtwp.getDateTime( queryParameters); + Assert.assertNull(date); + } + @Test public void getDateLiteralTest(){ String FIELDNAME = "testfield";