Java Code Examples for org.activiti.engine.impl.persistence.entity.ExecutionEntity#getParentId()

The following examples show how to use org.activiti.engine.impl.persistence.entity.ExecutionEntity#getParentId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutionTreeUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static ExecutionTree buildExecutionTree(DelegateExecution executionEntity) {
  
  // Find highest parent
  ExecutionEntity parentExecution = (ExecutionEntity) executionEntity;
  while (parentExecution.getParentId() != null || parentExecution.getSuperExecutionId() != null) {
    if (parentExecution.getParentId() != null) {
      parentExecution = parentExecution.getParent();
    } else {
      parentExecution = parentExecution.getSuperExecution();
    }
  }
  
  // Collect all child executions now we have the parent
  List<ExecutionEntity> allExecutions = new ArrayList<ExecutionEntity>();
  allExecutions.add(parentExecution);
  collectChildExecutions(parentExecution, allExecutions);
  return buildExecutionTree(allExecutions);
}
 
Example 2
Source File: ExecutionTreeUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static ExecutionTree buildExecutionTree(Collection<ExecutionEntity> executions) {
  ExecutionTree executionTree = new ExecutionTree();

  // Map the executions to their parents. Catch and store the root element (process instance execution) while were at it
  Map<String, List<ExecutionEntity>> parentMapping = new HashMap<String, List<ExecutionEntity>>();
  for (ExecutionEntity executionEntity : executions) {
    String parentId = executionEntity.getParentId();
    
    // Support for call activity
    if (parentId == null) {
      parentId = executionEntity.getSuperExecutionId();
    }
    
    if (parentId != null) {
      if (!parentMapping.containsKey(parentId)) {
        parentMapping.put(parentId, new ArrayList<ExecutionEntity>());
      }
      parentMapping.get(parentId).add(executionEntity);
    } else if (executionEntity.getSuperExecutionId() == null){
      executionTree.setRoot(new ExecutionTreeNode(executionEntity));
    }
  }
  
  fillExecutionTree(executionTree, parentMapping);
  return executionTree;
}
 
Example 3
Source File: ExecutionTreeUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static ExecutionTree buildExecutionTreeForProcessInstance(Collection<ExecutionEntity> executions) {
  ExecutionTree executionTree = new ExecutionTree();
  if (executions.size() == 0) {
    return executionTree;
  }

  // Map the executions to their parents. Catch and store the root element (process instance execution) while were at it
  Map<String, List<ExecutionEntity>> parentMapping = new HashMap<String, List<ExecutionEntity>>();
  for (ExecutionEntity executionEntity : executions) {
    String parentId = executionEntity.getParentId();
    
    if (parentId != null) {
      if (!parentMapping.containsKey(parentId)) {
        parentMapping.put(parentId, new ArrayList<ExecutionEntity>());
      }
      parentMapping.get(parentId).add(executionEntity);
    } else {
      executionTree.setRoot(new ExecutionTreeNode(executionEntity));
    }
  }
  
  fillExecutionTree(executionTree, parentMapping);
  return executionTree;
}
 
Example 4
Source File: TakeOutgoingSequenceFlowsOperation.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * @param executionEntityToIgnore The execution entity which we can ignore to be ended,
 * as it's the execution currently being handled in this operation.
 */
protected ExecutionEntity findNextParentScopeExecutionWithAllEndedChildExecutions(ExecutionEntity executionEntity, ExecutionEntity executionEntityToIgnore) {
  if (executionEntity.getParentId() != null) {
    ExecutionEntity scopeExecutionEntity = executionEntity.getParent();

    // Find next scope
    while (!scopeExecutionEntity.isScope() || !scopeExecutionEntity.isProcessInstanceType()) {
      scopeExecutionEntity = scopeExecutionEntity.getParent();
    }

    // Return when all child executions for it are ended
    if (allChildExecutionsEnded(scopeExecutionEntity, executionEntityToIgnore)) {
      return scopeExecutionEntity;
    }

  }
  return null;
}
 
Example 5
Source File: GatewayActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void lockFirstParentScope(DelegateExecution execution) {
  
  ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
  
  boolean found = false;
  ExecutionEntity parentScopeExecution = null;
  ExecutionEntity currentExecution = (ExecutionEntity) execution;
  while (!found && currentExecution != null && currentExecution.getParentId() != null) {
    parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId());
    if (parentScopeExecution != null && parentScopeExecution.isScope()) {
      found = true;
    }
    currentExecution = parentScopeExecution;
  }
  
  parentScopeExecution.forceUpdate();
}
 
