use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class ExportParametersUtil method populateFromPreparationExportParameter.
/**
* Return a copy of the export parameter with all clean value for a preparation (good step Id and good datasetId)
*
* @param exportParam incoming export param
* @return a full value copy of the export parameter
*/
public ExportParameters populateFromPreparationExportParameter(ExportParameters exportParam) throws IOException {
ExportParameters result = new ExportParameters();
result.setPreparationId(exportParam.getPreparationId());
result.setExportType(exportParam.getExportType());
result.setFrom(exportParam.getFrom());
result.setContent(exportParam.getContent());
result.setArguments(exportParam.getArguments());
result.setExportName(exportParam.getExportName());
result.setDatasetId(exportParam.getDatasetId());
if (StringUtils.isNotEmpty(exportParam.getFilter())) {
result.setFilter(mapper.readTree(exportParam.getFilter()));
}
// we deal with a preparation export parameter. We need to populate stepId and datasetId
if (StringUtils.isNotEmpty(exportParam.getPreparationId())) {
Preparation prep = getPreparation(exportParam.getPreparationId(), exportParam.getStepId());
result.setStepId(getCleanStepId(prep, exportParam.getStepId()));
if (exportParam.getFrom() != ExportParameters.SourceType.FILTER) {
result.setDatasetId(prep.getDataSetId());
}
} else {
// it'w a dataset export parameter. We need to switch stepId to empty
result.setStepId("");
}
return result;
}
use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class PreparationAPITest method should_change_preparation_head.
@Test
public void should_change_preparation_head() throws Exception {
// given
final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparation", home.getId());
testClient.applyActionFromFile(preparationId, "transformation/upper_case_firstname.json");
Preparation preparation = preparationRepository.get(preparationId, Preparation.class);
final String newHead = preparationRepository.get(preparation.getHeadId(), Step.class).getParent();
// when
given().when().put("/api/preparations/{id}/head/{stepId}", preparationId, //
newHead).then().statusCode(200);
// then
preparation = preparationRepository.get(preparationId, Preparation.class);
assertThat(preparation.getHeadId(), is(newHead));
}
use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class PreparationAPITest method testPreparationUpdate.
// ------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------LIFECYCLE-----------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------
@Test
public void testPreparationUpdate() throws Exception {
// given
String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
final String preparationId = testClient.createPreparationFromDataset(tagadaId, "original_name", home.getId());
JsonPath longFormat = when().get("/api/preparations/?format=long").jsonPath();
assertThat(longFormat.getList("name").size(), is(1));
assertThat(longFormat.getList("name").get(0), is("original_name"));
assertThat(longFormat.getList("id").size(), is(1));
assertThat(longFormat.getList("id").get(0), is(preparationId));
Preparation preparation = new Preparation();
preparation.setId(preparationId);
String newName = "updated_name";
preparation.setName(newName);
// when
given().contentType(ContentType.JSON).body(preparation).put("/api/preparations/{id}", preparationId).asString();
// then
longFormat = when().get("/api/preparations/?format=long").jsonPath();
assertThat(longFormat.getList("name").size(), is(1));
assertThat(longFormat.getList("name").get(0), is(newName));
}
use of org.talend.dataprep.api.preparation.Preparation in project data-prep by Talend.
the class PreparationAPITest method shouldCopySteps.
@Test
public void shouldCopySteps() throws Exception {
// given
final String referenceId = testClient.createPreparationFromFile("dataset/dataset.csv", "reference", home.getId());
testClient.applyActionFromFile(referenceId, "transformation/upper_case_firstname.json");
Preparation reference = preparationRepository.get(referenceId, Preparation.class);
final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "prep", home.getId());
// when
final Response response = //
given().param("from", //
referenceId).expect().statusCode(200).log().ifError().when().put("/api/preparations/{id}/steps/copy", preparationId);
// then
assertThat(response.getStatusCode(), is(200));
final Preparation preparation = preparationRepository.get(preparationId, Preparation.class);
assertNotEquals(reference.getHeadId(), preparation.getHeadId());
assertEquals(preparation.getSteps().size(), reference.getSteps().size());
assertThat(preparation.getSteps().get(0).getId(), is(Step.ROOT_STEP.id()));
assertEquals(preparation.getSteps().get(1).getContent(), reference.getSteps().get(1).getContent());
}
use of org.talend.dataprep.api.preparation.Preparation 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());
}
Aggregations