Ejemplo n.º 1
0
  /**
   * Test various things about marker features.
   *
   * @param dbre The database to use.
   * @return Result.
   */
  public boolean run(DatabaseRegistryEntry dbre) {

    boolean result = true;

    Connection con = dbre.getConnection();

    // only check for human, mouse, rat and zebrafish
    Species s = dbre.getSpecies();
    if ((dbre.getType() != DatabaseType.SANGER_VEGA
            && (s.equals(Species.HOMO_SAPIENS)
                || s.equals(Species.MUS_MUSCULUS)
                || s.equals(Species.RATTUS_NORVEGICUS)))
        || s.equals(Species.DANIO_RERIO)) { // for
      // sangervega
      // only
      // run
      // the
      // test
      // for
      // zebrafish

      result &= checkFeaturesAndMapWeights(con);

      result &= checkMarkerPriorities(con);

      result &= checkAllChromosomesHaveMarkers(con);
    }

    return result;
  } // run
  /**
   * Re-implementation of the compare tables in schema method used to detect if two schemas are
   * equal to each other. This is due to variation specific logic which means that schemas can
   * differ but this is still valid.
   *
   * <p>The logic is the same as variation's original version
   *
   * @param master The master connection
   * @param targetDbre The registry entry for the given target schema
   * @param ignoreBackupTables Ignored option
   * @param directionFlag Ignored option
   */
  @Override
  public boolean compareTableEquality(
      Connection master,
      DatabaseRegistryEntry targetDbre,
      boolean ignoreBackupTables,
      int directionFlag) {
    boolean result = true;

    Connection target = targetDbre.getConnection();
    String targetName = getDbNameForMsg(target);
    String masterName = getDbNameForMsg(master);

    Set<String> targetTables = createLinkedHashSet(getTableNames(target));
    Set<String> masterTables = createLinkedHashSet(getTableNames(master));

    Species species = targetDbre.getSpecies();

    Set<String> notRequired = getSets(notRequiredTables(), species);
    Set<String> required = getSets(requiredTables(), species);

    // Check that tables that are in the master are in the target & skip those
    // in the notRequired list
    for (String masterTable : masterTables) {
      if (notRequired.contains(masterTable)) {
        String msg =
            String.format(
                "Table `%s` is in the list of 'notRequiredTables()' exceptions for %s. Skipping",
                masterTable, species.getAlias());
        ReportManager.info(this, target, msg);
        continue;
      }
      if (!targetTables.contains(masterTable)) {
        String msg =
            String.format(
                "Table `%s` exists in `%s` but not in `%s`", masterTable, masterName, targetName);
        ReportManager.problem(this, target, msg);
        result = false;
      }
    }

    // Check that tables in the target are in the master & it was a required table
    for (String targetTable : targetTables) {
      if (!masterTables.contains(targetTable) && !required.contains(targetTable)) {
        String msg =
            String.format(
                "Table `%s` exists in `%s` but not in `%s`", targetTable, targetName, masterName);
        ReportManager.problem(this, target, msg);
        result = false;
      }
    }

    // Finally check for the required tables
    for (String table : required) {
      if (!targetTables.contains(table)) {
        String msg = String.format("Table `%s` does not exist in `%s`", table, targetName);
        ReportManager.problem(this, target, msg);
        result = false;
      }
    }

    return result;
  }