use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTime.
@Test
public void should_encode_Datarecord_with_fieldTime() throws EncodingException {
final String field1Name = "test-name";
final DateTime field1Value = new DateTime(System.currentTimeMillis());
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTime().setValue(field1Value))));
assertThat(encode, is(instanceOf(DataRecordType.class)));
final DataRecordType xbDataRecord = (DataRecordType) encode;
final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
assertThat(xbDataRecord.getFieldArray().length, is(1));
assertThat(field1.isSetTime(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
final DateTime xbTime = new DateTime(((XmlCalendar) field1.getTime().getValue()).getTimeInMillis(), DateTimeZone.UTC);
assertThat(xbTime.toDateTime(field1Value.getZone()), is(field1Value));
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_fieldQuantity.
@Test
public void should_encode_simpleDatarecord_with_fieldQuantity() throws EncodingException {
final String name = "field-1";
final double value = 42.5;
final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(name, new SweQuantity().setValue(value))));
assertThat(encode, instanceOf(SimpleDataRecordType.class));
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
assertThat(xbSimpleDataRecord.getFieldArray().length, is(1));
assertThat(field1.getName(), is(name));
assertThat(field1.isSetQuantity(), is(TRUE));
assertThat(field1.getQuantity().getValue(), is(value));
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_simpleDataRecordWithFields.
@Test
public void should_encode_simpleDataRecordWithFields() throws EncodingException {
final String field0Value = "field-0-value";
final String field0Name = "field-0";
final String field1Name = "field-1";
final Boolean field1Value = Boolean.TRUE;
final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(field0Name, new SweText().setValue(field0Value))).addField(new SweField(field1Name, new SweBoolean().setValue(field1Value))));
assertThat(encode, instanceOf(SimpleDataRecordType.class));
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
final AnyScalarPropertyType field0 = xbSimpleDataRecord.getFieldArray(0);
final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(1);
assertThat(xbSimpleDataRecord.getFieldArray().length, is(2));
assertThat(field0.isSetText(), is(TRUE));
assertThat(field0.getName(), is(field0Name));
assertThat(field0.getText().getValue(), is(field0Value));
assertThat(field1.isSetBoolean(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
assertThat(field1.getBoolean().getValue(), is(field1Value));
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createField.
private DataComponentPropertyType createField(SweField sweField) throws EncodingException {
SweAbstractDataComponent sosElement = sweField.getElement();
DataComponentPropertyType xbField = DataComponentPropertyType.Factory.newInstance(getXmlOptions());
if (sweField.isSetName()) {
xbField.setName(sweField.getName().getValue());
}
if (sosElement instanceof SweBoolean) {
xbField.addNewBoolean().set(createSimpleType((SweBoolean) sosElement));
} else if (sosElement instanceof SweCategory) {
xbField.addNewCategory().set(createSimpleType((SweCategory) sosElement));
} else if (sosElement instanceof SweCount) {
xbField.addNewCount().set(createSimpleType((SweCount) sosElement));
} else if (sosElement instanceof SweCountRange) {
xbField.addNewCount().set(createSimpleType((SweCountRange) sosElement));
} else if (sosElement instanceof SweQuantity) {
xbField.addNewQuantity().set(createSimpleType((SweQuantity) sosElement));
} else if (sosElement instanceof SweQuantityRange) {
xbField.addNewQuantity().set(createSimpleType((SweQuantityRange) sosElement));
} else if (sosElement instanceof SweText) {
xbField.addNewText().set(createSimpleType((SweText) sosElement));
} else if (sosElement instanceof SweTimeRange) {
xbField.addNewTimeRange().set(createSimpleType((SweTimeRange) sosElement));
} else if (sosElement instanceof SweTime) {
xbField.addNewTime().set(createSimpleType((SweTime) sosElement));
} else if (sosElement instanceof SweEnvelope) {
EnvelopeType xbEnvelope = (EnvelopeType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_ENVELOPE_SWE_101, EnvelopeType.type);
xbEnvelope.set(createEnvelope((SweEnvelope) sosElement));
} else if (sosElement instanceof SweDataRecord) {
DataRecordType xbEnvelope = (DataRecordType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataRecordType.type);
xbEnvelope.set(createDataRecord((SweDataRecord) sosElement));
} else if (sosElement instanceof SweDataArray) {
DataArrayType xbEnvelope = (DataArrayType) xbField.addNewAbstractDataRecord().substitute(SweConstants.QN_DATA_RECORD_SWE_101, DataArrayType.type);
xbEnvelope.set(createDataArray((SweDataArray) sosElement).getDataArray1());
} else {
throw new EncodingException("The element type '%s' of the received '%s' is not supported by this encoder '%s'.", new Object[] { sosElement != null ? sosElement.getClass().getName() : null, sweField.getClass().getName(), getClass().getName() });
}
return xbField;
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SensorMLEncoderv101 method createCharacteristics.
/**
* Creates the characteristics section of the SensorML description.
*
* @param smlCharacteristics
* SOS characteristics list
*
* @return XML Characteristics array
*
* @throws EncodingException
* If an error occurs
*/
private Characteristics[] createCharacteristics(final List<SmlCharacteristics> smlCharacteristics) throws EncodingException {
final List<Characteristics> characteristicsList = Lists.newArrayListWithExpectedSize(smlCharacteristics.size());
for (final SmlCharacteristics sosSMLCharacteristics : smlCharacteristics) {
final Characteristics xbCharacteristics = Characteristics.Factory.newInstance(getXmlOptions());
if (sosSMLCharacteristics.isSetName()) {
xbCharacteristics.setName(sosSMLCharacteristics.getName());
}
if (sosSMLCharacteristics.isSetAbstractDataRecord()) {
if (sosSMLCharacteristics.getDataRecord() instanceof SweSimpleDataRecord) {
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) xbCharacteristics.addNewAbstractDataRecord().substitute(SweConstants.QN_SIMPLEDATARECORD_SWE_101, SimpleDataRecordType.type);
if (sosSMLCharacteristics.isSetTypeDefinition()) {
xbSimpleDataRecord.setDefinition(sosSMLCharacteristics.getTypeDefinition());
}
if (sosSMLCharacteristics.getDataRecord().isSetFields()) {
for (final SweField field : sosSMLCharacteristics.getDataRecord().getFields()) {
final AnyScalarPropertyType xbField = xbSimpleDataRecord.addNewField();
xbField.setName(field.getName().getValue());
addSweSimpleTypeToField(xbField, field.getElement());
}
}
} else if (sosSMLCharacteristics.getDataRecord() instanceof SweDataRecord) {
throw unsupportedCharacteristicsType(SweAggregateType.DataRecord);
} else {
throw unsupportedCharacteristicsType(sosSMLCharacteristics.getDataRecord().getClass().getName());
}
} else if (sosSMLCharacteristics.isSetHref()) {
if (sosSMLCharacteristics.isSetName()) {
xbCharacteristics.setName(sosSMLCharacteristics.getName());
}
xbCharacteristics.setHref(sosSMLCharacteristics.getHref());
if (sosSMLCharacteristics.isSetTitle()) {
xbCharacteristics.setTitle(sosSMLCharacteristics.getTitle());
}
}
characteristicsList.add(xbCharacteristics);
}
return characteristicsList.toArray(new Characteristics[characteristicsList.size()]);
}
Aggregations