package edu.northwestern.bioinformatics.studycalendar.web;

import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.beans.factory.annotation.Required;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.northwestern.bioinformatics.studycalendar.dao.StudyDao;
import edu.northwestern.bioinformatics.studycalendar.domain.Study;
import edu.northwestern.bioinformatics.studycalendar.service.TemplateService;
import edu.northwestern.bioinformatics.studycalendar.utils.accesscontrol.AccessControl;
import edu.northwestern.bioinformatics.studycalendar.utils.accesscontrol.ApplicationSecurityManager;
import edu.northwestern.bioinformatics.studycalendar.utils.accesscontrol.StudyCalendarProtectionGroup;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

/**
 * @author Rhett Sutphin
 */
@AccessControl(protectionGroups = StudyCalendarProtectionGroup.BASE)
public class StudyListController extends AbstractController {
    private StudyDao studyDao;
    private TemplateService templateService; 

    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        List<Study> studies = studyDao.getAll();
        String userName = ApplicationSecurityManager.getUser(request);
        List<Study> ownedStudies = templateService.checkOwnership(userName, studies);
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("studies", ownedStudies);
        return new ModelAndView("studyList", model);
    }

    ////// CONFIGURATION

    @Required
    public void setStudyDao(StudyDao studyDao) {
        this.studyDao = studyDao;
    }
    
    @Required
    public void setTemplateService(TemplateService templateService) {
        this.templateService = templateService;
    }
}

@@ -460,16 +460,156 @@
 .Study;%0A
+import edu.northwestern.bioinformatics.studycalendar.domain.Site;%0Aimport edu.northwestern.bioinformatics.studycalendar.service.SiteService;%0A
 import e
@@ -670,32 +670,32 @@
 emplateService;%0A
-
 import edu.north
@@ -1311,17 +1311,53 @@
 Service;
- 
+%0A    private SiteService siteService;
 %0A%0A    pr
@@ -1785,32 +1785,163 @@
  ownedStudies);%0A
+        %0A        List%3CSite%3E ownedSites = siteService.getSitesForSiteCd(userName);%0A        model.put(%22sites%22, ownedSites);%0A        %0A
         return n
@@ -2069,24 +2069,24 @@
 studyDao) %7B%0A
-
         this
@@ -2124,32 +2124,155 @@
  %0A    @Required%0A
+    public void setSiteService(SiteService siteService) %7B%0A        this.siteService = siteService;%0A    %7D%0A    %0A    @Required%0A
     public void 

change interface of Calendar Menu