Esempio n. 1
0
 def update(
     self,
     _id,
     nodeDisplay,
     nodeDescription,
     nodeTags,
     nodeParents,
     nodeChildren,
     nodeVotes,
     nodeStatus,
     nodeCreateAt,
 ):
     conn = ConnectDB().connect()
     conn.put(
         "test_nodes",
         _id,
         {
             "nodeDisplay": nodeDisplay,
             "nodeDescription": nodeDescription,
             "nodeTags": nodeTags,
             "nodeParents": nodeParents,
             "nodeChildren": nodeChildren,
             "nodeVotes": nodeVotes,  # This can be replaced by invoke methods in vote class
             "nodeStatus": str(nodeStatus),
             "nodeCreateAt": nodeCreateAt,
         },
     )
Esempio n. 2
0
 def retrieveAll(self):
     conn = ConnectDB().connect()
     nodes = conn.list("test_nodes").all()
     list = []
     for node in nodes:
         list.append(node["value"])
     return list
Esempio n. 3
0
 def create(self, nodeDisplay, nodeDescription, nodeTags, nodeParents, nodeChildren, nodeVotes, nodeStatus):
     current_time = datetime.datetime.now()
     conn = ConnectDB().connect()
     node = conn.post(
         "test_nodes",
         {
             "nodeDisplay": nodeDisplay,
             "nodeDescription": nodeDescription,
             "nodeTags": nodeTags,
             "nodeParents": nodeParents,
             "nodeChildren": nodeChildren,
             "nodeVotes": nodeVotes,  # This can be replaced by invoke methods in vote class
             "nodeStatus": str(nodeStatus),
             "nodeCreateAt": str(current_time),
         },
     )
     if nodeParents:
         pa_node = self.retrieveById(nodeParents)
         pa_nodeChildren = pa_node["nodeChildren"]
         pa_nodeChildren.append(node.key)
         patch = Patch()
         patch.replace("nodeChildren", pa_nodeChildren)
         conn.patch("test_nodes", nodeParents, patch)
     # update parentnode's nodeChildren
     return node
Esempio n. 4
0
 def retrieveChild(self, _id):
     conn = ConnectDB().connect()
     node = conn.get("test_nodes", _id)
     _list = node["nodeChildren"]
     if not _list:
         _list = "This node has no child"
     return _list
Esempio n. 5
0
 def retrieveAll():
     client = ConnectDB().connect()
     vote_list = []
     vote_list_response = client.list('votes').all()
     for vote_res in vote_list_response:
         value = vote_res['value']
         vote_list.append(value)
     return vote_list
Esempio n. 6
0
 def retrieveById(user_key):
     client = ConnectDB().connect()
     response = client.get('users', user_key)
     status = response.status_code
     if status == 200:
         return response.json
     else:
         return None
Esempio n. 7
0
 def retrieveAll():
     client = ConnectDB().connect()
     user_list = []
     user_list_response = client.list('users').all()
     for user_res in user_list_response:
         value = user_res['value']
         user_list.append(value)
     return user_list
Esempio n. 8
0
 def retrieveAll():
     client = ConnectDB().connect()
     user_list = []
     user_list_response = client.list('users').all()
     for user_res in user_list_response:
         value = user_res['value']
         user_list.append(value)
     return user_list
Esempio n. 9
0
    def delete(self, _id):
        """ Delete a node from database

        :param _id: node ID
        :return: nothing
        """
        conn = ConnectDB().connect()
        conn.delete('test_nodes', _id)
Esempio n. 10
0
 def retrieveAll():
     client = ConnectDB().connect()
     add_list =[]
     add_list_response = client.list('adds').all()
     for add_res in add_list_response:
         value = add_res['value']
         add_list.append(value)
     return add_list
Esempio n. 11
0
 def retrieveByEmail(email):
     client = ConnectDB().connect()
     user_list =[]
     users = client.search('users', 'email:'+email).all()[0]['value']
     # for user in users:
     #     value = user['value']
     #     user_list.append(value)
     return users
Esempio n. 12
0
 def retrieveAll():
     client = ConnectDB().connect()
     tag_list = []
     tag_list_response = client.list('tags').all()
     for tag_res in tag_list_response:
         value = tag_res['value']
         tag_list.append(value)
     return tag_list
Esempio n. 13
0
 def retrieveById(user_key):
     client = ConnectDB().connect()
     response = client.get('users', user_key)
     status = response.status_code
     if status == 200:
         return response.json
     else:
         return None
Esempio n. 14
0
 def retrieveAll():
     client = ConnectDB().connect()
     vote_list =[]
     vote_list_response = client.list('votes').all()
     for vote_res in vote_list_response:
         value = vote_res['value']
         vote_list.append(value)
     return vote_list
