Search in sources :

Example 6 with KnowledgeBuilderErrors

use of org.drools.builder.KnowledgeBuilderErrors in project jBPM5-Developer-Guide by Salaboy.

the class AsyncWorkItemWaitForCompletionTest method initializeSession.

private void initializeSession() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    //We are using a proces containing a single Task. The task is configured
    //to wait until the completion of the external system. A specialized
    //callback (CompleteWorkItemCallback) is used to complete the work item 
    //after the command was executed.
    kbuilder.add(new ClassPathResource("async-work-item-wait.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        for (KnowledgeBuilderError error : errors) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    session = kbase.newStatefulKnowledgeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    session.addEventListener(new DefaultAgendaEventListener() {

        @Override
        public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
            session.fireAllRules();
        }
    });
    //Registers the session in SessionStoreUtil. The callback we are using
    //for the process' Task will retrieve this session later and completes
    //the work item using it.
    SessionStoreUtil.sessionCache.put("sessionId=" + session.getId(), session);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) DefaultAgendaEventListener(org.drools.event.rule.DefaultAgendaEventListener) ClassPathResource(org.drools.io.impl.ClassPathResource)

Example 7 with KnowledgeBuilderErrors

use of org.drools.builder.KnowledgeBuilderErrors in project jBPM5-Developer-Guide by Salaboy.

the class GenericWebServiceTaskTest method initializeSession.

private void initializeSession() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("HospitalInvokeInsuranceScenarioV3-data.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        for (KnowledgeBuilderError error : errors) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    session = kbase.newStatefulKnowledgeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    session.addEventListener(new DefaultAgendaEventListener() {

        @Override
        public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
            session.fireAllRules();
        }
    });
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) DefaultAgendaEventListener(org.drools.event.rule.DefaultAgendaEventListener) ClassPathResource(org.drools.io.impl.ClassPathResource)

Example 8 with KnowledgeBuilderErrors

use of org.drools.builder.KnowledgeBuilderErrors in project jBPM5-Developer-Guide by Salaboy.

the class HospitalInsuranceProcessExecutorTest method initializeSession.

private void initializeSession() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("InsuranceProcessV2.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        for (KnowledgeBuilderError error : errors) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    session = kbase.newStatefulKnowledgeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    session.addEventListener(new DefaultAgendaEventListener() {

        @Override
        public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
            session.fireAllRules();
        }
    });
    //Registers the same generic handler for all the tasks. The handler will
    //schedule commands into the Executor Service. Each task in the process
    //is configured to use a different command.
    AsyncGenericWorkItemHandler genericHandler = new AsyncGenericWorkItemHandler(executor, session.getId());
    session.getWorkItemManager().registerWorkItemHandler("Gather Patient Data", genericHandler);
    session.getWorkItemManager().registerWorkItemHandler("Insurance Service", genericHandler);
    session.getWorkItemManager().registerWorkItemHandler("External Insurance Company Service", genericHandler);
    session.getWorkItemManager().registerWorkItemHandler("Rates Service", genericHandler);
    session.getWorkItemManager().registerWorkItemHandler("Invoice Service", genericHandler);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) AsyncGenericWorkItemHandler(com.salaboy.jbpm5.dev.guide.workitems.AsyncGenericWorkItemHandler) KnowledgeBase(org.drools.KnowledgeBase) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) DefaultAgendaEventListener(org.drools.event.rule.DefaultAgendaEventListener) ClassPathResource(org.drools.io.impl.ClassPathResource)

Example 9 with KnowledgeBuilderErrors

use of org.drools.builder.KnowledgeBuilderErrors in project jBPM5-Developer-Guide by Salaboy.

the class EmergencyBedRequestBaseTest method initializeSession.

/**
     * Compiles the resources indicated by the concrete implementation of 
     * this class (using {@link #getResources()} abstract method.
     * If there is any compilation error an {@link IllegalStateException} is
     * thrown.
     * After the resources are compiled, a kbase is created and populated with
     * the resulting knowledge package/s.
     * From this kbase, a new StatefulKnowledgeSession is created. The session
     * is configured with 2 listeners:
     * 1.- An Agenda event listener that will fireAllRules() every time an
     * activation happens
     * 2.- A Process event listener that will insert the process instance as
     * a Fact once a process is started.
     */
