/**
   * gets the relationship that the attribute represents on the class
   *
   * @param c - the class to which the attribute belongs
   * @param attributeName - property name for the attribute
   * @return a relationship definition for the attribute
   */
  @Override
  public RelationshipDefinition getDictionaryRelationship(Class<?> c, String attributeName) {
    DataDictionaryEntry entryBase =
        KRADServiceLocatorWeb.getDataDictionaryService()
            .getDataDictionary()
            .getDictionaryObjectEntry(c.getName());
    if (entryBase == null) {
      return null;
    }

    RelationshipDefinition relationship = null;

    List<RelationshipDefinition> ddRelationships = entryBase.getRelationships();

    int minKeys = Integer.MAX_VALUE;
    for (RelationshipDefinition def : ddRelationships) {
      // favor key sizes of 1 first
      if (def.getPrimitiveAttributes().size() == 1) {
        for (PrimitiveAttributeDefinition primitive : def.getPrimitiveAttributes()) {
          if (primitive.getSourceName().equals(attributeName)
              || def.getObjectAttributeName().equals(attributeName)) {
            relationship = def;
            minKeys = 1;
            break;
          }
        }
      } else if (def.getPrimitiveAttributes().size() < minKeys) {
        for (PrimitiveAttributeDefinition primitive : def.getPrimitiveAttributes()) {
          if (primitive.getSourceName().equals(attributeName)
              || def.getObjectAttributeName().equals(attributeName)) {
            relationship = def;
            minKeys = def.getPrimitiveAttributes().size();
            break;
          }
        }
      }
    }

    // check the support attributes
    if (relationship == null) {
      for (RelationshipDefinition def : ddRelationships) {
        if (def.hasIdentifier()) {
          if (def.getIdentifier().getSourceName().equals(attributeName)) {
            relationship = def;
          }
        }
      }
    }

    return relationship;
  }
  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;
  }