code: def add_identity(cls, db, identity, backend):
          uuid = None
          try:
              uuid = api.add_identity(db, backend, identity['email'],
                                      identity['name'], identity['username'])
              logger.debug("New sortinghat identity %s %s,%s,%s ",
                           uuid, identity['username'], identity['name'], identity['email'])
              profile = {"name": identity['name'] if identity['name'] else identity['username'],
                         "email": identity['email']}
              api.edit_profile(db, uuid, **profile)
          except AlreadyExistsError as ex:
              uuid = ex.eid
          except InvalidValueError as ex:
              logger.warning("Trying to add a None identity. Ignoring it.")
          except UnicodeEncodeError as ex:
              logger.warning("UnicodeEncodeError. Ignoring it. %s %s %s",
                             identity['email'], identity['name'],
                             identity['username'])
          except Exception as ex:
              logger.warning("Unknown exception adding identity. Ignoring it. %s %s %s",
                             identity['email'], identity['name'],
                             identity['username'], exc_info=True)
          if 'company' in identity and identity['company'] is not None:
              try:
                  api.add_organization(db, identity['company'])
                  api.add_enrollment(db, uuid, identity['company'],
                                     datetime(1900, 1, 1),
                                     datetime(2100, 1, 1))
              except AlreadyExistsError:
                  pass
          return uuid