use of org.drools.verifier.report.components.MissingRange in project drools by kiegroup.
the class DataRow method visitRestrictionsCollection.
public static Collection<String> visitRestrictionsCollection(String sourceFolder, Collection<Restriction> restrictions, Collection<MissingRange> causes) {
Multimap<String, DataRow> dt = TreeMultimap.create();
Collection<String> stringRows = new ArrayList<String>();
for (MissingRange cause : causes) {
dt.put(cause.getValueAsString(), new DataRow(null, null, cause.getOperator(), cause.getValueAsString()));
}
for (Restriction r : restrictions) {
if (r instanceof NumberRestriction) {
try {
NumberRestriction restriction = (NumberRestriction) r;
dt.put(restriction.getValue().toString(), new DataRow(restriction.getRulePath(), restriction.getRuleName(), restriction.getOperator(), restriction.getValueAsString()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
DataRow previous = null;
for (Iterator<DataRow> iterator = dt.values().iterator(); iterator.hasNext(); ) {
DataRow current = iterator.next();
if (previous != null) {
// Check if previous and current are from the same rule.
if (previous.ruleId == null && current.ruleId == null && !previous.operator.equals(Operator.EQUAL) && !previous.operator.equals(Operator.NOT_EQUAL) && !current.operator.equals(Operator.EQUAL) && !current.operator.equals(Operator.NOT_EQUAL)) {
// Combine these two.
stringRows.add("Missing : " + previous + " .. " + current);
if (iterator.hasNext())
current = iterator.next();
} else if (previous.ruleId != null && previous.ruleId.equals(current.ruleId)) {
// Combine these two.
stringRows.add(UrlFactory.getRuleUrl(sourceFolder, current.ruleId, current.ruleName) + " : " + previous.toString() + " " + current.toString());
if (iterator.hasNext())
current = iterator.next();
} else if (!iterator.hasNext()) {
// If this is last row
// Print previous and current if they were not merged.
processRangeOutput(previous, stringRows, sourceFolder);
processRangeOutput(current, stringRows, sourceFolder);
} else {
// If they are not from the same rule
// Print previous.
processRangeOutput(previous, stringRows, sourceFolder);
}
} else if (!iterator.hasNext()) {
processRangeOutput(current, stringRows, sourceFolder);
}
// Set current as previous.
previous = current;
}
return stringRows;
}
use of org.drools.verifier.report.components.MissingRange in project drools by kiegroup.
the class ComponentsReportVisitor method visitField.
public static String visitField(String sourceFolder, Field field, VerifierReport result) {
VerifierData data = result.getVerifierData();
ObjectType objectType = data.getVerifierObject(VerifierComponentType.OBJECT_TYPE, field.getObjectTypePath());
Collection<VerifierRule> rules = data.getRulesByFieldPath(field.getPath());
Map<String, Object> map = new HashMap<String, Object>();
map.put("sourceFolder", sourceFolder);
map.put("ruleFolder", UrlFactory.RULE_FOLDER);
map.put("objectTypeFolder", UrlFactory.OBJECT_TYPE_FOLDER);
map.put("fieldFolder", UrlFactory.FIELD_FOLDER);
map.put("field", field);
map.put("objectType", objectType);
map.put("rules", rules);
if (field.getFieldType() == Field.DOUBLE || field.getFieldType() == Field.DATE || field.getFieldType() == Field.INT) {
Collection<MissingRange> causes = result.getRangeCheckCausesByFieldPath(field.getPath());
Collection<Restriction> restrictions = data.getRestrictionsByFieldPath(field.getPath());
map.put("ranges", "Ranges:" + MissingRangesReportVisitor.visitRanges(UrlFactory.PREVIOUS_FOLDER, restrictions, causes));
} else {
map.put("ranges", "");
}
String myTemplate = readFile("field.htm");
return String.valueOf(TemplateRuntime.eval(myTemplate, map));
}
Aggregations