use of org.n52.shetland.ogc.swe.simpleType.SweBoolean in project arctic-sea by 52North.
the class SweCommonDecoderV101Test method should_decode_Boolean_with_Quality_Quantity.
@Test
public void should_decode_Boolean_with_Quality_Quantity() throws DecodingException {
final BooleanDocument xbBoolean = BooleanDocument.Factory.newInstance();
final BigDecimal quantityValue = BigDecimal.valueOf(42.5);
xbBoolean.addNewBoolean().addNewQuality().addNewQuantity().setValue(quantityValue.doubleValue());
final Object decodedObject = new SweCommonDecoderV101().decode(xbBoolean);
assertThat(decodedObject, is(instanceOf(SweBoolean.class)));
final SweBoolean sweBoolean = (SweBoolean) decodedObject;
assertThat(sweBoolean.isSetQuality(), is(true));
assertThat(sweBoolean.getQuality().size(), is(1));
assertThat(sweBoolean.getQuality().iterator().next(), is(instanceOf(SweQuantity.class)));
assertThat(((SweQuantity) sweBoolean.getQuality().iterator().next()).getValue(), is(quantityValue));
}
use of org.n52.shetland.ogc.swe.simpleType.SweBoolean 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.simpleType.SweBoolean in project arctic-sea by 52North.
the class SwesExtensionsTest method isBooleanExtensionSet_should_return_true_if_set_to_true.
@Test
public void isBooleanExtensionSet_should_return_true_if_set_to_true() {
final Extensions extensions = new Extensions();
extensions.addExtension(new SwesExtension<>().setDefinition(DEFINITION_1).setValue(new SweBoolean().setValue(TRUE)));
assertThat(extensions.getBooleanExtension(DEFINITION_1), is(TRUE));
}
use of org.n52.shetland.ogc.swe.simpleType.SweBoolean in project arctic-sea by 52North.
the class FieldDecoderTest method testBooleanWithValueFalse.
@Test
public void testBooleanWithValueFalse() throws DecodingException {
ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.BOOLEAN_TYPE).put(JSONConstants.VALUE, false);
SweField field = checkCommon(json, true);
assertThat(field.getElement(), is(instanceOf(SweBoolean.class)));
SweBoolean swe = (SweBoolean) field.getElement();
errors.checkThat(swe.getValue(), is(false));
}
use of org.n52.shetland.ogc.swe.simpleType.SweBoolean in project arctic-sea by 52North.
the class AbstractGmlDecoderv321 method parseNamedValueValue.
protected NamedValue<?> parseNamedValueValue(XmlObject xml) throws DecodingException {
XmlObject xmlObject = xml;
if (xmlObject.schemaType() == XmlAnyTypeImpl.type) {
try {
xmlObject = XmlObject.Factory.parse(xml.xmlText().trim());
} catch (XmlException e) {
LOGGER.error("Error while parsing NamedValueValue", e);
}
}
Object value;
if (XmlBoolean.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlBoolean) xmlObject).getBooleanValue();
} else if (XmlString.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlString) xmlObject).getStringValue();
} else if (XmlInt.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlInt) xmlObject).getIntValue();
} else if (XmlInteger.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlInteger) xmlObject).getBigIntegerValue().intValue();
} else if (XmlDouble.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
value = ((XmlDouble) xmlObject).getDoubleValue();
} else {
value = decodeXmlObject(xmlObject);
}
if (value instanceof BooleanValue) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue((BooleanValue) value);
return namedValue;
} else if (value instanceof SweBoolean) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue(new BooleanValue(((SweBoolean) value).getValue()));
return namedValue;
} else if (value instanceof Boolean) {
NamedValue<Boolean> namedValue = new NamedValue<>();
namedValue.setValue(new BooleanValue((Boolean) value));
return namedValue;
} else if (value instanceof CategoryValue) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue((CategoryValue) value);
return namedValue;
} else if (value instanceof SweCategory) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new CategoryValue(((SweCategory) value).getValue(), ((SweCategory) value).getCodeSpace()));
return namedValue;
} else if (value instanceof CountValue) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue((CountValue) value);
return namedValue;
} else if (value instanceof SweCount) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue(new CountValue(((SweCount) value).getValue()));
return namedValue;
} else if (value instanceof Integer) {
NamedValue<Integer> namedValue = new NamedValue<>();
namedValue.setValue(new CountValue((Integer) value));
return namedValue;
} else if (value instanceof GeometryValue) {
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setValue((GeometryValue) value);
return namedValue;
} else if (value instanceof QuantityValue) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue((QuantityValue) value);
return namedValue;
} else if (value instanceof GmlMeasureType) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue(((GmlMeasureType) value).getValue(), ((GmlMeasureType) value).getUnit()));
return namedValue;
} else if (value instanceof SweQuantity) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue(((SweQuantity) value).getValue(), ((SweQuantity) value).getUom()));
return namedValue;
} else if (value instanceof Double) {
NamedValue<BigDecimal> namedValue = new NamedValue<>();
namedValue.setValue(new QuantityValue((Double) value));
return namedValue;
} else if (value instanceof TextValue) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue((TextValue) value);
return namedValue;
} else if (value instanceof SweText) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new TextValue(((SweText) value).getValue()));
return namedValue;
} else if (value instanceof String) {
NamedValue<String> namedValue = new NamedValue<>();
namedValue.setValue(new TextValue((String) value));
return namedValue;
} else if (value instanceof AbstractGeometry) {
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setValue(new GeometryValue((AbstractGeometry) value));
return namedValue;
} else if (value instanceof org.n52.shetland.ogc.gml.ReferenceType) {
NamedValue<org.n52.shetland.ogc.gml.ReferenceType> namedValue = new NamedValue<>();
namedValue.setValue(new ReferenceValue((org.n52.shetland.ogc.gml.ReferenceType) value));
return namedValue;
} else if (value instanceof W3CHrefAttribute) {
NamedValue<W3CHrefAttribute> namedValue = new NamedValue<>();
namedValue.setValue(new HrefAttributeValue((W3CHrefAttribute) value));
return namedValue;
} else {
throw new UnsupportedDecoderInputException(this, xmlObject);
}
}
Aggregations