/*
 * ValidarCIIUMCNovedad.java
 *
 * Created on 28 de marzo de 2007, 03:28 PM
 *
 * To change this template, choose Tools | Template Manager
 * 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 Jsolano
 */
public class ValidarCIIUMCNovedadNC extends AbstractRule {
	public static final String CIIUS = "CIIU";

	public boolean performValidation(String field, String registro[],
			String nombreArchivo) {
		String codigoReturnCampo = registro[new Integer((String) getParams()[0])
				.intValue()];
		if (codigoReturnCampo.equals((String) getParams()[1])) {

			if (!registro[18].equals("4") && !registro[18].equals("10")
					&& !registro[18].equals("11")) {

				if (!field.equals("8890")) {
					if (Context.getContext().getAttribute(CIIUS) == null) {
						Properties defaultProps = new Properties();
						FileInputStream in;

						try {

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

						} catch (FileNotFoundException e) {

							return false;
						} catch (IOException e) {

							return false;

						}

					}

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

			} else {
				if (registro[18].equals("4") && !field.equals("8890")) {
					return true;
				} else if (registro[18].equals("10")
						|| registro[18].equals("11")) {
					if (field.length() > 0) {
						return true;
					}
				}
			}
		}

		return false;

	}
}
