use of org.n52.shetland.ogc.om.values.CountValue in project arctic-sea by 52North.
the class CountObservationDecodingTest method testObservation.
@Test
public void testObservation() {
assertThat(observation, is(notNullValue()));
final String type = observation.getObservationConstellation().getObservationType();
assertThat(type, is(equalTo(OmConstants.OBS_TYPE_COUNT_OBSERVATION)));
final ObservationValue<?> value = observation.getValue();
assertThat(value, is(instanceOf(SingleObservationValue.class)));
assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
assertThat(value.getValue(), is(instanceOf(CountValue.class)));
CountValue v = (CountValue) value.getValue();
assertThat(v.getValue(), is(1));
assertThat(v.getUnit(), is(nullValue()));
}
use of org.n52.shetland.ogc.om.values.CountValue in project arctic-sea by 52North.
the class ODataFesParserTest method testDisjunction.
@Test
@SuppressWarnings("unchecked")
public void testDisjunction() throws Exception {
Filter<?> filter = parser.decode("countValue lt 10 or textValue eq 'thetext'");
assertThat(filter, is(instanceOf(BinaryLogicFilter.class)));
BinaryLogicFilter blf = (BinaryLogicFilter) filter;
errors.checkThat(blf.getOperator(), is(BinaryLogicOperator.Or));
Set<Filter<?>> filterPredicates = blf.getFilterPredicates();
errors.checkThat(filterPredicates, Matchers.containsInAnyOrder(Matchers.instanceOf(ComparisonFilter.class), Matchers.instanceOf(ComparisonFilter.class)));
}
use of org.n52.shetland.ogc.om.values.CountValue 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.om.values.CountValue in project arctic-sea by 52North.
the class OmDecoderv20 method getResult.
private ObservationValue<?> getResult(OMObservationType omObservation) throws DecodingException {
XmlObject xbResult = omObservation.getResult();
if (xbResult.schemaType() == XmlAnyTypeImpl.type) {
// Template observation for InsertResultTemplate operation
if (!xbResult.getDomNode().hasChildNodes()) {
return new SingleObservationValue<>(new NilTemplateValue());
} else {
try {
xbResult = XmlObject.Factory.parse(xbResult.xmlText().trim());
} catch (XmlException e) {
LOGGER.error("Error while parsing NamedValueValue", e);
}
}
}
if (xbResult.schemaType() == XmlBoolean.type) {
// TruthObservation
XmlBoolean xbBoolean = (XmlBoolean) xbResult;
BooleanValue booleanValue = new BooleanValue(xbBoolean.getBooleanValue());
return new SingleObservationValue<>(booleanValue);
} else if (xbResult.schemaType() == XmlInteger.type) {
// CountObservation
XmlInteger xbInteger = (XmlInteger) xbResult;
CountValue countValue = new CountValue(Integer.parseInt(xbInteger.getBigIntegerValue().toString()));
return new SingleObservationValue<>(countValue);
} else if (xbResult.schemaType() == XmlString.type) {
// TextObservation
XmlString xbString = (XmlString) xbResult;
TextValue stringValue = new TextValue(xbString.getStringValue());
return new SingleObservationValue<>(stringValue);
} else {
// result elements with other encoding like SWE_ARRAY_OBSERVATION
Object decodedObject = decodeXmlObject(xbResult);
if (decodedObject instanceof ObservationValue) {
return (ObservationValue<?>) decodedObject;
} else if (decodedObject instanceof GmlMeasureType) {
GmlMeasureType measureType = (GmlMeasureType) decodedObject;
QuantityValue quantitiyValue = new QuantityValue(measureType.getValue(), measureType.getUnit());
return new SingleObservationValue<>(quantitiyValue);
} else if (decodedObject instanceof ReferenceType) {
if (omObservation.isSetType() && omObservation.getType().isSetHref() && omObservation.getType().getHref().equals(OmConstants.OBS_TYPE_REFERENCE_OBSERVATION)) {
return new SingleObservationValue<>(new ReferenceValue((ReferenceType) decodedObject));
}
return new SingleObservationValue<>(new CategoryValue(((ReferenceType) decodedObject).getHref()));
} else if (decodedObject instanceof Geometry) {
return new SingleObservationValue<>(new GeometryValue((Geometry) decodedObject));
} else if (decodedObject instanceof AbstractGeometry) {
SingleObservationValue<Geometry> result = new SingleObservationValue<>();
result.setValue(new GeometryValue(((AbstractGeometry) decodedObject).getGeometry()));
return result;
} else if (decodedObject instanceof SweDataArray) {
return new SingleObservationValue<>(new SweDataArrayValue((SweDataArray) decodedObject));
} else if (decodedObject instanceof SweDataRecord) {
return new SingleObservationValue<>(new ComplexValue((SweDataRecord) decodedObject));
}
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested result type '{}' is not supported by this service!", decodedObject.getClass().getSimpleName());
}
}
use of org.n52.shetland.ogc.om.values.CountValue in project arctic-sea by 52North.
the class AbstractCoverageEncoder method encodeValueList.
/**
* Encode value list of {@link RangeSetType} from {@link DiscreteCoverage}
*
* @param rst
* The {@link RangeSetType} to encode value list for
* @param discreteCoverage
* The {@link DiscreteCoverage} with the value list
* @throws EncodingException
* If an error occurs
*/
protected void encodeValueList(RangeSetType rst, DiscreteCoverage<?> discreteCoverage) throws EncodingException {
List<?> list = getList(discreteCoverage);
Value<?> value = discreteCoverage.getRangeSet().iterator().next();
if (value instanceof BooleanValue) {
BooleanListDocument bld = BooleanListDocument.Factory.newInstance(getXmlOptions());
bld.setBooleanList(list);
rst.set(bld);
} else if (value instanceof CategoryValue || value instanceof TextValue) {
DataBlockType dbt = rst.addNewDataBlock();
dbt.addNewRangeParameters().setHref(discreteCoverage.getRangeParameters());
CoordinatesType ct = dbt.addNewTupleList();
ct.setCs(",");
ct.setStringValue(Joiner.on(",").join(list));
} else if (value instanceof CountValue) {
CountListDocument cld = CountListDocument.Factory.newInstance(getXmlOptions());
cld.setCountList(list);
rst.set(cld);
} else if (value instanceof QuantityValue) {
QuantityListDocument qld = QuantityListDocument.Factory.newInstance(getXmlOptions());
MeasureOrNilReasonListType monrlt = qld.addNewQuantityList();
if (discreteCoverage.isSetUnit()) {
monrlt.setUom(discreteCoverage.getUnit());
} else if (value.isSetUnit()) {
monrlt.setUom(value.getUnit());
}
monrlt.setListValue(list);
rst.set(qld);
}
}
Aggregations