use of org.n52.shetland.ogc.sos.SosResultStructure in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method encodeResultStructure.
private void encodeResultStructure(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
ObjectNode jrs = json.putObject(JSONConstants.RESULT_STRUCTURE);
SweAbstractDataComponent structure;
SosResultStructure rs = t.getResultStructure();
if (rs.isDecoded()) {
structure = t.getResultStructure().get().get();
} else {
try {
XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractDataComponent.class);
Decoder<SweAbstractDataComponent, XmlObject> decoder = this.decoderRepository.getDecoder(key);
if (decoder == null) {
throw new NoDecoderForKeyException(key);
}
structure = decoder.decode(XmlObject.Factory.parse(rs.getXml().get()));
} catch (XmlException | DecodingException ex) {
throw new EncodingException(ex);
}
}
if (structure instanceof SweDataRecord) {
encodeSweDataRecord(structure, jrs);
} else {
LOG.warn("Unsupported structure: {}", structure == null ? null : structure.getClass());
}
}
use of org.n52.shetland.ogc.sos.SosResultStructure 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.SosResultStructure in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method createResultStructure.
private ResultStructure createResultStructure(SosResultStructure resultStructure) throws EncodingException {
// TODO move encoding to SWECommonEncoder
final DataRecordDocument dataRecordDoc;
if (resultStructure.isEncoded()) {
try {
dataRecordDoc = DataRecordDocument.Factory.parse(resultStructure.getXml().get());
} catch (XmlException ex) {
throw unsupportedResultStructure(ex);
}
} else {
XmlObject xml = encodeSwe(EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT), resultStructure.get().get());
if (xml instanceof DataRecordDocument) {
dataRecordDoc = (DataRecordDocument) xml;
} else {
throw unsupportedResultStructure();
}
}
ResultStructure xbResultStructure = ResultStructure.Factory.newInstance(getXmlOptions());
xbResultStructure.addNewAbstractDataComponent().set(dataRecordDoc.getDataRecord());
XmlHelper.substituteElement(xbResultStructure.getAbstractDataComponent(), dataRecordDoc.getDataRecord());
return xbResultStructure;
}
use of org.n52.shetland.ogc.sos.SosResultStructure 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.SosResultStructure in project arctic-sea by 52North.
the class InsertResultTemplateRequestEncoderTest method shouldThrowExceptionWhenResultEncodingIsMissing.
@Test
public void shouldThrowExceptionWhenResultEncodingIsMissing() throws EncodingException {
thrown.expect(UnsupportedEncoderInputException.class);
thrown.expectMessage(Is.is("Encoder " + InsertResultTemplateRequestEncoder.class.getSimpleName() + " can not encode 'missing resultEncoding'"));
request = new InsertResultTemplateRequest("service", "version");
request.setObservationTemplate(new OmObservationConstellation());
request.setResultStructure(new SosResultStructure(new SweDataRecord()));
OmObservationConstellation observationTemplate = new OmObservationConstellation();
observationTemplate.addOffering(offering);
request.setObservationTemplate(observationTemplate);
encoder.create(request);
}
Aggregations