Search in sources :

Example 1 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class DefaultContextAssociationManager method setExecution.

@Override
public void setExecution(Execution execution) {
    if (execution == null) {
        throw new ActivitiCdiException("Cannot associate with execution: null");
    }
    if (Context.getCommandContext() != null) {
        throw new ActivitiCdiException("Cannot work with scoped associations inside command context.");
    }
    ScopedAssociation scopedAssociation = getScopedAssociation();
    Execution associatedExecution = scopedAssociation.getExecution();
    if (associatedExecution != null && !associatedExecution.getId().equals(execution.getId())) {
        throw new ActivitiCdiException("Cannot associate " + execution + ", already associated with " + associatedExecution + ". Disassociate first!");
    }
    if (log.isTraceEnabled()) {
        log.trace("Associating {} (@{})", execution, scopedAssociation.getClass().getAnnotations()[0].annotationType().getSimpleName());
    }
    scopedAssociation.setExecution(execution);
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiCdiException(org.activiti.cdi.ActivitiCdiException)

Example 2 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class AsyncPingTest method testRunProcess.

@Deployment(resources = { "process/asyncPing.bpmn20.xml" })
public void testRunProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncPingProcess");
    List<Execution> executionList = runtimeService.createExecutionQuery().list();
    Assert.assertEquals(1, executionList.size());
    managementService.executeJob(managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult().getId());
    Thread.sleep(1500);
    executionList = runtimeService.createExecutionQuery().list();
    Assert.assertEquals(0, executionList.size());
    Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class AsyncProcessTest method testRunProcess.

@Deployment(resources = { "process/async.bpmn20.xml" })
public void testRunProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncCamelProcess");
    List<Execution> executionList = runtimeService.createExecutionQuery().list();
    assertEquals(3, executionList.size());
    Thread.sleep(4000);
    assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 4 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ActivitiProducer method signal.

protected void signal(Exchange exchange) {
    String processInstanceId = findProcessInstanceId(exchange);
    String executionId = exchange.getProperty(EXECUTION_ID_PROPERTY, String.class);
    boolean firstTime = true;
    long initialTime = System.currentTimeMillis();
    Execution execution = null;
    while (firstTime || (timeout > 0 && (System.currentTimeMillis() - initialTime < timeout))) {
        try {
            Thread.sleep(timeResolution);
        } catch (InterruptedException e) {
            throw new ActivitiException("error occured while waiting for activiti=" + activity + " for processInstanceId=" + processInstanceId);
        }
        firstTime = false;
        if (executionId != null) {
            execution = runtimeService.createExecutionQuery().executionId(executionId).activityId(activity).singleResult();
        } else {
            execution = runtimeService.createExecutionQuery().processDefinitionKey(processKey).processInstanceId(processInstanceId).activityId(activity).singleResult();
        }
        if (execution != null) {
            break;
        }
    }
    if (execution == null) {
        throw new ActivitiException("Couldn't find activity " + activity + " for processId " + processInstanceId + " in defined timeout.");
    }
    runtimeService.setVariables(execution.getId(), ExchangeUtils.prepareVariables(exchange, getActivitiEndpoint()));
    runtimeService.signal(execution.getId());
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Execution(org.activiti.engine.runtime.Execution)

Example 5 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class EventSubscriptionQueryTest method testQueryByExecutionId.

@Deployment
public void testQueryByExecutionId() {
    // starting two instances:
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("catchSignal");
    runtimeService.startProcessInstanceByKey("catchSignal");
    // test query by process instance id
    EventSubscriptionEntity subscription = newEventSubscriptionQuery().processInstanceId(processInstance.getId()).singleResult();
    assertNotNull(subscription);
    Execution executionWaitingForSignal = runtimeService.createExecutionQuery().activityId("signalEvent").processInstanceId(processInstance.getId()).singleResult();
    // test query by execution id
    EventSubscriptionEntity signalSubscription = newEventSubscriptionQuery().executionId(executionWaitingForSignal.getId()).singleResult();
    assertNotNull(signalSubscription);
    assertEquals(signalSubscription, subscription);
    cleanDb();
}
Also used : Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Execution (org.activiti.engine.runtime.Execution)131 Deployment (org.activiti.engine.test.Deployment)105 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)75 Task (org.activiti.engine.task.Task)33 HashMap (java.util.HashMap)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)10 HttpPut (org.apache.http.client.methods.HttpPut)10 StringEntity (org.apache.http.entity.StringEntity)9 ArrayList (java.util.ArrayList)8 ActivitiException (org.activiti.engine.ActivitiException)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Date (java.util.Date)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5