Example 6
Source File: ParallelMultiInstanceBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void lockFirstParentScope(DelegateExecution execution) {

    ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();

    boolean found = false;
    ExecutionEntity parentScopeExecution = null;
    ExecutionEntity currentExecution = (ExecutionEntity) execution;
    while (!found && currentExecution != null && currentExecution.getParentId() != null) {
      parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId());
      if (parentScopeExecution != null && parentScopeExecution.isScope()) {
        found = true;
      }
      currentExecution = parentScopeExecution;
    }

    parentScopeExecution.forceUpdate();
  }
 
Example 7
Source File: ExecutionsByProcessInstanceIdEntityMatcher.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
  // parameter = process instance execution id
    return entity.getProcessInstanceId() != null 
        && entity.getProcessInstanceId().equals((String) parameter) 
        && entity.getParentId() != null;
}
 
Example 8
Source File: ExecutionsByParentExecutionIdAndActivityIdEntityMatcher.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity executionEntity, Object parameter) {
  Map<String, Object> paramMap = (Map<String, Object>) parameter;
  String parentExecutionId = (String) paramMap.get("parentExecutionId");
  Collection<String> activityIds = (Collection<String>) paramMap.get("activityIds");
  
  return executionEntity.getParentId() != null && executionEntity.getParentId().equals(parentExecutionId)
      && executionEntity.getActivityId() != null && activityIds.contains(executionEntity.getActivityId());
}
 
Example 9
Source File: ProcessExecutionLogger.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected List<DebugInfoExecutionTree> generateExecutionTrees() {

    // Gather information
    List<ExecutionEntity> processInstances = new ArrayList<ExecutionEntity>();
    Map<String, List<ExecutionEntity>> parentMapping = new HashMap<String, List<ExecutionEntity>>();

    for (ExecutionEntity executionEntity : createdExecutions.values()) {
      if (!deletedExecutions.containsKey(executionEntity.getId())) {
        if (executionEntity.getParentId() == null) {
          processInstances.add(executionEntity);
        } else {
          if (!parentMapping.containsKey(executionEntity.getParentId())) {
            parentMapping.put(executionEntity.getParentId(), new ArrayList<ExecutionEntity>());
          }
          parentMapping.get(executionEntity.getParentId()).add(executionEntity);
        }
      }
    }

    // Build tree representation
    List<DebugInfoExecutionTree> executionTrees = new ArrayList<DebugInfoExecutionTree>();
    for (ExecutionEntity processInstance : processInstances) {

      DebugInfoExecutionTree executionTree = new DebugInfoExecutionTree();
      executionTrees.add(executionTree);

      DebugInfoExecutionTreeNode rootNode = new DebugInfoExecutionTreeNode();
      executionTree.setProcessInstance(rootNode);
      rootNode.setId(processInstance.getId());

      internalPopulateExecutionTree(rootNode, parentMapping);
    }

    return executionTrees;
  }
 
Example 10
Source File: TerminateEndEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected ActivityExecution findRootProcessInstanceExecution(ExecutionEntity execution) {
    ExecutionEntity currentExecution = execution;
    while (currentExecution.getParentId() != null || currentExecution.getSuperExecutionId() != null) {
        ExecutionEntity parentExecution = currentExecution.getParent();
        if (parentExecution != null) {
            currentExecution = parentExecution;
        } else if (currentExecution.getSuperExecutionId() != null) {
            currentExecution = currentExecution.getSuperExecution();
        }
    }
    return currentExecution;
}
 
Example 11
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected HistoricActivityInstanceEntity findActivityInstance(ExecutionEntity execution, String activityId, boolean checkPersistentStore) {

        String executionId = execution.getId();

        // search for the historic activity instance in the dbsqlsession cache
        List<HistoricActivityInstanceEntity> cachedHistoricActivityInstances = getDbSqlSession()
                .findInCache(HistoricActivityInstanceEntity.class);
        for (HistoricActivityInstanceEntity cachedHistoricActivityInstance : cachedHistoricActivityInstances) {
            if (executionId.equals(cachedHistoricActivityInstance.getExecutionId())
                    && activityId != null
                    && (activityId.equals(cachedHistoricActivityInstance.getActivityId()))
                    && (cachedHistoricActivityInstance.getEndTime() == null)) {
                return cachedHistoricActivityInstance;
            }
        }

        List<HistoricActivityInstance> historicActivityInstances = null;
        if (checkPersistentStore) {
            historicActivityInstances = new HistoricActivityInstanceQueryImpl(Context.getCommandContext())
                    .executionId(executionId)
                    .activityId(activityId)
                    .unfinished()
                    .listPage(0, 1);
        }

        if (historicActivityInstances != null && !historicActivityInstances.isEmpty()) {
            return (HistoricActivityInstanceEntity) historicActivityInstances.get(0);
        }

        if (execution.getParentId() != null) {
            return findActivityInstance(execution.getParent(), activityId, checkPersistentStore);
        }

        return null;
    }
 
