Search in sources :

Example 1 with IoParameters

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());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with IoParameters

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);
    }
}
Also used : InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) BadRequestException(org.n52.web.exception.BadRequestException) IoParameters(org.n52.io.request.IoParameters) IOException(java.io.IOException) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Example 3 with IoParameters

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;
}
Also used : HashMap(java.util.HashMap) IoParameters(org.n52.io.request.IoParameters)

Example 4 with IoParameters

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());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with IoParameters

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());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IoParameters (org.n52.io.request.IoParameters)31 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)14 ModelAndView (org.springframework.web.servlet.ModelAndView)7 Test (org.junit.Test)5 IntervalWithTimeZone (org.n52.io.IntervalWithTimeZone)4 Stopwatch (org.n52.web.common.Stopwatch)4 IoStyleContext (org.n52.io.IoStyleContext)3 RequestStyledParameterSet (org.n52.io.request.RequestStyledParameterSet)3 ResourceNotFoundException (org.n52.web.exception.ResourceNotFoundException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 I18N (org.n52.io.I18N)1