Search in sources :

Example 16 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class RuntimeManagerWithDescriptorTest method testDeployWithFullCustomDeploymentDescriptor.

@Test
public void testDeployWithFullCustomDeploymentDescriptor() throws Exception {
    Map<String, String> resources = new HashMap<String, String>();
    String scriptString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ScriptTask.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-ScriptTask.bpmn2", scriptString);
    String manualString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ManualTask.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-ManualTask.bpmn2", manualString);
    String userString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-UserTask.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-UserTask.bpmn2", userString);
    String callString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivity.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-CallActivity.bpmn2", callString);
    String subProcessString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivitySubProcess.bpmn2"), "UTF-8");
    resources.put("src/main/resources/BPMN2-CallActivitySubProcess.bpmn2", subProcessString);
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
    customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addMarshalingStrategy(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestMarshallingStrategy")).addConfiguration(new NamedObjectModel("drools.processSignalManagerFactory", "java.lang.String", new Object[] { DefaultSignalManagerFactory.class.getName() })).addEnvironmentEntry(new NamedObjectModel("jbpm.business.calendar", "org.jbpm.runtime.manager.impl.deploy.RuntimeManagerWithDescriptorTest$TestBusinessCalendar")).addEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestProcessEventListener")).addGlobal(new NamedObjectModel("service", "java.util.ArrayList")).addTaskEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestTaskEventListener")).addWorkItemHandler(new NamedObjectModel("Manual Task", "org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestWorkItemHandler"));
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    String drl = "package org.jbpm; global java.util.List service; " + "	rule \"Start Hello1\"" + "	  when" + "	  then" + "	    System.out.println(\"Hello\");" + "	end";
    resources.put("src/main/resources/simple.drl", drl);
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.dd", "-kjar-with-dd", "1.0.0");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    InternalRuntimeManager internalManager = (InternalRuntimeManager) manager;
    RegisterableItemsFactory factory = internalManager.getEnvironment().getRegisterableItemsFactory();
    assertNotNull(factory);
    assertTrue(factory instanceof InternalRegisterableItemsFactory);
    assertNotNull(((InternalRegisterableItemsFactory) factory).getRuntimeManager());
    DeploymentDescriptor descriptor = internalManager.getDeploymentDescriptor();
    assertNotNull(descriptor);
    assertEquals("org.jbpm.persistence.jpa", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.persistence.jpa", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
    assertEquals(1, descriptor.getMarshallingStrategies().size());
    // assertEquals(1, descriptor.getConfiguration().size());
    assertEquals(1, descriptor.getEnvironmentEntries().size());
    assertEquals(1, descriptor.getEventListeners().size());
    assertEquals(1, descriptor.getGlobals().size());
    assertEquals(1, descriptor.getTaskEventListeners().size());
    assertEquals(1, descriptor.getWorkItemHandlers().size());
    assertEquals(0, descriptor.getRequiredRoles().size());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    assertNotNull(engine);
    KieSession kieSession = engine.getKieSession();
    // configuration
    assertEquals(((SessionConfiguration) kieSession.getSessionConfiguration()).getSignalManagerFactory(), DefaultSignalManagerFactory.class.getName());
    BusinessCalendar bc = (BusinessCalendar) kieSession.getEnvironment().get("jbpm.business.calendar");
    assertNotNull(bc);
    assertTrue(bc instanceof TestBusinessCalendar);
    // globals
    Object service = kieSession.getGlobal("service");
    assertNotNull(service);
    assertTrue(service instanceof ArrayList);
    // work item handler
    ProcessInstance processInstance = kieSession.startProcess("ManualTask");
    long processInstanceId = processInstance.getId();
    assertNotNull(kieSession.getProcessInstance(processInstanceId));
    kieSession.getWorkItemManager().completeWorkItem(TestWorkItemHandler.getWorkItem().getId(), null);
    assertNull(kieSession.getProcessInstance(processInstanceId));
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    kieSession = engine.getKieSession();
    // process event listener
    assertArrayEquals(new String[] { "beforeProcessStarted", "afterProcessStarted", "beforeProcessCompleted", "afterProcessCompleted" }, processEvents.toArray());
    processEvents.clear();
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    kieSession = engine.getKieSession();
    // task event listener
    processInstance = kieSession.startProcess("UserTask");
    processInstanceId = processInstance.getId();
    assertNotNull(kieSession.getProcessInstance(processInstanceId));
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    TaskService taskService = engine.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    long taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    assertArrayEquals(new String[] { "beforeTaskAddedEvent", "afterTaskAddedEvent", "beforeTaskStartedEvent", "afterTaskStartedEvent", "beforeTaskCompletedEvent", "afterTaskCompletedEvent" }, taskEvents.toArray());
    manager.disposeRuntimeEngine(engine);
    engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    kieSession = engine.getKieSession();
    // marshalling strategy
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "marshal");
    processInstance = kieSession.startProcess("ParentProcess", params);
    processInstanceId = processInstance.getId();
    ProcessInstance pi = kieSession.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    String varX = (String) ((WorkflowProcessInstance) pi).getVariable("x");
    assertEquals(TestMarshallingStrategy.ALWAYS_RESPOND_WITH, varX);
    manager.disposeRuntimeEngine(engine);
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) ArrayList(java.util.ArrayList) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) RegisterableItemsFactory(org.kie.api.runtime.manager.RegisterableItemsFactory) KieServices(org.kie.api.KieServices) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) KieSession(org.kie.api.runtime.KieSession) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskService(org.kie.api.task.TaskService) ReleaseId(org.kie.api.builder.ReleaseId) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) TaskSummary(org.kie.api.task.model.TaskSummary) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Example 17 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class MBeansMonitoringWithJBpmTest method testRulesAndProcesses.

