use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class TimeJSONEncoder method encodeJSON.
@Override
public JsonNode encodeJSON(Time time) {
if (time instanceof TimeInstant) {
TimeInstant ti = (TimeInstant) time;
return nodeFactory().textNode(encodeTimePosition(ti.getTimePosition()));
}
if (time instanceof TimePeriod) {
TimePeriod tp = (TimePeriod) time;
ArrayNode a = nodeFactory().arrayNode();
a.add(encodeTimePosition(tp.getStartTimePosition()));
a.add(encodeTimePosition(tp.getEndTimePosition()));
return a;
} else {
return null;
}
}
use of org.n52.shetland.ogc.gml.time.TimeInstant 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.gml.time.TimeInstant in project arctic-sea by 52North.
the class TruthObservationDecodingTest method testObservation.
@Test
public void testObservation() {
assertThat(observation, is(notNullValue()));
final String type = observation.getObservationConstellation().getObservationType();
assertThat(type, is(equalTo(OmConstants.OBS_TYPE_TRUTH_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(BooleanValue.class)));
BooleanValue v = (BooleanValue) value.getValue();
assertThat(v.getValue(), is(true));
assertThat(v.getUnit(), is(nullValue()));
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class SosDecoderv20 method parseInsertObservation.
private OwsServiceRequest parseInsertObservation(final InsertObservationDocument insertObservationDoc) throws DecodingException {
// set namespace for default XML type (e.g. xs:string, xs:integer,
// xs:boolean, ...)
// Fix for problem with XmlBeans: namespace is not set in child elements
// when defined in root of request (SOAP)
final XmlCursor cursor = insertObservationDoc.newCursor();
if (cursor.toFirstChild() && cursor.namespaceForPrefix(W3CConstants.NS_XS_PREFIX) == null) {
cursor.prefixForNamespace(W3CConstants.NS_XS);
}
cursor.dispose();
final InsertObservationRequest insertObservationRequest = new InsertObservationRequest();
final InsertObservationType insertObservationType = insertObservationDoc.getInsertObservation();
insertObservationRequest.setService(insertObservationType.getService());
insertObservationRequest.setVersion(insertObservationType.getVersion());
if (insertObservationDoc.getInsertObservation().getOfferingArray() != null) {
insertObservationRequest.setOfferings(Arrays.asList(insertObservationType.getOfferingArray()));
}
insertObservationRequest.setExtensions(parseExtensibleRequest(insertObservationType));
if (insertObservationType.getObservationArray() != null) {
final int length = insertObservationType.getObservationArray().length;
final Map<String, Time> phenomenonTimes = new HashMap<>(length);
final Map<String, TimeInstant> resultTimes = new HashMap<>(length);
final Map<String, AbstractFeature> features = new HashMap<>(length);
CompositeException exceptions = new CompositeException();
for (final Observation observation : insertObservationType.getObservationArray()) {
final Object decodedObject = decodeXmlElement(observation.getOMObservation());
if (decodedObject instanceof OmObservation) {
final OmObservation sosObservation = (OmObservation) decodedObject;
checkAndAddPhenomenonTime(sosObservation.getPhenomenonTime(), phenomenonTimes);
checkAndAddResultTime(sosObservation.getResultTime(), resultTimes);
checkAndAddFeatures(sosObservation.getObservationConstellation().getFeatureOfInterest(), features);
insertObservationRequest.addObservation(sosObservation);
} else {
exceptions.add(new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested observation type (%s) is not supported by this server!", observation.getOMObservation().getDomNode().getNodeName()));
}
}
checkReferencedElements(insertObservationRequest.getObservations(), phenomenonTimes, resultTimes, features);
try {
exceptions.throwIfNotEmpty();
} catch (CompositeException ex) {
throw new DecodingException(ex, Sos2Constants.InsertObservationParams.observation);
}
} else {
// TODO MissingMandatoryParameterException?
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The request does not contain an observation");
}
return insertObservationRequest;
}
use of org.n52.shetland.ogc.gml.time.TimeInstant in project arctic-sea by 52North.
the class OmDecoderv20 method getPhenomenonTime.
private Time getPhenomenonTime(OMObservationType omObservation) throws DecodingException {
TimeObjectPropertyType phenomenonTime = omObservation.getPhenomenonTime();
if (phenomenonTime.isSetHref() && phenomenonTime.getHref().startsWith("#")) {
TimeInstant timeInstant = new TimeInstant();
timeInstant.setGmlId(phenomenonTime.getHref());
return timeInstant;
} else if (phenomenonTime.isSetNilReason() && phenomenonTime.getNilReason() instanceof String && ((String) phenomenonTime.getNilReason()).equals(IndeterminateValue.TEMPLATE.getValue())) {
return new TimeInstant(IndeterminateValue.TEMPLATE);
} else if (phenomenonTime.isSetAbstractTimeObject()) {
Object decodedObject = decodeXmlObject(phenomenonTime.getAbstractTimeObject());
if (decodedObject instanceof Time) {
return (Time) decodedObject;
}
// FIXME else
}
throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested phenomenonTime type is not supported by this service!");
}
Aggregations