private void initializeSession() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    for (Map.Entry<Resource, ResourceType> entry : this.getResources().entrySet()) {
        kbuilder.add(entry.getKey(), entry.getValue());
    }
    if (kbuilder.hasErrors()) {
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        for (KnowledgeBuilderError error : errors) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    session = kbase.newStatefulKnowledgeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    session.addEventListener(new DefaultAgendaEventListener() {

        @Override
        public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
            session.fireAllRules();
        }
    });
    session.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            session.insert(event.getProcessInstance());
        }
    });
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) Resource(org.drools.io.Resource) ProcessStartedEvent(org.drools.event.process.ProcessStartedEvent) DefaultAgendaEventListener(org.drools.event.rule.DefaultAgendaEventListener) ResourceType(org.drools.builder.ResourceType) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) DefaultProcessEventListener(org.drools.event.process.DefaultProcessEventListener) Map(java.util.Map)

Example 10 with KnowledgeBuilderErrors

use of org.drools.builder.KnowledgeBuilderErrors in project jBPM5-Developer-Guide by Salaboy.

the class HospitalInsuranceProcessTest method initializeSession.

private void initializeSession() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("InsuranceProcessV1.bpmn"), ResourceType.BPMN2);
    if (kbuilder.hasErrors()) {
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        for (KnowledgeBuilderError error : errors) {
            System.out.println(">>> Error:" + error.getMessage());
        }
        throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    session = kbase.newStatefulKnowledgeSession();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
    session.addEventListener(new DefaultAgendaEventListener() {

        @Override
        public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
            session.fireAllRules();
        }
    });
    //Registers an independent mocked work item handler for each task present
    //in the process.
    PatientDataServiceWorkItemHandler patientDataHandler = new PatientDataServiceWorkItemHandler();
    session.getWorkItemManager().registerWorkItemHandler("Gather Patient Data", patientDataHandler);
    InsuranceServiceWorkItemHandler insuranceServiceHandler = new InsuranceServiceWorkItemHandler();
    session.getWorkItemManager().registerWorkItemHandler("Insurance Service", insuranceServiceHandler);
    CompanyGatewayWorkItemHandler companyGatewayHandler = new CompanyGatewayWorkItemHandler();
    session.getWorkItemManager().registerWorkItemHandler("External Insurance Company Service", companyGatewayHandler);
    RatesServiceWorkItemHandler ratesServiceHandler = new RatesServiceWorkItemHandler();
    session.getWorkItemManager().registerWorkItemHandler("Rates Service", ratesServiceHandler);
    InvoiceServiceWorkItemHandler invoiceServiceHandler = new InvoiceServiceWorkItemHandler();
    session.getWorkItemManager().registerWorkItemHandler("Invoice Service", invoiceServiceHandler);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) KnowledgeBuilderErrors(org.drools.builder.KnowledgeBuilderErrors) DefaultAgendaEventListener(org.drools.event.rule.DefaultAgendaEventListener) ClassPathResource(org.drools.io.impl.ClassPathResource) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase)

Aggregations

KnowledgeBuilder (org.drools.builder.KnowledgeBuilder)10 KnowledgeBuilderError (org.drools.builder.KnowledgeBuilderError)10 KnowledgeBuilderErrors (org.drools.builder.KnowledgeBuilderErrors)10 KnowledgeBase (org.drools.KnowledgeBase)9 ClassPathResource (org.drools.io.impl.ClassPathResource)9 DefaultAgendaEventListener (org.drools.event.rule.DefaultAgendaEventListener)7 KnowledgeBaseConfiguration (org.drools.KnowledgeBaseConfiguration)2 StatefulKnowledgeSession (org.drools.runtime.StatefulKnowledgeSession)2 HornetQHTWorkItemHandler (org.jbpm.process.workitem.wsht.HornetQHTWorkItemHandler)2 AsyncGenericWorkItemHandler (com.salaboy.jbpm5.dev.guide.workitems.AsyncGenericWorkItemHandler)1 Map (java.util.Map)1 ResourceType (org.drools.builder.ResourceType)1 DefaultProcessEventListener (org.drools.event.process.DefaultProcessEventListener)1 ProcessStartedEvent (org.drools.event.process.ProcessStartedEvent)1 DebugAgendaEventListener (org.drools.event.rule.DebugAgendaEventListener)1 Resource (org.drools.io.Resource)1 KnowledgeSessionConfiguration (org.drools.runtime.KnowledgeSessionConfiguration)1 QueryResultsRow (org.drools.runtime.rule.QueryResultsRow)1 Task (org.jbpm.task.Task)1 User (org.jbpm.task.User)1