Search in sources :

Example 1 with SweField

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

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

the class SweDataRecordTest method getFieldIndexByIdentifier_should_not_fail_on_bad_input.

@Test
public void getFieldIndexByIdentifier_should_not_fail_on_bad_input() {
    final SweDataRecord dataRecord = new SweDataRecord();
    dataRecord.addField(new SweField("identifier", new SweBoolean()));
    final SweBoolean b = new SweBoolean();
    b.setDefinition("test-element-definition");
    dataRecord.addField(new SweField("test-field-name", b));
    assertThat(dataRecord.getFieldIndexByIdentifier(null), is(-1));
    assertThat(dataRecord.getFieldIndexByIdentifier(""), is(-1));
}
Also used : SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) Test(org.junit.Test)

Example 3 with SweField

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

the class SweHelper method getFieldForValue.

private SweField getFieldForValue(Value<?> iValue, String name) throws EncodingException {
    SweAbstractDataComponent value = getValue(iValue);
    value.setDefinition(name);
    return new SweField(name, value);
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent)

Example 4 with SweField

use of org.n52.shetland.ogc.swe.SweField 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 5 with SweField

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

the class FieldDecoder method decodeJSON.

public SweField decodeJSON(JsonNode node) throws DecodingException {
    final String type = node.path(JSONConstants.TYPE).textValue();
    final SweAbstractDataComponent element;
    if (type.equals(JSONConstants.BOOLEAN_TYPE)) {
        element = decodeBoolean(node);
    } else if (type.equals(JSONConstants.COUNT_TYPE)) {
        element = decodeCount(node);
    } else if (type.equals(JSONConstants.COUNT_RANGE_TYPE)) {
        element = decodeCountRange(node);
    } else if (type.equals(JSONConstants.OBSERVABLE_PROPERTY_TYPE)) {
        element = decodeObservableProperty(node);
    } else if (type.equals(JSONConstants.QUALITY_TYPE)) {
        element = decodeQuality(node);
    } else if (type.equals(JSONConstants.TEXT_TYPE)) {
        element = decodeText(node);
    } else if (type.equals(JSONConstants.QUANTITY_TYPE)) {
        element = decodeQuantity(node);
    } else if (type.equals(JSONConstants.QUANTITY_RANGE_TYPE)) {
        element = decodeQuantityRange(node);
    } else if (type.equals(JSONConstants.TIME_TYPE)) {
        element = decodeTime(node);
    } else if (type.equals(JSONConstants.TIME_RANGE_TYPE)) {
        element = decodeTimeRange(node);
    } else if (type.equals(JSONConstants.CATEGORY_TYPE)) {
        element = decodeCategory(node);
    } else {
        throw new UnsupportedDecoderInputException(this, node);
    }
    final String name = node.path(JSONConstants.NAME).textValue();
    element.setDescription(node.path(JSONConstants.DESCRIPTION).textValue());
    element.setIdentifier(node.path(JSONConstants.IDENTIFIER).textValue());
    element.setDefinition(node.path(JSONConstants.DEFINITION).textValue());
    element.setLabel(node.path(JSONConstants.LABEL).textValue());
    return new SweField(name, element);
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException)

Aggregations

SweField (org.n52.shetland.ogc.swe.SweField)59 Test (org.junit.Test)42 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 XmlObject (org.apache.xmlbeans.XmlObject)20 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)19 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)19 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)12 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)12 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)11 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)11 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)11 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)10 SweSimpleDataRecord (org.n52.shetland.ogc.swe.SweSimpleDataRecord)10 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)9 DataRecordType (net.opengis.swe.x101.DataRecordType)9 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)9 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)9 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 DateTime (org.joda.time.DateTime)4