Search in sources :

Example 1 with ResourceNotFoundException

use of org.n52.web.exception.ResourceNotFoundException in project series-rest-api by 52North.

the class StationsParameterController method getItem.

@RequestMapping(value = "/{item}", method = RequestMethod.GET)
public ModelAndView getItem(@PathVariable("item") String procedureId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    map = IoParameters.ensureBackwardsCompatibility(map);
    // TODO check parameters and throw BAD_REQUEST if invalid
    Stopwatch stopwatch = Stopwatch.startStopwatch();
    Object result = parameterService.getParameter(procedureId, map);
    logRequestTime(stopwatch);
    if (result == null) {
        throw new ResourceNotFoundException("Found no station with given id.");
    }
    return new ModelAndView().addObject(result);
}
Also used : Stopwatch(org.n52.web.common.Stopwatch) ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ResourceNotFoundException

use of org.n52.web.exception.ResourceNotFoundException in project series-rest-api by 52North.

the class TimeseriesDataController method processRawDataRequest.

private void processRawDataRequest(HttpServletResponse response, RequestSimpleParameterSet query) {
    if (!timeseriesDataService.supportsRawData()) {
        throwNewRawDataQueryNotSupportedException();
    }
    final RawDataService rawDataService = timeseriesDataService.getRawDataService();
    try (InputStream inputStream = rawDataService.getRawData(query)) {
        if (inputStream == null) {
            throw new ResourceNotFoundException("No raw data found.");
        }
        response.setContentType(query.getFormat());
        IOUtils.copyLarge(inputStream, response.getOutputStream());
    } catch (IOException e) {
        throw new InternalServerException("Error while querying raw data", e);
    }
}
Also used : RawDataService(org.n52.series.spi.srv.RawDataService) InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) IOException(java.io.IOException) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Example 3 with ResourceNotFoundException

use of org.n52.web.exception.ResourceNotFoundException in project series-rest-api by 52North.

the class DataController method writeRawData.

private void writeRawData(IoParameters parameters, HttpServletResponse response) throws InternalServerException, ResourceNotFoundException, BadRequestException {
    LOGGER.debug("get raw data collection with parameters: {}", parameters);
    if (!dataService.supportsRawData()) {
        throw new BadRequestException("Querying of raw timeseries data is not supported " + "by the underlying service!");
    }
    final RawDataService rawDataService = dataService.getRawDataService();
    try (InputStream inputStream = rawDataService.getRawData(parameters)) {
        response.setContentType(parameters.getRawFormat());
        IOUtils.copyLarge(inputStream, response.getOutputStream());
    } catch (IOException e) {
        throw new InternalServerException("Error while querying raw data", e);
    }
}
Also used : RawDataService(org.n52.series.spi.srv.RawDataService) InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) BadRequestException(org.n52.web.exception.BadRequestException) IOException(java.io.IOException)

Example 4 with ResourceNotFoundException

use of org.n52.web.exception.ResourceNotFoundException in project series-rest-api by 52North.

the class ParameterController method getItem.

@Override
public ModelAndView getItem(String id, String locale, MultiValueMap<String, String> query) {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    LOGGER.debug("getItem() with id '{}' and query '{}'", id, map);
    T item = parameterService.getParameter(id, map);
    if (item == null) {
        throw new ResourceNotFoundException("Resource with id '" + id + "' not found.");
    }
    T parameter = addExtensionInfos(item);
    return new ModelAndView().addObject(parameter);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Example 5 with ResourceNotFoundException

use of org.n52.web.exception.ResourceNotFoundException in project series-rest-api by 52North.

the class PreRenderingJob method writePrerenderedGraphToOutputStream.

public void writePrerenderedGraphToOutputStream(String datasetId, String qualifier, OutputStream outputStream) {
    if (taskConfigPrerendering == null) {
        taskConfigPrerendering = readJobConfig(configFile);
    }
    try {
        BufferedImage image = loadImage(datasetId, qualifier);
        if (image == null) {
            ResourceNotFoundException ex = new ResourceNotFoundException("Could not find image on server.");
            ex.addHint("Perhaps the image is being rendered at the moment. Try again later.");
            throw ex;
        }
        LOGGER.debug("write prerendered image '{}'", createFileName(datasetId, qualifier));
        ImageIO.write(image, IMAGE_EXTENSION, outputStream);
    } catch (IOException e) {
        LOGGER.error("Error while loading pre rendered image", e);
    }
}
Also used : IOException(java.io.IOException) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ResourceNotFoundException (org.n52.web.exception.ResourceNotFoundException)7 IOException (java.io.IOException)5 InputStream (java.io.InputStream)3 IoParameters (org.n52.io.request.IoParameters)3 RawDataService (org.n52.series.spi.srv.RawDataService)3 InternalServerException (org.n52.web.exception.InternalServerException)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 BufferedImage (java.awt.image.BufferedImage)2 Stopwatch (org.n52.web.common.Stopwatch)2 BadRequestException (org.n52.web.exception.BadRequestException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2