<commit_before>package edu.duke.cabig.c3pr.web.study;

import edu.duke.cabig.c3pr.domain.Study;
import edu.duke.cabig.c3pr.utils.web.navigation.Task;
import edu.duke.cabig.c3pr.xml.XmlMarshaller;
import gov.nih.nci.cabig.ctms.web.tabs.Flow;
import gov.nih.nci.cabig.ctms.web.tabs.Tab;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: kherm
 * Date: Jun 19, 2007
 * Time: 1:10:17 PM
 * To change this template use File | Settings | File Templates.
 */
public class ViewStudyController extends StudyController<Study> {
    private edu.duke.cabig.c3pr.utils.web.navigation.Task editTask;
    private XmlMarshaller xmlUtility;


    public ViewStudyController() {
        super("View Study Details");
        setBindOnNewForm(true);
    }

    /**
     * Create a nested object graph that Create Study Design needs
     *
     * @param request - HttpServletRequest
     * @throws javax.servlet.ServletException
     */
    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
        Study study = studyDao.getStudyDesignById(Integer.parseInt(request.getParameter("studyId")));
        if (study != null) {
            log.debug("Retrieving Study Details for Id: " + study.getId());
        }
        return study;
    }

    @Override
    protected boolean shouldSave(HttpServletRequest request, Study command, Tab<Study> tab) {
        return false;

    }

    @Override
    protected void layoutTabs(Flow flow) {
        flow.addTab(new StudyEmptyTab("Summary", "Summary", "study/study_summary_view"));
        flow.addTab(new StudyRegistrationsTab());

    }

    @Override
    protected boolean isSummaryEnabled() {
        return false;
    }

    @Override
    /**
     * Reference data to enable Edit button in view
     */
    protected Map referenceData(HttpServletRequest httpServletRequest, Object o, Errors errors, int i) throws Exception {
        Map<String, Object> refdata = super.referenceData(httpServletRequest, o, errors, i);    //To change body of overridden methods use File | Settings | File Templates.
        refdata.put("editAuthorizationTask", editTask);
        return refdata;
    }

    @Override
    protected boolean isFormSubmission(HttpServletRequest httpServletRequest) {
        Set<String> paramNames = httpServletRequest.getParameterMap().keySet();
        return paramNames.contains("_action");

    }

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        // study export
        if (isFormSubmission(httpServletRequest)) {
                Study study = (Study) httpServletRequest.getSession().getAttribute(getFormSessionAttributeName());
                //log.debug("Exporting Study " + study.getId());
                httpServletResponse.setContentType("application/xml");
                httpServletResponse.setHeader("Content-Disposition", "attachment; filename=study-" + study.getId() + ".xml");
                xmlUtility.toXML(study, httpServletResponse.getWriter());
                httpServletResponse.getWriter().close();

                return null;
        }

        return super.handleRequestInternal(httpServletRequest, httpServletResponse);    //To change body of overridden methods use File | Settings | File Templates.
    }

    protected ModelAndView processFinish(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object command, BindException e) throws Exception {
        Study study = (Study) command;

        ModelAndView modelAndView = new ModelAndView(new RedirectView("editStudy?studyId=" + study.getId()));
        return modelAndView;
    }

    public Task getEditTask() {<commit_msg>added a check for export action<commit_after>package edu.duke.cabig.c3pr.web.study;

import edu.duke.cabig.c3pr.domain.Study;
import edu.duke.cabig.c3pr.utils.StringUtils;
import edu.duke.cabig.c3pr.utils.web.navigation.Task;
import edu.duke.cabig.c3pr.xml.XmlMarshaller;
import gov.nih.nci.cabig.ctms.web.tabs.Flow;
import gov.nih.nci.cabig.ctms.web.tabs.Tab;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.web.util.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: kherm
 * Date: Jun 19, 2007
 * Time: 1:10:17 PM
 * To change this template use File | Settings | File Templates.
 */
public class ViewStudyController extends StudyController<Study> {
    private edu.duke.cabig.c3pr.utils.web.navigation.Task editTask;
    private XmlMarshaller xmlUtility;


    public ViewStudyController() {
        super("View Study Details");
        setBindOnNewForm(true);
    }

    /**
     * Create a nested object graph that Create Study Design needs
     *
     * @param request - HttpServletRequest
     * @throws javax.servlet.ServletException
     */
    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
        Study study = studyDao.getStudyDesignById(Integer.parseInt(request.getParameter("studyId")));
        if (study != null) {
            log.debug("Retrieving Study Details for Id: " + study.getId());
        }
        return study;
    }

    @Override
    protected boolean shouldSave(HttpServletRequest request, Study command, Tab<Study> tab) {
        return false;

    }

    @Override
    protected void layoutTabs(Flow flow) {
        flow.addTab(new StudyEmptyTab("Summary", "Summary", "study/study_summary_view"));
        flow.addTab(new StudyRegistrationsTab());

    }

    @Override
    protected boolean isSummaryEnabled() {
        return false;
    }

    @Override
    /**
     * Reference data to enable Edit button in view
     */
    protected Map referenceData(HttpServletRequest httpServletRequest, Object o, Errors errors, int i) throws Exception {
        Map<String, Object> refdata = super.referenceData(httpServletRequest, o, errors, i);    //To change body of overridden methods use File | Settings | File Templates.
        refdata.put("editAuthorizationTask", editTask);
        return refdata;
    }

    @Override
    protected boolean isFormSubmission(HttpServletRequest httpServletRequest) {
        Set<String> paramNames = httpServletRequest.getParameterMap().keySet();
        return paramNames.contains("_action");

    }

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        // study export
        if (isFormSubmission(httpServletRequest)&&StringUtils.getBlankIfNull(httpServletRequest.getParameter("_action")).equalsIgnoreCase("export")) {
                Study study = (Study) httpServletRequest.getSession().getAttribute(getFormSessionAttributeName());
                //log.debug("Exporting Study " + study.getId());
                httpServletResponse.setContentType("application/xml");
                httpServletResponse.setHeader("Content-Disposition", "attachment; filename=study-" + study.getId() + ".xml");
                xmlUtility.toXML(study, httpServletResponse.getWriter());
                httpServletResponse.getWriter().close();

                return null;
        }

        return super.handleRequestInternal(httpServletRequest, httpServletResponse);    //To change body of overridden methods use File | Settings | File Templates.
    }

    protected ModelAndView processFinish(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object command, BindException e) throws Exception {
        Study study = (Study) command;

        ModelAndView modelAndView = new ModelAndView(new RedirectView("editStudy?studyId=" + study.getId()));
        return modelAndView;
    }

    public Task getEditTask() {
{'fraction_non_alphanumeric': 0.09686204854943754, 'fraction_numerical': 0.003907637655417406, 'mean_word_length': 3.5262593783494105, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1922923', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2260, 'n_words': 523}