当前位置: 首页>>代码示例>>Java>>正文


Java KieBase类代码示例

本文整理汇总了Java中org.kie.api.KieBase的典型用法代码示例。如果您正苦于以下问题:Java KieBase类的具体用法?Java KieBase怎么用?Java KieBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KieBase类属于org.kie.api包,在下文中一共展示了KieBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doTest

import org.kie.api.KieBase; //导入依赖的package包/类
@Test
public void doTest() {
    try {
    	KieBase kbase = getKieBase(URL, USER, PASSWORD);
        RuntimeManager manager = getRuntimeManager(kbase);        
        RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
        KieSession ksession = runtime.getKieSession();
        ksession.startProcess("test.proc_ht");

        // "sales-rep" reviews request
        TaskService taskService = runtime.getTaskService();
		long taskId = taskService.getTasksAssignedAsPotentialOwner(TASK_USER, "en-UK").get(0).getId();
		taskService.claim(taskId, TASK_USER);
		taskService.start(taskId, TASK_USER);
		taskService.complete(taskId, TASK_USER, null);
		System.out.println("Process instance completed");
		manager.disposeRuntimeEngine(runtime);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(0);
}
 
开发者ID:jesuino,项目名称:bpms6-examples,代码行数:23,代码来源:HumanTaskTest.java

示例2: determineWorkgroups

import org.kie.api.KieBase; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public List<String> determineWorkgroups(TaskTemplate taskTemplate, TaskInstance taskInstance) throws StrategyException {
    KieBase knowledgeBase = getKnowledgeBase();

    StatelessKieSession knowledgeSession = knowledgeBase.newStatelessKieSession();

    List<Object> facts = new ArrayList<Object>();
    facts.add(getParameters());
    knowledgeSession.setGlobal("taskTemplate", taskTemplate);
    knowledgeSession.setGlobal("taskInstance", taskInstance);
    knowledgeSession.setGlobal("now", new Date());

    knowledgeSession.execute(CommandFactory.newInsertElements(facts));

    return taskInstance.getWorkgroups();
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:17,代码来源:RulesBasedRoutingStrategy.java

示例3: getKnowledgeBase

import org.kie.api.KieBase; //导入依赖的package包/类
/**
 * Returns the asset based on specified version/range whose attributes match the custom attribute
 * Override to apply additional or non-standard conditions.
 */
protected KieBase getKnowledgeBase(String name, String assetVersion, String modifier) throws ActivityException {
    Map<String,String> customAttrs = null;
    KnowledgeBaseAsset kbrs;
    if (assetVersion == null)
        kbrs = DroolsKnowledgeBaseCache.getKnowledgeBaseAsset(name, modifier, customAttrs, getClassLoader());
    else
        kbrs = DroolsKnowledgeBaseCache.getKnowledgeBaseAsset(new AssetVersionSpec(name, assetVersion), modifier, customAttrs, getClassLoader());

    if (kbrs == null) {
        return null;
    }
    else {
        super.loginfo("Using Knowledge Base: " + kbrs.getAsset().getLabel());

        String versionLabelVarName = getAttributeValue(RULE_VERSION_VAR);
        if (versionLabelVarName != null)
            setParameterValue(versionLabelVarName, kbrs.getAsset().getLabel());
        return kbrs.getKnowledgeBase();
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:25,代码来源:DroolsActivity.java

示例4: determineDueDate

import org.kie.api.KieBase; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Date determineDueDate(TaskTemplate taskTemplate) throws StrategyException {

    TaskInstance taskInstanceVO = new TaskInstance();  // for holding values

    // execute rules only once (results are stored in taskInstanceVO)
    KieBase knowledgeBase = getKnowledgeBase();
    StatelessKieSession knowledgeSession = knowledgeBase.newStatelessKieSession();

    List<Object> facts = new ArrayList<Object>();
    facts.add(getParameters());
    knowledgeSession.setGlobal("taskTemplate", taskTemplate);
    knowledgeSession.setGlobal("taskInstance", taskInstanceVO);

    knowledgeSession.execute(CommandFactory.newInsertElements(facts));

    return Date.from(taskInstanceVO.getDue());
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw-demo,代码行数:20,代码来源:RulesBasedPrioritizationStrategy.java

示例5: helloDroolsTest

import org.kie.api.KieBase; //导入依赖的package包/类
@Test
public void helloDroolsTest() {

    System.out.println( "Bootstrapping the Rule Engine ..." );
    // Bootstrapping a Rule Engine Session
    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.newKieClasspathContainer();
    KieBase kBase = kContainer.getKieBase( "confKBase" );

    KieSession kSession = kBase.newKieSession();
    ArrayList<String> errors = new ArrayList<String>();
    kSession.setGlobal( "errors", errors );
    House house = new House( "Maniac Mansion" );
    kSession.insert( house );

    int fired = kSession.fireAllRules();
    assertEquals( 1, fired );
    assertEquals( 1, errors.size() );
    assertThat( errors, Matchers.contains( "Warn: Your House ( " + house.getName() + " ) has no Rooms" ) );

    kSession.dispose();

}
 
开发者ID:Salaboy,项目名称:drools-game-engine,代码行数:24,代码来源:E_NoCDIRulesTest.java

示例6: setup

import org.kie.api.KieBase; //导入依赖的package包/类
@Before
public void setup() {
    KieServices kieServices = KieServices.Factory.get();

    KieContainer kContainer = kieServices.getKieClasspathContainer();
    Results verifyResults = kContainer.verify();
    for (Message m : verifyResults.getMessages()) {
        LOG.debug("Kie container message: {}", m);
    }

    KieBase kieBase = kContainer.getKieBase();
    LOG.debug("Created kieBase");

    for ( KiePackage kp : kieBase.getKiePackages() ) {
        for (Rule rule : kp.getRules()) {
            LOG.debug("kp " + kp + " rule " + rule.getName());
        }
    }

    session = kieBase.newKieSession();
    LOG.info(session.getGlobals().toString());
    Logger kieLogger = LoggerFactory.getLogger(this.getClass());
   // session.setGlobal("logger",kieLogger);
}
 
开发者ID:sabre1041,项目名称:iot-ocp,代码行数:25,代码来源:BaseTest.java

示例7: newShoppingCart

import org.kie.api.KieBase; //导入依赖的package包/类
@Override
public String newShoppingCart() throws BusinessException {
    String cartId = UUID.randomUUID().toString();
    RuleBaseConfiguration conf = new RuleBaseConfiguration();
    conf.setAssertBehaviour(RuleBaseConfiguration.AssertBehaviour.EQUALITY);
    KieBase kBase = kContainer.newKieBase(conf);
    KieSession kSession = kBase.newKieSession();
    kSession.registerChannel("outboundChannel", new Channel() {

        @Override
        public void send(Object o) {
            System.out.println(o);
        }
    });
    shoppingCarts.put(cartId, kSession);
    return cartId;
}
 
开发者ID:Salaboy,项目名称:drools-workshop,代码行数:18,代码来源:ShoppingCartServiceImpl.java

示例8: main

import org.kie.api.KieBase; //导入依赖的package包/类
public static void main(String[] args) {
	//Get the KieBase
	EmbeddedKieBaseProvider kbp = new EmbeddedKieBaseProvider();
	KieBase kieBase = kbp.getKieBase();
	
	//Create a Fact
	SLACriteria slCri = new SLACriteria();
	slCri.setSlaCatalogName("NAVProdBSE");
	
	
	//Determine SLA with Drools
	SLACriteria slCriVal = determineSLA(slCri,kieBase);
	
	//Was our values set correctly?
	System.out.println(slCriVal.toString()+":"+slCriVal.getTime()+":"+slCriVal.getPercentage());
}
 
开发者ID:anurag-saran,项目名称:sla-mgmt-brms,代码行数:17,代码来源:Runner.java

示例9: doTest

import org.kie.api.KieBase; //导入依赖的package包/类
@Test
public void doTest() {
	logger.info("Running test using persistence");
	// start our mock DB
	JBPMHelper.startH2Server();
	JBPMHelper.setupDataSource();
	// setting persistence
	EntityManagerFactory emf = Persistence
			.createEntityManagerFactory("org.jbpm.persistence.jpa");
	Environment env = KnowledgeBaseFactory.newEnvironment();
	// to load our kbase
	KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
	KieBase kb = kc.getKieBase("TestProcessKB");
	env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
	StatefulKnowledgeSession kSession = JPAKnowledgeService
			.newStatefulKnowledgeSession(kb, null, env);
	kSession.startProcess("HelloWorldProcess");
}
 
开发者ID:jesuino,项目名称:bpms6-examples,代码行数:19,代码来源:ProcessPersistenceTest.java

示例10: testCallService

import org.kie.api.KieBase; //导入依赖的package包/类
@Test
public void testCallService() throws Exception {
    final Holder holder = new Holder();
    serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            holder.setValue("message handled");
        }
    });
    serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    ksession.startProcess("CallService");
    ksession.halt();
    ksession.dispose();
    Assert.assertEquals("message handled", holder.getValue());
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:23,代码来源:BPMServiceTests.java

示例11: runFaultBoundaryProcess

import org.kie.api.KieBase; //导入依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler(){
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
    String output = (String)wpi.getVariable("TestOutput");
    Assert.assertEquals(bomb ? "Failure" : "Success", output);
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:24,代码来源:BPMServiceTests.java

示例12: setupClasspathKmoduleBuilder

import org.kie.api.KieBase; //导入依赖的package包/类
private static RuntimeEnvironmentBuilder setupClasspathKmoduleBuilder(KieContainer kieContainer,
                                                                      String kbaseName,
                                                                      String ksessionName) {
    if (StringUtils.isEmpty(kbaseName)) {
        KieBaseModel defaultKBaseModel = ((KieContainerImpl)kieContainer).getKieProject().getDefaultKieBaseModel();
        if (defaultKBaseModel != null) {
            kbaseName = defaultKBaseModel.getName();
        } else {
            kbaseName = DEFAULT_KBASE_NAME;
        }
    }
    InternalKieModule module = (InternalKieModule) ((KieContainerImpl)kieContainer).getKieModuleForKBase(kbaseName);
    if (module == null) {
        throw new IllegalStateException("Cannot find kbase with name " + kbaseName);
    }
    KieBase kbase = kieContainer.getKieBase(kbaseName);

    return getDefault()
            .knowledgeBase(kbase)
            .classLoader(kieContainer.getClassLoader())
            .registerableItemsFactory(new KModuleRegisterableItemsFactory(kieContainer, ksessionName));
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:23,代码来源:PatchedRuntimeEnvironmentBuilder.java

示例13: knowledgeBaseDetails

import org.kie.api.KieBase; //导入依赖的package包/类
/**
 * Return a string containing the packages used to build the knowledge base.
 */
public static String knowledgeBaseDetails(KieBase kbase) {
    if (kbase == null) {
        return "Knowledge Base is null.";
    } else {
        StringBuilder sb = new StringBuilder(
                "Knowledge base built from the following packages:");
        Collection<KiePackage> packages = kbase
                .getKiePackages();
        for (KiePackage kp : packages) {
            sb.append("\n    Package: [" + kp.getName() + "]");
            for (Rule rule : kp.getRules()) {
                sb.append("\n        Rule: [" + rule.getName() + "]");
            }
        }
        return sb.toString();
    }
}
 
开发者ID:gratiartis,项目名称:qzr,代码行数:21,代码来源:DroolsUtil.java

示例14: testCallService

import org.kie.api.KieBase; //导入依赖的package包/类
@Test
public void testCallService() throws Exception {
    final Holder holder = new Holder();
    serviceDomain.registerService(new QName("CallService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            holder.setValue("message handled");
        }
    });
    serviceDomain.registerServiceReference(new QName("CallService"), new InOnlyService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(CALL_SERVICE_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    ksession.startProcess("CallService");
    ksession.halt();
    ksession.dispose();
    Assert.assertEquals("message handled", holder.getValue());
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:23,代码来源:BPMServiceTests.java

示例15: runFaultBoundaryProcess

import org.kie.api.KieBase; //导入依赖的package包/类
private void runFaultBoundaryProcess(final boolean bomb) throws Exception {
    serviceDomain.registerService(new QName("TestService"), new InOnlyService(), new BaseHandler() {
        public void handleMessage(Exchange exchange) throws HandlerException {
            if (bomb) {
                throw new HandlerException("BOOM!");
            }
        }
    });
    serviceDomain.registerServiceReference(new QName("TestService"), new InOutService());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource(FAULT_BOUNDARY_PROCESS_BPMN), ResourceType.BPMN2);
    KieBase kbase = kbuilder.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    SwitchYardServiceTaskHandler ssth = new SwitchYardServiceTaskHandler();
    ssth.setProcessRuntime(ksession);
    ssth.setInvoker(new SwitchYardServiceInvoker(serviceDomain));
    ksession.getWorkItemManager().registerWorkItemHandler(SWITCHYARD_SERVICE_TASK, ssth);
    WorkflowProcessInstance wpi = (WorkflowProcessInstance)ksession.startProcess("FaultBoundaryProcess");
    String output = (String)wpi.getVariable("TestOutput");
    Assert.assertEquals(bomb ? "Failure" : "Success", output);
    ksession.halt();
    ksession.dispose();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:24,代码来源:BPMServiceTests.java


注:本文中的org.kie.api.KieBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。