/*
 * 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.fidufosyga.rules;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import com.fidufosyga.context.Context;

/**
 *
 * @author Marinela.QuinteroT1
 */

    

public class ValidarPaisesNov extends AbstractRule {
	public static final String PAISES = "PAISES";

	public boolean performValidation(String field, String registro[],
			String nombreArchivo) {
            
            
        String campoTipoNovedad = (String) (getParams()[0]);
        int campoDepNovedad = Integer.parseInt(campoTipoNovedad);
        String TipoNovedad = registro[campoDepNovedad];
        
        
        String Novedad = (String) getParams()[1];
        
         if ( TipoNovedad.equals(Novedad)) {

		if (Context.getContext().getAttribute(PAISES) == null) {
			Properties defaultProps = new Properties();
			FileInputStream in;

			try {

				in = new FileInputStream(System.getProperty("user.dir")
						+ File.separator + "Paises" + File.separator
						+ "Paises.properties");
				defaultProps.load(in);
				in.close();
				Context.getContext().addAttribute(PAISES, defaultProps);

			} catch (FileNotFoundException e) {

				return false;
			} catch (IOException e) {

				return false;

			}

		}
		if (((Properties) Context.getContext().getAttribute(PAISES))
				.getProperty(field) != null) {
			return false;
		}
		return true;
	}
            return false;
}
}
