use of org.n52.svalbard.encode.exception.EncodingException 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.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GetObservationByIdResponseEncoder method createResponse.
@Override
protected XmlObject createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationByIdResponse response) throws EncodingException {
GetObservationByIdResponseDocument doc = GetObservationByIdResponseDocument.Factory.newInstance(getXmlOptions());
GetObservationByIdResponseType xbResponse = doc.addNewGetObservationByIdResponse();
ObservationStream observations = getObservationsAndCheckForStreaming(response, encoder);
HashMap<CodeWithAuthority, String> gmlID4sfIdentifier = new HashMap<>();
try {
while (observations.hasNext()) {
OmObservation observation = observations.next();
EncodingContext codingContext = EncodingContext.empty();
CodeWithAuthority foiId = observation.getObservationConstellation().getFeatureOfInterest().getIdentifierCodeWithAuthority();
if (gmlID4sfIdentifier.containsKey(foiId)) {
codingContext = codingContext.with(XmlBeansEncodingFlags.EXIST_FOI_IN_DOC, true);
} else {
gmlID4sfIdentifier.put(foiId, GML_ID);
codingContext = codingContext.with(XmlBeansEncodingFlags.EXIST_FOI_IN_DOC, false);
}
codingContext = codingContext.with(XmlBeansEncodingFlags.GMLID, gmlID4sfIdentifier.get(foiId));
xbResponse.addNewObservation().addNewOMObservation().set(encoder.encode(observation, codingContext));
}
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
XmlHelper.makeGmlIdsUnique(xbResponse.getDomNode());
return doc;
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GetObservationResponseEncoder method createResponse.
@Override
protected void createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationResponse response, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
try {
EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions).with(StreamingEncoderFlags.ENCODER, this);
new GetObservationResponseXmlStreamWriter(context, outputStream, response).write();
} catch (XMLStreamException xmlse) {
throw new EncodingException(xmlse);
}
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class GetObservationResponseEncoder method createResponse.
@Override
protected XmlObject createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationResponse response) throws EncodingException {
try {
GetObservationResponseDocument doc = GetObservationResponseDocument.Factory.newInstance(getXmlOptions());
GetObservationResponseType xbResponse = doc.addNewGetObservationResponse();
ObservationStream observationCollection = response.getObservationCollection();
while (observationCollection.hasNext()) {
xbResponse.addNewObservationData().addNewOMObservation().set(encoder.encode(observationCollection.next()));
}
// in a single observation the gml:ids must be unique
XmlHelper.makeGmlIdsUnique(doc.getDomNode());
return doc;
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.svalbard.encode.exception.EncodingException in project arctic-sea by 52North.
the class OwsEncoderv110 method encodeOperationsMetadata.
private OperationsMetadata encodeOperationsMetadata(OwsOperationsMetadata om) throws EncodingException {
OperationsMetadata xom = OperationsMetadata.Factory.newInstance(getXmlOptions());
om.getOperations().forEach(x -> encodeOwsOperation(x, xom.addNewOperation()));
om.getConstraints().forEach(x -> encodeOwsDomain(x, xom.addNewConstraint()));
om.getParameters().forEach(x -> encodeOwsDomain(x, xom.addNewParameter()));
if (om.getExtension().isPresent()) {
xom.setExtendedCapabilities(encodeOwsOperationsMetadataExtension(om.getExtension().get()));
}
return xom;
}
Aggregations