class ExternalInterfaceServiceImpl implements ExternalInterfaceService {

    @Override
    public ExternalInterface createExternalInterface(ExternalInterfaceCreateRequest request)
    {
        // Perform the validation.
        validateExternalInterfaceCreateRequest(request);

        // Ensure an external interface with the specified external interface name doesn't already exist.
        ExternalInterfaceEntity externalInterfaceEntity =
            externalInterfaceDao.getExternalInterfaceByName(request.getExternalInterfaceKey().getExternalInterfaceName());
        if (externalInterfaceEntity != null)
        {
            throw new AlreadyExistsException(String
                .format("Unable to create external interface \"%s\" because it already exists.", request.getExternalInterfaceKey().getExternalInterfaceName()));
        }

        // Create an external interface entity from the request information.
        externalInterfaceEntity = createExternalInterfaceEntity(request);

        // Persist the new entity.
        externalInterfaceEntity = externalInterfaceDao.saveAndRefresh(externalInterfaceEntity);

        // Create and return the external interface object from the persisted entity.
        return createExternalInterfaceFromEntity(externalInterfaceEntity);
    }

}