Search in sources :

Example 11 with SweTimeRange

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

Example 12 with SweTimeRange

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);
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ArrayList(java.util.ArrayList) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 13 with SweTimeRange

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);
}
Also used : SweVector(org.n52.shetland.ogc.swe.SweVector) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange)

Example 14 with SweTimeRange

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

Example 15 with SweTimeRange

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange)

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