Search in sources :

Example 1 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project herd by FINRAOS.

the class ActivitiServiceTest method getExecutionByProcessInstanceIdAndActivitiId.

@Test
public void getExecutionByProcessInstanceIdAndActivitiId() {
    String processInstanceId = "processInstanceId";
    String activitiId = "activitiId";
    ExecutionQuery executionQuery = mock(ExecutionQuery.class);
    when(activitiRuntimeService.createExecutionQuery()).thenReturn(executionQuery);
    when(executionQuery.processInstanceId(processInstanceId)).thenReturn(executionQuery);
    when(executionQuery.activityId(activitiId)).thenReturn(executionQuery);
    Execution expectedExecution = mock(Execution.class);
    when(executionQuery.singleResult()).thenReturn(expectedExecution);
    Execution actualExecution = activitiService.getExecutionByProcessInstanceIdAndActivitiId(processInstanceId, activitiId);
    assertSame(expectedExecution, actualExecution);
    InOrder inOrder = inOrder(executionQuery);
    inOrder.verify(executionQuery).processInstanceId(processInstanceId);
    inOrder.verify(executionQuery).activityId(activitiId);
    inOrder.verify(executionQuery).singleResult();
    inOrder.verifyNoMoreInteractions();
}
Also used : Execution(org.activiti.engine.runtime.Execution) InOrder(org.mockito.InOrder) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Test(org.junit.Test)

Example 2 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project herd by FINRAOS.

the class ActivitiRuntimeHelper method signal.

/**
 * Signals a task by its process instance ID and the ID of the task to signal.
 *
 * @param processInstanceId The process instance ID of the waiting task.
 * @param signalTaskId The ID of the task to signal.
 */
public void signal(String processInstanceId, String signalTaskId) {
    ExecutionQuery signalTaskQuery = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).activityId(signalTaskId);
    Execution execution = signalTaskQuery.singleResult();
    runtimeService.signal(execution.getId());
}
Also used : DelegateExecution(org.activiti.engine.delegate.DelegateExecution) Execution(org.activiti.engine.runtime.Execution) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery)

Example 3 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project carbon-business-process by wso2.

the class CorrelationProcess method getQueryResponse.

public Response getQueryResponse(CorrelationActionRequest correlationActionRequest, UriInfo uriInfo) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    ExecutionQuery query = runtimeService.createExecutionQuery();
    String value = correlationActionRequest.getProcessDefinitionId();
    if (value != null) {
        query.processDefinitionId(value);
    }
    value = correlationActionRequest.getProcessDefinitionKey();
    if (value != null) {
        query.processDefinitionKey(value);
    }
    value = correlationActionRequest.getMessageName();
    if (value != null) {
        query.messageEventSubscriptionName(value);
    }
    value = correlationActionRequest.getSignalName();
    if (value != null) {
        query.signalEventSubscriptionName(value);
    }
    List<QueryVariable> queryVariableList = correlationActionRequest.getCorrelationVariables();
    if (queryVariableList != null) {
        List<QueryVariable> updatedQueryVariableList = new ArrayList<>();
        for (QueryVariable queryVariable : queryVariableList) {
            if (queryVariable.getVariableOperation() == null) {
                queryVariable.setOperation("equals");
            }
            updatedQueryVariableList.add(queryVariable);
        }
        addVariables(query, updatedQueryVariableList, true);
    }
    value = correlationActionRequest.getTenantId();
    if (value != null) {
        query.executionTenantId(value);
    }
    QueryProperty qp = allowedSortProperties.get("processInstanceId");
    ((AbstractQuery) query).orderBy(qp);
    query.asc();
    List<Execution> executionList = query.listPage(0, 10);
    int size = executionList.size();
    if (size == 0) {
        throw new ActivitiIllegalArgumentException("No Executions found to correlate with given information");
    }
    if (size > 1) {
        throw new ActivitiIllegalArgumentException("More than one Executions found to correlate with given information");
    }
    Execution execution = executionList.get(0);
    String action = correlationActionRequest.getAction();
    if (CorrelationActionRequest.ACTION_SIGNAL.equals(action)) {
        if (correlationActionRequest.getVariables() != null) {
            runtimeService.signal(execution.getId(), getVariablesToSet(correlationActionRequest));
        } else {
            runtimeService.signal(execution.getId());
        }
    } else if (CorrelationActionRequest.ACTION_SIGNAL_EVENT_RECEIVED.equals(action)) {
        if (correlationActionRequest.getSignalName() == null) {
            throw new ActivitiIllegalArgumentException("Signal name is required");
        }
        if (correlationActionRequest.getVariables() != null) {
            runtimeService.signalEventReceived(correlationActionRequest.getSignalName(), execution.getId(), getVariablesToSet(correlationActionRequest));
        } else {
            runtimeService.signalEventReceived(correlationActionRequest.getSignalName(), execution.getId());
        }
    } else if (CorrelationActionRequest.ACTION_MESSAGE_EVENT_RECEIVED.equals(action)) {
        if (correlationActionRequest.getMessageName() == null) {
            throw new ActivitiIllegalArgumentException("Message name is required");
        }
        if (correlationActionRequest.getVariables() != null) {
            runtimeService.messageEventReceived(correlationActionRequest.getMessageName(), execution.getId(), getVariablesToSet(correlationActionRequest));
        } else {
            runtimeService.messageEventReceived(correlationActionRequest.getMessageName(), execution.getId());
        }
    } else {
        throw new ActivitiIllegalArgumentException("Invalid action: '" + correlationActionRequest.getAction() + "'.");
    }
    Response.ResponseBuilder responseBuilder = Response.ok();
    // Re-fetch the execution, could have changed due to action or even completed
    execution = runtimeService.createExecutionQuery().executionId(execution.getId()).singleResult();
    if (execution == null) {
        // Execution is finished, return empty body to inform user
        responseBuilder.status(Response.Status.NO_CONTENT);
        return responseBuilder.build();
    } else {
        return responseBuilder.entity(new RestResponseFactory().createExecutionResponse(execution, uriInfo.getBaseUri().toString())).build();
    }
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) QueryVariable(org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable) ArrayList(java.util.ArrayList) CorrelationQueryProperty(org.wso2.carbon.bpmn.rest.model.common.CorrelationQueryProperty) QueryProperty(org.activiti.engine.query.QueryProperty) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Response(javax.ws.rs.core.Response) Execution(org.activiti.engine.runtime.Execution) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) AbstractQuery(org.activiti.engine.impl.AbstractQuery)

