use of org.n52.io.request.IoParameters in project series-rest-api by 52North.
the class DataController method getSeriesChart.
@RequestMapping(value = "/{seriesId}/data", produces = { "image/png" }, method = RequestMethod.GET)
public void getSeriesChart(HttpServletResponse response, @PathVariable String seriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
RequestUtils.overrideQueryLocaleWhenSet(locale, query);
IoParameters map = QueryParameters.createFromQuery(query);
LOGGER.debug("get data collection chart for '{}' with query: {}", seriesId, map);
checkAgainstTimespanRestriction(map.getTimespan().toString());
checkForUnknownDatasetIds(map, seriesId);
String handleAsValueTypeFallback = map.getAsString(Parameters.HANDLE_AS_VALUE_TYPE);
String valueType = ValueType.extractType(seriesId, handleAsValueTypeFallback);
RequestSimpleParameterSet parameters = map.toSimpleParameterSet();
String outputFormat = MimeType.IMAGE_PNG.toString();
response.setContentType(outputFormat);
createIoFactory(valueType).withSimpleRequest(parameters).createHandler(outputFormat).writeBinary(response.getOutputStream());
}
use of org.n52.io.request.IoParameters in project series-rest-api by 52North.
the class ParameterController method getRawData.
@Override
public void getRawData(HttpServletResponse response, String id, String locale, MultiValueMap<String, String> query) {
RequestUtils.overrideQueryLocaleWhenSet(locale, query);
if (!getParameterService().supportsRawData()) {
throw new BadRequestException("Querying raw procedure data is not supported!");
}
IoParameters queryMap = QueryParameters.createFromQuery(query);
LOGGER.debug("getRawData() with id '{}' and query '{}'", id, queryMap);
try (InputStream inputStream = getParameterService().getRawDataService().getRawData(id, queryMap)) {
if (inputStream == null) {
throw new ResourceNotFoundException("No raw data found for id '" + id + "'.");
}
IOUtils.copyLarge(inputStream, response.getOutputStream());
} catch (IOException e) {
throw new InternalServerException("Error while querying raw data", e);
}
}
use of org.n52.io.request.IoParameters in project series-rest-api by 52North.
the class ParameterController method getExtras.
@Override
public Map<String, Object> getExtras(String resourceId, String locale, MultiValueMap<String, String> query) {
RequestUtils.overrideQueryLocaleWhenSet(locale, query);
IoParameters map = QueryParameters.createFromQuery(query);
LOGGER.debug("getExtras() with id '{}' and query '{}'", resourceId, map);
Map<String, Object> extras = new HashMap<>();
for (MetadataExtension<T> extension : metadataExtensions) {
T from = parameterService.getParameter(resourceId, map);
final Map<String, Object> furtherExtras = extension.getExtras(from, map);
Collection<String> overridableKeys = checkForOverridingData(extras, furtherExtras);
if (!overridableKeys.isEmpty()) {
String[] keys = overridableKeys.toArray(new String[0]);
LOGGER.warn("Metadata extension overrides existing extra data: {}", Arrays.toString(keys));
}
extras.putAll(furtherExtras);
}
return extras;
}
use of org.n52.io.request.IoParameters in project series-rest-api by 52North.
the class DataController method getSeriesAsCsv.
@RequestMapping(value = "/{seriesId}/data", produces = { "text/csv" }, method = RequestMethod.GET)
public void getSeriesAsCsv(HttpServletResponse response, @PathVariable String seriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
RequestUtils.overrideQueryLocaleWhenSet(locale, query);
IoParameters map = QueryParameters.createFromQuery(query);
LOGGER.debug("get data collection csv for '{}' with query: {}", seriesId, map);
RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(seriesId, map);
checkAgainstTimespanRestriction(parameters.getTimespan());
checkForUnknownDatasetIds(map, seriesId);
response.setCharacterEncoding(DEFAULT_RESPONSE_ENCODING);
if (Boolean.parseBoolean(map.getOther("zip"))) {
response.setContentType(MimeType.APPLICATION_ZIP.toString());
} else {
response.setContentType(MimeType.TEXT_CSV.toString());
}
final String datasetType = parameters.getValueType();
createIoFactory(datasetType).withSimpleRequest(parameters).createHandler(MimeType.TEXT_CSV.toString()).writeBinary(response.getOutputStream());
}
use of org.n52.io.request.IoParameters in project series-rest-api by 52North.
the class DataController method getSeriesAsZippedCsv.
@RequestMapping(value = "/{seriesId}/data", produces = { "application/zip" }, method = RequestMethod.GET)
public void getSeriesAsZippedCsv(HttpServletResponse response, @PathVariable String seriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
RequestUtils.overrideQueryLocaleWhenSet(locale, query);
IoParameters map = QueryParameters.createFromQuery(query);
LOGGER.debug("get data collection zip for '{}' with query: {}", seriesId, map);
RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(seriesId, map);
checkAgainstTimespanRestriction(parameters.getTimespan());
checkForUnknownDatasetIds(map, seriesId);
response.setCharacterEncoding(DEFAULT_RESPONSE_ENCODING);
response.setContentType(MimeType.APPLICATION_ZIP.toString());
final String datasetType = parameters.getValueType();
createIoFactory(datasetType).withSimpleRequest(parameters).createHandler(MimeType.APPLICATION_ZIP.toString()).writeBinary(response.getOutputStream());
}
Aggregations