/**
   * Get the records count
   *
   * @param directory the {@link Directory}
   * @param user the {@link AdminUser}
   * @return the record count
   */
  public int getRecordsCount(Directory directory, AdminUser user) {
    Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME);
    int nNbRecords = 0;
    boolean bWorkflowServiceEnable = WorkflowService.getInstance().isAvailable();
    RecordFieldFilter filter = new RecordFieldFilter();
    filter.setIdDirectory(directory.getIdDirectory());
    filter.setWorkgroupKeyList(AdminWorkgroupService.getUserWorkgroups(user, user.getLocale()));

    if ((directory.getIdWorkflow() != DirectoryUtils.CONSTANT_ID_NULL)
        && (directory.getIdWorkflow() != DirectoryUtils.CONSTANT_ID_ZERO)
        && bWorkflowServiceEnable) {
      List<Integer> listResultRecordIds =
          DirectorySearchService.getInstance()
              .getSearchResults(directory, null, null, null, null, filter, plugin);
      List<Integer> listTmpResultRecordIds =
          WorkflowService.getInstance()
              .getAuthorizedResourceList(
                  Record.WORKFLOW_RESOURCE_TYPE,
                  directory.getIdWorkflow(),
                  DirectoryUtils.CONSTANT_ID_NULL,
                  Integer.valueOf(directory.getIdDirectory()),
                  user);
      listResultRecordIds =
          DirectoryUtils.retainAllIdsKeepingFirstOrder(listResultRecordIds, listTmpResultRecordIds);
      nNbRecords = listResultRecordIds.size();
    } else {
      IRecordService recordService = SpringContextService.getBean(RecordService.BEAN_SERVICE);
      nNbRecords = recordService.getCountRecord(filter, plugin);
    }

    return nNbRecords;
  }
  @Override
  public String processTicketingTask(
      int nIdResourceHistory, HttpServletRequest request, Locale locale) {
    String strTaskInformation = StringUtils.EMPTY;

    // We get the ticket to modify
    Ticket ticket = getTicket(nIdResourceHistory);
    TicketCategory ticketCategory =
        TicketCategoryHome.findByPrimaryKey(ticket.getIdTicketCategory());
    int nIdWorkflow = ticketCategory.getIdWorkflow();
    State state =
        WorkflowService.getInstance()
            .getState(ticket.getId(), Ticket.TICKET_RESOURCE_TYPE, nIdWorkflow, null);

    IndexerAction indexerAction = new IndexerAction();
    indexerAction.setIdTicket(ticket.getId());

    if ((state == null)
        || (state.getId()
            == AppPropertiesService.getPropertyInt(PROPERTY_WORKFLOW_ACTION_ID_NEW, 301))) {
      indexerAction.setIdTask(IndexerAction.TASK_CREATE);
    } else {
      indexerAction.setIdTask(IndexerAction.TASK_MODIFY);
    }

    IndexerActionHome.create(indexerAction);

    return strTaskInformation;
  }
  /**
   * Get the resource action for a record
   *
   * @param record the record
   * @param directory the directory
   * @param listEntryResultSearch the list of entry
   * @param adminUser the AdminUser
   * @param listActionsForDirectoryEnable The list of actions to use if the record is enabled
   * @param listActionsForDirectoryDisable The list of actions to use if the record is disabled
   * @param bGetFileName True to get file names. <i>Warning :</i> The file name is fetch by a
   *     webservice call. Beware of performance.
   * @param plugin the plugin
   * @return a map of string - object
   */
  public Map<String, Object> getResourceAction(
      Record record,
      Directory directory,
      List<IEntry> listEntryResultSearch,
      AdminUser adminUser,
      List<DirectoryAction> listActionsForDirectoryEnable,
      List<DirectoryAction> listActionsForDirectoryDisable,
      boolean bGetFileName,
      Plugin plugin) {
    if (record.isEnabled()) {
      record.setActions(listActionsForDirectoryEnable);
    } else {
      record.setActions(listActionsForDirectoryDisable);
    }

    // workflow service
    Map<String, Object> resourceActions = new HashMap<String, Object>();
    resourceActions.put(MARK_RECORD, record);
    resourceActions.put(
        MARK_MAP_ID_ENTRY_LIST_RECORD_FIELD,
        DirectoryUtils.getMapIdEntryListRecordField(
            listEntryResultSearch, record.getIdRecord(), plugin, bGetFileName));

    boolean bWorkflowServiceEnable =
        WorkflowService.getInstance().isAvailable()
            && (directory.getIdWorkflow() != DirectoryUtils.CONSTANT_ID_NULL);

    if (bWorkflowServiceEnable) {
      WorkflowService workflowService = WorkflowService.getInstance();
      Collection<Action> lListActions =
          workflowService.getActions(
              record.getIdRecord(),
              Record.WORKFLOW_RESOURCE_TYPE,
              directory.getIdWorkflow(),
              adminUser);
      State state =
          workflowService.getState(
              record.getIdRecord(),
              Record.WORKFLOW_RESOURCE_TYPE,
              directory.getIdWorkflow(),
              Integer.valueOf(directory.getIdDirectory()));
      resourceActions.put(MARK_WORKFLOW_STATE, state);
      resourceActions.put(MARK_WORKFLOW_ACTION_LIST, lListActions);
    }

    return resourceActions;
  }