class BusinessObjectFormatExternalInterfaceServiceImpl implements BusinessObjectFormatExternalInterfaceService {

    @Override
    public BusinessObjectFormatExternalInterface createBusinessObjectFormatExternalInterface(
        BusinessObjectFormatExternalInterfaceCreateRequest businessObjectFormatExternalInterfaceCreateRequest)
    {
        // Validate and trim the business object format to external interface mapping create request.
        businessObjectFormatExternalInterfaceHelper
            .validateAndTrimBusinessObjectFormatExternalInterfaceCreateRequest(businessObjectFormatExternalInterfaceCreateRequest);

        // Get a business object format key from the request. Please note that the key is version-less.
        BusinessObjectFormatKey businessObjectFormatKey =
            new BusinessObjectFormatKey(businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getNamespace(),
                businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectDefinitionName(),
                businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectFormatUsage(),
                businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectFormatFileType(), null);

        // Get an external interface name from the request.
        String externalInterfaceName =
            businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getExternalInterfaceName();

        // Retrieve and ensure that a business object format with the specified alternate key values exists.
        BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);

        // Retrieve and ensure that an external interface with the specified name exists.
        ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDaoHelper.getExternalInterfaceEntity(externalInterfaceName);

        // Ensure a business object format to external interface mapping with the specified parameters doesn't already exist.
        BusinessObjectFormatExternalInterfaceEntity businessObjectFormatExternalInterfaceEntity = businessObjectFormatExternalInterfaceDao
            .getBusinessObjectFormatExternalInterfaceByBusinessObjectFormatAndExternalInterface(businessObjectFormatEntity, externalInterfaceEntity);
        if (businessObjectFormatExternalInterfaceEntity != null)
        {
            throw new AlreadyExistsException(String.format("Unable to create business object format to external interface mapping for \"%s\" namespace, " +
                    "\"%s\" business object definition name, \"%s\" business object format usage, \"%s\" business object format file type, and " +
                    "\"%s\" external interface name because it already exists.", businessObjectFormatKey.getNamespace(),
                businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(),
                businessObjectFormatKey.getBusinessObjectFormatFileType(), externalInterfaceName));
        }

        // Creates a business object format to external interface mapping entity.
        businessObjectFormatExternalInterfaceEntity = new BusinessObjectFormatExternalInterfaceEntity();
        businessObjectFormatExternalInterfaceEntity.setBusinessObjectFormat(businessObjectFormatEntity);
        businessObjectFormatExternalInterfaceEntity.setExternalInterface(externalInterfaceEntity);

        // Persist the new entity.
        businessObjectFormatExternalInterfaceDao.saveAndRefresh(businessObjectFormatExternalInterfaceEntity);

        // Create a business object format to external interface mapping object from the entity and return it.
        return businessObjectFormatExternalInterfaceHelper.createBusinessObjectFormatExternalInterfaceFromEntity(businessObjectFormatExternalInterfaceEntity);
    }

}