Пример #1
0
  public static String updateUserSettings(Map<String, String[]> settings, String user) {
    String message = "Internal error";
    if (settings == null || settings.size() == 0) {
      return "Empty post body";
    }

    String defaultView = "";
    if (settings.containsKey("detail_default_view")) {
      String[] defaultViewArray = settings.get("detail_default_view");
      if (defaultViewArray != null && defaultViewArray.length > 0) {
        defaultView = defaultViewArray[0];
      }
    }
    String defaultWatch = "";
    if (settings.containsKey("default_watch")) {
      String[] defaultWatchArray = settings.get("default_watch");
      if (defaultWatchArray != null && defaultWatchArray.length > 0) {
        defaultWatch = defaultWatchArray[0];
      }
    }
    Integer userId = 0;
    if (StringUtils.isNotBlank(user)) {
      try {
        userId = (Integer) getJdbcTemplate().queryForObject(GET_USER_ID, Integer.class, user);
      } catch (EmptyResultDataAccessException e) {
        Logger.error("UserDAO updateUserSettings get user id failed, username = "******"Exception = " + e.getMessage());
      }
    }
    if (userId != null && userId > 0) {
      if (StringUtils.isBlank(defaultView)) {
        defaultView = DEFAULT_DETAIL_VIEW;
      }

      if (StringUtils.isBlank(defaultWatch)) {
        defaultWatch = DEFAULT_WATCH;
      }

      int row =
          getJdbcTemplate()
              .update(
                  UPDATE_USER_SETTINGS,
                  userId,
                  defaultView,
                  defaultWatch,
                  defaultView,
                  defaultWatch);
      if (row > 0) {
        message = "";
      }
    } else {
      message = "User not found";
    }
    return message;
  }
Пример #2
0
  public static Integer getUserIDByUserName(String userName) {
    Integer userId = 0;
    if (StringUtils.isNotBlank(userName)) {
      try {
        userId = (Integer) getJdbcTemplate().queryForObject(GET_USER_ID, Integer.class, userName);
      } catch (EmptyResultDataAccessException e) {
        userId = 0;
        Logger.error("Get user id failed, user name = " + userName);
        Logger.error("Exception = " + e.getMessage());
      }
    }

    return userId;
  }
Пример #3
0
  public static User getCurrentUser(String username) {
    User user = new User();
    try {
      if (StringUtils.isNotBlank(username)) {
        user =
            (User)
                getJdbcTemplate()
                    .queryForObject(GET_CURRENT_USER_INFO, new UserRowMapper(), username);
      }
    } catch (EmptyResultDataAccessException e) {
      Logger.error("UserDAO getCurrentUser failed, username = "******"Exception = " + e.getMessage());
    }

    return user;
  }