<commit_before>package gov.nih.nci.cananolab.ui.protocol;

import gov.nih.nci.cananolab.domain.common.Protocol;
import gov.nih.nci.cananolab.domain.common.ProtocolFile;
import gov.nih.nci.cananolab.dto.common.ProtocolFileBean;
import gov.nih.nci.cananolab.dto.common.UserBean;
import gov.nih.nci.cananolab.exception.CaNanoLabSecurityException;
import gov.nih.nci.cananolab.service.common.FileService;
import gov.nih.nci.cananolab.service.common.impl.FileServiceLocalImpl;
import gov.nih.nci.cananolab.service.protocol.ProtocolService;
import gov.nih.nci.cananolab.service.protocol.impl.ProtocolServiceLocalImpl;
import gov.nih.nci.cananolab.service.security.AuthorizationService;
import gov.nih.nci.cananolab.ui.core.AbstractDispatchAction;
import gov.nih.nci.cananolab.ui.security.InitSecuritySetup;
import gov.nih.nci.cananolab.util.CaNanoLabConstants;

import java.util.List;
import java.util.SortedSet;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.DynaValidatorForm;

/**
 * Create or update protocol file and protocol
 * 
 * @author pansu
 * 
 */
public class SubmitProtocolAction extends AbstractDispatchAction {

	public ActionForward create(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward forward = null;
		DynaValidatorForm theForm = (DynaValidatorForm) form;
		UserBean user = (UserBean) request.getSession().getAttribute("user");
		ProtocolFileBean pfileBean = (ProtocolFileBean) theForm.get("file");
		pfileBean.setupDomainFile(CaNanoLabConstants.FOLDER_PROTOCOL, user
				.getLoginName());
		ProtocolService service = new ProtocolServiceLocalImpl();
		ProtocolFile protocolFile = (ProtocolFile) pfileBean.getDomainFile();
		service.saveProtocolFile(protocolFile, pfileBean.getNewFileData());
		// set visibility
		AuthorizationService authService = new AuthorizationService(
				CaNanoLabConstants.CSM_APP_NAME);
		authService.assignVisibility(pfileBean.getDomainFile().getId()
				.toString(), pfileBean.getVisibilityGroups());
		
		//remove protocol visibility
		ProtocolServiceLocalImpl localService = new ProtocolServiceLocalImpl();
		Protocol dbProtocol = localService.findProtocolBy(protocolFile.getProtocol()
				.getType(), protocolFile.getProtocol().getName());
		authService.removePublicGroup(dbProtocol.getId().toString());
		//assign protocol visibility
		if (pfileBean.getVisibilityStr()!=null && pfileBean.getVisibilityStr().contains(CaNanoLabConstants.CSM_PUBLIC_GROUP)){
			authService.assignVisibility(dbProtocol.getId().toString(),new String[]{CaNanoLabConstants.CSM_PUBLIC_GROUP});
		}	
		
		InitProtocolSetup.getInstance().persistProtocolDropdowns(request,
				pfileBean);
		ActionMessages msgs = new ActionMessages();
		ActionMessage msg = new ActionMessage("message.submitProtocol.file",
				pfileBean.getDomainFile().getTitle());
		msgs.add(ActionMessages.GLOBAL_MESSAGE, msg);
		saveMessages(request, msgs);
		forward = mapping.findForward("success");
		return forward;
	}

	public ActionForward setup(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		InitProtocolSetup.getInstance().setProtocolDropdowns(request);
		return mapping.getInputForward();
	}

	public ActionForward setupUpdate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		InitProtocolSetup.getInstance().setProtocolDropdowns(request);
		DynaValidatorForm theForm = (DynaValidatorForm) form;
		UserBean user = (UserBean) request.getSession().getAttribute("user");
		String fileId = request.getParameter("fileId");
		ProtocolService service = new ProtocolServiceLocalImpl();
		ProtocolFileBean pfileBean = service.findProtocolFileById(fileId);
		theForm.set("file", pfileBean);
		String selectedProtocolType = ((ProtocolFile) pfileBean.getDomainFile())
				.getProtocol().getType();
		String selectedProtocolName = ((ProtocolFile) pfileBean.getDomainFile())
				.getProtocol().getName();
		SortedSet<String> protocolNames = service
				.getProtocolNames(selectedProtocolType);
		request.getSession().setAttribute("protocolNamesByType", protocolNames);
		List<ProtocolFileBean> pFiles = service.findProtocolFilesBy(
				selectedProtocolType, selectedProtocolName, null);
		request.getSession().setAttribute("protocolFilesByTypeName", pFiles);
		FileService fileService = new FileServiceLocalImpl();
		fileService.retrieveVisibility(pfileBean, user);
		return mapping.getInputForward();
	}

	public boolean loginRequired() {
		return true;
	}

	public boolean canUserExecute(UserBean user)
			throws CaNanoLabSecurityException {
		return InitSecuritySetup.getInstance().userHasCreatePrivilege(user,
				CaNanoLabConstants.CSM_PG_PROTOCOL);
	}
}<commit_msg>added dispatch method input and updated return forwards for other dispatches<commit_after>package gov.nih.nci.cananolab.ui.protocol;

import gov.nih.nci.cananolab.domain.common.Protocol;
import gov.nih.nci.cananolab.domain.common.ProtocolFile;
import gov.nih.nci.cananolab.dto.common.ProtocolFileBean;
import gov.nih.nci.cananolab.dto.common.UserBean;
import gov.nih.nci.cananolab.exception.CaNanoLabSecurityException;
import gov.nih.nci.cananolab.service.common.FileService;
import gov.nih.nci.cananolab.service.common.impl.FileServiceLocalImpl;
import gov.nih.nci.cananolab.service.protocol.ProtocolService;
import gov.nih.nci.cananolab.service.protocol.impl.ProtocolServiceLocalImpl;
import gov.nih.nci.cananolab.service.security.AuthorizationService;
import gov.nih.nci.cananolab.ui.core.AbstractDispatchAction;
import gov.nih.nci.cananolab.ui.security.InitSecuritySetup;
import gov.nih.nci.cananolab.util.CaNanoLabConstants;

