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