use of com.buschmais.jqassistant.core.rule.api.model.RuleException in project jqa-core-framework by buschmais.
the class RulePluginRepositoryImpl method initialize.
@Override
public void initialize() {
for (JqassistantPlugin plugin : plugins) {
IdClassListType ruleParsers = plugin.getRuleParser();
if (ruleParsers != null) {
for (IdClassType pluginType : ruleParsers.getClazz()) {
RuleParserPlugin ruleParserPlugin = createInstance(pluginType.getValue());
try {
ruleParserPlugin.initialize();
} catch (RuleException e) {
throw new PluginRepositoryException("Cannot initialize plugin " + ruleParserPlugin, e);
}
ruleParserPlugins.add(ruleParserPlugin);
}
}
}
}
use of com.buschmais.jqassistant.core.rule.api.model.RuleException in project jqa-core-framework by buschmais.
the class AnalyzerRuleVisitor method getRuleParameters.
private Map<String, Object> getRuleParameters(ExecutableRule executableRule) throws RuleException {
Map<String, Object> ruleParameters = new HashMap<>();
Map<String, Parameter> parameters = executableRule.getParameters();
for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
String parameterName = entry.getKey();
Parameter parameter = entry.getValue();
Object parameterValue;
String parameterValueAsString = this.ruleParameters.get(parameterName);
if (parameterValueAsString != null) {
try {
parameterValue = parameter.getType().parse(parameterValueAsString);
} catch (RuleException e) {
throw new RuleException("Cannot determine value for parameter " + parameterName + "' of rule '" + executableRule + "'.");
}
} else {
parameterValue = parameter.getDefaultValue();
}
if (parameterValue == null) {
throw new RuleException("No value or default value defined for required parameter '" + parameterName + "' of rule '" + executableRule + "'.");
}
ruleParameters.put(parameterName, parameterValue);
}
return ruleParameters;
}
use of com.buschmais.jqassistant.core.rule.api.model.RuleException in project jqa-core-framework by buschmais.
the class AnalyzerRuleVisitor method execute.
private <T extends ExecutableRule> Result<T> execute(T executableRule, Severity severity) throws RuleException {
Map<String, Object> ruleParameters = getRuleParameters(executableRule);
Executable<?> executable = executableRule.getExecutable();
Collection<RuleInterpreterPlugin> languagePlugins = ruleInterpreterPlugins.get(executable.getLanguage());
if (languagePlugins == null) {
throw new RuleException("Could not determine plugin to execute " + executableRule);
}
for (RuleInterpreterPlugin languagePlugin : languagePlugins) {
if (languagePlugin.accepts(executableRule)) {
Result<T> result = execute(executableRule, severity, ruleParameters, languagePlugin);
if (result != null) {
return result;
}
}
}
throw new RuleException("No plugin for language '" + executable.getLanguage() + "' returned a result for " + executableRule);
}
use of com.buschmais.jqassistant.core.rule.api.model.RuleException 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();
}
use of com.buschmais.jqassistant.core.rule.api.model.RuleException in project jqa-core-framework by buschmais.
the class AggregationVerificationStrategy method verify.
@Override
public <T extends ExecutableRule> Result.Status verify(T executable, AggregationVerification verification, List<String> columnNames, List<Map<String, Object>> rows) throws RuleException {
LOGGER.debug("Verifying result of " + executable);
if (rows.isEmpty()) {
return getStatus(executable, 0, verification.getMin(), verification.getMax());
}
if (columnNames.isEmpty()) {
throw new RuleException("Result contains no columns, at least one with a numeric value is expected.");
}
String column = verification.getColumn();
if (column == null) {
column = columnNames.get(0);
LOGGER.debug("No aggregation column specified, using " + column);
}
for (Map<String, Object> row : rows) {
Object value = row.get(column);
if (value == null) {
throw new RuleException("The result does not contain a column '" + column);
} else if (!Number.class.isAssignableFrom(value.getClass())) {
throw new RuleException("The value in column '" + column + "' must be a numeric value but was '" + value + "'");
}
int aggregationValue = ((Number) value).intValue();
Result.Status status = getStatus(executable, aggregationValue, verification.getMin(), verification.getMax());
if (Result.Status.FAILURE.equals(status)) {
return Result.Status.FAILURE;
}
}
return Result.Status.SUCCESS;
}
Aggregations