class PermissionConverter implements ToClientConverter<ObjectPermission, RepositoryPermission, ToClientConversionOptions>, ToServerConverter<RepositoryPermission, ObjectPermission, ToServerConversionOptions> {

    public RepositoryPermission toClient(ObjectPermission serverObject, ToClientConversionOptions options) {
        RepositoryPermission client = new RepositoryPermission(stripRepo(serverObject.getURI()), null, serverObject.getPermissionMask());

        if (serverObject.getPermissionRecipient() instanceof InternalURI){
            client.setRecipient(((InternalURI) serverObject.getPermissionRecipient()).getURI());
        } else if (serverObject.getPermissionRecipient() instanceof MetadataUserDetails) {
            User internalUri = new UserImpl(), metaUser = (User)serverObject.getPermissionRecipient();
            internalUri.setUsername(metaUser.getUsername());
            internalUri.setTenantId(metaUser.getTenantId());
            client.setRecipient(((InternalURI) internalUri).getURI());
        }
        return client;
    }

}