Search in sources :

Example 1 with VerifierError

use of org.drools.verifier.VerifierError in project drools by kiegroup.

the class VerifierKnowledgeBaseBuilder method newVerifierKnowledgeBase.

public KieBase newVerifierKnowledgeBase(VerifierConfiguration configuration) {
    InternalKnowledgeBase verifierKnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
    KnowledgeBuilderConfiguration kbuilderConfiguration = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
    kbuilderConfiguration.setProperty("drools.dialect.java.compiler", "JANINO");
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbuilderConfiguration);
    if (configuration.getVerifyingResources() != null) {
        for (Resource resource : configuration.getVerifyingResources().keySet()) {
            kbuilder.add(resource, configuration.getVerifyingResources().get(resource));
        }
    }
    if (kbuilder.hasErrors()) {
        Iterator<KnowledgeBuilderError> errors = kbuilder.getErrors().iterator();
        while (errors.hasNext()) {
            this.errors.add(new VerifierError("Error compiling verifier rules: " + errors.next().getMessage()));
        }
    }
    verifierKnowledgeBase.addPackages(kbuilder.getKnowledgePackages());
    return verifierKnowledgeBase;
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) VerifierError(org.drools.verifier.VerifierError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Resource(org.kie.api.io.Resource) KnowledgeBuilderConfiguration(org.kie.internal.builder.KnowledgeBuilderConfiguration) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase)

Example 2 with VerifierError

use of org.drools.verifier.VerifierError in project drools by kiegroup.

the class VerifierImpl method addResourcesToVerify.

public void addResourcesToVerify(Resource resource, ResourceType type) {
    verifierPackageBuilder.addKnowledgeResource(resource, type, null);
    if (verifierPackageBuilder.hasErrors()) {
        addVerifierErrors(verifierPackageBuilder.getErrors());
    }
    PackageDescr pkg = verifierPackageBuilder.getPackageDescr();
    if (pkg != null) {
        addPackageDescr(pkg);
    } else {
        errors.add(new VerifierError("Verifier could not form a PackageDescr from the resources that it was trying to verify."));
    }
}
Also used : VerifierError(org.drools.verifier.VerifierError) PackageDescr(org.drools.compiler.lang.descr.PackageDescr)

Example 3 with VerifierError

use of org.drools.verifier.VerifierError in project drools by kiegroup.

the class SubsumptantSubPatternsTest method testSubpatternSubsumption1.

@Test
public void testSubpatternSubsumption1() throws Exception {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    Verifier verifier = vBuilder.newVerifier();
    verifier.addResourcesToVerify(ResourceFactory.newClassPathResource("SubsumptantSubPatterns1.drl", getClass()), ResourceType.DRL);
    // for ( VerifierError error : verifier.getMissingClasses() ) {
    // System.out.println( error.getMessage() );
    // }
    assertFalse(verifier.hasErrors());
    boolean noProblems = verifier.fireAnalysis();
    if (!noProblems) {
        for (VerifierError error : verifier.getErrors()) {
            System.out.println(error.getMessage());
        }
    }
    Collection<? extends Object> subsumptionList = ((VerifierImpl) verifier).getKnowledgeSession().getObjects(new ClassObjectFilter(Subsumption.class));
    int count = 0;
    for (Object object : subsumptionList) {
        // System.out.println( " * " + ((Subsumption) object) );
        if (((VerifierComponent) ((Subsumption) object).getLeft()).getVerifierComponentType().equals(VerifierComponentType.SUB_PATTERN)) {
            // System.out.println( " ** " + ((SubPattern) ((Subsumption) object).getLeft()).getItems() + " - " + ((SubPattern) ((Subsumption) object).getRight()).getItems() );
            count++;
        }
    }
    assertEquals(1, count);
    verifier.dispose();
}
Also used : VerifierError(org.drools.verifier.VerifierError) Subsumption(org.drools.verifier.report.components.Subsumption) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) Verifier(org.drools.verifier.Verifier) Test(org.junit.Test)

Example 4 with VerifierError

use of org.drools.verifier.VerifierError in project drools by kiegroup.

the class VerifierImpl method addResourcesToVerify.

public void addResourcesToVerify(Resource resource, ResourceType type, ResourceConfiguration config) {
    verifierPackageBuilder.addKnowledgeResource(resource, type, config);
    if (verifierPackageBuilder.hasErrors()) {
        addVerifierErrors(verifierPackageBuilder.getErrors());
    }
    PackageDescr pkg = verifierPackageBuilder.getPackageDescr();
    if (pkg != null) {
        addPackageDescr(pkg);
    } else {
        errors.add(new VerifierError("Verifier could not form a PackageDescr from the resources that it was trying to verify."));
    }
}
Also used : VerifierError(org.drools.verifier.VerifierError) PackageDescr(org.drools.compiler.lang.descr.PackageDescr)

Aggregations

VerifierError (org.drools.verifier.VerifierError)4 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 Verifier (org.drools.verifier.Verifier)1 VerifierBuilder (org.drools.verifier.builder.VerifierBuilder)1 Subsumption (org.drools.verifier.report.components.Subsumption)1 Test (org.junit.Test)1 Resource (org.kie.api.io.Resource)1 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1 KnowledgeBuilderConfiguration (org.kie.internal.builder.KnowledgeBuilderConfiguration)1 KnowledgeBuilderError (org.kie.internal.builder.KnowledgeBuilderError)1