Search in sources :

Example 71 with Execution

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

the class AsyncProcessRevisitedTest method testRunProcess.

@Deployment(resources = { "process/revisited/async-revisited.bpmn20.xml" })
public void testRunProcess() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncCamelProcessRevisited");
    List<Execution> executionList = runtimeService.createExecutionQuery().list();
    assertEquals(3, executionList.size());
    waitForJobExecutorToProcessAllJobs(10000, 500);
    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 72 with Execution

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

the class BusinessProcess method associateExecutionById.

/**
   * Associate with the provided execution. This starts a unit of work.
   * 
   * @param executionId
   *          the id of the execution to associate with.
   * @throw ActivitiCdiException
   *          if no such execution exists
   */
public void associateExecutionById(String executionId) {
    Execution execution = processEngine.getRuntimeService().createExecutionQuery().executionId(executionId).singleResult();
    if (execution == null) {
        throw new ActivitiCdiException("Cannot associate execution by id: no execution with id '" + executionId + "' found.");
    }
    associationManager.setExecution(execution);
}
Also used : Execution(org.activiti.engine.runtime.Execution)

Example 73 with Execution

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

the class BaseProcessDefinitionDiagramLayoutResource method getActivity.

private void getActivity(String processInstanceId, ActivityImpl activity, ArrayNode activityArray, ArrayNode sequenceFlowArray, ProcessInstance processInstance, List<String> highLightedFlows, Map<String, ObjectNode> subProcessInstanceMap) {
    ObjectNode activityJSON = new ObjectMapper().createObjectNode();
    // Gather info on the multi instance marker
    String multiInstance = (String) activity.getProperty("multiInstance");
    if (multiInstance != null) {
        if (!"sequential".equals(multiInstance)) {
            multiInstance = "parallel";
        }
    }
    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    // Gather info on the collapsed marker
    Boolean collapsed = (activityBehavior instanceof CallActivityBehavior);
    Boolean expanded = (Boolean) activity.getProperty(BpmnParse.PROPERTYNAME_ISEXPANDED);
    if (expanded != null) {
        collapsed = !expanded;
    }
    Boolean isInterrupting = null;
    if (activityBehavior instanceof BoundaryEventActivityBehavior) {
        isInterrupting = ((BoundaryEventActivityBehavior) activityBehavior).isInterrupting();
    }
    // Outgoing transitions of activity
    for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
        String flowName = (String) sequenceFlow.getProperty("name");
        boolean isHighLighted = (highLightedFlows.contains(sequenceFlow.getId()));
        boolean isConditional = sequenceFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION) != null && !((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        boolean isDefault = sequenceFlow.getId().equals(activity.getProperty("default")) && ((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        List<Integer> waypoints = ((TransitionImpl) sequenceFlow).getWaypoints();
        ArrayNode xPointArray = new ObjectMapper().createArrayNode();
        ArrayNode yPointArray = new ObjectMapper().createArrayNode();
        for (int i = 0; i < waypoints.size(); i += 2) {
            // waypoints.size()
            // minimally 4: x1, y1,
            // x2, y2
            xPointArray.add(waypoints.get(i));
            yPointArray.add(waypoints.get(i + 1));
        }
        ObjectNode flowJSON = new ObjectMapper().createObjectNode();
        flowJSON.put("id", sequenceFlow.getId());
        flowJSON.put("name", flowName);
        flowJSON.put("flow", "(" + sequenceFlow.getSource().getId() + ")--" + sequenceFlow.getId() + "-->(" + sequenceFlow.getDestination().getId() + ")");
        if (isConditional)
            flowJSON.put("isConditional", isConditional);
        if (isDefault)
            flowJSON.put("isDefault", isDefault);
        if (isHighLighted)
            flowJSON.put("isHighLighted", isHighLighted);
        flowJSON.put("xPointArray", xPointArray);
        flowJSON.put("yPointArray", yPointArray);
        sequenceFlowArray.add(flowJSON);
    }
    // Nested activities (boundary events)
    ArrayNode nestedActivityArray = new ObjectMapper().createArrayNode();
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        nestedActivityArray.add(nestedActivity.getId());
    }
    Map<String, Object> properties = activity.getProperties();
    ObjectNode propertiesJSON = new ObjectMapper().createObjectNode();
    for (String key : properties.keySet()) {
        Object prop = properties.get(key);
        if (prop instanceof String)
            propertiesJSON.put(key, (String) properties.get(key));
        else if (prop instanceof Integer)
            propertiesJSON.put(key, (Integer) properties.get(key));
        else if (prop instanceof Boolean)
            propertiesJSON.put(key, (Boolean) properties.get(key));
        else if ("initial".equals(key)) {
            ActivityImpl act = (ActivityImpl) properties.get(key);
            propertiesJSON.put(key, act.getId());
        } else if ("timerDeclarations".equals(key)) {
            ArrayList<TimerDeclarationImpl> timerDeclarations = (ArrayList<TimerDeclarationImpl>) properties.get(key);
            ArrayNode timerDeclarationArray = new ObjectMapper().createArrayNode();
            if (timerDeclarations != null)
                for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
                    ObjectNode timerDeclarationJSON = new ObjectMapper().createObjectNode();
                    timerDeclarationJSON.put("isExclusive", timerDeclaration.isExclusive());
                    if (timerDeclaration.getRepeat() != null)
                        timerDeclarationJSON.put("repeat", timerDeclaration.getRepeat());
                    timerDeclarationJSON.put("retries", String.valueOf(timerDeclaration.getRetries()));
                    timerDeclarationJSON.put("type", timerDeclaration.getJobHandlerType());
                    timerDeclarationJSON.put("configuration", timerDeclaration.getJobHandlerConfiguration());
                    //timerDeclarationJSON.put("expression", timerDeclaration.getDescription());
                    timerDeclarationArray.add(timerDeclarationJSON);
                }
            if (timerDeclarationArray.size() > 0)
                propertiesJSON.put(key, timerDeclarationArray);
        // TODO: implement getting description
        } else if ("eventDefinitions".equals(key)) {
            ArrayList<EventSubscriptionDeclaration> eventDefinitions = (ArrayList<EventSubscriptionDeclaration>) properties.get(key);
            ArrayNode eventDefinitionsArray = new ObjectMapper().createArrayNode();
            if (eventDefinitions != null) {
                for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
                    ObjectNode eventDefinitionJSON = new ObjectMapper().createObjectNode();
                    if (eventDefinition.getActivityId() != null)
                        eventDefinitionJSON.put("activityId", eventDefinition.getActivityId());
                    eventDefinitionJSON.put("eventName", eventDefinition.getEventName());
                    eventDefinitionJSON.put("eventType", eventDefinition.getEventType());
                    eventDefinitionJSON.put("isAsync", eventDefinition.isAsync());
                    eventDefinitionJSON.put("isStartEvent", eventDefinition.isStartEvent());
                    eventDefinitionsArray.add(eventDefinitionJSON);
                }
            }
            if (eventDefinitionsArray.size() > 0)
                propertiesJSON.put(key, eventDefinitionsArray);
        // TODO: implement it
        } else if ("errorEventDefinitions".equals(key)) {
            ArrayList<ErrorEventDefinition> errorEventDefinitions = (ArrayList<ErrorEventDefinition>) properties.get(key);
            ArrayNode errorEventDefinitionsArray = new ObjectMapper().createArrayNode();
            if (errorEventDefinitions != null) {
                for (ErrorEventDefinition errorEventDefinition : errorEventDefinitions) {
                    ObjectNode errorEventDefinitionJSON = new ObjectMapper().createObjectNode();
                    if (errorEventDefinition.getErrorCode() != null)
                        errorEventDefinitionJSON.put("errorCode", errorEventDefinition.getErrorCode());
                    else
                        errorEventDefinitionJSON.putNull("errorCode");
                    errorEventDefinitionJSON.put("handlerActivityId", errorEventDefinition.getHandlerActivityId());
                    errorEventDefinitionsArray.add(errorEventDefinitionJSON);
                }
            }
            if (errorEventDefinitionsArray.size() > 0)
                propertiesJSON.put(key, errorEventDefinitionsArray);
        }
    }
    if ("callActivity".equals(properties.get("type"))) {
        CallActivityBehavior callActivityBehavior = null;
        if (activityBehavior instanceof CallActivityBehavior) {
            callActivityBehavior = (CallActivityBehavior) activityBehavior;
        }
        if (callActivityBehavior != null) {
            propertiesJSON.put("processDefinitonKey", callActivityBehavior.getProcessDefinitonKey());
            // get processDefinitonId from execution or get last processDefinitonId
            // by key
            ArrayNode processInstanceArray = new ObjectMapper().createArrayNode();
            if (processInstance != null) {
                List<Execution> executionList = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).activityId(activity.getId()).list();
                if (!executionList.isEmpty()) {
                    for (Execution execution : executionList) {
                        ObjectNode processInstanceJSON = subProcessInstanceMap.get(execution.getId());
                        processInstanceArray.add(processInstanceJSON);
                    }
                }
            }
            // last definition
            if (processInstanceArray.size() == 0 && StringUtils.isNotEmpty(callActivityBehavior.getProcessDefinitonKey())) {
                // Get last definition by key
                ProcessDefinition lastProcessDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(callActivityBehavior.getProcessDefinitonKey()).latestVersion().singleResult();
                // TODO: unuseful fields there are processDefinitionName, processDefinitionKey
                if (lastProcessDefinition != null) {
                    ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode();
                    processInstanceJSON.put("processDefinitionId", lastProcessDefinition.getId());
                    processInstanceJSON.put("processDefinitionKey", lastProcessDefinition.getKey());
                    processInstanceJSON.put("processDefinitionName", lastProcessDefinition.getName());
                    processInstanceArray.add(processInstanceJSON);
                }
            }
            if (processInstanceArray.size() > 0) {
                propertiesJSON.put("processDefinitons", processInstanceArray);
            }
        }
    }
    activityJSON.put("activityId", activity.getId());
    activityJSON.put("properties", propertiesJSON);
    if (multiInstance != null)
        activityJSON.put("multiInstance", multiInstance);
    if (collapsed)
        activityJSON.put("collapsed", collapsed);
    if (nestedActivityArray.size() > 0)
        activityJSON.put("nestedActivities", nestedActivityArray);
    if (isInterrupting != null)
        activityJSON.put("isInterrupting", isInterrupting);
    activityJSON.put("x", activity.getX());
    activityJSON.put("y", activity.getY());
    activityJSON.put("width", activity.getWidth());
    activityJSON.put("height", activity.getHeight());
    activityArray.add(activityJSON);
    // Nested activities (boundary events)
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        getActivity(processInstanceId, nestedActivity, activityArray, sequenceFlowArray, processInstance, highLightedFlows, subProcessInstanceMap);
    }
}
Also used : TimerDeclarationImpl(org.activiti.engine.impl.jobexecutor.TimerDeclarationImpl) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Execution(org.activiti.engine.runtime.Execution) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CallActivityBehavior(org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ErrorEventDefinition(org.activiti.engine.impl.bpmn.parser.ErrorEventDefinition) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) ActivityBehavior(org.activiti.engine.impl.pvm.delegate.ActivityBehavior) CallActivityBehavior(org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) EventSubscriptionDeclaration(org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration)

