@SneakyThrows @Test void writeToInboxTest() { when(dataSafeService.inboxService().write(any())).thenReturn(new ByteArrayOutputStream()); RestDocumentationResultHandler document = document("inbox-write-success", pathParameters( parameterWithName("path").description("path to the file") ), requestHeaders( headerWithName("token").description(TOKEN_DESCRIPTION), headerWithName("users").description("recipients array") ) ); mvc.perform(putFileBuilder("/inbox/document/{path}", TEST_PATH) .contentType(MediaType.MULTIPART_FORM_DATA_VALUE) .header("users", TEST_USER) .header("token", token) ) .andExpect(status().isOk()) .andDo(document); verify(inboxService).write(any()); }
@SneakyThrows @PutMapping(value = "/inbox/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Send document to inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully sent"), @ApiResponse(code = 403, message = "Access denied") }) public void writeToInbox(@RequestHeader Set<String> users, @PathVariable String path, @RequestParam("file") MultipartFile file) { Set<UserID> toUsers = users.stream().map(UserID::new).collect(Collectors.toSet()); try (OutputStream os = dataSafeService.inboxService().write(WriteRequest.forDefaultPublic(toUsers, path)); InputStream is = file.getInputStream()) { StreamUtils.copy(is, os); } log.debug("Users {}, write to INBOX file: {}", toUsers, path); }
InboxController { @SneakyThrows @PutMapping(value = "/inbox/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Send document to inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully sent"), @ApiResponse(code = 403, message = "Access denied") }) public void writeToInbox(@RequestHeader Set<String> users, @PathVariable String path, @RequestParam("file") MultipartFile file) { Set<UserID> toUsers = users.stream().map(UserID::new).collect(Collectors.toSet()); try (OutputStream os = dataSafeService.inboxService().write(WriteRequest.forDefaultPublic(toUsers, path)); InputStream is = file.getInputStream()) { StreamUtils.copy(is, os); } log.debug("Users {}, write to INBOX file: {}", toUsers, path); } }
InboxController { @SneakyThrows @PutMapping(value = "/inbox/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Send document to inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully sent"), @ApiResponse(code = 403, message = "Access denied") }) public void writeToInbox(@RequestHeader Set<String> users, @PathVariable String path, @RequestParam("file") MultipartFile file) { Set<UserID> toUsers = users.stream().map(UserID::new).collect(Collectors.toSet()); try (OutputStream os = dataSafeService.inboxService().write(WriteRequest.forDefaultPublic(toUsers, path)); InputStream is = file.getInputStream()) { StreamUtils.copy(is, os); } log.debug("Users {}, write to INBOX file: {}", toUsers, path); }  }
InboxController { @SneakyThrows @PutMapping(value = "/inbox/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Send document to inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully sent"), @ApiResponse(code = 403, message = "Access denied") }) public void writeToInbox(@RequestHeader Set<String> users, @PathVariable String path, @RequestParam("file") MultipartFile file) { Set<UserID> toUsers = users.stream().map(UserID::new).collect(Collectors.toSet()); try (OutputStream os = dataSafeService.inboxService().write(WriteRequest.forDefaultPublic(toUsers, path)); InputStream is = file.getInputStream()) { StreamUtils.copy(is, os); } log.debug("Users {}, write to INBOX file: {}", toUsers, path); }  @SneakyThrows @PutMapping(value = "/inbox/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Send document to inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully sent"), @ApiResponse(code = 403, message = "Access denied") }) void writeToInbox(@RequestHeader Set<String> users,
                             @PathVariable String path,
                             @RequestParam("file") MultipartFile file); @SneakyThrows @GetMapping(value = "/inbox/document/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read document from inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) void readFromInbox(@RequestHeader String user,
                              @RequestHeader String password,
                              @PathVariable String path,
                              HttpServletResponse response); @DeleteMapping("/inbox/document/{path:.*}") @ApiOperation("Delete document from inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document successfully deleted") }) void deleteFromInbox(@RequestHeader String user,
                                @RequestHeader String password,
                                @PathVariable String path); @GetMapping(value = "/inbox/documents/{path:.*}", produces = APPLICATION_JSON_VALUE) @ApiOperation("List files in inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> listInbox(@RequestHeader String user,
                                  @RequestHeader String password,
                                  @ApiParam(defaultValue = ".")
                                  @PathVariable(required = false) String path); }
InboxController { @SneakyThrows @PutMapping(value = "/inbox/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Send document to inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully sent"), @ApiResponse(code = 403, message = "Access denied") }) public void writeToInbox(@RequestHeader Set<String> users, @PathVariable String path, @RequestParam("file") MultipartFile file) { Set<UserID> toUsers = users.stream().map(UserID::new).collect(Collectors.toSet()); try (OutputStream os = dataSafeService.inboxService().write(WriteRequest.forDefaultPublic(toUsers, path)); InputStream is = file.getInputStream()) { StreamUtils.copy(is, os); } log.debug("Users {}, write to INBOX file: {}", toUsers, path); }  @SneakyThrows @PutMapping(value = "/inbox/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Send document to inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully sent"), @ApiResponse(code = 403, message = "Access denied") }) void writeToInbox(@RequestHeader Set<String> users,
                             @PathVariable String path,
                             @RequestParam("file") MultipartFile file); @SneakyThrows @GetMapping(value = "/inbox/document/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read document from inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) void readFromInbox(@RequestHeader String user,
                              @RequestHeader String password,
                              @PathVariable String path,
                              HttpServletResponse response); @DeleteMapping("/inbox/document/{path:.*}") @ApiOperation("Delete document from inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document successfully deleted") }) void deleteFromInbox(@RequestHeader String user,
                                @RequestHeader String password,
                                @PathVariable String path); @GetMapping(value = "/inbox/documents/{path:.*}", produces = APPLICATION_JSON_VALUE) @ApiOperation("List files in inbox") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> listInbox(@RequestHeader String user,
                                  @RequestHeader String password,
                                  @ApiParam(defaultValue = ".")
                                  @PathVariable(required = false) String path);  }