Search in sources :

Example 1 with NodeUserRoleGroup

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

the class EditionBean method init.

@PostConstruct
public void init() {
    editTheso = new Thesaurus();
    userRoleGroups = new LinkedHashMap();
    ArrayList<NodeUserRoleGroup> nodeUserRoleGroups = new UserHelper2().getUserRoleGroup(connect.getPoolConnexion(), currentUser.getUser().getIdUser());
    for (NodeUserRoleGroup nodeUserRoleGroup : nodeUserRoleGroups) {
        if (nodeUserRoleGroup.getIdRole() < 3) {
            userRoleGroups.put("" + nodeUserRoleGroup.getIdGroup(), nodeUserRoleGroup.getGroupName());
            selectedUserGroup = "" + nodeUserRoleGroup.getIdGroup();
        }
    }
    vue.setCreat(false);
    vue.setTrad(false);
    vue.setEdit(false);
}
Also used : Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) NodeUserRoleGroup(mom.trd.opentheso.bdd.helper.nodes.NodeUserRoleGroup) UserHelper2(mom.trd.opentheso.bdd.helper.UserHelper2) LinkedHashMap(java.util.LinkedHashMap) PostConstruct(javax.annotation.PostConstruct)

Example 2 with NodeUserRoleGroup

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

the class UserHelper2 method getUserRoleOnThisGroup.

/**
 * cette fonction permet de retourner le role de l'utilisateur sur ce groupe
 *
 * @param ds
 * @param idUser
 * @param idGroup
 * @return
 */
