Search in sources :

Example 21 with FolderEntry

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

the class FileSystemUtilsTest method writeEntryToStream.

@Test
public void writeEntryToStream() throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    FolderEntry folderEntry = new FolderEntry();
    folderEntry.setContentType(FolderContentType.PREPARATION);
    folderEntry.setContentId("contentId");
    folderEntry.setFolderId("folderId");
    FileSystemUtils.writeEntryToStream(folderEntry, outputStream);
    outputStream.close();
    Properties properties = new Properties();
    properties.load(new ByteArrayInputStream(outputStream.toByteArray()));
    assertEquals("contentId", properties.getProperty("contentId"));
    assertEquals("folderId", properties.getProperty("folderId"));
    assertEquals(FolderContentType.PREPARATION, FolderContentType.fromName(properties.getProperty("contentType")));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) Test(org.junit.Test)

Example 22 with FolderEntry

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

the class PreparationService method create.

/**
 * Create a preparation from the http request body.
 *
 * @param preparation the preparation to create.
 * @param folderId where to store the preparation.
 * @return the created preparation id.
 */
public String create(final Preparation preparation, String folderId) {
    LOGGER.debug("Create new preparation for data set {} in {}", preparation.getDataSetId(), folderId);
    Preparation toCreate = new Preparation(UUID.randomUUID().toString(), versionService.version().getVersionId());
    toCreate.setHeadId(Step.ROOT_STEP.id());
    toCreate.setAuthor(security.getUserId());
    toCreate.setName(preparation.getName());
    toCreate.setDataSetId(preparation.getDataSetId());
    toCreate.setRowMetadata(preparation.getRowMetadata());
    preparationRepository.add(toCreate);
    final String id = toCreate.id();
    // create associated folderEntry
    FolderEntry folderEntry = new FolderEntry(PREPARATION, id);
    folderRepository.addFolderEntry(folderEntry, folderId);
    LOGGER.info("New preparation {} created and stored in {} ", preparation, folderId);
    return id;
}
Also used : PreparationSearchCriterion.filterPreparation(org.talend.dataprep.preparation.service.PreparationSearchCriterion.filterPreparation) FolderEntry(org.talend.dataprep.api.folder.FolderEntry)

Example 23 with FolderEntry

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

the class PreparationControllerTest method createInFolder.

@Test
public void createInFolder() throws Exception {
    // given
    final String path = "/test/create/preparation";
    final Folder folder = folderRepository.addFolder(home.getId(), path);
    final Iterator<FolderEntry> iterator;
    try (Stream<FolderEntry> folderEntriesStream = folderRepository.entries(folder.getId(), PREPARATION)) {
        iterator = folderEntriesStream.iterator();
        assertThat(iterator.hasNext(), is(false));
    }
    // when
    final String preparationId = clientTest.createPreparation(createTestPreparation("another_preparation", "75368"), folder.getId()).id();
    // then
    final FolderEntry entry = assertThatPreparationIsFirstInsideFolder(preparationId, folder.getId());
    assertThat(entry.getContentType(), is(PREPARATION));
}
Also used : FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Folder(org.talend.dataprep.api.folder.Folder) BasePreparationTest(org.talend.dataprep.preparation.BasePreparationTest) Test(org.junit.Test)

Example 24 with FolderEntry

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

the class PreparationControllerTest method assertThatPreparationIsFirstInsideFolder.

private FolderEntry assertThatPreparationIsFirstInsideFolder(String expectedPreparationId, String folderId) {
    try (Stream<FolderEntry> folderEntriesStream = folderRepository.entries(folderId, PREPARATION)) {
        final Iterator<FolderEntry> iterator = folderEntriesStream.iterator();
        assertTrue(iterator.hasNext());
        final FolderEntry copy = iterator.next();
        assertEquals(copy.getContentId(), expectedPreparationId);
        return copy;
    }
}
Also used : FolderEntry(org.talend.dataprep.api.folder.FolderEntry)

Example 25 with FolderEntry

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

the class PreparationControllerTest method shouldCopyWithDefaultParameters.

@Test
public void shouldCopyWithDefaultParameters() throws Exception {
    // given
    final Folder folder = folderRepository.addFolder(home.getId(), "yet_another_folder");
    final String originalId = clientTest.createPreparation(createTestPreparation("prep_1", "1234"), folder.getId()).getId();
    final Folder toFolder = folderRepository.addFolder(home.getId(), "to");
    // when
    final Response response = // 
    given().queryParam("destination", // 
    toFolder.getId()).when().expect().statusCode(200).log().ifError().post("/preparations/{id}/copy", originalId);
    final String copyId = response.asString();
    // then
    assertThat(response.getStatusCode(), is(200));
    final Iterator<FolderEntry> iterator;
    try (Stream<FolderEntry> folderEntriesStream = folderRepository.entries(toFolder.getId(), PREPARATION)) {
        iterator = folderEntriesStream.iterator();
        boolean found = false;
        while (iterator.hasNext()) {
            final FolderEntry entry = iterator.next();
            if (entry.getContentId().equals(copyId)) {
                found = true;
                assertEquals("prep_1 copy", repository.get(entry.getContentId(), Preparation.class).getName());
            }
        }
        assertTrue(found);
    }
}
Also used : Response(com.jayway.restassured.response.Response) FolderEntry(org.talend.dataprep.api.folder.FolderEntry) Folder(org.talend.dataprep.api.folder.Folder) BasePreparationTest(org.talend.dataprep.preparation.BasePreparationTest) 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