/**
   * @param modelCache
   * @param ai
   * @return
   */
  private static Map<String, DescriptorDTO> getProcessDescriptors(
      ModelCache modelCache, ActivityInstance ai) {
    List<ProcessDescriptor> processDescriptorsList = CollectionUtils.newList();

    Model model = modelCache.getModel(ai.getModelOID());
    ProcessDefinition processDefinition =
        (model != null) ? model.getProcessDefinition(ai.getProcessDefinitionId()) : null;
    if (processDefinition != null) {
      ProcessInstanceDetails processInstanceDetails =
          (ProcessInstanceDetails) ai.getProcessInstance();
      Map<String, Object> descriptorValues = processInstanceDetails.getDescriptors();
      CommonDescriptorUtils.updateProcessDocumentDescriptors(
          descriptorValues, ai.getProcessInstance(), processDefinition);
      if (processInstanceDetails.isCaseProcessInstance()) {
        processDescriptorsList =
            CommonDescriptorUtils.createCaseDescriptors(
                processInstanceDetails.getDescriptorDefinitions(),
                descriptorValues,
                processDefinition,
                true);
      } else {
        processDescriptorsList =
            CommonDescriptorUtils.createProcessDescriptors(
                descriptorValues, processDefinition, true, true);
      }

      Map<String, DescriptorDTO> descriptors = new LinkedHashMap<String, DescriptorDTO>();
      for (Object descriptor : processDescriptorsList) {
        if (descriptor instanceof ProcessDocumentDescriptor) {
          ProcessDocumentDescriptor desc = (ProcessDocumentDescriptor) descriptor;

          List<DocumentDTO> documents = new ArrayList<DocumentDTO>();

          for (DocumentInfo documentInfo : desc.getDocuments()) {
            DocumentDTO documentDTO = new DocumentDTO();
            documentDTO.name = documentInfo.getName();
            documentDTO.uuid = documentInfo.getId();
            documentDTO.contentType =
                (MimeTypesHelper.detectMimeType(documentInfo.getName(), null).getType());
            documents.add(documentDTO);
          }

          DescriptorDTO descriptorDto =
              new DescriptorDTO(desc.getKey(), desc.getValue(), true, documents);
          descriptors.put(desc.getId(), descriptorDto);
        } else {
          ProcessDescriptor desc = (ProcessDescriptor) descriptor;
          DescriptorDTO descriptorDto =
              new DescriptorDTO(desc.getKey(), desc.getValue(), false, null);
          descriptors.put(desc.getId(), descriptorDto);
        }
      }
      return descriptors;
    }
    return null;
  }
  private void calculateIconStatus(ProcessProgressInstance instance) {
    if (instance != null && instance.getTerminationTime() != null) {
      this.completeIconStatus = true;
    } else {
      this.completeIconStatus = false;
    }

    this.completeText = "";

    if (instance != null && !instance.getDescriptors().isEmpty()) {
      this.descriptorIconStatus = true;

      List<ProcessDescriptor> processdescList =
          CommonDescriptorUtils.createProcessDescriptors(instance.getProcessInstance(), false);

      StringBuffer buffer = new StringBuffer();
      for (ProcessDescriptor processDescriptors : processdescList) {
        if (StringUtils.isNotEmpty(buffer.toString())) {
          buffer.append(", ");
        }
        buffer
            .append(processDescriptors.getKey())
            .append(" : ")
            .append(processDescriptors.getValue());
      }

      this.descriptorText = buffer.toString();

      if (instance.getNote() != null) {
        this.noteIconStatus = true;
        this.noteText = instance.getNote();
      } else {
        this.noteIconStatus = false;
      }

      if (instance.getError() != null) {
        this.errorIconStatus = true;
        this.errorText = instance.getError();
      } else {
        this.errorIconStatus = false;
      }
    } else {
      this.descriptorIconStatus = false;
      this.noteIconStatus = false;
      this.descriptorIconStatus = false;
    }
  }