/**
   * Adds the activity status conditions for all the objects in the from clause.
   *
   * @param simpleConditionNodeCollection The SimpleConditionsNode Collection.
   * @param fromTables Set of tables in the from clause of the query.
   * @param simpleConditionsNode The last condition in the simpleConditionNode's Collection.
   */
  public void addActivityStatusConditions(Collection simpleConditionNodeCollection, Set fromTables)
      throws DAOException, ClassNotFoundException {
    // Creating aliasName set with full package names.
    // Required for checking the activityStatus.
    Iterator fromTableSetIterator = fromTables.iterator();
    // Check and get the activity status conditions for all the objects in the conditions.
    List activityStatusConditionList = new ArrayList();

    while (fromTableSetIterator.hasNext()) {
      String alias = (String) fromTableSetIterator.next();
      String className = getClassName(alias);
      SimpleConditionsNode activityStatusCondition = getActivityStatusCondition(alias, className);

      if (activityStatusCondition != null) {
        activityStatusCondition.getOperator().setOperator(Constants.AND_JOIN_CONDITION);
        activityStatusConditionList.add(activityStatusCondition);
      }
    }

    if (activityStatusConditionList.isEmpty() == false) {
      // Set the next operator of the last simple condition nodes as AND.
      Iterator iterator = simpleConditionNodeCollection.iterator();
      SimpleConditionsNode simpleConditionsNode = null;
      while (iterator.hasNext()) {
        simpleConditionsNode = (SimpleConditionsNode) iterator.next();
      }
      simpleConditionsNode.getOperator().setOperator(Constants.AND_JOIN_CONDITION);

      // Add the activity status conditions in the simple conditions node collection.
      simpleConditionNodeCollection.addAll(activityStatusConditionList);
    }
  }
  /**
   * Adds quotes to the value of the attribute whose type is string or date and returns the tables
   * in path for that object.
   *
   * @param simpleConditionsNode The conditio node to be checked.
   * @return The tables in path for that object.
   */
  private String addSingleQuotes(SimpleConditionsNode simpleConditionsNode) {
    String columnName = simpleConditionsNode.getCondition().getDataElement().getField();
    Logger.out.debug(" columnName:" + columnName);
    StringTokenizer stringToken = new StringTokenizer(columnName, ".");
    simpleConditionsNode.getCondition().getDataElement().setTable(stringToken.nextToken());
    Logger.out.debug(
        "tablename:" + simpleConditionsNode.getCondition().getDataElement().getTableAliasName());
    simpleConditionsNode.getCondition().getDataElement().setField(stringToken.nextToken());
    simpleConditionsNode.getCondition().getDataElement().setFieldType(stringToken.nextToken());
    String tableInPath = null;

    if (stringToken.hasMoreTokens()) {
      tableInPath = stringToken.nextToken();
    }

    Logger.out.debug("^^^^^^^^^^^Condition:" + simpleConditionsNode.getCondition());

    return tableInPath;
  }
  /**
   * Returns SimpleConditionsNode if the object named aliasName contains the activityStatus data
   * member, else returns null.
   *
   * @param aliasName The alias name of the object.
   * @param className The fully qualified name of the class in which activity status field is to be
   *     searched.
   * @return SimpleConditionsNode if the object named aliasName contains the activityStatus data
   *     member, else returns null.
   */
  private SimpleConditionsNode getActivityStatusCondition(String aliasName, String className)
      throws DAOException, ClassNotFoundException {
    SimpleConditionsNode activityStatusCondition = null;

    if (className.equals(Constants.REPORTED_PROBLEM_CLASS_NAME)) {
      return null;
    }
    // Returns the Class object if it is a valid class else returns null.
    Class classObject = edu.wustl.common.util.Utility.getClassObject(className);
    if (classObject != null) {
      Field[] objectFields = classObject.getDeclaredFields();

      for (int i = 0; i < objectFields.length; i++) {
        if (objectFields[i].getName().equals(Constants.ACTIVITY_STATUS)) {
          activityStatusCondition = new SimpleConditionsNode();
          activityStatusCondition.getCondition().getDataElement().setTableName(aliasName);
          activityStatusCondition
              .getCondition()
              .getDataElement()
              .setField(Constants.ACTIVITY_STATUS_COLUMN);
          activityStatusCondition.getCondition().getOperator().setOperator("!=");
          activityStatusCondition.getCondition().setValue(Constants.ACTIVITY_STATUS_DISABLED);
          activityStatusCondition
              .getCondition()
              .getDataElement()
              .setFieldType(Constants.FIELD_TYPE_VARCHAR);
          return activityStatusCondition;
        }
      }

      Class superClass = classObject.getSuperclass();
      if ((activityStatusCondition == null)
          && (superClass.getName().equals("edu.wustl.common.domain.AbstractDomainObject")
              == false)) {
        String superClassAliasName = getAliasName(superClass);
        activityStatusCondition =
            getActivityStatusCondition(superClassAliasName, superClass.getName());
      }
    }

    return activityStatusCondition;
  }
  /**
   * Adds single quotes (') for string and date type attributes in the condition collecion and the
   * returns the Set of objects to which the condition attributes belong.
   *
   * @param simpleConditionNodeCollection The condition collection.
   * @return the Set of objects to which the condition attributes belong.
   * @throws DAOException
   */
  public List handleStringAndDateConditions(
      Collection simpleConditionNodeCollection, List fromTables) throws DAOException {
    // Adding single quotes to strings and date values.
    Iterator iterator = simpleConditionNodeCollection.iterator();
    while (iterator.hasNext()) {
      SimpleConditionsNode simpleConditionsNode = (SimpleConditionsNode) iterator.next();

      // Add all the objects selected in UI to the fromtables Set.
      addInListIfNotPresent(
          fromTables, simpleConditionsNode.getCondition().getDataElement().getTableAliasName());

      // Adds single quotes to the value of attributes whose type is string or date.
      String tableInPath = addSingleQuotes(simpleConditionsNode);

      // Get the tables in path for this field and add it in the fromTables Set.
      if (tableInPath != null) {
        addTablesInPathToFromSet(fromTables, tableInPath);
      }

      addInListIfNotPresent(
          fromTables, simpleConditionsNode.getCondition().getDataElement().getTableAliasName());
    }
    return fromTables;
  }