<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ms.portalv1.validators;

import com.ms.portalv1.interfacedaos.RequestInterfaceDao;
import com.ms.portalv1.models.ServiceRequest;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 *
 * @author <NAME>
 * <EMAIL>
 * 02/julio/2014
 */
public class ServiceRequestValidator implements Validator{
    private static final String PATTERN_NUMERIC = "[0-9]*";
    private RequestInterfaceDao RequestDao;

    public RequestInterfaceDao getRequestDao() {
        return RequestDao;
    }

    public void setRequestDao(RequestInterfaceDao RequestDao) {
        this.RequestDao = RequestDao;
    }

    public void initValidator(RequestInterfaceDao RequestDao) {
        this.setRequestDao(RequestDao);
    }

    @Override
    public boolean supports(Class clazz) {
        return ServiceRequest.class.isAssignableFrom(clazz);
    }

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

        //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "pais","required.pais", "Seleccionar pa&iacute;s.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "codeArea", "required.codeArea", "Se requiere el c&oacute;digo de area.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "required.phone", "Se requiere el n&uacute;mero de tel&eacute;fono.");
        //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "typeLicence","required.typeLicence", "Seleccionar tipo de licencia");
        //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "totalMessage", "required.totalMessage", "Se requiere el numero de mensajes.");
        //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "frecuencyMessage", "required.frecuencyMessage", "Seleccionar frecuencia del mensaje");
        
        ServiceRequest sr = (ServiceRequest) target;
        
        try {
            if (!sr.getCodeArea().equals("") && !sr.getCodeArea().isEmpty()) {
                if(!sr.getCodeArea().matches(PATTERN_NUMERIC)){
                    errors.rejectValue("codeArea", "notnumeric.codeArea");
                }else{
                    if(sr.getCodeArea().length()!=2){
                        errors.rejectValue("codeArea", "length.codeArea");
                    }
                }
            }
        } catch (Exception e) {
            errors.rejectValue("codeArea", "required.codeArea");
        }
        
        try {
            if (!sr.getPhone().equals("") && !sr.getPhone().isEmpty()) {
                if(!sr.getPhone().matches(PATTERN_NUMERIC)){
                    errors.rejectValue("phone", "notnumeric.phone");
                }else{
                    if(sr.getPhone().length()!=8){
                        errors.rejectValue("phone", "length.phone");
                    }else{
                        
                    }
                }
            }
        } catch (Exception e) {
            errors.rejectValue("phone", "required.phone");
        }
        
        
        try {
            if (sr.getPais().equals("0") || sr.getPais().equals("") || sr.getPais().isEmpty()) {
                errors.rejectValue("pais", "required.pais");
            }
        } catch (Exception e) {
            errors.rejectValue("pais", "required.pais");
        }
        
        
        if(!errors.hasFieldErrors("pais") && !errors.hasFieldErrors("codeArea") && !errors.hasFieldErrors("phone")){
            errors.rejectValue("pais", "required.pais");
            if(this.getRequestDao().getCountPhoneForUser(sr.getPais()+sr.getCodeArea()+sr.getPhone(),sr.getIdent(), true)>0){
                errors.rejectValue("phone", "repeateduser.phone");
            }else{
                if(this.getRequestDao().getCountPhoneForOtherUser(sr.getPais()+sr.getCodeArea()+sr.getPhone(),sr.getIdent(), true)>0){
                    errors.rejectValue("phone", "repeateduser.phone");
                }
            }
        }
        
        
        try {
            if (sr.getTypeLicence().equals("0") || sr.getTypeLicence().equals("") || sr.getTypeLicence().isEmpty()) {
                errors.rejectValue("typeLicence", "required.typeLicence");
            }else{
                //Verificar si es tipo licencia FREE
                if(this.getRequestDao().getVerifyLicenseClass(sr.getTypeLicence())>0){
                    if(this.getRequestDao().getCountPhone(sr.getPhone(),sr.getIdent())>0){
                        errors.rejectValue("phone", "repeated.phone");
                    }
                }
            }
        } catch (Exception e) {
            errors.rejectValue("typeLicence", "required.typeLicence");
        }

