use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class SweCommonDecoderV20Test method should_decode_TimeRange.
@Test
public void should_decode_TimeRange() throws DecodingException {
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));
}
use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class SweHelper method createBlock.
@SuppressFBWarnings("BC_VACUOUS_INSTANCEOF")
private List<String> createBlock(SweAbstractDataComponent elementType, Time phenomenonTime, String phenID, Value<?> value) {
if (elementType instanceof SweDataRecord) {
SweDataRecord elementTypeRecord = (SweDataRecord) elementType;
List<String> block = new ArrayList<>(elementTypeRecord.getFields().size());
if (!(value instanceof NilTemplateValue)) {
elementTypeRecord.getFields().forEach(field -> {
if (field.getElement() instanceof SweTime || field.getElement() instanceof SweTimeRange) {
block.add(DateTimeHelper.format(phenomenonTime));
} else if (field.getElement() instanceof SweAbstractDataComponent && field.getElement().getDefinition().equals(phenID)) {
block.add(value.getValue().toString());
} else if (field.getElement() instanceof SweObservableProperty) {
block.add(phenID);
}
});
}
return block;
}
String exceptionMsg = String.format("Type of ElementType is not supported: %s", elementType != null ? elementType.getClass().getName() : "null");
LOGGER.debug(exceptionMsg);
throw new IllegalArgumentException(exceptionMsg);
}
use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class SweCommonDecoderV101 method parseEnvelope.
private SweAbstractDataComponent parseEnvelope(EnvelopeType envelopeType) throws DecodingException {
String referenceFrame = null;
SweVector lowerCorner = null;
SweVector upperCorner = null;
SweTimeRange time = null;
if (envelopeType.isSetReferenceFrame()) {
referenceFrame = envelopeType.getReferenceFrame();
}
if (envelopeType.getLowerCorner() != null) {
lowerCorner = parseVectorProperty(envelopeType.getLowerCorner());
}
if (envelopeType.getUpperCorner() != null) {
upperCorner = parseVectorProperty(envelopeType.getUpperCorner());
}
if (envelopeType.isSetTime()) {
time = parseTimeRange(envelopeType.getTime().getTimeRange());
}
// FIXME get the northing first value for the reference frame
boolean northingFirst = false;
return new SweEnvelope(referenceFrame, upperCorner, lowerCorner, time, northingFirst);
}
use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class SweCommonDecoderV20 method parseTimeRange.
private SweTimeRange parseTimeRange(TimeRangeType xbTime) throws DecodingException {
SweTimeRange sosTimeRange = new SweTimeRange();
if (xbTime.isSetValue()) {
List<?> value = xbTime.getValue();
if (value != null && !value.isEmpty()) {
RangeValue<DateTime> range = new RangeValue<>();
Iterator<?> iter = value.iterator();
if (iter.hasNext()) {
range.setRangeStart(DateTimeHelper.parseIsoString2DateTime(iter.next().toString()));
}
if (iter.hasNext()) {
range.setRangeEnd(DateTimeHelper.parseIsoString2DateTime(iter.next().toString()));
}
sosTimeRange.setValue(range);
}
}
if (xbTime.getUom() != null) {
sosTimeRange.setUom(xbTime.getUom().getHref());
}
if (xbTime.isSetConstraint()) {
sosTimeRange.setConstraint(parseConstraint(xbTime.getConstraint()));
}
if (xbTime.getQualityArray() != null) {
sosTimeRange.setQuality(parseQuality(xbTime.getQualityArray()));
}
return sosTimeRange;
}
use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class FieldEncoder method encodeSweTimeRangeField.
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;
}
Aggregations