From 6a08dbf7bdc9c489b64a94637b7b04f04e3edba6 Mon Sep 17 00:00:00 2001 From: Chris Burr Date: Sat, 14 Jun 2025 01:14:15 +0200 Subject: [PATCH 1/2] feat: Support getting transformation logging for multiple transformations --- src/DIRAC/TransformationSystem/DB/TransformationDB.py | 6 +++++- .../Service/TransformationManagerHandler.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/DIRAC/TransformationSystem/DB/TransformationDB.py b/src/DIRAC/TransformationSystem/DB/TransformationDB.py index 1e9ce2f99ba..419c26e3bb8 100755 --- a/src/DIRAC/TransformationSystem/DB/TransformationDB.py +++ b/src/DIRAC/TransformationSystem/DB/TransformationDB.py @@ -1247,7 +1247,11 @@ def getTransformationLogging(self, transName, connection=False): connection = res["Value"]["Connection"] transID = res["Value"]["TransformationID"] req = "SELECT TransformationID, Message, Author, MessageDate FROM TransformationLog" - req = req + f" WHERE TransformationID={transID} ORDER BY MessageDate;" + if isinstance(transID, (int, str)): + req += f" WHERE TransformationID={int(transID)}" + else: + req += f" WHERE TransformationID IN ({','.join(str(int(x)) for x in transID)})" + req += " ORDER BY MessageDate;" res = self._query(req) if not res["OK"]: return res diff --git a/src/DIRAC/TransformationSystem/Service/TransformationManagerHandler.py b/src/DIRAC/TransformationSystem/Service/TransformationManagerHandler.py index 16e053d420f..23053926be6 100644 --- a/src/DIRAC/TransformationSystem/Service/TransformationManagerHandler.py +++ b/src/DIRAC/TransformationSystem/Service/TransformationManagerHandler.py @@ -459,7 +459,7 @@ def export_getTransformationMetaQuery(self, transName, queryType): # These are the methods for transformation logging manipulation # - types_getTransformationLogging = [[int, str]] + types_getTransformationLogging = [[int, str, list]] def export_getTransformationLogging(self, transName): return self.transformationDB.getTransformationLogging(transName) From fd984d7c51bae7a68a5c7e598b7bb92fcd82982c Mon Sep 17 00:00:00 2001 From: Chris Burr Date: Sat, 14 Jun 2025 01:31:38 +0200 Subject: [PATCH 2/2] feat: Enhance _getTransformationID to support multiple transformation IDs and names --- .../DB/TransformationDB.py | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/src/DIRAC/TransformationSystem/DB/TransformationDB.py b/src/DIRAC/TransformationSystem/DB/TransformationDB.py index 419c26e3bb8..6e0d517cd23 100755 --- a/src/DIRAC/TransformationSystem/DB/TransformationDB.py +++ b/src/DIRAC/TransformationSystem/DB/TransformationDB.py @@ -406,21 +406,49 @@ def __updateTransformationParameter(self, transID, paramName, paramValue, connec def _getTransformationID(self, transName, connection=False): """Method returns ID of transformation with the name=""" - try: - transName = int(transName) - cmd = f"SELECT TransformationID from Transformations WHERE TransformationID={transName};" - except ValueError: - if not isinstance(transName, str): - return S_ERROR("Transformation should be ID or name") - cmd = f"SELECT TransformationID from Transformations WHERE TransformationName='{transName}';" - res = self._query(cmd, conn=connection) - if not res["OK"]: - gLogger.error("Failed to obtain transformation ID for transformation", f"{transName}: {res['Message']}") - return res - elif not res["Value"]: - gLogger.verbose(f"Transformation {transName} does not exist") - return S_ERROR("Transformation does not exist") - return S_OK(res["Value"][0][0]) + tids = [] + tnames = [] + for name in [transName] if isinstance(transName, (int, str)) else transName: + if isinstance(name, int): + tids.append(name) + elif name.isdigit(): + tids.append(int(name)) + else: + tnames.append(name) + + result = [] + if tids: + cmd = "SELECT TransformationID from Transformations" + cmd += f" WHERE TransformationID IN ({','.join(map(connection._escapeString, tids))})" + res = self._query(cmd, conn=connection) + if not res["OK"]: + gLogger.error( + "Failed to obtain transformation IDs for transformations", f"{transName}: {res['Message']}" + ) + return res + if len(res["Value"]) != len(tids): + missing = set(tids) - {row[0] for row in res["Value"]} + gLogger.verbose(f"Transformations {missing} do not exist") + return S_ERROR(f"Transformations {missing} do not exist") + result.extend(row[0] for row in res["Value"]) + if tnames: + cmd = "SELECT TransformationID, TransformationName from Transformations" + cmd += f" WHERE TransformationName IN ({','.join(map(connection._escapeString, tnames))})" + res = self._query(cmd, conn=connection) + if not res["OK"]: + gLogger.error( + "Failed to obtain transformation IDs for transformations", f"{transName}: {res['Message']}" + ) + return res + if len(res["Value"]) != len(tnames): + missing = set(tnames) - {row[1] for row in res["Value"]} + gLogger.verbose(f"Transformations {missing} do not exist") + return S_ERROR(f"Transformations {missing} do not exist") + result.extend(row[0] for row in res["Value"]) + + if isinstance(transName, (int, str)): + return S_OK(result[0]) + return S_OK(result) def __deleteTransformation(self, transID, connection=False): return self._update(f"DELETE FROM Transformations WHERE TransformationID={transID};", conn=connection)