@@ -0,0 +1,2979 @@
+/*%0A Copyright (C) 2003 EBI, GRL%0A %0A This library is free software; you can redistribute it and/or%0A modify it under the terms of the GNU Lesser General Public%0A License as published by the Free Software Foundation; either%0A version 2.1 of the License, or (at your option) any later version.%0A %0A This library is distributed in the hope that it will be useful,%0A but WITHOUT ANY WARRANTY; without even the implied warranty of%0A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A Lesser General Public License for more details.%0A %0A You should have received a copy of the GNU Lesser General Public%0A License along with this library; if not, write to the Free Software%0A Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA%0A */%0Apackage org.ensembl.healthcheck.testcase.generic;%0A%0Aimport java.sql.Connection;%0A%0Aimport org.ensembl.healthcheck.DatabaseRegistryEntry;%0Aimport org.ensembl.healthcheck.ReportManager;%0Aimport org.ensembl.healthcheck.testcase.SingleDatabaseTestCase;%0Aimport org.ensembl.healthcheck.util.Utils;%0A%0A/**%0A * Check that all xrefs for a particular external_db map to one%0A * and only one ensembl object type.%0A */%0A%0Apublic class XrefTypes extends SingleDatabaseTestCase %7B%0A%0A    /**%0A     * Create a new XrefTypes testcase.%0A     */%0A    public XrefTypes() %7B%0A%0A        addToGroup(%22post_genebuild%22);%0A        addToGroup(%22release%22);%0A%09addToGroup(%22xrefs%22);%0A        setDescription(%22Check that all xrefs only map to one ensembl object type.%22);%0A%0A    %7D%0A%0A    /**%0A     * Run the test.%0A     * %0A     * @param dbre%0A     *          The database to use.%0A     * @return true if the test pased.%0A     *  %0A     */%0A    public boolean run(DatabaseRegistryEntry dbre) %7B%0A%0A        boolean result = true;%0A        %0A%09Connection con = dbre.getConnection();%0A%0A%09String%5B%5D dbNames = getColumnValues(con, %22SELECT DISTINCT(db_name) FROM external_db WHERE db_name NOT LIKE 'AFFY%25'%22);%0A%09%09%09%09%09%09%09%09%09%09%09    %0A%09for (int i = 0; i %3C dbNames.length; i++) %7B%0A%0A%09    String dbName = dbNames%5Bi%5D;%0A%09    logger.fine(%22Checking object types for %22 + dbName);%0A%09    String sql = %22SELECT DISTINCT(ox.ensembl_object_type) FROM external_db e, xref x, object_xref ox WHERE e.external_db_id=x.external_db_id AND x.xref_id=ox.xref_id AND e.db_name='%22 + dbName + %22'%22;%0A%09    String%5B%5D objectTypes = getColumnValues(con, sql);%0A%0A%09    // note that since the same external_db table is used across all databases%0A%09    // it is allowable for some external_db entries to have no associated xrefs%0A%09    if (objectTypes.length == 1) %7B%0A%0A%09%09ReportManager.correct(this, con, %22Exactly one object type associated with %22 + dbName + %22 xrefs%22);%0A%09%09%0A%09    %7D else if (objectTypes.length %3E 1) %7B%0A%0A%09%09ReportManager.problem(this, con, dbName + %22 xrefs are associated with %22 + objectTypes.length + %22 Ensembl object types (%22 + Utils.arrayToString(objectTypes, %22,%22) + %22) - should only be one%22);%0A%09%09result = false;%0A%0A%09    %7D%0A%0A%09%7D%0A%0A        return result;%0A%0A    %7D // run%0A%0A    // ----------------------------------------------------------------------%0A%0A%7D // XrefTypes%0A

Check that no external_dbs have xrefs that are associated with more than one type of Ensembl object (which would break Mart).