use of org.talend.dataprep.api.preparation.Actions in project data-prep by Talend.
the class ActionMetadataTestUtils method parseParameters.
/**
* Parse the given input stream into a parameter map.
*
* @param input the parameters input stream.
* @return the parsed parameters.
* @throws IOException if an error occurs.
*/
public static Map<String, String> parseParameters(InputStream input) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MixedContentMapModule());
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
List<Action> parsedAction = ((Actions) mapper.reader(Actions.class).readValue(input)).getActions();
return parsedAction.get(0).getParameters();
}
use of org.talend.dataprep.api.preparation.Actions in project data-prep by Talend.
the class ActionParser method parse.
/**
* Return the parsed actions ready to be run.
*
* @param actions the actions to be parsed as string.
* @return the parsed actions.
* @throws IllegalArgumentException if <code>actions</code> is null.
*/
public List<RunnableAction> parse(String actions) {
if (actions == null) {
// Actions cannot be null (but can be empty string for no op actions).
throw new IllegalArgumentException("Actions parameter can not be null.");
}
if (StringUtils.isEmpty(actions)) {
return Collections.emptyList();
}
try {
// Parse action JSON
final Actions parsedActions = mapper.reader(Actions.class).readValue(actions);
final List<Action> allActions = parsedActions.getActions();
// Create closures from parsed actions
final List<RunnableAction> builtActions = new ArrayList<>(allActions.size() + 1);
//
allActions.stream().filter(//
parsedAction -> parsedAction != null && parsedAction.getName() != null).forEach(parsedAction -> {
String actionNameLowerCase = parsedAction.getName().toLowerCase();
final ActionDefinition metadata = actionRegistry.get(actionNameLowerCase);
builtActions.add(factory.create(metadata, parsedAction.getParameters()));
});
// all set: wraps everything and return to caller
return builtActions;
} catch (TalendRuntimeException tpe) {
// leave TDPException as is
throw tpe;
} catch (Exception e) {
throw new TalendRuntimeException(BaseErrorCodes.UNABLE_TO_PARSE_JSON, e);
}
}
Aggregations