Пример #1
0
    def createChatroom(cls, obj, params):
        """ Inserts the object in the database according to all the kind of indexing types, in this case:
        -Chat rooms by conference
        -Chat rooms by user
        -Chat rooms by name (to check if there's already a chat room with that name in our XMPP server)
        -Chat rooms by ID (to access faster to the object when querying)
        """
        room = params['room']

        conference = params['conference']

        # index by conference id
        confIndex = IndexByConf()
        room.setId(DBHelpers.newID())
        confIndex.index(conference.getId(), room)

        # Index by chat room's name
        crNameIndex = IndexByCRName()
        crNameIndex.index(room)

        # Index by id
        idIndex = IndexByID()
        idIndex.index(room)

        # Index by room creator
        userIndex = IndexByUser()
        userIndex.index(room.getOwner().getId(), room)
Пример #2
0
    def createChatroom(cls, obj, params):
        """ Inserts the object in the database according to all the kind of indexing types, in this case:
        -Chat rooms by conference
        -Chat rooms by user
        -Chat rooms by name (to check if there's already a chat room with that name in our XMPP server)
        -Chat rooms by ID (to access faster to the object when querying)
        """
        room = params['room']

        conference = params['conference']

        # index by conference id
        confIndex = IndexByConf()
        room.setId(DBHelpers.newID())
        confIndex.index(conference.getId(), room)

        # Index by chat room's name
        crNameIndex = IndexByCRName()
        crNameIndex.index(room)

        # Index by id
        idIndex = IndexByID()
        idIndex.index(room)

        # Index by room creator
        userIndex = IndexByUser()
        userIndex.index(room.getOwner().getId(), room)
Пример #3
0
    def getRoomsByUser(cls, user):
        """ Will return the chat rooms created by the requested user """
        userID = str(user['id'])
        index = IndexByUser().get()

        if not index.has_key(userID):
            return []
        return index[userID]
Пример #4
0
    def getNumberOfRoomsByUser(cls, user, exclude=None):
        """ Will return the number of rooms that the user has in this index,
            can exclude a conference if passed through by exclude param.
        """
        userID = str(user['id'])
        index = IndexByUser().get()

        if not index.has_key(userID):
            return 0

        idx = index[userID].values()

        if exclude is not None:
            idx = DBHelpers()._filterIndexExclusion(idx, exclude)

        return len(idx)
Пример #5
0
    def editChatroom(self, obj, params):
        oldTitle = params['oldTitle']
        newRoom = params['newRoom']
        userId = params['userId']

        #we have an index by the chat room name. If, while editing, someone changes the chat room name, we'll have to update the index
        if oldTitle != newRoom.getTitle():
            #the title has been changed. Get rid of the old index and substitute it for the new one
            crNameIndex = IndexByCRName()
            crNameIndex.unindex(newRoom, oldTitle)
            crNameIndex.index(newRoom)

            # For dynamic loading this needs to be in alphabetical order,
            # therefore reindex on change.
            userIndex = IndexByUser()
            userIndex.reindex(userId, newRoom, oldTitle)
Пример #6
0
    def getNumberOfRoomsByUser(cls, user, exclude=None):
        """ Will return the number of rooms that the user has in this index,
            can exclude a conference if passed through by exclude param.
        """
        userID = str(user['id'])
        index = IndexByUser().get()

        if not index.has_key(userID):
            return 0

        idx = index[userID].values()

        if exclude is not None:
            idx = DBHelpers()._filterIndexExclusion(idx, exclude)

        return len(idx)
Пример #7
0
    def editChatroom(self, obj, params):
        oldTitle = params['oldTitle']
        newRoom = params['newRoom']
        userId = params['userId']

        #we have an index by the chat room name. If, while editing, someone changes the chat room name, we'll have to update the index
        if oldTitle != newRoom.getTitle():
            #the title has been changed. Get rid of the old index and substitute it for the new one
            crNameIndex = IndexByCRName()
            crNameIndex.unindex(newRoom, oldTitle)
            crNameIndex.index(newRoom)

            # For dynamic loading this needs to be in alphabetical order,
            # therefore reindex on change.
            userIndex = IndexByUser()
            userIndex.reindex(userId, newRoom, oldTitle)