import java.util.List;
import java.util.SortedSet;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.DynaValidatorForm;

/**
 * Create or update protocol file and protocol
 * 
 * @author pansu
 * 
 */
public class SubmitProtocolAction extends AbstractDispatchAction {

	public ActionForward create(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward forward = null;
		DynaValidatorForm theForm = (DynaValidatorForm) form;
		UserBean user = (UserBean) request.getSession().getAttribute("user");
		ProtocolFileBean pfileBean = (ProtocolFileBean) theForm.get("file");
		pfileBean.setupDomainFile(CaNanoLabConstants.FOLDER_PROTOCOL, user
				.getLoginName());
		ProtocolService service = new ProtocolServiceLocalImpl();
		ProtocolFile protocolFile = (ProtocolFile) pfileBean.getDomainFile();
		service.saveProtocolFile(protocolFile, pfileBean.getNewFileData());
		// set visibility
		AuthorizationService authService = new AuthorizationService(
				CaNanoLabConstants.CSM_APP_NAME);
		authService.assignVisibility(pfileBean.getDomainFile().getId()
				.toString(), pfileBean.getVisibilityGroups());

		// remove protocol visibility
		ProtocolServiceLocalImpl localService = new ProtocolServiceLocalImpl();
		Protocol dbProtocol = localService.findProtocolBy(protocolFile
				.getProtocol().getType(), protocolFile.getProtocol().getName());
		authService.removePublicGroup(dbProtocol.getId().toString());
		// assign protocol visibility
		if (pfileBean.getVisibilityStr() != null
				&& pfileBean.getVisibilityStr().contains(
						CaNanoLabConstants.CSM_PUBLIC_GROUP)) {
			authService.assignVisibility(dbProtocol.getId().toString(),
					new String[] { CaNanoLabConstants.CSM_PUBLIC_GROUP });
		}

		InitProtocolSetup.getInstance().persistProtocolDropdowns(request,
				pfileBean);
		ActionMessages msgs = new ActionMessages();
		ActionMessage msg = new ActionMessage("message.submitProtocol.file",
				pfileBean.getDomainFile().getTitle());
		msgs.add(ActionMessages.GLOBAL_MESSAGE, msg);
		saveMessages(request, msgs);
		forward = mapping.findForward("success");
		return forward;
	}

	// for retaining user selected values during validation
	public ActionForward input(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		InitProtocolSetup.getInstance().setProtocolDropdowns(request);
		DynaValidatorForm theForm = (DynaValidatorForm) form;
		ProtocolFileBean pfileBean = ((ProtocolFileBean) theForm.get("file"));
		String selectedProtocolType = ((ProtocolFile) pfileBean.getDomainFile())
				.getProtocol().getType();
		ProtocolService service = new ProtocolServiceLocalImpl();
		SortedSet<String> protocolNames = service
				.getProtocolNames(selectedProtocolType);
		request.getSession().setAttribute("protocolNamesByType", protocolNames);
		String selectedProtocolName = ((ProtocolFile) pfileBean.getDomainFile())
				.getProtocol().getName();
		List<ProtocolFileBean> pFiles = service.findProtocolFilesBy(
				selectedProtocolType, selectedProtocolName, null);
		request.getSession().setAttribute("protocolFilesByTypeName", pFiles);

		return mapping.findForward("inputPage");
	}

	public ActionForward setup(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		InitProtocolSetup.getInstance().setProtocolDropdowns(request);
		return mapping.findForward("inputPage");
	}

	public ActionForward setupUpdate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		InitProtocolSetup.getInstance().setProtocolDropdowns(request);
		DynaValidatorForm theForm = (DynaValidatorForm) form;
		UserBean user = (UserBean) request.getSession().getAttribute("user");
		String fileId = request.getParameter("fileId");
		ProtocolService service = new ProtocolServiceLocalImpl();
		ProtocolFileBean pfileBean = service.findProtocolFileById(fileId);
		theForm.set("file", pfileBean);
		String selectedProtocolType = ((ProtocolFile) pfileBean.getDomainFile())
				.getProtocol().getType();
		String selectedProtocolName = ((ProtocolFile) pfileBean.getDomainFile())
				.getProtocol().getName();
		SortedSet<String> protocolNames = service
				.getProtocolNames(selectedProtocolType);
		request.getSession().setAttribute("protocolNamesByType", protocolNames);
		List<ProtocolFileBean> pFiles = service.findProtocolFilesBy(
				selectedProtocolType, selectedProtocolName, null);
		request.getSession().setAttribute("protocolFilesByTypeName", pFiles);
		FileService fileService = new FileServiceLocalImpl();
		fileService.retrieveVisibility(pfileBean, user);
		return mapping.findForward("inputPage");
	}

	public boolean loginRequired() {
		return true;
	}

	public boolean canUserExecute(UserBean user)
			throws CaNanoLabSecurityException {
		return InitSecuritySetup.getInstance().userHasCreatePrivilege(user,
				CaNanoLabConstants.CSM_PG_PROTOCOL);
	}
}
{'fraction_non_alphanumeric': 0.10183317252872555, 'fraction_numerical': 0.0, 'mean_word_length': 6.550993377483444, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4229458', 'n_tokens_mistral': 3480, 'n_tokens_neox': 3205, 'n_words': 564}