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

Added getVOSpaceChildNodes() method.

parent b8b557e1
Loading
Loading
Loading
Loading
+30 −0
Original line number Original line Diff line number Diff line
@@ -211,6 +211,36 @@ class DbConnector(object):
        finally:
        finally:
            self.connPool.putconn(conn, close = False)
            self.connPool.putconn(conn, close = False)


    def getVOSpaceChildNodes(self, vospacePath, nodeType = None):
        """
        Returns a list containing the child nodes (vospace path and node type)
        for a given vospace path.
        """
        try:
            conn = self.getConnection()
            cursor = conn.cursor(cursor_factory = RealDictCursor)
            cursor.execute("""
                SELECT get_vos_path(n.node_id) as vospace_path, type
                FROM node n
                WHERE n.parent_path <@ (SELECT path
                                        FROM node
                                        WHERE node_id = id_from_vos_path(%s))
                """,
                (vospacePath,))
            result = cursor.fetchall()
            cursor.close()
        except Exception:
            if not conn.closed:
                conn.rollback()
            raise
        else:
            if nodeType is None:
                return result
            else:
                return [ result[i] for i in range(len(result)) if result[i]["type"] == nodeType ]
        finally:
            self.connPool.putconn(conn, close = False)

    def getVOSpacePathList(self, vospacePath):
    def getVOSpacePathList(self, vospacePath):
        """Returns the list of VOSpace paths carried by a VOSpace node, according to the node VOSpace path."""
        """Returns the list of VOSpace paths carried by a VOSpace node, according to the node VOSpace path."""
        try:
        try: