Search in sources :

Example 6 with SweTimeRange

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"));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) InsertResultTemplateRequest(org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest) Test(org.junit.Test)

Example 7 with SweTimeRange

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;
}
Also used : SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTime(org.joda.time.DateTime) RangeValue(org.n52.shetland.ogc.swe.RangeValue)

Example 8 with SweTimeRange

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;
}
Also used : DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweAbstractSimpleType(org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) XmlObject(org.apache.xmlbeans.XmlObject) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) DataRecordDocument(net.opengis.swe.x101.DataRecordDocument) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 9 with SweTimeRange

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()));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) XmlObject(org.apache.xmlbeans.XmlObject) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTime(org.joda.time.DateTime) RangeValue(org.n52.shetland.ogc.swe.RangeValue) Test(org.junit.Test)

Example 10 with SweTimeRange

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));
}
Also used : SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) TimeRange(net.opengis.swe.x101.TimeRangeDocument.TimeRange) TimeRangeDocument(net.opengis.swe.x101.TimeRangeDocument) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)18 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)7 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)7 DateTime (org.joda.time.DateTime)6 Test (org.junit.Test)6 SweField (org.n52.shetland.ogc.swe.SweField)6 XmlObject (org.apache.xmlbeans.XmlObject)4 SweEnvelope (org.n52.shetland.ogc.swe.SweEnvelope)4 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)4 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)3 DataRecordType (net.opengis.swe.x101.DataRecordType)3 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)3 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)3 RangeValue (org.n52.shetland.ogc.swe.RangeValue)3 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)3 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)3 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)3 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)3