use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.
the class OgcDecoderv100 method parseTemporalOperatorType.
/**
* parses a single temporal filter of the requests and returns SOS temporal filter
*
* @param xbBinaryTemporalOp XmlObject representing the temporal filter
*
* @return Returns SOS representation of temporal filter
*
* @throws DecodingException if parsing of the element failed
*/
private Object parseTemporalOperatorType(BinaryTemporalOpType xbBinaryTemporalOp) throws DecodingException {
TemporalFilter temporalFilter = new TemporalFilter();
// FIXME local workaround against SOSHelper check value reference
String valueRef = "phenomenonTime";
try {
NodeList nodes = xbBinaryTemporalOp.getDomNode().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
if (nodes.item(i).getNamespaceURI() != null && !nodes.item(i).getLocalName().equals(FilterConstants.EN_VALUE_REFERENCE)) {
// GML decoder will return TimeInstant or TimePriod
Object timeObject = decodeXmlElement(XmlObject.Factory.parse(nodes.item(i)));
if (timeObject instanceof PropertyNameType) {
PropertyNameType propType = (PropertyNameType) timeObject;
// TODO here apply logic for ogc property
// om:samplingTime etc
// valueRef = propType.getDomNode().getNodeValue();
}
if (timeObject instanceof Time) {
TimeOperator operator;
Time time = (Time) timeObject;
String localName = XmlHelper.getLocalName(xbBinaryTemporalOp);
// change to SOS 1.0. TMDuring kind of
if (localName.equals(TimeOperator.TM_During.name()) && time instanceof TimePeriod) {
operator = TimeOperator.TM_During;
} else if (localName.equals(TimeOperator.TM_Equals.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_Equals;
} else if (localName.equals(TimeOperator.TM_After.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_After;
} else if (localName.equals(TimeOperator.TM_Before.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_Before;
} else {
throw unsupportedTemporalFilterOperand();
}
temporalFilter.setOperator(operator);
temporalFilter.setTime(time);
// actually it should be eg om:samplingTime
temporalFilter.setValueReference(valueRef);
break;
}
}
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing temporal filter!", xmle);
}
return temporalFilter;
}
use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.
the class OmEncoderv100 method addResultTime.
private void addResultTime(ObservationType xbObs, OmObservation sosObservation) throws EncodingException {
Time phenomenonTime = sosObservation.getPhenomenonTime();
if (sosObservation.isSetResultTime()) {
if (sosObservation.getResultTime().equals(phenomenonTime)) {
xbObs.addNewResultTime().setHref("#".concat(phenomenonTime.getGmlId()));
} else {
TimeInstant resultTime = sosObservation.getResultTime();
if (!resultTime.isSetGmlId()) {
resultTime.setGmlId(RESULT_TIME_ID_PREFIX.concat(sosObservation.getObservationID()));
}
addResultTime(xbObs, resultTime);
}
} else {
if (phenomenonTime instanceof TimeInstant) {
xbObs.addNewResultTime().setHref("#".concat(phenomenonTime.getGmlId()));
} else if (phenomenonTime instanceof TimePeriod) {
TimeInstant resultTime = new TimeInstant(((TimePeriod) sosObservation.getPhenomenonTime()).getEnd());
resultTime.setGmlId(RESULT_TIME_ID_PREFIX + sosObservation.getObservationID());
addResultTime(xbObs, resultTime);
}
}
}
use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.
the class GmlEncoderv311 method createTimePeriodType.
/**
* Creates a XML TimePeriod from the SOS time object.
*
* @param timePeriod
* SOS time object
* @param timePeriodType
* the xml time period (may be {@code null})
* @return XML TimePeriod
*
* @throws EncodingException
* if an error occurs.
*/
private TimePeriodType createTimePeriodType(TimePeriod timePeriod, TimePeriodType timePeriodType) throws EncodingException {
try {
TimePeriodType tpt;
if (timePeriodType == null) {
tpt = TimePeriodType.Factory.newInstance(getXmlOptions());
} else {
tpt = timePeriodType;
}
if (timePeriod.getGmlId() != null && !timePeriod.getGmlId().isEmpty()) {
tpt.setId(timePeriod.getGmlId());
}
tpt.setBeginPosition(createTimePositionType(timePeriod.getStartTimePosition()));
tpt.setEndPosition(createTimePositionType(timePeriod.getEndTimePosition()));
return tpt;
} catch (XmlRuntimeException | XmlValueDisconnectedException x) {
throw new EncodingException("Error while creating TimePeriod!", x);
}
}
use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.
the class AqdEncoder method encodeGetObservationResponse.
private XmlObject encodeGetObservationResponse(GetObservationResponse response, EncodingContext ctx) throws EncodingException {
try {
FeatureCollection featureCollection = getFeatureCollection(response);
// TODO get FLOW from response
EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
TimePeriod timePeriod = new TimePeriod();
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
int counter = 1;
ObservationStream observationCollection = response.getObservationCollection();
while (observationCollection.hasNext()) {
OmObservation observation = observationCollection.next();
if (observation.getValue() instanceof ObservationStream) {
ObservationStream value = (ObservationStream) observation.getValue();
if (value instanceof StreamingValue) {
value = value.merge();
}
while (value.hasNext()) {
processObservation(value.next(), timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
} else {
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
return encodeObjectToXml(GmlConstants.NS_GML_32, featureCollection, ctx.with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT));
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.
the class AqdGetObservationResponseEncoder method create.
@Override
protected XmlObject create(GetObservationResponse response) throws EncodingException {
try {
FeatureCollection featureCollection = createFeatureCollection(response);
// TODO get FLOW from response
EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
TimePeriod timePeriod = new TimePeriod();
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
int counter = 1;
while (response.getObservationCollection().hasNext()) {
OmObservation observation = response.getObservationCollection().next();
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
EncodingContext ctx = EncodingContext.empty().with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
return encodeGml(ctx, featureCollection);
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
Aggregations