use of org.n52.shetland.ogc.sos.SosResultEncoding in project arctic-sea by 52North.
the class InsertResultTemplateRequestDecoder method parseResultEncoding.
private SosResultEncoding parseResultEncoding(JsonNode node) {
SweTextEncoding textEncoding = new SweTextEncoding();
textEncoding.setTokenSeparator(node.path(JSONConstants.TOKEN_SEPARATOR).textValue());
textEncoding.setBlockSeparator(node.path(JSONConstants.BLOCK_SEPARATOR).textValue());
if (!node.path(JSONConstants.DECIMAL_SEPARATOR).isMissingNode()) {
textEncoding.setDecimalSeparator(node.path(JSONConstants.DECIMAL_SEPARATOR).textValue());
}
return new SosResultEncoding(textEncoding);
}
use of org.n52.shetland.ogc.sos.SosResultEncoding in project arctic-sea by 52North.
the class SosDecoderv20 method parseGetResultTemplateResponse.
private OwsServiceResponse parseGetResultTemplateResponse(final GetResultTemplateResponseDocument getResultTemplateResponseDoc) throws DecodingException {
final GetResultTemplateResponse sosGetResultTemplateResponse = new GetResultTemplateResponse();
final GetResultTemplateResponseType getResultTemplateResponse = getResultTemplateResponseDoc.getGetResultTemplateResponse();
final SosResultEncoding resultEncoding = parseResultEncoding(getResultTemplateResponse.getResultEncoding().getAbstractEncoding());
final SosResultStructure resultStructure = parseResultStructure(getResultTemplateResponse.getResultStructure().getAbstractDataComponent());
sosGetResultTemplateResponse.setResultEncoding(resultEncoding);
sosGetResultTemplateResponse.setResultStructure(resultStructure);
return sosGetResultTemplateResponse;
}
use of org.n52.shetland.ogc.sos.SosResultEncoding in project arctic-sea by 52North.
the class InsertResultTemplateRequestEncoderTest method setup.
@Before
public void setup() throws InvalidSridException, ParseException {
SensorML procedure = new SensorML();
procedure.setIdentifier(procedureIdentifier);
SamplingFeature featureOfInterest = new SamplingFeature(new CodeWithAuthority(featureIdentifier));
featureOfInterest.setIdentifier(featureIdentifier);
featureOfInterest.setName(new CodeType(featureName));
featureOfInterest.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT);
featureOfInterest.setGeometry(JTSHelper.createGeometryFromWKT("POINT(30 10)", 4326));
observationTemplate = new OmObservationConstellation();
observationTemplate.addOffering(offering);
observationTemplate.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
observationTemplate.setProcedure(procedure);
observationTemplate.setObservableProperty(new OmObservableProperty(observedProperty));
observationTemplate.setFeatureOfInterest(featureOfInterest);
SweTextEncoding textEncoding = new SweTextEncoding();
textEncoding.setBlockSeparator(blockSeparator);
textEncoding.setTokenSeparator(tokenSeparator);
SweDataRecord resultStructure = new SweDataRecord();
SweTime sweTime = new SweTime();
sweTime.setDefinition(field1Definition);
sweTime.setUom(field1Uom);
resultStructure.addField(new SweField(field1Name, sweTime));
request = new InsertResultTemplateRequest(SosConstants.SOS, Sos2Constants.SERVICEVERSION, Sos2Constants.Operations.InsertResultTemplate.name());
request.setResultEncoding(new SosResultEncoding(textEncoding));
request.setResultStructure(new SosResultStructure(resultStructure));
request.setIdentifier(templateIdentifier);
request.setObservationTemplate(observationTemplate);
Supplier<XmlOptions> xmlOptions = () -> new XmlOptions();
encoder = new InsertResultTemplateRequestEncoder();
encoder.setXmlOptions(xmlOptions);
OmEncoderv20 omEncoder = new OmEncoderv20();
omEncoder.setXmlOptions(xmlOptions);
SamplingEncoderv20 samsEncoder = new SamplingEncoderv20();
samsEncoder.setXmlOptions(xmlOptions);
GmlEncoderv321 gml32Encoder = new GmlEncoderv321();
gml32Encoder.setXmlOptions(xmlOptions);
SweCommonEncoderv20 sweEncoderv20 = new SweCommonEncoderv20();
sweEncoderv20.setXmlOptions(xmlOptions);
EncoderRepository encoderRepository = new EncoderRepository();
encoderRepository.setEncoders(Arrays.asList(encoder, omEncoder, samsEncoder, gml32Encoder, sweEncoderv20));
encoderRepository.init();
encoderRepository.getEncoders().stream().forEach(e -> ((AbstractDelegatingEncoder<?, ?>) e).setEncoderRepository(encoderRepository));
}
use of org.n52.shetland.ogc.sos.SosResultEncoding in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method encodeResultEncoding.
private void encodeResultEncoding(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
ObjectNode jre = json.putObject(JSONConstants.RESULT_ENCODING);
SweAbstractEncoding encoding = null;
SosResultEncoding re = t.getResultEncoding();
if (re.isDecoded()) {
encoding = t.getResultEncoding().get().get();
} else {
try {
XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractEncoding.class);
Decoder<SweAbstractEncoding, XmlObject> decoder = this.decoderRepository.getDecoder(key);
if (decoder == null) {
throw new NoDecoderForKeyException(key);
}
encoding = decoder.decode(XmlObject.Factory.parse(re.getXml().get()));
} catch (XmlException | DecodingException ex) {
throw new EncodingException(ex);
}
}
if (encoding instanceof SweTextEncoding) {
encodeSweTextEncoding(encoding, jre);
} else {
LOG.warn("Unsupported encoding: {}", encoding == null ? null : encoding.getClass());
}
}
use of org.n52.shetland.ogc.sos.SosResultEncoding in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method createResultEncoding.
private ResultEncoding createResultEncoding(SosResultEncoding resultEncoding) throws EncodingException {
// TODO move encoding to SWECommonEncoder
final TextEncodingDocument xbEncoding;
if (resultEncoding.isEncoded()) {
try {
xbEncoding = TextEncodingDocument.Factory.parse(resultEncoding.getXml().get());
} catch (XmlException ex) {
throw unsupportedResultEncoding(ex);
}
} else {
XmlObject xml = encodeSwe(EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT), resultEncoding.get().get());
if (xml instanceof TextEncodingDocument) {
xbEncoding = (TextEncodingDocument) xml;
} else {
throw unsupportedResultEncoding();
}
}
ResultEncoding xbResultEncoding = ResultEncoding.Factory.newInstance(getXmlOptions());
xbResultEncoding.addNewAbstractEncoding().set(xbEncoding.getTextEncoding());
XmlHelper.substituteElement(xbResultEncoding.getAbstractEncoding(), xbEncoding.getTextEncoding());
return xbResultEncoding;
}
Aggregations