FolderAPI extends APIService { @RequestMapping(value = "/api/folders", method = PUT) @ApiOperation(value = "Add a folder.", produces = APPLICATION_JSON_VALUE) @Timed public StreamingResponseBody addFolder(@RequestParam(required = false) final String parentId, @RequestParam final String path) { try { final HystrixCommand<InputStream> createChildFolder = getCommand(CreateChildFolder.class, parentId, path); return CommandHelper.toStreaming(createChildFolder); } catch (Exception e) { throw new TDPException(APIErrorCodes.UNABLE_TO_CREATE_FOLDER, e); } }  @RequestMapping(value = "/api/folders", method = GET) @ApiOperation(value = "List folders. Optional filter on parent ID may be supplied.", produces = APPLICATION_JSON_VALUE) @Timed ResponseEntity<StreamingResponseBody> listFolders(@RequestParam(required = false) String parentId); @RequestMapping(value = "/api/folders/tree", method = GET) @ApiOperation(value = "List all folders", produces = APPLICATION_JSON_VALUE) @Timed StreamingResponseBody getTree(); @RequestMapping(value = "/api/folders/{id}", method = GET, produces = APPLICATION_JSON_VALUE) @ApiOperation(value = "Get folder by id", produces = APPLICATION_JSON_VALUE, notes = "Get a folder by id") @Timed ResponseEntity<StreamingResponseBody> getFolderAndHierarchyById(@PathVariable(value = "id") final String id); @RequestMapping(value = "/api/folders", method = PUT) @ApiOperation(value = "Add a folder.", produces = APPLICATION_JSON_VALUE) @Timed StreamingResponseBody addFolder(@RequestParam(required = false) final String parentId,
            @RequestParam final String path); @RequestMapping(value = "/api/folders/{id}", method = DELETE) @ApiOperation(value = "Remove a Folder") @Timed ResponseEntity<String> removeFolder(@PathVariable final String id, final OutputStream output); @RequestMapping(value = "/api/folders/{id}/name", method = PUT) @ApiOperation(value = "Rename a Folder") @Timed void renameFolder(@PathVariable final String id, @RequestBody final String newName); @RequestMapping(value = "/api/folders/search", method = GET, produces = APPLICATION_JSON_VALUE) @ApiOperation(value = "Search Folders with parameter as part of the name", produces = APPLICATION_JSON_VALUE) @Timed ResponseEntity<StreamingResponseBody> search(@RequestParam(required = false) final String name,
            @RequestParam(required = false) final Boolean strict, @RequestParam(required = false) final String path); @RequestMapping(value = "/api/folders/{id}/preparations", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE) @ApiOperation(value = "Get all preparations for a given id.", notes = "Returns the list of preparations for the given id the current user is allowed to see.") @Timed PreparationsByFolder listPreparationsByFolder(
            @PathVariable @ApiParam(name = "id", value = "The destination to search preparations from.") final String id, //
            @ApiParam(value = "Sort key (by name or date), defaults to 'date'.") @RequestParam(defaultValue = "creationDate") final Sort sort, //
            @ApiParam(value = "Order for sort key (desc or asc), defaults to 'desc'.") @RequestParam(defaultValue = "desc") final Order order);  }
@Test public void shouldListPreparationsInFolder() throws Exception { folderRepository.addFolder(home.getId(), "/one"); folderRepository.addFolder(home.getId(), "/two"); testClient.createPreparationFromFile("dataset/dataset.csv", "yet another preparation", home.getId()); testClient.createPreparationFromFile("dataset/dataset.csv", "prep 2", home.getId()); testClient.createPreparationFromFile("dataset/dataset.csv", "preparation 3 !", home.getId()); final Response response = given() .when() .expect() .statusCode(200) .log() .ifError() .get("/api/folders/{id}/preparations", home.getId()); assertThat(response.getStatusCode(), is(200)); final JsonNode rootNode = mapper.readTree(response.asInputStream()); final JsonNode folders = rootNode.get("folders"); assertNotNull(folders); assertEquals(2, folders.size()); final JsonNode preparations = rootNode.get("preparations"); assertNotNull(preparations); assertEquals(3, preparations.size()); for (JsonNode preparation : preparations) { final JsonNode dataset = preparation.get("dataset"); assertNotNull(dataset); assertTrue(dataset.has("dataSetName")); } }