public SpecifyQueryAdjusterForDomain() {
    permsOKForGlobalSearch =
        !AppContextMgr.isSecurityOn() || SpecifyUser.isCurrentUserType(UserType.Manager);

    // This kicks Global Search into gear if there is just one, but only for that one
    // divisionCnt   = BasicSQLUtils.getCountAsInt(CNT_TBL_SQL+"division");
    // disciplineCnt = BasicSQLUtils.getCountAsInt(CNT_TBL_SQL+"discipline");
    // collectionCnt = BasicSQLUtils.getCountAsInt(CNT_TBL_SQL+"collection");

  }
  /* (non-Javadoc)
   * @see edu.ku.brc.af.core.expresssearch.QueryAdjusterForDomain#adjustSQL(java.lang.String, boolean)
   */
  @Override
  public String adjustSQL(final String sql) {
    AppPreferences locPrefs = AppPreferences.getLocalPrefs();
    boolean doGlobalSearch =
        permsOKForGlobalSearch
            && locPrefs.getBoolean("GLOBAL_SEARCH_AVAIL", false)
            && locPrefs.getBoolean("GLOBAL_SEARCH", false);
    // divisionCnt++;
    // disciplineCnt++;
    // collectionCnt++;

    // SpecifyUser should NEVER be null nor the Id !
    SpecifyUser user = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
    if (user != null) {
      Integer id = user.getId();
      if (id != null) {
        String adjSQL = sql;
        if (StringUtils.contains(adjSQL, SPECIFYUSERID)) {
          adjSQL = StringUtils.replace(adjSQL, SPECIFYUSERID, Integer.toString(id));
        }

        if (StringUtils.contains(adjSQL, DIVID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || divisionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, DIVID);
          }

          if (adjustedSQL == null) {
            Integer divId = null;
            Division division = AppContextMgr.getInstance().getClassObject(Division.class);
            if (division != null) {
              divId = division.getId();
            } else {
              divId =
                  Agent.getUserAgent().getDivision() != null
                      ? Agent.getUserAgent().getDivision().getDivisionId()
                      : null;
            }

            if (divId != null) {
              adjSQL = StringUtils.replace(adjSQL, DIVID, Integer.toString(divId));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        // System.out.println(adjSQL);
        if (StringUtils.contains(adjSQL, COLMEMID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || collectionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, COLMEMID);
          }

          if (adjustedSQL == null) {
            Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);
            if (collection != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, COLMEMID, Integer.toString(collection.getCollectionId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, COLLID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || collectionCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, COLLID);
          }

          if (adjustedSQL == null) {
            Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);
            if (collection != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, COLLID, Integer.toString(collection.getCollectionId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, DSPLNID)) {
          String adjustedSQL = null;
          if (doGlobalSearch || disciplineCnt == 1) {
            adjustedSQL = removeSpecialFilter(adjSQL, DSPLNID);
          }

          if (adjustedSQL == null) {
            Discipline discipline = AppContextMgr.getInstance().getClassObject(Discipline.class);
            if (discipline != null) {
              adjSQL =
                  StringUtils.replace(
                      adjSQL, DSPLNID, Integer.toString(discipline.getDisciplineId()));
            }
          } else {
            adjSQL = adjustedSQL;
          }
        }

        if (StringUtils.contains(adjSQL, TAXTREEDEFID)) {
          TaxonTreeDef taxonTreeDef =
              AppContextMgr.getInstance().getClassObject(TaxonTreeDef.class);
          if (taxonTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, TAXTREEDEFID, Integer.toString(taxonTreeDef.getTaxonTreeDefId()));
          }
        }

        if (StringUtils.contains(adjSQL, GTPTREEDEFID)) {
          GeologicTimePeriodTreeDef gtpTreeDef =
              AppContextMgr.getInstance().getClassObject(GeologicTimePeriodTreeDef.class);
          if (gtpTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL,
                    GTPTREEDEFID,
                    Integer.toString(gtpTreeDef.getGeologicTimePeriodTreeDefId()));
          } else {
            return null;
          }
        }

        if (StringUtils.contains(adjSQL, STORTREEDEFID)) {
          StorageTreeDef locTreeDef =
              AppContextMgr.getInstance().getClassObject(StorageTreeDef.class);
          if (locTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, STORTREEDEFID, Integer.toString(locTreeDef.getStorageTreeDefId()));
          }
        }

        if (StringUtils.contains(adjSQL, LITHOTREEDEFID)) {
          LithoStratTreeDef lithoTreeDef =
              AppContextMgr.getInstance().getClassObject(LithoStratTreeDef.class);
          if (lithoTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL,
                    LITHOTREEDEFID,
                    Integer.toString(lithoTreeDef.getLithoStratTreeDefId()));
          } else {
            return null;
          }
        }

        if (StringUtils.contains(adjSQL, GEOTREEDEFID)) {
          GeographyTreeDef lithoTreeDef =
              AppContextMgr.getInstance().getClassObject(GeographyTreeDef.class);
          if (lithoTreeDef != null) {
            adjSQL =
                StringUtils.replace(
                    adjSQL, GEOTREEDEFID, Integer.toString(lithoTreeDef.getGeographyTreeDefId()));
          }
        }

        return adjSQL;
      }
      throw new RuntimeException("The SpecifyUser ID cannot be null!");

    } else {
      throw new RuntimeException("The SpecifyUser cannot be null!");
    }
  }