Example 12
Source File: ProcessInstancesByProcessDefinitionMatcher.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
  return entity.getParentId() == null && entity.getProcessDefinitionId() != null && entity.getProcessDefinitionId().equals(parameter);
}
 
Example 13
Source File: ExecutionsByParentExecutionIdEntityMatcher.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRetained(ExecutionEntity entity, Object parameter) {
  // parameter = parent execution id
  return entity.getParentId() != null && entity.getParentId().equals((String) parameter);
}
 
Example 14
Source File: ErrorPropagation.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected static void executeCatch(Map<String, List<Event>> eventMap, DelegateExecution delegateExecution, String errorId) {
  Event matchingEvent = null;
  ExecutionEntity currentExecution = (ExecutionEntity) delegateExecution;
  ExecutionEntity parentExecution = null;

  if (eventMap.containsKey(currentExecution.getActivityId())) {
    matchingEvent = eventMap.get(currentExecution.getActivityId()).get(0);

    // Check for multi instance
    if (currentExecution.getParentId() != null && currentExecution.getParent().isMultiInstanceRoot()) {
      parentExecution = currentExecution.getParent();
    } else {
      parentExecution = currentExecution;
    }

  } else {
    parentExecution = currentExecution.getParent();

    // Traverse parents until one is found that is a scope and matches the activity the boundary event is defined on
    while (matchingEvent == null && parentExecution != null) {
      FlowElementsContainer currentContainer = null;
      if (parentExecution.getCurrentFlowElement() instanceof FlowElementsContainer) {
        currentContainer = (FlowElementsContainer) parentExecution.getCurrentFlowElement();
      } else if (parentExecution.getId().equals(parentExecution.getProcessInstanceId())) {
        currentContainer = ProcessDefinitionUtil.getProcess(parentExecution.getProcessDefinitionId());
      }

      for (String refId : eventMap.keySet()) {
        List<Event> events = eventMap.get(refId);
        if (CollectionUtil.isNotEmpty(events) && events.get(0) instanceof StartEvent) {
          if (currentContainer.getFlowElement(refId) != null) {
            matchingEvent = events.get(0);
          }
        }
      }

      if (matchingEvent == null) {
        if (eventMap.containsKey(parentExecution.getActivityId())) {
          matchingEvent = eventMap.get(parentExecution.getActivityId()).get(0);

          // Check for multi instance
          if (parentExecution.getParentId() != null && parentExecution.getParent().isMultiInstanceRoot()) {
            parentExecution = parentExecution.getParent();
          }

        } else if (StringUtils.isNotEmpty(parentExecution.getParentId())) {
          parentExecution = parentExecution.getParent();
        } else {
          parentExecution = null;
        }
      }
    }
  }

  if (matchingEvent != null && parentExecution != null) {
    executeEventHandler(matchingEvent, parentExecution, currentExecution, errorId);
  } else {
    throw new ActivitiException("No matching parent execution for error code " + errorId + " found");
  }
}
 
Example 15
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public HistoricActivityInstanceEntity findActivityInstance(ExecutionEntity execution, String activityId, boolean createOnNotFound, boolean endTimeMustBeNull) {
  
  // No use looking for the HistoricActivityInstance when no activityId is provided.
  if (activityId == null) {
    return null;
  }
  
  String executionId = execution.getId();

  // Check the cache
  HistoricActivityInstanceEntity historicActivityInstanceEntityFromCache = 
      getHistoricActivityInstanceFromCache(executionId, activityId, endTimeMustBeNull);
  if (historicActivityInstanceEntityFromCache != null) {
    return historicActivityInstanceEntityFromCache;
  }
  
  // If the execution was freshly created, there is no need to check the database, 
  // there can never be an entry for a historic activity instance with this execution id.
  if (!execution.isInserted() && !execution.isProcessInstanceType()) {

    // Check the database
    List<HistoricActivityInstanceEntity> historicActivityInstances = getHistoricActivityInstanceEntityManager()
        .findUnfinishedHistoricActivityInstancesByExecutionAndActivityId(executionId, activityId); 

    if (historicActivityInstances.size() > 0) {
      return historicActivityInstances.get(0);
    }
    
  }
  
  if (execution.getParentId() != null) {
    HistoricActivityInstanceEntity historicActivityInstanceFromParent 
      = findActivityInstance((ExecutionEntity) execution.getParent(), activityId, false, endTimeMustBeNull); // always false for create, we only check if it can be found
    if (historicActivityInstanceFromParent != null) {
      return historicActivityInstanceFromParent;
    }
  }
  
  if (createOnNotFound 
      && activityId != null
      && ( (execution.getCurrentFlowElement() != null && execution.getCurrentFlowElement() instanceof FlowNode) || execution.getCurrentFlowElement() == null)) {
    return createHistoricActivityInstanceEntity(execution);
  }

  return null;
}