@Test
public void testRulesAndProcesses() throws Exception {
    String drl = "package org.drools.droolsjbpm_integration_testmgt\n" + "rule S\n" + "when\n" + "    $s: String() \n" + "then\n" + "    try { Thread.sleep(10); } catch (Exception e) { }\n" + "    System.out.println($s); \n" + "end\n";
    String process = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" + "<definitions id=\"Definition\"\n" + "             targetNamespace=\"http://www.example.org/MinimalExample\"\n" + "             typeLanguage=\"http://www.java.com/javaTypes\"\n" + "             expressionLanguage=\"http://www.mvel.org/2.0\"\n" + "             xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"\n" + "             xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "             xs:schemaLocation=\"http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd\"\n" + "             xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"\n" + "             xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"\n" + "             xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"\n" + "             xmlns:tns=\"http://www.jboss.org/drools\">\n" + "\n" + "  <process processType=\"Private\" isExecutable=\"true\" id=\"com.sample.HelloWorld\" name=\"Hello World\" >\n" + "\n" + "    <!-- nodes -->\n" + "    <startEvent id=\"_a1\" name=\"StartProcess\" />\n" + "    <scriptTask id=\"_a2\" name=\"Hello\" >\n" + "      <script>System.out.println(\"Hello World\");</script>\n" + "    </scriptTask>\n" + "    <endEvent id=\"_a3\" name=\"EndProcess\" >\n" + "        <terminateEventDefinition/>\n" + "    </endEvent>\n" + "\n" + "    <!-- connections -->\n" + "    <sequenceFlow id=\"_a1-_a2\" sourceRef=\"_a1\" targetRef=\"_a2\" />\n" + "    <sequenceFlow id=\"_a2-_a3\" sourceRef=\"_a2\" targetRef=\"_a3\" />\n" + "\n" + "  </process>" + "  <process processType=\"Private\" isExecutable=\"true\" id=\"com.sample.CiaoWorld\" name=\"Ciao World\" >\n" + "\n" + "    <!-- nodes -->\n" + "    <startEvent id=\"_b1\" name=\"StartProcess\" />\n" + "    <scriptTask id=\"_b2\" name=\"Ciao\" >\n" + "      <script>System.out.println(\"Ciao World\");</script>\n" + "    </scriptTask>\n" + "    <endEvent id=\"_b3\" name=\"EndProcess\" >\n" + "        <terminateEventDefinition/>\n" + "    </endEvent>\n" + "\n" + "    <!-- connections -->\n" + "    <sequenceFlow id=\"_b1-_b2\" sourceRef=\"_b1\" targetRef=\"_b2\" />\n" + "    <sequenceFlow id=\"_b2-_b3\" sourceRef=\"_b2\" targetRef=\"_b3\" />\n" + "\n" + "  </process>" + "</definitions>";
    KieServices ks = KieServices.Factory.get();
    KieModuleModel kproj = ks.newKieModuleModel();
    KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(KBASE1).setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
    KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel(KSESSION1).setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
    KieSessionModel ksessionModel2 = kieBaseModel1.newKieSessionModel(KSESSION2).setDefault(false).setType(KieSessionModel.KieSessionType.STATELESS);
    ReleaseId releaseId1 = ks.newReleaseId("org.kie.test", "mbeans", "1.0.0");
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML());
    kfs.generateAndWritePomXML(releaseId1);
    kfs.write("src/main/resources/r" + 1 + ".drl", drl);
    kfs.write("src/main/resources/p" + 1 + ".bpmn2", process);
    KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
    if (kb.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
        for (org.kie.api.builder.Message result : kb.getResults().getMessages()) {
            LOG.error(result.getText());
        }
    }
    InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId1);
    KieContainer kc = ks.newKieContainer(KCONTAINER1, releaseId1);
    KieBase kiebase = kc.getKieBase(KBASE1);
    Properties ksessionConfigProps = new Properties();
    ksessionConfigProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
    ksessionConfigProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
    KieSessionConfiguration sessionConf = ks.newKieSessionConfiguration(ksessionConfigProps);
    sessionConf.setOption(ForceEagerActivationOption.YES);
    KieSession ksession = kc.newKieSession(KSESSION1, sessionConf);
    MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
    KieSessionMonitoringMXBean aggrMonitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(KCONTAINER1, KBASE1, KieSessionType.STATEFUL, KSESSION1), KieSessionMonitoringMXBean.class);
    long tft = 0;
    print(aggrMonitor);
    checkAgendaTotals(aggrMonitor, 0, 0, 0);
    checkTotalFactCount(aggrMonitor, 0);
    tft = checkTotalFiringTimeGEQ(aggrMonitor, tft);
    checkTotalSessions(aggrMonitor, 1);
    assertNull(aggrMonitor.getStatsForProcess("com.sample.HelloWorld"));
    assertNull(aggrMonitor.getStatsForProcess("com.sample.CiaoWorld"));
    assertFalse(aggrMonitor.getStatsByProcess().containsKey("com.sample.HelloWorld"));
    assertFalse(aggrMonitor.getStatsByProcess().containsKey("com.sample.CiaoWorld"));
    ksession.insert("Ciao");
    ksession.startProcess("com.sample.HelloWorld");
    ksession.startProcess("com.sample.HelloWorld");
    ksession.startProcess("com.sample.CiaoWorld");
    ksession.fireAllRules();
    print(aggrMonitor);
    checkAgendaTotals(aggrMonitor, 1, 0, 1);
    checkTotalFactCount(aggrMonitor, 1);
    tft = checkTotalFiringTimeGEQ(aggrMonitor, tft + 1);
    checkTotalSessions(aggrMonitor, 1);
    checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 2, 2, 6);
    checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 1, 1, 3);
    ksession.fireAllRules();
    print(aggrMonitor);
    checkAgendaTotals(aggrMonitor, 1, 0, 1);
    checkTotalFactCount(aggrMonitor, 1);
    tft = checkTotalFiringTimeGEQ(aggrMonitor, tft);
    checkTotalSessions(aggrMonitor, 1);
    checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 2, 2, 6);
    checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 1, 1, 3);
    LOG.debug("---");
    KieSession ksession2 = kc.newKieSession(KSESSION1, sessionConf);
    ksession2.insert("Ciao");
    ksession.startProcess("com.sample.HelloWorld");
    ksession.startProcess("com.sample.HelloWorld");
    ksession.startProcess("com.sample.CiaoWorld");
    ksession2.fireAllRules();
    print(aggrMonitor);
    checkAgendaTotals(aggrMonitor, 2, 0, 2);
    checkTotalFactCount(aggrMonitor, 2);
    tft = checkTotalFiringTimeGEQ(aggrMonitor, tft + 1);
    checkTotalSessions(aggrMonitor, 2);
    checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 4, 4, 12);
    checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 2, 2, 6);
    LOG.debug("--- NOW for the STATELESS ---");
    tft = 0;
    StatelessKieSession stateless = kc.newStatelessKieSession(KSESSION2, sessionConf);
    StatelessKieSessionMonitoringMXBean aggrMonitor2 = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(KCONTAINER1, KBASE1, KieSessionType.STATELESS, KSESSION2), StatelessKieSessionMonitoringMXBean.class);
    print(aggrMonitor2);
    checkAgendaTotals(aggrMonitor2, 0, 0, 0);
    checkRuleRuntimeTotals(aggrMonitor2, 0, 0);
    tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft);
    checkTotalSessions(aggrMonitor2, 0);
    List<Command> cmds = new ArrayList<Command>();
    cmds.add(CommandFactory.newInsert("Ciao"));
    cmds.add(CommandFactory.newStartProcess("com.sample.HelloWorld"));
    cmds.add(CommandFactory.newStartProcess("com.sample.HelloWorld"));
    cmds.add(CommandFactory.newStartProcess("com.sample.CiaoWorld"));
    BatchExecutionCommand batch = CommandFactory.newBatchExecution(cmds);
    stateless.execute(batch);
    print(aggrMonitor2);
    checkAgendaTotals(aggrMonitor2, 1, 0, 1);
    checkRuleRuntimeTotals(aggrMonitor2, 1, 0);
    tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
    checkTotalSessions(aggrMonitor2, 1);
    checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 2, 2, 6);
    checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 1, 1, 3);
    stateless.execute(batch);
    print(aggrMonitor2);
    checkAgendaTotals(aggrMonitor2, 2, 0, 2);
    checkRuleRuntimeTotals(aggrMonitor2, 2, 0);
    tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
    checkTotalSessions(aggrMonitor2, 2);
    checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 4, 4, 12);
    checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 2, 2, 6);
    StatelessKieSession stateless2 = kc.newStatelessKieSession(KSESSION2, sessionConf);
    LOG.debug(stateless + " " + stateless2);
    checkTotalSessions(aggrMonitor2, 2);
    stateless2.execute(batch);
    print(aggrMonitor2);
    checkAgendaTotals(aggrMonitor2, 3, 0, 3);
    checkRuleRuntimeTotals(aggrMonitor2, 3, 0);
    tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
    checkTotalSessions(aggrMonitor2, 3);
    checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 6, 6, 18);
    checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 3, 3, 9);
}
Also used : DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) DefaultProcessInstanceManagerFactory(org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory) Properties(java.util.Properties) KieBase(org.kie.api.KieBase) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) KieBuilder(org.kie.api.builder.KieBuilder) StatelessKieSessionMonitoringMXBean(org.kie.api.management.StatelessKieSessionMonitoringMXBean) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieContainer(org.kie.api.runtime.KieContainer) MBeanServer(javax.management.MBeanServer) KieFileSystem(org.kie.api.builder.KieFileSystem) GenericKieSessionMonitoringMXBean(org.kie.api.management.GenericKieSessionMonitoringMXBean) KieSessionMonitoringMXBean(org.kie.api.management.KieSessionMonitoringMXBean) StatelessKieSessionMonitoringMXBean(org.kie.api.management.StatelessKieSessionMonitoringMXBean) ReleaseId(org.kie.api.builder.ReleaseId) KieSessionModel(org.kie.api.builder.model.KieSessionModel) KieBaseModel(org.kie.api.builder.model.KieBaseModel) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) KieModuleModel(org.kie.api.builder.model.KieModuleModel) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Example 18 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class EJBService method createKieJar.

