<commit_before>package gov.nih.nci.cabig.caaers.web.study;

import gov.nih.nci.cabig.caaers.dao.workflow.WorkflowConfigDao;
import gov.nih.nci.cabig.caaers.domain.Study;
import gov.nih.nci.cabig.caaers.domain.StudySite;
import gov.nih.nci.cabig.caaers.domain.StudyOrganization;
import gov.nih.nci.cabig.caaers.domain.Organization;
import gov.nih.nci.cabig.caaers.domain.workflow.StudySiteWorkflowConfig;
import gov.nih.nci.cabig.caaers.domain.workflow.WorkflowConfig;
import gov.nih.nci.cabig.caaers.web.fields.InputField;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldFactory;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroup;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroupMap;
import gov.nih.nci.cabig.caaers.web.fields.RepeatingFieldGroupFactory;

import java.util.*;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.validation.Errors;

/**
 * @author <NAME>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
class SitesTab extends StudyTab {

    private RepeatingFieldGroupFactory rfgFactory;
    private WorkflowConfigDao workflowConfigDao;
     
    public SitesTab() {
        super("Sites", "Sites", "study/study_sites");
    }

    @Override
    public void postProcess(HttpServletRequest request, StudyCommand command, Errors errors) {
        String action = request.getParameter("_action");
        Object isAjax = request.getAttribute("_isAjax");

        if (isAjax != null) return;

        if (StringUtils.equals(action, "removeSite")) {

            int index = Integer.parseInt(request.getParameter("_selected"));
            StudySite site = command.getStudy().getStudySites().get(index);

            if (site.getId() != null) {
                if (CollectionUtils.isNotEmpty(site.getActiveStudyInvestigators())) {
                  errors.reject("STU_013", "The site is associated to investigators, so unable to delete");
                }
                if (CollectionUtils.isNotEmpty(site.getActiveStudyPersonnel())) {
                  errors.reject("STU_014", "The site is associated to research staffs, so unable to delete");
                }<commit_msg>CAAERS-5777<commit_after>package gov.nih.nci.cabig.caaers.web.study;

import gov.nih.nci.cabig.caaers.dao.workflow.WorkflowConfigDao;
import gov.nih.nci.cabig.caaers.domain.Study;
import gov.nih.nci.cabig.caaers.domain.StudySite;
import gov.nih.nci.cabig.caaers.domain.StudyOrganization;
import gov.nih.nci.cabig.caaers.domain.Organization;
import gov.nih.nci.cabig.caaers.domain.workflow.StudySiteWorkflowConfig;
import gov.nih.nci.cabig.caaers.domain.workflow.WorkflowConfig;
import gov.nih.nci.cabig.caaers.web.fields.InputField;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldFactory;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroup;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroupMap;
import gov.nih.nci.cabig.caaers.web.fields.RepeatingFieldGroupFactory;

import java.util.*;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.validation.Errors;

/**
 * @author <NAME>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
class SitesTab extends StudyTab {

    private RepeatingFieldGroupFactory rfgFactory;
    private WorkflowConfigDao workflowConfigDao;
     
    public SitesTab() {
        super("Sites", "Sites", "study/study_sites");
    }
    
    @Override
    public Map<String, Object> referenceData(HttpServletRequest request,
    		StudyCommand command) {
    	for(StudySite site : command.getStudy().getActiveStudySites()){
    		site.getActiveStudyInvestigators().size();
    		site.getActiveStudyPersonnel().size();
    	}
    	return super.referenceData(request, command);
    }

    @Override
    public void postProcess(HttpServletRequest request, StudyCommand command, Errors errors) {
        String action = request.getParameter("_action");
        Object isAjax = request.getAttribute("_isAjax");

        if (isAjax != null) return;

        if (StringUtils.equals(action, "removeSite")) {

            int index = Integer.parseInt(request.getParameter("_selected"));
            StudySite site = command.getStudy().getStudySites().get(index);

            if (site.getId() != null) {
                if (CollectionUtils.isNotEmpty(site.getActiveStudyInvestigators())) {
                  errors.reject("STU_013", "The site is associated to investigators, so unable to delete");
                }
                if (CollectionUtils.isNotEmpty(site.getActiveStudyPersonnel())) {
                  errors.reject("STU_014", "The site is associated to research staffs, so unable to delete");
                }
{'fraction_non_alphanumeric': 0.11963377416073245, 'fraction_numerical': 0.0032553407934893183, 'mean_word_length': 3.7405978784956604, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '7154200', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1580, 'n_words': 248}