Search in sources :

Example 21 with SweDataRecord

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

the class SweCommonEncoderv20Test method shouldEncodeDataRecordWithSweTextField.

@Test
public void shouldEncodeDataRecordWithSweTextField() throws OwsExceptionReport, EncodingException {
    final SweDataRecord record = new SweDataRecord();
    record.addField(new SweField("text", new SweText().setValue("textValue").setDefinition("textDef")));
    record.addField(new SweField("count", new SweCount().setValue(2).setDefinition("countDef")));
    final XmlObject encoded = sweCommonEncoderv20.encode(record);
    // validateDocument throws exceptions if the document is invalid
    XmlHelper.validateDocument(encoded, EncodingException::new);
}
Also used : SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Example 22 with SweDataRecord

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

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

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

the class SweDataRecordTest method getFieldIndexByIdentifier_should_return_one.

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

Example 25 with SweDataRecord

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

the class ProfileLevel method valueAsDataRecord.

public SweDataRecord valueAsDataRecord(SweDataRecord dataRecord) {
    int counter = 0;
    for (Value<?> v : getValue()) {
        if (v instanceof SweAbstractDataComponent) {
            SweAbstractDataComponent adc = (SweAbstractDataComponent) v;
            String name;
            if (adc.isSetName()) {
                name = adc.getName().getValue();
            } else if (adc.isSetDefinition()) {
                name = adc.getDefinition();
            } else {
                name = "component_" + counter++;
            }
            dataRecord.addField(new SweField(name, adc));
        }
    }
    return dataRecord;
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent)

Aggregations

SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)29 SweField (org.n52.shetland.ogc.swe.SweField)21 XmlObject (org.apache.xmlbeans.XmlObject)14 Test (org.junit.Test)13 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)11 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)10 DataRecordType (net.opengis.swe.x101.DataRecordType)10 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)7 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)6 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)6 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)6 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)5 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)5 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)5 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)5 EncodingException (org.n52.svalbard.encode.exception.EncodingException)5 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 XmlException (org.apache.xmlbeans.XmlException)3 DateTime (org.joda.time.DateTime)3