private static InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, List<String> resources, Map<String, String> extraResources) {
    KieFileSystem kfs = createKieFileSystemWithKProject(ks);
    kfs.writePomXML(getPom(releaseId));
    for (String resource : resources) {
        kfs.write("src/main/resources/KBase-test/" + resource, ResourceFactory.newClassPathResource(EJB_SERVICES_ASSETS_PATH + resource));
    }
    if (extraResources != null) {
        for (Map.Entry<String, String> entry : extraResources.entrySet()) {
            kfs.write(entry.getKey(), ResourceFactory.newByteArrayResource(entry.getValue().getBytes()));
        }
    }
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {
        for (Message message : kieBuilder.buildAll().getResults().getMessages()) {
            LOGGER.error("Error Message: ({}) {}", message.getPath(), message.getText());
        }
        throw new RuntimeException("There are errors building the package, please check your knowledge assets!");
    }
    return (InternalKieModule) kieBuilder.getKieModule();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieBuilder(org.kie.api.builder.KieBuilder) HashMap(java.util.HashMap) Map(java.util.Map) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 19 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class RuntimeDataServiceImplTest method prepare.

@Before
public void prepare() {
    configureServices();
    logger.debug("Preparing kjar");
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("repo/processes/general/EmptyHumanTask.bpmn");
    processes.add("repo/processes/general/humanTask.bpmn");
    processes.add("repo/processes/general/BPMN2-UserTask.bpmn2");
    processes.add("repo/processes/general/SimpleHTProcess.bpmn2");
    processes.add("repo/processes/general/AdHocSubProcess.bpmn2");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployArtifact(releaseId, kJar1, pom);
    assertNotNull(deploymentService);
    deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) File(java.io.File) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Before(org.junit.Before)

Example 20 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project jbpm by kiegroup.

the class TaskQueryBuilderTest method prepare.

@Before
public void prepare() {
    this.dataSourceJNDIname = getDataSourceJNDI();
    configureServices();
    logger.debug("Preparing kjar");
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("repo/processes/general/humanTask.bpmn");
    processes.add("repo/processes/hr/hiring.bpmn2");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployArtifact(releaseId, kJar1, pom);
    assertNotNull(deploymentService);
    deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    prepareJPAModule(ks, repository);
    assertNotNull(processService);
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) File(java.io.File) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Before(org.junit.Before)

Aggregations

InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)201 ReleaseId (org.kie.api.builder.ReleaseId)125 KieServices (org.kie.api.KieServices)120 Test (org.junit.Test)86 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)72 File (java.io.File)62 ArrayList (java.util.ArrayList)57 KieContainer (org.kie.api.runtime.KieContainer)57 KieBuilder (org.kie.api.builder.KieBuilder)55 KieFileSystem (org.kie.api.builder.KieFileSystem)54 FileOutputStream (java.io.FileOutputStream)53 KieMavenRepository (org.kie.scanner.KieMavenRepository)51 KieSession (org.kie.api.runtime.KieSession)43 HashMap (java.util.HashMap)28 Before (org.junit.Before)28 KieModule (org.kie.api.builder.KieModule)24 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)23 KieScanner (org.kie.api.builder.KieScanner)20 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)18 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)17