@SneakyThrows @Test void listVersionedDocumentsTest() { Uri location = new Uri("s3: PrivateResource privateResource = new BasePrivateResource(location).resolve(new Uri("/path/to/file.txt"), new Uri("/path/to/file.txt")); BaseResolvedResource resolvedResource = new BaseResolvedResource(privateResource, Instant.now()); AbsoluteLocation<PrivateResource> absoluteLocation = new AbsoluteLocation<>(privateResource); BaseVersionedPath<PrivateResource, ResolvedResource, Version> versionedPath = new BaseVersionedPath<>(new DFSVersion("1"), absoluteLocation, resolvedResource); when(versionedPrivateSpaceService.listWithDetails(any())).thenReturn(Stream.of(versionedPath)); RestDocumentationResultHandler document = document("versioned-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) ) ); String path = ""; mvc.perform(get("/versioned/{path}", path) .contentType(MediaType.APPLICATION_JSON_VALUE) .header("user", TEST_USER) .header("password", TEST_PASS) .header("token", token) ).andExpect(status().isOk()) .andExpect(content().string("[\"/path/to/file.txt\"]")) .andDo(document); verify(versionedPrivateSpaceService).listWithDetails(any()); }
@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") }) public List<String> listVersionedDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path).orElse("./"); try { List<String> documentList = versionedDatasafeServices.latestPrivate().listWithDetails( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.absolute().getResource().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }
VersionController { @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") }) public List<String> listVersionedDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path).orElse("./"); try { List<String> documentList = versionedDatasafeServices.latestPrivate().listWithDetails( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.absolute().getResource().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } } }
VersionController { @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") }) public List<String> listVersionedDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path).orElse("./"); try { List<String> documentList = versionedDatasafeServices.latestPrivate().listWithDetails( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.absolute().getResource().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  }
VersionController { @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") }) public List<String> listVersionedDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path).orElse("./"); try { List<String> documentList = versionedDatasafeServices.latestPrivate().listWithDetails( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.absolute().getResource().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  @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 { @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") }) public List<String> listVersionedDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path).orElse("./"); try { List<String> documentList = versionedDatasafeServices.latestPrivate().listWithDetails( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.absolute().getResource().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  @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);  }