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

Added getters + changed path query into the 'insertNode()' method.

parent cba4b576
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
@@ -112,6 +112,19 @@ class DbConnector(object):
            self.cursor.execute("SELECT * FROM storage WHERE storage_type = %s;", (storageType,))
            return self.cursor.fetchall()
        
    def getStorageBasePath(self, storageId):
        """Returns the storage base path fro a give storage id"""
        if self.conn:
            self.cursor.execute("SELECT base_path FROM storage WHERE storage_id = %s;", (storageId,))
            return self.cursor.fetchall()[0]["base_path"]

    def getLocationId(self, destStorageId):
        """Returns the location id according to the storage id of the destination"""
        if self.conn:
            self.cursor.execute("SELECT location_id FROM location WHERE storage_src_id = %s;", (destStorageId,))
            return self.cursor.fetchall()[0]["location_id"]


    """
    Setters
    """
@@ -162,11 +175,12 @@ class DbConnector(object):
        """Inserts a VOSpace node."""
        if self.conn:
            out = open("db_connector_log.txt", "a")
            #print(f"parentOSPath: {node.parentPath}")
            out.write(f"parentOSPath: {node.parentPath}\n")
            out.write(f"name: {node.name}\n")
            self.cursor.execute("""
                SELECT path FROM node n
                JOIN node_os_path o ON n.node_id = o.node_id
                WHERE os_path = %s;
                JOIN node_vos_path o ON n.node_id = o.node_id
                WHERE vos_path = %s;
                """,
                (node.parentPath,))
            result = self.cursor.fetchall()
@@ -174,19 +188,24 @@ class DbConnector(object):
                out.write(f"queryResult: {i}\n")
            #parentLtreePath = self.cursor.fetchone()[0]
            parentLtreePath = result[0]["path"]
            parentLtreeRelativePath = None
            if "." in parentLtreePath:
                parentLtreeRelativePath = ".".join(parentLtreePath.strip(".").split('.')[1:])
            out.write(f"parentLtreeRelativePath: {parentLtreeRelativePath}\n")
            out.write(f"parentLtreePath: {parentLtreePath}\n")
            out.write(f"parentPath: {node.parentPath}\n\n")
            out.close()
            #print(f"parentLtreePath: {parentLtreePath}, type: {type(parentLtreePath)}")
            self.cursor.execute("""
                INSERT INTO node(parent_path, parent_relative_path, name, tstamp_wrapper_dir, type, owner_id, creator_id, content_md5)
                VALUES (%s, %s, %s, %s, %s, %s, %s, %s);
                INSERT INTO node(parent_path, parent_relative_path, name, tstamp_wrapper_dir, type, location_id, owner_id, creator_id, content_md5)
                VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s);
                """,
                (parentLtreePath,
                 parentLtreePath,
                 parentLtreeRelativePath,
                 node.name,
                 node.wrapperDir,
                 node.type,
                 node.locationId,
                 node.ownerID,
                 node.creatorID,
                 node.contentMD5,))