Exemplo n.º 1
0
 private ObjectNode encodeSweTimeRangeField(SweField field) {
   ObjectNode jfield = createField(field);
   jfield.put(JSONConstants.TYPE, JSONConstants.TIME_RANGE_TYPE);
   SweTimeRange sweTimeRange = (SweTimeRange) field.getElement();
   jfield.put(JSONConstants.UOM, sweTimeRange.getUom());
   if (sweTimeRange.isSetValue()) {
     ArrayNode av = jfield.putArray(JSONConstants.VALUE);
     av.add(DateTimeHelper.formatDateTime2IsoString(sweTimeRange.getValue().getRangeStart()));
     av.add(DateTimeHelper.formatDateTime2IsoString(sweTimeRange.getValue().getRangeEnd()));
   }
   return jfield;
 }
 @Test
 public void should_decode_TimeRange() throws OwsExceptionReport {
   final TimeRangeDocument xbTimeRangeDoc = TimeRangeDocument.Factory.newInstance();
   TimeRangeType xbTimeRange = xbTimeRangeDoc.addNewTimeRange();
   final DateTime startDate = new DateTime(1970, 1, 1, 0, 0, DateTimeZone.UTC);
   final DateTime endDate = new DateTime(2013, 12, 31, 23, 59, DateTimeZone.UTC);
   final List<String> values = Lists.newArrayList(startDate.toString(), endDate.toString());
   xbTimeRange.setValue(values);
   final String iso8601Uom = "urn:ogc:def:unit:ISO:8601";
   xbTimeRange.addNewUom().setHref(iso8601Uom);
   final Object decodedObject = new SweCommonDecoderV20().decode(xbTimeRange);
   assertThat(decodedObject, is(instanceOf(SweTimeRange.class)));
   final SweTimeRange sweTimeRange = (SweTimeRange) decodedObject;
   assertThat(sweTimeRange.isSetUom(), is(true));
   assertThat(sweTimeRange.getUom(), is(iso8601Uom));
   assertThat(sweTimeRange.isSetValue(), is(true));
   assertThat(sweTimeRange.getValue().getRangeStart(), is(startDate));
   assertThat(sweTimeRange.getValue().getRangeEnd(), is(endDate));
 }