/*
 Copyright (C) 2004 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.sql.Connection;

import org.ensembl.healthcheck.DatabaseRegistryEntry;
import org.ensembl.healthcheck.ReportManager;
import org.ensembl.healthcheck.Team;
import org.ensembl.healthcheck.testcase.SingleDatabaseTestCase;


/**
 * An EnsEMBL Healthcheck test case that looks for correct analysis table structure
 */

public class AnalysisLogicName extends SingleDatabaseTestCase {

        /**
         * Create the analysis table.
         */
        public AnalysisLogicName() {

                addToGroup("post_genebuild");
                addToGroup("release");
                addToGroup("compara-ancestral");
                addToGroup("id_mapping");
                addToGroup("pre-compara-handover");
                addToGroup("post-compara-handover");

                setDescription("Check the analysis data is correct.");
                setSecondTeamResponsible(Team.GENEBUILD);

        }

       /**
         * Check the data in the analysis table.
         * 
         * @param dbre
         *          The database to use.
         * @return true if all data is there and in the correct format.
         */


        public boolean run(DatabaseRegistryEntry dbre) {

                boolean result = true;

                Connection con = dbre.getConnection();

                // check that db_version is not empty if not a raw compute

                int rows = getRowCount(con, "SELECT COUNT(*) FROM analysis where isnull(db_version) " );
                if (rows > 0) {
                         result = false ;
                         ReportManager.problem(this, con,  rows + " Analyses are missing db_version");
                }

                return result;

        }

}



@@ -1023,16 +1023,60 @@
 stCase;%0A
+import org.ensembl.healthcheck.util.Utils;%0A%0A
 %0A%0A/**%0A *
@@ -2069,17 +2069,16 @@
 = true;%0A
-%0A
         
@@ -2121,24 +2121,25 @@
 nection();%0A%0A
+%0A
             
@@ -2146,410 +2146,1530 @@
     
-// check that db_version is not empty if not a raw compute%0A%0A                int rows = getRowCount(con, %22SELECT COUNT(*) FROM analysis where isnull(db_version) %22 );%0A                if (rows %3E 0) %7B%0A                         result = false ;%0A                         ReportManager.problem(this, con,  rows + %22 Analyses are missing db_version%22);%0A                %7D%0A%0A                return result;%0A%0A        %7D
+result &= checkdbVersion(con);%0A                %0A                result &= checkLowerCase(con);%0A%0A                return result;%0A        %7D%0A%0A%0A        // ---------------------------------------------------------------------%0A%0A%0A       /**%0A         * Check that db_version is not empty if not a raw compute%0A         */%0A%0A%0A        private boolean checkdbVersion(Connection con) %7B%0A%0A                boolean result = true;%0A                int rows = getRowCount(con, %22SELECT COUNT(*) FROM analysis where isnull(db_version) %22 );%0A                if (rows %3E 0) %7B%0A                         result = false ;%0A                         ReportManager.problem(this, con,  rows + %22 Analyses are missing db_version%22);%0A                %7D%0A%0A                return result;%0A        %7D%0A%0A%0A%0A        // ---------------------------------------------------------------------%0A%0A%0A%0A       /**%0A         * Check all logic names are lower case %0A         */%0A%0A        private boolean checkLowerCase(Connection con) %7B%0A%0A                boolean result = true;%0A%0A                String%5B%5D logicNames = getColumnValues(con, %22SELECT logic_name FROM analysis where BINARY logic_name != lower(logic_name) %22);%0A                if (logicNames.length %3E 0) %7B%0A                        ReportManager.problem(this, con, %22The following logic_names are not lower case: %22 + Utils.arrayToString(logicNames,%22,%22) );%0A                %7D else %7B%0A                        ReportManager.correct(this, con, %22All logic names are lower case%22);%0A                %7D%0A%0A                return result;%0A        %7D%0A%0A
 %0A%0A%7D%0A

check if logic name lower case