use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.
the class SensorMLEncoderv20 method createComponents.
/**
* Creates the components section of the SensorML description.
*
* @param sosComponents
* SOS SWE representation.
*
* @return encoded sml:components
*
* @throws EncodingException
* if the process encoding fails
*/
private ComponentListPropertyType createComponents(final List<SmlComponent> sosComponents) throws EncodingException {
ComponentListPropertyType clpt = ComponentListPropertyType.Factory.newInstance(getXmlOptions());
final ComponentListType clt = clpt.addNewComponentList();
for (final SmlComponent sosSMLComponent : sosComponents) {
final Component component = clt.addNewComponent();
if (sosSMLComponent.isSetName()) {
component.setName(sosSMLComponent.getName());
}
if (sosSMLComponent.isSetHref()) {
component.setHref(sosSMLComponent.getHref());
if (sosSMLComponent.isSetTitle()) {
component.setTitle(sosSMLComponent.getTitle());
}
} else if (sosSMLComponent.isSetProcess()) {
XmlObject xmlObject = encode(sosSMLComponent.getProcess(), EncodingContext.of(XmlBeansEncodingFlags.TYPE));
// }
if (xmlObject != null) {
// AbstractProcessType xbProcess = null;
// if (xmlObject instanceof AbstractProcessType) {
// xbProcess = (AbstractProcessType) xmlObject;
// } else {
// throw new NoApplicableCodeException()
// .withMessage("The sensor type is not supported by this
// SOS");
// }
// TODO add feature/parentProcs/childProcs to component - is
// this already done?
// XmlObject substituteElement =
// XmlHelper.substituteElement(component.addNewAbstractProcess(),
// xmlObject);
// substituteElement.set(xmlObject);
substitute(component.addNewAbstractProcess(), xmlObject);
}
}
}
return clpt;
}
use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.
the class WmlTVPEncoderv20 method addValues.
private String addValues(MeasurementTimeseriesType measurementTimeseries, ObservationValue<?> observationValue) throws CodedException {
String unit = null;
if (observationValue instanceof SingleObservationValue) {
SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
String time = getTimeString(singleObservationValue.getPhenomenonTime());
unit = singleObservationValue.getValue().getUnit();
String value = null;
if (singleObservationValue.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) singleObservationValue.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (singleObservationValue.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) singleObservationValue.getValue();
if (countValue.getValue() != null) {
value = Integer.toString(countValue.getValue());
}
} else if (singleObservationValue.getValue() instanceof ProfileValue) {
ProfileValue profileValue = (ProfileValue) singleObservationValue.getValue();
if (profileValue.isSetValue()) {
if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
if (quantityValue.isSetValue()) {
value = Double.toString(quantityValue.getValue().doubleValue());
}
}
}
}
addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
} else if (observationValue instanceof MultiObservationValues) {
MultiObservationValues<?> mov = (MultiObservationValues<?>) observationValue;
TVPValue tvpValue = (TVPValue) mov.getValue();
List<TimeValuePair> timeValuePairs = tvpValue.getValue();
unit = tvpValue.getUnit();
for (TimeValuePair timeValuePair : timeValuePairs) {
String time = getTimeString(timeValuePair.getTime());
String value = null;
if (timeValuePair.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) timeValuePair.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (timeValuePair.getValue() instanceof ProfileValue) {
ProfileValue profileValue = (ProfileValue) timeValuePair.getValue();
if (profileValue.isSetValue()) {
if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
if (quantityValue.isSetValue()) {
value = Double.toString(quantityValue.getValue().doubleValue());
}
}
}
} else if (timeValuePair.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) timeValuePair.getValue();
if (countValue.isSetValue()) {
value = Integer.toString(countValue.getValue());
}
} else {
throw new NoApplicableCodeException().withMessage("The types of values '%s' is not yet supported", mov.getValue().getClass().getSimpleName());
}
addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
}
}
return unit;
}
use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.
the class OwsEncoderv110Test method generateException.
private NoApplicableCodeException generateException() {
final NoApplicableCodeException nace = new NoApplicableCodeException();
nace.setVersion(Sos2Constants.SERVICEVERSION);
return nace;
}
use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.
the class SimpleBinding method encodeResponse.
protected Object encodeResponse(OwsServiceResponse response, MediaType contentType) throws OwsExceptionReport {
try {
OperationResponseEncoderKey key = new OperationResponseEncoderKey(new OwsOperationKey(response), contentType);
Encoder<Object, OwsServiceResponse> encoder = getEncoder(key);
if (encoder == null) {
throw new NoEncoderForKeyException(key);
}
return encoder.encode(response);
} catch (EncodingException ex) {
throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
}
}
use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.
the class EXIBinding method decode.
/**
* Parse the incoming EXI encoded {@link InputStream} transform to
* {@link XmlObject}
*
* @param request
* {@link HttpServletRequest} with EXI encoded
* {@link InputStream}
* @return {@link XmlObject} created from the EXI encoded
* {@link InputStream}
* @throws OwsExceptionReport
* If an error occurs during parsing
*/
protected XmlObject decode(HttpServletRequest request) throws OwsExceptionReport {
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
EXIFactory ef = this.exiUtils.newEXIFactory();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
if (ef.isFragment()) {
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
}
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
// decode EXI encoded InputStream
EXISource exiSource = new EXISource(ef);
XMLReader exiReader = exiSource.getXMLReader();
InputSource inputSource = new InputSource(request.getInputStream());
inputSource.setEncoding(request.getCharacterEncoding());
SAXSource saxSource = new SAXSource(inputSource);
saxSource.setXMLReader(exiReader);
transformer.transform(saxSource, new StreamResult(os));
// create XmlObject from OutputStream
return XmlHelper.parseXmlString(os.toString(StandardCharsets.UTF_8.name()));
} catch (IOException | EXIException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while reading request! Message: %s", ex.getMessage());
} catch (TransformerException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while transforming request! Message: %s", ex.getMessage());
} catch (DecodingException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while parsing request! Message: %s", ex.getMessage());
}
}
Aggregations