예제 #1
0
  public boolean userAdminHasPositiveBalance(Integer balanceItem, String loggedUser) {
    boolean hasPositiveBalance = false;
    String ndgMode = null;

    if (properties.containsKey("NDG_MODE")) {
      ndgMode = properties.getProperty("NDG_MODE");
    }

    char userAdminHasFullPermission = 'N';
    try {
      userAdminHasFullPermission =
          findNdgUserByName(findNdgUserByName(loggedUser).getUserAdmin()).getHasFullPermissions();
    } catch (MSMApplicationException e) {
      e.printStackTrace();
    }

    if (!("hosted".equals(ndgMode))
        || (userAdminHasFullPermission == 'Y')
        || (userAdminHasFullPermission == 'y')) {
      hasPositiveBalance = true;
    } else {
      NdgUser onlineUser = null;
      try {
        onlineUser = findNdgUserByName(loggedUser);
      } catch (MSMApplicationException e) {
        e.printStackTrace();
      }

      Query query = manager.createNamedQuery("userbalance.findByUserAdmin");
      query.setParameter("useradmin", onlineUser.getUserAdmin());

      try {
        UserBalance userBalance = (UserBalance) query.getSingleResult();
        if (balanceItem.intValue() == UserVO.USER_LIMIT.intValue()) {
          hasPositiveBalance = (userBalance.getUsers() > 0);
        } else if (balanceItem.intValue() == UserVO.IMEI_LIMIT.intValue()) {
          hasPositiveBalance = (userBalance.getImeis() > 0);
        } else if (balanceItem.intValue() == UserVO.ALERT_LIMIT.intValue()) {
          hasPositiveBalance = (userBalance.getSendAlerts() > 0);
        } else if (balanceItem.intValue() == UserVO.RESULT_LIMIT.intValue()) {
          hasPositiveBalance = (userBalance.getResults() > 0);
        } else if (balanceItem.intValue() == UserVO.SURVEY_LIMIT.intValue()) {
          hasPositiveBalance = (userBalance.getSurveys() > 0);
        }
      } catch (Exception e) {
        hasPositiveBalance = false;
      }
    }
    return hasPositiveBalance;
  }
예제 #2
0
  public void updateUserAdminBalance(Integer balanceItem, String loggedUser) {
    String ndgMode = null;
    if (properties.containsKey("NDG_MODE")) {
      ndgMode = properties.getProperty("NDG_MODE");
    }

    char userAdminHasFullPermission = 'N';
    try {
      userAdminHasFullPermission =
          findNdgUserByName(findNdgUserByName(loggedUser).getUserAdmin()).getHasFullPermissions();
    } catch (MSMApplicationException e) {
      e.printStackTrace();
    }

    try {
      if ("hosted".equals(ndgMode)) {
        if (!((userAdminHasFullPermission == 'y') || (userAdminHasFullPermission == 'Y'))) {
          NdgUser onlineUser = findNdgUserByName(loggedUser);

          Query query = manager.createNamedQuery("userbalance.findByUserAdmin");
          query.setParameter("useradmin", onlineUser.getUserAdmin());

          UserBalance userBalance = (UserBalance) query.getSingleResult();
          if (balanceItem.intValue() == UserVO.USER_LIMIT.intValue()) {
            userBalance.setUsers(userBalance.getUsers() - 1);
          } else if (balanceItem.intValue() == UserVO.IMEI_LIMIT.intValue()) {
            userBalance.setImeis(userBalance.getImeis() - 1);
          } else if (balanceItem.intValue() == UserVO.ALERT_LIMIT.intValue()) {
            userBalance.setSendAlerts(userBalance.getSendAlerts() - 1);
          } else if (balanceItem.intValue() == UserVO.RESULT_LIMIT.intValue()) {
            userBalance.setResults(userBalance.getResults() - 1);
          } else if (balanceItem.intValue() == UserVO.SURVEY_LIMIT.intValue()) {
            userBalance.setSurveys(userBalance.getSurveys() - 1);
          }

          manager.persist(userBalance);
        }
      }
    } catch (MSMApplicationException e) {
      e.printStackTrace();
    }
  }