package edu.northwestern.bioinformatics.studycalendar.web.schedule;

import edu.northwestern.bioinformatics.studycalendar.dao.ScheduledCalendarDao;
import edu.northwestern.bioinformatics.studycalendar.web.ControllerTools;
import edu.northwestern.bioinformatics.studycalendar.domain.ScheduledEventMode;
import edu.northwestern.bioinformatics.studycalendar.utils.editors.ControlledVocabularyEditor;
import edu.northwestern.bioinformatics.studycalendar.utils.accesscontrol.AccessControl;
import edu.northwestern.bioinformatics.studycalendar.utils.accesscontrol.StudyCalendarProtectionGroup;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import org.springframework.web.bind.ServletRequestDataBinder;

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

/**
 * @author Rhett Sutphin
 */
@AccessControl(protectionGroups = StudyCalendarProtectionGroup.PARTICIPANT_COORDINATOR)
public class BatchRescheduleController extends AbstractCommandController {
    private ScheduledCalendarDao scheduledCalendarDao;

    public BatchRescheduleController() {
        super(BatchRescheduleCommand.class);
    }

    protected Object getCommand(HttpServletRequest request) throws Exception {
        return new BatchRescheduleCommand(scheduledCalendarDao);
    }

    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
        super.initBinder(request, binder);
        ControllerTools.registerDomainObjectEditor(binder, "scheduledCalendar", scheduledCalendarDao);
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
        binder.registerCustomEditor(ScheduledEventMode.class, "newMode", new ControlledVocabularyEditor(ScheduledEventMode.class));
    }

    protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object oCommand, BindException errors) throws Exception {
        BatchRescheduleCommand command = (BatchRescheduleCommand) oCommand;
        command.apply();
        return new ModelAndView("schedule/batchReschedule", "scheduledCalendar", command.getScheduledCalendar());
    }

    ////// CONFIGURATION

    @Required
    public void setScheduledCalendarDao(ScheduledCalendarDao scheduledCalendarDao) {
        this.scheduledCalendarDao = scheduledCalendarDao;
    }
}

@@ -198,202 +198,33 @@
 dar.
-web.ControllerTools;%0Aimport edu.northwestern.bioinformatics.studycalendar.domain.ScheduledEventMode;%0Aimport edu.northwestern.bioinformatics.studycalendar.utils.editors.ControlledVocabularyEditor
+domain.ScheduledEventMode
 ;%0Aim
@@ -412,16 +412,185 @@
 nGroup;%0A
+import edu.northwestern.bioinformatics.studycalendar.utils.editors.ControlledVocabularyEditor;%0Aimport edu.northwestern.bioinformatics.studycalendar.web.ControllerTools;%0A
 import o
@@ -766,16 +766,78 @@
 eption;%0A
+import org.springframework.web.bind.ServletRequestDataBinder;%0A
 import o
@@ -954,70 +954,8 @@
 ler;
-%0Aimport org.springframework.web.bind.ServletRequestDataBinder;
 %0A%0Aim

Optimize imports