Search in sources :

Example 1 with NodeUser

use of mom.trd.opentheso.bdd.helper.nodes.NodeUser in project opentheso by miledrousset.

the class CurrentUser method selectAuthorizedUser.

/**
 * retoure la liste des utilisateurs suivant leurs droits
 *
 * @return
 */
public ArrayList<NodeUser> selectAuthorizedUser() {
    UserHelper userHelper = new UserHelper();
    int idRoleFrom = 1;
    if (user.getIdRole() == 1) {
        // l'utilisateur est superAdmin
        return selectAllUsers();
    }
    if (user.getIdRole() == 2) {
        // l'utilisateur est admin
        idRoleFrom = 2;
    }
    if (user.getIdRole() > 2) {
        // l'utilisateur est autre
        idRoleFrom = 3;
    }
    ArrayList<NodeUser> listeUser = userHelper.getAuthorizedUsers(connect.getPoolConnexion(), idTheso, idRoleFrom);
    return listeUser;
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) NodeUser(mom.trd.opentheso.bdd.helper.nodes.NodeUser)

Example 2 with NodeUser

use of mom.trd.opentheso.bdd.helper.nodes.NodeUser in project opentheso by miledrousset.

the class UserHelper method getAllUsers.

/**
 * permet de retourner la liste de tous les utilisateurs sans exception avec
 * leurs role
 *
 * @param ds
 * @return
 */
