use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class ActionParserTest method should_return_expected_actions.
@Test
public void should_return_expected_actions() throws IOException {
String json = IOUtils.toString(ActionParserTest.class.getResourceAsStream("actions.json"), UTF_8);
// when
List<RunnableAction> actualActions = actionParser.parse(json);
// then
assertTrue(actualActions.size() == 1);
Action actionParsed = actualActions.get(0);
assertEquals("lookup", actionParsed.getName());
}
use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class SerializableTest method testSerializableClass.
@Test
public void testSerializableClass() throws Exception {
LOGGER.info("{} actions for testing...", actions.length);
int okActions = 0;
for (ActionDefinition action : actions) {
Map<String, String> parameters = new HashMap<>();
if (action.acceptScope(ScopeCategory.COLUMN)) {
parameters.put(ImplicitParameters.SCOPE.getKey(), "COLUMN");
} else if (action.acceptScope(ScopeCategory.CELL)) {
parameters.put(ImplicitParameters.SCOPE.getKey(), "CELL");
} else if (action.acceptScope(ScopeCategory.LINE)) {
parameters.put(ImplicitParameters.SCOPE.getKey(), "LINE");
} else if (action.acceptScope(ScopeCategory.DATASET)) {
parameters.put(ImplicitParameters.SCOPE.getKey(), "DATASET");
}
parameters.put(ImplicitParameters.COLUMN_ID.getKey(), "0000");
parameters.put(ImplicitParameters.ROW_ID.getKey(), "0");
final Action actionInstance = factory.create(action, parameters);
try {
try (ObjectOutputStream oos = new ObjectOutputStream(new NullOutputStream())) {
oos.writeObject(actionInstance);
oos.flush();
}
okActions++;
} catch (IOException e) {
LOGGER.error("Unable to serialize {}", action.getClass());
}
}
LOGGER.info("{} actions for tested ({}/{} ok).", actions.length, okActions, actions.length);
}
use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class PreparationAPITest method testPreparationPreviewOnPreparationWithTrimAction_TDP_5057.
/**
* Verify a calculate time since preview after a trim step on a preparation
* see <a href="https://jira.talendforge.org/browse/TDP-5057">TDP-5057</a>
*/
@Test
public void testPreparationPreviewOnPreparationWithTrimAction_TDP_5057() throws IOException {
// Create a dataset from csv
final String datasetId = testClient.createDataset("preview/best_sad_songs_of_all_time.csv", "testPreview");
// Create a preparation
String preparationId = testClient.createPreparationFromDataset(datasetId, "testPrep", home.getId());
// apply trim action on the 8nd column to make this column date valid
Map<String, String> trimParameters = new HashMap<>();
trimParameters.put("create_new_column", "false");
trimParameters.put("padding_character", "whitespace");
trimParameters.put("scope", "column");
trimParameters.put("column_id", "0008");
trimParameters.put("column_name", "Added At");
trimParameters.put("row_id", "null");
testClient.applyAction(preparationId, Trim.TRIM_ACTION_NAME, trimParameters);
// check column is date valid after trim action
InputStream inputStream = testClient.getPreparation(preparationId).asInputStream();
mapper.getDeserializationConfig().without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
RowMetadata preparationContent = mapper.readValue(inputStream, Data.class).metadata;
List<PatternFrequency> patternFrequencies = preparationContent.getColumns().get(8).getStatistics().getPatternFrequencies();
assertTrue(patternFrequencies.stream().map(//
PatternFrequency::getPattern).anyMatch("yyyy-MM-dd"::equals));
// create a preview of calculate time since action
PreviewAddParameters previewAddParameters = new PreviewAddParameters();
previewAddParameters.setDatasetId(datasetId);
previewAddParameters.setPreparationId(preparationId);
previewAddParameters.setTdpIds(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
Action calculateTimeUntilAction = new Action();
calculateTimeUntilAction.setName(ComputeTimeSince.TIME_SINCE_ACTION_NAME);
MixedContentMap actionParameters = new MixedContentMap();
actionParameters.put("create_new_column", "true");
actionParameters.put("time_unit", "HOURS");
actionParameters.put("since_when", "now_server_side");
actionParameters.put("scope", "column");
actionParameters.put("column_id", "0008");
actionParameters.put("column_name", "Added At");
calculateTimeUntilAction.setParameters(actionParameters);
previewAddParameters.setActions(Collections.singletonList(calculateTimeUntilAction));
JsonPath jsonPath = given().contentType(//
ContentType.JSON).body(//
previewAddParameters).expect().statusCode(200).log().ifError().when().post(//
"/api/preparations/preview/add").jsonPath();
// check non empty value for the new column
assertEquals(//
"new preview column should contains values according to calculate time since action", //
0, jsonPath.getList("records.0009").stream().map(String::valueOf).filter(StringUtils::isBlank).count());
}
use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class APIClientTest method applyAction.
/**
* Add a step to a preparation.
*
* @param preparationId the preparation id.
* @param actionName action name
* @param parameters action parameters
* @throws IOException sh*t happens.
*/
public void applyAction(final String preparationId, final String actionName, Map<String, String> parameters) throws IOException {
org.talend.dataprep.api.preparation.Actions actions = new org.talend.dataprep.api.preparation.Actions();
Action action = new Action();
action.setName(actionName);
action.setParameters(MixedContentMap.convert(parameters));
actions.setActions(Collections.singletonList(action));
given().contentType(JSON.withCharset(UTF_8)).content(//
actions).when().post("/api/preparations/{id}/actions", //
preparationId).then().statusCode(is(200));
}
use of org.talend.dataprep.api.preparation.Action in project data-prep by Talend.
the class ActionsStaticProfiler method getActionMetadataByAction.
/**
* Get the actions metadata by actions
*/
private Map<Action, ActionDefinition> getActionMetadataByAction(final List<RunnableAction> actions) {
final Map<Action, ActionDefinition> actionToMetadata = new HashMap<>(actions.size());
for (final Action action : actions) {
final ActionDefinition actionMetadata = //
actionRegistry.get(action.getName()).adapt(ScopeCategory.from(action.getParameters().get(ImplicitParameters.SCOPE.getKey())));
actionToMetadata.put(action, actionMetadata);
}
return actionToMetadata;
}
Aggregations