diff --git a/src/DIRAC/TransformationSystem/Client/TransformationFilesStatus.py b/src/DIRAC/TransformationSystem/Client/TransformationFilesStatus.py index 73a4731e612..d35e5e67c17 100644 --- a/src/DIRAC/TransformationSystem/Client/TransformationFilesStatus.py +++ b/src/DIRAC/TransformationSystem/Client/TransformationFilesStatus.py @@ -17,6 +17,8 @@ PROB_IN_FC = "ProbInFC" #: REMOVED = "Removed" +#: +DELETED = "Deleted" # below ones are for inherited transformations #: diff --git a/src/DIRAC/TransformationSystem/DB/TransformationDB.py b/src/DIRAC/TransformationSystem/DB/TransformationDB.py index 37ec1b752cd..3f7aa4ef2dc 100755 --- a/src/DIRAC/TransformationSystem/DB/TransformationDB.py +++ b/src/DIRAC/TransformationSystem/DB/TransformationDB.py @@ -15,6 +15,7 @@ from DIRAC import gLogger, S_OK, S_ERROR from DIRAC.Core.Base.DB import DB from DIRAC.Core.Utilities.DErrno import cmpError +from DIRAC.TransformationSystem.Client import TransformationFilesStatus from DIRAC.Resources.Catalog.FileCatalog import FileCatalog from DIRAC.Core.Security.ProxyInfo import getProxyInfo from DIRAC.Core.Utilities.List import stringListToString, intListToString, breakListIntoChunks @@ -1126,7 +1127,7 @@ def __addMetaQuery(self, transID, queryDict, queryType, author="", connection=Fa for parameterName in sorted(queryDict): parameterValue = queryDict[parameterName] - if not parameterValue: + if parameterValue is None: continue parameterType = "String" if isinstance(parameterValue, (list, tuple)): @@ -1138,6 +1139,9 @@ def __addMetaQuery(self, transID, queryDict, queryType, author="", connection=Fa if isinstance(parameterValue, int): parameterType = "Integer" parameterValue = str(parameterValue) + if isinstance(parameterValue, float): + parameterType = "Float" + parameterValue = str(parameterValue) if isinstance(parameterValue, dict): parameterType = "Dict" parameterValue = str(parameterValue) @@ -1617,6 +1621,26 @@ def addFile(self, fileDicts, force=False, connection=False): gLogger.info("Files to add to transformations:", filesToAdd) if filesToAdd: for transID, lfns in transFiles.items(): + # Check if file is already in the Transformation and if is in Deleted Status + res = self.getTransformationFiles( + condDict={"TransformationID": transID, "LFN": lfns}, connection=connection + ) + if not res["OK"]: + return res + for fileDict in res["Value"]: + if fileDict["Status"] == TransformationFilesStatus.DELETED: + res = self.__setTransformationFileStatus( + list([fileDict["FileID"]]), TransformationFilesStatus.UNUSED, connection=connection + ) + if not res["OK"]: + return res + if not ( + res := self.__setDataFileStatus( + list([fileDict["FileID"]]), "New", connection=connection + )["OK"] + ): + return res + res = self.addFilesToTransformation(transID, lfns) if not res["OK"]: gLogger.error("Failed to add files to transformation", f"{transID} {res['Message']}") @@ -1689,7 +1713,7 @@ def __addDirectory(self, path, force): successful.append(lfn) return {"OK": True, "Value": len(res["Value"]["Successful"]), "Successful": successful, "Failed": failed} - def setMetadata(self, path, usermetadatadict): + def setMetadata(self, path, usermetadatadict, connection=False): """ It can be applied to a file or to a directory (path). For a file, add the file to Transformations if the updated metadata dictionary passes the filter. @@ -1747,6 +1771,23 @@ def setMetadata(self, path, usermetadatadict): gLogger.info("Files to add to transformations:", filesToAdd) if filesToAdd: for transID, lfns in transFiles.items(): + # Check if file is already in the Transformation and if is in Deleted Status + res = self.getTransformationFiles( + condDict={"TransformationID": transID, "LFN": lfns}, connection=connection + ) + if not res["OK"]: + return res + for fileDict in res["Value"]: + if fileDict["Status"] == TransformationFilesStatus.DELETED: + res = self.__setTransformationFileStatus( + list([fileDict["FileID"]]), TransformationFilesStatus.UNUSED, connection=connection + ) + if not res["OK"]: + return res + res = self.__setDataFileStatus(list([fileDict["FileID"]]), "New", connection=connection) + if not res["OK"]: + return res + res = self.addFilesToTransformation(transID, lfns) if not res["OK"]: gLogger.error("Failed to add files to transformation", f"{transID} {res['Message']}")