package edu.northwestern.bioinformatics.studycalendar.dao;

import edu.northwestern.bioinformatics.studycalendar.domain.*;
import edu.northwestern.bioinformatics.studycalendar.StudyCalendarError;
import edu.nwu.bioinformatics.commons.CollectionUtils;

import java.util.List;
import java.io.Serializable;


public class UserDao extends StudyCalendarMutableDomainObjectDao<User> implements Serializable {
    @Override public Class<User> domainClass() { return User.class; }

    public List<User> getAll() {
        return getHibernateTemplate().find("from User order by name");
    }

    public User getByName(String name) {
        List<User> results = getHibernateTemplate().find("from User where name = ?", name);
        if (results.size() == 0) {
            return null;
        }
        return results.get(0);
    }

    public List getByCsmUserId(Long csmUserId) {
        List<User> results = getHibernateTemplate().find("from User where csm_user_id = ?", csmUserId);
        return results;
    }

    public List<StudySubjectAssignment> getAssignments(User user) {
        List<StudySubjectAssignment> results = getHibernateTemplate().find(
                "from StudySubjectAssignment a where a.subjectCoordinator = ? ", user);
        return results;
    }

    public List<User> getAllSubjectCoordinators() {
        return getByRole(Role.SUBJECT_COORDINATOR);
    }
    
    public List<User> getByRole(Role role) {
        return getHibernateTemplate()
                .find("select u from User u join u.userRoles r where r.role = ? order by u.name", role);
    }
}

package edu.northwestern.bioinformatics.studycalendar.dao;

import edu.northwestern.bioinformatics.studycalendar.domain.Role;
import edu.northwestern.bioinformatics.studycalendar.domain.StudySubjectAssignment;
import edu.northwestern.bioinformatics.studycalendar.domain.User;
import edu.nwu.bioinformatics.commons.CollectionUtils;

import java.util.List;
import java.io.Serializable;


public class UserDao extends StudyCalendarMutableDomainObjectDao<User> implements Serializable {
    @Override public Class<User> domainClass() { return User.class; }

    @SuppressWarnings({ "unchecked" })
    public List<User> getAll() {
        return getHibernateTemplate().find("from User order by name");
    }

    @SuppressWarnings({ "unchecked" })
    public User getByName(String name) {
        return (User) CollectionUtils.firstElement(getHibernateTemplate().find("from User where name = ?", name));
    }

    @SuppressWarnings({ "unchecked" })
    public List<StudySubjectAssignment> getAssignments(User user) {
        return (List<StudySubjectAssignment>) getHibernateTemplate().find(
                "from StudySubjectAssignment a where a.subjectCoordinator = ? ", user);
    }

    public List<User> getAllSubjectCoordinators() {
        return getByRole(Role.SUBJECT_COORDINATOR);
    }
    
    @SuppressWarnings({ "unchecked" })
    public List<User> getByRole(Role role) {
        return getHibernateTemplate()
                .find("select u from User u join u.userRoles r where r.role = ? order by u.name", role);
    }
}

Remove unused method; suppress unchecked cast warnings
Remove unused method; suppress unchecked cast warnings

git-svn-id: 4b387fe5ada7764508e2ca96c335714e4c1692c6@1836 0d517254-b314-0410-acde-c619094fa49f
