<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add(self, organization, domain=None, is_top_domain=False, overwrite=False):
 """Add organizations and domains to the registry. This method adds the given 'organization' or 'domain' to the registry, but not both at the same time. When 'organization' is the only parameter given, it will be added to the registry. When 'domain' parameter is also given, the function will assign it to 'organization'. In this case, 'organization' must exists in the registry prior adding the domain. A domain can only be assigned to one company. If the given domain is already in the registry, the method will fail. Set 'overwrite' to 'True' to create the new relationship. In this case, previous relationships will be removed. The new domain can be also set as a top domain. That is useful to avoid the insertion of sub-domains that belong to the same organization (i.e eu.example.com, us.example.com). Take into account when 'overwrite' is set it will update 'is_top_domain' flag too. :param organization: name of the organization to add :param domain: domain to add to the registry :param is_top_domain: set the domain as a top domain :param overwrite: force to reassign the domain to the given company """

        # Empty or None values for organizations are not allowed
        if not organization:
            return CMD_SUCCESS

        if not domain:
            try:
                api.add_organization(self.db, organization)
            except InvalidValueError as e:
                # If the code reaches here, something really wrong has happened
                # because organization cannot be None or empty
                raise RuntimeError(str(e))
            except AlreadyExistsError as e:
                msg = "organization '%s' already exists in the registry" % organization
                self.error(msg)
                return e.code
        else:
            try:
                api.add_domain(self.db, organization, domain,
                               is_top_domain=is_top_domain,
                               overwrite=overwrite)
            except InvalidValueError as e:
                # Same as above, domains cannot be None or empty
                raise RuntimeError(str(e))
            except AlreadyExistsError as e:
                msg = "domain '%s' already exists in the registry" % domain
                self.error(msg)
                return e.code
            except NotFoundError as e:
                self.error(str(e))
                return e.code

        return CMD_SUCCESS