use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class GetObservationResponseXmlStreamWriter method writeGetObservationResponseDoc.
private void writeGetObservationResponseDoc() throws XMLStreamException, EncodingException {
start(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
namespace(W3CConstants.NS_XLINK_PREFIX, W3CConstants.NS_XLINK);
namespace(SosConstants.NS_SOS_PREFIX, Sos2Constants.NS_SOS_20);
GetObservationResponse response = getElement();
// get observation encoder
ObservationEncoder<XmlObject, OmObservation> encoder = findObservationEncoder(response.getResponseFormat());
// write schemaLocation
schemaLocation(getSchemaLocation(encoder));
EncodingContext ctx = getContext().with(XmlEncoderFlags.ENCODE_NAMESPACE, response.getResponseFormat()).with(XmlBeansEncodingFlags.DOCUMENT).with(StreamingEncoderFlags.EMBEDDED).without(XmlBeansEncodingFlags.PROPERTY_TYPE).without(XmlBeansEncodingFlags.TYPE);
try {
ObservationStream stream = response.getObservationCollection();
if (encoder.shouldObservationsWithSameXBeMerged()) {
stream = stream.merge();
}
while (stream.hasNext()) {
OmObservation o = stream.next();
if (o.getValue() instanceof ObservationStream) {
ObservationStream value = (ObservationStream) o.getValue();
if (encoder.supportsResultStreamingForMergedValues()) {
writeObservationData(ctx, o, encoder);
} else {
while (value.hasNext()) {
writeObservationData(ctx, value.next(), encoder);
}
}
} else {
writeObservationData(ctx, o, encoder);
}
}
} catch (OwsExceptionReport owse) {
throw new EncodingException(owse);
}
end(Sos2StreamingConstants.GET_OBSERVATION_RESPONSE);
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class WmlTVPEncoderv20XmlStreamWriter method writeInterpolationType.
/**
* Write wml:interpolationType to stream
*
* @throws XMLStreamException
* If an error occurs when writing to stream
*/
private void writeInterpolationType(ObservationValue<?> value) throws XMLStreamException {
empty(WaterMLConstants.QN_INTERPOLATION_TYPE);
if (value != null && value.isSetMetadata() && value.getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && value.getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) {
InterpolationType interpolationtype = value.getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().getInterpolationtype();
addXlinkHrefAttr(interpolationtype.getIdentifier());
addXlinkTitleAttr(interpolationtype.getTitle());
} else {
addXlinkHrefAttr("http://www.opengis.net/def/timeseriesType/WaterML/2.0/continuous");
addXlinkTitleAttr("Instantaneous");
}
}
use of org.n52.shetland.ogc.om.values.Value in project series-rest-api by 52North.
the class MultipleChartsRenderer method writeDataToChart.
@Override
public void writeDataToChart(DataCollection<QuantityData> data) {
Map<String, QuantityData> allTimeseries = data.getAllSeries();
List<? extends DatasetOutput> timeseriesMetadatas = getMetadataOutputs();
int rendererCount = timeseriesMetadatas.size();
for (int rendererIndex = 0; rendererIndex < timeseriesMetadatas.size(); rendererIndex++) {
/*
* For each index put data and its renderer configured to a particular style.
*
* As each timeseries may define its custom styling and different chart types we have to loop over
* all timeseries to configure chart rendering.
*/
DatasetOutput timeseriesMetadata = timeseriesMetadatas.get(rendererIndex);
String timeseriesId = timeseriesMetadata.getId();
StyleProperties style = getTimeseriesStyleFor(timeseriesId);
QuantityData timeseriesData = allTimeseries.get(timeseriesId);
String chartId = createChartId(timeseriesMetadata);
ChartIndexConfiguration configuration = new ChartIndexConfiguration(chartId, rendererIndex);
configuration.setData(timeseriesData, timeseriesMetadata, style);
configuration.setRenderer(createRenderer(style));
if (timeseriesData.hasReferenceValues()) {
int referenceIndex = rendererCount;
/*
* Configure timeseries reference value renderers with the same metadata and add it at the end
* of the plot's renderer list.
*/
QuantityDatasetMetadata metadata = timeseriesData.getMetadata();
Map<String, QuantityData> referenceValues = metadata.getReferenceValues();
for (Entry<String, QuantityData> referencedTimeseries : referenceValues.entrySet()) {
String referenceTimeseriesId = referencedTimeseries.getKey();
ReferenceValueOutput referenceOutput = getReferenceValue(referenceTimeseriesId, timeseriesMetadata);
String referenceChartId = createChartId(timeseriesMetadata, referenceOutput.getLabel());
QuantityData referenceData = referenceValues.get(referenceTimeseriesId);
ChartIndexConfiguration referenceConfiguration = new ChartIndexConfiguration(referenceChartId, referenceIndex);
StyleProperties referenceStyle = getTimeseriesStyleFor(timeseriesId, referenceTimeseriesId);
referenceConfiguration.setReferenceData(referenceData, timeseriesMetadata, referenceStyle);
referenceConfiguration.setRenderer(createRenderer(referenceStyle));
referenceIndex++;
}
}
}
}
use of org.n52.shetland.ogc.om.values.Value in project series-rest-api by 52North.
the class BaseController method handleException.
@ExceptionHandler(value = { RuntimeException.class, Exception.class, Throwable.class })
public void handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
if (e instanceof HttpMessageNotReadableException) {
WebException wrappedException = new BadRequestException("The request could not been read.", e);
wrappedException.addHint("Check the message which has been sent to the server. Probably it is not valid.");
writeExceptionResponse(wrappedException, response, HttpStatus.BAD_REQUEST);
} else {
WebException wrappedException = new InternalServerException("Unexpected Exception occured.", e);
writeExceptionResponse(wrappedException, response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.n52.shetland.ogc.om.values.Value in project series-rest-api by 52North.
the class DataController method getSeriesCollectionChart.
@RequestMapping(value = "/data", produces = { "image/png" }, method = RequestMethod.POST)
public void getSeriesCollectionChart(HttpServletResponse response, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestBody RequestStyledParameterSet parameters) throws Exception {
RequestUtils.overrideQueryLocaleWhenSet(locale, parameters);
IoParameters map = QueryParameters.createFromQuery(parameters);
checkForUnknownDatasetIds(map, parameters.getDatasets());
LOGGER.debug("get data collection chart with query: {}", map);
final String datasetType = parameters.getValueType();
String outputFormat = MimeType.IMAGE_PNG.toString();
response.setContentType(outputFormat);
createIoFactory(datasetType).withStyledRequest(parameters).createHandler(outputFormat).writeBinary(response.getOutputStream());
}
Aggregations