From bae5dc50e87471470ae860adcffb649cfb5dbb72 Mon Sep 17 00:00:00 2001
From: Cristiano Urban <cristiano.urban@inaf.it>
Date: Tue, 18 Apr 2023 14:06:58 +0200
Subject: [PATCH] Added getVOSpaceChildNodes() method.

Signed-off-by: Cristiano Urban <cristiano.urban@inaf.it>
---
 transfer_service/db_connector.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/transfer_service/db_connector.py b/transfer_service/db_connector.py
index cd04458..debb493 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:
-- 
GitLab