Search in sources :

Example 11 with NotFoundRestException

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);
}
Also used : Path(java.nio.file.Path) RemainingPath(com.infiniteautomation.mango.rest.latest.resolver.RemainingPath) FileStorePath(com.infiniteautomation.mango.spring.service.FileStoreService.FileStorePath) FileModel(com.infiniteautomation.mango.rest.latest.model.filestore.FileModel) HttpHeaders(org.springframework.http.HttpHeaders) NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) ResponseEntity(org.springframework.http.ResponseEntity) MediaType(org.springframework.http.MediaType) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Aggregations

NotFoundRestException (com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException)11 ApiOperation (io.swagger.annotations.ApiOperation)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseEntity (org.springframework.http.ResponseEntity)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 HttpHeaders (org.springframework.http.HttpHeaders)3 VirtualSerialPortConfig (com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig)2 BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)2 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)1 FileModel (com.infiniteautomation.mango.rest.latest.model.filestore.FileModel)1 PermissionDefinitionModel (com.infiniteautomation.mango.rest.latest.model.permissions.PermissionDefinitionModel)1 PatchVORequestBody (com.infiniteautomation.mango.rest.latest.patch.PatchVORequestBody)1