From ba13a71e3ee4d6447a472fc3cb36c0a7c2bbf003 Mon Sep 17 00:00:00 2001 From: bdc34 Date: Wed, 22 Dec 2010 22:36:47 +0000 Subject: [PATCH] Working on dateTime with precision NIHVIVO-295 --- .../forms/personHasEducationalTraining.jsp | 42 +- .../edit/elements/DateTimeWithPrecision.java | 433 ------------------ .../elements/DateTimeWithPrecisionTest.java | 216 --------- 3 files changed, 28 insertions(+), 663 deletions(-) delete mode 100644 src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java delete mode 100644 test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java diff --git a/productMods/edit/forms/personHasEducationalTraining.jsp b/productMods/edit/forms/personHasEducationalTraining.jsp index 4a30b2bf..49bd6e07 100644 --- a/productMods/edit/forms/personHasEducationalTraining.jsp +++ b/productMods/edit/forms/personHasEducationalTraining.jsp @@ -43,6 +43,7 @@ core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary"%> +<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary.Precision"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory"%> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> @@ -51,6 +52,8 @@ core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) <%@ page import="org.apache.commons.logging.LogFactory" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field"%> +<%@page import="edu.cornell.mannlib.vitro.webapp.edit.elements.DateTimeWithPrecision"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%> <%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %> @@ -82,7 +85,7 @@ core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) - + @@ -92,19 +95,23 @@ core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) +--%> SELECT ?existingYear WHERE { - ?edTraining <${hasDateTimeValue}> ?existingYear . } + ?edTraining <${edToDateTime}> ?dateTimeNode . + ?dateTimeNode <${dateTimeValue}> ?existingYear . } - - @prefix core: <${vivoCore}> . - ?dateTime a core:DateTimeValue ; - core:dateTime ?year ; - core:dateTimeValuePrecision core:YearPrecision . - ?edTraining core:dateTimeValue ?dateTime . + + + SELECT ?existingPrecision WHERE { + ?edTraining <${edToDateTime}> ?dateTimeNode . + ?dateTimeNode <${dateTimePrecision}> ?existingPrecision . } + + + + SELECT ?dateTime WHERE { ?edTraining <${edToDateTime}> ?dateTime . } ---%> <%-- Assertions for adding a new educational training entry --%> @@ -128,7 +135,7 @@ core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) ?edTraining <${edToDateTime}> ?dateTimeNode . ?dateTimeNode <${type}> <${dateTimeValueType}> . - ?dateTimeNode <${hasDateTimeValue}> ?dateTime.value . + ?dateTimeNode <${dateTimeValue}> ?dateTime.value . ?dateTimeNode <${dateTimePrecision}> ?dateTime.precision . @@ -230,12 +237,15 @@ core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) "orgLabel" : "${orgLabelQuery}", "majorField" : "${majorFieldQuery}", "dept" : "${deptQuery}", - "info" : "${infoQuery}" + "info" : "${infoQuery}", + "dateTime.value" : "${existingYearQuery}" }, "sparqlForExistingUris" : { "org" : "${orgQuery}", "orgType" : "${orgTypeQuery}", - "degree" : "${degreeQuery}" + "degree" : "${degreeQuery}", + "dateTimeNode" : "${existingDateTimeQuery}", + "dateTime.precision" : "${existingYearPrecision}" }, "fields" : { "degree" : { @@ -261,7 +271,6 @@ core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) "assertions" : [ "${majorFieldAssertion}" ] }, "dateTime" : { - "editElement" : "edu.cornell.mannlib.vitro.webapp.edit.elements.DateTimeWithPrecision", "newResource" : "true", "validators" : [ ], "optionsType" : "UNDEFINED", @@ -335,7 +344,12 @@ core:dateTimePrecision (DateTimeValue : DateTimeValuePrecision) EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request); if (editConfig == null) { - editConfig = new EditConfiguration((String) request.getAttribute("editjson")); + editConfig = new EditConfiguration((String) request.getAttribute("editjson")); + + //setup date time edit element + Field dateTime = editConfig.getField("dateTime"); + dateTime.setEditElement( new DateTimeWithPrecision(dateTime, VitroVocabulary.Precision.YEAR)); + EditConfiguration.putConfigInSession(editConfig,session); } diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java b/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java deleted file mode 100644 index 3dd1c59c..00000000 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecision.java +++ /dev/null @@ -1,433 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.edit.elements; - -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.joda.time.DateTime; - -import com.hp.hpl.jena.rdf.model.Literal; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; - -import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; -import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditSubmission; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field; -import freemarker.template.Configuration; - -/** - * This is intended to work in conjunction with a template to create the HTML for a - * datetime with precision and to convert he submitted parameters into - * varname -> Literal and varname -> URI maps. - */ -public class DateTimeWithPrecision extends BaseEditElement { - - String fieldName; - - public DateTimeWithPrecision(Field field) { - super(field); - fieldName = field.getName(); - } - - - private static final Log log = LogFactory.getLog(DateTimeWithPrecision.class); - protected String TEMPATE_NAME = "dateTimeWithPrecision.ftl"; - protected static final String vivoCore = "http://vivoweb.org/ontology/core#"; - protected static final String[] PRECISIONS = { - vivoCore+"NoPrecision", - vivoCore+"YearPrecision", - vivoCore+"YearMonthPrecision", - vivoCore+"YearMonthDayPrecision", - vivoCore+"YearMonthDayHourPrecision", - vivoCore+"YearMonthDayHourMinutePrecision", - vivoCore+"YearMonthDayTimePrecision"}; - - protected enum Precision { - NONE(PRECISIONS[0]), - YEAR(PRECISIONS[1]), - MONTH(PRECISIONS[2]), - DAY(PRECISIONS[3]), - HOUR(PRECISIONS[4]), - MINUTE(PRECISIONS[5]), - SECOND(PRECISIONS[6]); - - private final String URI; - Precision(String uri){ - URI=uri; - } - public String uri(){return URI;} - } - - @Override - public String draw(String fieldName, EditConfiguration editConfig, - EditSubmission editSub, Configuration fmConfig) { - Map map = getMapForTemplate( editConfig, editSub); - map.putAll( FreemarkerHttpServlet.getDirectives()); - return merge( fmConfig, TEMPATE_NAME, map); - } - - /** - * This produces a map for use in the template. - */ - private Map getMapForTemplate(EditConfiguration editConfig, EditSubmission editSub) { - Mapmap = new HashMap(); - - map.put("fieldName", fieldName); - - DateTime value = getTimeValue(editConfig,editSub); - map.put("year", Integer.toString(value.getYear())); - map.put("month", Integer.toString(value.getMonthOfYear())); - map.put("day", Integer.toString(value.getDayOfMonth()) ); - map.put("hour", Integer.toString(value.getHourOfDay()) ); - map.put("minute", Integer.toString(value.getMinuteOfHour()) ); - map.put("second", Integer.toString(value.getSecondOfMinute() )) ; - - map.put("precision", getPrecision(editConfig,editSub)); - - //maybe we should put in empty validation errors to show what they would be? - //ex: map.put("year.error",""); - - return map; - } - - - private String getPrecision(EditConfiguration editConfig, EditSubmission editSub) { - // TODO Auto-generated method stub - return "http://bogus.precision.uri.com/bogus"; - } - - private DateTime getTimeValue(EditConfiguration editConfig, EditSubmission editSub) { - return new DateTime(); - } - - /** - * This gets the literals for a submitted form from the queryParmeters. - * It will only be called if getValidationErrors() doesn't return any errors. - */ - @Override - public Map getLiterals(String fieldName, - EditConfiguration editConfig, Map queryParameters) { - Map literalMap = new HashMap(); - - Literal datetime =getDateTime( queryParameters); - literalMap.put(fieldName+".value", datetime); - - return literalMap; - } - - protected Literal getDateTime( Map queryParameters ) { - Integer year = parseToInt(fieldName+".year", queryParameters); - Integer month = parseToInt(fieldName+".month", queryParameters); - if( month == null || month == 0 ) - month = 1; - Integer day = parseToInt(fieldName+".day", queryParameters); - if( day == null || day == 0 ) - day = 1; - Integer hour = parseToInt(fieldName+".hour", queryParameters); - if( hour == null ) - hour = 0; - Integer minute = parseToInt(fieldName+".minute", queryParameters); - if( minute == null ) - minute = 0; - Integer second = parseToInt(fieldName+".second", queryParameters); - if( second == null ) - second = 0; - int mills = 0; - - - DateTime value = new DateTime( - year.intValue(),month.intValue(),day.intValue(), - hour.intValue(),minute.intValue(),second.intValue(),mills); - - Date dValue = value.toDate(); - - /*This isn't doing what I want it to do. It is recording the correct instance of timeb - * but it is recording it with the timezone UTC/zulu */ - //return ResourceFactory.createTypedLiteral(ISODateTimeFormat.dateTimeNoMillis().print(value),XSDDatatype.XSDdateTime); - - Calendar c = Calendar.getInstance(); - c.setTime(value.toDate()); - - Model m = ModelFactory.createDefaultModel(); - Literal lit = m.createTypedLiteral( c ); - return lit; - } - - /** - * This gets the URIs for a submitted form from the queryParmeters. - * It will only be called if getValidationErrors() doesn't return any errors. - */ - @Override - public Map getURIs(String fieldName, - EditConfiguration editConfig, Map queryParameters) { - String precisionUri; - try { - precisionUri = getSubmittedPrecision( queryParameters); - } catch (Exception e) { - // TODO Auto-generated catch block - log.error("getURIS() should only be called on input that passed getValidationErrors()"); - return Collections.emptyMap(); - } - Map uriMap = new HashMap(); - uriMap.put(fieldName+".precision", precisionUri); - return uriMap; - } - - /** - * Precision is based on the values returned by the form. Throws an exception with - * the error message if the queryParameters cannot make a valid date/precision because - * there are values missing. - */ - protected String getSubmittedPrecision(Map queryParameters) throws Exception { - - Integer year = parseToInt(fieldName+".year",queryParameters); - Integer month = parseToInt(fieldName+".month",queryParameters); - Integer day = parseToInt(fieldName+".day",queryParameters); - Integer hour = parseToInt(fieldName+".hour",queryParameters); - Integer minute = parseToInt(fieldName+".minute",queryParameters); - Integer second = parseToInt(fieldName+".second",queryParameters); - Integer[] values = { year, month, day, hour, minute, second }; - - /* find the most significant date field that is null. */ - int indexOfFirstNull= -1; - for(int i=0; i < values.length ; i++){ - if( values[i] == null ){ - indexOfFirstNull = i; - break; - } - } - - /* if they all had values then we have seconds precision */ - if( indexOfFirstNull == -1 ) - return PRECISIONS[6]; - - - /* check that there are no values after the most significant null field - * that are non-null. */ - boolean nonNullAfterFirstNull=false; - for(int i=0; i < values.length ; i++){ - if( i > indexOfFirstNull && values[i] != null ){ - nonNullAfterFirstNull = true; - break; - } - } - if( nonNullAfterFirstNull ) - throw new Exception("cannot determine precision, there were filledout values after the first un-filledout value, "); - else{ - - return PRECISIONS[ indexOfFirstNull ]; - } - } - - @Override - public Map getValidationMessages(String fieldName, - EditConfiguration editConfig, Map queryParameters) { - Map errorMsgMap = new HashMap(); - - //check that any parameters we got are single values - String[] names = {"year","month","day","hour","minute","second", "precision"}; - for( String name:names){ - if ( !hasNoneOrSingle(fieldName+"."+name, queryParameters)) - errorMsgMap.put(fieldName+"."+name, "must have only one value for " + name); - } - - String precisionURI = null; - try{ - precisionURI = getSubmittedPrecision( queryParameters); - }catch(Exception ex){ - errorMsgMap.put(fieldName,ex.getMessage()); - return errorMsgMap; - } - - errorMsgMap.putAll(checkDate( precisionURI, queryParameters) ); - - return errorMsgMap; - } - - /** - * This checks for invalid date times. - */ - final static String NON_INTEGER_YEAR = "must enter a valid year"; - final static String NON_INTEGER_MONTH = "must enter a valid month"; - final static String NON_INTEGER_DAY = "must enter a valid day"; - final static String NON_INTEGER_HOUR = "must enter a valid hour"; - final static String NON_INTEGER_MINUTE = "must enter a valid minute"; - final static String NON_INTEGER_SECOND = "must enter a valid second"; - - private Map checkDate( String precisionURI, Map qp){ - if( precisionURI == null ) - return Collections.emptyMap(); - - Map errors = new HashMap(); - - Integer year,month,day,hour,minute,second; - - //just check if the values for the precision parse to integers - if( precisionURI.equals( Precision.YEAR.uri() ) ){ - if( ! canParseToNumber(fieldName+".year" ,qp)) - errors.put(fieldName+".year", NON_INTEGER_YEAR); - }else if( precisionURI.equals( Precision.MONTH.uri() )){ - if( ! canParseToNumber(fieldName+".year" ,qp)) - errors.put(fieldName+".year", NON_INTEGER_YEAR); - if( ! canParseToNumber(fieldName+".month" ,qp)) - errors.put(fieldName+".month", NON_INTEGER_MONTH); - }else if( precisionURI.equals( Precision.DAY.uri() )){ - if( ! canParseToNumber(fieldName+".year" ,qp)) - errors.put(fieldName+".year", NON_INTEGER_YEAR); - if( ! canParseToNumber(fieldName+".month" ,qp)) - errors.put(fieldName+".month", NON_INTEGER_MONTH); - if( ! canParseToNumber(fieldName+".day" ,qp)) - errors.put(fieldName+".day", NON_INTEGER_DAY); - }else if( precisionURI.equals( Precision.HOUR.uri() )){ - if( ! canParseToNumber(fieldName+".year" ,qp)) - errors.put(fieldName+".year", NON_INTEGER_YEAR); - if( ! canParseToNumber(fieldName+".month" ,qp)) - errors.put(fieldName+".month", NON_INTEGER_MONTH); - if( ! canParseToNumber(fieldName+".day" ,qp)) - errors.put(fieldName+".day", NON_INTEGER_DAY); - if( ! canParseToNumber(fieldName+".hour" ,qp)) - errors.put(fieldName+".hour", NON_INTEGER_HOUR); - }else if( precisionURI.equals( Precision.MINUTE.uri() )){ - if( ! canParseToNumber(fieldName+".year" ,qp)) - errors.put(fieldName+".year", NON_INTEGER_YEAR); - if( ! canParseToNumber(fieldName+".month" ,qp)) - errors.put(fieldName+".month", NON_INTEGER_MONTH); - if( ! canParseToNumber(fieldName+".day" ,qp)) - errors.put(fieldName+".day", NON_INTEGER_DAY); - if( ! canParseToNumber(fieldName+".hour" ,qp)) - errors.put(fieldName+".hour", NON_INTEGER_HOUR); - if( ! canParseToNumber(fieldName+".minute" ,qp)) - errors.put(fieldName+".minute", NON_INTEGER_HOUR); - }else if( precisionURI.equals( Precision.SECOND.uri() )){ - if( ! canParseToNumber(fieldName+".year" ,qp)) - errors.put(fieldName+".year", NON_INTEGER_YEAR); - if( ! canParseToNumber(fieldName+".month" ,qp)) - errors.put(fieldName+".month", NON_INTEGER_MONTH); - if( ! canParseToNumber(fieldName+".day" ,qp)) - errors.put(fieldName+".day", NON_INTEGER_DAY); - if( ! canParseToNumber(fieldName+".hour" ,qp)) - errors.put(fieldName+".hour", NON_INTEGER_HOUR); - if( ! canParseToNumber(fieldName+".minute" ,qp)) - errors.put(fieldName+".minute", NON_INTEGER_HOUR); - if( ! canParseToNumber(fieldName+".second" ,qp)) - errors.put(fieldName+".second", NON_INTEGER_SECOND); - } - - //check if we can make a valid date with these integers - year = parseToInt(fieldName+".year", qp); - if( year == null ) - year = 1999; - month= parseToInt(fieldName+".month", qp); - if(month == null ) - month = 1; - day = parseToInt(fieldName+".day", qp); - if( day == null ) - day = 1; - hour = parseToInt(fieldName+".hour", qp); - if( hour == null ) - hour = 0; - minute = parseToInt(fieldName+".minute",qp); - if( minute == null ) - minute = 0; - second = parseToInt(fieldName+".second", qp); - if( second == null ) - second = 0; - - DateTime dateTime = new DateTime(); - try{ - dateTime.withYear(year); - }catch(IllegalArgumentException iae){ - errors.put(fieldName+".year", iae.getLocalizedMessage()); - } - try{ - dateTime.withMonthOfYear(month); - }catch(IllegalArgumentException iae){ - errors.put(fieldName+".month", iae.getLocalizedMessage()); - } - try{ - dateTime.withDayOfMonth(day); - }catch(IllegalArgumentException iae){ - errors.put(fieldName+".day", iae.getLocalizedMessage()); - } - try{ - dateTime.withHourOfDay(hour); - }catch(IllegalArgumentException iae){ - errors.put(fieldName+".hour", iae.getLocalizedMessage()); - } - try{ - dateTime.withSecondOfMinute(second); - }catch(IllegalArgumentException iae){ - errors.put(fieldName+".second", iae.getLocalizedMessage()); - } - - return errors; - } - - - private boolean fieldMatchesPattern( String fieldName, MapqueryParameters, Pattern pattern){ - String[] varg = queryParameters.get(fieldName); - if( varg == null || varg.length != 1 || varg[0] == null) - return false; - String value = varg[0]; - Matcher match = pattern.matcher(value); - return match.matches(); - } - - private boolean emptyOrBlank(String key,Map queryParameters){ - String[] vt = queryParameters.get(key); - return ( vt == null || vt.length ==0 || vt[0] == null || vt[0].length() == 0 ); - } - - private boolean canParseToNumber(String key,Map queryParameters){ - Integer out = null; - try{ - String[] vt = queryParameters.get(key); - if( vt == null || vt.length ==0 || vt[0] == null) - return false; - else{ - out = Integer.parseInt(vt[0]); - return true; - } - }catch(IndexOutOfBoundsException iex){ - out = null; - }catch(NumberFormatException nfe){ - out = null; - }catch(NullPointerException npe){ - out = null; - } - return false; - } - - - - private Integer parseToInt(String key,Map queryParameters){ - Integer out = null; - try{ - String[] vt = queryParameters.get(key); - if( vt == null || vt.length ==0 || vt[0] == null) - out = null; - else - out = Integer.parseInt(vt[0]); - }catch(IndexOutOfBoundsException iex){ - out = null; - }catch(NumberFormatException nfe){ - out = null; - }catch(NullPointerException npe){ - out = null; - } - return out; - } - -} - - diff --git a/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java b/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java deleted file mode 100644 index e643e4b2..00000000 --- a/test/edu/cornell/mannlib/vitro/webapp/edit/elements/DateTimeWithPrecisionTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - -package edu.cornell.mannlib.vitro.webapp.edit.elements; - -import java.util.HashMap; -import java.util.Map; - -import org.joda.time.DateTime; -import org.junit.Assert; -import org.junit.Test; - -import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; -import com.hp.hpl.jena.datatypes.xsd.XSDDateTime; -import com.hp.hpl.jena.rdf.model.Literal; - -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.Field; - - -public class DateTimeWithPrecisionTest { - - @Test - public void precisionSecondsValidationTest() throws Exception{ - String FIELDNAME = "testfield"; - Field field = new Field(); - field.setName(FIELDNAME); - DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field); - - Map queryParameters = new HashMap(); - queryParameters.put(FIELDNAME+".year", new String[]{"1999" }); - queryParameters.put(FIELDNAME+".month", new String[]{"12"}); - queryParameters.put(FIELDNAME+".day", new String[]{"01"}); - queryParameters.put(FIELDNAME+".hour", new String[]{"12"}); - queryParameters.put(FIELDNAME+".minute", new String[]{"00"}); - queryParameters.put(FIELDNAME+".second", new String[]{"00"}); - 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(dtwp.PRECISIONS[6], precisionURI); - } - - @Test - public void precisionMinutesValidationTest() throws Exception{ - String FIELDNAME = "testfield"; - Field field = new Field(); - field.setName(FIELDNAME); - DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field); - - Map queryParameters = new HashMap(); - queryParameters.put(FIELDNAME+".year", new String[]{"1999" }); - queryParameters.put(FIELDNAME+".month", new String[]{"12"}); - queryParameters.put(FIELDNAME+".day", new String[]{"01"}); - queryParameters.put(FIELDNAME+".hour", new String[]{"12"}); - queryParameters.put(FIELDNAME+".minute", new String[]{"00"}); - //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(dtwp.PRECISIONS[5], precisionURI); - } - - @Test - public void precisionHourssValidationTest() throws Exception{ - String FIELDNAME = "testfield"; - Field field = new Field(); - field.setName(FIELDNAME); - DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field); - - Map queryParameters = new HashMap(); - queryParameters.put(FIELDNAME+".year", new String[]{"1999" }); - queryParameters.put(FIELDNAME+".month", new String[]{"12"}); - queryParameters.put(FIELDNAME+".day", new String[]{"01"}); - queryParameters.put(FIELDNAME+".hour", new String[]{"12"}); - //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(dtwp.PRECISIONS[4], precisionURI); - } - - @Test - public void precisionDaysValidationTest() throws Exception{ - String FIELDNAME = "testfield"; - Field field = new Field(); - field.setName(FIELDNAME); - DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field); - - Map queryParameters = new HashMap(); - queryParameters.put(FIELDNAME+".year", new String[]{"1999" }); - queryParameters.put(FIELDNAME+".month", new String[]{"12"}); - queryParameters.put(FIELDNAME+".day", new String[]{"01"}); - //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(dtwp.PRECISIONS[3], precisionURI); - } - - @Test - public void precisionMonthsValidationTest()throws Exception{ - String FIELDNAME = "testfield"; - Field field = new Field(); - field.setName(FIELDNAME); - DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field); - - Map queryParameters = new HashMap(); - queryParameters.put(FIELDNAME+".year", new String[]{"1999" }); - queryParameters.put(FIELDNAME+".month", new String[]{"12"}); - //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(dtwp.PRECISIONS[2], precisionURI); - } - - @Test - public void precisionYearValidationTest() throws Exception{ - String FIELDNAME = "testfield"; - Field field = new Field(); - field.setName(FIELDNAME); - DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field); - - Map queryParameters = new HashMap(); - queryParameters.put(FIELDNAME+".year", new String[]{"1999" }); - //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(dtwp.PRECISIONS[1], precisionURI); - } - - @Test - public void getDateLiteralTest(){ - String FIELDNAME = "testfield"; - Field field = new Field(); - field.setName(FIELDNAME); - DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field); - - Map queryParameters = new HashMap(); - queryParameters.put(FIELDNAME+".year", new String[]{"1999" }); - //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 ); - - Literal date = dtwp.getDateTime( queryParameters); - Assert.assertNotNull(date); - Assert.assertEquals( XSDDatatype.XSDdateTime.getURI() ,date.getDatatypeURI() ); - - DateTime result = new DateTime( date.getLexicalForm() ); - DateTime expected = new DateTime(1999,1,1,0,0,0,0); - Assert.assertEquals(expected, result); - - Object obj = date.getValue(); - Assert.assertNotNull(obj); - Assert.assertEquals(XSDDateTime.class, obj.getClass()); - } - -}