/**
   * @param activityOid
   * @param targetActivityOid
   */
  public ActivityInstanceDTO relocateActivity(long activityOid, String activityId) {
    // TODO - not performant - check if this step can be avoided.
    List<TransitionTarget> targets =
        serviceFactoryUtils
            .getWorkflowService()
            .getAdHocTransitionTargets(
                activityOid, TransitionOptions.DEFAULT, ScanDirection.BACKWARD);
    List<ActivityInstanceDTO> list = new ArrayList<ActivityInstanceDTO>();
    if (null != targets) {
      for (TransitionTarget target : targets) {
        if (target.getActivityId().equals(activityId)) {
          ActivityInstance activityInstance =
              activityInstanceUtils.getActivityInstance(target.getActivityInstanceOid());
          if (org.eclipse.stardust.ui.web.viewscommon.utils.ActivityInstanceUtils
              .isRelocationEligible(activityInstance)) {
            if (activityInstance.getActivity().isInteractive()
                && activityInstance.getState().equals(ActivityInstanceState.Suspended)) {
              serviceFactoryUtils.getWorkflowService().activate(target.getActivityInstanceOid());
            }
          }
          TransitionReport report =
              serviceFactoryUtils.getWorkflowService().performAdHocTransition(target, false);
          return DTOBuilder.build(report.getTargetActivityInstance(), ActivityInstanceDTO.class);
        }
      }
    }

    return null;
  }
  public static void performTransition(
      ActivityInstanceBean activityInstance, TransitionTarget transitionTarget, boolean complete) {
    ExecutionPlan plan = new ExecutionPlan(transitionTarget);
    plan.assertNoOtherActiveActivities();

    ModelManager mm = ModelManagerFactory.getCurrent();
    IActivity target =
        mm.findActivity(transitionTarget.getModelOid(), transitionTarget.getActivityRuntimeOid());
    if (target == null) {
      throw new ObjectNotFoundException(
          BpmRuntimeError.MDL_UNKNOWN_ACTIVITY_IN_MODEL.raise(
              transitionTarget.getActivityRuntimeOid(), transitionTarget.getModelOid()));
    }

    BpmRuntimeEnvironment rtEnv = PropertyLayerProviderInterceptor.getCurrent();
    ExecutionPlan oldPlan = rtEnv.getExecutionPlan();
    try {
      rtEnv.setExecutionPlan(plan);
      if (complete) {
        ActivityInstanceUtils.complete(activityInstance, null, null, true);
      } else {
        long rootOid = plan.getRootActivityInstanceOid();
        if (rootOid != activityInstance.getOID()) {
          activityInstance = ActivityInstanceUtils.lock(rootOid);
        }
        ActivityInstanceUtils.abortActivityInstance(activityInstance);
      }
    } finally {
      rtEnv.setExecutionPlan(oldPlan);
    }
  }
  /**
   * @param oid
   * @return
   */
  public List<ActivityInstanceDTO> getAllRelocationTargets(long oid) {
    List<TransitionTarget> targets =
        serviceFactoryUtils
            .getWorkflowService()
            .getAdHocTransitionTargets(oid, TransitionOptions.DEFAULT, ScanDirection.BACKWARD);
    List<ActivityInstanceDTO> list = new ArrayList<ActivityInstanceDTO>();
    if (null != targets) {
      for (TransitionTarget target : targets) {
        // TODO - needs a new transition target DTO?
        ActivityInstanceDTO dto = new ActivityInstanceDTO();
        dto.activity = new ActivityDTO();
        dto.activity.name = target.getActivityName();
        dto.activity.id = target.getActivityId();
        list.add(dto);
      }
    }

    return list;
  }