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

import java.util.Map;

import gov.nih.nci.cabig.caaers.CaaersSystemException;
import gov.nih.nci.cabig.caaers.domain.ReportPerson;
import gov.nih.nci.cabig.caaers.domain.report.Report;
import gov.nih.nci.cabig.caaers.web.fields.DefaultInputFieldGroup;
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.TabWithFields;

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

/**
 * @author Kulasekaran
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class SubmitterTab extends TabWithFields<ExpeditedAdverseEventInputCommand> {

    public SubmitterTab() {
        super("Submitter info", "Submitter", "ae/submitter");
    }

    @Override
    @SuppressWarnings("unchecked")
    public InputFieldGroupMap createFieldGroups(ExpeditedAdverseEventInputCommand command) {
        String reportIndex = ((SubmitExpeditedAdverseEventCommand) command).getReportIndex();
        if (reportIndex == null) {
            throw new CaaersSystemException("Report Index Not Defined");
        }
        InputFieldGroupMap map = new InputFieldGroupMap();
        map.addInputFieldGroup(createPersonGroup("reporter", null));
        map.addInputFieldGroup(createPersonGroup("reports[" + reportIndex + "].lastVersion.submitter", "submitter"));
        return map;
    }

    private InputFieldGroup createPersonGroup(String person, String name) {
        String groupName = name == null ? person : name;
        InputFieldGroup group = new DefaultInputFieldGroup(groupName, StringUtils
                        .capitalize(person)
                        + " details");
        String base = "aeReport." + person + '.';
        group.getFields().add(InputFieldFactory.createTextField(base + "firstName", "First name", true));
        group.getFields().add(InputFieldFactory.createTextField(base + "middleName","Middle name", false));
        group.getFields().add(InputFieldFactory.createTextField(base + "lastName", "Last name", true));
        group.getFields().add(createContactField(base, ReportPerson.EMAIL, "E-mail address", true));
        InputField phoneField = createContactField(base, ReportPerson.PHONE, "Phone", true);
        phoneField.getAttributes().put(InputField.EXTRA_VALUE_PARAMS, "phone-number");
        InputField faxField = createContactField(base, ReportPerson.FAX, "Fax", true);
        faxField.getAttributes().put(InputField.EXTRA_VALUE_PARAMS, "phone-number");
        
        group.getFields().add(phoneField);
        group.getFields().add(faxField);
        
        return group;
    }


    private InputField createContactField(String base, String contactType, String displayName, boolean required) {
        return InputFieldFactory.createTextField(base + "contactMechanisms[" + contactType + ']', displayName, required);
    }
    
    @Override
    protected void validate(ExpeditedAdverseEventInputCommand command,BeanWrapper commandBean, Map<String, InputFieldGroup> fieldGroups,Errors errors) {
    	//check if the report is in submittable state?
    	String reportIndex = ((SubmitExpeditedAdverseEventCommand) command).getReportIndex();
    	if(StringUtils.isNotEmpty(reportIndex)){
    		Report report = command.getAeReport().getReports().get(Integer.parseInt(reportIndex));
    		if(!report.isActive()){
    			errors.reject("SAE_032", new Object[]{report.getStatus().getDisplayName()},
    					"Cannot submit this report, as it is already submitted/withdrawn/amended/replaced");
    		}
    	}
    }


}<commit_msg>CAAERS-2499<commit_after>package gov.nih.nci.cabig.caaers.web.ae;

import java.util.Map;

import gov.nih.nci.cabig.caaers.CaaersSystemException;
import gov.nih.nci.cabig.caaers.domain.ReportPerson;
import gov.nih.nci.cabig.caaers.domain.report.Report;
import gov.nih.nci.cabig.caaers.web.fields.DefaultInputFieldGroup;
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.TabWithFields;

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

/**
 * @author Kulasekaran
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class SubmitterTab extends TabWithFields<ExpeditedAdverseEventInputCommand> {

    public SubmitterTab() {
        super("Submitter info", "Submitter", "ae/submitter");
    }

    @Override
    @SuppressWarnings("unchecked")
    public InputFieldGroupMap createFieldGroups(ExpeditedAdverseEventInputCommand command) {
        String reportIndex = ((SubmitExpeditedAdverseEventCommand) command).getReportIndex();
        if (reportIndex == null) {
            throw new CaaersSystemException("Report Index Not Defined");
        }
        InputFieldGroupMap map = new InputFieldGroupMap();
        map.addInputFieldGroup(createPersonGroup("reporter", null));
        map.addInputFieldGroup(createPersonGroup("reports[" + reportIndex + "].lastVersion.submitter", "submitter"));
        return map;
    }

    private InputFieldGroup createPersonGroup(String person, String name) {
        String groupName = name == null ? person : name;
        InputFieldGroup group = new DefaultInputFieldGroup(groupName, StringUtils
                        .capitalize(person)
                        + " details");
        String base = "aeReport." + person + '.';
        group.getFields().add(InputFieldFactory.createTextField(base + "firstName", "First name", true));
        group.getFields().add(InputFieldFactory.createTextField(base + "middleName","Middle name", false));
        group.getFields().add(InputFieldFactory.createTextField(base + "lastName", "Last name", true));
        group.getFields().add(createContactField(base, ReportPerson.EMAIL, "E-mail address", true));
        InputField phoneField = createContactField(base, ReportPerson.PHONE, "Phone", true);
        phoneField.getAttributes().put(InputField.EXTRA_VALUE_PARAMS, "phone-number");
        InputField faxField = createContactField(base, ReportPerson.FAX, "Fax", true);
        faxField.getAttributes().put(InputField.EXTRA_VALUE_PARAMS, "phone-number");
        
        group.getFields().add(phoneField);
        group.getFields().add(faxField);
        
        return group;
    }


    private InputField createContactField(String base, String contactType, String displayName, boolean required) {
        return InputFieldFactory.createTextField(base + "contactMechanisms[" + contactType + ']', displayName, required);
    }
    


}
{'fraction_non_alphanumeric': 0.11900329371330373, 'fraction_numerical': 0.001002434483746241, 'mean_word_length': 3.9743589743589745, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '7324626', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2062, 'n_words': 352}