/**
  * @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);
   }
 }
 /**
  * Add descriptor policy
  *
  * @param options
  * @param query
  */
 public static void addDescriptorPolicy(Options options, Query query) {
   if (options.allDescriptorsVisible) {
     query.setPolicy(DescriptorPolicy.WITH_DESCRIPTORS);
   } else if (CollectionUtils.isNotEmpty(options.visibleDescriptorColumns)) {
     query.setPolicy(
         DescriptorPolicy.withIds(new HashSet<String>(options.visibleDescriptorColumns)));
   } else {
     query.setPolicy(DescriptorPolicy.NO_DESCRIPTORS);
   }
 }
  /**
   * @param queryResult
   * @return
   */
  public static QueryResultDTO buildTableResult(
      QueryResult<?> queryResult,
      MODE mode,
      Map<String, TrivialManualActivityDTO> trivialManualActivityDetails,
      List<String> extraColumns) {
    List<ActivityInstanceDTO> list = new ArrayList<ActivityInstanceDTO>();
    List<CriticalityCategory> criticalityConfigurations =
        CriticalityUtils.getCriticalityConfiguration();

    ModelCache modelCache = ModelCache.findModelCache();
    QueryResultDTO resultDTO = new QueryResultDTO();
    if (null != queryResult) {
      for (Object object : queryResult) {
        if (object instanceof ActivityInstance) {
          ActivityInstance ai = (ActivityInstance) object;
          ActivityInstanceDTO dto;

          if (ActivityInstanceUtils.isTrivialManualActivity(ai)) {
            TrivialActivityInstanceDTO trivialDto =
                DTOBuilder.build(ai, TrivialActivityInstanceDTO.class);
            trivialDto.trivial = true;

            if (null != trivialManualActivityDetails
                && trivialManualActivityDetails.keySet().contains(String.valueOf(ai.getOID()))) {
              TrivialManualActivityDTO tivialManualActivity =
                  trivialManualActivityDetails.get(String.valueOf(ai.getOID()));
              trivialDto.dataMappings = tivialManualActivity.dataMappings;
              trivialDto.inOutData = tivialManualActivity.inOutData;
            }

            dto = trivialDto;
          } else {
            dto = DTOBuilder.build(ai, ActivityInstanceDTO.class);
          }

          dto.auxillary = isAuxiliaryActivity(ai.getActivity());
          dto.duration = ActivityInstanceUtils.getDuration(ai);
          dto.assignedTo = getAssignedToLabel(ai);
          dto.criticality = populateCriticalityDTO(criticalityConfigurations, ai);
          dto.priority = DTOBuilder.build(ai, PriorityDTO.class);
          dto.status = DTOBuilder.build(ai, StatusDTO.class);
          dto.status.label = ActivityInstanceUtils.getActivityStateLabel(ai);
          dto.descriptorValues = getProcessDescriptors(modelCache, ai);
          dto.activatable = findIfActivatable(ai);
          dto.relocationEligible =
              org.eclipse.stardust.ui.web.viewscommon.utils.ActivityInstanceUtils
                  .isRelocationEligible(ai);
          dto.benchmark = getBenchmarkForActivity(ai);

          List<Note> notes =
              org.eclipse.stardust.ui.web.viewscommon.utils.ProcessInstanceUtils.getNotes(
                  ai.getProcessInstance());
          if (null != notes) {
            dto.notesCount = notes.size();
          }

          if (CollectionUtils.isNotEmpty(extraColumns)
              && extraColumns.contains(Constants.RESUBMISSION_TIME)) {
            Date resubmissionDate =
                org.eclipse.stardust.ui.web.viewscommon.utils.ActivityInstanceUtils
                    .getResubmissionDate(ai);
            if (null != resubmissionDate) {
              dto.resubmissionTime = resubmissionDate.getTime();
            }
          }
          ProcessDefinition processDefinition =
              ProcessDefinitionUtils.getProcessDefinition(
                  ai.getModelOID(), ai.getProcessDefinitionId());
          dto.processInstance.supportsProcessAttachments =
              ProcessDefinitionUtils.supportsProcessAttachments(processDefinition);

          if (mode.equals(MODE.ACTIVITY_TABLE)) {
            dto.completedBy = ActivityInstanceUtils.getPerformedByName(ai);
            dto.participantPerformer = getParticipantPerformer(ai);
            dto.abortActivity = !dto.isCaseInstance && isAbortable(ai);
            dto.delegable = isDelegable(ai);
            dto.abortProcess = ProcessInstanceUtils.isAbortable(ai.getProcessInstance());

          } else {
            dto.lastPerformer = getLastPerformer(ai, UserUtils.getDefaultUserNameDisplayFormat());
            if (!dto.defaultCaseActivity) {
              dto.abortActivity = isAbortable(ai);
              dto.delegable = isDelegable(ai);
            }
          }
          dto.defaultCaseActivity = ActivityInstanceUtils.isDefaultCaseActivity(ai);
          dto.isCaseInstance = ai.getProcessInstance().isCaseProcessInstance();
          if (dto.defaultCaseActivity) {
            dto.activity.name = getCaseName(ai);
          }
          list.add(dto);
        }
      }
      resultDTO.totalCount = queryResult.getTotalCount();
    }
    resultDTO.list = list;
    return resultDTO;
  }