/*
 * Copyright (C) 2003 EBI, GRL
 * 
 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ensembl.healthcheck.testcase.generic;

import java.util.ArrayList;
import java.util.List;

import org.ensembl.healthcheck.DatabaseRegistryEntry;
import org.ensembl.healthcheck.testcase.Priority;
import org.ensembl.healthcheck.testcase.SingleDatabaseTestCase;
import org.ensembl.healthcheck.DatabaseType;

/**
 * Check that the content of the master_* tables in the production databases matches the equivalent table in this database.
 */

public class ProductionMasterTables extends SingleDatabaseTestCase {

	/**
	 * Constructor.
	 */
	public ProductionMasterTables() {

		addToGroup("production");
		addToGroup("release");
		setDescription("Check that the content of the master_* tables in the production databases matches the equivalent table in this database");
		setPriority(Priority.AMBER);
		setEffect("Discrepancies between tables can cause problems.");
		setFix("Resync tables");
		setTeamResponsible("Release coordinator");

	}

    /**
	 * This test Does not apply to sanger_vega dbs
	 */
	public void types() {
		removeAppliesToType(DatabaseType.SANGER_VEGA);
	}

	/**
	 * Run the test.
	 * 
	 * @param dbre
	 *          The database to use.
	 * @return true if the test passed.
	 * 
	 */
	public boolean run(DatabaseRegistryEntry dbre) {

		boolean result = true;

		// compare all columns of some tables
		String[] tables = { "attrib_type", "misc_set" };

		for (String table : tables) {

			String key = table + "_id";
			result &= compareProductionTable(dbre, table, key, "master_" + table, key);

		}
		
		// external_db is an exception as we don't want to consider db_release
		List<String> exceptions = new ArrayList<String>();
		exceptions.add("db_release");
		
		result &= compareProductionTableWithExceptions(dbre, "external_db", "external_db_id", "master_external_db", "external_db_id", exceptions);
		
		return result;

	} // run

} // ProductionMasterTables

@@ -2018,16 +2018,17 @@
 bre) %7B%0A%0A
+%0A
 %09%09boolea
@@ -2045,16 +2045,477 @@
  true;%0A%0A
+%09%09String%5B%5D tables = %7B %22attrib_type%22, %22misc_set%22, %22external_db%22 %7D;%0A%0A%09%09List%3CString%3E exceptions = new ArrayList%3CString%3E();%0A%09%09exceptions.add(%22is_current%22);%0A%09%09exceptions.add(%22created_by%22);%0A%09%09exceptions.add(%22created_at%22);%0A%09%09exceptions.add(%22modified_by%22);%0A%09%09exceptions.add(%22modified_at%22);%0A%0A%09%09for (String table : tables) %7B%0A%09%09%09String key = table + %22_id%22;%0A%09%09%09result &= compareProductionTableWithExceptions(dbre, table, key, %22master_%22 + table, key, exceptions);%0A%09%09%7D%0A%0A%09%09/*%0A
 %09%09// com
@@ -3049,24 +3049,27 @@
 eptions);%0A%09%09
+*/%0A
 %0A%09%09return re

update to current columns in production master tables