Esempio n. 15
0
 def retrieveDescendent(self, _id):
     conn = ConnectDB().connect()
     node = conn.get("test_nodes", _id)
     _list = node["nodeChildren"]
     if not _list:
         _list = "This node has no child."
     for child in _list:
         findChild(child, _list, conn)
     return _list
Esempio n. 16
0
    def retrieveById(self, _id):
        """ Retrieve a node by its ID

        :param _id: node ID
        :return: node object
        """
        conn = ConnectDB().connect()
        node = conn.get('test_nodes', _id)
        print node.status_code
        return node
Esempio n. 17
0
 def update(_id, event):
     """
     Update an event
     :param event:
     :return:
     """
     print 'update'
     db_conn = ConnectDB().connect()
     update_result = db_conn.put('node_events', _id, event)
     event_key = update_result.key
     return event_key
Esempio n. 18
0
    def retrieveAll(self):
        """ Retrieve all the nodes from database

        :return: array of all the nodes
        """
        conn = ConnectDB().connect()
        nodes = conn.list('test_nodes').all()
        list = []
        for node in nodes:
            list.append(node['value'])
        return list
Esempio n. 19
0
    def retrieveChild(self, _id):
        """ Retrieve all direct children nodes of this node

        :param _id: node ID
        :return: all the children nodes of this node
        """
        conn = ConnectDB().connect()
        node = conn.get('test_nodes', _id)
        _list = node['nodeChildren']
        if not _list:
            _list = 'This node has no child'
        return _list
Esempio n. 20
0
 def downvoteNode(self, node_id, user_id):
     conn = ConnectDB().connect()
     node = conn.get("test_nodes", node_id)
     nodeVotes = node["nodeVotes"]
     nodeStatus = int(node["nodeStatus"]) - 1
     vote = {"_id": str(user_id), "type": "-1"}
     assert isinstance(nodeVotes, list)
     nodeVotes.append(vote)
     patch = Patch()
     patch.replace("nodeStatus", str(nodeStatus)).replace("nodeVotes", nodeVotes)
     conn.patch("test_nodes", node_id, patch)
     new_node = conn.get("test_nodes", "node_id")
     return new_node
Esempio n. 21
0
    def retrieve_by_id(_id):
        """
        Retrieve an event by its id
        :param _id: event id
        :return: event object
        """
        print 'retrieve by event id'

        db_conn = ConnectDB().connect()
        event = db_conn.get('node_events', _id)
        print event.status_code

        return event
Esempio n. 22
0
    def retrieve_all():
        """
        Retrieve all the events from database
        :return: json array of events
        """
        print 'retrieve all'
        db_conn = ConnectDB().connect()
        events = db_conn.list('node_events').all()
        events_list = []
        for event in events:
            events_list.append(event['value'])

        return events_list
Esempio n. 23
0
    def retrieveDescendant(self, _id):
        """ Retrieve all the descendant nodes of this node

        :param _id: node ID
        :return: descendant nodes of the node
        """
        conn = ConnectDB().connect()
        node = conn.get('test_nodes', _id)
        _list = node['nodeChildren']
        if not _list:
            _list = 'This node has no descendant node.'
        for child in _list:
            findChild(child, _list, conn)
        return _list
