use of org.geotoolkit.swe.xml.v101.DataRecordType in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTimeRange.
@Test
public void should_encode_Datarecord_with_fieldTimeRange() throws EncodingException {
final String field1Name = "test-name";
final RangeValue<DateTime> field1Value = new RangeValue<DateTime>();
final long now = System.currentTimeMillis();
final DateTime rangeStart = new DateTime(now - 1000);
final DateTime rangeEnd = new DateTime(now + 1000);
field1Value.setRangeStart(rangeStart);
field1Value.setRangeEnd(rangeEnd);
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTimeRange().setValue(field1Value))));
assertThat(encode, is(instanceOf(DataRecordType.class)));
final DataRecordType xbDataRecord = (DataRecordType) encode;
assertThat(xbDataRecord.getFieldArray().length, is(1));
final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
assertThat(field1.isSetTimeRange(), is(TRUE));
final DateTime xbTimeRangeStart = new DateTime(((XmlCalendar) field1.getTimeRange().getValue().get(0)).getTimeInMillis());
final DateTime xbTimeRangeEnd = new DateTime(((XmlCalendar) field1.getTimeRange().getValue().get(1)).getTimeInMillis());
assertThat(field1.getName(), is(field1Name));
assertThat(xbTimeRangeStart, is(field1Value.getRangeStart()));
assertThat(xbTimeRangeEnd, is(field1Value.getRangeEnd()));
}
use of org.geotoolkit.swe.xml.v101.DataRecordType in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldQuantity.
@Test
public void should_encode_Datarecord_with_fieldQuantity() throws EncodingException {
final String field1Name = "test-name";
final double field1Value = 52.0;
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweQuantity().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.isSetQuantity(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
assertThat(field1.getQuantity().getValue(), is(field1Value));
}
use of org.geotoolkit.swe.xml.v101.DataRecordType in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldCategory.
@Test
public void should_encode_Datarecord_with_fieldCategory() throws EncodingException {
final String field1Name = "test-name";
final String field1Value = "test-value";
final String codeSpace = "test-codespace";
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweCategory().setCodeSpace(codeSpace).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.isSetCategory(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
assertThat(field1.getCategory().getValue(), is(field1Value));
assertThat(field1.getCategory().getCodeSpace().getHref(), is(codeSpace));
}
use of org.geotoolkit.swe.xml.v101.DataRecordType in project arctic-sea by 52North.
the class SweCommonDecoderV20 method parseAbstractDataComponent.
private SweAbstractDataComponent parseAbstractDataComponent(AbstractDataComponentType abstractDataComponent) throws DecodingException {
SweAbstractDataComponent sosAbstractDataComponent = null;
if (abstractDataComponent instanceof BooleanType) {
sosAbstractDataComponent = parseBoolean((BooleanType) abstractDataComponent);
} else if (abstractDataComponent instanceof CategoryType) {
sosAbstractDataComponent = parseCategory((CategoryType) abstractDataComponent);
} else if (abstractDataComponent instanceof CountRangeType) {
sosAbstractDataComponent = parseCountRange((CountRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof CountType) {
sosAbstractDataComponent = parseCount((CountType) abstractDataComponent);
} else if (abstractDataComponent instanceof QuantityType) {
sosAbstractDataComponent = parseQuantity((QuantityType) abstractDataComponent);
} else if (abstractDataComponent instanceof QuantityRangeType) {
sosAbstractDataComponent = parseQuantityRange((QuantityRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof TextType) {
sosAbstractDataComponent = parseText((TextType) abstractDataComponent);
} else if (abstractDataComponent instanceof TimeType) {
sosAbstractDataComponent = parseTime((TimeType) abstractDataComponent);
} else if (abstractDataComponent instanceof TimeRangeType) {
sosAbstractDataComponent = parseTimeRange((TimeRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof VectorType) {
sosAbstractDataComponent = parseVector((VectorType) abstractDataComponent);
} else if (abstractDataComponent instanceof DataRecordType) {
SweDataRecord sosDataRecord = parseDataRecord((DataRecordType) abstractDataComponent);
DataRecordDocument dataRecordDoc = DataRecordDocument.Factory.newInstance(getXmlOptions());
dataRecordDoc.setDataRecord((DataRecordType) abstractDataComponent);
sosDataRecord.setXml(dataRecordDoc.xmlText(getXmlOptions()));
sosAbstractDataComponent = sosDataRecord;
} else if (abstractDataComponent instanceof DataArrayType) {
SweDataArray sosDataArray = parseDataArray((DataArrayType) abstractDataComponent);
DataArrayDocument dataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
dataArrayDoc.setDataArray1((DataArrayType) abstractDataComponent);
sosDataArray.setXml(dataArrayDoc.xmlText(getXmlOptions()));
sosAbstractDataComponent = sosDataArray;
} else if (abstractDataComponent == null) {
LOGGER.debug("abstractDataComponent is null");
} else {
throw new UnsupportedDecoderXmlInputException(this, abstractDataComponent);
}
if (sosAbstractDataComponent != null) {
if (abstractDataComponent.isSetDefinition()) {
sosAbstractDataComponent.setDefinition(abstractDataComponent.getDefinition());
}
if (abstractDataComponent.isSetDescription()) {
sosAbstractDataComponent.setDescription(abstractDataComponent.getDescription());
}
if (abstractDataComponent.isSetIdentifier()) {
sosAbstractDataComponent.setIdentifier(abstractDataComponent.getIdentifier());
}
if (abstractDataComponent.isSetLabel()) {
sosAbstractDataComponent.setLabel(abstractDataComponent.getLabel());
}
}
return sosAbstractDataComponent;
}
use of org.geotoolkit.swe.xml.v101.DataRecordType in project arctic-sea by 52North.
the class SweCommonEncoderv20 method asDocument.
private XmlObject asDocument(AbstractDataComponentType type) throws NotYetSupportedEncodingException {
if (type instanceof BooleanType) {
BooleanDocument document = BooleanDocument.Factory.newInstance();
document.setBoolean((BooleanType) type);
return document;
} else if (type instanceof CountType) {
CountDocument document = CountDocument.Factory.newInstance();
document.setCount((CountType) type);
return document;
} else if (type instanceof CountRangeType) {
CountRangeDocument document = CountRangeDocument.Factory.newInstance();
document.setCountRange((CountRangeType) type);
return document;
} else if (type instanceof QuantityType) {
QuantityDocument document = QuantityDocument.Factory.newInstance();
document.setQuantity((QuantityType) type);
return document;
} else if (type instanceof QuantityRangeType) {
QuantityRangeDocument document = QuantityRangeDocument.Factory.newInstance();
document.setQuantityRange((QuantityRangeType) type);
return document;
} else if (type instanceof TimeType) {
TimeDocument document = TimeDocument.Factory.newInstance();
document.setTime((TimeType) type);
return document;
} else if (type instanceof TimeRangeType) {
TimeRangeDocument document = TimeRangeDocument.Factory.newInstance();
document.setTimeRange((TimeRangeType) type);
return document;
} else if (type instanceof CategoryType) {
CategoryDocument document = CategoryDocument.Factory.newInstance();
document.setCategory((CategoryType) type);
return document;
} else if (type instanceof CategoryRangeType) {
CategoryRangeDocument document = CategoryRangeDocument.Factory.newInstance();
document.setCategoryRange((CategoryRangeType) type);
return document;
} else if (type instanceof MatrixType) {
MatrixDocument document = MatrixDocument.Factory.newInstance();
document.setMatrix((MatrixType) type);
return document;
} else if (type instanceof DataArrayType) {
DataArrayDocument document = DataArrayDocument.Factory.newInstance();
document.setDataArray1((DataArrayType) type);
return document;
} else if (type instanceof DataChoiceType) {
DataChoiceDocument document = DataChoiceDocument.Factory.newInstance();
document.setDataChoice((DataChoiceType) type);
return document;
} else if (type instanceof DataRecordType) {
DataRecordDocument document = DataRecordDocument.Factory.newInstance();
document.setDataRecord((DataRecordType) type);
return document;
} else if (type instanceof TextType) {
TextDocument document = TextDocument.Factory.newInstance();
document.setText((TextType) type);
return document;
} else if (type instanceof VectorType) {
VectorDocument document = VectorDocument.Factory.newInstance();
document.setVector((VectorType) type);
return document;
} else {
throw new NotYetSupportedEncodingException(type.getClass().getName(), type);
}
}
Aggregations