Search in sources :

Example 86 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class AsyncStartProcessCommand method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
    String deploymentId = getDeploymentId(ctx);
    String processId = (String) getData("ProcessId", ctx);
    String correlationKey = (String) getData("CorrelationKey", ctx);
    Map<String, Object> variables = (Map<String, Object>) getData("Variables", ctx);
    if (deploymentId == null || processId == null) {
        throw new IllegalArgumentException("Deployment id and process id is required");
    }
    RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId);
    if (runtimeManager == null) {
        throw new IllegalArgumentException("No runtime manager found for deployment id " + deploymentId);
    }
    RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());
    try {
        if (correlationKey == null || correlationKey.isEmpty()) {
            engine.getKieSession().startProcess(processId, variables);
        } else {
            String[] correlationKeyProperties = correlationKey.split(",");
            CorrelationKey ck = correlationKeyFactory.newCorrelationKey(Arrays.asList(correlationKeyProperties));
            ((CorrelationAwareProcessRuntime) engine.getKieSession()).startProcess(processId, ck, variables);
        }
        return new ExecutionResults();
    } finally {
        runtimeManager.disposeRuntimeEngine(engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) CorrelationKey(org.kie.internal.process.CorrelationKey) ExecutionResults(org.kie.api.executor.ExecutionResults) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) Map(java.util.Map)

Example 87 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class ProcessTest method testEvaluationProcess.

@Test
public void testEvaluationProcess() {
    RuntimeManager manager = createRuntimeManager("Evaluation.bpmn");
    RuntimeEngine engine = getRuntimeEngine(null);
    KieSession ksession = engine.getKieSession();
    KieRuntimeLogger log = KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
    TaskService taskService = engine.getTaskService();
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "krisv");
    params.put("reason", "Yearly performance evaluation");
    ProcessInstance processInstance = ksession.startProcess("com.sample.evaluation", params);
    System.out.println("Process started ...");
    // complete Self Evaluation
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    System.out.println("'krisv' completing task " + task.getName() + ": " + task.getDescription());
    taskService.start(task.getId(), "krisv");
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("performance", "exceeding");
    taskService.complete(task.getId(), "krisv", results);
    // john from HR
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    System.out.println("'john' completing task " + task.getName() + ": " + task.getDescription());
    taskService.claim(task.getId(), "john");
    taskService.start(task.getId(), "john");
    results = new HashMap<String, Object>();
    results.put("performance", "acceptable");
    taskService.complete(task.getId(), "john", results);
    // mary from PM
    tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    System.out.println("'mary' completing task " + task.getName() + ": " + task.getDescription());
    taskService.claim(task.getId(), "mary");
    taskService.start(task.getId(), "mary");
    results = new HashMap<String, Object>();
    results.put("performance", "outstanding");
    taskService.complete(task.getId(), "mary", results);
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
    System.out.println("Process instance completed");
    log.close();
    manager.disposeRuntimeEngine(engine);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 88 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager 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 89 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager 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 90 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager 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)

Aggregations

RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)150 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)116 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)79 KieSession (org.kie.api.runtime.KieSession)55 TaskService (org.kie.api.task.TaskService)53 Test (org.junit.Test)51 HashMap (java.util.HashMap)49 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)46 InternalTaskService (org.kie.internal.task.api.InternalTaskService)44 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)38 UserTaskService (org.jbpm.services.api.UserTaskService)36 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)35 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)23 TaskSummary (org.kie.api.task.model.TaskSummary)21 ArrayList (java.util.ArrayList)19 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)19 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)18 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15