Ejemplo n.º 1
0
 def post(self):
     json_data = request.get_json(force=True)
     app_context.init()
     app_context.application_context = json_data
     log_info(
         "Resource Layout_Detector_WF  Layout_Detector service started",
         app_context.application_context)
     task_id = str("LD-" + str(time.time()).replace('.', '')[0:13])
     task_starttime = eval(str(time.time()).replace('.', '')[0:13])
     #json_data = request.get_json(force = True)
     try:
         error_validator = ValidationResponse(DOWNLOAD_FOLDER)
         if error_validator.format_error(json_data) is True:
             response_gen = Response(json_data, DOWNLOAD_FOLDER)
             response = response_gen.workflow_response(
                 task_id, task_starttime)
             log_info(
                 "Resource Layout_Detector_WF Layout_Detector api response completed",
                 app_context.application_context)
             return jsonify(response)
     except FormatError as e:
         log_error(
             "Resource Layout_Detector_WF Input json format is not correct or dict_key is missing",
             app_context.application_context, e)
         return Status.ERR_request_input_format.value
Ejemplo n.º 2
0
 def nonwf_response(self):
     log_info("non workflow response started the response generation", app_context.application_context)
     input_files = self.json_data['files']
     error_validator = ValidationResponse(self.DOWNLOAD_FOLDER)
     try:
         error_validator.inputfile_list_empty(input_files)
         output_file_response = list()
         for item in input_files:
             input_filename, in_file_type, in_locale = file_ops.accessing_files(item)
             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_locale, in_file_type)
             output_file_response.append(file_res)
         response_true = Status.SUCCESS.value
         response_true['output'] = output_file_response
         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 pdf to block conversion.", app_context.application_context, e)
         response = copy.deepcopy(response)
         return response
Ejemplo n.º 3
0
    def post(self):
        json_data = request.get_json(force=True)
        app_context.init()
        app_context.application_context = json_data
        log_info("Resource Vision_OCR service started", app_context.application_context)

        try:
            error_validator = ValidationResponse(DOWNLOAD_FOLDER)
            if error_validator.format_error(json_data) is True:
                response_gen = Response(json_data, DOWNLOAD_FOLDER)
                response = response_gen.nonwf_response()
                log_info("Resource Vision_OCR api response completed", app_context.application_context)
                return jsonify(response)
        except FormatError as e:
            log_error("Resource Vision_OCR Input json format is not correct or dict_key is missing", app_context.application_context, e)
            return Status.ERR_request_input_format.value
Ejemplo n.º 4
0
 def post(self):
     log_info("Resource BlockMerger", "Block-merger service started", None)
     json_data = request.get_json(force=True)
     try:
         error_validator = ValidationResponse(DOWNLOAD_FOLDER)
         if error_validator.format_error(json_data) is True:
             response_gen = Response(json_data, DOWNLOAD_FOLDER)
             response = response_gen.nonwf_response()
             log_info("Resource BlockMerger",
                      "Block-merger api response completed", None)
             return jsonify(response)
     except FormatError as e:
         log_error(
             "Resource BlockMerger",
             "Input json format is not correct or dict_key is missing",
             None, e)
         return Status.ERR_request_input_format.value
Ejemplo n.º 5
0
 def post(self):
     log_info("Resource BlockMergerWF", "Block-merger service started",
              None)
     task_id = str("BM-" + str(time.time()).replace('.', ''))
     task_starttime = str(time.time()).replace('.', '')
     json_data = request.get_json(force=True)
     try:
         error_validator = ValidationResponse(DOWNLOAD_FOLDER)
         if error_validator.format_error(json_data) is True:
             response_gen = Response(json_data, DOWNLOAD_FOLDER)
             response = response_gen.workflow_response(
                 task_id, task_starttime)
             log_info("Resource BlockMergerWF",
                      "Block-merger api response completed", None)
             return jsonify(response)
     except FormatError as e:
         log_error(
             "Resource BlockMergerWF",
             "Input json format is not correct or dict_key is missing",
             None, e)
         return Status.ERR_request_input_format.value
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    def workflow_response(self, task_id, task_starttime):

        app_context.init()
        app_context.application_context = self.json_data

        input_params, 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)

            # --------------------------

            result = process_incoming_request(app_context, input_params[0],
                                              jobid, workflow_id)

            # --------------------------

            task_endtime = eval(str(time.time()).replace('.', '')[0:13])
            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, result)
            log_info(
                "workflow_response : successfully generated response for workflow",
                app_context.application_context)
            return response_success

        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 ocr.",
                          app_context.application_context, e)
            response = copy.deepcopy(response)
            return response