Add a AbstractMetadataRepository to remove duplicated code

Remove a lot of duplications and make it easier to add new methods to MetadataRepository