/**
  * Overrides base implementation to determine whether or not we are dealing with looking up the
  * model or editing it
  *
  * @see
  *     org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#setFieldConversions(java.util.Map)
  */
 @Override
 public void setFieldConversions(Map fieldConversions) {
   super.setFieldConversions(fieldConversions);
   if (fieldConversions == null || fieldConversions.size() == 0) {
     // if we don't have any field conversions, then we must be
     // actually dealing with the model, instead of looking up the model
     // in order to initalize a new global account delegate
     //
     // yeah, it's a hack...but at least a semi-clever hack
     initializingDelegate = false;
   }
 }
  /**
   * Validate trial balance search params: university fiscal year and period code
   *
   * @see
   *     org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#validateSearchParameters(java.util.Map)
   */
  @Override
  public void validateSearchParameters(Map fieldValues) {
    super.validateSearchParameters(fieldValues);

    String selectedFiscalYear =
        (String) fieldValues.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR);
    if (StringUtils.isNotBlank(selectedFiscalYear)) {
      try {
        int year = Integer.parseInt(selectedFiscalYear);
      } catch (NumberFormatException e) {
        GlobalVariables.getMessageMap()
            .putError(
                "universityFiscalYear",
                KFSKeyConstants.ERROR_CUSTOM,
                new String[] {"Fiscal Year must be a four-digit number"});
        throw new ValidationException("errors in search criteria");
      }
    }

    String selectedPeriodCode =
        (String) fieldValues.get(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE);

    if (StringUtils.isNotBlank(selectedPeriodCode)) {
      try {
        int period = Integer.parseInt(selectedPeriodCode);
        if (period <= 0 || period > 13) {
          GlobalVariables.getMessageMap()
              .putError(
                  "universityFiscalPeriodCode",
                  KFSKeyConstants.ERROR_CUSTOM,
                  new String[] {"Fiscal Period Code must be a number in the range of 01 to 13"});
          throw new ValidationException("errors in search criteria");
        }
      } catch (NumberFormatException e) {
        GlobalVariables.getMessageMap()
            .putError(
                "universityFiscalPeriodCode",
                KFSKeyConstants.ERROR_CUSTOM,
                new String[] {"Fiscal Period Code must be a number in the range of 01 to 13"});
        throw new ValidationException("errors in search criteria");
      }
    }
  }
 /**
  * Overridden to fix a field conversion
  *
  * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#setRows()
  */
 @Override
 protected void setRows() {
   super.setRows();
   convertOrganizationOwnerAccountField();
 }
 /**
  * This is a hack. This is called by Lookup's execute and it's just our way of making sure that
  * maint links are turned on, even for an otherwise erstwhile non-maintainable object
  *
  * @see
  *     org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#applyConditionalLogicForFieldDisplay()
  */
 @Override
 public void applyConditionalLogicForFieldDisplay() {
   super.applyConditionalLogicForFieldDisplay();
   LookupForm lookupForm = (LookupForm) KNSGlobalVariables.getKualiForm();
   lookupForm.setShowMaintenanceLinks(true);
 }
  /**
   * @see
   *     org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#validateSearchParameters(java.util.Map)
   */
  @Override
  public void validateSearchParameters(Map fieldValues) {
    // call super method to check validation against DD
    super.validateSearchParameters(fieldValues);

    // get field values
    String batchIdValue = (String) fieldValues.get(PdpPropertyConstants.BatchConstants.BATCH_ID);
    String paymentCountValue =
        (String) fieldValues.get(PdpPropertyConstants.BatchConstants.PAYMENT_COUNT);
    String paymentTotalAmountValue =
        (String) fieldValues.get(PdpPropertyConstants.BatchConstants.PAYMENT_TOTAL_AMOUNT);
    String fileCreationTimeValueLower =
        (String)
            fieldValues.get(
                KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX
                    + PdpPropertyConstants.BatchConstants.FILE_CREATION_TIME);
    String fileCreationTimeValueUpper =
        (String)
            fieldValues.get(
                KRADConstants.LOOKUP_DEFAULT_RANGE_SEARCH_UPPER_BOUND_LABEL
                    + PdpPropertyConstants.BatchConstants.FILE_CREATION_TIME);
    String chartCodeValue =
        (String) fieldValues.get(PdpPropertyConstants.BatchConstants.CHART_CODE);
    String orgCodeValue = (String) fieldValues.get(PdpPropertyConstants.BatchConstants.ORG_CODE);
    String subUnitCodeValue =
        (String) fieldValues.get(PdpPropertyConstants.BatchConstants.SUB_UNIT_CODE);

    // check if there is any search criteria entered
    if (StringUtils.isBlank(batchIdValue)
        && StringUtils.isBlank(chartCodeValue)
        && StringUtils.isBlank(orgCodeValue)
        && StringUtils.isBlank(subUnitCodeValue)
        && StringUtils.isBlank(paymentCountValue)
        && StringUtils.isBlank(paymentTotalAmountValue)
        && StringUtils.isBlank(fileCreationTimeValueLower)
        && StringUtils.isBlank(fileCreationTimeValueUpper)) {
      GlobalVariables.getMessageMap()
          .putError(
              KFSConstants.DOCUMENT_HEADER_ERRORS,
              PdpKeyConstants.BatchConstants.ErrorMessages.ERROR_BATCH_CRITERIA_NONE_ENTERED);
    } else if (StringUtils.isBlank(batchIdValue)
        && StringUtils.isBlank(paymentCountValue)
        && StringUtils.isBlank(paymentTotalAmountValue)) {
      // If batchId, paymentCount, and paymentTotalAmount are empty then at least creation date is
      // required
      if (StringUtils.isBlank(fileCreationTimeValueLower)
          && StringUtils.isBlank(fileCreationTimeValueUpper)) {
        GlobalVariables.getMessageMap()
            .putError(
                PdpPropertyConstants.BatchConstants.FILE_CREATION_TIME,
                PdpKeyConstants.BatchConstants.ErrorMessages.ERROR_BATCH_CRITERIA_NO_DATE);
      } else if (StringUtils.isBlank(fileCreationTimeValueLower)
          || StringUtils.isBlank(fileCreationTimeValueUpper)) {
        // If we have one (but not both) dates the user must enter either the chartCode, orgCode, or
        // subUnitCode
        if (StringUtils.isBlank(chartCodeValue)
            && StringUtils.isBlank(orgCodeValue)
            && StringUtils.isBlank(subUnitCodeValue)) {
          GlobalVariables.getMessageMap()
              .putError(
                  KRADConstants.GLOBAL_ERRORS,
                  PdpKeyConstants.BatchConstants.ErrorMessages.ERROR_BATCH_CRITERIA_SOURCE_MISSING);
        }
      }
    }

    if (GlobalVariables.getMessageMap().hasErrors()) {
      throw new ValidationException("errors in search criteria");
    }
  }