use of com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class FileStoreRestController method listStoreContents.
protected ResponseEntity<List<FileModel>> listStoreContents(FileStorePath fileStorePath, HttpServletRequest request) {
Path directory = fileStorePath.getAbsolutePath();
if (!Files.isDirectory(directory)) {
throw new NotFoundRestException();
}
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
List<FileModel> models;
try {
models = Files.list(directory).map(p -> fileToModel(fileStorePath.resolve(p), request.getServletContext())).collect(Collectors.toList());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Set<MediaType> mediaTypes = Sets.newHashSet(MediaType.APPLICATION_JSON);
request.setAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes);
return new ResponseEntity<>(models, responseHeaders, HttpStatus.OK);
}
Aggregations