FolderAPI extends APIService { @RequestMapping(value = "/api/folders/{id}", method = DELETE) @ApiOperation(value = "Remove a Folder") @Timed public ResponseEntity<String> removeFolder(@PathVariable final String id, final OutputStream output) { try { return getCommand(RemoveFolder.class, id).execute(); } catch (Exception e) { throw new TDPException(APIErrorCodes.UNABLE_TO_DELETE_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 should_remove_empty_folder() throws IOException { createFolder("beer", home.getId()); final Folder beer = getFolder(home.getId(), "beer"); final Response response = removeFolder(beer.getId()); assertThat(response.getStatusCode(), is(204)); final List<Folder> folders = getFolderChildren(home.getId()); assertThat(folders, is(empty())); }
@Test public void should_remove_missing_folder() throws IOException { final Response response = removeFolder("folder1234"); assertThat(response.getStatusCode(), is(404)); }
@Test public void should_return_conflict_on_non_empty_folder_remove() throws IOException { createFolder("beer", home.getId()); final Folder beer = getFolder(home.getId(), "beer"); final FolderEntry folderEntry = new FolderEntry(DATASET, "6f8a54051bc454"); createFolderEntry(folderEntry, beer.getId()); final Response response = removeFolder(beer.getId()); assertThat(response.getStatusCode(), is(409)); final String content = response.asString(); assertTrue(StringUtils.isNoneBlank(content)); assertTrue(content.contains(FolderErrorCodes.FOLDER_NOT_EMPTY.name())); final List<Folder> folders = getFolderChildren(home.getId()); assertThat(folders, hasSize(1)); }