/**
  * Creates and returns a business object data attribute key from a specified business object data
  * attribute entity.
  *
  * @param businessObjectDataAttributeEntity the business object data attribute entity
  * @return the newly created business object data attribute key
  */
 private BusinessObjectDataAttributeKey getBusinessObjectDataAttributeKey(
     BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity) {
   return new BusinessObjectDataAttributeKey(
       businessObjectDataAttributeEntity
           .getBusinessObjectData()
           .getBusinessObjectFormat()
           .getBusinessObjectDefinition()
           .getNamespace()
           .getCode(),
       businessObjectDataAttributeEntity
           .getBusinessObjectData()
           .getBusinessObjectFormat()
           .getBusinessObjectDefinition()
           .getName(),
       businessObjectDataAttributeEntity
           .getBusinessObjectData()
           .getBusinessObjectFormat()
           .getUsage(),
       businessObjectDataAttributeEntity
           .getBusinessObjectData()
           .getBusinessObjectFormat()
           .getFileType()
           .getCode(),
       businessObjectDataAttributeEntity
           .getBusinessObjectData()
           .getBusinessObjectFormat()
           .getBusinessObjectFormatVersion(),
       businessObjectDataAttributeEntity.getBusinessObjectData().getPartitionValue(),
       dmHelper.getSubPartitionValues(businessObjectDataAttributeEntity.getBusinessObjectData()),
       businessObjectDataAttributeEntity.getBusinessObjectData().getVersion(),
       businessObjectDataAttributeEntity.getName());
 }
  /**
   * Deletes an existing business object data attribute by key.
   *
   * @param businessObjectDataAttributeKey the business object data attribute key
   * @return the business object data attribute that got deleted
   */
  @Override
  public BusinessObjectDataAttribute deleteBusinessObjectDataAttribute(
      BusinessObjectDataAttributeKey businessObjectDataAttributeKey) {
    // Validate and trim the key.
    dmHelper.validateBusinessObjectDataAttributeKey(businessObjectDataAttributeKey);

    // If namespace is not specified, get the namespace code by locating the legacy business object
    // definition.
    populateLegacyNamespace(businessObjectDataAttributeKey);

    // Get the business object format and ensure it exists.
    BusinessObjectFormatEntity businessObjectFormatEntity =
        dmDaoHelper.getBusinessObjectFormatEntity(
            new BusinessObjectFormatKey(
                businessObjectDataAttributeKey.getNamespace(),
                businessObjectDataAttributeKey.getBusinessObjectDefinitionName(),
                businessObjectDataAttributeKey.getBusinessObjectFormatUsage(),
                businessObjectDataAttributeKey.getBusinessObjectFormatFileType(),
                businessObjectDataAttributeKey.getBusinessObjectFormatVersion()));

    // Make sure we are not trying to delete a required attribute.
    if (dmDaoHelper.isBusinessObjectDataAttributeRequired(
        businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(),
        businessObjectFormatEntity)) {
      throw new IllegalArgumentException(
          String.format(
              "Cannot delete \"%s\" attribute since it is a required attribute for business object format {%s}.",
              businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(),
              dmDaoHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
    }

    // Retrieve and ensure that a business object data attribute exists with the specified key.
    BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity =
        dmDaoHelper.getBusinessObjectDataAttributeEntity(businessObjectDataAttributeKey);

    // Delete the business object data attribute.
    BusinessObjectDataEntity businessObjectDataEntity =
        businessObjectDataAttributeEntity.getBusinessObjectData();
    businessObjectDataEntity.getAttributes().remove(businessObjectDataAttributeEntity);
    dmDao.saveAndRefresh(businessObjectDataEntity);

    // Create and return the business object data attribute object from the deleted entity.
    return createBusinessObjectDataAttributeFromEntity(businessObjectDataAttributeEntity);
  }