@@ -63,13 +63,12 @@ def get_all_specific_asset_ids_by_aas_id(self, aas_id: model.Identifier) -> List
6363
6464 def add_specific_asset_ids_to_aas (self , aas_id : model .Identifier ,
6565 asset_ids : List [model .SpecificAssetId ]) -> None :
66- serialized_assets = [encoder .default (asset_id ) for asset_id in asset_ids ]
67- if aas_id in self .aas_id_to_asset_ids :
68- for asset in serialized_assets :
69- if asset not in self .aas_id_to_asset_ids [aas_id ]:
70- self .aas_id_to_asset_ids [aas_id ].append (asset )
71- else :
72- self .aas_id_to_asset_ids [aas_id ] = serialized_assets [:]
66+
67+ if aas_id not in self .aas_id_to_asset_ids :
68+ self .aas_id_to_asset_ids [aas_id ] = set ()
69+
70+ for asset in asset_ids :
71+ self .aas_id_to_asset_ids [aas_id ].add (asset )
7372
7473 def delete_specific_asset_ids_by_aas_id (self , aas_id : model .Identifier ) -> None :
7574 key = aas_id
@@ -85,16 +84,16 @@ def search_aas_ids_by_asset_link(self, asset_link: server_model.AssetLink) -> Li
8584 return result
8685
8786 def _add_aas_id_to_specific_asset_id (self , asset_id : model .SpecificAssetId , aas_id : model .Identifier ) -> None :
88- asset_key = f"{ asset_id .name } :{ asset_id .value } "
89- if asset_key in self .asset_id_to_aas_ids :
90- self .asset_id_to_aas_ids [asset_key ].add (aas_id )
87+ if asset_id in self .asset_id_to_aas_ids :
88+ self .asset_id_to_aas_ids [asset_id ].add (aas_id )
9189 else :
92- self .asset_id_to_aas_ids [asset_key ] = {aas_id }
90+ self .asset_id_to_aas_ids [asset_id ] = {aas_id }
9391
9492 def _delete_aas_id_from_specific_asset_ids (self , asset_id : model .SpecificAssetId , aas_id : model .Identifier ) -> None :
95- asset_key = f"{ asset_id .name } :{ asset_id .value } "
96- if asset_key in self .asset_id_to_aas_ids :
97- self .asset_id_to_aas_ids [asset_key ].discard (aas_id )
93+ if asset_id in self .asset_id_to_aas_ids :
94+ self .asset_id_to_aas_ids [asset_id ].discard (aas_id )
95+
96+
9897
9998
10099class MongoDiscoveryStore (AbstractDiscoveryStore ):
@@ -103,7 +102,7 @@ def __init__(self,
103102 db_name : str = "basyx" ,
104103 coll_aas_to_assets : str = "aas_to_assets" ,
105104 coll_asset_to_aas : str = "asset_to_aas" ):
106- self .client = MongoClient (uri )
105+ self .client : MongoClient = MongoClient (uri )
107106 self .db = self .client [db_name ]
108107 self .coll_aas_to_assets : Collection = self .db [coll_aas_to_assets ]
109108 self .coll_asset_to_aas : Collection = self .db [coll_asset_to_aas ]
@@ -181,17 +180,16 @@ def search_all_aas_ids_by_asset_link(self, request: Request, url_args: dict, res
181180 for asset_link in asset_links :
182181 aas_keys = self .persistent_store .search_aas_ids_by_asset_link (asset_link )
183182 matching_aas_keys .update (aas_keys )
184- matching_aas_keys = list (matching_aas_keys )
185- paginated_slice , cursor = self ._get_slice (request , matching_aas_keys )
183+ paginated_slice , cursor = self ._get_slice (request , list (matching_aas_keys ))
186184 return response_t (list (paginated_slice ), cursor = cursor )
187185
188186 def get_all_specific_asset_ids_by_aas_id (self , request : Request , url_args : dict , response_t : type , ** _kwargs ) -> Response :
189- aas_identifier = url_args . get ( "aas_id" )
187+ aas_identifier = str ( url_args [ "aas_id" ] )
190188 asset_ids = self .persistent_store .get_all_specific_asset_ids_by_aas_id (aas_identifier )
191189 return response_t (asset_ids )
192190
193191 def post_all_asset_links_by_id (self , request : Request , url_args : dict , response_t : type , ** _kwargs ) -> Response :
194- aas_identifier = url_args . get ( "aas_id" )
192+ aas_identifier = str ( url_args [ "aas_id" ] )
195193 specific_asset_ids = HTTPApiDecoder .request_body_list (request , model .SpecificAssetId , False )
196194 self .persistent_store .add_specific_asset_ids_to_aas (aas_identifier , specific_asset_ids )
197195 for asset_id in specific_asset_ids :
@@ -200,7 +198,7 @@ def post_all_asset_links_by_id(self, request: Request, url_args: dict, response_
200198 return response_t (updated )
201199
202200 def delete_all_asset_links_by_id (self , request : Request , url_args : dict , response_t : type , ** _kwargs ) -> Response :
203- aas_identifier = url_args . get ( "aas_id" )
201+ aas_identifier = str ( url_args [ "aas_id" ] )
204202 self .persistent_store .delete_specific_asset_ids_by_aas_id (aas_identifier )
205203 for key in list (self .persistent_store .asset_id_to_aas_ids .keys ()):
206204 self .persistent_store .asset_id_to_aas_ids [key ].discard (aas_identifier )
0 commit comments