Graphene on a metal surface with an h-BN buffer layer: gap opening and N-doping