Search in sources :

Example 1 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.

the class SweDataArrayValue method getPhenomenonTime.

@Override
public Time getPhenomenonTime() {
    final TimePeriod timePeriod = new TimePeriod();
    Set<Integer> dateTokenIndizes = Sets.newHashSet();
    if (getValue() != null && getValue().getElementType() != null && getValue().getEncoding() != null) {
        // get index of time token from elementtype
        if (getValue().getElementType() instanceof SweDataRecord) {
            final SweDataRecord elementType = (SweDataRecord) getValue().getElementType();
            final List<SweField> fields = elementType.getFields();
            for (int i = 0; i < fields.size(); i++) {
                final SweField sweField = fields.get(i);
                if (sweField.getElement() instanceof SweTime || sweField.getElement() instanceof SweTimeRange) {
                    if (checkFieldNameAndElementDefinition(sweField)) {
                        dateTokenIndizes.add(i);
                    }
                }
            }
        }
        if (CollectionHelper.isNotEmpty(dateTokenIndizes)) {
            for (final List<String> block : getValue().getValues()) {
                // datetimehelper to DateTime from joda time
                for (Integer index : dateTokenIndizes) {
                    String token = null;
                    try {
                        token = block.get(index);
                        final Time time = DateTimeHelper.parseIsoString2DateTime2Time(token);
                        timePeriod.extendToContain(time);
                    } catch (final DateTimeParseException dte) {
                        LOGGER.error(String.format("Could not parse ISO8601 string \"%s\"", token), dte);
                        // try next block;
                        continue;
                    }
                }
            }
        } else {
            final String errorMsg = "PhenomenonTime field could not be found in ElementType";
            LOGGER.error(errorMsg);
        }
    } else {
        final String errorMsg = String.format("Value of type \"%s\" not set correct.", SweDataArrayValue.class.getName());
        LOGGER.error(errorMsg);
    }
    return timePeriod;
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) Time(org.n52.shetland.ogc.gml.time.Time) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTimeParseException(java.time.format.DateTimeParseException) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField)

Example 2 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.

the class SweHelper method getPhenomenonTimeField.

private SweField getPhenomenonTimeField(Time sosTime) {
    SweAbstractUomType<?> time;
    if (sosTime instanceof TimePeriod) {
        time = new SweTimeRange();
    } else {
        time = new SweTime();
    }
    time.setDefinition(OmConstants.PHENOMENON_TIME);
    time.setUom(OmConstants.PHEN_UOM_ISO8601);
    return new SweField(OmConstants.PHENOMENON_TIME_NAME, time);
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweField(org.n52.shetland.ogc.swe.SweField) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange)

Example 3 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.

the class FieldDecoderTest method time.

@Test
public void time() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.TIME_TYPE).put(JSONConstants.UOM, UOM);
    SweField field = checkCommon(json, false);
    assertThat(field.getElement(), is(instanceOf(SweTime.class)));
    SweTime swe = (SweTime) field.getElement();
    errors.checkThat(swe.getValue(), is(nullValue()));
    errors.checkThat(swe.getUom(), is(UOM));
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) Test(org.junit.Test)

Example 4 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.

the class FieldDecoderTest method timeWithValue.

@Test
public void timeWithValue() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.TIME_TYPE).put(JSONConstants.UOM, UOM).put(JSONConstants.VALUE, TIME_START);
    SweField field = checkCommon(json, true);
    assertThat(field.getElement(), is(instanceOf(SweTime.class)));
    SweTime swe = (SweTime) field.getElement();
    errors.checkThat(swe.getValue(), is(timeStart));
    errors.checkThat(swe.getUom(), is(UOM));
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) Test(org.junit.Test)

Example 5 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime 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)

Aggregations

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