<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_metadata_as_dict(self, user_id=None, source=None):
 """ Convert a metadata json string into a dictionary. Args: user_id (int):
 Optional: Insert user_id into the metadata if specified source (string):
 Optional: Insert source (the name of the app typically) into the metadata if necessary. Returns: dict: THe metadata as a python dictionary """


        if self.metadata is None or self.metadata == "":
            return {}

        metadata_dict = self.metadata if isinstance(self.metadata, dict) else json.loads(self.metadata)

        # These should be set on all datasets by default, but we don't enforce this rigidly
        metadata_keys = [m.lower() for m in metadata_dict]
        if user_id is not None and 'user_id' not in metadata_keys:
            metadata_dict['user_id'] = six.text_type(user_id)

        if source is not None and 'source' not in metadata_keys:
            metadata_dict['source'] = six.text_type(source)

        return { k : six.text_type(v) for k, v in metadata_dict.items() }