3535 FoilHoleResponse ,
3636 MicrographResponse ,
3737)
38- from src .epu_data_intake .data_model import (
39- EpuSessionData ,
40- Grid ,
38+ from src .epu_data_intake .model . schemas import (
39+ AcquisitionData ,
40+ GridData ,
4141 GridSquareData ,
4242 FoilHoleData ,
4343 MicrographData ,
@@ -66,10 +66,11 @@ class EntityConverter:
6666 """
6767
6868 @staticmethod
69- def epu_session_to_request (entity : EpuSessionData ) -> AcquisitionCreateRequest :
69+ def acquisition_to_request (entity : AcquisitionData ) -> AcquisitionCreateRequest :
7070 """Convert EPU session data to acquisition request model"""
7171 return AcquisitionCreateRequest (
72- id = entity .id ,
72+ uuid = entity .uuid ,
73+ # TODO check if natural `id` should also be included
7374 name = entity .name ,
7475 start_time = entity .start_time ,
7576 storage_path = entity .storage_path ,
@@ -80,11 +81,11 @@ def epu_session_to_request(entity: EpuSessionData) -> AcquisitionCreateRequest:
8081 )
8182
8283 @staticmethod
83- def grid_to_request (entity : Grid , acquisition_id : str ) -> GridCreateRequest :
84+ def grid_to_request (entity : GridData , acquisition_id : str ) -> GridCreateRequest :
8485 """Convert Grid data to grid request model"""
8586 return GridCreateRequest (
86- id = entity .id ,
87- name = entity .session_data .name if entity .session_data else "Unknown" ,
87+ uuid = entity .uuid ,
88+ name = entity .acquisition_data .name if entity .acquisition_data else "Unknown" , # Fixed to acquisition_data
8889 acquisition_id = acquisition_id ,
8990 data_dir = str (entity .data_dir ) if entity .data_dir else None ,
9091 atlas_dir = str (entity .atlas_dir ) if entity .atlas_dir else None ,
@@ -407,11 +408,11 @@ async def aget_acquisitions(self) -> List[AcquisitionResponse]:
407408 get_acquisitions = _sync_wrap (aget_acquisitions )
408409
409410 async def acreate_acquisition (self ,
410- acquisition : Union [AcquisitionCreateRequest , EpuSessionData ]) -> AcquisitionResponse :
411+ acquisition : Union [AcquisitionCreateRequest , AcquisitionData ]) -> AcquisitionResponse :
411412 """Create a new acquisition (async)"""
412- # Convert EpuSessionData to AcquisitionCreateRequest if needed
413- if isinstance (acquisition , EpuSessionData ):
414- acquisition = EntityConverter .epu_session_to_request (acquisition )
413+ # Convert AcquisitionData to AcquisitionCreateRequest if needed
414+ if isinstance (acquisition , AcquisitionData ):
415+ acquisition = EntityConverter .acquisition_to_request (acquisition )
415416
416417 response = await self ._request ("post" , "acquisitions" , acquisition , AcquisitionResponse )
417418 # Store ID mapping
@@ -473,11 +474,11 @@ async def aget_acquisition_grids(self, acquisition_id: str) -> List[GridResponse
473474 async def acreate_acquisition_grid (
474475 self ,
475476 acquisition_id : str ,
476- grid : Union [GridCreateRequest , Grid ]
477+ grid : Union [GridCreateRequest , GridData ]
477478 ) -> GridResponse :
478479 """Create a new grid for a specific acquisition (async)"""
479480 # Convert Grid to GridCreateRequest if needed
480- if isinstance (grid , Grid ):
481+ if isinstance (grid , GridData ):
481482 grid_request = EntityConverter .grid_to_request (grid , acquisition_id )
482483 else :
483484 grid_request = grid
@@ -787,13 +788,13 @@ def create(self, entity_type: str, entity_id: str, entity: Any, parent: Optional
787788 self ._logger .info (f"Creating { entity_type } /{ entity_id } via API" +
788789 (f" with parent { parent [0 ]} /{ parent [1 ]} " if parent else "" ))
789790
790- if entity_type == "acquisition" and isinstance (entity , EpuSessionData ):
791+ if entity_type == "acquisition" and isinstance (entity , AcquisitionData ):
791792 response = self .create_acquisition (entity )
792793 self ._store_entity_id_mapping ("acquisition" , entity_id , response .id )
793794 self ._logger .info (f"Successfully created acquisition { entity_id } (DB ID: { response .id } )" )
794795 return True
795796
796- elif entity_type == "grid" and isinstance (entity , Grid ):
797+ elif entity_type == "grid" and isinstance (entity , GridData ):
797798 if parent and parent [0 ] == "acquisition" :
798799 acquisition_db_id = self ._get_db_id ("acquisition" , parent [1 ])
799800 if not acquisition_db_id :
@@ -823,6 +824,27 @@ def create(self, entity_type: str, entity_id: str, entity: Any, parent: Optional
823824 self ._logger .error ("Cannot create gridsquare: No valid grid parent" )
824825 return False
825826
827+ # TODO this looks like nonsense, check it can be thrown away:
828+ # elif entity_type == "gridsquare" and isinstance(entity, GridSquareData):
829+ # if parent and parent[0] == "grid":
830+ # grid_uuid = parent[1]
831+ # # Ensure grid_uuid is set on the entity
832+ # if not hasattr(entity, 'grid_uuid') or not entity.grid_uuid:
833+ # entity.grid_uuid = grid_uuid
834+ #
835+ # grid_db_id = self._get_db_id("grid", grid_uuid)
836+ # if not grid_db_id:
837+ # self._logger.error(f"Cannot create gridsquare: Grid {grid_uuid} not found in ID map")
838+ # return False
839+ #
840+ # response = self.create_grid_gridsquare(grid_db_id, entity)
841+ # self._store_entity_id_mapping("gridsquare", entity_id, response.id)
842+ # self._logger.info(f"Successfully created gridsquare {entity_id} (DB ID: {response.id})")
843+ # return True
844+ # else:
845+ # self._logger.error("Cannot create gridsquare: No valid grid parent")
846+ # return False
847+
826848 elif entity_type == "foilhole" and isinstance (entity , FoilHoleData ):
827849 if parent and parent [0 ] == "gridsquare" :
828850 gridsquare_db_id = self ._get_db_id ("gridsquare" , parent [1 ])
0 commit comments