Commit d7749d1c authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Modified 'insertNode()' method + added 'nodeExists()' method.

parent 1c37335e
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -51,11 +51,21 @@ class DbConnector(object):
                 json.dumps(jobObj.results),))
            self.conn.commit()
            
    def insertNode(self, node, parentOSPath):
    def nodeExists(self, node):
        if self.conn:
            nodeOSPath = node.parentPath + '/' + node.name
            self.cursor.execute("SELECT * FROM node_os_path WHERE os_path = %s;", (nodeOSPath,))
            result = self.cursor.fetchall()
            if result:
                return True
            else:
                return False

    def insertNode(self, node):
        if self.conn:
            out = open("db_connector_log.txt", "a")
            #print(f"parentOSPath: {parentOSPath}")
            self.cursor.execute("SELECT path FROM Node n JOIN node_os_path o ON n.node_id = o.node_id WHERE os_path = %s;", (parentOSPath,))
            #print(f"parentOSPath: {node.parentPath}")
            self.cursor.execute("SELECT path FROM Node n JOIN node_os_path o ON n.node_id = o.node_id WHERE os_path = %s;", (node.parentPath,))
            result = self.cursor.fetchall()
            for i in result:
                out.write(f"queryResult: {i}\n")
+2 −2
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ class StorePreprocessor(TaskExecutor):
                cnode.setParentPath(basePath)
                cnode.setOwnerID(self.userId)
                cnode.setCreatorID(self.userId)
                self.dbConn.insertNode(cnode, cnode.parentPath)
                self.dbConn.insertNode(cnode)

        out.write("\n\n")

@@ -184,7 +184,7 @@ class StorePreprocessor(TaskExecutor):
                    dnode.setOwnerID(self.userId)
                    dnode.setCreatorID(self.userId)
                    dnode.setContentMD5(self.md5calc.getMD5(file))
                    self.dbConn.insertNode(dnode, dnode.parentPath)
                    self.dbConn.insertNode(dnode)

        out.write("\n")
        out.close()