Example #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)
Example #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)
Example #3
0
    def getChatroomList(cls, conf):
        conf = str(conf.getId())
        index = IndexByConf().get()

        if not index.has_key(conf):
            return []
            # raise ServiceError( message=_('Conference not found in database: %s' %conf))
        return index[conf]
Example #4
0
    def getChatroomList(cls, conf):
        conf = str(conf.getId())
        index = IndexByConf().get()

        if not index.has_key(conf):
            return []
            # raise ServiceError( message=_('Conference not found in database: %s' %conf))
        return index[conf]
Example #5
0
 def addConference2Room(cls, obj, params):
     """ When we re use a chat room for another conference(s), this is the method called.
         It may be called from the AJAX service, but also from the clone event. Since we
         don't know it, we have to check the parameters accordingly"""
     room = params['room']
     confId = params['conf']
     room.setConference(ConferenceHolder().getById(confId))
     confIndex = IndexByConf()
     confIndex.index(confId, room)
Example #6
0
 def addConference2Room(cls, obj, params):
     """ When we re use a chat room for another conference(s), this is the method called.
         It may be called from the AJAX service, but also from the clone event. Since we
         don't know it, we have to check the parameters accordingly"""
     room = params['room']
     confId = params['conf']
     room.setConference(ConferenceHolder().getById(confId))
     confIndex = IndexByConf()
     confIndex.index(confId, room)
Example #7
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
Example #8
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)
Example #9
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)