/**
   * get the available agent count map in all regions of the user, including the free agents and
   * user specified agents.
   *
   * @param user current user
   * @return user available agent count map
   */
  @Override
  @Transactional
  public Map<String, MutableInt> getUserAvailableAgentCountMap(User user) {
    Set<String> regions = getRegions();
    Map<String, MutableInt> availShareAgents = newHashMap(regions);
    Map<String, MutableInt> availUserOwnAgent = newHashMap(regions);
    for (String region : regions) {
      availShareAgents.put(region, new MutableInt(0));
      availUserOwnAgent.put(region, new MutableInt(0));
    }
    String myAgentSuffix = "_owned_" + user.getUserId();

    for (AgentInfo agentInfo : getAllActiveAgentInfoFromDB()) {
      // Skip the all agents which doesn't approved, is inactive or
      // doesn't have region
      // prefix.
      if (!agentInfo.isApproved()) {
        continue;
      }

      String fullRegion = agentInfo.getRegion();
      String region = extractRegionFromAgentRegion(fullRegion);
      if (StringUtils.isBlank(region) || !regions.contains(region)) {
        continue;
      }
      // It's my own agent
      if (fullRegion.endsWith(myAgentSuffix)) {
        incrementAgentCount(availUserOwnAgent, region, user.getUserId());
      } else if (fullRegion.contains("_owned_")) {
        // If it's the others agent.. skip..
        continue;
      } else {
        incrementAgentCount(availShareAgents, region, user.getUserId());
      }
    }

    int maxAgentSizePerConsole = getMaxAgentSizePerConsole();

    for (String region : regions) {
      MutableInt mutableInt = availShareAgents.get(region);
      int shareAgentCount = mutableInt.intValue();
      mutableInt.setValue(Math.min(shareAgentCount, maxAgentSizePerConsole));
      mutableInt.add(availUserOwnAgent.get(region));
    }
    return availShareAgents;
  }