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);
}
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);
}
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;
}
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));
}
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;
}
Aggregations