'Get the record ID that corresponds to the given import item
or UUID
@param item: the import item
@param uid: the UUID
@return: the record ID if successfully identified, or
None if there is no record for that item yet
@raise ValueError: if there are multiple matches in the DB'

@classmethod
def identify(cls, item=None, uid=None):

    if item.id:
        return item.id
    if (uid is not None):
        table = (item.table if item else current.s3db.org_organisation)
        row = current.db((table.uuid == uid)).select(table.id, limitby=(0, 1)).first()
        if row:
            return row.id
    name_matches = cls.name_match(item)
    if (not name_matches):
        return None
    (parent_id, parent_uid, parent_item) = cls.parent(item)
    if (not any((parent_id, parent_uid, parent_item))):
        if (len(name_matches) == 1):
            match = name_matches.keys()[0]
            name = name_matches[match].get('name')
            if name:
                item.data.name = name
            return match
        else:
            hits = [k for (k, v) in name_matches.items() if (v.get('parent') is None)]
            if (len(hits) == 1):
                match = hits[0]
                name = name_matches[match].get('name')
                if name:
                    item.data.name = name
                return match
            else:
                raise ValueError
    else:
        if (not parent_id):
            parent_id = cls.identify(item=parent_item, uid=parent_uid)
        if (not parent_id):
            return None
        hits = [k for (k, v) in name_matches.items() if (v.get('parent') == parent_id)]
        if (len(hits) == 0):
            return None
        if (len(hits) == 1):
            match = hits[0]
            name = name_matches[match].get('name')
            if name:
                item.data.name = name
            return match
        else:
            raise ValueError
    return None