Example 74 with Execution

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

the class ActivityEventsTest method testActivityMessageEvents.

/**
	 * Test events related to message events, called from the API.
	 */
@Deployment
public void testActivityMessageEvents() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageProcess");
    assertNotNull(processInstance);
    Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("shipOrder").singleResult();
    assertNotNull(executionWithMessage);
    runtimeService.messageEventReceived("messageName", executionWithMessage.getId());
    assertEquals(2, listener.getEventsReceived().size());
    // First, a message-event is expected
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiMessageEvent);
    ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, messageEvent.getType());
    assertEquals("shipOrder", messageEvent.getActivityId());
    assertEquals(executionWithMessage.getId(), messageEvent.getExecutionId());
    assertEquals(executionWithMessage.getProcessInstanceId(), messageEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), messageEvent.getProcessDefinitionId());
    assertEquals("messageName", messageEvent.getMessageName());
    assertNull(messageEvent.getMessageData());
    // Next, an signal-event is expected, as a result of the message
    assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiSignalEvent);
    ActivitiSignalEvent signalEvent = (ActivitiSignalEvent) listener.getEventsReceived().get(1);
    assertEquals(ActivitiEventType.ACTIVITY_SIGNALED, signalEvent.getType());
    assertEquals("shipOrder", signalEvent.getActivityId());
    assertEquals(executionWithMessage.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithMessage.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertEquals("messageName", signalEvent.getSignalName());
    assertNull(signalEvent.getSignalData());
    assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiSignalEvent(org.activiti.engine.delegate.event.ActivitiSignalEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ActivitiMessageEvent(org.activiti.engine.delegate.event.ActivitiMessageEvent) Deployment(org.activiti.engine.test.Deployment)

Example 75 with Execution

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

the class ActivityEventsTest method testActivitySignalBoundaryEventsOnUserTask.

@Deployment
public void testActivitySignalBoundaryEventsOnUserTask() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("signalOnUserTask");
    assertNotNull(processInstance);
    Execution executionWithSignal = runtimeService.createExecutionQuery().activityId("userTask").singleResult();
    assertNotNull(executionWithSignal);
    runtimeService.signalEventReceived("signalName");
    assertEquals(1, listener.getEventsReceived().size());
    // Next, an signal-event is expected, as a result of the message
    assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiActivityCancelledEvent);
    ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(0);
    assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
    assertEquals("userTask", signalEvent.getActivityId());
    assertEquals(executionWithSignal.getId(), signalEvent.getExecutionId());
    assertEquals(executionWithSignal.getProcessInstanceId(), signalEvent.getProcessInstanceId());
    assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
    assertNotNull(signalEvent.getCause());
    assertTrue(signalEvent.getCause() instanceof SignalEventSubscriptionEntity);
    SignalEventSubscriptionEntity cause = (SignalEventSubscriptionEntity) signalEvent.getCause();
    assertEquals("signalName", cause.getEventName());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ActivitiActivityCancelledEvent(org.activiti.engine.delegate.event.ActivitiActivityCancelledEvent) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) 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