2323 user ,
2424 knowledge_term ,
2525 weak_supervision ,
26+ comments as comment ,
2627)
2728from submodules .model .enums import NotificationType
2829from controller .labeling_access_link import manager as link_manager
@@ -117,7 +118,7 @@ def import_sample_project(
117118 project_item .id ,
118119 )
119120 notification .send_organization_update (
120- project_item .id , "project_update" , is_global = True
121+ project_item .id , f "project_update: { str ( project_item . id ) } " , is_global = True
121122 )
122123 data = extract_first_zip_data (file_name )
123124 import_file (project_item .id , user_id , data )
@@ -129,14 +130,14 @@ def import_sample_project(
129130 )
130131
131132 notification .send_organization_update (
132- project_item .id , "project_update" , is_global = True
133+ project_item .id , f "project_update: { str ( project_item . id ) } " , is_global = True
133134 )
134135 return project_item
135136
136137
137138def import_file (
138139 project_id : str ,
139- user_id : str ,
140+ import_user_id : str ,
140141 data : Dict [str , Dict [str , Any ]],
141142 task_id : Optional [str ] = None ,
142143) -> None :
@@ -490,7 +491,7 @@ def import_file(
490491 )
491492 ] = data_slice_object .id
492493 link_manager .generate_data_slice_access_link (
493- project_id , user_id , data_slice_object .id , with_commit = False
494+ project_id , import_user_id , data_slice_object .id , with_commit = False
494495 )
495496
496497 for information_source_payload_item in data .get (
@@ -778,6 +779,42 @@ def import_file(
778779 "blacklisted" ,
779780 ),
780781 )
782+ comment_data = data .get ("comments" )
783+ if comment_data :
784+ for comment_item in comment_data :
785+ old_xfkey = comment_item .get ("xfkey" )
786+ new_xfkey = None
787+ xftype = comment_item .get ("xftype" )
788+ if xftype == enums .CommentCategory .RECORD .value :
789+ new_xfkey = record_ids .get (old_xfkey )
790+ if xftype == enums .CommentCategory .LABELING_TASK .value :
791+ new_xfkey = labeling_task_ids .get (old_xfkey )
792+ if xftype == enums .CommentCategory .ATTRIBUTE .value :
793+ new_xfkey = attribute_ids_by_old_id .get (old_xfkey )
794+ if xftype == enums .CommentCategory .LABEL .value :
795+ new_xfkey = labeling_task_labels_ids .get (old_xfkey )
796+ if xftype == enums .CommentCategory .DATA_SLICE .value :
797+ new_xfkey = data_slice_ids .get (old_xfkey )
798+ if xftype == enums .CommentCategory .EMBEDDING .value :
799+ new_xfkey = embedding_ids .get (old_xfkey )
800+ if xftype == enums .CommentCategory .HEURISTIC .value :
801+ new_xfkey = information_source_ids .get (old_xfkey )
802+ if xftype == enums .CommentCategory .KNOWLEDGE_BASE .value :
803+ new_xfkey = knowledge_base_ids .get (old_xfkey )
804+ if not new_xfkey :
805+ continue
806+
807+ comment .create (
808+ xfkey = new_xfkey ,
809+ xftype = comment_item .get ("xftype" ),
810+ comment = comment_item .get ("comment" ),
811+ created_by = import_user_id ,
812+ project_id = project_id ,
813+ order_key = comment_item .get ("order_key" ),
814+ is_markdown = comment_item .get ("is_markdown" ),
815+ created_at = comment_item .get ("created_at" ),
816+ is_private = comment_item .get ("is_private" ),
817+ )
781818
782819 general .commit ()
783820
@@ -787,7 +824,7 @@ def import_file(
787824 ):
788825 embedding_manager .create_embeddings_one_by_one (
789826 project_id ,
790- user_id ,
827+ import_user_id ,
791828 data .get (
792829 "embeddings_data" ,
793830 ),
@@ -802,7 +839,9 @@ def import_file(
802839 logger .info (f"Finished import of project { project_id } " )
803840
804841
805- def get_project_export_dump (project_id : str , export_options : Dict [str , bool ]) -> str :
842+ def get_project_export_dump (
843+ project_id : str , user_id : str , export_options : Dict [str , bool ]
844+ ) -> str :
806845 """Exports data of a project in JSON-String format. Queries all useful database entries and
807846 puts them in a format which again fits for import. For some entities database joins
808847 are useful, so there are vanilla SQL statements in execute-blocks.
@@ -829,6 +868,7 @@ def get_project_export_dump(project_id: str, export_options: Dict[str, bool]) ->
829868 knowledge_bases = []
830869 weak_supervision_task = []
831870 terms = []
871+ comments = []
832872 # -------------------- READ OF ENTITIES BY SQLALCHEMY --------------------
833873
834874 if "basic project data" in export_options :
@@ -874,6 +914,38 @@ def get_project_export_dump(project_id: str, export_options: Dict[str, bool]) ->
874914 knowledge_bases = knowledge_base .get_all (project_id )
875915 terms = knowledge_term .get_terms_by_project_id (project_id )
876916
917+ if "comment data" in export_options :
918+ comments = []
919+ comments += comment .get_by_all_by_category (
920+ enums .CommentCategory .LABELING_TASK , user_id , None , project_id , True
921+ )
922+ comments += comment .get_by_all_by_category (
923+ enums .CommentCategory .ATTRIBUTE , user_id , None , project_id , True
924+ )
925+ comments += comment .get_by_all_by_category (
926+ enums .CommentCategory .LABEL , user_id , None , project_id , True
927+ )
928+ comments += comment .get_by_all_by_category (
929+ enums .CommentCategory .DATA_SLICE , user_id , None , project_id , True
930+ )
931+ if "records" in export_options :
932+ comments += comment .get_by_all_by_category (
933+ enums .CommentCategory .RECORD , user_id , None , project_id , True
934+ )
935+ # only makes sense with records
936+ if "embeddings" in export_options :
937+ comments += comment .get_by_all_by_category (
938+ enums .CommentCategory .EMBEDDING , user_id , None , project_id , True
939+ )
940+ if "information sources" in export_options :
941+ comments += comment .get_by_all_by_category (
942+ enums .CommentCategory .HEURISTIC , user_id , None , project_id , True
943+ )
944+ if "knowledge bases" in export_options :
945+ comments += comment .get_by_all_by_category (
946+ enums .CommentCategory .KNOWLEDGE_BASE , user_id , None , project_id , True
947+ )
948+
877949 # -------------------- FORMATTING OF ENTITIES --------------------
878950 project_details_data = {
879951 "id" : project_item .id ,
@@ -1026,6 +1098,9 @@ def get_project_export_dump(project_id: str, export_options: Dict[str, bool]) ->
10261098 for association_item in data_slice_record_association
10271099 ]
10281100
1101+ # no need to format since db reteurns as json :)
1102+ comment_data = comments
1103+
10291104 # -------------------- READ AND FORMATTING OF ENTITIES WITH SQL JOINS --------------------
10301105
10311106 record_label_association_tokens_data = [
@@ -1116,6 +1191,7 @@ def get_project_export_dump(project_id: str, export_options: Dict[str, bool]) ->
11161191 "terms_data" : terms_data ,
11171192 "data_slice_data" : data_slice_data ,
11181193 "data_slice_record_association_data" : data_slice_record_association_data ,
1194+ "comments" : comment_data ,
11191195 }
11201196
11211197 logger .info (f"Finished export of project { project_id } " )
0 commit comments