Example 4 with ExecutionQuery

use of org.activiti.engine.runtime.ExecutionQuery in project carbon-business-process by wso2.

the class BaseExecutionService method getQueryResponse.

protected DataResponse getQueryResponse(ExecutionQueryRequest queryRequest, Map<String, String> requestParams, UriInfo uriInfo) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    ExecutionQuery query = runtimeService.createExecutionQuery();
    // Populate query based on request
    if (queryRequest.getId() != null) {
        query.executionId(queryRequest.getId());
        requestParams.put("id", queryRequest.getId());
    }
    if (queryRequest.getProcessInstanceId() != null) {
        query.processInstanceId(queryRequest.getProcessInstanceId());
        requestParams.put("processInstanceId", queryRequest.getProcessInstanceId());
    }
    if (queryRequest.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(queryRequest.getProcessDefinitionKey());
        requestParams.put("processDefinitionKey", queryRequest.getProcessDefinitionKey());
    }
    if (queryRequest.getProcessDefinitionId() != null) {
        query.processDefinitionId(queryRequest.getProcessDefinitionId());
        requestParams.put("processDefinitionId", queryRequest.getProcessDefinitionId());
    }
    if (queryRequest.getProcessBusinessKey() != null) {
        query.processInstanceBusinessKey(queryRequest.getProcessBusinessKey());
        requestParams.put("processInstanceBusinessKey", queryRequest.getProcessBusinessKey());
    }
    if (queryRequest.getActivityId() != null) {
        query.activityId(queryRequest.getActivityId());
        requestParams.put("activityId", queryRequest.getActivityId());
    }
    if (queryRequest.getParentId() != null) {
        query.parentId(queryRequest.getParentId());
        requestParams.put("parentId", queryRequest.getParentId());
    }
    if (queryRequest.getMessageEventSubscriptionName() != null) {
        query.messageEventSubscriptionName(queryRequest.getMessageEventSubscriptionName());
        requestParams.put("messageEventSubscriptionName", queryRequest.getMessageEventSubscriptionName());
    }
    if (queryRequest.getSignalEventSubscriptionName() != null) {
        query.signalEventSubscriptionName(queryRequest.getSignalEventSubscriptionName());
        requestParams.put("signalEventSubscriptionName", queryRequest.getSignalEventSubscriptionName());
    }
    if (queryRequest.getVariables() != null) {
        addVariables(query, queryRequest.getVariables(), false);
    }
    if (queryRequest.getProcessInstanceVariables() != null) {
        addVariables(query, queryRequest.getProcessInstanceVariables(), true);
    }
    if (queryRequest.getTenantId() != null) {
        query.executionTenantId(queryRequest.getTenantId());
        requestParams.put("tenantId", queryRequest.getTenantId());
    }
    if (queryRequest.getTenantIdLike() != null) {
        query.executionTenantIdLike(queryRequest.getTenantIdLike());
        requestParams.put("tenantIdLike", queryRequest.getTenantIdLike());
    }
    if (Boolean.TRUE.equals(queryRequest.getWithoutTenantId())) {
        query.executionWithoutTenantId();
        requestParams.put("withoutTenantId", queryRequest.getWithoutTenantId().toString());
    }
    DataResponse dataResponse = new ExecutionPaginateList(new RestResponseFactory(), uriInfo).paginateList(requestParams, queryRequest, query, "processInstanceId", allowedSortProperties);
    return dataResponse;
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery)

Example 5 with ExecutionQuery

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

the class ExecutionQueryTest method testQueryByInvalidActivityId.

public void testQueryByInvalidActivityId() {
    ExecutionQuery query = runtimeService.createExecutionQuery().activityId("invalid");
    assertThat(query.singleResult()).isNull();
    assertThat(query.list()).hasSize(0);
    assertThat(query.count()).isEqualTo(0);
}
Also used : ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery)

Aggregations

ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)26 Execution (org.activiti.engine.runtime.Execution)14 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 Deployment (org.activiti.engine.test.Deployment)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)2 RuntimeService (org.activiti.engine.RuntimeService)2 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)2 Test (org.junit.Test)2 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Response (javax.ws.rs.core.Response)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 AbstractQuery (org.activiti.engine.impl.AbstractQuery)1 QueryProperty (org.activiti.engine.query.QueryProperty)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1