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")));
}
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;
}
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));
}
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;
}
}
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);
}
}
Aggregations