Search in sources :

Example 16 with SweAbstractDataComponent

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

the class SweCommonEncoderv20 method createField.

private DataRecordType.Field createField(SweField field) throws EncodingException {
    SweAbstractDataComponent element = field.getElement();
    DataRecordType.Field xmlField = DataRecordType.Field.Factory.newInstance(getXmlOptions());
    if (field.isSetName()) {
        xmlField.setName(NcName.makeValid(field.getName().getValue()));
    }
    XmlObject encodeObjectToXml = createAbstractDataComponent(element, EncodingContext.empty());
    XmlObject substituteElement = XmlHelper.substituteElement(xmlField.addNewAbstractDataComponent(), encodeObjectToXml);
    substituteElement.set(encodeObjectToXml);
    return xmlField;
}
Also used : DataRecordType(net.opengis.swe.x20.DataRecordType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) Field(net.opengis.swe.x20.DataRecordType.Field) XmlObject(org.apache.xmlbeans.XmlObject)

Example 17 with SweAbstractDataComponent

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

the class SweCommonEncoderv101Test method should_throw_NoApplicableCodeException_with_DataRecord_and_field_with_not_supported_element.

@Test
public void should_throw_NoApplicableCodeException_with_DataRecord_and_field_with_not_supported_element() throws EncodingException {
    thrown.expect(EncodingException.class);
    thrown.expectMessage("The element type '" + getClass().getName() + "$1' " + "of the received '" + SweField.class.getName() + "' is not supported" + " by this encoder '" + SweCommonEncoderv101.class.getName() + "'.");
    sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField("test", new SweAbstractDataComponent() {

        @Override
        public SweDataComponentType getDataComponentType() {
            return null;
        }

        @Override
        public <T, X extends Throwable> T accept(SweDataComponentVisitor<T, X> visitor) {
            return null;
        }

        @Override
        public <X extends Throwable> void accept(VoidSweDataComponentVisitor<X> visitor) {
        }

        @Override
        public SweAbstractDataComponent copy() {
            return null;
        }
    })));
}
Also used : SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) SweDataComponentType(org.n52.shetland.ogc.swe.SweConstants.SweDataComponentType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) Test(org.junit.Test)

Example 18 with SweAbstractDataComponent

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

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

the class SweHelper method createElementType.

private SweAbstractDataComponent createElementType(SingleObservationValue<?> sov, String name) throws EncodingException {
    SweDataRecord dataRecord = new SweDataRecord();
    dataRecord.addField(getPhenomenonTimeField(sov.getPhenomenonTime()));
    dataRecord.addField(getFieldForValue(sov.getValue(), name));
    return dataRecord;
}
Also used : SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord)

Example 20 with SweAbstractDataComponent

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

the class FieldDecoder method decodeTime.

protected SweAbstractDataComponent decodeTime(JsonNode node) throws DecodingException {
    SweTime swe = new SweTime();
    if (node.hasNonNull(JSONConstants.VALUE)) {
        String value = node.path(JSONConstants.VALUE).textValue();
        swe.setValue(parseDateTime(value));
    }
    return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime)

Aggregations

SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)24 XmlObject (org.apache.xmlbeans.XmlObject)11 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)8 SweField (org.n52.shetland.ogc.swe.SweField)7 ArrayList (java.util.ArrayList)4 DecodingException (org.n52.svalbard.decode.exception.DecodingException)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)3 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)3 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 CapabilityListType (net.opengis.sensorml.x20.CapabilityListType)2 Capability (net.opengis.sensorml.x20.CapabilityListType.Capability)2 CharacteristicListType (net.opengis.sensorml.x20.CharacteristicListType)2 Characteristic (net.opengis.sensorml.x20.CharacteristicListType.Characteristic)2 Capabilities (net.opengis.sensorml.x20.DescribedObjectType.Capabilities)2 DataRecordType (net.opengis.swe.x20.DataRecordType)2 DescribedObject (org.n52.shetland.ogc.sensorML.v20.DescribedObject)2 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)2 SweEnvelope (org.n52.shetland.ogc.swe.SweEnvelope)2