<commit_before>/*
 * UniTime 3.2 (University Timetabling Application)
 * Copyright (C) 2008 - 2010, UniTime LLC, and individual contributors
 * as indicated by the @authors tag.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
*/
package org.unitime.timetable.model;

import java.util.Enumeration;
import java.util.List;
import java.util.Vector;

import org.hibernate.criterion.Order;
import org.unitime.timetable.model.base.BaseRoles;
import org.unitime.timetable.model.dao.RolesDAO;
import org.unitime.timetable.security.rights.HasRights;
import org.unitime.timetable.security.rights.Right;




public class Roles extends BaseRoles implements HasRights {

/**
	 *
	 */
	private static final long serialVersionUID = 3256722879445154100L;

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Roles () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Roles (java.lang.Long roleId) {
		super(roleId);
	}

/*[CONSTRUCTOR MARKER END]*/

	@Deprecated
	public static String EVENT_MGR_ROLE = "Event Mgr";
	
	public static final String ROLE_STUDENT = "Student";
	public static final String ROLE_INSTRUCTOR = "Instructor";
	public static final String ROLE_NONE = "No Role";
	
    public static String USER_ROLES_ATTR_NAME = "userRoles";
    public static String ROLES_ATTR_NAME = "rolesList";

	/** Roles List **/
    private static Vector rolesList = null;
    
	/**
	 * Retrieves all roles in the database
	 * ordered by column label
	 * @param refresh true - refreshes the list from database
	 * @return Vector of Roles objects
	 */
    public static synchronized Vector getRolesList(boolean refresh) {
        
        if(rolesList!=null && !refresh)
            return rolesList;
        

        RolesDAO rdao = new RolesDAO();

        List l = rdao.findAll(Order.asc("abbv"));
        rolesList = new Vector(l);
        return rolesList;
    }
    
    public static Roles getRole(String roleRef) {
        for (Enumeration e=getRolesList(false).elements();e.hasMoreElements();) {
            Roles role = (Roles)e.nextElement();
            if (roleRef.equals(role.getReference())) return role;
        }
        return null;
    }

    @Override
	public boolean hasRight(Right right) {
    	return getRights().contains(right.name());
    }
    
    public Long getUniqueId() { return getRoleId(); }
    
    public boolean isUsed() {
    	return ((Number)RolesDAO.getInstance().getSession().createQuery(
    			"count m from ManagerRole m where m.role.roleId = :roleId")
    			.setLong("roleId", getRoleId()).uniqueResult()).intValue() > 0;
    }
}<commit_msg>Spring Security  - Roles: fixed the isUsed() query<commit_after>/*
 * UniTime 3.2 (University Timetabling Application)
 * Copyright (C) 2008 - 2010, UniTime LLC, and individual contributors
 * as indicated by the @authors tag.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
*/
package org.unitime.timetable.model;

import java.util.Enumeration;
import java.util.List;
import java.util.Vector;

import org.hibernate.criterion.Order;
import org.unitime.timetable.model.base.BaseRoles;
import org.unitime.timetable.model.dao.RolesDAO;
import org.unitime.timetable.security.rights.HasRights;
import org.unitime.timetable.security.rights.Right;




public class Roles extends BaseRoles implements HasRights {

/**
	 *
	 */
	private static final long serialVersionUID = 3256722879445154100L;

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Roles () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Roles (java.lang.Long roleId) {
		super(roleId);
	}

/*[CONSTRUCTOR MARKER END]*/

	@Deprecated
	public static String EVENT_MGR_ROLE = "Event Mgr";
	
	public static final String ROLE_STUDENT = "Student";
	public static final String ROLE_INSTRUCTOR = "Instructor";
	public static final String ROLE_NONE = "No Role";
	
    public static String USER_ROLES_ATTR_NAME = "userRoles";
    public static String ROLES_ATTR_NAME = "rolesList";

	/** Roles List **/
    private static Vector rolesList = null;
    
	/**
	 * Retrieves all roles in the database
	 * ordered by column label
	 * @param refresh true - refreshes the list from database
	 * @return Vector of Roles objects
	 */
    public static synchronized Vector getRolesList(boolean refresh) {
        
        if(rolesList!=null && !refresh)
            return rolesList;
        

        RolesDAO rdao = new RolesDAO();

        List l = rdao.findAll(Order.asc("abbv"));
        rolesList = new Vector(l);
        return rolesList;
    }
    
    public static Roles getRole(String roleRef) {
        for (Enumeration e=getRolesList(false).elements();e.hasMoreElements();) {
            Roles role = (Roles)e.nextElement();
            if (roleRef.equals(role.getReference())) return role;
        }
        return null;
    }

    @Override
	public boolean hasRight(Right right) {
    	return getRights().contains(right.name());
    }
    
    public Long getUniqueId() { return getRoleId(); }
    
    public boolean isUsed() {
    	return ((Number)RolesDAO.getInstance().getSession().createQuery(
    			"select count(m) from ManagerRole m where m.role.roleId = :roleId")
    			.setLong("roleId", getRoleId()).uniqueResult()).intValue() > 0;
    }
}
{'fraction_non_alphanumeric': 0.09913995308835027, 'fraction_numerical': 0.009695074276778733, 'mean_word_length': 3.304172274562584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5621876', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1866, 'n_words': 610}