def nonwf_response(self): log_info("non workflow response started the response generation", app_context.application_context) input_files = self.json_data['input']['inputs'] app_context.init() app_context.application_context = self.json_data error_validator = ValidationResponse(self.DOWNLOAD_FOLDER) try: error_validator.inputfile_list_error(input_files) # output_file_response = list() # for item in input_files: # input_filename, in_file_type, identifier = file_ops.accessing_files(item['file']) # output_json_data = DocumentStructure(None, input_filename) # output_filename_json = file_ops.writing_json_file(i, output_json_data, self.DOWNLOAD_FOLDER) # file_res = file_ops.one_filename_response(input_filename, output_filename_json, in_file_type) # output_file_response.append(file_res) response_true = Status.SUCCESS.value #response_true['output'] = output_file_response output_json_data = Service(app_context=app_context) output_filename_json = file_ops.writing_json_file( 0, output_json_data, self.DOWNLOAD_FOLDER) response_true = file_ops.one_filename_response( output_filename_json, langs=' ') log_info( "non workflow_response successfully generated response for rest server", app_context.application_context) response_true = copy.deepcopy(response_true) return response_true except FileErrors as e: response_custom = Status.ERR_STATUS.value response_custom['message'] = e.message response = file_ops.error_handler(response_custom, e.code, False) log_exception( "non workflow_response some error occured while validating file", app_context.application_context, e) response = copy.deepcopy(response) return response except ServiceError as e: response_custom = Status.ERR_STATUS.value response_custom['message'] = str(e) response = file_ops.error_handler(response_custom, "SERVICE_ERROR", False) log_exception( "non workflow_response Something went wrong during ocr.", app_context.application_context, e) response = copy.deepcopy(response) return response
def workflow_response(self, task_id, task_starttime): input_files, workflow_id, jobid, tool_name, step_order = file_ops.json_input_format( self.json_data) log_info("workflow_response", "started the response generation", jobid) error_validator = ValidationResponse(self.DOWNLOAD_FOLDER) try: error_validator.wf_keyerror(jobid, workflow_id, tool_name, step_order) error_validator.inputfile_list_error(input_files) output_file_response = list() for i, item in enumerate(input_files): input_filename, in_file_type, in_locale = file_ops.accessing_files( item) output_json_data = DocumentStructure(jobid=jobid, file_name=input_filename, lang=in_locale) output_filename_json = file_ops.writing_json_file( i, output_json_data, self.DOWNLOAD_FOLDER) file_res = file_ops.one_filename_response( input_filename, output_filename_json, in_locale, in_file_type) output_file_response.append(file_res) task_endtime = str(time.time()).replace('.', '') response_true = CustomResponse(Status.SUCCESS.value, jobid, task_id) response_success = response_true.success_response( workflow_id, task_starttime, task_endtime, tool_name, step_order, output_file_response) response = copy.deepcopy(response_success) log_info("workflow_response", "successfully generated response for workflow", jobid) return response except WorkflowkeyError as e: response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id) response_custom.status_code['message'] = str(e) response = file_ops.error_handler(response_custom.status_code, "WORKFLOWKEY-ERROR", True) log_exception("workflow_response", "workflow key error: key value missing", jobid, e) response = copy.deepcopy(response) return response except FileErrors as e: response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id) response_custom.status_code['message'] = e.message response = file_ops.error_handler(response_custom.status_code, e.code, True) log_exception("workflow_response", "some error occured while validating file", jobid, e) response = copy.deepcopy(response) return response except ServiceError as e: response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id) response_custom.status_code['message'] = str(e) response = file_ops.error_handler(response_custom.status_code, "SERVICE_ERROR", True) log_exception( "workflow_response", "Something went wrong during pdf to block conversion.", jobid, e) response = copy.deepcopy(response) return response
def workflow_response(self, task_id, task_starttime, debug_flush=False): app_context.init() app_context.application_context = {} input_files, workflow_id, jobid, tool_name, step_order = file_ops.json_input_format(self.json_data) log_info("workflow_response started the response generation", app_context.application_context) error_validator = ValidationResponse(self.DOWNLOAD_FOLDER) try: error_validator.wf_keyerror(jobid, workflow_id, tool_name, step_order) error_validator.inputfile_list_error(input_files) output_file_response = list() for i, item in enumerate(input_files): input_filename, in_file_type, in_locale = file_ops.accessing_files(item) self.json_data['taskID'] = task_id app_context.application_context = self.json_data if debug_flush == False: bm_response = DocumentStructure(app_context=app_context, file_name=input_filename, lang=in_locale) if bm_response['code'] == 200: output_filename_json = file_ops.writing_json_file(i, bm_response['rsp'], self.DOWNLOAD_FOLDER) file_res = file_ops.one_filename_response(input_filename, output_filename_json, in_locale, in_file_type) output_file_response.append(file_res) task_endtime = str(time.time()).replace('.', '') response_true = CustomResponse(Status.SUCCESS.value, jobid, task_id) response_success = response_true.success_response(workflow_id, task_starttime, task_endtime, tool_name, step_order, output_file_response) response = copy.deepcopy(response_success) log_info("successfully generated response for workflow", app_context.application_context) return response else: post_error_wf(bm_response.code, bm_response.message, app_context.application_context, None) return None else: log_info('flushing queue data, not handling file {}'.format(input_files), app_context.application_context) post_error_wf(400, 'flushing queue data, not handling file {}'.format(input_files), app_context.application_context, None) return None except WorkflowkeyError as e: response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id) response_custom.status_code['message'] = str(e) response = file_ops.error_handler(response_custom.status_code, "WORKFLOWKEY-ERROR", True) log_exception("workflow_response workflow key error: key value missing", app_context.application_context, e) response = copy.deepcopy(response) return response except FileErrors as e: response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id) response_custom.status_code['message'] = e.message response = file_ops.error_handler(response_custom.status_code, e.code, True) log_exception("workflow_response some error occured while validating file", app_context.application_context, e) response = copy.deepcopy(response) return response except ServiceError as e: response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id) response_custom.status_code['message'] = str(e) response = file_ops.error_handler(response_custom.status_code, "SERVICE_ERROR", True) log_exception("workflow_response Something went wrong during pdf to block conversion.", app_context.application_context, e) response = copy.deepcopy(response) return response