Search in sources :

Example 1 with ProcessInstanceWithVarsDesc

use of org.jbpm.services.api.model.ProcessInstanceWithVarsDesc in project jbpm by kiegroup.

the class QueryServiceImplTest method testGetProcessInstancesWithVariables.

@Test
public void testGetProcessInstancesWithVariables() {
    query = new SqlQueryDefinition("getAllProcessInstancesWithVariables", dataSourceJNDIname);
    query.setExpression("select pil.*, v.variableId, v.value " + "from ProcessInstanceLog pil " + "inner join (select vil.processInstanceId ,vil.variableId, MAX(vil.ID) maxvilid  FROM VariableInstanceLog vil " + "GROUP BY vil.processInstanceId, vil.variableId ORDER BY vil.processInstanceId)  x " + "ON (v.variableId = x.variableId  AND v.id = x.maxvilid )" + "INNER JOIN VariableInstanceLog v " + "ON (v.processInstanceId = pil.processInstanceId)");
    queryService.registerQuery(query);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    params.put("approval_translatedDocument", "translated content");
    params.put("approval_reviewComment", "reviewed content");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    List<ProcessInstanceWithVarsDesc> processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    ProcessInstanceWithVarsDesc instance = processInstanceLogs.get(0);
    assertEquals(3, instance.getVariables().size());
    processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_VAR_NAME, "approval_document"));
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    instance = processInstanceLogs.get(0);
    assertEquals(1, instance.getVariables().size());
    processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_VAR_NAME, "not existing"));
    assertNotNull(processInstanceLogs);
    assertEquals(0, processInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : HashMap(java.util.HashMap) ProcessInstanceWithVarsDesc(org.jbpm.services.api.model.ProcessInstanceWithVarsDesc) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 2 with ProcessInstanceWithVarsDesc

use of org.jbpm.services.api.model.ProcessInstanceWithVarsDesc in project jbpm by kiegroup.

the class ProcessInstanceWithCustomVarsQueryMapper method map.

@Override
public List<ProcessInstanceWithVarsDesc> map(Object result) {
    if (result instanceof DataSet) {
        DataSet dataSetResult = (DataSet) result;
        List<ProcessInstanceWithVarsDesc> mappedResult = new ArrayList<ProcessInstanceWithVarsDesc>();
        Map<Long, ProcessInstanceWithVarsDesc> tmp = new HashMap<Long, ProcessInstanceWithVarsDesc>();
        if (dataSetResult != null) {
            for (int i = 0; i < dataSetResult.getRowCount(); i++) {
                Long processInstanceId = getColumnLongValue(dataSetResult, COLUMN_PROCESSINSTANCEID, i);
                ProcessInstanceWithVarsDesc pi = tmp.get(processInstanceId);
                if (pi == null) {
                    pi = buildInstance(dataSetResult, i);
                    mappedResult.add(pi);
                    tmp.put(processInstanceId, pi);
                }
                Map<String, Object> variables = readVariables(variablesMap, dataSetResult, i);
                ((org.jbpm.kie.services.impl.model.ProcessInstanceWithVarsDesc) pi).setVariables(variables);
            }
        }
        tmp = null;
        return mappedResult;
    }
    throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Also used : DataSet(org.dashbuilder.dataset.DataSet) ProcessInstanceWithVarsDesc(org.jbpm.services.api.model.ProcessInstanceWithVarsDesc) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 3 with ProcessInstanceWithVarsDesc

use of org.jbpm.services.api.model.ProcessInstanceWithVarsDesc in project jbpm by kiegroup.

the class ProcessInstanceWithVarsQueryMapper method map.

@Override
public List<ProcessInstanceWithVarsDesc> map(Object result) {
    if (result instanceof DataSet) {
        DataSet dataSetResult = (DataSet) result;
        List<ProcessInstanceWithVarsDesc> mappedResult = new ArrayList<ProcessInstanceWithVarsDesc>();
        Map<Long, ProcessInstanceWithVarsDesc> tmp = new HashMap<Long, ProcessInstanceWithVarsDesc>();
        if (dataSetResult != null) {
            for (int i = 0; i < dataSetResult.getRowCount(); i++) {
                Long processInstanceId = getColumnLongValue(dataSetResult, COLUMN_PROCESSINSTANCEID, i);
                ProcessInstanceWithVarsDesc pi = tmp.get(processInstanceId);
                if (pi == null) {
                    pi = buildInstance(dataSetResult, i);
                    mappedResult.add(pi);
                    tmp.put(processInstanceId, pi);
                }
                // now add variable
                String varName = getColumnStringValue(dataSetResult, COLUMN_VAR_NAME, i);
                String varValue = getColumnStringValue(dataSetResult, COLUMN_VAR_VALUE, i);
                ((org.jbpm.kie.services.impl.model.ProcessInstanceWithVarsDesc) pi).addVariable(varName, varValue);
            }
        }
        tmp = null;
        return mappedResult;
    }
    throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Also used : DataSet(org.dashbuilder.dataset.DataSet) ProcessInstanceWithVarsDesc(org.jbpm.services.api.model.ProcessInstanceWithVarsDesc) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 4 with ProcessInstanceWithVarsDesc

use of org.jbpm.services.api.model.ProcessInstanceWithVarsDesc 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 5 with ProcessInstanceWithVarsDesc

use of org.jbpm.services.api.model.ProcessInstanceWithVarsDesc in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method testGetProcessInstancesWithVariables.

@Test
public void testGetProcessInstancesWithVariables() {
    query = new SqlQueryDefinition("getAllProcessInstancesWithVariables", "java:jboss/datasources/ExampleDS");
    query.setExpression("select pil.*, v.variableId, v.value " + "from ProcessInstanceLog pil " + "inner join (select vil.processInstanceId ,vil.variableId, MAX(vil.ID) maxvilid  FROM VariableInstanceLog vil " + "GROUP BY vil.processInstanceId, vil.variableId ORDER BY vil.processInstanceId)  x " + "ON (v.variableId = x.variableId  AND v.id = x.maxvilid )" + "INNER JOIN VariableInstanceLog v " + "ON (v.processInstanceId = pil.processInstanceId)");
    queryService.registerQuery(query);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    params.put("approval_translatedDocument", "translated content");
    params.put("approval_reviewComment", "reviewed content");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    List<ProcessInstanceWithVarsDesc> processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    ProcessInstanceWithVarsDesc instance = processInstanceLogs.get(0);
    assertEquals(3, instance.getVariables().size());
    processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_VAR_NAME, "approval_document"));
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    instance = processInstanceLogs.get(0);
    assertEquals(1, instance.getVariables().size());
    processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_VAR_NAME, "not existing"));
    assertNotNull(processInstanceLogs);
    assertEquals(0, processInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : HashMap(java.util.HashMap) ProcessInstanceWithVarsDesc(org.jbpm.services.api.model.ProcessInstanceWithVarsDesc) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)5 ProcessInstanceWithVarsDesc (org.jbpm.services.api.model.ProcessInstanceWithVarsDesc)5 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)3 Test (org.junit.Test)3 QueryContext (org.kie.api.runtime.query.QueryContext)3 ArrayList (java.util.ArrayList)2 DataSet (org.dashbuilder.dataset.DataSet)2 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)2 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)2 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)1