@SneakyThrows @Test void readVersionedDocumentTest() { when(versionedDatasafeServices.latestPrivate().read(any())).thenReturn(new PasswordClearingInputStream(new ByteArrayInputStream("hello".getBytes()), null)); RestDocumentationResultHandler document = document("versioned-read-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) ) ); String path = "path/to/file"; mvc.perform(get("/versioned/{path}", path) .header("user", TEST_USER) .header("password", TEST_PASS) .header("token", token) .accept(MediaType.APPLICATION_OCTET_STREAM_VALUE)) .andExpect(status().isOk()) .andExpect(header().string(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE)) .andDo(document); verify(versionedPrivateSpaceService).read(any()); }
@SneakyThrows @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) public void readVersionedDocument(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable String path, HttpServletResponse response) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); ReadRequest<UserIDAuth, PrivateResource> request = ReadRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path); response.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE); try (InputStream is = versionedDatasafeServices.latestPrivate().read(request); OutputStream os = response.getOutputStream()) { StreamUtils.copy(is, os); } log.debug("User: {}, read private file from: {}", user, path); }
VersionController { @SneakyThrows @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) public void readVersionedDocument(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable String path, HttpServletResponse response) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); ReadRequest<UserIDAuth, PrivateResource> request = ReadRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path); response.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE); try (InputStream is = versionedDatasafeServices.latestPrivate().read(request); OutputStream os = response.getOutputStream()) { StreamUtils.copy(is, os); } log.debug("User: {}, read private file from: {}", user, path); } }
VersionController { @SneakyThrows @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) public void readVersionedDocument(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable String path, HttpServletResponse response) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); ReadRequest<UserIDAuth, PrivateResource> request = ReadRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path); response.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE); try (InputStream is = versionedDatasafeServices.latestPrivate().read(request); OutputStream os = response.getOutputStream()) { StreamUtils.copy(is, os); } log.debug("User: {}, read private file from: {}", user, path); }  }
VersionController { @SneakyThrows @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) public void readVersionedDocument(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable String path, HttpServletResponse response) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); ReadRequest<UserIDAuth, PrivateResource> request = ReadRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path); response.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE); try (InputStream is = versionedDatasafeServices.latestPrivate().read(request); OutputStream os = response.getOutputStream()) { StreamUtils.copy(is, os); } log.debug("User: {}, read private file from: {}", user, path); }  @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_JSON_VALUE) @ApiOperation("List latest documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> listVersionedDocuments(@RequestHeader String user,
                                               @RequestHeader String password,
                                               @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                               @PathVariable(required = false) String path); @SneakyThrows @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) void readVersionedDocument(@RequestHeader String user,
                                      @RequestHeader String password,
                                      @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                      @PathVariable String path,
                                      HttpServletResponse response); @SneakyThrows @PutMapping(value = "/versioned/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Write latest document to user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully written") }) void writeVersionedDocument(@RequestHeader String user,
                                       @RequestHeader String password,
                                       @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                       @PathVariable String path,
                                       @RequestParam("file") MultipartFile file); @DeleteMapping("/versioned/{path:.*}") @ApiOperation("Delete latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document successfully deleted") }) void deleteVersionedDocument(@RequestHeader String user,
                                        @RequestHeader String password,
                                        @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                        @PathVariable String path); @GetMapping(value = "/versions/list/{path:.*}", produces = APPLICATION_JSON_VALUE) @ApiOperation("List versions of document") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> versionsOf(@RequestHeader String user,
                                   @RequestHeader String password,
                                   @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                   @ApiParam(defaultValue = ".")
                                   @PathVariable(required = false) String path); }
VersionController { @SneakyThrows @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) public void readVersionedDocument(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable String path, HttpServletResponse response) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); ReadRequest<UserIDAuth, PrivateResource> request = ReadRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path); response.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM_VALUE); try (InputStream is = versionedDatasafeServices.latestPrivate().read(request); OutputStream os = response.getOutputStream()) { StreamUtils.copy(is, os); } log.debug("User: {}, read private file from: {}", user, path); }  @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_JSON_VALUE) @ApiOperation("List latest documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> listVersionedDocuments(@RequestHeader String user,
                                               @RequestHeader String password,
                                               @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                               @PathVariable(required = false) String path); @SneakyThrows @GetMapping(value = "/versioned/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 404, message = "Document not found") }) void readVersionedDocument(@RequestHeader String user,
                                      @RequestHeader String password,
                                      @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                      @PathVariable String path,
                                      HttpServletResponse response); @SneakyThrows @PutMapping(value = "/versioned/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Write latest document to user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully written") }) void writeVersionedDocument(@RequestHeader String user,
                                       @RequestHeader String password,
                                       @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                       @PathVariable String path,
                                       @RequestParam("file") MultipartFile file); @DeleteMapping("/versioned/{path:.*}") @ApiOperation("Delete latest document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document successfully deleted") }) void deleteVersionedDocument(@RequestHeader String user,
                                        @RequestHeader String password,
                                        @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                        @PathVariable String path); @GetMapping(value = "/versions/list/{path:.*}", produces = APPLICATION_JSON_VALUE) @ApiOperation("List versions of document") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> versionsOf(@RequestHeader String user,
                                   @RequestHeader String password,
                                   @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                   @ApiParam(defaultValue = ".")
                                   @PathVariable(required = false) String path);  }