/*
 * 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;
import static com.fidufosyga.rules.ValidarDivipola.DIVIPOLA;


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

public class ValidarDivipolaNov extends AbstractRule {
	public static final String DIVIPOLA = "DIVIPOLA";

	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 (field == null || field.trim().isEmpty()) {
                return false;
            }
            if (field.length() > 5) {
                return true;
            }
            
		if (Context.getContext().getAttribute(DIVIPOLA) == null) {
			Properties defaultProps = new Properties();
			FileInputStream in;

			try {

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

			} catch (FileNotFoundException e) {

				return false;
			} catch (IOException e) {

				return false;

			}

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

        }
}