Пример #8
0
    def getRoomsByUser(cls, user, offset=0, limit=None, exclude=None):
        """ Will return the chat rooms created by the requested user """
        userID = str(user['id'])
        index = IndexByUser().get()

        if not index.has_key(userID):
            return []

        idx = index[userID].values()

        if exclude is not None:
            idx = DBHelpers()._filterIndexExclusion(idx, exclude)

        if offset >= len(idx): # If we have gone over the boundaries
            return []

        limit = limit if limit is not None else (len(index[userID]) - 1)
        limit += offset

        return list(idx[offset:limit])
Пример #9
0
    def getRoomsByUser(cls, user, offset=0, limit=None, exclude=None):
        """ Will return the chat rooms created by the requested user """
        userID = str(user['id'])
        index = IndexByUser().get()

        if not index.has_key(userID):
            return []

        idx = index[userID].values()

        if exclude is not None:
            idx = DBHelpers()._filterIndexExclusion(idx, exclude)

        if offset >= len(idx): # If we have gone over the boundaries
            return []

        limit = limit if limit is not None else (len(index[userID]) - 1)
        limit += offset

        return list(idx[offset:limit])
Пример #10
0
def chatroomIndexMigration(dbi, withRBDB, prevVersion):
    """
    Migrating Chat Room index to new structure
    """

    # The structure of the indexes is such that for each one self._data
    #    is a BTree and each node is referenced by the IndexBy___ designation,
    #    where ___ is the ID in question. Each node is then a TreeSet of
    #    ChatRoom or XMPPChatRoom objects originally orderded by ID, we need
    #    this to be ordered by title for effective searching / querying.
    #   The __cmp__ method has been altered to accommodate this new format,
    #    take each subnode, iterate through saving the current objects, clear the
    #    index and reinsert them - they will now be in the correct order.

    from MaKaC.plugins.InstantMessaging.indexes import IndexByUser, IndexByConf, IndexByCRName, IndexByID

    im_plugin = PluginsHolder().getPluginType('InstantMessaging')

    if not im_plugin.isUsable():
        print console.colored('  IM plugin not usable - jumping task',
                              'yellow')
        return

    try:
        for idx in [IndexByUser(), IndexByConf(), IndexByCRName()]:
            tmp_idx = defaultdict(list)
            print console.colored("  * Index: " + str(idx), 'blue')

            for key, node in idx._data.iteritems():
                for leaf in node:
                    tmp_idx[key].append(leaf)

            # reset index
            idx._data.clear()

            for accum, rooms in tmp_idx.iteritems():
                for room in rooms:
                    # Specific handling as IndexByUser & IndexByConf have different
                    # arguements for tree insertion.
                    if isinstance(idx, IndexByUser) or isinstance(
                            idx, IndexByConf):
                        idx.index(str(accum), room)
                    else:
                        idx.index(room)

        print console.colored(
            "\tAll indexes have now been re-indexed and committed to the DB.",
            'green')
    except:
        dbi.abort()
        print console.colored(
            "Process failed, ended abruptly, changes not committed.", 'red')
        raise
Пример #11
0
    def deleteChatroom(cls, obj, params):
        """ Deletes the chat room in the database according to all kind of indexing types"""

        chatroom = params['room']

        confId = obj._conferenceID
        #if we have the same room used in two or more different conferences, we just delete it from the
        #conferences list in the chat room and from the IndexByConf index
        chatroom.getConferences().pop(confId)
        confIndex = IndexByConf()
        confIndex.unindex(confId, chatroom)

        if len(chatroom.getConferences()) is 0:
            #there are no more references to the chat room, we completely delete it
            crNameIndex = IndexByCRName()
            crNameIndex.unindex(chatroom)

            idIndex = IndexByID()
            idIndex.unindex(chatroom)

            userIndex = IndexByUser()
            userIndex.unindex(chatroom.getOwner().getId(), chatroom)
Пример #12
0
    def deleteChatroom(cls, obj, params):
        """ Deletes the chat room in the database according to all kind of indexing types"""

        chatroom = params['room']

        confId = obj._conferenceID
        #if we have the same room used in two or more different conferences, we just delete it from the
        #conferences list in the chat room and from the IndexByConf index
        chatroom.getConferences().pop(confId)
        confIndex = IndexByConf()
        confIndex.unindex(confId, chatroom)

        if len(chatroom.getConferences()) is 0:
            #there are no more references to the chat room, we completely delete it
            crNameIndex = IndexByCRName()
            crNameIndex.unindex(chatroom)

            idIndex = IndexByID()
            idIndex.unindex(chatroom)

            userIndex = IndexByUser()
            userIndex.unindex(chatroom.getOwner().getId(), chatroom)