Search in sources :

Example 16 with FolderEntry

use of org.talend.dataprep.api.folder.FolderEntry in project data-prep by Talend.

the class FileSystemUtils method readEntryFromStream.

private static FolderEntry readEntryFromStream(InputStream inputStream) throws IOException {
    // use java Properties to save the files
    Properties properties = new Properties();
    properties.load(inputStream);
    FolderEntry folderEntry = new FolderEntry();
    folderEntry.setContentId(properties.getProperty(CONTENT_ID));
    folderEntry.setContentType(FolderContentType.fromName(properties.getProperty(CONTENT_TYPE)));
    folderEntry.setFolderId(properties.getProperty(FOLDER_ID));
    return folderEntry;
}
Also used : FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Properties(java.util.Properties)

Example 17 with FolderEntry

use of org.talend.dataprep.api.folder.FolderEntry in project data-prep by Talend.

the class FolderAPITest method should_return_conflict_on_non_empty_folder_remove.

@Test
public void should_return_conflict_on_non_empty_folder_remove() throws IOException {
    // given
    createFolder("beer", home.getId());
    final Folder beer = getFolder(home.getId(), "beer");
    final FolderEntry folderEntry = new FolderEntry(DATASET, "6f8a54051bc454");
    createFolderEntry(folderEntry, beer.getId());
    // when
    final Response response = removeFolder(beer.getId());
    // then
    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));
}
Also used : Response(com.jayway.restassured.response.Response) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Folder(org.talend.dataprep.api.folder.Folder) Test(org.junit.Test)

Example 18 with FolderEntry

use of org.talend.dataprep.api.folder.FolderEntry in project data-prep by Talend.

the class PreparationAPITest method shouldCreatePreparationInSpecificFolder.

@Test
public void shouldCreatePreparationInSpecificFolder() throws Exception {
    // given
    final String path = "/folder-1/sub-folder-2";
    Folder folder = folderRepository.addFolder(folderRepository.getHome().getId(), path);
    List<FolderEntry> entries = getEntries(folder.getId());
    assertThat(entries.size(), is(0));
    // when
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testCreatePreparation", folder.getId());
    // then
    entries = getEntries(folder.getId());
    assertThat(entries.size(), is(1));
    final FolderEntry entry = entries.get(0);
    assertThat(entry.getContentId(), is(preparationId));
    assertThat(entry.getContentType(), is(PREPARATION));
}
Also used : FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Folder(org.talend.dataprep.api.folder.Folder) Test(org.junit.Test)

Example 19 with FolderEntry

use of org.talend.dataprep.api.folder.FolderEntry in project data-prep by Talend.

the class PreparationAPITest method shouldMovePreparation.

@Test
public void shouldMovePreparation() throws Exception {
    // given
    final Folder source = folderRepository.addFolder(home.getId(), "source");
    final String id = testClient.createPreparationFromFile("dataset/dataset.csv", "great_preparation", source.getId());
    final Folder destination = folderRepository.addFolder(home.getId(), "destination");
    // when
    final Response response = // 
    given().queryParam("folder", // 
    source.getId()).queryParam("destination", // 
    destination.getId()).queryParam("newName", // 
    "NEW great preparation").when().expect().statusCode(200).log().ifError().put("api/preparations/{id}/move", id);
    // then
    assertEquals(200, response.getStatusCode());
    // check the folder entry
    final List<FolderEntry> entries = getEntries(destination.getId());
    assertThat(entries.size(), greaterThan(0));
    final FolderEntry entry = entries.get(0);
    assertEquals(entry.getContentId(), id);
    // check the name
    final Preparation actual = preparationRepository.get(id, Preparation.class);
    assertEquals("NEW great preparation", actual.getName());
}
Also used : Response(com.jayway.restassured.response.Response) StandalonePreparation(org.talend.dataprep.StandalonePreparation) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Folder(org.talend.dataprep.api.folder.Folder) Test(org.junit.Test)

Example 20 with FolderEntry

use of org.talend.dataprep.api.folder.FolderEntry in project data-prep by Talend.

the class AbstractFolderTest method shouldLocateEntry.

@Test
public void shouldLocateEntry() throws Exception {
    // given (root & 2 entries)
    final Folder root = getFolderRepository().getHome();
    final FolderEntry littleCreatures = new FolderEntry(DATASET, "littleCreatures");
    getFolderRepository().addFolderEntry(littleCreatures, root.getId());
    final FolderEntry bordeaux = new FolderEntry(PREPARATION, "bordeaux");
    getFolderRepository().addFolderEntry(bordeaux, root.getId());
    // given (foo & 2 entries)
    final Folder foo = getFolderRepository().addFolder(homeFolderId, "foo");
    final FolderEntry cars = new FolderEntry(DATASET, "cars");
    getFolderRepository().addFolderEntry(cars, foo.getId());
    final FolderEntry boats = new FolderEntry(PREPARATION, "boats");
    getFolderRepository().addFolderEntry(boats, foo.getId());
    // add some noise
    getFolderRepository().addFolder(foo.getId(), "bar");
    getFolderRepository().addFolder(homeFolderId, "hello");
    // then
    assertNull(getFolderRepository().locateEntry(pathToId("not to be found"), PREPARATION));
    assertEquals(root.getId(), getFolderRepository().locateEntry(bordeaux.getContentId(), bordeaux.getContentType()).getId());
    assertEquals(root.getId(), getFolderRepository().locateEntry(littleCreatures.getContentId(), littleCreatures.getContentType()).getId());
    assertEquals(foo.getId(), getFolderRepository().locateEntry(cars.getContentId(), cars.getContentType()).getId());
    assertEquals(foo.getId(), getFolderRepository().locateEntry(boats.getContentId(), boats.getContentType()).getId());
}
Also used : FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Folder(org.talend.dataprep.api.folder.Folder) ServiceBaseTest(org.talend.ServiceBaseTest)

Aggregations

FolderEntry (org.talend.dataprep.api.folder.FolderEntry)25 Folder (org.talend.dataprep.api.folder.Folder)14 Test (org.junit.Test)10 ServiceBaseTest (org.talend.ServiceBaseTest)6 Response (com.jayway.restassured.response.Response)5 PreparationSearchCriterion.filterPreparation (org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation)4 Properties (java.util.Properties)3 Preparation (org.talend.dataprep.api.preparation.Preparation)3 TDPException (org.talend.dataprep.exception.TDPException)3 StandalonePreparation (org.talend.dataprep.StandalonePreparation)2 EnrichedPreparation (org.talend.dataprep.api.service.api.EnrichedPreparation)2 BasePreparationTest (org.talend.dataprep.preparation.BasePreparationTest)2 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 FolderContentType (org.talend.dataprep.api.folder.FolderContentType)1