@@ -4345,7 +4345,7 @@ async def query_data_agreement_version_history(self, data_agreement_id: str) ->
4345
4345
f"Failed to fetch all data agreements from wallet; Reason: { e .roll_up } "
4346
4346
)
4347
4347
4348
- def serialize_personal_data_record (self , * , personal_data_records : typing .List [DataAgreementPersonalDataRecord ], is_list : bool = True ) -> typing .List [dict ]:
4348
+ def serialize_personal_data_record (self , * , personal_data_records : typing .List [dict ], is_list : bool = True ) -> typing .List [dict ]:
4349
4349
"""
4350
4350
Serialize personal data records.
4351
4351
@@ -4357,26 +4357,11 @@ def serialize_personal_data_record(self, *, personal_data_records: typing.List[D
4357
4357
Serialized personal data records.
4358
4358
"""
4359
4359
4360
- personal_data_records_list : typing .List [dict ] = []
4361
-
4362
- for personal_data_record in personal_data_records :
4363
- temp_personal_data_record = {
4364
- "attribute_id" : personal_data_record .personal_data_id ,
4365
- "attribute_name" : personal_data_record .attribute_name ,
4366
- "attribute_description" : personal_data_record .attribute_description ,
4367
- "data_agreement_template_id" : personal_data_record .da_template_id ,
4368
- "data_agreement_template_version" : personal_data_record .da_template_version ,
4369
- "created_at" : str_to_epoch (personal_data_record .created_at ),
4370
- "updated_at" : str_to_epoch (personal_data_record .updated_at ),
4371
- }
4372
-
4373
- personal_data_records_list .append (temp_personal_data_record )
4374
-
4375
4360
# Sort personal data list by created_at in descending order
4376
- personal_data_records_list = sorted (
4377
- personal_data_records_list , key = lambda k : k ['created_at' ], reverse = True )
4361
+ personal_data_records = sorted (
4362
+ personal_data_records , key = lambda k : k ['created_at' ], reverse = True )
4378
4363
4379
- return personal_data_records_list if is_list else personal_data_records_list [0 ]
4364
+ return personal_data_records if is_list else personal_data_records [0 ]
4380
4365
4381
4366
async def update_personal_data_description (self , personal_data_id : str , updated_description : str ) -> typing .Tuple [DataAgreementPersonalDataRecord , dict ]:
4382
4367
@@ -4439,7 +4424,7 @@ async def update_personal_data_description(self, personal_data_id: str, updated_
4439
4424
except (StorageError , ValidationError ) as err :
4440
4425
raise ADAManagerError (err_string .format (err = err )) from err
4441
4426
4442
- async def query_da_personal_data_in_wallet (self , personal_data_id : str = None ) -> typing .Tuple [ typing . List [DataAgreementPersonalDataRecord ], dict ]:
4427
+ async def query_da_personal_data_in_wallet (self , personal_data_id : str = None , method_of_use : str = None ) -> typing .List [dict ]:
4443
4428
"""
4444
4429
Query personal data in the wallet.
4445
4430
"""
@@ -4460,8 +4445,41 @@ async def query_da_personal_data_in_wallet(self, personal_data_id: str = None) -
4460
4445
else :
4461
4446
matched_personal_data_records = personal_data_records
4462
4447
4463
- return matched_personal_data_records , self .serialize_personal_data_record (personal_data_records = matched_personal_data_records , is_list = True )
4464
- except StorageSearchError as e :
4448
+ serialised_personal_data_records = []
4449
+
4450
+ # Iterate through personal data
4451
+ for pd in matched_personal_data_records :
4452
+
4453
+ # Fetch data agreement template.
4454
+ data_agreement_record : DataAgreementV1Record = await DataAgreementV1Record .retrieve_non_deleted_data_agreement_by_id (
4455
+ self .context ,
4456
+ pd .da_template_id
4457
+ )
4458
+
4459
+ temp_pd = {
4460
+ "attribute_id" : pd .personal_data_id ,
4461
+ "attribute_name" : pd .attribute_name ,
4462
+ "attribute_description" : pd .attribute_description ,
4463
+ "data_agreement" : {
4464
+ "data_agreement_id" : data_agreement_record .data_agreement_record_id ,
4465
+ "method_of_use" : data_agreement_record .method_of_use ,
4466
+ },
4467
+ "created_at" : str_to_epoch (pd .created_at ),
4468
+ "updated_at" : str_to_epoch (pd .updated_at ),
4469
+ }
4470
+
4471
+ if method_of_use :
4472
+ if data_agreement_record .method_of_use == method_of_use :
4473
+ serialised_personal_data_records .append (temp_pd )
4474
+ else :
4475
+ serialised_personal_data_records .append (temp_pd )
4476
+
4477
+ return self .serialize_personal_data_record (
4478
+ personal_data_records = serialised_personal_data_records ,
4479
+ is_list = True
4480
+ )
4481
+
4482
+ except (StorageSearchError ) as e :
4465
4483
# Raise an error
4466
4484
raise ADAManagerError (
4467
4485
f"Failed to fetch all data agreements from wallet: { e } "
0 commit comments