use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class FieldDecoderTest method testQuantity.
@Test
public void testQuantity() throws DecodingException {
ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.QUANTITY_TYPE).put(JSONConstants.UOM, UOM);
SweField field = checkCommon(json, false);
assertThat(field.getElement(), is(instanceOf(SweQuantity.class)));
SweQuantity swe = (SweQuantity) field.getElement();
errors.checkThat(swe.getUom(), is(UOM));
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class InsertResultTemplateRequestDecoderTest method resultStructure.
@Test
public void resultStructure() throws IOException, DecodingException {
InsertResultTemplateRequest req = load();
assertThat(req.getResultStructure(), is(notNullValue()));
assertThat(req.getResultStructure().isDecoded(), is(true));
assertThat(req.getResultStructure().isEncoded(), is(false));
assertThat(req.getResultStructure().get().get(), is(instanceOf(SweDataRecord.class)));
SweDataRecord structure = (SweDataRecord) req.getResultStructure().get().get();
assertThat(structure.getFields(), is(notNullValue()));
assertThat(structure.getFields(), hasSize(3));
SweField field1 = structure.getFields().get(0);
assertThat(field1, is(notNullValue()));
errors.checkThat(field1.getName().getValue(), is("phenomenonTime"));
assertThat(field1.getElement(), is(instanceOf(SweTimeRange.class)));
SweTimeRange phenomenonTime = (SweTimeRange) field1.getElement();
errors.checkThat(phenomenonTime.getDefinition(), is("http://www.opengis.net/def/property/OGC/0/PhenomenonTime"));
errors.checkThat(phenomenonTime.getUom(), is("http://www.opengis.net/def/uom/ISO-8601/0/Gregorian"));
SweField field2 = structure.getFields().get(1);
assertThat(field2, is(notNullValue()));
errors.checkThat(field2.getName().getValue(), is("resultTime"));
assertThat(field2.getElement(), is(instanceOf(SweTime.class)));
SweTime resultTime = (SweTime) field2.getElement();
errors.checkThat(resultTime.getDefinition(), is("http://www.opengis.net/def/property/OGC/0/ResultTime"));
errors.checkThat(resultTime.getUom(), is("testunit1"));
SweField field3 = structure.getFields().get(2);
assertThat(field3, is(notNullValue()));
errors.checkThat(field3.getName().getValue(), is("observable_property_6"));
assertThat(field3.getElement(), is(instanceOf(SweQuantity.class)));
SweQuantity quantity = (SweQuantity) field3.getElement();
errors.checkThat(quantity.getDefinition(), is("http://www.52north.org/test/observableProperty/6"));
errors.checkThat(quantity.getUom(), is("test_unit_6"));
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class FieldEncoder method encodeSweQuantityField.
private ObjectNode encodeSweQuantityField(SweField field) {
ObjectNode jfield = createField(field);
jfield.put(JSONConstants.TYPE, JSONConstants.QUANTITY_TYPE);
SweQuantity sweQuantity = (SweQuantity) field.getElement();
if (sweQuantity.isSetValue()) {
jfield.put(JSONConstants.VALUE, sweQuantity.getValue());
}
jfield.put(JSONConstants.UOM, sweQuantity.getUom());
return jfield;
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class ObservationEncoder method getFieldForValue.
private SweField getFieldForValue(String phenomenon, Value<?> value) throws EncodingException {
final SweAbstractDataComponent def;
if (value instanceof BooleanValue) {
def = new SweBoolean();
} else if (value instanceof CategoryValue) {
SweCategory sweCategory = new SweCategory();
CategoryValue categoryValue = (CategoryValue) value;
sweCategory.setCodeSpace(categoryValue.getUnit());
def = sweCategory;
} else if (value instanceof CountValue) {
def = new SweCount();
} else if (value instanceof QuantityValue) {
SweQuantity sweQuantity = new SweQuantity();
QuantityValue quantityValue = (QuantityValue) value;
sweQuantity.setUom(quantityValue.getUnit());
def = sweQuantity;
} else if (value instanceof TextValue) {
def = new SweText();
} else if (value instanceof NilTemplateValue) {
def = new SweText();
} else if (value instanceof BooleanValue) {
def = new SweBoolean();
} else if (value instanceof GeometryValue) {
def = new SweText();
} else {
throw new UnsupportedEncoderInputException(this, value);
}
def.setDefinition(phenomenon);
return new SweField(phenomenon, def);
}
use of org.n52.shetland.ogc.swe.simpleType.SweQuantity in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createQuality.
private QualityPropertyType[] createQuality(Collection<SweQuality> quality) {
if (!quality.isEmpty()) {
ArrayList<QualityPropertyType> xbQualities = Lists.newArrayListWithCapacity(quality.size());
for (SweQuality sweQuality : quality) {
QualityPropertyType xbQuality = QualityPropertyType.Factory.newInstance();
if (sweQuality instanceof SweText) {
xbQuality.addNewText().set(createText((SweText) sweQuality));
} else if (sweQuality instanceof SweCategory) {
xbQuality.addNewCategory().set(createCategory((SweCategory) sweQuality));
} else if (sweQuality instanceof SweQuantity) {
xbQuality.addNewQuantity().set(createQuantity((SweQuantity) sweQuality));
} else if (sweQuality instanceof SweQuantityRange) {
xbQuality.addNewQuantityRange().set(createQuantityRange((SweQuantityRange) sweQuality));
}
xbQualities.add(xbQuality);
}
return xbQualities.toArray(new QualityPropertyType[xbQualities.size()]);
}
return new QualityPropertyType[] { QualityPropertyType.Factory.newInstance() };
}
Aggregations