protected List<PlanItem> gatherEventListenerDependencies(PlanItem planItem) { List<PlanItem> eventListenerDependencies = Stream.concat( planItem.getEntryDependencies().stream().filter(p -> p.getPlanItemDefinition() instanceof EventListener), planItem.getExitDependencies().stream().filter(p -> p.getPlanItemDefinition() instanceof EventListener)) .collect(Collectors.toList()); // Special case: if the current plan item is a stage, we need to also verify all event listeners // that reference a child plan item of this stage. Normally this will happen automatically, unless // the child plan item instances haven't been created yet (e.g with nested stages). // As such, we need to check all plan items for which there hasn't been a plan item instance yet. if (planItem.getPlanItemDefinition() instanceof PlanFragment && PlanItemInstanceState.isInTerminalState(planItemInstanceEntity)) { // This is only true when stopping, not when a plan item gets activated (in that case, the child plan items can still be created and no special care is needed) List<PlanItem> childPlanItemsWithDependencies = getChildPlanItemsWithDependencies((PlanFragment) planItem.getPlanItemDefinition()); CaseInstanceEntity caseInstanceEntity = CommandContextUtil .getCaseInstanceEntityManager(commandContext).findById(planItemInstanceEntity.getCaseInstanceId()); Map<String, List<PlanItemInstanceEntity>> childPlanItemInstancesMap = CaseInstanceUtil .findChildPlanItemInstancesMap(caseInstanceEntity, childPlanItemsWithDependencies); for (PlanItem childPlanItemWithDependencies : childPlanItemsWithDependencies) { if (!childPlanItemInstancesMap.containsKey(childPlanItemWithDependencies.getId())) { eventListenerDependencies.addAll(childPlanItemWithDependencies.getEntryDependencies().stream() .filter(p -> p.getPlanItemDefinition() instanceof EventListener).collect(Collectors.toList())); eventListenerDependencies.addAll(childPlanItemWithDependencies.getExitDependencies().stream() .filter(p -> p.getPlanItemDefinition() instanceof EventListener).collect(Collectors.toList())); } } } return eventListenerDependencies; }
.findChildPlanItemInstancesMap(caseInstanceEntity, dependentPlanItems);
.findChildPlanItemInstancesMap(caseInstanceEntity, parentPlanItems); List<PlanItemInstanceEntity> parentPlanItemInstancesToActivate = new ArrayList<>();