use of com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method visitConcept.
@Override
public boolean visitConcept(Concept concept, Severity effectiveSeverity) throws RuleExecutorException {
try {
store.beginTransaction();
ConceptDescriptor conceptDescriptor = store.find(ConceptDescriptor.class, concept.getId());
Result.Status status;
if (conceptDescriptor == null || configuration.isExecuteAppliedConcepts()) {
logger.info("Applying concept '" + concept.getId() + "' with severity: '" + concept.getSeverity().getInfo(effectiveSeverity) + "'.");
reportPlugin.beginConcept(concept);
Result<Concept> result = execute(concept, effectiveSeverity);
reportPlugin.setResult(result);
status = result.getStatus();
if (conceptDescriptor == null) {
conceptDescriptor = store.create(ConceptDescriptor.class);
conceptDescriptor.setId(concept.getId());
conceptDescriptor.setStatus(result.getStatus());
}
reportPlugin.endConcept();
} else {
status = conceptDescriptor.getStatus();
}
store.commitTransaction();
return Result.Status.SUCCESS.equals(status);
} catch (XOException e) {
store.rollbackTransaction();
throw new RuleExecutorException("Cannot apply concept " + concept.getId(), e);
}
}
use of com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method visitConstraint.
@Override
public void visitConstraint(Constraint constraint, Severity effectiveSeverity) throws RuleExecutorException {
logger.info("Validating constraint '" + constraint.getId() + "' with severity: '" + constraint.getSeverity().getInfo(effectiveSeverity) + "'.");
try {
store.beginTransaction();
reportPlugin.beginConstraint(constraint);
reportPlugin.setResult(execute(constraint, effectiveSeverity));
reportPlugin.endConstraint();
store.commitTransaction();
} catch (XOException e) {
store.rollbackTransaction();
throw new RuleExecutorException("Cannot validate constraint " + constraint.getId(), e);
}
}
use of com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method getRuleParameters.
private Map<String, Object> getRuleParameters(ExecutableRule executableRule) throws RuleExecutorException {
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 RuleExecutorException("Cannot determine value for parameter " + parameterName + "' of rule '" + executableRule + "'.");
}
} else {
parameterValue = parameter.getDefaultValue();
}
if (parameterValue == null) {
throw new RuleExecutorException("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.executor.RuleExecutorException in project jqa-core-framework by buschmais.
the class AnalyzerVisitor method executeCypher.
/**
* Execute the cypher query of a rule.
*
* @param executableRule
* The executable.
* @param executable
* The executable.
* @param parameters
* The parameters.
* @param severity
* The severity.
* @param <T>
* The rule type.
* @return The result.
* @throws RuleExecutorException
* If execution fails.
*/
private <T extends ExecutableRule> Result<T> executeCypher(T executableRule, CypherExecutable executable, Map<String, Object> parameters, Severity severity) throws RuleExecutorException {
String cypher = executable.getStatement();
List<Map<String, Object>> rows = new ArrayList<>();
try (Query.Result<Query.Result.CompositeRowObject> compositeRowObjects = executeQuery(cypher, parameters)) {
List<String> columnNames = null;
for (Query.Result.CompositeRowObject rowObject : compositeRowObjects) {
if (columnNames == null) {
columnNames = new ArrayList<>(rowObject.getColumns());
}
Map<String, Object> row = new LinkedHashMap<>();
for (String columnName : columnNames) {
row.put(columnName, rowObject.get(columnName, Object.class));
}
rows.add(row);
}
Result.Status status = verify(executableRule, columnNames, rows);
return new Result<>(executableRule, status, severity, columnNames, rows);
} catch (Exception e) {
throw new RuleExecutorException("Cannot execute query for rule '" + executableRule + "'.", e);
}
}
use of com.buschmais.jqassistant.core.rule.api.executor.RuleExecutorException in project jqa-core-framework by buschmais.
the class AnalyzerVisitorTest method missingParameter.
@Test
public void missingParameter() throws RuleException {
String statement = "match (n) return n";
Concept concept = createConcept(statement);
ReportPlugin reportWriter = mock(ReportPlugin.class);
try {
AnalyzerVisitor analyzerVisitor = new AnalyzerVisitor(configuration, Collections.<String, String>emptyMap(), store, reportWriter, console);
analyzerVisitor.visitConcept(concept, Severity.MINOR);
fail("Expecting an " + RuleExecutorException.class.getName());
} catch (RuleExecutorException e) {
String message = e.getMessage();
assertThat(message, containsString(concept.getId()));
assertThat(message, containsString(PARAMETER_WITHOUT_DEFAULT));
}
}
Aggregations