Search in sources :

Example 1 with FolderInfo

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()));
}
Also used : Response(com.jayway.restassured.response.Response) Folder(org.talend.dataprep.api.folder.Folder) FolderInfo(org.talend.dataprep.api.folder.FolderInfo) Test(org.junit.Test)

Example 2 with FolderInfo

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);
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) Folder(org.talend.dataprep.api.folder.Folder) FolderInfo(org.talend.dataprep.api.folder.FolderInfo) Timed(org.talend.dataprep.metrics.Timed) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with FolderInfo

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()));
}
Also used : Response(com.jayway.restassured.response.Response) Folder(org.talend.dataprep.api.folder.Folder) FolderInfo(org.talend.dataprep.api.folder.FolderInfo) Test(org.junit.Test) BasePreparationTest(org.talend.dataprep.preparation.BasePreparationTest)

Aggregations

Folder (org.talend.dataprep.api.folder.Folder)3 FolderInfo (org.talend.dataprep.api.folder.FolderInfo)3 Response (com.jayway.restassured.response.Response)2 Test (org.junit.Test)2 ApiOperation (io.swagger.annotations.ApiOperation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 TDPException (org.talend.dataprep.exception.TDPException)1 Timed (org.talend.dataprep.metrics.Timed)1 BasePreparationTest (org.talend.dataprep.preparation.BasePreparationTest)1