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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations