/**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingExpression(java.lang.String)
   */
  public Pattern getAttributeValidatingExpression(String entryName, String attributeName) {
    Pattern regex = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null && (attributeDefinition.getValidationPattern() != null)) {
      regex = attributeDefinition.getValidationPattern().getRegexPattern();
    } else {
      // workaround for existing calls which don't bother checking for null return values
      regex = Pattern.compile(".*");
    }

    return regex;
  }
 /**
  * @see
  *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingErrorMessageKey(java.lang.String,
  *     java.lang.String)
  */
 public String getAttributeValidatingErrorMessageKey(String entryName, String attributeName) {
   AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
   if (attributeDefinition != null) {
     if (attributeDefinition.hasValidationPattern()) {
       ValidationPattern validationPattern = attributeDefinition.getValidationPattern();
       return validationPattern.getValidationErrorMessageKey();
     }
   }
   return null;
 }
 /**
  * @see
  *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingErrorMessageParameters(java.lang.String,
  *     java.lang.String)
  */
 public String[] getAttributeValidatingErrorMessageParameters(
     String entryName, String attributeName) {
   AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
   if (attributeDefinition != null) {
     if (attributeDefinition.hasValidationPattern()) {
       ValidationPattern validationPattern = attributeDefinition.getValidationPattern();
       String attributeLabel = getAttributeErrorLabel(entryName, attributeName);
       return validationPattern.getValidationErrorMessageParameters(attributeLabel);
     }
   }
   return null;
 }
  /**
   * Checks an account numbers exact length
   *
   * @param accountNumber
   * @param size to be returned
   * @return
   */
  protected boolean isValidAccountNumberLength(
      String accountNumber, AccountCreationStatusDTO accountCreationStatus) {

    boolean isValid = false;
    int fieldSize = -1;

    // grab account number length from DD and set size
    final org.kuali.rice.krad.datadictionary.BusinessObjectEntry entry =
        SpringContext.getBean(DataDictionaryService.class)
            .getDataDictionary()
            .getBusinessObjectEntry(Account.class.getName());
    AttributeDefinition attributeDefinition =
        entry.getAttributeDefinition(KFSPropertyConstants.ACCOUNT_NUMBER);

    if (ObjectUtils.isNotNull(attributeDefinition)) {
      final ValidationPattern validationPattern = attributeDefinition.getValidationPattern();

      if (ObjectUtils.isNotNull(validationPattern)
          && validationPattern instanceof AlphaNumericValidationPattern) {
        AlphaNumericValidationPattern alphaPattern =
            (AlphaNumericValidationPattern) validationPattern;
        fieldSize = alphaPattern.getExactLength();
      }
    }

    // skip if account number null
    if (ObjectUtils.isNotNull(accountNumber)) {

      // data dictionary defined size must equal length of incoming value
      if (fieldSize == accountNumber.length()) {
        isValid = true;
      }
    }

    if (isValid == false) {
      setFailStatus(
          accountCreationStatus,
          KcUtils.getErrorMessage(
              KcConstants.AccountCreationService.ERROR_KR_ALPHANUMERIC_VALIDATION_EXACT_LENGTH,
              new String[] {"account number", String.valueOf(fieldSize)}));
    }

    return isValid;
  }
  private boolean verifyProposaEditableColumnsDataType(MaintenanceDocument maintenanceDocument) {
    ProposalColumnsToAlter newEditableProposalField =
        (ProposalColumnsToAlter) maintenanceDocument.getNewMaintainableObject().getDataObject();
    KcPersistenceStructureService kraPersistenceStructureService =
        KcServiceLocator.getService(KcPersistenceStructureService.class);
    DataDictionaryService dataDictionaryService =
        (DataDictionaryService) KNSServiceLocator.getDataDictionaryService();
    Map<String, String> fieldMap =
        kraPersistenceStructureService.getDBColumnToObjectAttributeMap(ProposalOverview.class);
    DataDictionaryEntry entry =
        dataDictionaryService
            .getDataDictionary()
            .getDictionaryObjectEntry(ProposalDevelopmentDocument.class.getName());

    boolean returnFlag = true;
    String editableProposalField = "";
    Integer fieldMaxLength = -1;
    Integer inputDataLength = -1;
    String proposalFieldDataType = "";
    String inputDataType = "";
    ValidationPattern validatingPattern = null;

    if (newEditableProposalField != null
        && StringUtils.isNotEmpty(newEditableProposalField.getColumnName())) {
      editableProposalField = fieldMap.get(newEditableProposalField.getColumnName());
      if (StringUtils.isNotEmpty(editableProposalField)) {
        if (entry != null) {
          AttributeDefinition attributeDefinition =
              entry.getAttributeDefinition(editableProposalField);
          if (attributeDefinition != null && attributeDefinition.hasValidationPattern()) {
            validatingPattern = attributeDefinition.getValidationPattern();
            if (validatingPattern != null) {
              proposalFieldDataType =
                  validationClassesMap.get(validatingPattern.getClass().getName());
              inputDataType = newEditableProposalField.getDataType();
              if (!proposalFieldDataType.equalsIgnoreCase(inputDataType)) {
                // throw error
                GlobalVariables.getMessageMap()
                    .putError(
                        Constants.PROPOSAL_EDITABLECOLUMN_DATATYPE,
                        KeyConstants.PROPOSAL_EDITABLECOLUMN_DATATYPE_MISMATCH);
                returnFlag = false;
              }
            }
          }
        }

        inputDataLength = newEditableProposalField.getDataLength();
        fieldMaxLength =
            dataDictionaryService.getAttributeMaxLength(
                DevelopmentProposal.class, editableProposalField);
        if (fieldMaxLength > inputDataLength) {
          // throw error
          GlobalVariables.getMessageMap()
              .putError(
                  Constants.PROPOSAL_EDITABLECOLUMN_DATALENGTH,
                  KeyConstants.PROPOSAL_EDITABLECOLUMN_DATALENGTH_MISMATCH);
          returnFlag = false;
        }
      }
    }

    return returnFlag;
  }