diff --git a/mupifDB/models.py b/mupifDB/models.py index 9703461..64cc6e9 100644 --- a/mupifDB/models.py +++ b/mupifDB/models.py @@ -41,7 +41,7 @@ class DbRef_Model(StrictBase): class TEMP_DbLookup_Model(StrictBase): where: str attrs: List[str] - values: List[str] + values: List[str|int] class MongoObjBase_Model(StrictBase): dbID: Optional[DatabaseID]=Field(None,alias='_id') # type: ignore[arg-type] @@ -53,7 +53,7 @@ def model_dump_db(self): ret=self.model_dump(mode='json') if '_id' in ret and ret['_id'] is None: del ret['_id'] return ret - def TEMP_getChildren(self) -> List[DbRef_Model]: return [] + def TEMP_getChildren(self) -> List[Tuple[str,DbRef_Model]]: return [] def TEMP_getLookupChildren(self) -> List[TEMP_DbLookup_Model]: return [] import abc @@ -148,8 +148,8 @@ class Link_Model(StrictBase): FileID: Optional[str]=None Compulsory: Optional[bool]=False # deema: allow None Object: dict[str,Any] - def TEMP_getChildren(self) -> List[DbRef_Model]: - return [DbRef_Model(where=where,id=id) for where,id in [('fs.files',self.FileID)] if id is not None and id!=''] + def TEMP_getChildren(self) -> List[Tuple[str,DbRef_Model]]: + return [('FileID',DbRef_Model(where=where,id=id)) for where,id in [('fs.files',self.FileID)] if id is not None and id!=''] class IODataRecord_Model(MongoObj_Model): DataSet: List[IODataRecordItem_Model]=[] @@ -188,8 +188,7 @@ class Output_Model(InputOutputBase_Model): EDMMapping: List[EDMMapping_Model]=[] Version: int=1 - # TODO: WorkflowID==self.wid and WorkflowVersion==self.Version - def TEMP_getLookupChildren(self) -> List[TEMP_DbLookup_Model]: return [TEMP_DbLookup_Model(where='WorkflowExecutions',attrs=['WorkflowID'],values=[self.wid])] + def TEMP_getLookupChildren(self) -> List[TEMP_DbLookup_Model]: return [TEMP_DbLookup_Model(where='WorkflowExecutions',attrs=['WorkflowID','WorkflowVersion'],values=[self.wid,self.Version])] class WorkflowExecution_Model(MongoObj_Model): @@ -213,8 +212,8 @@ class WorkflowExecution_Model(MongoObj_Model): Inputs: str Outputs: str - def TEMP_getChildren(self) -> List[DbRef_Model]: - return [DbRef_Model(where=where,id=id) for where,id in [('IOData',self.Inputs),('IOData',self.Outputs),('fs.files',self.ExecutionLog)] if id is not None and id!=''] + def TEMP_getChildren(self) -> List[Tuple[str,DbRef_Model]]: + return [(attr,DbRef_Model(where=where,id=id)) for where,id,attr in [('IOData',self.Inputs,'Inputs'),('IOData',self.Outputs,'Outputs'),('fs.files',self.ExecutionLog,'ExecutionLog')] if id is not None and id!=''] diff --git a/tools/database-add-parents.py b/tools/database-add-parents.py index 5a3bf1b..a32e3a0 100644 --- a/tools/database-add-parents.py +++ b/tools/database-add-parents.py @@ -1,8 +1,9 @@ -dbPort=27001 +dbPort=27017 from pymongo import MongoClient import pymongo +import pymongo.errors from bson import ObjectId import bson, bson.objectid from rich import print_json @@ -105,7 +106,7 @@ def set_attr_null(dbColl,obj,attr): progress.update(doc_task,description=' ↳[cyan]…',start=False,visible=False) progress.update(chi_task,description=' ↳[yellow]…',start=False,visible=False) - client = MongoClient(f'mongodb://localhost:27017') + client = MongoClient(f'mongodb://localhost:{dbPort}') db = client.MuPIF progress.reset(col_task,start=True) progress.update(col_task,description='↳[green]…',total=len(coll2model),completed=0,visible=True) @@ -125,10 +126,11 @@ def set_attr_null(dbColl,obj,attr): try: obj=Model.model_validate(rec) thisRef=models.DbRef_Model(where=coll,id=obj.dbID) - for i,cref in enumerate(obj.TEMP_getChildren()): + for i,(attr,cref) in enumerate(obj.TEMP_getChildren()): child=resolve_DbRef(db,cref) if child is None: - log.error(f'Unresolvable child {cref=} (setting to null not yet implemented)') + log.error(f'Unresolvable child {cref=}; setting {attr=} to null!') + set_attr_null(dbColl,obj,attr) print_mongo(rec) continue if child.parent is None: