Search in sources :

Example 1 with Status

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();
}
Also used : Status(com.buschmais.jqassistant.core.report.api.model.Result.Status) Query(com.buschmais.xo.api.Query) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) LinkedList(java.util.LinkedList) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) Result(com.buschmais.jqassistant.core.report.api.model.Result) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Result (com.buschmais.jqassistant.core.report.api.model.Result)1 Status (com.buschmais.jqassistant.core.report.api.model.Result.Status)1 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)1 Query (com.buschmais.xo.api.Query)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1