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();
}
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());
}
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();
}
}
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;
}
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);
}
Aggregations