Search in sources :

Example 16 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class ProcessServiceImplPerProcessInstanceTest method testGetProcessInstanceWithCorrelationKeyAbortedProcess.

@Test
public void testGetProcessInstanceWithCorrelationKeyAbortedProcess() {
    CorrelationKey key = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey("my business key");
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), PROCESS_ID_SIGNAL, key);
    assertNotNull(processInstanceId);
    processService.abortProcessInstance(processInstanceId);
    ProcessInstance processInstance = processService.getProcessInstance(key);
    assertNull(processInstance);
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 17 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class ProcessServiceImplTest method testStartProcessWithCorrelationKey.

@Test
public void testStartProcessWithCorrelationKey() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);
    CorrelationKey key = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey("my business key");
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "customtask", key);
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(key);
    assertNull(pi);
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 18 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class AuditQueryTest method simpleProcessInstanceLogQueryBuilderTest.

@Test
public void simpleProcessInstanceLogQueryBuilderTest() {
    int p = 0;
    long duration = pilTestData[p++].getDuration();
    ProcessInstanceLogQueryBuilder builder = this.processInstanceLogQuery().duration(duration);
    List<org.kie.api.runtime.manager.audit.ProcessInstanceLog> resultList = builder.build().getResultList();
    assertEquals("duration query result", 2, resultList.size());
    {
        Date end = pilTestData[p++].getEnd();
        builder = this.processInstanceLogQuery().endDate(end);
        resultList = builder.build().getResultList();
        assertEquals("end date query result", 2, resultList.size());
    }
    {
        String identity = pilTestData[p++].getIdentity();
        builder = this.processInstanceLogQuery().identity(identity);
        resultList = builder.build().getResultList();
        assertEquals("identity query result", 2, resultList.size());
    }
    {
        String processId = pilTestData[p++].getProcessId();
        builder = this.processInstanceLogQuery().processId(processId);
        resultList = builder.build().getResultList();
        assertEquals("process id query result", 2, resultList.size());
    }
    {
        long processInstanceId = pilTestData[p++].getProcessInstanceId();
        builder = this.processInstanceLogQuery().processInstanceId(processInstanceId);
        resultList = builder.build().getResultList();
        assertEquals("process instance id query result", 2, resultList.size());
    }
    {
        String processName = pilTestData[p++].getProcessName();
        builder = this.processInstanceLogQuery().processName(processName);
        resultList = builder.build().getResultList();
        assertEquals("process name query result", 2, resultList.size());
    }
    {
        String version = pilTestData[p++].getProcessVersion();
        builder = this.processInstanceLogQuery().processVersion(version);
        resultList = builder.build().getResultList();
        assertEquals("process version query result", 2, resultList.size());
    }
    {
        Date start = pilTestData[p++].getStart();
        builder = this.processInstanceLogQuery().startDate(start);
        resultList = builder.build().getResultList();
        assertEquals("start date query result", 2, resultList.size());
    }
    {
        int status = pilTestData[p++].getStatus();
        builder = this.processInstanceLogQuery().status(status);
        resultList = builder.build().getResultList();
        assertEquals("status query result", 2, resultList.size());
    }
    {
        String outcome = pilTestData[p++].getOutcome();
        builder = this.processInstanceLogQuery().outcome(outcome);
        resultList = builder.build().getResultList();
        assertEquals("outcome query result", 2, resultList.size());
    }
    {
        String correlationKey = pilTestData[p++].getCorrelationKey();
        CorrelationKey ck = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey(correlationKey);
        builder = this.processInstanceLogQuery().correlationKey(ck);
        resultList = builder.build().getResultList();
        assertEquals("identity query result", 1, resultList.size());
    }
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstanceLogQueryBuilder(org.kie.internal.runtime.manager.audit.query.ProcessInstanceLogQueryBuilder) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Date(java.util.Date) AuditLogServiceTest(org.jbpm.process.audit.AuditLogServiceTest) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 19 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class DefaultAuditEventBuilderImpl method buildEvent.

@Override
public AuditEvent buildEvent(ProcessStartedEvent pse) {
    ProcessInstanceImpl pi = (ProcessInstanceImpl) pse.getProcessInstance();
    ProcessInstanceLog log = new ProcessInstanceLog(pi.getId(), pi.getProcessId());
    log.setExternalId("" + ((KieSession) pse.getKieRuntime()).getIdentifier());
    log.setProcessName(pi.getProcess().getName());
    log.setProcessVersion(pi.getProcess().getVersion());
    log.setStatus(ProcessInstance.STATE_ACTIVE);
    log.setProcessInstanceDescription(pi.getDescription());
    log.setProcessType(((WorkflowProcess) pi.getProcess()).getProcessType());
    log.setSlaCompliance(pi.getSlaCompliance());
    log.setSlaDueDate(pi.getSlaDueDate());
    // store correlation key in its external form
    CorrelationKey correlationKey = (CorrelationKey) pi.getMetaData().get("CorrelationKey");
    if (correlationKey != null) {
        log.setCorrelationKey(correlationKey.toExternalForm());
    }
    long parentProcessInstanceId = (Long) pi.getMetaData().getOrDefault("ParentProcessInstanceId", -1L);
    log.setParentProcessInstanceId(parentProcessInstanceId);
    return log;
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 20 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class RuntimeDataServiceImplSecurityTest method testGetProcessInstancesByPartialCorrelationKey.

@Test
public void testGetProcessInstancesByPartialCorrelationKey() {
    // let's grant managers role so process can be started
    List<String> roles = new ArrayList<String>();
    roles.add("managers");
    identityProvider.setRoles(roles);
    Collection<ProcessInstanceDesc> instances = runtimeDataService.getProcessInstances(new QueryContext());
    assertNotNull(instances);
    assertEquals(0, instances.size());
    List<String> props = new ArrayList<String>();
    props.add("first");
    props.add("second");
    props.add("third");
    List<String> partial1props = new ArrayList<String>();
    partial1props.add("first");
    partial1props.add("second");
    List<String> partial2props = new ArrayList<String>();
    partial2props.add("first");
    CorrelationKey key = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey(props);
    CorrelationKey partialKey1 = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey(partial1props);
    CorrelationKey partialKey2 = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey(partial2props);
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", key);
    assertNotNull(processInstanceId);
    Collection<ProcessInstanceDesc> keyedInstances = runtimeDataService.getProcessInstancesByCorrelationKey(key, new QueryContext());
    assertNotNull(keyedInstances);
    assertEquals(1, keyedInstances.size());
    ProcessInstanceDesc instance = keyedInstances.iterator().next();
    assertNotNull(instance);
    assertEquals(1, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    assertEquals("first:second:third", instance.getCorrelationKey());
    List<UserTaskInstanceDesc> tasks = instance.getActiveTasks();
    assertNull(tasks);
    // search by partial key 1
    keyedInstances = runtimeDataService.getProcessInstancesByCorrelationKey(partialKey1, new QueryContext());
    assertNotNull(keyedInstances);
    assertEquals(1, keyedInstances.size());
    instance = keyedInstances.iterator().next();
    assertNotNull(instance);
    assertEquals(1, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    assertEquals("first:second:third", instance.getCorrelationKey());
    // search by partial key 2
    keyedInstances = runtimeDataService.getProcessInstancesByCorrelationKey(partialKey2, new QueryContext());
    assertNotNull(keyedInstances);
    assertEquals(1, keyedInstances.size());
    instance = keyedInstances.iterator().next();
    assertNotNull(instance);
    assertEquals(1, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    assertEquals("first:second:third", instance.getCorrelationKey());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) Test(org.junit.Test)

Aggregations

CorrelationKey (org.kie.internal.process.CorrelationKey)38 Test (org.junit.Test)27 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)21 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)12 QueryContext (org.kie.api.runtime.query.QueryContext)12 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)8 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)7 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)7 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)6 KieSession (org.kie.api.runtime.KieSession)6 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)5 Collection (java.util.Collection)4 List (java.util.List)4 Map (java.util.Map)4 Collectors.toList (java.util.stream.Collectors.toList)4 RegistryContext (org.drools.core.command.impl.RegistryContext)4 CaseEventSupport (org.jbpm.casemgmt.impl.event.CaseEventSupport)4 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)4