<commit_before>package edu.asu.conceptpower.validation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import edu.asu.conceptpower.core.IConceptListManager;
import edu.asu.conceptpower.web.ConceptListAddForm;
import edu.asu.conceptpower.wordnet.Constants;

@Component
public class ConceptListAddValidator implements Validator {

	@Autowired
	private IConceptListManager conceptListManager;

	@Override
	public boolean supports(Class<?> arg0) {
		return arg0.isAssignableFrom(ConceptListAddForm.class);
	}

	@Override
	public void validate(Object target, Errors errors) {

		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "listName", "concept_name.required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "concept_description.required");

		if (!errors.hasErrors()) {
			ConceptListAddForm conceptListAddForm = (ConceptListAddForm) target;
			if (conceptListAddForm.getListName().equals(Constants.WORDNET_DICTIONARY)) {
				errors.rejectValue("listName", "concept_name.wordnet");
			}

			if (conceptListManager.checkExistingConceptList(conceptListAddForm.getListName())) {
				errors.rejectValue("listName", "concept_unique.required");
			}
		}

	}

}<commit_msg>Included old name for checking if the description alone has been changed in the concept list edit screen<commit_after>package edu.asu.conceptpower.validation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import edu.asu.conceptpower.core.IConceptListManager;
import edu.asu.conceptpower.web.ConceptListAddForm;
import edu.asu.conceptpower.wordnet.Constants;

@Component
public class ConceptListAddValidator implements Validator {

    @Autowired
    private IConceptListManager conceptListManager;

    @Override
    public boolean supports(Class<?> arg0) {
        return arg0.isAssignableFrom(ConceptListAddForm.class);
    }

    @Override
    public void validate(Object target, Errors errors) {

        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "listName", "concept_name.required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "concept_description.required");

        if (!errors.hasErrors()) {
            ConceptListAddForm conceptListAddForm = (ConceptListAddForm) target;
            if (conceptListAddForm.getListName().equals(Constants.WORDNET_DICTIONARY)) {
                errors.rejectValue("listName", "concept_name.wordnet");
            }

            if (!conceptListAddForm.getListName().equalsIgnoreCase(conceptListAddForm.getOldListName())) {

                if (conceptListManager.checkExistingConceptList(conceptListAddForm.getListName())) {
                    errors.rejectValue("listName", "concept_unique.required");
                }
            }
        }

    }

}
{'fraction_non_alphanumeric': 0.09499683343888538, 'fraction_numerical': 0.001266624445851805, 'mean_word_length': 4.926829268292683, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4159095', 'n_tokens_mistral': 922, 'n_tokens_neox': 862, 'n_words': 143}