package edu.northwestern.bioinformatics.studycalendar.dao;

import edu.northwestern.bioinformatics.studycalendar.domain.ScheduledActivity;
import edu.northwestern.bioinformatics.studycalendar.domain.ScheduledCalendar;
import edu.northwestern.bioinformatics.studycalendar.domain.PlannedActivity;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;

/**
 * @author Rhett Sutphin
 */
public class ScheduledActivityDao extends StudyCalendarMutableDomainObjectDao<ScheduledActivity> {
    @Override public Class<ScheduledActivity> domainClass() { return ScheduledActivity.class; }

    @SuppressWarnings({ "unchecked" })
    public Collection<ScheduledActivity> getEventsByDate(ScheduledCalendar calendar, Date start, Date end) {
        StringBuilder builder = new StringBuilder("from ScheduledActivity e where e.scheduledStudySegment.scheduledCalendar = ?");
        List<Object> params = new ArrayList<Object>(3);
        params.add(calendar);
        if (start != null) {
            builder.append(" and e.currentState.date >= ?");
            params.add(start);
        }
        if (end != null) {
            builder.append(" and e.currentState.date <= ?");
            params.add(end);
        }
        return getHibernateTemplate().find(builder.toString(), params.toArray());
    }

    @SuppressWarnings({ "unchecked" })
    public Collection<ScheduledActivity> getEventsFromPlannedActivity(
        PlannedActivity source, ScheduledCalendar calendar
    ) {
        return getHibernateTemplate().find(
            "from ScheduledActivity e where e.plannedActivity = ? and e.scheduledStudySegment.scheduledCalendar = ?",
            new Object[] { source, calendar });
    }
}

@@ -53,16 +53,93 @@
 r.dao;%0A%0A
+import edu.northwestern.bioinformatics.studycalendar.domain.PlannedActivity;%0A
 import e
@@ -292,85 +292,36 @@
 ar;%0A
+%0A
 import 
-edu.northwestern.bioinformatics.studycalendar.domain.PlannedActivity;%0A
+java.util.ArrayList;
 %0Aimp
@@ -395,36 +395,8 @@
 ist;
-%0Aimport java.util.ArrayList;
 %0A%0A/*
@@ -618,24 +618,414 @@
 y.class; %7D%0A%0A
+    /**%0A    * Finds all the scheduled activities for a given calendar by the start date and end date given.%0A    *%0A    * @param  calendar the calendar to retrieve the scheduled activities from%0A    * @param  start the start date of the time span search%0A    * @param  end the end date of the time span search%0A    * @return      a list of scheduled activities for the criteria specified%0A    */%0A
     @Suppres
@@ -1720,24 +1720,392 @@
 ());%0A    %7D%0A%0A
+    /**%0A    * Finds all the scheduled activities for the given calendar and planned activity%0A    *%0A    * @param  source the planned activity to search for in the scheduled activities%0A    * @param  calendar the calendar to search through for all the scheduled activities%0A    * @return      a list of all the scheduled activities that meet the criteria specified%0A    */%0A
     @Suppres

Add javadoc to scheduled activity dao.