use of org.drools.verifier.data.VerifierData in project drools by kiegroup.
the class NestedPatternsTest method runVisitor.
@Test
public void runVisitor() throws Exception {
VerifierData data = VerifierReportFactory.newVerifierData();
PackageDescrVisitor visitor = new PackageDescrVisitor(data, Collections.EMPTY_LIST);
assertNotNull(data);
Reader drlReader = new InputStreamReader(getClass().getResourceAsStream("NestedPatterns.drl"));
PackageDescr packageDescr = new DrlParser(LanguageLevelOption.DRL5).parse(drlReader);
assertNotNull(packageDescr);
visitor.visitPackageDescr(packageDescr);
Collection<VerifierComponent> all = data.getAll();
int patternCount = 0;
for (VerifierComponent verifierComponent : all) {
if (verifierComponent.getVerifierComponentType().equals(VerifierComponentType.PATTERN)) {
patternCount++;
}
}
assertEquals(4, patternCount);
Collection<Pattern> patterns = data.getAll(VerifierComponentType.PATTERN);
// for ( Pattern pattern : patterns ) {
// System.out.println( pattern.getPath() + " " + pattern );
// }
assertNotNull(patterns);
assertEquals(4, patterns.size());
Collection<Restriction> restrictions = data.getAll(VerifierComponentType.RESTRICTION);
// for ( Restriction restriction : restrictions ) {
// System.out.println( restriction.getPath() + " " + restriction );
// }
assertNotNull(restrictions);
assertEquals(3, restrictions.size());
}
use of org.drools.verifier.data.VerifierData in project drools by kiegroup.
the class VerifierComponentTest method testVisit.
@Test
public void testVisit() throws Exception {
// Drools Package description from Drl file
Reader drlReader = new InputStreamReader(Verifier.class.getResourceAsStream("Misc3.drl"));
PackageDescr descr = new DrlParser(LanguageLevelOption.DRL5).parse(drlReader);
// Drools Verifier objects
VerifierData verifierData = VerifierReportFactory.newVerifierData();
PackageDescrVisitor visitor = new PackageDescrVisitor(verifierData, Collections.EMPTY_LIST);
visitor.visitPackageDescr(descr);
// Collect the results.
Collection<VerifierComponent> datas = verifierData.getAll();
VerifierComponent[] components = datas.toArray(new VerifierComponent[datas.size()]);
// Misc3.drl
assertVerifierComponent((TextConsequence) components[0], 51);
assertVerifierComponent((TextConsequence) components[1], 42);
assertVerifierComponent((Field) components[2], 48);
assertVerifierComponent((Field) components[3], 39);
assertVerifierComponent((Field) components[4], 40);
assertVerifierComponent((Field) components[5], 41);
assertVerifierComponent((Import) components[6], 19);
assertVerifierComponent((ObjectType) components[7], 48);
assertVerifierComponent((ObjectType) components[8], 19);
assertVerifierComponent((ObjectType) components[9], 39);
assertVerifierComponent((ObjectType) components[10], 40);
assertVerifierComponent((ObjectType) components[11], 41);
assertVerifierComponent((RuleOperatorDescr) components[12], 48);
assertVerifierComponent((PatternOperatorDescr) components[13], 48);
assertVerifierComponent((PatternOperatorDescr) components[14], 49);
assertVerifierComponent((PatternOperatorDescr) components[15], 50);
assertVerifierComponent((RuleOperatorDescr) components[16], 39);
assertVerifierComponent((PatternOperatorDescr) components[17], 39);
assertVerifierComponent((PatternOperatorDescr) components[18], 40);
assertVerifierComponent((PatternOperatorDescr) components[19], 41);
assertVerifierComponent((Pattern) components[20], 48);
assertVerifierComponent((Pattern) components[21], 49);
assertVerifierComponent((Pattern) components[22], 50);
assertVerifierComponent((Pattern) components[23], 39);
assertVerifierComponent((Pattern) components[24], 40);
assertVerifierComponent((Pattern) components[25], 41);
assertVerifierComponent((NumberRestriction) components[26], 48);
assertVerifierComponent((NumberRestriction) components[27], 49);
assertVerifierComponent((NumberRestriction) components[28], 50);
assertVerifierComponent((NumberRestriction) components[29], 39);
assertVerifierComponent((NumberRestriction) components[30], 40);
assertVerifierComponent((NumberRestriction) components[31], 41);
assertVerifierComponent((NumberRestriction) components[32], 41);
assertVerifierComponent((VerifierRule) components[33], 46);
assertVerifierComponent((VerifierRule) components[34], 37);
assertVerifierComponent((RulePackage) components[35], 17);
assertVerifierComponent((SubPattern) components[36], 48);
assertVerifierComponent((SubPattern) components[37], 49);
assertVerifierComponent((SubPattern) components[38], 50);
assertVerifierComponent((SubPattern) components[39], 39);
assertVerifierComponent((SubPattern) components[40], 40);
assertVerifierComponent((SubPattern) components[41], 41);
assertVerifierComponent((SubRule) components[42], 46);
assertVerifierComponent((SubRule) components[43], 37);
assertVerifierComponent((WorkingMemory) components[44], -1);
}
use of org.drools.verifier.data.VerifierData 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));
}
use of org.drools.verifier.data.VerifierData in project drools by kiegroup.
the class HTMLReportWriter method writeMessages.
private void writeMessages(VerifierReport result) throws IOException {
VerifierData data = result.getVerifierData();
String errors = VerifierMessagesVisitor.visitVerifierMessagesCollection(Severity.ERROR.getTuple(), result.getBySeverity(Severity.ERROR), data);
String warnings = VerifierMessagesVisitor.visitVerifierMessagesCollection(Severity.WARNING.getTuple(), result.getBySeverity(Severity.WARNING), data);
String notes = VerifierMessagesVisitor.visitVerifierMessagesCollection(Severity.NOTE.getTuple(), result.getBySeverity(Severity.NOTE), data);
writeToFile(UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.HTML_FILE_VERIFIER_MESSAGES, formPage(UrlFactory.THIS_FOLDER, errors + warnings + notes));
}
use of org.drools.verifier.data.VerifierData in project drools by kiegroup.
the class HTMLReportWriter method writeReport.
public void writeReport(OutputStream out, VerifierReport result) throws IOException {
zout = new ZipOutputStream(out);
VerifierData data = result.getVerifierData();
// Base files
// index.htm
writeToFile(UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.HTML_FILE_INDEX, formPage(UrlFactory.THIS_FOLDER, ComponentsReportVisitor.visitObjectTypeCollection(UrlFactory.THIS_FOLDER, data.<ObjectType>getAll(VerifierComponentType.OBJECT_TYPE))));
// packages.htm
writeToFile(UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.HTML_FILE_PACKAGES, formPage(UrlFactory.THIS_FOLDER, ComponentsReportVisitor.visitRulePackageCollection(UrlFactory.THIS_FOLDER, data.<RulePackage>getAll(VerifierComponentType.RULE_PACKAGE))));
// Rules
String ruleFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.RULE_FOLDER;
for (VerifierRule rule : data.<VerifierRule>getAll(VerifierComponentType.RULE)) {
writeToFile(ruleFolder + File.separator + rule.getPath() + ".htm", formPage(UrlFactory.PREVIOUS_FOLDER, ComponentsReportVisitor.visitRule(UrlFactory.PREVIOUS_FOLDER, rule, data)));
}
// ObjectTypes
String objectTypeFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.OBJECT_TYPE_FOLDER;
for (ObjectType objectType : data.<ObjectType>getAll(VerifierComponentType.OBJECT_TYPE)) {
writeToFile(objectTypeFolder + File.separator + objectType.getPath() + ".htm", formPage(UrlFactory.PREVIOUS_FOLDER, ComponentsReportVisitor.visitObjectType(UrlFactory.PREVIOUS_FOLDER, objectType, data)));
}
// Fields
String fieldFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.FIELD_FOLDER;
for (Field field : data.<Field>getAll(VerifierComponentType.FIELD)) {
writeToFile(fieldFolder + File.separator + field.getPath() + ".htm", formPage(UrlFactory.PREVIOUS_FOLDER, ComponentsReportVisitor.visitField(UrlFactory.PREVIOUS_FOLDER, field, result)));
}
// Verifier messages
writeMessages(result);
// css files
String cssFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.CSS_FOLDER;
writeToFile(cssFolder + File.separator + UrlFactory.CSS_BASIC, ComponentsReportVisitor.getCss(UrlFactory.CSS_BASIC));
// Image files
String imagesFolder = UrlFactory.SOURCE_FOLDER + File.separator + UrlFactory.IMAGES_FOLDER;
copyFile(imagesFolder, "hdrlogo_drools50px.gif");
copyFile(imagesFolder, "jbossrules_hdrbkg_blue.gif");
zout.close();
}
Aggregations