use of org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse in project arctic-sea by 52North.
the class GetDataAvailabilityXmlEncoder method create.
@Override
protected XmlObject create(GetDataAvailabilityResponse response) throws EncodingException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
EncodingContext ctx = EncodingContext.empty().with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
if (GetDataAvailabilityConstants.NS_GDA.equals(response.getResponseFormat())) {
new GetDataAvailabilityStreamWriter(ctx, baos, response.getDataAvailabilities()).write();
} else if (GetDataAvailabilityConstants.NS_GDA_20.equals(response.getResponseFormat())) {
new GetDataAvailabilityV20StreamWriter(ctx, baos, response.getDataAvailabilities()).write();
}
XmlObject encodedObject = XmlObject.Factory.parse(baos.toString("UTF8"));
XmlHelper.validateDocument(encodedObject, EncodingException::new);
return encodedObject;
} catch (XMLStreamException | XmlException | UnsupportedEncodingException ex) {
throw new EncodingException("Error encoding response", ex);
}
}
use of org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse in project arctic-sea by 52North.
the class GetDataAvailabilityJsonEncoder method encodeResponse.
@Override
protected void encodeResponse(ObjectNode json, GetDataAvailabilityResponse t) throws EncodingException {
ArrayNode a = json.putArray(GetDataAvailabilityConstants.DATA_AVAILABILITY);
for (DataAvailability da : t.getDataAvailabilities()) {
ObjectNode objectNode = a.addObject();
objectNode.put(JSONConstants.FEATURE_OF_INTEREST, da.getFeatureOfInterest().getHref()).put(JSONConstants.PROCEDURE, da.getProcedure().getHref()).put(JSONConstants.OBSERVED_PROPERTY, da.getObservedProperty().getHref()).set(JSONConstants.PHENOMENON_TIME, encodeObjectToJson(da.getPhenomenonTime()));
if (t.isSetResponseFormat() && GetDataAvailabilityConstants.NS_GDA_20.equals(t.getResponseFormat())) {
if (da.isSetOffering()) {
objectNode.put(JSONConstants.OFFERING, da.getOffering().getHref());
}
if (da.isSetFormatDescriptors()) {
ObjectNode fdNode = objectNode.putObject(GetDataAvailabilityConstants.FORMAT_DESCRIPTOR);
encodeProcedureFormatDescriptor(da.getFormatDescriptor().getProcedureDescriptionFormatDescriptor(), fdNode);
encodeObservationFormatDescriptor(da.getFormatDescriptor().getObservationFormatDescriptors(), fdNode);
}
}
if (da.isSetCount()) {
objectNode.put(JSONConstants.COUNT, da.getCount());
}
}
}
use of org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse in project arctic-sea by 52North.
the class GetDataAvailabilityResponseDecoder method decodeV20.
private GetDataAvailabilityResponse decodeV20(net.opengis.sosgda.x20.GetDataAvailabilityResponseDocument document) throws DecodingException {
GetDataAvailabilityResponse response = new GetDataAvailabilityResponse();
setService(response);
setVersions(response);
response.setNamespace(GetDataAvailabilityConstants.NS_GDA_20);
response.setDataAvailabilities(parseDataAvalabilities(document.getGetDataAvailabilityResponse()));
return response;
}
use of org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse in project arctic-sea by 52North.
the class GetDataAvailabilityResponseDecoder method decodeV10.
private GetDataAvailabilityResponse decodeV10(GetDataAvailabilityResponseDocument document) throws DecodingException {
GetDataAvailabilityResponse response = new GetDataAvailabilityResponse();
setService(response);
setVersions(response);
response.setNamespace(GetDataAvailabilityConstants.NS_GDA);
response.setDataAvailabilities(parseDataAvalabilities(document.getGetDataAvailabilityResponse()));
return response;
}
use of org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse in project arctic-sea by 52North.
the class GetDataAvailabilityXmlEncoderTest method test.
@Test
public void test() throws EncodingException {
GetDataAvailabilityResponse response = new GetDataAvailabilityResponse("SOS", "2.0.0");
response.setNamespace(GetDataAvailabilityConstants.NS_GDA);
DateTime begin = DateTime.now().withZone(DateTimeZone.UTC);
DateTime end = begin.plusHours(1).withZone(DateTimeZone.UTC);
TimePeriod timePeriod = new TimePeriod(begin, end);
ReferenceType procedure = new ReferenceType("procedure");
ReferenceType observedProperty = new ReferenceType("observedProperty");
ReferenceType featureOfInterest = new ReferenceType("featureOfInterest");
ReferenceType offering = new ReferenceType("offering");
int count = 100;
response.addDataAvailability(new DataAvailability(procedure, observedProperty, featureOfInterest, offering, timePeriod, count));
XmlObject encoded = encoder.encode(response);
System.out.println(encoded.xmlText());
errors.checkThat(encoded.xmlText(), is(String.format("<gda:GetDataAvailabilityResponse xsi:schemaLocation=\"http://www.opengis.net/sosgda/1.0 http://waterml2.org/schemas/gda/1.0/gda.xsd\" " + "xmlns:gda=\"http://www.opengis.net/sosgda/1.0\" " + "xmlns:gml=\"http://www.opengis.net/gml/3.2\" " + "xmlns:swe=\"http://www.opengis.net/swe/2.0\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + " <gda:dataAvailabilityMember gml:id=\"dam_1\">\n" + " <gda:procedure xlink:href=\"procedure\" xlink:title=\"procedure\"/>\n" + " <gda:observedProperty xlink:href=\"observedProperty\" xlink:title=\"observedProperty\"/>\n" + " <gda:featureOfInterest xlink:href=\"featureOfInterest\" xlink:title=\"featureOfInterest\"/>\n" + " <gda:phenomenonTime>\n" + " <gml:TimePeriod gml:id=\"tp_1\">\n" + " <gml:beginPosition>%s</gml:beginPosition>\n" + " <gml:endPosition>%s</gml:endPosition>\n" + " </gml:TimePeriod>\n" + " </gda:phenomenonTime>\n" + " <gda:count>100</gda:count>\n" + " <gda:extension>\n" + " <swe:Text definition=\"offering\">\n" + " <swe:value>offering</swe:value>\n" + " </swe:Text>\n" + " </gda:extension>\n" + " </gda:dataAvailabilityMember>\n" + "</gda:GetDataAvailabilityResponse>", begin.toString(ISODateTimeFormat.dateTime()), end.toString(ISODateTimeFormat.dateTime()))));
}
Aggregations