use of com.buschmais.jqassistant.core.report.api.model.Result.Status in project jqa-core-framework by buschmais.
the class AbstractCypherRuleInterpreterPlugin method execute.
protected <T extends ExecutableRule<?>> Result<T> execute(String cypher, T executableRule, Map<String, Object> parameters, Severity severity, AnalyzerContext context) throws RuleException {
List<Map<String, Object>> rows = new LinkedList<>();
context.getLogger().debug("Executing query '" + cypher + "' with parameters [" + parameters + "]");
String primaryColumn = null;
List<String> columnNames = null;
try (Query.Result<Query.Result.CompositeRowObject> compositeRowObjects = context.getStore().executeQuery(cypher, parameters)) {
for (Query.Result.CompositeRowObject rowObject : compositeRowObjects) {
if (columnNames == null) {
columnNames = unmodifiableList(rowObject.getColumns());
primaryColumn = executableRule.getReport().getPrimaryColumn();
if (primaryColumn == null) {
primaryColumn = columnNames.get(0);
}
}
Map<String, Object> row = new LinkedHashMap<>();
for (String columnName : columnNames) {
row.put(columnName, rowObject.get(columnName, Object.class));
}
if (!isSuppressedRow(executableRule.getId(), row, primaryColumn)) {
rows.add(row);
}
}
} catch (Exception e) {
throw new RuleException("Cannot execute query for rule '" + executableRule + "'.", e);
}
Status status = getStatus(executableRule, columnNames, rows, context);
return Result.<T>builder().rule(executableRule).status(status).severity(severity).columnNames(columnNames).rows(rows).build();
}
Aggregations