private static RUserDto mapUser(ResultSet rs, int colShift, DbConn cnx) { try { RUserDto tmp = new RUserDto(); tmp.setId(rs.getInt(1 + colShift)); tmp.setLogin(rs.getString(2 + colShift)); tmp.setLocked(rs.getBoolean(5 + colShift)); tmp.setExpirationDate(cnx.getCal(rs, 6 + colShift)); tmp.setCreationDate(cnx.getCal(rs, 7 + colShift)); tmp.setEmail(rs.getString(9 + colShift)); tmp.setFreeText(rs.getString(10 + colShift)); tmp.setInternal(rs.getBoolean(11 + colShift)); return tmp; } catch (SQLException e) { throw new JqmAdminApiInternalException(e); } }
public static void upsertUser(DbConn cnx, RUserDto dto) if (dto.getId() != null) cnx.runUpdate("user_update_changed", dto.getLogin(), dto.getLocked(), dto.getExpirationDate(), dto.getEmail(), dto.getFreeText(), dto.getId(), dto.getLogin(), dto.getLocked(), dto.getExpirationDate(), dto.getEmail(), dto.getFreeText()); if (dto.getNewPassword() != null && !dto.getNewPassword().isEmpty()) changeUserPassword(cnx, dto.getId(), dto.getNewPassword()); cnx.runUpdate("user_remove_all_roles_by_id", dto.getId()); for (int i : dto.getRoles()) cnx.runUpdate("user_add_role_by_id", dto.getId(), i); QueryResult r = cnx.runUpdate("user_insert", dto.getEmail(), dto.getExpirationDate(), dto.getFreeText(), null, dto.getInternal(), false, dto.getLogin(), null); int newId = r.getGeneratedId(); if (dto.getNewPassword() != null && !dto.getNewPassword().isEmpty()) changeUserPassword(cnx, newId, dto.getNewPassword()); for (int i : dto.getRoles())
public static void syncUsers(DbConn cnx, List<RUserDto> dtos) { for (RUserDto existing : getUsers(cnx)) { boolean foundInNewSet = false; for (RUserDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteUser(cnx, existing.getId()); } } for (RUserDto dto : dtos) { upsertUser(cnx, dto); } } }
public static void syncUsers(DbConn cnx, List<RUserDto> dtos) { for (RUserDto existing : getUsers(cnx)) { boolean foundInNewSet = false; for (RUserDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteUser(cnx, existing.getId()); } } for (RUserDto dto : dtos) { upsertUser(cnx, dto); } } }
private static RUserDto mapUser(ResultSet rs, int colShift, DbConn cnx) { try { RUserDto tmp = new RUserDto(); tmp.setId(rs.getInt(1 + colShift)); tmp.setLogin(rs.getString(2 + colShift)); tmp.setLocked(rs.getBoolean(5 + colShift)); tmp.setExpirationDate(cnx.getCal(rs, 6 + colShift)); tmp.setCreationDate(cnx.getCal(rs, 7 + colShift)); tmp.setEmail(rs.getString(9 + colShift)); tmp.setFreeText(rs.getString(10 + colShift)); tmp.setInternal(rs.getBoolean(11 + colShift)); return tmp; } catch (SQLException e) { throw new JqmAdminApiInternalException(e); } }
public static void upsertUser(DbConn cnx, RUserDto dto) if (dto.getId() != null) cnx.runUpdate("user_update_changed", dto.getLogin(), dto.getLocked(), dto.getExpirationDate(), dto.getEmail(), dto.getFreeText(), dto.getId(), dto.getLogin(), dto.getLocked(), dto.getExpirationDate(), dto.getEmail(), dto.getFreeText()); if (dto.getNewPassword() != null && !dto.getNewPassword().isEmpty()) changeUserPassword(cnx, dto.getId(), dto.getNewPassword()); cnx.runUpdate("user_remove_all_roles_by_id", dto.getId()); for (int i : dto.getRoles()) cnx.runUpdate("user_add_role_by_id", dto.getId(), i); QueryResult r = cnx.runUpdate("user_insert", dto.getEmail(), dto.getExpirationDate(), dto.getFreeText(), null, dto.getInternal(), false, dto.getLogin(), null); int newId = r.getGeneratedId(); if (dto.getNewPassword() != null && !dto.getNewPassword().isEmpty()) changeUserPassword(cnx, newId, dto.getNewPassword()); for (int i : dto.getRoles())
public static void changeUserPassword(DbConn cnx, String userLogin, String newPassword) { List<RUserDto> dtos = getUsers(cnx, "user_select_by_key", 0, userLogin); if (dtos.size() == 0) { throw new JqmAdminApiUserException("Cannot update the password of a user which does not exist - given login was " + userLogin); } changeUserPassword(cnx, dtos.get(0).getId(), newPassword); }
public static void changeUserPassword(DbConn cnx, String userLogin, String newPassword) { List<RUserDto> dtos = getUsers(cnx, "user_select_by_key", 0, userLogin); if (dtos.size() == 0) { throw new JqmAdminApiUserException("Cannot update the password of a user which does not exist - given login was " + userLogin); } changeUserPassword(cnx, dtos.get(0).getId(), newPassword); }