@SneakyThrows @Test void listInboxTest() { Uri location = new Uri("s3: PrivateResource privateResource = new BasePrivateResource(location).resolve(new Uri("/path/to/file.txt"), new Uri("/path/to/file.txt")); AbsoluteLocation<ResolvedResource> resolvedPrivate = new AbsoluteLocation<>(new BaseResolvedResource(privateResource, Instant.now())); when(inboxService.list(any())).thenReturn(Stream.of(resolvedPrivate)); RestDocumentationResultHandler document = document("inbox-list-success", pathParameters( parameterWithName("path").description("path to the file") ), requestHeaders( headerWithName("token").description(TOKEN_DESCRIPTION), headerWithName("user").description(USER_DESCRIPTION), headerWithName("password").description(PASSWORD_DESCRIPTION) ) ); mvc.perform(get("/inbox/documents/{path}", TEST_PATH) .header("user", TEST_USER) .header("password", TEST_PASS) .header("token", token) .accept(APPLICATION_JSON_VALUE)) .andExpect(status().isOk()) .andDo(document); verify(inboxService).list(any()); }
@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") }) public List<String> listInbox(@RequestHeader String user, @RequestHeader String password, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> inboxList = dataSafeService.inboxService().list(ListRequest.forDefaultPrivate(userIDAuth, path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("User's {} inbox contains {} items", user, inboxList.size()); return inboxList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }
InboxController { @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") }) public List<String> listInbox(@RequestHeader String user, @RequestHeader String password, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> inboxList = dataSafeService.inboxService().list(ListRequest.forDefaultPrivate(userIDAuth, path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("User's {} inbox contains {} items", user, inboxList.size()); return inboxList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } } }
InboxController { @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") }) public List<String> listInbox(@RequestHeader String user, @RequestHeader String password, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> inboxList = dataSafeService.inboxService().list(ListRequest.forDefaultPrivate(userIDAuth, path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("User's {} inbox contains {} items", user, inboxList.size()); return inboxList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  }
InboxController { @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") }) public List<String> listInbox(@RequestHeader String user, @RequestHeader String password, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> inboxList = dataSafeService.inboxService().list(ListRequest.forDefaultPrivate(userIDAuth, path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("User's {} inbox contains {} items", user, inboxList.size()); return inboxList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  @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 { @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") }) public List<String> listInbox(@RequestHeader String user, @RequestHeader String password, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> inboxList = dataSafeService.inboxService().list(ListRequest.forDefaultPrivate(userIDAuth, path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("User's {} inbox contains {} items", user, inboxList.size()); return inboxList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  @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);  }