@Override
 public void update() {
   HashMap<String, ProcessFilter> filters = new HashMap<String, ProcessFilter>();
   Models models = client.getModels();
   models.update();
   Iterator<DeployedModelDescription> iterator = models.iterator();
   while (iterator.hasNext()) {
     Model model = models.getModel(iterator.next().getModelOID());
     @SuppressWarnings("unchecked")
     List<ProcessDefinition> definitions = model.getAllProcessDefinitions();
     for (ProcessDefinition processDefinition : definitions) {
       @SuppressWarnings("unchecked")
       List<Activity> activities = processDefinition.getAllActivities();
       for (Activity activity : activities) {
         if (activity.isInteractive()) {
           String id = processDefinition.getId();
           ProcessFilter filter = filters.get(id);
           if (filter == null) {
             filter = new ProcessFilter(client, id);
             filters.put(id, filter);
           }
           filter.add(processDefinition);
           break;
         }
       }
     }
   }
   items = filters.values().toArray(new ProcessFilter[filters.size()]);
   observers.notifyObservers(StatusEvent.updated(this));
 }
  /**
   * @param model
   * @param modelDto
   * @param adminRoleAdded
   * @return
   */
  private ArrayList<ParticipantDTO> updateTopLevelRoles(Model model) {
    List<Role> topLevelRoles = null;
    topLevelRoles = model.getAllTopLevelRoles();
    ArrayList<ParticipantDTO> allTopLevelRoles = new ArrayList<ParticipantDTO>();

    for (Role role : topLevelRoles) {
      // We the "Administrator" role that belong to Predefined model
      if (PredefinedConstants.ADMINISTRATOR_ROLE.equals(role.getId())) {
        if (PredefinedConstants.PREDEFINED_MODEL_ID.equals(model.getId())) {
          ParticipantDTO participantDTO = new ParticipantDTO(role);
          participantDTO.type = ParticipantManagementUtils.getParticipantType(role).name();
          allTopLevelRoles.add(participantDTO);
        }
        continue;
      }

      String modelId = ModelUtils.extractModelId(role.getQualifiedId());

      if ((modelId == null) || (modelId.equals(model.getId()))) {
        ParticipantDTO participantDTO = new ParticipantDTO(role);
        participantDTO.type = ParticipantManagementUtils.getParticipantType(role).name();
        allTopLevelRoles.add(participantDTO);
      }
    }
    return allTopLevelRoles;
  }
  /**
   * @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;
  }
  /**
   * @param model
   * @param modelDto
   * @return
   */
  private List<ParticipantDTO> updateTopLevelOrganizations(Model model) {
    List<Organization> topLevelOrganizations = null;

    topLevelOrganizations = model.getAllTopLevelOrganizations();
    List<ParticipantDTO> allTopLevelOrganizations = new ArrayList<ParticipantDTO>();

    for (Organization organization : topLevelOrganizations) {
      String modelId = ModelUtils.extractModelId(organization.getQualifiedId());
      if (modelId.equals(model.getId())) {
        ParticipantDTO participantDTO = new ParticipantDTO(organization);
        participantDTO.type = ParticipantManagementUtils.getParticipantType(organization).name();
        allTopLevelOrganizations.add(participantDTO);
      }
    }

    return allTopLevelOrganizations;
  }
  private void addDepartmentData(Department department) {
    Map<String, Object> map = null;
    if (department != null) {
      map = CollectionUtils.newMap();
      Department department1 = department;
      do {
        if (department1 == null) {
          break;
        }
        Organization organization = department1.getOrganization();
        if (organization != null) {
          String s = (String) organization.getAttribute("carnot:engine:dataId");
          if (s != null) {
            ModelCache modelCache = ModelCache.findModelCache();
            Model model = modelCache.getModel(organization.getModelOID());

            Data data = model.getData(s);
            String s1 = data.getTypeId();
            if ("primitive".equals(s1)) {
              map.put(s, department1.getId());
            } else if ("struct".equals(s1)) {
              Object obj = map.get(s);
              if (!(obj instanceof Map)) {
                obj = CollectionUtils.newMap();
                map.put(s, obj);
              }
              Map map1 = (Map) obj;
              String s2 = (String) organization.getAttribute("carnot:engine:dataPath");
              if (StringUtils.isEmpty(s2)) {
                map.put(s, department1.getId());
              } else {
                do {
                  int i;
                  if (0 >= (i = s2.indexOf('/'))) {
                    break;
                  }
                  String s3 = s2.substring(0, i).trim();
                  s2 = s2.substring(i + 1);
                  if (s3.length() > 0) {
                    Map map2 = (Map) map1.get(s3);
                    if (map2 == null) {
                      map2 = CollectionUtils.newMap();
                      map1.put(s3, map2);
                    }
                    map1 = map2;
                  }
                } while (true);
                s2 = s2.trim();
                if (s2.length() > 0) {
                  map1.put(s2, department1.getId());
                }
              }
            } else {
              throw new PublicException(
                  (new StringBuilder())
                      .append("Unsupported data type in manual triggers: ")
                      .append(s1)
                      .toString());
            }
            department1 = department1.getParentDepartment();
          }
        }
      } while (true);
    }

    ActivityInstance nextActivityInstance =
        PPUtils.activateNextActivityInstance(
            PPUtils.startProcess(getProcessDefinition(), map, true));

    if (nextActivityInstance != null) {
      ActivityInstanceUtils.openActivity(nextActivityInstance);
    } else {
      MessageDialog.addInfoMessage(
          MessagePropertiesBean.getInstance()
              .getParamString("common.processStarted.message", new String[] {getName()}));
    }
  }