Esempio n. 24
0
 def delete(add_key):
     add = Add.retrieveById(add_key)
     if None == add:
         result = {"result": "failed", "message": "add doesn't exist"}
         return result
     client = ConnectDB().connect()
     response = client.delete('adds', add_key)
     add = Add.retrieveById(add_key)
     if None == add:
         result = {"result": "success", "message": "success"}
         return result
     else:
         reason = response.reason
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 25
0
 def delete(user_key):
     user = User.retrieveById(user_key)
     if None == user:
         result = {"result": "failed", "message": "user doesn't exist"}
         return result
     client = ConnectDB().connect()
     response = client.delete('users', user_key)
     user = User.retrieveById(user_key)
     if None == user:
         result = {"result": "success", "message": "success"}
         return result
     else:
         reason = response.reason
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 26
0
 def delete(tag_key):
     tag = Tag.retrieveById(tag_key)
     if None == tag:
         result = {"result": "failed", "message": "tag doesn't exist"}
         return result
     client = ConnectDB().connect()
     response = client.delete('tags', tag_key)
     tag = Tag.retrieveById(tag_key)
     if None == tag:
         result = {"result": "success", "message": "success"}
         return result
     else:
         reason = response.reason
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 27
0
 def update(add_key, add):
     client = ConnectDB().connect()
     response = client.put('adds', add_key, {
         "_id": add_key,
         "node": add.node,
         "addAt": add.addAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 28
0
 def delete(vote_key):
     vote = Vote.retrieveById(vote_key)
     if None == vote:
         result = {"result": "failed", "message": "vote doesn't exist"}
         return result
     client = ConnectDB().connect()
     response = client.delete('votes', vote_key)
     vote = Vote.retrieveById(vote_key)
     if None == vote:
         result = {"result": "success", "message": "success"}
         return result
     else:
         reason = response.reason
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 29
0
 def delete(vote_key):
     vote = Vote.retrieveById(vote_key)
     if None == vote:
         result = {"result": "failed", "message": "vote doesn't exist"}
         return result
     client = ConnectDB().connect()
     response = client.delete('votes', vote_key)
     vote = Vote.retrieveById(vote_key)
     if None == vote:
         result = {"result": "success", "message": "success"}
         return result
     else:
         reason = response.reason
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 30
0
 def delete(user_key):
     user = User.retrieveById(user_key)
     if None == user:
         result = {"result": "failed", "message": "user doesn't exist"}
         return result
     client = ConnectDB().connect()
     response = client.delete('users', user_key)
     user = User.retrieveById(user_key)
     if None == user:
         result = {"result": "success", "message": "success"}
         return result
     else:
         reason = response.reason
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 31
0
 def update(user_key, user):
     client = ConnectDB().connect()
     response = client.put('users', user_key, {
         "_id": user_key,
         "given_name": user.given_name,
         "surname": user.surname,
         "email": user.email
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 32
0
 def update(tag_key, tag):
     client = ConnectDB().connect()
     response = client.put('tags', tag_key, {
         "_id": tag_key,
         "tagName": tag.tagName,
         "tagDescription": tag.tagDescription,
         "createdBy": tag.createdBy,
         "createdAt": tag.createdAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 33
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('adds', {
         "node": self.node,
         "addAt": self.addAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('adds', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 34
0
 def update(user_key, user):
     client = ConnectDB().connect()
     response = client.put('users', user_key, {
         "_id": user_key,
         "username": user.username,
         "loginToken": user.loginToken,
         "email": user.email,
         "intro": user.intro,
         "registerAt": user.registerAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 35
0
 def update(vote_key, vote):
     client = ConnectDB().connect()
     response = client.put('votes', vote_key, {
         "_id": vote_key,
         "type": vote.type,
         "description": vote.description,
         "voteUser": vote.voteUser,
         "voteAt": vote.voteAt,
         "voteOnNode": vote.voteOnNode
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 36
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('users', {
         "given_name": self.given_name,
         "surname": self.surname,
         "email": self.email
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('users', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 37
0
 def update(vote_key, vote):
     client = ConnectDB().connect()
     response = client.put(
         'votes', vote_key, {
             "_id": vote_key,
             "type": vote.type,
             "description": vote.description,
             "voteUser": vote.voteUser,
             "voteAt": vote.voteAt,
             "voteOnNode": vote.voteOnNode
         })
     status = response.status_code
     reason = response.reason
     if status == 201:
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 38
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('tags', {
         "tagName": self.tagName,
         "tagDescription": self.tagDescription,
         "createdBy": self.createdBy,
         "createdAt": self.createdAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('tags', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 39
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('votes', {
         "type": self.type,
         "description": self.description,
         "voteUser": self.voteUser,
         "voteAt": self.voteAt,
         "voteOnNode": self.voteOnNode
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('votes', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 40
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post('users', {
         "username": self.username,
         "loginToken": self.loginToken,
         "email": self.email,
         "intro": self.intro,
         "registerAt": self.registerAt
     })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('users', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 41
0
    def create(self, nodeDisplay, nodeDescription, nodeTags, nodeParents,
               nodeChildren, nodeVotes, nodeStatus, userId):
        """ Create a new node
        The check of node data has been completed by service

        :param nodeDisplay: display name of a node
        :param nodeDescription: description of a node
        :param nodeTags: tags of a node
        :param nodeParents: parent node ID of this node
        :param nodeChildren: children nodes (if already has)
        :param nodeVotes: votes on node
        :param nodeStatus: status of node
        :param userId: author identification
        :return: a key of the node as an identification
        """

        current_time = datetime.datetime.now()
        conn = ConnectDB().connect()
        node = conn.post(
            'test_nodes',
            {
                "nodeDisplay": nodeDisplay,
                "nodeDescription": nodeDescription,
                "nodeTags": nodeTags,
                "nodeParents": nodeParents,
                "nodeChildren": nodeChildren,
                "nodeVotes":
                nodeVotes,  # This can be replaced by invoke methods in vote class
                "nodeStatus": str(nodeStatus),
                "nodeCreateAt": str(current_time),
                "userId": userId
            })

        patch = Patch()
        nodeKey = node.key
        patch.add("_id", node.key)

        conn.patch('test_nodes', node.key, patch)
        print 'nodeKey is ' + node.key

        return nodeKey
Esempio n. 42
0
    def create(event):
        """
        Create a new event object
        :param event:
        :return:
        """
        print 'create'
        db_conn = ConnectDB().connect()
        current_time = datetime.datetime.now()  # create_at
        event['create_at'] = str(current_time)
        event['status'] = data_checker.EVENT_UNREAD
        event_create = db_conn.post('node_events', event)

        # append a key as ID to event
        patch = Patch()
        event_key = event_create.key
        patch.add("_id", event_key)
        db_conn.patch('node_events', event_key, patch)
        print 'event_key=' + event_key

        return event_key
Esempio n. 43
0
 def create(self):
     client = ConnectDB().connect()
     response = client.post(
         'votes', {
             "type": self.type,
             "description": self.description,
             "voteUser": self.voteUser,
             "voteAt": self.voteAt,
             "voteOnNode": self.voteOnNode
         })
     status = response.status_code
     reason = response.reason
     if status == 201:
         patch = Patch()
         patch.add("_id", response.key)
         client.patch('votes', response.key, patch)
         result = {"result": "success", "message": reason}
         return result
     else:
         result = {"result": "failed", "message": reason}
         return result
Esempio n. 44
0
    def downvoteNode(self, node_id, user_id, comment):
        """ Voting down on a node

        :param node_id: ID of node
        :param user_id: ID of user (not required)
        :param comment: Comment on the vote
        :return: node object after voting
        """
        conn = ConnectDB().connect()
        node = conn.get('test_nodes', node_id)
        nodeVotes = node['nodeVotes']
        nodeStatus = int(node['nodeStatus']) - 1
        vote = {
            'userId': str(user_id),
            'type': '-1',
            'voteDate': str(datetime.datetime.now()),
            'comment': comment
        }
        assert isinstance(nodeVotes, list)
        nodeVotes.append(vote)
        patch = Patch()
        patch.replace('nodeStatus',
                      str(nodeStatus)).replace('nodeVotes', nodeVotes)
        conn.patch('test_nodes', node_id, patch)
        new_node = conn.get('test_nodes', node_id)
        return new_node
Esempio n. 45
0
    def update(self, _id, nodeDisplay, nodeDescription, nodeTags, nodeParents,
               nodeChildren, nodeVotes, nodeStatus, nodeCreateAt, userId):
        """ Update an existing node in database

        :param _id: node ID
        :param nodeDisplay: display name of a node
        :param nodeDescription: description
        :param nodeTags: tags of the node
        :param nodeParents: parent of the node
        :param nodeChildren: children nodes of the node
        :param nodeVotes: votes on the node
        :param nodeStatus: node status
        :param nodeCreateAt: node creation time
        :param userId: user identification
        :return: the key (ID) of the node
        """
        conn = ConnectDB().connect()
        update_result = conn.put(
            'test_nodes',
            _id,
            {
                "nodeDisplay": nodeDisplay,
                "nodeDescription": nodeDescription,
                "nodeTags": nodeTags,
                "nodeParents": nodeParents,
                "nodeChildren": nodeChildren,
                "nodeVotes":
                nodeVotes,  # This can be replaced by invoke methods in vote class
                "nodeStatus": str(nodeStatus),
                "nodeCreateAt": nodeCreateAt,
                "userId": userId,
                "_id": _id
            })

        node_key = update_result.key
        return node_key
Esempio n. 46
0
 def retrieve_numb_vote_by_node_id(node_key, vote_type):
     client = ConnectDB().connect()
     vote_list = client.search('votes', 'voteOnNode:'+node_key + ' AND type:'+vote_type).all()
     return len(vote_list)
Esempio n. 47
0
 def retrieve_numb_vote_by_node_id(node_key, vote_type):
     client = ConnectDB().connect()
     vote_list = client.search(
         'votes',
         'voteOnNode:' + node_key + ' AND type:' + vote_type).all()
     return len(vote_list)
Esempio n. 48
0
class GenericOperation(object):
    client = ConnectDB().connect()

    def __init__(self, obj):
        self.operate_obj = obj
Esempio n. 49
0
 def delete(self, _id):
     conn = ConnectDB().connect()
     conn.delete("test_nodes", _id)
Esempio n. 50
0
 def retrieveById(self, _id):
     conn = ConnectDB().connect()
     node = conn.get("test_nodes", _id)
     return node