Search in sources :

Example 11 with ObjectType

use of org.drools.verifier.components.ObjectType in project drools by kiegroup.

the class VerifierDataMapsTest method testSaveVerifierComponentAndGetForAllComponentTypes.

@Test
public void testSaveVerifierComponentAndGetForAllComponentTypes() {
    RulePackage rulePackage = VerifierComponentMockFactory.createPackage1();
    saveVerifierComponentAndGet(rulePackage);
    VerifierRule rule = VerifierComponentMockFactory.createRule1();
    saveVerifierComponentAndGet(rule);
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    saveVerifierComponentAndGet(pattern);
    saveVerifierComponentAndGet(new InlineEvalDescr(pattern));
    saveVerifierComponentAndGet(new ObjectType(new PackageDescr("testPackage1")));
    saveVerifierComponentAndGet(new RuleOperatorDescr(new AndDescr(), rule, OperatorDescrType.AND));
    saveVerifierComponentAndGet(new PatternOperatorDescr(pattern, OperatorDescrType.AND));
    saveVerifierComponentAndGet(new SubPattern(pattern, 0));
    saveVerifierComponentAndGet(new ReturnValueFieldDescr(pattern));
    saveVerifierComponentAndGet(new SubRule(rule, 0));
    saveVerifierComponentAndGet(new TextConsequence(rule));
    saveVerifierComponentAndGet(new PatternVariable(rule));
    saveVerifierComponentAndGet(new VerifierAccessorDescr(rule));
    saveVerifierComponentAndGet(new VerifierAccumulateDescr(pattern));
    saveVerifierComponentAndGet(new VerifierCollectDescr(pattern));
    saveVerifierComponentAndGet(new RuleEval(rule));
    saveVerifierComponentAndGet(new VerifierFieldAccessDescr(rule));
    saveVerifierComponentAndGet(new VerifierFromDescr(pattern));
    saveVerifierComponentAndGet(new VerifierMethodAccessDescr(rule));
    saveVerifierComponentAndGet(new PatternEval(pattern));
}
Also used : Pattern(org.drools.verifier.components.Pattern) SubPattern(org.drools.verifier.components.SubPattern) TextConsequence(org.drools.verifier.components.TextConsequence) PatternVariable(org.drools.verifier.components.PatternVariable) VerifierMethodAccessDescr(org.drools.verifier.components.VerifierMethodAccessDescr) ReturnValueFieldDescr(org.drools.verifier.components.ReturnValueFieldDescr) SubRule(org.drools.verifier.components.SubRule) VerifierFieldAccessDescr(org.drools.verifier.components.VerifierFieldAccessDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) VerifierAccumulateDescr(org.drools.verifier.components.VerifierAccumulateDescr) VerifierRule(org.drools.verifier.components.VerifierRule) VerifierFromDescr(org.drools.verifier.components.VerifierFromDescr) SubPattern(org.drools.verifier.components.SubPattern) RuleEval(org.drools.verifier.components.RuleEval) RulePackage(org.drools.verifier.components.RulePackage) PatternEval(org.drools.verifier.components.PatternEval) ObjectType(org.drools.verifier.components.ObjectType) PatternOperatorDescr(org.drools.verifier.components.PatternOperatorDescr) RuleOperatorDescr(org.drools.verifier.components.RuleOperatorDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) VerifierCollectDescr(org.drools.verifier.components.VerifierCollectDescr) VerifierAccessorDescr(org.drools.verifier.components.VerifierAccessorDescr) InlineEvalDescr(org.drools.verifier.components.InlineEvalDescr) Test(org.junit.Test)

Example 12 with ObjectType

use of org.drools.verifier.components.ObjectType in project drools by kiegroup.

the class VerifierDataMapsTest method saveVerifierComponentAndGet.

private void saveVerifierComponentAndGet(Field field) {
    VerifierData data = VerifierReportFactory.newVerifierData();
    ObjectType objectType = new ObjectType(new PackageDescr("testPackage1"));
    field.setObjectTypePath(objectType.getPath());
    data.add(objectType);
    data.add(field);
    Collection<VerifierComponent> all = data.getAll();
    assertEquals(2, all.size());
    assertTrue(all.contains(objectType));
    assertTrue(all.contains(field));
    Collection<VerifierComponent> fields = data.getAll(field.getVerifierComponentType());
    assertEquals(1, fields.size());
    assertEquals(field, fields.toArray()[0]);
    VerifierComponent field2 = data.getVerifierObject(field.getVerifierComponentType(), field.getPath());
    assertNotNull(field2);
    assertEquals(field, field2);
    Collection<VerifierComponent> objectTypes = data.getAll(objectType.getVerifierComponentType());
    assertEquals(1, objectTypes.size());
    assertEquals(objectType, objectTypes.toArray()[0]);
    VerifierComponent objectType2 = data.getVerifierObject(objectType.getVerifierComponentType(), objectType.getPath());
    assertNotNull(objectType2);
    assertEquals(objectType, objectType2);
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) PackageDescr(org.drools.compiler.lang.descr.PackageDescr)

Example 13 with ObjectType

use of org.drools.verifier.components.ObjectType 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));
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Restriction(org.drools.verifier.components.Restriction) MissingRange(org.drools.verifier.report.components.MissingRange) VerifierData(org.drools.verifier.data.VerifierData) HashMap(java.util.HashMap) VerifierRule(org.drools.verifier.components.VerifierRule)

Example 14 with ObjectType

use of org.drools.verifier.components.ObjectType 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();
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Field(org.drools.verifier.components.Field) VerifierData(org.drools.verifier.data.VerifierData) ZipOutputStream(java.util.zip.ZipOutputStream) VerifierRule(org.drools.verifier.components.VerifierRule)

Aggregations

ObjectType (org.drools.verifier.components.ObjectType)14 Field (org.drools.verifier.components.Field)7 VerifierRule (org.drools.verifier.components.VerifierRule)5 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)4 Test (org.junit.Test)4 Import (org.drools.verifier.components.Import)3 VerifierReport (org.drools.verifier.data.VerifierReport)3 IOException (java.io.IOException)2 JarInputStream (java.util.jar.JarInputStream)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)2 EnumField (org.drools.verifier.components.EnumField)2 Pattern (org.drools.verifier.components.Pattern)2 PatternVariable (org.drools.verifier.components.PatternVariable)2 SubPattern (org.drools.verifier.components.SubPattern)2 VerifierData (org.drools.verifier.data.VerifierData)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1