1010from anuvaad_auditor .errorhandler import post_error_wf , post_error , log_exception
1111from anuvaad_auditor .loghandler import log_info , log_error
1212from repository .redisrepo import REDISRepository
13+ from service .pipelinecalls import PipelineCalls
1314from configs .wfmconfig import app_context , workflowCodesTranslation
1415import datetime
1516
1920wfmutils = WFMUtils ()
2021validator = WFMValidator ()
2122redisRepo = REDISRepository ()
23+ pipelineCalls = PipelineCalls ()
2224
2325class WFMService :
2426 def __init__ (self ):
@@ -389,6 +391,9 @@ def get_job_details_bulk(self, req_criteria, skip_pagination, isReviewer=False):
389391 jobIDs .append (jobID )
390392 if len (jobIDs ) > 0 :
391393 criteria ["jobID" ] = {"$in" : jobIDs }
394+ if 'inputFileName' in req_criteria .keys ():
395+ jobName_pattern = req_criteria ["inputFileName" ]
396+ criteria ["input.jobName" ] = {"$regex" : jobName_pattern }
392397 if 'orgIDs' in req_criteria .keys ():
393398 if req_criteria ["orgIDs" ]:
394399 orgIDs = []
@@ -404,7 +409,13 @@ def get_job_details_bulk(self, req_criteria, skip_pagination, isReviewer=False):
404409 if currentStat :
405410 currentStatus .append (currentStat )
406411 if len (currentStatus ) > 0 :
407- criteria ["granularity.currentStatus" ] = {"$in" : currentStatus }
412+ if "auto_translation_completed" in currentStatus :
413+ criteria ["$or" ] = [
414+ {"granularity.currentStatus" : {"$in" : currentStatus }},
415+ {"granularity.currentStatus" : {"$exists" : False }}
416+ ]
417+ else :
418+ criteria ["granularity.currentStatus" ] = {"$in" : currentStatus }
408419 if 'filterByStartTime' in req_criteria .keys ():
409420 if 'startTimeStamp' in req_criteria ['filterByStartTime' ].keys () and 'endTimeStamp' in req_criteria ['filterByStartTime' ].keys ():
410421 criteria ["startTime" ] = { "$gte" : req_criteria ['filterByStartTime' ]['startTimeStamp' ], "$lte" : req_criteria ['filterByStartTime' ]['endTimeStamp' ]}
@@ -581,4 +592,92 @@ def get_active_doc_count(self):
581592 response = redisRepo .get_active_count ()
582593 return response
583594 except Exception as e :
584- log_exception ("Active Job Status Retrieval: {wf_async_input['jobID']} " + str (e ), None , e )
595+ log_exception ("Active Job Status Retrieval: {wf_async_input['jobID']} " + str (e ), None , e )
596+
597+ def digitization_translation_pipeline (self ,data ):
598+ """
599+ {
600+ "record_id": "A_FWLBOD20TESOT-hnHgN-1693227866067%7C0-16932280318450673.json",
601+ "user_id": "d225fb2cd78a45078518356548f396ff1686290705872",
602+ "file_type": "pdf",
603+ "file_name": "name.pdf"
604+ "translation_async_flow" : {
605+ "workflowCode": "WF_A_FCBMTKTR",
606+ "jobName": "1958_1_1150_1155_updated.pdf",
607+ "jobDescription": "",
608+ "files": [
609+ {
610+ "path": "01c440b8-8aac-4352-9b44-c3fbf1ddca6e.pdf",
611+ "type": "pdf",
612+ "locale": "en",
613+ "model": {
614+ "uuid": "687baea0-4512-4fb9-9264-5c7b368afc59",
615+ "is_primary": true,
616+ "model_id": 103,
617+ "model_name": "English-Hindi IndicTrans Model-1",
618+ "source_language_code": "en",
619+ "source_language_name": "English",
620+ "target_language_code": "hi",
621+ "target_language_name": "Hindi",
622+ "description": "AAI4B en-hi model-1(indictrans/fairseq)",
623+ "status": "ACTIVE",
624+ "connection_details": {
625+ "kafka": {
626+ "input_topic": "KAFKA_AAI4B_NMT_TRANSLATION_INPUT_TOPIC",
627+ "output_topic": "KAFKA_AAI4B_NMT_TRANSLATION_OUTPUT_TOPIC"
628+ },
629+ "translation": {
630+ "api_endpoint": "AAIB_NMT_TRANSLATE_ENDPOINT",
631+ "host": "AAI4B_NMT_HOST"
632+ },
633+ "interactive": {
634+ "api_endpoint": "AAIB_NMT_IT_ENDPOINT",
635+ "host": "AAI4B_NMT_HOST"
636+ }
637+ },
638+ "interactive_translation": true
639+ },
640+ "context": "JUDICIARY",
641+ "modifiedSentences": "a"
642+ }
643+ ]
644+ }
645+ }
646+ """
647+ try :
648+ if "record_id" not in data .keys ():
649+ return {"status" : "Error" , "reason" :"record_id missing" }
650+ if data ["file_type" ] in ["jpg" ,"bmp" ,"png" ,"svg" ,"jpeg" ]:
651+ data ["record_id" ] = data ["record_id" ].replace ("%7C" ,"|" )
652+ data ["file_type" ] = "pdf"
653+ data ["file_name" ] = data ["file_name" ].replace (data ["file_name" ].split ("." )[- 1 ],"pdf" )
654+
655+ document = pipelineCalls .document_export (data ["user_id" ],data ["record_id" ],data ["file_type" ],data ["metadata" ])
656+ if document is None :
657+ return {"status" :"Error" ,"reason" :"Document Export Failed" }
658+ file_content = pipelineCalls .download_file (document )
659+ if file_content is None :
660+ return {"status" :"Error" ,"reason" :"File Download Failed" }
661+
662+ if not os .path .exists ("upload_files" ):
663+ # If it doesn't exist, create it
664+ os .makedirs ("upload_files" )
665+
666+ with open ("./upload_files/" + data ["file_name" ], "wb" ) as file :
667+ file .write (file_content )
668+
669+ file_id = pipelineCalls .upload_files ("./upload_files/" + data ["file_name" ],data ["metadata" ])
670+ if file_id is None :
671+ return {"status" :"Error" ,"reason" :"File Upload Failed" }
672+
673+ # Delete uploaded file
674+ try :
675+ os .remove ("./upload_files/" + data ["file_name" ])
676+ except Exception as e :
677+ log_error (f"Exception during file deletion" ,app_context ,e )
678+
679+ response = pipelineCalls .translate (data ["file_name" ],file_id ,data ["translation_async_flow" ],data ["metadata" ])
680+ return response
681+ except Exception as e :
682+ log_error (f"Exception occurred { e } " ,e ,app_context )
683+
0 commit comments