package gov.nih.nci.cabig.caaers.web;

import gov.nih.nci.cabig.caaers.dao.StudyDao;
import gov.nih.nci.cabig.caaers.domain.Study;

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

import org.springframework.beans.factory.annotation.Required;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

/**
 * Controller class for the Study module.
 * This handles the Create/Update/List flows for the Study.
 * @author Sujith Vellat Thayyilthodi
 * @see gov.nih.nci.cabig.caaers.dao.StudyDao
 * @since 1.0
 * */
public final class StudyController extends CaaersAbstractFormController {

	private StudyDao studyDao;

	public StudyController() {
		setCommandClass(Study.class);
        setFormView("createStudy");
        setSuccessView("createStudy");
	}

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

	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object oCommand, BindException errors)
			throws Exception {
		Study study = (Study) oCommand;
		studyDao.save(study);
		ModelAndView modelAndView = new ModelAndView(getSuccessView());
		modelAndView.addObject("study", study);
		modelAndView.addAllObjects(errors.getModel());
		return modelAndView;
	}
}
@@ -118,19 +118,116 @@
 rs.d
-omain.Study
+ao.SiteDao;%0D%0Aimport gov.nih.nci.cabig.caaers.domain.Study;%0D%0Aimport gov.nih.nci.cabig.caaers.domain.StudySite
 ;%0D%0A%0D
@@ -820,19 +820,52 @@
 dyDao;%0D%0A
-%0D%0A%09
+    private SiteDao siteDao;%0D%0A%0D%0A    
 public S
@@ -1004,102 +1004,8 @@
 %0D%0A%0D%0A
-%09@Required%0D%0A%09public void setStudyDao(StudyDao studyDao) %7B%0D%0A%09%09this.studyDao = studyDao;%0D%0A%09%7D%0D%0A%0D%0A
 %09pro
@@ -1197,218 +1197,709 @@
 d;%0D%0A
-%09%09studyDao.save(study);%0D%0A%09%09ModelAndView modelAndView = new ModelAndView(getSuccessView());%0D%0A%09%09modelAndView.addObject(%22study%22, study);%0D%0A%09%09modelAndView.addAllObjects(errors.getModel());%0D%0A%09%09return modelAndView;%0D%0A%09
+%0D%0A        // TODO: this is a temporary fix.  It should be moved to a service.%0D%0A        StudySite defaultStudySite = new StudySite();%0D%0A        defaultStudySite.setSite(siteDao.getDefaultSite());%0D%0A        study.addStudySite(defaultStudySite);%0D%0A%0D%0A        studyDao.save(study);%0D%0A%09%09ModelAndView modelAndView = new ModelAndView(getSuccessView());%0D%0A%09%09modelAndView.addObject(%22study%22, study);%0D%0A%09%09modelAndView.addAllObjects(errors.getModel());%0D%0A%09%09return modelAndView;%0D%0A%09%7D%0D%0A%0D%0A    ////// CONIFGURATION%0D%0A%0D%0A    @Required%0D%0A    public void setStudyDao(StudyDao studyDao) %7B%0D%0A        this.studyDao = studyDao;%0D%0A    %7D%0D%0A%0D%0A    @Required%0D%0A    public void setSiteDao(SiteDao siteDao) %7B%0D%0A        this.siteDao = siteDao;%0D%0A    
 %7D%0D%0A%7D

Add default studySite to new studies. This is a quick hack -- the real solution should be put in a service.