Search in sources :

Example 6 with NodeUserRoleGroup

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

the class UserHelper2 method getUserRoleWithoutGroup.

/**
 * cette fonction permet de retourner un objet vide de type
 * NodeUserRoleGroup pour un utilisateur qui n'a aucun role encore sur aucun
 * groupe
 *
 * @param ds
 * @return
 */
public NodeUserRoleGroup getUserRoleWithoutGroup(HikariDataSource ds) {
    // NodeUserRoleGroup nodeUserRoleGroup = null;
    NodeUserRoleGroup nodeUserRoleGroup = new NodeUserRoleGroup();
    nodeUserRoleGroup.setIdRole(-1);
    nodeUserRoleGroup.setRoleName("");
    nodeUserRoleGroup.setGroupName("");
    nodeUserRoleGroup.setIdGroup(-1);
    nodeUserRoleGroup.setIsAdmin(false);
    nodeUserRoleGroup.setIsManager(false);
    nodeUserRoleGroup.setIsContributor(false);
    /*
        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;
                    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 : NodeUserRoleGroup(mom.trd.opentheso.bdd.helper.nodes.NodeUserRoleGroup)

Example 7 with NodeUserRoleGroup

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

the class UserHelper2 method getUserRoleForSuperAdmin.

/**
 * cette fonction permet de retourner le role du superAdmin
 *
 * @param ds
 * @return
 */
public NodeUserRoleGroup getUserRoleForSuperAdmin(HikariDataSource ds) {
    NodeUserRoleGroup nodeUserRoleGroup = null;
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT " + "  roles.id, " + "  roles.name " + " FROM " + "  public.roles " + " WHERE " + "  roles.id = 1";
                resultSet = stmt.executeQuery(query);
                if (resultSet.next()) {
                    nodeUserRoleGroup = new NodeUserRoleGroup();
                    nodeUserRoleGroup.setIdRole(resultSet.getInt("id"));
                    nodeUserRoleGroup.setRoleName(resultSet.getString("name"));
                }
            } 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)

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