diff --git a/transfer_service/db_connector.py b/transfer_service/db_connector.py index cd04458cbc7074f00ccbac0ab8e72dd44d4ac456..debb4938c01ff492d34a715ab67f0777fa10808e 100644 --- a/transfer_service/db_connector.py +++ b/transfer_service/db_connector.py @@ -211,6 +211,36 @@ class DbConnector(object): finally: 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): """Returns the list of VOSpace paths carried by a VOSpace node, according to the node VOSpace path.""" try: