Search in sources :

Example 26 with InternalRuntimeManager

use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.

the class QueryServiceImplTest method testGetTaskInstancesWithCustomVariables.

@Test
public void testGetTaskInstancesWithCustomVariables() throws Exception {
    deploymentService.deploy(deploymentUnitJPA);
    units.add(deploymentUnitJPA);
    query = new SqlQueryDefinition("getAllTaskInstancesWithCustomVariables", dataSourceJNDIname);
    query.setExpression("select ti.*,  c.firstname, c.lastname, c.age, c.customerId from AuditTaskImpl ti " + "inner join (select mv.map_var_id, mv.taskid from MappedVariable mv) mv " + "on (mv.taskid = ti.taskId) " + "inner join Customer c " + "on (c.id = mv.map_var_id)");
    queryService.registerQuery(query);
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnitJPA.getIdentifier());
    assertNotNull(manager);
    Class<?> clazz = Class.forName("org.jbpm.test.Customer", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    Object cinstance = clazz.newInstance();
    // set fields
    setFieldValue(cinstance, "firstName", "john");
    setFieldValue(cinstance, "lastName", "doe");
    setFieldValue(cinstance, "age", new Integer(45));
    setFieldValue(cinstance, "customerId", new Long(1234));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("customer", cinstance);
    processInstanceId = processService.startProcess(deploymentUnitJPA.getIdentifier(), "persistence-test.customer-evaluation", params);
    assertNotNull(processInstanceId);
    Map<String, String> variableMap = new HashMap<String, String>();
    variableMap.put("FIRSTNAME", "string");
    variableMap.put("LASTNAME", "string");
    variableMap.put("AGE", "integer");
    variableMap.put("CUSTOMERID", "long");
    List<UserTaskInstanceWithVarsDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    UserTaskInstanceWithVarsDesc instance = taskInstanceLogs.get(0);
    assertEquals(4, instance.getVariables().size());
    assertTrue(instance.getVariables().containsKey("FIRSTNAME"));
    assertTrue(instance.getVariables().containsKey("LASTNAME"));
    assertTrue(instance.getVariables().containsKey("AGE"));
    assertTrue(instance.getVariables().containsKey("CUSTOMERID"));
    assertEquals("john", instance.getVariables().get("FIRSTNAME"));
    assertEquals("doe", instance.getVariables().get("LASTNAME"));
    assertEquals(45, instance.getVariables().get("AGE"));
    assertEquals(1234l, instance.getVariables().get("CUSTOMERID"));
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) UserTaskInstanceWithVarsDesc(org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 27 with InternalRuntimeManager

use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.

the class QueryServiceImplTest method testGetProcessInstancesWithCustomVariables.

@Test
public void testGetProcessInstancesWithCustomVariables() throws Exception {
    deploymentService.deploy(deploymentUnitJPA);
    units.add(deploymentUnitJPA);
    query = new SqlQueryDefinition("getAllProcessInstancesWithCustomVariables", dataSourceJNDIname);
    query.setExpression("select pi.*,  c.firstname, c.lastname, c.age, c.customerId from ProcessInstanceLog pi " + "inner join (select mv.map_var_id, mv.processInstanceId from MappedVariable mv) mv " + "on (mv.processInstanceId = pi.processinstanceId) " + "inner join Customer c " + "on (c.id = mv.map_var_id)");
    queryService.registerQuery(query);
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnitJPA.getIdentifier());
    assertNotNull(manager);
    Class<?> clazz = Class.forName("org.jbpm.test.Customer", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    Object cinstance = clazz.newInstance();
    // set fields
    setFieldValue(cinstance, "firstName", "john");
    setFieldValue(cinstance, "lastName", "doe");
    setFieldValue(cinstance, "age", new Integer(45));
    setFieldValue(cinstance, "customerId", new Long(1234));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("customer", cinstance);
    processInstanceId = processService.startProcess(deploymentUnitJPA.getIdentifier(), "persistence-test.customer-evaluation", params);
    assertNotNull(processInstanceId);
    Map<String, String> variableMap = new HashMap<String, String>();
    variableMap.put("FIRSTNAME", "string");
    variableMap.put("LASTNAME", "string");
    variableMap.put("AGE", "integer");
    variableMap.put("CUSTOMERID", "long");
    List<ProcessInstanceWithVarsDesc> processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    ProcessInstanceWithVarsDesc instance = processInstanceLogs.get(0);
    assertEquals(4, instance.getVariables().size());
    assertTrue(instance.getVariables().containsKey("FIRSTNAME"));
    assertTrue(instance.getVariables().containsKey("LASTNAME"));
    assertTrue(instance.getVariables().containsKey("AGE"));
    assertTrue(instance.getVariables().containsKey("CUSTOMERID"));
    assertEquals("john", instance.getVariables().get("FIRSTNAME"));
    assertEquals("doe", instance.getVariables().get("LASTNAME"));
    assertEquals(45, instance.getVariables().get("AGE"));
    assertEquals(1234l, instance.getVariables().get("CUSTOMERID"));
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) ProcessInstanceWithVarsDesc(org.jbpm.services.api.model.ProcessInstanceWithVarsDesc) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 28 with InternalRuntimeManager

use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.

the class KModuleDeploymentServiceTest method testDeploymentOfProcessWithDescriptorWitSecurityManager.

@Test(expected = SecurityException.class)
public void testDeploymentOfProcessWithDescriptorWitSecurityManager() {
    assertNotNull(deploymentService);
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "kjar-with-dd", VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("repo/processes/general/customtask.bpmn");
    processes.add("repo/processes/general/humanTask.bpmn");
    processes.add("repo/processes/general/import.bpmn");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addWorkItemHandler(new NamedObjectModel("Log", "org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler")).addRequiredRole("experts");
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes, resources);
    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);
    DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, "kjar-with-dd", VERSION, "KBase-test", "ksession-test2");
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployedGeneral);
    assertNotNull(deployedGeneral.getDeploymentUnit());
    assertNotNull(deployedGeneral.getRuntimeManager());
    DeploymentDescriptor descriptor = ((InternalRuntimeManager) deployedGeneral.getRuntimeManager()).getDeploymentDescriptor();
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(1, descriptor.getWorkItemHandlers().size());
    assertEquals(1, descriptor.getRequiredRoles().size());
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
    assertNotNull(manager);
    manager.getRuntimeEngine(EmptyContext.get());
    checkFormsDeployment(deploymentUnit.getIdentifier());
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ArrayList(java.util.ArrayList) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) FileOutputStream(java.io.FileOutputStream) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) File(java.io.File) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 29 with InternalRuntimeManager

use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.

the class TaskVariablesQueryServiceTest method testTaskVariableQueryOnBigTaskSetAsJPA.

@Test
public void testTaskVariableQueryOnBigTaskSetAsJPA() throws Exception {
    Map<String, String> variableMap = new HashMap<String, String>();
    variableMap.put("COUNTRY", "string");
    variableMap.put("PRODUCTCODE", "string");
    variableMap.put("QUANTITY", "integer");
    variableMap.put("PRICE", "double");
    variableMap.put("SALEDATE", "date");
    SqlQueryDefinition query = new SqlQueryDefinition("getAllTaskInstancesWithCustomVariables", "jdbc/testDS1");
    query.setExpression("select ti.*,  c.country, c.productCode, c.quantity, c.price, c.saleDate " + "from AuditTaskImpl ti " + "    inner join (select mv.map_var_id, mv.taskid from MappedVariable mv) mv " + "      on (mv.taskid = ti.taskId) " + "    inner join ProductSale c " + "      on (c.id = mv.map_var_id)");
    queryService.registerQuery(query);
    SqlQueryDefinition queryTPO = new SqlQueryDefinition("getMyTaskInstancesWithCustomVariables", "jdbc/testDS1", Target.PO_TASK);
    queryTPO.setExpression("select ti.*,  c.country, c.productCode, c.quantity, c.price, c.saleDate, oe.id oeid " + "from AuditTaskImpl ti " + "    inner join (select mv.map_var_id, mv.taskid from MappedVariable mv) mv " + "      on (mv.taskid = ti.taskId) " + "    inner join ProductSale c " + "      on (c.id = mv.map_var_id), " + "  PeopleAssignments_PotOwners po, OrganizationalEntity oe " + "    where ti.taskId = po.task_id and po.entity_id = oe.id");
    queryService.registerQuery(queryTPO);
    queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"));
    long currentTime = System.currentTimeMillis();
    Calendar cal = Calendar.getInstance();
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnitSalesId);
    assertNotNull(manager);
    Class<?> clazz = Class.forName("org.jbpm.test.ProductSale", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    Random random = new Random();
    int i = 0;
    for (i = 0; i < 10000; i++) {
        cal.setTimeInMillis(currentTime);
        // add random number of days
        cal.add(Calendar.DAY_OF_YEAR, random.nextInt(60));
        Object product = clazz.newInstance();
        // set fields
        setFieldValue(product, "country", countries.get(random.nextInt(9)));
        setFieldValue(product, "productCode", productCodes.get(random.nextInt(9)));
        setFieldValue(product, "quantity", random.nextInt(50));
        setFieldValue(product, "price", (random.nextDouble() * 1000));
        setFieldValue(product, "saleDate", cal.getTime());
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("product", product);
        params.put("sales", "john,actor" + i);
        params.put("salesGroup", "Crusaders");
        logger.debug("Params : " + params);
        processService.startProcess(deploymentUnitSalesId, "product-sale.sale-product", params);
    }
    logger.info("Generated {} process instances... doing searches now", i);
    logger.info("let's find tasks for product EAP only");
    long timestamp = System.currentTimeMillis();
    List<UserTaskInstanceWithVarsDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product EAP or Wildfly");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.in("productCode", Arrays.asList("EAP", "WILDFLY")));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product EAP and country Brazil");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.equalsTo("country", "Brazil"));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product BPMS and BRMS by using wildcard search");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "B%"));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product Weblogic or WebSphere by wildcard and country Canada");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "WEB%"), QueryParam.equalsTo("country", "Canada"));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product EAP and country Brazil and tasks with status Ready and Reserved");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.equalsTo("country", "Brazil"), QueryParam.in("status", Arrays.asList(Status.Ready.toString(), Status.Reserved.toString())));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product Weblogic or WebSphere by wildcard where quantity is bigger than 20");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "WEB%"), QueryParam.greaterOrEqualTo("quantity", 20));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product EAP where sale was put in one month from now");
    cal.setTimeInMillis(currentTime);
    Date from = cal.getTime();
    cal.add(Calendar.MONTH, 1);
    Date to = cal.getTime();
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.between("saleDate", from, to));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    // now same queries but with user/group filtering
    logger.info("################################################");
    logger.info("Task with user/group filtering");
    logger.info("################################################");
    identityProvider.setName("john");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product EAP or Wildfly");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.in("productCode", Arrays.asList("EAP", "WILDFLY")));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product EAP and country Brazil");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.equalsTo("country", "Brazil"));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product BPMS and BRMS by using wildcard search");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "B%"));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product Weblogic or WebSphere by wildcard and country Canada");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "WEB%"), QueryParam.equalsTo("country", "Canada"));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product EAP and country Brazil and tasks with status Ready and Reserved");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.equalsTo("country", "Brazil"), QueryParam.in("status", Arrays.asList(Status.Ready.toString(), Status.Reserved.toString())));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product Weblogic or WebSphere by wildcard where quantity is bigger than 20");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "WEB%"), QueryParam.greaterOrEqualTo("quantity", 20));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
    logger.info("let's find tasks for product EAP where sale was put in one month from now");
    timestamp = System.currentTimeMillis();
    taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.between("saleDate", from, to));
    logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) Calendar(java.util.Calendar) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) UserTaskInstanceWithVarsDesc(org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc) QueryContext(org.kie.api.runtime.query.QueryContext) Date(java.util.Date) Random(java.util.Random) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 30 with InternalRuntimeManager

use of org.kie.internal.runtime.manager.InternalRuntimeManager in project jbpm by kiegroup.

the class AdHocProcessServiceImpl method startProcess.

@Override
public Long startProcess(String deploymentId, String processId, CorrelationKey correlationKey, Map<String, Object> params, Long parentProcessInstanceId) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    if (!deployedUnit.isActive()) {
        throw new DeploymentNotFoundException("Deployments " + deploymentId + " is not active");
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    params = process(params, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = engine.getKieSession();
    ProcessInstance pi = null;
    try {
        pi = ((CorrelationAwareProcessRuntime) ksession).createProcessInstance(processId, correlationKey, params);
        pi = ksession.execute(new StartProcessInstanceWithParentCommand(pi.getId(), parentProcessInstanceId));
        return pi.getId();
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) StartProcessInstanceWithParentCommand(org.jbpm.kie.services.impl.cmd.StartProcessInstanceWithParentCommand)

Aggregations

InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)51 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)29 Test (org.junit.Test)23 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)23 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)17 HashMap (java.util.HashMap)14 KieSession (org.kie.api.runtime.KieSession)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)14 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)12 ArrayList (java.util.ArrayList)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)9 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)8 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)7 KieServices (org.kie.api.KieServices)7 ReleaseId (org.kie.api.builder.ReleaseId)7 TaskService (org.kie.api.task.TaskService)7 InternalTaskService (org.kie.internal.task.api.InternalTaskService)7 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)6