private Collection<String> getTestResultSortSelection(AuditResultSortCommand asuc) {
   Collection<String> selectedValues = new HashSet<>();
   if ((asuc.getSortOptionMap().get(testResultSortKey)) instanceof Object[]) {
     CollectionUtils.addAll(
         selectedValues, ((Object[]) asuc.getSortOptionMap().get(testResultSortKey)));
   } else if ((asuc.getSortOptionMap().get(testResultSortKey)) instanceof String) {
     selectedValues.add((String) asuc.getSortOptionMap().get(testResultSortKey));
   }
   return selectedValues;
 }
 /**
  * Extract from the audit parameter the referential. Regarding this value, the returned page
  * displays results sorted by tests or criterion
  *
  * @param request
  * @param arsc
  * @return
  */
 private String computeDisplayScope(HttpServletRequest request, AuditResultSortCommand arsc) {
   if (StringUtils.contains(
       request.getHeader(TgolKeyStore.REFERER_HEADER_KEY),
       TgolKeyStore.CRITERION_RESULT_PAGE_KEY)) {
     return TgolKeyStore.CRITERION_DISPLAY_SCOPE_VALUE;
   }
   if (arsc != null) {
     return arsc.getDisplayScope();
   }
   return TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE;
 }
  /**
   * This methods handles audit data in case of the audit is of site type
   *
   * @param site
   * @param audit
   * @param model
   * @return
   * @throws IOException
   */
  private String prepareSuccessfullSiteData(Site site, Audit audit, Model model) {
    AuditResultSortCommand asuc =
        ((AuditResultSortCommand) model.asMap().get(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY));
    model.addAttribute(
        TgolKeyStore.TEST_RESULT_LIST_KEY,
        TestResultFactory.getInstance()
            .getTestResultSortedByThemeMap(
                site,
                getSiteScope(),
                asuc.getSortOptionMap().get(themeSortKey).toString(),
                getTestResultSortSelection(asuc)));

    // Attributes for breadcrumb
    Contract contract = retrieveContractFromAudit(audit);
    model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
    model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
    model.addAttribute(TgolKeyStore.RESULT_ACTION_LIST_KEY, actionHandler.getActionList("EXPORT"));
    return TgolKeyStore.RESULT_SITE_VIEW_NAME;
  }
  /**
   * This methods handles audit data in case of page type audit
   *
   * @param page
   * @param audit
   * @param model
   * @param displayScope
   * @param isManualAudit
   * @param manualAuditCommand
   * @return the success audit page result view name
   */
  protected String prepareSuccessfullPageData(
      Page page,
      Audit audit,
      Model model,
      String displayScope,
      boolean isManualAudit,
      ManualAuditCommand manualAuditCommand) {

    Contract contract = retrieveContractFromAudit(audit);

    if (!audit.getStatus().equals(AuditStatus.COMPLETED)
        && !audit.getStatus().equals(AuditStatus.MANUAL_ANALYSE_IN_PROGRESS)
        && !audit.getStatus().equals(AuditStatus.MANUAL_COMPLETED)
        && !audit.getStatus().equals(AuditStatus.MANUAL_INITIALIZING)) {
      return prepareFailedAuditData(audit, model);
    }

    model.addAttribute(TgolKeyStore.STATUS_KEY, computeAuditStatus(audit));
    model.addAttribute(TgolKeyStore.RESULT_ACTION_LIST_KEY, actionHandler.getActionList("EXPORT"));
    // Attributes for breadcrumb
    model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
    model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
    model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());

    // Add a boolean used to display the breadcrumb.
    model.addAttribute(
        TgolKeyStore.AUTHORIZED_SCOPE_FOR_PAGE_LIST, isAuthorizedScopeForPageList(audit));

    // Add a command to relaunch the audit from the result page
    model.addAttribute(
        TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY,
        AuditSetUpCommandFactory.getInstance()
            .getPageAuditSetUpCommand(
                contract,
                page.getURL(),
                getParameterDataService().getParameterSetFromAudit(audit)));

    if (StringUtils.equalsIgnoreCase(displayScope, TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE)) {
      AuditResultSortCommand asuc =
          ((AuditResultSortCommand) model.asMap().get(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY));

      model.addAttribute(
          TgolKeyStore.TEST_RESULT_LIST_KEY,
          TestResultFactory.getInstance()
              .getTestResultSortedByThemeMap(
                  page,
                  getPageScope(),
                  asuc.getSortOptionMap().get(themeSortKey).toString(),
                  getTestResultSortSelection(asuc)));
      if (isManualAudit) {
        if (manualAuditCommand == null) {
          manualAuditCommand = new ManualAuditCommand();
        }
        manualAuditCommand.setModifedManualResultMap(
            TestResultFactory.getInstance()
                .getTestResultMap(
                    page,
                    getPageScope(),
                    asuc.getSortOptionMap().get(themeSortKey).toString(),
                    getTestResultSortSelection(asuc)));
        model.addAttribute(TgolKeyStore.MANUAL_AUDIT_COMMAND_KEY, manualAuditCommand);
      }

      return TgolKeyStore.RESULT_PAGE_VIEW_NAME;
    } else {
      AuditResultSortCommand asuc =
          ((AuditResultSortCommand) model.asMap().get(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY));
      model.addAttribute(
          TgolKeyStore.CRITERION_RESULT_LIST_KEY,
          CriterionResultFactory.getInstance()
              .getCriterionResultSortedByThemeMap(
                  page,
                  asuc.getSortOptionMap().get(themeSortKey).toString(),
                  getTestResultSortSelection(asuc)));
      return TgolKeyStore.RESULT_PAGE_BY_CRITERION_VIEW_NAME;
    }
  }