NXP-14868: cleanup and factorization

See https://github.com/nuxeo/nuxeo-core/