use of org.flowable.engine.runtime.ProcessInstanceQuery in project petals-se-flowable by petalslink.
the class Assert method assertProcessInstancePending.
/**
* Assertion to check that a process instance is running. The process instance is not finished.
*
* @param processInstanceId
* The process instance identifier
* @param processDefinitionKey
* The process definition key
* @param runtimeService
* The Flowable's runtime service used to request the Flowable engine about process instances.
*/
public static void assertProcessInstancePending(final String processInstanceId, final String processDefinitionKey, final RuntimeService runtimeService) {
final ProcessInstanceQuery processInstQuery = runtimeService.createProcessInstanceQuery();
final ProcessInstance processInstance = processInstQuery.processInstanceId(processInstanceId).singleResult();
assertNotNull(processInstance);
assertEquals(processInstanceId, processInstance.getProcessInstanceId());
assertEquals(processDefinitionKey, processInstance.getProcessDefinitionKey());
assertFalse(processInstance.isEnded());
assertFalse(processInstance.isSuspended());
}
use of org.flowable.engine.runtime.ProcessInstanceQuery in project petals-se-flowable by petalslink.
the class GetProcessInstancesOperation method searchProcessInstances.
/**
* Search process instances that are not ended (in state 'active' or 'suspended').
*/
private GetProcessInstancesResponse searchProcessInstances(final GetProcessInstances incomingObject, final ProcessInstanceState state) throws MessagingException {
final ProcessInstanceQuery processInstanceQuery = this.runtimeService.createProcessInstanceQuery();
if (state == ProcessInstanceState.ACTIVE) {
processInstanceQuery.active();
} else if (state == ProcessInstanceState.SUSPENDED) {
processInstanceQuery.suspended();
} else {
// we search all process instances independently of their state: ACTIVE and SUSPENDED
assert state == null;
}
final String processDefinitionId = incomingObject.getProcessDefinitionIdentifier();
if (processDefinitionId != null && !processDefinitionId.isEmpty()) {
processInstanceQuery.processDefinitionKey(processDefinitionId);
}
final String processInstanceId = incomingObject.getProcessInstanceIdentifier();
if (processInstanceId != null && !processInstanceId.isEmpty()) {
processInstanceQuery.processInstanceId(processInstanceId);
}
final Variables variables = incomingObject.getVariables();
if (variables != null && !variables.getVariable().isEmpty()) {
for (final Variable variable : variables.getVariable()) {
processInstanceQuery.variableValueEquals(variable.getName(), Utils.parseVariableValue(variable));
}
}
processInstanceQuery.includeProcessVariables();
final GetProcessInstancesResponse response = new GetProcessInstancesResponse();
final ProcessInstances responseProcessInstances = new ProcessInstances();
response.setProcessInstances(responseProcessInstances);
final List<ProcessInstance> processInstances = processInstanceQuery.list();
for (final ProcessInstance processInstance : processInstances) {
final org.ow2.petals.components.flowable.generic._1.ProcessInstance responseProcessInstance = new org.ow2.petals.components.flowable.generic._1.ProcessInstance();
responseProcessInstances.getProcessInstance().add(responseProcessInstance);
responseProcessInstance.setProcessInstanceIdentifier(processInstance.getProcessInstanceId());
if (processInstance.isSuspended()) {
responseProcessInstance.setState(ProcessInstanceState.SUSPENDED);
} else if (processInstance.isEnded()) {
responseProcessInstance.setState(ProcessInstanceState.FINISHED);
} else {
responseProcessInstance.setState(ProcessInstanceState.ACTIVE);
}
final ProcessDefinitionQuery processDefQuery = this.repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId());
final ProcessDefinition processDefinition = processDefQuery.singleResult();
responseProcessInstance.setProcessDefinitionIdentifier(processDefinition.getKey());
responseProcessInstance.setVariables(Utils.buildVariables(processInstance.getProcessVariables(), this.log));
}
return response;
}
use of org.flowable.engine.runtime.ProcessInstanceQuery in project petals-se-flowable by petalslink.
the class CallActivityStartedEventListener method createLogData.
@Override
protected AbstractFlowLogData createLogData(final FlowableEvent event) {
if (event instanceof FlowableProcessStartedEventImpl) {
final FlowableProcessStartedEventImpl eventImpl = (FlowableProcessStartedEventImpl) event;
if (eventImpl.getNestedProcessDefinitionId() != null) {
final String callActivityInstanceId = eventImpl.getProcessInstanceId();
final String parentInstanceId = eventImpl.getNestedProcessInstanceId();
final ExecutionEntity callActivityEntity = (ExecutionEntity) eventImpl.getEntity();
this.log.fine(String.format("The call activity '%s' (instance id '%s') is started from instance '%s'.", callActivityEntity.getProcessDefinitionKey(), callActivityInstanceId, parentInstanceId));
// To be able to retrieve variables of the parent process, the call activity must be executed
// asynchronously. See note in this class documentation.
final ProcessInstanceQuery processInstanceQuery = this.runtimeService.createProcessInstanceQuery().processInstanceId(parentInstanceId).includeProcessVariables();
final ProcessInstance processInstance = processInstanceQuery.singleResult();
final Map<String, Object> processVariables = processInstance.getProcessVariables();
final String flowInstanceId = (String) processVariables.get(VAR_PETALS_FLOW_INSTANCE_ID);
final String previousFlowStepId = (String) processVariables.get(VAR_PETALS_FLOW_STEP_ID);
if (previousFlowStepId == null) {
this.log.warning(String.format(MISSING_VARIABLE_PATTERN, VAR_PETALS_FLOW_STEP_ID, parentInstanceId));
}
final String flowStepId = this.simpleUUIDGenerator.getNewID();
// final Map callACtivityVariables = eventImpl.getVariables();
// callACtivityVariables.put(FlowableSEConstants.Flowable.VAR_PETALS_FLOW_INSTANCE_ID, flowInstanceId);
// callACtivityVariables.put(FlowableSEConstants.Flowable.VAR_PETALS_FLOW_STEP_ID, flowStepId);
this.runtimeService.setVariable(eventImpl.getExecutionId(), VAR_PETALS_FLOW_INSTANCE_ID, flowInstanceId);
this.runtimeService.setVariable(eventImpl.getExecutionId(), VAR_PETALS_FLOW_STEP_ID, flowStepId);
// Placeholders must be copied in the call activity scope
this.runtimeService.setVariable(eventImpl.getExecutionId(), VAR_PETALS_PLACEHOLDERS, processVariables.get(VAR_PETALS_PLACEHOLDERS));
final ExecutionEntity parentEntity = callActivityEntity.getParent();
return new CallActivityFlowStepBeginLogData(flowInstanceId, flowStepId, previousFlowStepId, parentEntity.getProcessDefinitionKey(), parentInstanceId, callActivityEntity.getProcessDefinitionKey(), callActivityInstanceId);
} else {
// It's a nominal process instance start. It is processed by ProcessInstanceStartedEventListener
return null;
}
} else {
this.log.warning("Unexpected event implementation: " + event.getClass().getName());
return null;
}
}
use of org.flowable.engine.runtime.ProcessInstanceQuery in project petals-se-flowable by petalslink.
the class IntermediateCatchMessageEventEndedEventListener method createLogData.
@Override
protected AbstractFlowLogData createLogData(final FlowableEvent event) {
if (event instanceof FlowableMessageEvent) {
final FlowableMessageEvent messageEvent = (FlowableMessageEvent) event;
final ProcessInstanceQuery processInstanceQuery = this.runtimeService.createProcessInstanceQuery().processInstanceId(messageEvent.getProcessInstanceId()).includeProcessVariables();
final ProcessInstance processInstance = processInstanceQuery.singleResult();
final Map<String, Object> processVariables = processInstance.getProcessVariables();
final String flowInstanceId = (String) processVariables.get(VAR_PETALS_FLOW_INSTANCE_ID);
final Map<String, Object> localVariable = this.runtimeService.getVariablesLocal(messageEvent.getExecutionId());
final String flowStepId = (String) localVariable.get(VAR_PETALS_FLOW_STEP_ID);
final String correlatedFlowInstanceId = (String) localVariable.get(VAR_PETALS_CORRELATED_FLOW_INSTANCE_ID);
final String correlatedFlowStepId = (String) localVariable.get(VAR_PETALS_CORRELATED_FLOW_STEP_ID);
if (flowInstanceId != null && flowStepId != null) {
return new IntermediateCatchMessageEventFlowStepEndLogData(flowInstanceId, flowStepId, correlatedFlowInstanceId, correlatedFlowStepId);
} else {
this.log.warning(String.format("No MONIT end trace generated because a variable is missing: %s.", flowInstanceId == null ? VAR_PETALS_FLOW_INSTANCE_ID : VAR_PETALS_FLOW_STEP_ID));
return null;
}
}
return null;
}
use of org.flowable.engine.runtime.ProcessInstanceQuery in project petals-se-flowable by petalslink.
the class ServiceTaskStartedEventListener method processEvent.
@Override
protected void processEvent(final FlowableEvent event) {
if (event instanceof FlowableActivityEvent) {
final FlowableActivityEvent eventImpl = (FlowableActivityEvent) event;
if ("serviceTask".equals(eventImpl.getActivityType())) {
final ProcessInstanceQuery processInstanceQuery = this.runtimeService.createProcessInstanceQuery().processInstanceId(eventImpl.getProcessInstanceId()).includeProcessVariables();
final ProcessInstance processInstance = processInstanceQuery.singleResult();
final Map<String, Object> processVariables = processInstance.getProcessVariables();
final String flowInstanceId = (String) processVariables.get(VAR_PETALS_FLOW_INSTANCE_ID);
final String flowStepId = (String) processVariables.get(VAR_PETALS_FLOW_STEP_ID);
final Optional<Boolean> extFlowTracingActivated;
if (processVariables.containsKey(VAR_PETALS_EXT_FLOW_TRACING_ACTIVATION_STATE)) {
extFlowTracingActivated = Optional.of(Boolean.valueOf((boolean) processVariables.get(VAR_PETALS_EXT_FLOW_TRACING_ACTIVATION_STATE)));
} else {
extFlowTracingActivated = Optional.empty();
}
PetalsConduit.flowAttributes.set(new FlowAttributes(flowInstanceId, flowStepId));
PetalsConduit.extFlowTracingActivated.set(extFlowTracingActivated);
}
} else {
this.log.warning("Unexpected event implementation: " + event.getClass().getName());
}
}
Aggregations