use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class InsertResultTemplateRequestDecoderTest method resultStructure.
@Test
public void resultStructure() throws IOException, DecodingException {
InsertResultTemplateRequest req = load();
assertThat(req.getResultStructure(), is(notNullValue()));
assertThat(req.getResultStructure().isDecoded(), is(true));
assertThat(req.getResultStructure().isEncoded(), is(false));
assertThat(req.getResultStructure().get().get(), is(instanceOf(SweDataRecord.class)));
SweDataRecord structure = (SweDataRecord) req.getResultStructure().get().get();
assertThat(structure.getFields(), is(notNullValue()));
assertThat(structure.getFields(), hasSize(3));
SweField field1 = structure.getFields().get(0);
assertThat(field1, is(notNullValue()));
errors.checkThat(field1.getName().getValue(), is("phenomenonTime"));
assertThat(field1.getElement(), is(instanceOf(SweTimeRange.class)));
SweTimeRange phenomenonTime = (SweTimeRange) field1.getElement();
errors.checkThat(phenomenonTime.getDefinition(), is("http://www.opengis.net/def/property/OGC/0/PhenomenonTime"));
errors.checkThat(phenomenonTime.getUom(), is("http://www.opengis.net/def/uom/ISO-8601/0/Gregorian"));
SweField field2 = structure.getFields().get(1);
assertThat(field2, is(notNullValue()));
errors.checkThat(field2.getName().getValue(), is("resultTime"));
assertThat(field2.getElement(), is(instanceOf(SweTime.class)));
SweTime resultTime = (SweTime) field2.getElement();
errors.checkThat(resultTime.getDefinition(), is("http://www.opengis.net/def/property/OGC/0/ResultTime"));
errors.checkThat(resultTime.getUom(), is("testunit1"));
SweField field3 = structure.getFields().get(2);
assertThat(field3, is(notNullValue()));
errors.checkThat(field3.getName().getValue(), is("observable_property_6"));
assertThat(field3.getElement(), is(instanceOf(SweQuantity.class)));
SweQuantity quantity = (SweQuantity) field3.getElement();
errors.checkThat(quantity.getDefinition(), is("http://www.52north.org/test/observableProperty/6"));
errors.checkThat(quantity.getUom(), is("test_unit_6"));
}
use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class SweCommonDecoderV101 method parseTimeRange.
private SweTimeRange parseTimeRange(TimeRange timeRange) throws DecodingException {
SweTimeRange sosTimeRange = new SweTimeRange();
if (timeRange.isSetValue()) {
RangeValue<DateTime> range = new RangeValue<>();
Iterator<?> iter = timeRange.getValue().iterator();
if (iter.hasNext()) {
range.setRangeStart(DateTimeHelper.parseIsoString2DateTime(iter.next().toString()));
while (iter.hasNext()) {
range.setRangeEnd(DateTimeHelper.parseIsoString2DateTime(iter.next().toString()));
}
}
sosTimeRange.setValue(range);
}
if (timeRange.getUom() != null) {
sosTimeRange.setUom(timeRange.getUom().getHref());
}
return sosTimeRange;
}
use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class SweCommonEncoderv101 method encode.
@Override
public XmlObject encode(Object element, EncodingContext context) throws EncodingException {
XmlObject encodedObject = null;
if (element instanceof SweAbstractSimpleType) {
encodedObject = createSimpleType((SweAbstractSimpleType<?>) element, context);
// }
// if (element instanceof SweBoolean) {
// encodedObject = createBoolean((SweBoolean) element);
// } else if (element instanceof SweCategory) {
// encodedObject = createCategory((SweCategory) element);
// } else if (element instanceof SweCount) {
// encodedObject = createCount((SweCount) element);
// } else if (element instanceof SweObservableProperty) {
// encodedObject = createObservableProperty((SweObservableProperty)
// element);
// } else if (element instanceof SweQuantity) {
// encodedObject = createQuantity((SweQuantity) element);
// } else if (element instanceof SweQuantityRange) {
// encodedObject = createQuantityRange((SweQuantityRange) element);
// } else if (element instanceof SweText) {
// encodedObject = createText((SweText) element);
// } else if (element instanceof SweTime) {
// encodedObject = createTime((SweTime) element);
// } else if (element instanceof SweTimeRange) {
// encodedObject = createTimeRange((SweTimeRange) element);
} else if (element instanceof SweCoordinate) {
encodedObject = createCoordinate((SweCoordinate<?>) element);
} else if (element instanceof SweDataArray) {
encodedObject = createDataArray((SweDataArray) element);
} else if (element instanceof SweDataRecord) {
DataRecordType drt = createDataRecord((SweDataRecord) element);
if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
DataRecordDocument drd = DataRecordDocument.Factory.newInstance(getXmlOptions());
drd.setDataRecord(drt);
encodedObject = drd;
} else {
encodedObject = drt;
}
} else if (element instanceof SweEnvelope) {
encodedObject = createEnvelope((SweEnvelope) element);
} else if (element instanceof SweSimpleDataRecord) {
encodedObject = createSimpleDataRecord((SweSimpleDataRecord) element);
} else if (element instanceof TimePeriod) {
encodedObject = createTimeGeometricPrimitivePropertyType((TimePeriod) element);
} else {
throw new UnsupportedEncoderInputException(this, element);
}
XmlHelper.validateDocument(encodedObject, EncodingException::new);
return encodedObject;
}
use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTimeRange.
@Test
public void should_encode_Datarecord_with_fieldTimeRange() throws EncodingException {
final String field1Name = "test-name";
final RangeValue<DateTime> field1Value = new RangeValue<DateTime>();
final long now = System.currentTimeMillis();
final DateTime rangeStart = new DateTime(now - 1000);
final DateTime rangeEnd = new DateTime(now + 1000);
field1Value.setRangeStart(rangeStart);
field1Value.setRangeEnd(rangeEnd);
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTimeRange().setValue(field1Value))));
assertThat(encode, is(instanceOf(DataRecordType.class)));
final DataRecordType xbDataRecord = (DataRecordType) encode;
assertThat(xbDataRecord.getFieldArray().length, is(1));
final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
assertThat(field1.isSetTimeRange(), is(TRUE));
final DateTime xbTimeRangeStart = new DateTime(((XmlCalendar) field1.getTimeRange().getValue().get(0)).getTimeInMillis());
final DateTime xbTimeRangeEnd = new DateTime(((XmlCalendar) field1.getTimeRange().getValue().get(1)).getTimeInMillis());
assertThat(field1.getName(), is(field1Name));
assertThat(xbTimeRangeStart, is(field1Value.getRangeStart()));
assertThat(xbTimeRangeEnd, is(field1Value.getRangeEnd()));
}
use of org.n52.shetland.ogc.swe.simpleType.SweTimeRange in project arctic-sea by 52North.
the class SweCommonDecoderV101Test method should_decode_TimeRange.
@Test
public void should_decode_TimeRange() throws DecodingException {
final TimeRangeDocument xbTimeRangeDoc = TimeRangeDocument.Factory.newInstance();
TimeRange 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 SweCommonDecoderV101().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));
}
Aggregations