public ArrayList<NodeUser> getAllUsers(HikariDataSource ds) {
    ArrayList<NodeUser> listUser = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT DISTINCT roles.name, user_role.id_role," + " users.username, users.id_user, users.mail, users.active " + " FROM users, user_role, roles WHERE" + " users.id_user = user_role.id_user AND" + " user_role.id_role = roles.id" + " ORDER BY username";
                /*query = "SELECT users.id_user, username, mail, id_role, "
                            + "name, description FROM users, roles  "
                            + "WHERE users.id_role=roles.id AND active=true ORDER BY username";*/
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    NodeUser nu = new NodeUser();
                    nu.setId(resultSet.getInt("id_user"));
                    nu.setMail(resultSet.getString("mail"));
                    nu.setIdRole(resultSet.getInt("id_role"));
                    nu.setName(resultSet.getString("username"));
                    nu.setRole(resultSet.getString("name"));
                    nu.setIsActive(resultSet.getBoolean("active"));
                    listUser.add(nu);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(UserHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return listUser;
}
Also used : SQLException(java.sql.SQLException) NodeUser(mom.trd.opentheso.bdd.helper.nodes.NodeUser) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 3 with NodeUser

use of mom.trd.opentheso.bdd.helper.nodes.NodeUser in project opentheso by miledrousset.

the class UserHelper method getInfoAdmin.

/**
 * cette fonction permet de retourner les informations sur l'utilisateur et
 * son role
 *
 * @param ds
 * @param logName
 * @return
 */
public NodeUser getInfoAdmin(HikariDataSource ds, String logName) {
    NodeUser nu = new NodeUser();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT roles.name, user_role.id_role," + " user_role.id_thesaurus," + " users.username, users.id_user, users.mail " + " FROM users, user_role, roles WHERE" + " users.id_user = user_role.id_user AND" + " user_role.id_role = roles.id AND" + " users.username = '" + logName + "'";
                /*   String query = "SELECT users.id_user, username, mail, id_role, name, description FROM users, roles  "
                            + "WHERE users.id_role=roles.id AND username='" + logName + "' and active=true";*/
                resultSet = stmt.executeQuery(query);
                if (resultSet.next()) {
                    nu.setId(resultSet.getInt("id_user"));
                    nu.setMail(resultSet.getString("mail"));
                    nu.setIdRole(resultSet.getInt("id_role"));
                    nu.setName(logName);
                    nu.setRole(resultSet.getString("name"));
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(UserHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return nu;
}
Also used : SQLException(java.sql.SQLException) NodeUser(mom.trd.opentheso.bdd.helper.nodes.NodeUser) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 4 with NodeUser

use of mom.trd.opentheso.bdd.helper.nodes.NodeUser in project opentheso by miledrousset.

the class UserHelper method getAllUsersOfThesaurus.

/**
 * cette fonction permet de retourner la liste des utlisateurs par thésaurus
 *
 * @param ds
 * @param idThesaurus
 * @return
 */
public ArrayList<NodeUser> getAllUsersOfThesaurus(HikariDataSource ds, String idThesaurus) {
    ArrayList<NodeUser> listUser = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT roles.name, user_role.id_role," + " user_role.id_thesaurus," + " users.username, users.id_user, users.mail " + " FROM users, user_role, roles WHERE" + " users.id_user = user_role.id_user AND" + " user_role.id_role = roles.id AND" + " user_role.id_thesaurus = '" + idThesaurus + "'" + " ORDER BY username";
                /*query = "SELECT users.id_user, username, mail, id_role, "
                            + "name, description FROM users, roles  "
                            + "WHERE users.id_role=roles.id AND active=true ORDER BY username";*/
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    NodeUser nu = new NodeUser();
                    nu.setId(resultSet.getInt("id_user"));
                    nu.setMail(resultSet.getString("mail"));
                    nu.setIdRole(resultSet.getInt("id_role"));
                    nu.setName(resultSet.getString("username"));
                    nu.setRole(resultSet.getString("name"));
                    listUser.add(nu);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(UserHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return listUser;
}
Also used : SQLException(java.sql.SQLException) NodeUser(mom.trd.opentheso.bdd.helper.nodes.NodeUser) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 5 with NodeUser

use of mom.trd.opentheso.bdd.helper.nodes.NodeUser in project opentheso by miledrousset.

the class UserHelper method getAuthorizedUsers.

/**
 * cette fonction permet de retourner la liste des utlisateurs par thésaurus
 * mais filtrés par role : exp: un admin peut voir et modifier que les
 * admins et ceux qui sont en dessous
 *
 * @param ds
 * @param idThesaurus
 * @param idRoleFrom
 * @return
 */
public ArrayList<NodeUser> getAuthorizedUsers(HikariDataSource ds, String idThesaurus, int idRoleFrom) {
    ArrayList<NodeUser> listUser = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT roles.name, user_role.id_role," + " user_role.id_thesaurus," + " users.username, users.id_user, users.mail," + " users.active " + " FROM users, user_role, roles WHERE" + " users.id_user = user_role.id_user AND" + " user_role.id_role = roles.id AND" + " user_role.id_thesaurus = '" + idThesaurus + "'" + " and roles.id >= " + idRoleFrom + " ORDER BY username";
                /*query = "SELECT users.id_user, username, mail, id_role, "
                            + "name, description FROM users, roles  "
                            + "WHERE users.id_role=roles.id AND active=true ORDER BY username";*/
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    NodeUser nu = new NodeUser();
                    nu.setId(resultSet.getInt("id_user"));
                    nu.setMail(resultSet.getString("mail"));
                    nu.setIdRole(resultSet.getInt("id_role"));
                    nu.setName(resultSet.getString("username"));
                    nu.setRole(resultSet.getString("name"));
                    nu.setIsActive(resultSet.getBoolean("active"));
                    listUser.add(nu);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(UserHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return listUser;
}
Also used : SQLException(java.sql.SQLException) NodeUser(mom.trd.opentheso.bdd.helper.nodes.NodeUser) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Aggregations

NodeUser (mom.trd.opentheso.bdd.helper.nodes.NodeUser)16 SQLException (java.sql.SQLException)9 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 Statement (java.sql.Statement)7 CandidateHelper (mom.trd.opentheso.bdd.helper.CandidateHelper)6 FacesMessage (javax.faces.application.FacesMessage)5 ArrayList (java.util.ArrayList)3 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)3 NodeProposition (mom.trd.opentheso.bdd.helper.nodes.candidat.NodeProposition)3 UserHelper (mom.trd.opentheso.bdd.helper.UserHelper)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 FacesContext (javax.faces.context.FacesContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CurrentUser (mom.trd.opentheso.SelectedBeans.CurrentUser)1 SelectedCandidat (mom.trd.opentheso.SelectedBeans.SelectedCandidat)1 BaseDeDoneesHelper (mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper)1 Connexion (mom.trd.opentheso.bdd.helper.Connexion)1