use of org.talend.dataprep.api.folder.FolderInfo in project data-prep by Talend.
the class FolderAPITest method shouldFolderMetadataWithHierarchy.
@Test
public void shouldFolderMetadataWithHierarchy() throws Exception {
// given
// HOME
// ___________|____________
// | |
// first second
// ____|____ |
// | | |
// first child 1 first child 2 second child
// |
// |
// second child child
createFolder("first", home.getId());
createFolder("second", home.getId());
final Folder firstFolder = getFolder(home.getId(), "first");
final Folder secondFolder = getFolder(home.getId(), "second");
createFolder("first child one", firstFolder.getId());
createFolder("first child two", firstFolder.getId());
createFolder("second child", secondFolder.getId());
final Folder secondChildFolder = getFolder(secondFolder.getId(), "second child");
createFolder("second child child", secondChildFolder.getId());
final Folder firstChildTwo = getFolder(firstFolder.getId(), "first child two");
// when
final Response response = //
given().expect().statusCode(200).log().ifError().when().get("/folders/{id}", firstChildTwo.getId());
// then
final FolderInfo infos = mapper.readValue(response.asString(), new TypeReference<FolderInfo>() {
});
final List<Folder> hierarchy = StreamSupport.stream(infos.getHierarchy().spliterator(), false).collect(toList());
assertThat(infos.getFolder(), equalTo(firstChildTwo));
assertThat(hierarchy, hasSize(2));
assertThat(hierarchy.get(0).getId(), equalTo(home.getId()));
assertThat(hierarchy.get(1).getId(), equalTo(firstFolder.getId()));
}
use of org.talend.dataprep.api.folder.FolderInfo in project data-prep by Talend.
the class FolderService method getFolderAndHierarchyById.
/**
* Get a folder metadata with its hierarchy
*
* @param id the folder id.
* @return the folder metadata with its hierarchy.
*/
@RequestMapping(value = "/folders/{id}", method = GET)
@ApiOperation(value = "Get folder by id", notes = "GET a folder by id")
@Timed
public FolderInfo getFolderAndHierarchyById(@PathVariable(value = "id") final String id) {
final Folder folder = folderRepository.getFolderById(id);
if (folder == null) {
throw new TDPException(FOLDER_NOT_FOUND, ExceptionContext.build().put("path", id));
}
final List<Folder> hierarchy = folderRepository.getHierarchy(folder);
return new FolderInfo(folder, hierarchy);
}
use of org.talend.dataprep.api.folder.FolderInfo in project data-prep by Talend.
the class FolderServiceTest method shouldFolderMetadataWithHierarchy.
@Test
public void shouldFolderMetadataWithHierarchy() throws Exception {
// @formatter:off
// given
// HOME
// ___________|____________
// | |
// first second
// ____|____ |
// | | |
// first child 1 first child 2 second child
// |
// |
// second child child
// @formatter:on
createFolder(home.getId(), "first");
createFolder(home.getId(), "second");
final Folder firstFolder = getFolder(home.getId(), "first");
final Folder secondFolder = getFolder(home.getId(), "second");
createFolder(firstFolder.getId(), "first child one");
createFolder(firstFolder.getId(), "first child two");
createFolder(secondFolder.getId(), "second child");
final Folder secondChildFolder = getFolder(secondFolder.getId(), "second child");
createFolder(secondChildFolder.getId(), "second child child");
final Folder firstChildTwo = getFolder(firstFolder.getId(), "first child two");
// when
final Response response = //
given().expect().statusCode(200).log().ifError().when().get("/folders/{id}", firstChildTwo.getId());
// then
final FolderInfo infos = mapper.readValue(response.asString(), new TypeReference<FolderInfo>() {
});
final List<Folder> hierarchy = StreamSupport.stream(infos.getHierarchy().spliterator(), false).collect(toList());
assertThat(infos.getFolder(), equalTo(firstChildTwo));
assertThat(hierarchy, hasSize(2));
assertThat(hierarchy.get(0).getId(), equalTo(home.getId()));
assertThat(hierarchy.get(1).getId(), equalTo(firstFolder.getId()));
}
Aggregations