        try {
            if (sr.getTotalMessage().equals("0") || sr.getTotalMessage().equals("") || sr.getTotalMessage().isEmpty()) {
                errors.rejectValue("totalMessage", "required.totalMessage");<commit_msg>se corrigio validacion erronea  de pais<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ms.portalv1.validators;

import com.ms.portalv1.interfacedaos.RequestInterfaceDao;
import com.ms.portalv1.models.ServiceRequest;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 *
 * @author <NAME>
 * <EMAIL>
 * 02/julio/2014
 */
public class ServiceRequestValidator implements Validator{
    private static final String PATTERN_NUMERIC = "[0-9]*";
    private RequestInterfaceDao RequestDao;

    public RequestInterfaceDao getRequestDao() {
        return RequestDao;
    }

    public void setRequestDao(RequestInterfaceDao RequestDao) {
        this.RequestDao = RequestDao;
    }

    public void initValidator(RequestInterfaceDao RequestDao) {
        this.setRequestDao(RequestDao);
    }

    @Override
    public boolean supports(Class clazz) {
        return ServiceRequest.class.isAssignableFrom(clazz);
    }

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

        //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "pais","required.pais", "Seleccionar pa&iacute;s.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "codeArea", "required.codeArea", "Se requiere el c&oacute;digo de area.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "required.phone", "Se requiere el n&uacute;mero de tel&eacute;fono.");
        //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "typeLicence","required.typeLicence", "Seleccionar tipo de licencia");
        //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "totalMessage", "required.totalMessage", "Se requiere el numero de mensajes.");
        //ValidationUtils.rejectIfEmptyOrWhitespace(errors, "frecuencyMessage", "required.frecuencyMessage", "Seleccionar frecuencia del mensaje");
        
        ServiceRequest sr = (ServiceRequest) target;
        
        try {
            if (!sr.getCodeArea().equals("") && !sr.getCodeArea().isEmpty()) {
                if(!sr.getCodeArea().matches(PATTERN_NUMERIC)){
                    errors.rejectValue("codeArea", "notnumeric.codeArea");
                }else{
                    if(sr.getCodeArea().length()!=2){
                        errors.rejectValue("codeArea", "length.codeArea");
                    }
                }
            }
        } catch (Exception e) {
            errors.rejectValue("codeArea", "required.codeArea");
        }
        
        try {
            if (!sr.getPhone().equals("") && !sr.getPhone().isEmpty()) {
                if(!sr.getPhone().matches(PATTERN_NUMERIC)){
                    errors.rejectValue("phone", "notnumeric.phone");
                }else{
                    if(sr.getPhone().length()!=8){
                        errors.rejectValue("phone", "length.phone");
                    }else{
                        
                    }
                }
            }
        } catch (Exception e) {
            errors.rejectValue("phone", "required.phone");
        }
        
        
        try {
            
            if (sr.getPais().equals("0") || sr.getPais().equals("") || sr.getPais().isEmpty()) {
                errors.rejectValue("pais", "required.pais");
            }
        } catch (Exception e) {
            errors.rejectValue("pais", "required.pais");
        }
        
        
        if(!errors.hasFieldErrors("pais") && !errors.hasFieldErrors("codeArea") && !errors.hasFieldErrors("phone")){
            if(this.getRequestDao().getCountPhoneForUser(sr.getPais()+sr.getCodeArea()+sr.getPhone(),sr.getIdent(), true)>0){
                errors.rejectValue("phone", "repeateduser.phone");
            }else{
                if(this.getRequestDao().getCountPhoneForOtherUser(sr.getPais()+sr.getCodeArea()+sr.getPhone(),sr.getIdent(), true)>0){
                    errors.rejectValue("phone", "repeateduser.phone");
                }
            }
        }
        
        
        try {
            if (sr.getTypeLicence().equals("0") || sr.getTypeLicence().equals("") || sr.getTypeLicence().isEmpty()) {
                errors.rejectValue("typeLicence", "required.typeLicence");
            }else{
                //Verificar si es tipo licencia FREE
                if(this.getRequestDao().getVerifyLicenseClass(sr.getTypeLicence())>0){
                    if(this.getRequestDao().getCountPhone(sr.getPhone(),sr.getIdent())>0){
                        errors.rejectValue("phone", "repeated.phone");
                    }
                }
            }
        } catch (Exception e) {
            errors.rejectValue("typeLicence", "required.typeLicence");
        }

        try {
            if (sr.getTotalMessage().equals("0") || sr.getTotalMessage().equals("") || sr.getTotalMessage().isEmpty()) {
                errors.rejectValue("totalMessage", "required.totalMessage");
{'fraction_non_alphanumeric': 0.13413197172034563, 'fraction_numerical': 0.003927729772191673, 'mean_word_length': 2.283365570599613, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '4556385', 'n_tokens_mistral': 2873, 'n_tokens_neox': 2797, 'n_words': 450}