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

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 gov.nih.nci.cabig.caaers.web.rule.RuleInputCommand;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanWrapper;
import org.springframework.validation.Errors;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Represents the first tab while authoring Rules.
 * 
 * @author <NAME>
 * @author <NAME>
 */
public class SelectRuleTypeTab extends TabWithFields<RuleInputCommand> {
    private static final Log logger = LogFactory.getLog(SelectRuleTypeTab.class);
    private static final String RULE_LEVEL_FIELD_GROUP = "RuleLevel";

    public SelectRuleTypeTab(String longTitle, String shortTitle, String viewName) {
        super(longTitle, shortTitle, viewName);
    }

    public SelectRuleTypeTab() {
        super("Rule Type", "Rule Type", "rule/author/selectRuleType");
    }

    @Override
    public Map<String, Object> referenceData(RuleInputCommand cmd) {
        Map<String, Object> refdata = super.referenceData();
        
        CreateRuleCommand command = (CreateRuleCommand) cmd;
        boolean initializeLevelSelect = false;
        boolean initializeRuleSetNameSelect = false;
        String initialLevel = "Please select a Rule level";
        String initialRuleSet = "Please select a RuleSet Name";
        if(command.getLevel() != null && !command.getLevel().equals("")){
        	initializeLevelSelect = true;
        	initialLevel = command.getLevel();
        }
        if(command.getRuleSetName() != null && !command.getRuleSetName().equals("")){
        	initializeRuleSetNameSelect = true;
        	initialRuleSet = command.getRuleSetName();
        }
        refdata.put("initializeLevelSelect", initializeLevelSelect);
        refdata.put("initializeRuleSetNameSelect", initializeRuleSetNameSelect);
        refdata.put("initialLevel", initialLevel);
        refdata.put("initialRuleSet", initialRuleSet);
        

        return refdata;
    }
    
    @Override
    public Map<String, InputFieldGroup> createFieldGroups(RuleInputCommand cmd) {
    	InputFieldGroupMap fieldMap = new InputFieldGroupMap();
    	
    	return fieldMap;
    }
    
    @Override
    public void postProcess(HttpServletRequest arg0, RuleInputCommand arg1, Errors arg2) {
        logger.debug("In SelectRuleTab post process");
        super.postProcess(arg0, arg1, arg2);

    }

    /**
     * Validates the input for the pressens of following :
     *  - RuleSet name
     *  - Rule Level
     *  - Sponsor or Institution
     *  - Study (if a study based rule)
     * @param cmd - The command object
     * @param commandBean  - A command wrapper
     * @param fieldGroups  - The fields
     * @param errors     - The errors object.
     */
    @Override
    public void validate(RuleInputCommand cmd, BeanWrapper commandBean, Map<String, InputFieldGroup> fieldGroups, Errors errors) {
        CreateRuleCommand command = (CreateRuleCommand) cmd;
        String level = command.getLevel();
        String ruleSetName = command.getRuleSetName();

        if(StringUtils.isEmpty(ruleSetName)){
           errors.rejectValue("ruleSetName", "RUL_010");
           return;
        }

        if(StringUtils.isEmpty(level)){
           errors.rejectValue("level", "RUL_014");
           return;
        }

        if(command.isSponsorBased() && command.getSponsor() == null){
           errors.rejectValue("sponsor", "RUL_011");
        }
        if(command.isInstitutionBased() && command.getInstitution() == null){
           errors.rejectValue("institution", "RUL_013"); <commit_msg>CAAERS-2325 - Refactoring : SAE Rules, work based on Oranization name, but Oranization name is not UNIQUE<commit_after>package gov.nih.nci.cabig.caaers.web.rule.author;

import gov.nih.nci.cabig.caaers.rules.common.RuleType;
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 gov.nih.nci.cabig.caaers.web.rule.RuleInputCommand;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanWrapper;
import org.springframework.validation.Errors;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Represents the first tab while authoring Rules.
 * 
 * @author <NAME>
 * @author <NAME>
 */
public class SelectRuleTypeTab extends TabWithFields<RuleInputCommand> {
    private static final Log logger = LogFactory.getLog(SelectRuleTypeTab.class);
    private static final String RULE_LEVEL_FIELD_GROUP = "RuleLevel";

    public SelectRuleTypeTab(String longTitle, String shortTitle, String viewName) {
        super(longTitle, shortTitle, viewName);
    }

    public SelectRuleTypeTab() {
        super("Rule Type", "Rule Type", "rule/author/selectRuleType");
    }

    @Override
    public Map<String, Object> referenceData(RuleInputCommand cmd) {
        Map<String, Object> refdata = super.referenceData();
        
        CreateRuleCommand command = (CreateRuleCommand) cmd;
        boolean initializeLevelSelect = false;
        boolean initializeRuleSetNameSelect = false;
        String initialLevel = "Please select a Rule level";
        String initialRuleSet = "Please select a RuleSet Name";
        if(command.getLevel() != null && !command.getLevel().equals("")){
        	initializeLevelSelect = true;
        	initialLevel = command.getLevel();
        }
        if(command.getRuleSetName() != null && !command.getRuleSetName().equals("")){
        	initializeRuleSetNameSelect = true;
        	initialRuleSet = command.getRuleSetName();
        }
        refdata.put("initializeLevelSelect", initializeLevelSelect);
        refdata.put("initializeRuleSetNameSelect", initializeRuleSetNameSelect);
        refdata.put("initialLevel", initialLevel);
        refdata.put("initialRuleSet", initialRuleSet);
        

        return refdata;
    }
    
    @Override
    public Map<String, InputFieldGroup> createFieldGroups(RuleInputCommand cmd) {
    	InputFieldGroupMap fieldMap = new InputFieldGroupMap();
    	
    	return fieldMap;
    }
    
    @Override
    public void postProcess(HttpServletRequest arg0, RuleInputCommand arg1, Errors arg2) {
        logger.debug("In SelectRuleTab post process");
        super.postProcess(arg0, arg1, arg2);

    }

    /**
     * Validates the input for the pressens of following :
     *  - RuleSet name
     *  - Rule Level
     *  - Sponsor or Institution
     *  - Study (if a study based rule)
     * @param cmd - The command object
     * @param commandBean  - A command wrapper
     * @param fieldGroups  - The fields
     * @param errors     - The errors object.
     */
    @Override
    public void validate(RuleInputCommand cmd, BeanWrapper commandBean, Map<String, InputFieldGroup> fieldGroups, Errors errors) {
        CreateRuleCommand command = (CreateRuleCommand) cmd;
        String level = command.getLevel();
        String ruleSetName = command.getRuleSetName();

        if(StringUtils.isEmpty(ruleSetName)){
           errors.rejectValue("ruleSetName", "RUL_010");
           return;
        }
        //for field level rules ignore further validations. 
        if(StringUtils.equals(ruleSetName,  RuleType.FIELD_LEVEL_RULES.getName())) {
            return;
        }

        if(StringUtils.isEmpty(level)){
           errors.rejectValue("level", "RUL_014");
           return;
        }

        if(command.isSponsorBased() && command.getSponsor() == null){
           errors.rejectValue("sponsor", "RUL_011");
        }
        if(command.isInstitutionBased() && command.getInstitution() == null){
           errors.rejectValue("institution", "RUL_013"); 
{'fraction_non_alphanumeric': 0.10493140526510938, 'fraction_numerical': 0.004943764676801384, 'mean_word_length': 3.14974358974359, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '7595047', 'n_tokens_mistral': 2337, 'n_tokens_neox': 2293, 'n_words': 496}