Search in sources :

Example 1 with FolderEntry

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

the class FileSystemFolderRepository method copyFolderEntry.

@Override
public void copyFolderEntry(FolderEntry folderEntry, String destinationId) {
    FolderEntry cloned = new FolderEntry(folderEntry.getContentType(), folderEntry.getContentId());
    cloned.setFolderId(destinationId);
    addFolderEntry(cloned, destinationId);
}
Also used : FolderEntry(org.talend.dataprep.api.folder.FolderEntry)

Example 2 with FolderEntry

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

the class FileSystemUtils method toFolderEntry.

/**
 * Tries to read a file for a dataprep {@link FolderEntry}.
 *
 * @param pathFile the location of the file
 * @return the folder entry or throws an exception if it cannot be read
 */
static FolderEntry toFolderEntry(Path pathFile) {
    FolderEntry folderEntry;
    try (InputStream inputStream = Files.newInputStream(pathFile)) {
        Properties properties = new Properties();
        properties.load(inputStream);
        folderEntry = new FolderEntry();
        folderEntry.setFolderId(properties.getProperty(FOLDER_ID));
        folderEntry.setContentType(FolderContentType.fromName(properties.getProperty(CONTENT_TYPE)));
        folderEntry.setContentId(properties.getProperty(CONTENT_ID));
    } catch (IOException e) {
        throw new TDPException(UNABLE_TO_READ_FOLDER_ENTRY, e, build().put("path", pathFile));
    }
    return folderEntry;
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) InputStream(java.io.InputStream) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) IOException(java.io.IOException) Properties(java.util.Properties)

Example 3 with FolderEntry

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

the class PreparationAPITest method shouldCreatePreparationInDefaultFolder.

// ------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------CONTENT------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------
@Test
public void shouldCreatePreparationInDefaultFolder() throws Exception {
    // given
    Folder home = folderRepository.getHome();
    List<FolderEntry> entries = getEntries(home.getId());
    assertTrue(entries.isEmpty());
    // when
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testCreatePreparation", home.getId());
    // then
    entries = getEntries(home.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 4 with FolderEntry

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

the class PreparationAPITest method shouldCopyPreparation.

@Test
public void shouldCopyPreparation() throws Exception {
    // given
    Folder destination = folderRepository.addFolder(home.getId(), "/destination");
    Folder origin = folderRepository.addFolder(home.getId(), "/from");
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "super preparation", origin.getId());
    // when
    String newPreparationName = "NEW super preparation";
    final Response response = // 
    given().queryParam("destination", // 
    destination.getId()).queryParam("newName", // 
    newPreparationName).when().expect().statusCode(200).log().ifError().post("api/preparations/{id}/copy", preparationId);
    // then
    assertEquals(200, response.getStatusCode());
    String copyId = response.asString();
    // 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(), copyId);
    // check the name
    final Preparation actual = preparationRepository.get(copyId, Preparation.class);
    assertEquals(newPreparationName, 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 5 with FolderEntry

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

the class PreparationAPITest method shouldNotAcceptPreparationWithoutRowMetadata.

@Test
public void shouldNotAcceptPreparationWithoutRowMetadata() throws Exception {
    // given
    Folder home = folderRepository.getHome();
    final List<FolderEntry> entries = getEntries(home.getId());
    assertThat(entries.size(), is(0));
    String dataSetId = testClient.createDataset("dataset/dataset.csv", "testCreatePreparation");
    final Response response = // 
    given().contentType(// 
    ContentType.JSON).body("{ \"name\": \"" + "my_preparation" + "\", \"dataSetId\": \"" + dataSetId + "\"}").queryParam("folder", // 
    home.getId()).when().expect().statusCode(200).log().ifError().post("/api/preparations");
}
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)

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