public NodeUserRoleGroup getUserRoleOnThisGroup(HikariDataSource ds, int idUser, int idGroup) {
    NodeUserRoleGroup nodeUserRoleGroup = null;
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT \n" + "  roles.id, \n" + "  roles.name, \n" + "  user_group_label.label_group, \n" + "  user_group_label.id_group\n" + " FROM \n" + "  user_role_group, \n" + "  roles, \n" + "  user_group_label\n" + " WHERE \n" + "  user_role_group.id_role = roles.id AND\n" + "  user_group_label.id_group = user_role_group.id_group AND\n" + "  user_role_group.id_user = " + idUser + " AND \n" + "  user_role_group.id_group = " + idGroup;
                resultSet = stmt.executeQuery(query);
                if (resultSet.next()) {
                    nodeUserRoleGroup = new NodeUserRoleGroup();
                    nodeUserRoleGroup.setIdRole(resultSet.getInt("id"));
                    nodeUserRoleGroup.setRoleName(resultSet.getString("name"));
                    nodeUserRoleGroup.setGroupName(resultSet.getString("label_group"));
                    nodeUserRoleGroup.setIdGroup(resultSet.getInt("id_group"));
                    if (resultSet.getInt("id") == 2) {
                        nodeUserRoleGroup.setIsAdmin(true);
                    }
                    if (resultSet.getInt("id") == 3) {
                        nodeUserRoleGroup.setIsManager(true);
                    }
                    if (resultSet.getInt("id") == 4) {
                        nodeUserRoleGroup.setIsContributor(true);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(UserHelper2.class.getName()).log(Level.SEVERE, null, ex);
    }
    return nodeUserRoleGroup;
}
Also used : SQLException(java.sql.SQLException) NodeUserRoleGroup(mom.trd.opentheso.bdd.helper.nodes.NodeUserRoleGroup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 3 with NodeUserRoleGroup

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

the class UserHelper2 method getUserRoleOnThisGroupForSuperAdmin.

/**
 * cette fonction permet de retourner le role de l'utilisateur sur ce groupe
 *
 * @param ds
 * @param idUser
 * @param idGroup
 * @return
 */
public NodeUserRoleGroup getUserRoleOnThisGroupForSuperAdmin(HikariDataSource ds, int idUser, int idGroup) {
    NodeUserRoleGroup nodeUserRoleGroup = null;
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT \n" + "  roles.id, \n" + "  roles.name, \n" + "  user_group_label.id_group, \n" + "  user_group_label.label_group\n" + " FROM \n" + "  public.roles, \n" + "  public.user_group_label\n" + " WHERE \n" + "  roles.id = " + idUser + " AND \n" + "  user_group_label.id_group = " + idGroup;
                resultSet = stmt.executeQuery(query);
                if (resultSet.next()) {
                    nodeUserRoleGroup = new NodeUserRoleGroup();
                    nodeUserRoleGroup.setIdRole(resultSet.getInt("id"));
                    nodeUserRoleGroup.setRoleName(resultSet.getString("name"));
                    nodeUserRoleGroup.setGroupName(resultSet.getString("label_group"));
                    nodeUserRoleGroup.setIdGroup(resultSet.getInt("id_group"));
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(UserHelper2.class.getName()).log(Level.SEVERE, null, ex);
    }
    return nodeUserRoleGroup;
}
Also used : SQLException(java.sql.SQLException) NodeUserRoleGroup(mom.trd.opentheso.bdd.helper.nodes.NodeUserRoleGroup) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 4 with NodeUserRoleGroup

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

the class RoleOnThesoBean method setUserRoleGroup.

/**
 * permet de récuperer le role de l'utilisateur sur le group
 * applelé en cas où le group n'a aucun thésaurus pour que l'utilisateur
 * puisse créer des thésaurus et gérer les utilisateur pour le group
 * il faut être Admin
 */
private void setUserRoleGroup() {
    UserHelper2 userHelper = new UserHelper2();
    ArrayList<NodeUserRoleGroup> nodeUserRoleGroups = userHelper.getUserRoleGroup(connect.getPoolConnexion(), user.getUser().getIdUser());
    for (NodeUserRoleGroup nodeUserRoleGroup1 : nodeUserRoleGroups) {
        if (nodeUserRoleGroup1.isIsAdmin())
            setIsAdminOnThisTheso(true);
    }
}
Also used : NodeUserRoleGroup(mom.trd.opentheso.bdd.helper.nodes.NodeUserRoleGroup) UserHelper2(mom.trd.opentheso.bdd.helper.UserHelper2)

Example 5 with NodeUserRoleGroup

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

the class UserHelper2 method getUserRoleGroup.

/**
 * cette fonction permet de retourner la liste des groupes - roles pour un
 * un utilisateur
 *
 * @param ds
 * @param idUser
 * @return #MR
 */
public ArrayList<NodeUserRoleGroup> getUserRoleGroup(HikariDataSource ds, int idUser) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeUserRoleGroup> nodeUserRoleGroups = new ArrayList<>();
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT " + "  user_role_group.id_role," + "  roles.name," + "  user_role_group.id_group," + "  user_group_label.label_group" + " FROM user_role_group, roles, user_group_label" + " WHERE" + "  user_role_group.id_role = roles.id AND" + "  user_group_label.id_group = user_role_group.id_group AND" + "  user_role_group.id_user =" + idUser;
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    NodeUserRoleGroup nodeUserRoleGroup = new NodeUserRoleGroup();
                    nodeUserRoleGroup.setIdRole(resultSet.getInt("id_role"));
                    nodeUserRoleGroup.setRoleName(resultSet.getString("name"));
                    nodeUserRoleGroup.setIdGroup(resultSet.getInt("id_group"));
                    nodeUserRoleGroup.setGroupName(resultSet.getString("label_group"));
                    if (resultSet.getInt("id_role") == 2) {
                        nodeUserRoleGroup.setIsAdmin(true);
                    }
                    if (resultSet.getInt("id_role") == 3) {
                        nodeUserRoleGroup.setIsManager(true);
                    }
                    if (resultSet.getInt("id_role") == 4) {
                        nodeUserRoleGroup.setIsContributor(true);
                    }
                    nodeUserRoleGroups.add(nodeUserRoleGroup);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(UserHelper2.class.getName()).log(Level.SEVERE, null, ex);
    }
    return nodeUserRoleGroups;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) NodeUserRoleGroup(mom.trd.opentheso.bdd.helper.nodes.NodeUserRoleGroup) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList)

Aggregations

NodeUserRoleGroup (mom.trd.opentheso.bdd.helper.nodes.NodeUserRoleGroup)7 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 UserHelper2 (mom.trd.opentheso.bdd.helper.UserHelper2)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 PostConstruct (javax.annotation.PostConstruct)1 Thesaurus (mom.trd.opentheso.bdd.datas.Thesaurus)1