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);
}
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);
}
}
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);
}
}
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);
}
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);
}
}
Aggregations