/**
  * @param activityOID
  * @return
  */
 public NotificationMap reactivate(Long activityOID) {
   NotificationMap notification = new NotificationMap();
   ActivityInstance ai = null;
   try {
     ai = serviceFactoryUtils.getWorkflowService().activate(activityOID);
     serviceFactoryUtils
         .getWorkflowService()
         .unbindActivityEventHandler(activityOID, "Resubmission");
     notification.addSuccess(new NotificationDTO(activityOID, ai.getActivity().getName(), null));
   } catch (ConcurrencyException ce) {
     trace.error("Unable to activate Activity, activity not in worklist", ce);
     String msg = restCommonClientMessages.getString("activity.concurrencyError");
     notification.addFailure(
         new NotificationDTO(activityOID, activityInstanceUtils.getActivityLabel(ai), msg));
   } catch (AccessForbiddenException af) {
     trace.error("User not authorized to activate", af);
     String msg = restCommonClientMessages.getString("activity.acccessForbiddenError");
     notification.addFailure(
         new NotificationDTO(activityOID, activityInstanceUtils.getActivityLabel(ai), msg));
   } catch (Exception exception) {
     trace.error("Exception occurred while reactivating activity", exception);
     notification.addFailure(new NotificationDTO(activityOID, null, exception.getMessage()));
   }
   return notification;
 }
  /**
   * @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;
  }
  /**
   * @param oid
   * @param documentId
   * @return
   */
  public List<ProcessInstanceDTO> completeRendezvous(long oid, String documentId) {
    ActivityInstance completedAi = activityInstanceUtils.completeRendezvous(oid, documentId);

    // TODO: Change method return type
    // return completedAi;

    return null;
  }
  /**
   * @param activityInstanceOid
   * @return
   */
  public List<DocumentDTO> getProcessAttachmentsForActivityInstance(long activityInstanceOid) {
    List<Document> processAttachments =
        activityInstanceUtils.getProcessAttachments(activityInstanceOid);

    List<DocumentDTO> processAttachmentsDTO = DocumentDTOBuilder.build(processAttachments);

    return processAttachmentsDTO;
  }
 /**
  * @param userId
  * @return
  */
 public QueryResultDTO getAllInstances(Options options, ActivityInstanceQuery query) {
   QueryResult<?> queryResult = activityInstanceUtils.getActivityInstances(options, query);
   if (CollectionUtils.isNotEmpty(options.extraColumns)) {
     return ActivityTableUtils.buildTableResult(
         queryResult, MODE.ACTIVITY_TABLE, null, options.extraColumns);
   } else {
     return ActivityTableUtils.buildTableResult(queryResult, MODE.ACTIVITY_TABLE);
   }
 }
  /**
   * @author Yogesh.Manware
   * @param request
   * @return
   */
  public String abortActivities(String request) {
    JsonObject json = GsonUtils.readJsonObject(request);
    String scope = GsonUtils.extractString(json, "scope");

    Type listType = new TypeToken<List<Long>>() {}.getType();

    @SuppressWarnings("unchecked")
    List<Long> activities =
        (List<Long>)
            GsonUtils.extractList(GsonUtils.extractJsonArray(json, "activities"), listType);
    NotificationMap notificationMap = new NotificationMap();

    if (AbortScope.SubHierarchy.toString().equalsIgnoreCase(scope)) {
      notificationMap = activityInstanceUtils.abortActivities(AbortScope.SubHierarchy, activities);
    } else if (AbortScope.RootHierarchy.toString().equalsIgnoreCase(scope)) {
      notificationMap = activityInstanceUtils.abortActivities(AbortScope.RootHierarchy, activities);
    } else {
      throw new IllegalArgumentException("Scope not valid : " + scope);
    }
    return GsonUtils.toJsonHTMLSafeString(notificationMap);
  }
 /**
  * @param activityOID
  * @return
  */
 public NotificationMap activate(Long activityOID) {
   NotificationMap notification = new NotificationMap();
   ActivityInstance ai = null;
   try {
     notification = activityInstanceUtils.activate(activityOID);
   } catch (ConcurrencyException ce) {
     trace.error("Unable to activate Activity, activity not in worklist", ce);
     String msg = restCommonClientMessages.getString("activity.concurrencyError");
     notification.addFailure(
         new NotificationDTO(activityOID, activityInstanceUtils.getActivityLabel(ai), msg));
   } catch (AccessForbiddenException af) {
     trace.error("User not authorized to activate", af);
     String msg = restCommonClientMessages.getString("activity.acccessForbiddenError");
     notification.addFailure(
         new NotificationDTO(activityOID, activityInstanceUtils.getActivityLabel(ai), msg));
   } catch (Exception e) {
     trace.error("Exception occurred while activating", e);
     String msg = e.getMessage();
     notification.addFailure(
         new NotificationDTO(activityOID, activityInstanceUtils.getActivityLabel(ai), msg));
   }
   return notification;
 }
  /**
   * @param activities
   * @param context
   * @return
   */
  public String completeAll(List<ActivityInstanceOutDataDTO> activities, String context) {
    NotificationMap notificationMap = new NotificationMap();

    for (ActivityInstanceOutDataDTO aiDto : activities) {
      try {
        activityInstanceUtils.complete(aiDto.oid, context, aiDto.outData);
        notificationMap.addSuccess(
            new NotificationDTO(aiDto.oid, null, ActivityInstanceState.Completed.getName()));
      } catch (Exception e) {
        notificationMap.addFailure(new NotificationDTO(aiDto.oid, null, e.getMessage()));
      }
    }
    return GsonUtils.toJsonHTMLSafeString(notificationMap);
  }
 /** @return */
 public List<ColumnDTO> getParticipantColumns() {
   return activityInstanceUtils.getParticipantColumns();
 }
 public List<SelectItemDTO> getAllRoles() {
   return activityInstanceUtils.getAllRoles();
 }
 /** @return */
 public List<PendingActivitiesStatisticsDTO> getPendingActivities() {
   return activityInstanceUtils.getPendingActivities();
 }
 /**
  * @param oid
  * @return
  */
 public String getAllDataMappingsAsJson(long oid, String context) {
   ActivityInstance ai = activityInstanceUtils.getActivityInstance(oid);
   String json = activityInstanceUtils.getAllDataMappingsAsJson(ai, context);
   return json;
 }
 /**
  * @param userId
  * @return
  */
 public Map<String, TrivialManualActivityDTO> getTrivialManualActivitiesDetails(
     List<Long> oids, String context) {
   Map<String, TrivialManualActivityDTO> dto =
       activityInstanceUtils.getTrivialManualActivitiesDetails(oids, context);
   return dto;
 }
  /**
   * @param oid
   * @return
   */
  public Map<String, Serializable> getAllInDataValues(long oid, String context) {
    ActivityInstance ai = activityInstanceUtils.getActivityInstance(oid);
    Map<String, Serializable> values = activityInstanceUtils.getAllInDataValues(ai, context);

    return values;
  }
 /**
  * @param piOid
  * @return
  */
 public List<ActivityInstanceDTO> getByProcessOid(long piOid) {
   return activityInstanceUtils.getByProcessOid(piOid);
 }
 public ActivityInstance getActivityInstance(Long activityOId) {
   return activityInstanceUtils.getActivityInstance(activityOId);
 }
 /**
  * @param activityInstanceOid
  * @return
  */
 public ActivityInstanceDTO getActivityInstance(long activityInstanceOid) {
   ActivityInstance ai = activityInstanceUtils.getActivityInstance(activityInstanceOid);
   return DTOBuilder.build(ai, ActivityInstanceDTO.class);
 }