use of org.activiti.engine.impl.pvm.process.ActivityImpl in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowHistoricProcessInstanceService method getHighLightedFlows.
/**
* Add highlight flows by historic activity list
*
* @param activityList
* @param historicActivityInstanceList
* @param highLightedFlows
*/
private void getHighLightedFlows(List<ActivityImpl> activityList, List<String> historicActivityInstanceList, List<String> highLightedFlows) {
Map<Integer, String> usedActivityFlow = new HashMap<Integer, String>();
/**
* Iterate all used activity (start to end)
*/
for (int i = 0; i < historicActivityInstanceList.size(); i++) {
String activityId = historicActivityInstanceList.get(i);
ActivityImpl currentActivity = null;
for (ActivityImpl activity : activityList) {
if (activityId.equals(activity.getId())) {
currentActivity = activity;
break;
}
}
if (currentActivity == null) {
continue;
}
/**
* Get incoming transitions from current activity
*/
List<PvmTransition> pvmTransitionList = currentActivity.getIncomingTransitions();
boolean findedFlow = false;
// create index previous activity
int prevIndex = i - 1;
/**
* We will finding flow for highlight. We will start with previous activity.
* if we find nothing, then we will continuing with previous activity (index = index -1).
*/
while (!findedFlow) {
if (prevIndex < 0) {
// We are on begin .. nothing to highlight
break;
}
String tempActivity = historicActivityInstanceList.get(prevIndex);
for (PvmTransition pvmTransition : pvmTransitionList) {
String destinationFlowId = pvmTransition.getSource().getId();
if (tempActivity != null && destinationFlowId.equals(tempActivity)) {
highLightedFlows.add(pvmTransition.getId());
findedFlow = true;
for (ActivityImpl activity : activityList) {
if (tempActivity.equals(activity.getId()) && !(activity.getActivityBehavior() instanceof ParallelGatewayActivityBehavior)) {
// We use activity in other cycle if is ParallelGate.
// Its means, we don't put parralel gate to usedActivityFlow map.
usedActivityFlow.put(prevIndex, tempActivity);
}
}
}
}
if (!findedFlow) {
// If we don't find flow for highlight, we have to continue with previous historic activity
while (true) {
prevIndex = prevIndex - 1;
if (!usedActivityFlow.containsKey(prevIndex)) {
break;
}
}
}
}
}
}
use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class AtomicOperationActivityEnd method eventNotificationsCompleted.
@SuppressWarnings("unchecked")
@Override
protected void eventNotificationsCompleted(InterpretableExecution execution) {
ActivityImpl activity = (ActivityImpl) execution.getActivity();
ActivityImpl parentActivity = activity.getParentActivity();
if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
if (execution instanceof ExecutionEntity) {
ExecutionEntity executionEntity = (ExecutionEntity) execution;
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_COMPLETED, execution.getActivity().getId(), (String) executionEntity.getActivity().getProperties().get("name"), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), (String) executionEntity.getActivity().getProperties().get("type"), executionEntity.getActivity().getActivityBehavior().getClass().getCanonicalName()));
}
}
// if the execution is a single path of execution inside the process definition scope
if ((parentActivity != null) && (!parentActivity.isScope())) {
execution.setActivity(parentActivity);
execution.performOperation(ACTIVITY_END);
} else if (execution.isProcessInstanceType()) {
// dispatch process completed event
if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.PROCESS_COMPLETED, execution));
}
execution.performOperation(PROCESS_END);
} else if (execution.isScope()) {
ActivityBehavior parentActivityBehavior = (parentActivity != null ? parentActivity.getActivityBehavior() : null);
if (parentActivityBehavior instanceof CompositeActivityBehavior) {
CompositeActivityBehavior compositeActivityBehavior = (CompositeActivityBehavior) parentActivity.getActivityBehavior();
if (activity.isScope() && activity.getOutgoingTransitions().isEmpty()) {
// there is no transition destroying the scope
InterpretableExecution parentScopeExecution = (InterpretableExecution) execution.getParent();
execution.destroy();
execution.remove();
parentScopeExecution.setActivity(parentActivity);
compositeActivityBehavior.lastExecutionEnded(parentScopeExecution);
} else {
execution.setActivity(parentActivity);
compositeActivityBehavior.lastExecutionEnded(execution);
}
} else {
// default destroy scope behavior
InterpretableExecution parentScopeExecution = (InterpretableExecution) execution.getParent();
execution.destroy();
execution.remove();
// and have no outgoing transitions: end the process instance here
if (activity.getParent() == activity.getProcessDefinition()) {
parentScopeExecution.setActivity(activity);
if (activity.getOutgoingTransitions().isEmpty()) {
// we call end() because it sets isEnded on the execution
parentScopeExecution.end();
} else {
// dispatch process completed event
if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.PROCESS_COMPLETED, execution));
}
parentScopeExecution.performOperation(PROCESS_END);
}
} else {
parentScopeExecution.setActivity(parentActivity);
parentScopeExecution.performOperation(ACTIVITY_END);
}
}
} else {
// execution.isConcurrent() && !execution.isScope()
execution.remove();
// prune if necessary
InterpretableExecution concurrentRoot = (InterpretableExecution) execution.getParent();
if (concurrentRoot.getExecutions().size() == 1) {
InterpretableExecution lastConcurrent = (InterpretableExecution) concurrentRoot.getExecutions().get(0);
if (!lastConcurrent.isScope()) {
concurrentRoot.setActivity((ActivityImpl) lastConcurrent.getActivity());
lastConcurrent.setReplacedBy(concurrentRoot);
// Move children of lastConcurrent one level up
if (!lastConcurrent.getExecutions().isEmpty()) {
concurrentRoot.getExecutions().clear();
for (ActivityExecution childExecution : lastConcurrent.getExecutions()) {
InterpretableExecution childInterpretableExecution = (InterpretableExecution) childExecution;
// casting ... damn generics
((List) concurrentRoot.getExecutions()).add(childExecution);
childInterpretableExecution.setParent(concurrentRoot);
}
lastConcurrent.getExecutions().clear();
}
// Copy execution-local variables of lastConcurrent
concurrentRoot.setVariablesLocal(lastConcurrent.getVariablesLocal());
// Make sure parent execution is re-activated when the last concurrent child execution is active
if (!concurrentRoot.isActive() && lastConcurrent.isActive()) {
concurrentRoot.setActive(true);
}
lastConcurrent.remove();
} else {
lastConcurrent.setConcurrent(false);
}
}
}
}
use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class AtomicOperationActivityExecute method execute.
public void execute(InterpretableExecution execution) {
ActivityImpl activity = (ActivityImpl) execution.getActivity();
ActivityBehavior activityBehavior = activity.getActivityBehavior();
if (activityBehavior == null) {
throw new PvmException("no behavior specified in " + activity);
}
log.debug("{} executes {}: {}", execution, activity, activityBehavior.getClass().getName());
try {
if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_STARTED, execution.getActivity().getId(), (String) execution.getActivity().getProperty("name"), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), (String) activity.getProperties().get("type"), activity.getActivityBehavior().getClass().getCanonicalName()));
}
activityBehavior.execute(execution);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
LogMDC.putMDCExecution(execution);
throw new PvmException("couldn't execute activity <" + activity.getProperty("type") + " id=\"" + activity.getId() + "\" ...>: " + e.getMessage(), e);
}
}
use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class AtomicOperationProcessStartInitial method eventNotificationsCompleted.
@Override
protected void eventNotificationsCompleted(InterpretableExecution execution) {
ActivityImpl activity = (ActivityImpl) execution.getActivity();
ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
StartingExecution startingExecution = execution.getStartingExecution();
if (activity == startingExecution.getInitial()) {
execution.disposeStartingExecution();
execution.performOperation(ACTIVITY_EXECUTE);
} else {
List<ActivityImpl> initialActivityStack = processDefinition.getInitialActivityStack(startingExecution.getInitial());
int index = initialActivityStack.indexOf(activity);
activity = initialActivityStack.get(index + 1);
InterpretableExecution executionToUse = null;
if (activity.isScope()) {
executionToUse = (InterpretableExecution) execution.getExecutions().get(0);
} else {
executionToUse = execution;
}
executionToUse.setActivity(activity);
executionToUse.performOperation(PROCESS_START_INITIAL);
}
}
use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.
the class AtomicOperationTransitionDestroyScope method execute.
@SuppressWarnings("unchecked")
public void execute(InterpretableExecution execution) {
InterpretableExecution propagatingExecution = null;
ActivityImpl activity = (ActivityImpl) execution.getActivity();
// if this transition is crossing a scope boundary
if (activity.isScope()) {
InterpretableExecution parentScopeInstance = null;
// if this is a concurrent execution crossing a scope boundary
if (execution.isConcurrent() && !execution.isScope()) {
// first remove the execution from the current root
InterpretableExecution concurrentRoot = (InterpretableExecution) execution.getParent();
parentScopeInstance = (InterpretableExecution) execution.getParent().getParent();
log.debug("moving concurrent {} one scope up under {}", execution, parentScopeInstance);
List<InterpretableExecution> parentScopeInstanceExecutions = (List<InterpretableExecution>) parentScopeInstance.getExecutions();
List<InterpretableExecution> concurrentRootExecutions = (List<InterpretableExecution>) concurrentRoot.getExecutions();
// if the parent scope had only one single scope child
if (parentScopeInstanceExecutions.size() == 1) {
// it now becomes a concurrent execution
parentScopeInstanceExecutions.get(0).setConcurrent(true);
}
concurrentRootExecutions.remove(execution);
parentScopeInstanceExecutions.add(execution);
execution.setParent(parentScopeInstance);
execution.setActivity(activity);
propagatingExecution = execution;
// the concurrent root.
if (concurrentRootExecutions.size() == 1) {
InterpretableExecution lastConcurrent = concurrentRootExecutions.get(0);
if (lastConcurrent.isScope()) {
lastConcurrent.setConcurrent(false);
} else {
log.debug("merging last concurrent {} into concurrent root {}", lastConcurrent, concurrentRoot);
// We can't just merge the data of the lastConcurrent into the concurrentRoot.
// This is because the concurrent root might be in a takeAll-loop. So the
// concurrent execution is the one that will be receiving the take
concurrentRoot.setActivity((ActivityImpl) lastConcurrent.getActivity());
concurrentRoot.setActive(lastConcurrent.isActive());
lastConcurrent.setReplacedBy(concurrentRoot);
lastConcurrent.remove();
}
}
} else if (execution.isConcurrent() && execution.isScope()) {
log.debug("scoped concurrent {} becomes concurrent and remains under {}", execution, execution.getParent());
// TODO!
execution.destroy();
propagatingExecution = execution;
} else {
propagatingExecution = (InterpretableExecution) execution.getParent();
propagatingExecution.setActivity((ActivityImpl) execution.getActivity());
propagatingExecution.setTransition(execution.getTransition());
propagatingExecution.setActive(true);
log.debug("destroy scope: scoped {} continues as parent scope {}", execution, propagatingExecution);
execution.destroy();
execution.remove();
}
} else {
propagatingExecution = execution;
}
// if there is another scope element that is ended
ScopeImpl nextOuterScopeElement = activity.getParent();
TransitionImpl transition = propagatingExecution.getTransition();
ActivityImpl destination = transition.getDestination();
if (transitionLeavesNextOuterScope(nextOuterScopeElement, destination)) {
propagatingExecution.setActivity((ActivityImpl) nextOuterScopeElement);
propagatingExecution.performOperation(TRANSITION_NOTIFY_LISTENER_END);
} else {
propagatingExecution.performOperation(TRANSITION_NOTIFY_LISTENER_TAKE);
}
}
Aggregations