package edu.northwestern.bioinformatics.studycalendar.dao;

import edu.northwestern.bioinformatics.studycalendar.domain.Activity;

import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import static java.util.Collections.EMPTY_LIST;

import static org.apache.commons.lang.StringUtils.EMPTY;

/**
 * @author Jaron Sampson
 */
public class ActivityDao extends StudyCalendarMutableDomainObjectDao<Activity> {
    @Override
    public Class<Activity> domainClass() {
        return Activity.class;
    }

    public List<Activity> getAll() {
        List<Activity> sortedList;
        sortedList = getHibernateTemplate().find("from Activity");
        Collections.sort(sortedList);
        return sortedList;
    }

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

    public Activity getByCodeAndSourceName(String code, String sourceName) {
        List<Activity> activities = getHibernateTemplate().find("from Activity a where code = ? and a.source.name = ?", new String[] {code, sourceName});
        if (activities.size() == 0) {
            return null;
        }
        return activities.get(0);
    }

    public List<Activity> getActivitiesBySearchText(String searchText) {
        String search = "%" + searchText.toLowerCase() +"%";
        List<Activity> activities = getHibernateTemplate().find("from Activity where lower(name || code) LIKE ?", search);
        return activities;
    }


    public void delete(Activity activity) {
        getHibernateTemplate().delete(activity);
    }


}

@@ -186,146 +186,8 @@
 st;%0D
-%0Aimport java.util.ArrayList;%0D%0Aimport static java.util.Collections.EMPTY_LIST;%0D%0A%0D%0Aimport static org.apache.commons.lang.StringUtils.EMPTY;%0D
 %0A%0D%0A/
@@ -395,32 +395,187 @@
 lass;%0D%0A    %7D%0D%0A%0D%0A
+   /**%0D%0A    * Returns a list of all the activities currently available.%0D%0A    *%0D%0A    * @return      list of all the Activities currently available%0D%0A    */%0D%0A
     public List%3C
@@ -784,151 +784,255 @@
     
-public Activity getByName(String name) %7B%0D%0A//
+/**%0D%0A    * Finds the activity by activity name.%0D%0A
     
+*%0D%0A
     
-return (Activity) getHibernateTemplate().find(%22from Activity where name = ?%22, name).get(0);
+* @param  name the name of the activity we want to find%0D%0A    * @return      the activity found that corresponds to the name parameter%0D%0A    */%0D%0A    public Activity getByName(String name) %7B
 %0D%0A  
@@ -1245,32 +1245,356 @@
 t(0);%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A    * Finds the activity by activity code and source name.%0D%0A    *%0D%0A    * @param  code the code of the activity we want to find%0D%0A    * @param  sourceName the source name for the activity we want to find%0D%0A    * @return      the activity found that corresponds to the activity code and source name parameters%0D%0A    */%0D%0A
     public Activ
@@ -1926,24 +1926,281 @@
 ;%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A    * Finds the activity doing a LIKE search with some search text for activity name or activity code.%0D%0A    *%0D%0A    * @param  searchText the text we are searching with%0D%0A    * @return      a list of activities found based on the search text%0D%0A    */%0D%0A
     public L
@@ -2484,16 +2484,113 @@
    %7D%0D%0A%0D%0A
+    /**%0D%0A    * Deletes and activity%0D%0A    *%0D%0A    * @param  activity the activity to delete%0D%0A    */
 %0D%0A    pu
@@ -2685,15 +2685,11 @@
 %0A    %7D%0D%0A
-%0D%0A%0D%0A
 %7D%0D%0A

Add javadoc to activity dao.