@Override
  protected Map referenceData(HttpServletRequest request, Object command, Errors errors) {
    logger.debug("referenceData - START");
    Map map = new HashMap();
    ArrayList<String> errorMessages = new ArrayList<String>();
    UserAuth userAuth =
        (UserAuth) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    try {
      // adding to model the results per page for search results
      map.put(
          IConstant.NOM_RESULTS_PER_PAGE, TSContext.getFromContext(IConstant.NOM_RESULTS_PER_PAGE));
    } catch (Exception e) {
      logger.error("referenceData", e);
      errorMessages.add(
          messageSource.getMessage(
              GENERAL_ERROR,
              new Object[] {null, ControllerUtils.getInstance().getFormattedCurrentTime()},
              RequestContextUtils.getLocale(request)));
    }

    try {
      // add the organization available currencies
      List<Currency> currencies =
          BLCurrency.getInstance().getByOrganizationId(userAuth.getOrganisationId());
      if (currencies != null) {
        List<IntString> nomCurrencies = new ArrayList<IntString>();
        for (Currency currency : currencies) {
          IntString entry = new IntString();
          entry.setValue(currency.getCurrencyId());
          entry.setLabel(currency.getName());
          nomCurrencies.add(entry);
        }
        map.put(ORG_CURRENCIES, nomCurrencies);
      }
    } catch (BusinessException bexc) {
      logger.error(bexc.getMessage(), bexc);
      errorMessages.add(
          messageSource.getMessage(
              GET_ORG_CURRENCIES_ERROR,
              new Object[] {
                bexc.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime()
              },
              RequestContextUtils.getLocale(request)));
    }

    try {
      // adding the user's available project for search;
      // if the user has the USER_ALL role, all its organization's projects will be available
      List<Project> projects = null;
      if (userAuth.hasAuthority(PermissionConstant.getInstance().getTS_ExchangeSearchAll())) {
        projects = BLProject.getInstance().getAllProjects(userAuth.getOrganisationId(), true);
      } else {
        projects = BLProject.getInstance().getProjectsByManager(userAuth.getPersonId(), true, true);
      }
      map.put(USER_PROJECTS, projects);
      if (projects != null && projects.size() > 0) {
        map.put(IS_PM_FOR_AT_LEAST_ONE_PROJECT, new Boolean(true));
      } else {
        map.put(IS_PM_FOR_AT_LEAST_ONE_PROJECT, new Boolean(false));
      }
    } catch (BusinessException be) {
      logger.error(be.getMessage(), be);
      errorMessages.add(
          messageSource.getMessage(
              GET_USER_PROJECTS_ERROR,
              new Object[] {be.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime()},
              RequestContextUtils.getLocale(request)));
    }

    setErrors(request, errorMessages);
    logger.debug("referenceData - END");
    return map;
  }
  /**
   * Sends the notification when the exchange is deleted
   *
   * @author alexandru.dobre
   * @param projectId
   * @param projectDetailId
   * @param organizationId
   * @param messageCostKey
   * @param messageCostObjects
   * @param subjectCostKey
   * @param subjectCostObjects
   * @param setting
   */
  public void sendNotificationExchangeDelete(
      Integer projectId,
      Integer projectDetailId,
      Integer organizationId,
      String messageKey,
      Object[] messageObjects,
      String subjectKey,
      Object[] subjectObjects,
      Byte setting) {
    logger.debug(
        "sendNotificationExchangeDelete - START, projectId = ".concat(String.valueOf(projectId)));

    Set<String> userIds = new HashSet<String>();
    Map<String, Boolean> userIdsMap = new HashMap<String, Boolean>();

    try {
      if (projectId != null) {

        // get the project identified by it's projectId
        Project project = BLProject.getInstance().getSimpleProject(projectId);
        logger.debug("project = " + project);
        Integer managerId = project.getManagerId();
        logger.debug("managerId = " + managerId);

        // 1. I have to send a notification to the manager of the project
        userIds.add(String.valueOf(managerId));
        userIdsMap.put(String.valueOf(managerId), true);
      }

      // 2. I have to send a notification to the users, that have the permission
      // TS_NotificationReceive
      Set<UserSimple> users =
          OMWebServiceClient.getInstance()
              .getPersonsFromRole(
                  PermissionConstant.getTheInstance().getTS_NotificationReceive(), organizationId);
      logger.debug("users = " + users);
      if (users != null && users.size() > 0) {
        for (UserSimple user : users) {
          if (userIds.add(String.valueOf(user.getUserId()))) {
            userIdsMap.put(String.valueOf(user.getUserId()), false);
          }
        }
      }

      // send the notification
      Thread thread =
          new Thread(
              new NotificationThread(
                  projectDetailId,
                  userIdsMap,
                  organizationId,
                  messageKey,
                  messageObjects,
                  subjectKey,
                  subjectObjects,
                  setting,
                  messageSource));
      thread.start();

    } catch (Exception e) {
      logger.error(e);
    }
    logger.debug("sendNotificationExchangeDelete - END");
  }
  /**
   * Deletes exchanges
   *
   * @author coni
   * @param request
   * @param searchExchangeBean
   * @throws BusinessException
   * @throws ClassNotFoundException
   * @throws NoSuchMethodException
   * @throws SecurityException
   * @throws InvocationTargetException
   * @throws IllegalAccessException
   * @throws IllegalArgumentException
   */
  private void handleDeleteAllSimple(
      HttpServletRequest request,
      SearchExchangeBean searchExchangeBean,
      ArrayList<String> infoMessages,
      ArrayList<String> errorMessages)
      throws BusinessException, SecurityException, NoSuchMethodException, ClassNotFoundException,
          IllegalArgumentException, IllegalAccessException, InvocationTargetException {

    logger.debug("handleDeleteAllSimple - START ");

    UserAuth userAuth =
        (UserAuth) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    Exchange exchange = null;

    for (int i = 0; i < searchExchangeBean.getExchangeId().length; i++) {
      logger.debug("Delete exchange : " + searchExchangeBean.getExchangeId()[i]);
      boolean isDeleted = true;

      try {
        exchange = BLExchange.getInstance().delete(searchExchangeBean.getExchangeId()[i]);
      } catch (BusinessException be) {
        logger.error("", be);
        errorMessages.add(
            messageSource.getMessage(
                DELETE_ERROR,
                new Object[] {
                  be.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime()
                },
                RequestContextUtils.getLocale(request)));
        isDeleted = false;
      }

      if (isDeleted) {
        // send notification
        String projectName = null;
        String message = null;
        Integer projectId = null;

        if (exchange != null) {
          if (exchange.getProjectDetail() != null) {
            Project project =
                BLProject.getInstance().get(exchange.getProjectDetail().getProjectId(), true);
            projectId = exchange.getProjectDetail().getProjectId();
            if (project != null) {
              projectName = project.getName();
            }
            message = IConstant.NOTIFICATION_MESSAGE_EXCHANGE_PROJECT_DELETE;
          } else {
            projectName = IConstant.KEY.concat(IConstant.FROM_ORGANIZATION);
            message = IConstant.NOTIFICATION_MESSAGE_EXCHANGE_ORG_DELETE;
          }
        }

        // send a notification regarding the deleting of the exchange
        sendNotificationExchangeDelete(
            projectId,
            exchange.getProjectDetailId(),
            userAuth.getOrganisationId(),
            message,
            new Object[] {
              exchange.getFirstCurrency().getName(),
              exchange.getSecondCurrency().getName(),
              projectName,
              userAuth.getFirstName().concat(" ").concat(userAuth.getLastName())
            },
            IConstant.NOTIFICATION_SUBJECT_EXCHANGE_DELETE,
            new Object[] {null},
            IConstant.NOTIFICATION_SETTING_EXCHANGE_DELETE);

        infoMessages.add(
            messageSource.getMessage(
                DELETE_SUCCESS,
                new Object[] {
                  exchange
                      .getFirstCurrency()
                      .getInitials()
                      .concat(" - ")
                      .concat(exchange.getSecondCurrency().getInitials())
                },
                RequestContextUtils.getLocale(request)));

        // add the new audit event only if the user is not AdminIT
        try {
          if (!userAuth.isAdminIT()) {
            if (exchange.getProjectDetailId() == null) {
              BLAudit.getInstance()
                  .add(
                      IConstant.AUDIT_EVENT_EXCHANGE_DELETE_TYPE,
                      userAuth.getFirstName(),
                      userAuth.getLastName(),
                      messageSource.getMessage(
                          IConstant.AUDIT_EVENT_EXCHANGE_FOR_ORG_DELETE_MESSAGE,
                          new Object[] {
                            exchange.getFirstCurrency().getName(),
                            exchange.getSecondCurrency().getName()
                          },
                          new Locale("en")),
                      messageSource.getMessage(
                          IConstant.AUDIT_EVENT_EXCHANGE_FOR_ORG_DELETE_MESSAGE,
                          new Object[] {
                            exchange.getFirstCurrency().getName(),
                            exchange.getSecondCurrency().getName()
                          },
                          new Locale("ro")),
                      ControllerUtils.getInstance().getOrganisationIdFromSession(request),
                      userAuth.getPersonId());
            } else {
              Project project = BLProject.getInstance().get(exchange.getProjectId(), true);
              BLAudit.getInstance()
                  .add(
                      IConstant.AUDIT_EVENT_EXCHANGE_DELETE_TYPE,
                      userAuth.getFirstName(),
                      userAuth.getLastName(),
                      messageSource.getMessage(
                          IConstant.AUDIT_EVENT_EXCHANGE_FOR_PROJECT_DELETE_MESSAGE,
                          new Object[] {
                            exchange.getFirstCurrency().getName(),
                            exchange.getSecondCurrency().getName(),
                            project.getName()
                          },
                          new Locale("en")),
                      messageSource.getMessage(
                          IConstant.AUDIT_EVENT_EXCHANGE_FOR_PROJECT_DELETE_MESSAGE,
                          new Object[] {
                            exchange.getFirstCurrency().getName(),
                            exchange.getSecondCurrency().getName(),
                            project.getName()
                          },
                          new Locale("ro")),
                      ControllerUtils.getInstance().getOrganisationIdFromSession(request),
                      userAuth.getPersonId());
            }
          }
        } catch (Exception exc) {
          logger.error("", exc);
        }
      }
    }
    logger.debug("handleDeleteAllSimple - END ");
  }