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

@@ -117,9 +117,12 @@
 ain.
-*
+Role
 ;%0Aim
@@ -176,25 +176,102 @@
 dar.
-StudyCalendarErro
+domain.StudySubjectAssignment;%0Aimport edu.northwestern.bioinformatics.studycalendar.domain.Use
 r;%0Ai
@@ -543,24 +543,63 @@
 r.class; %7D%0A%0A
+    @SuppressWarnings(%7B %22unchecked%22 %7D)%0A
     public L
@@ -689,32 +689,71 @@
  name%22);%0A    %7D%0A%0A
+    @SuppressWarnings(%7B %22unchecked%22 %7D)%0A
     public User 
@@ -785,37 +785,59 @@
         
-List%3CUser%3E results = 
+return (User) CollectionUtils.firstElement(
 getHiber
@@ -893,301 +893,56 @@
 ame)
-;%0A        if (results.size() == 0) %7B%0A            return null;%0A        %7D%0A        return results.get(0);%0A    %7D%0A%0A    public List getByCsmUserId(Long csmUserId) %7B%0A        List%3CUser%3E results = getHibernateTemplate().find(%22from User where csm_user_id = ?%22, csmUserId);%0A        return results;%0A    %7D%0A
+);%0A    %7D%0A%0A    @SuppressWarnings(%7B %22unchecked%22 %7D)
 %0A   
@@ -1014,16 +1014,24 @@
         
+return (
 List%3CStu
@@ -1054,18 +1054,9 @@
 ent%3E
- results =
+)
  get
@@ -1173,32 +1173,8 @@
 r);%0A
-        return results;%0A
     
@@ -1291,16 +1291,55 @@
  %7D%0A    %0A
+    @SuppressWarnings(%7B %22unchecked%22 %7D)%0A
     publ

Remove unused method; suppress unchecked cast warnings