示例#1
0
  private UserBalanceVO userBalancePojoToVo(UserBalance userBalance) {
    UserBalanceVO vo = new UserBalanceVO();

    vo.setIdUserBalance(userBalance.getIdUSerBalance());
    vo.setImeis(userBalance.getImeis());
    vo.setResults(userBalance.getResults());
    vo.setSendAlerts(userBalance.getSendAlerts());
    vo.setSurveys(userBalance.getSurveys());
    vo.setUser(userPojoToVo(userBalance.getUser()));
    vo.setUsers(userBalance.getUsers());

    return vo;
  }
示例#2
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;
  }
示例#3
0
  public UserVO validateLogin(String username, String password) throws MSMApplicationException {
    NdgUser user = findNdgUserByName(username);
    UserVO vo = new UserVO();

    if (user != null) {
      try {
        if (user.getPassword().equals(MD5.createMD5(password))) {
          if ((user.getUserValidated() == 'y' || user.getUserValidated() == 'Y')) {
            vo = userPojoToVo(user);
            vo.setRetCode(UserVO.AUTHENTICATED);
            vo.setFirstTimeUse(user.getFirstTimeUse());

            try {
              NdgUser userAdmin = findNdgUserByName(user.getUserAdmin());
              vo.setHasFullPermissions(userAdmin.getHasFullPermissions());
            } catch (Exception e) {
              log.error("validateLogin: userAdmin not found - admin = " + user.getUserAdmin());
            }

            Query query = manager.createNamedQuery("userbalance.findByUserAdmin");
            query.setParameter("useradmin", user.getUserAdmin());
            UserBalance userAdminBalance = null;
            try {
              userAdminBalance = (UserBalance) query.getSingleResult();
            } catch (Exception e) {
              log.info("New user: "******"LIMIT_IMEIS")));
                initialUserBalance.setResults(
                    Integer.parseInt(properties.getProperty("LIMIT_RESULTS")));
                initialUserBalance.setSendAlerts(
                    Integer.parseInt(properties.getProperty("LIMIT_SEND_ALERTS")));
                initialUserBalance.setSurveys(
                    Integer.parseInt(properties.getProperty("LIMIT_SURVEYS")));
                initialUserBalance.setUser(findNdgUserByName(user.getUserAdmin()));
                initialUserBalance.setUsers(Integer.parseInt(properties.getProperty("LIMIT_USER")));
              } catch (Exception e) {
                initialUserBalance.setImeis(0);
                initialUserBalance.setResults(0);
                initialUserBalance.setSendAlerts(0);
                initialUserBalance.setSurveys(0);
                initialUserBalance.setUser(findNdgUserByName(user.getUserAdmin()));
                initialUserBalance.setUsers(0);
              }
              UserBalanceVO balanceVO = new UserBalanceVO();
              balanceVO.setImeis(initialUserBalance.getImeis());
              balanceVO.setResults(initialUserBalance.getResults());
              balanceVO.setSendAlerts(initialUserBalance.getSendAlerts());
              balanceVO.setSurveys(initialUserBalance.getSurveys());
              balanceVO.setUsers(initialUserBalance.getUsers());
              vo.setUserBalance(balanceVO);
              manager.persist(initialUserBalance);
            } else {
              UserBalanceVO balanceVO = new UserBalanceVO();
              balanceVO.setImeis(userAdminBalance.getImeis());
              balanceVO.setResults(userAdminBalance.getResults());
              balanceVO.setSendAlerts(userAdminBalance.getSendAlerts());
              balanceVO.setSurveys(userAdminBalance.getSurveys());
              balanceVO.setUsers(userAdminBalance.getUsers());
              vo.setUserBalance(balanceVO);
            }
          } else {
            vo.setRetCode(UserVO.EMAIL_NOT_VALIDATED);
            throw new UserEmailNotValidatedException();
          }
        } else {
          vo.setRetCode(UserVO.INVALID_PASSWORD);
          throw new InvalidPasswordException();
        }
      } catch (NoSuchAlgorithmException e) {
        throw new InvalidPasswordGenerationException();
      }
    } else {
      vo.setRetCode(UserVO.INVALID_USERNAME);
      throw new InvalidUsernameException();
    }
    return vo;
  }
示例#4
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();
    }
  }