예제 #1
0
  // this works as the setter of the fields
  public void addField(Field field) throws SessionInternalError {

    if (field.validate(locale) == OK) {
      if (field.getIsShown().intValue() == 1) {
        if (!isAgregated.booleanValue()) {
          if (field.isAgregated()) {
            isAgregated = new Boolean(true);
          }
        } else {
          if (!field.isAgregated()) {
            LOG.debug(
                "Can't add a non agregated field " + field.getColumnName() + " to this report");
            throw new SessionInternalError("Non agregated field" + " added to agregated report");
          }
        }
      }
      // add the field
      fields.add(field);
      // update some flags
      if (field.getOrdenable().intValue() == 1) {
        ordenable = new Boolean(true);
        ordenableFields = new Integer(ordenableFields.intValue() + 1);
      }
      if (field.getSelectable().intValue() == 1 && !selectable.booleanValue()) {
        selectable = new Boolean(true);
      }
      if (field.getWhereable().intValue() == 1 && !wherable.booleanValue()) {
        wherable = new Boolean(true);
      }
    } else {
      throw new SessionInternalError(
          "Adding field "
              + field.getTableName()
              + "."
              + field.getColumnName()
              + " but it is not valid");
    }
  }
예제 #2
0
  public boolean validate() {

    boolean retValue = true;
    int fieldsOrdered = 0;
    errorFields = new ArrayList();
    errorCodes = new ArrayList();

    LOG.debug("validating report. aggregated=" + isAgregated);

    int firstField = getFirstFieldIndex();

    if (getTitleKey() == null
        || getInstructionsKey() == null
        || fields == null
        || getTablesList() == null
        || getWhereStr() == null) {
      retValue = false;
      addError(ERROR_MISSING, -1);
      LOG.info("Missing fields.");
    } else {
      // go over each field and validate it
      for (int f = firstField; f < fields.size(); f++) {
        Field field = (Field) fields.get(f);
        int code = field.validate(locale);
        if (code != OK) {
          retValue = false;
          addError(code, f);
          LOG.info("Invalid field:" + field.getColumnName());
          break;
        }
        // verify that the select/group by is consistent
        if (isAgregated.booleanValue()) {
          if (!field.isAgregated() && field.getIsShown().intValue() == 1) {
            LOG.debug(
                "Field "
                    + field.getColumnName()
                    + " is not "
                    + "agregated for an agregated report");
            addError(ERROR_AGREGATE, f);
            retValue = false;
            break;
          }
        }

        if (field.getOrderPosition() != null) {
          // verify the value of the order by is within range
          int val = field.getOrderPosition().intValue();
          fieldsOrdered++;
          if (val > ordenableFields.intValue() || val < 1) {
            LOG.debug(
                "Field " + field.getColumnName() + " order " + "position is out of bounds:" + val);
            addError(ERROR_ORDER_RANGE, f);
            retValue = false;
            break;
          }
          // for aggregated reports, you can't order by a non
          // shown column
          if (isAgregated.booleanValue() && field.getIsShown().intValue() == 0) {
            addError(ERROR_ORDER_AGGREGATE, f);
            retValue = false;
            break;
          }
        }
      }
    }

    //  verify that the order values are consecutive
    if (fieldsOrdered > 0) {

      for (int done = 1; done <= fieldsOrdered; done++) {
        int f;
        for (f = firstField; f < fields.size(); f++) {
          Field field = (Field) fields.get(f);
          if (field.getOrderPosition() != null && field.getOrderPosition().intValue() == done) {
            break;
          }
        }
        if (f >= fields.size()) {
          LOG.debug("Order values are not consecutive");
          addError(ERROR_ORDER, -1);
          retValue = false;
          break;
        }
      }
    }

    return retValue;
  }