use of org.apache.metron.parsers.ParserRunnerImpl in project metron by apache.
the class StellarParserRunner method doParse.
private List<JSONObject> doParse(List<String> messages) {
// initialize
HashSet<String> sensorTypes = new HashSet<>();
sensorTypes.add(sensorType);
ParserRunnerImpl runner = new ParserRunnerImpl(sensorTypes);
runner.init(() -> parserConfigurations, context);
// parse each message
List<ParserRunnerResults<JSONObject>> results = messages.stream().map(str -> str.getBytes(StandardCharsets.UTF_8)).map(bytes -> DEFAULT.get(emptyMap(), bytes, false, emptyMap())).map(msg -> runner.execute(sensorType, msg, parserConfigurations)).collect(Collectors.toList());
// aggregate both successes and errors into a list that can be returned
List<JSONObject> successes = results.stream().flatMap(result -> result.getMessages().stream()).collect(Collectors.toList());
successCount += successes.size();
List<JSONObject> errors = results.stream().flatMap(result -> result.getErrors().stream()).map(err -> err.getJSONObject()).collect(Collectors.toList());
errorCount += errors.size();
// return a list of both successes and errors
successes.addAll(errors);
return successes;
}
Aggregations