def get(self, nr_id): return {"message": "Not Implemented"}, 503 try: nr_model = Request.query.get(nr_id) if nr_model.requestTypeCd and (not nr_model.entity_type_cd or not nr_model.request_action_cd): # If requestTypeCd is set, but a request_entity (entity_type_cd) and a request_action (request_action_cd) # are not, use get_mapped_entity_and_action_code to map the values from the requestTypeCd entity_type, request_action = get_mapped_entity_and_action_code( nr_model.requestTypeCd) nr_model.entity_type_cd = entity_type nr_model.request_action_cd = request_action response_data = nr_model.json() # If draft, get the wait time and oldest queued request if nr_model.stateCd == 'DRAFT': service = WaitTimeStatsService() wait_time_response = service.get_waiting_time_dict() response_data.update(wait_time_response) # Add the list of valid Name Request actions for the given state to the response response_data['actions'] = get_nr_state_actions( nr_model.stateCd, nr_model) return jsonify(response_data), 200 except Exception as err: current_app.logger.debug(repr(err)) return handle_exception(err, 'Error retrieving the NR.', 500)
def get(self, nr_id): try: nr_model = Request.query.get(nr_id) if nr_model.requestTypeCd and (not nr_model.entity_type_cd or not nr_model.request_action_cd): # If requestTypeCd is set, but a request_entity (entity_type_cd) and a request_action (request_action_cd) # are not, use get_mapped_entity_and_action_code to map the values from the requestTypeCd entity_type, request_action = get_mapped_entity_and_action_code(nr_model.requestTypeCd) nr_model.entity_type_cd = entity_type nr_model.request_action_cd = request_action response_data = nr_model.json() # Add the list of valid Name Request actions for the given state to the response response_data['actions'] = get_nr_state_actions(nr_model.stateCd, nr_model) return jsonify(response_data), 200 except Exception as err: return handle_exception(err, 'Error retrieving the NR.', 500)
def _get_template_data(nr_model): if nr_model.requestTypeCd and (not nr_model.entity_type_cd or not nr_model.request_action_cd): # For the NRO ones. entity_type, request_action = get_mapped_entity_and_action_code( nr_model.requestTypeCd) nr_model.entity_type_cd = entity_type nr_model.request_action_cd = request_action nr_report_json = nr_model.json() nr_report_json[ 'entityTypeDescription'] = ReportResource._get_entity_type_description( nr_model.entity_type_cd) isXPRO = nr_model.entity_type_cd in [ 'XCR', 'XUL', 'RLC', 'XLP', 'XLL', 'XCP', 'XSO' ] nr_report_json['isXPRO'] = isXPRO nr_report_json['requestCodeDescription'] = \ ReportResource._get_request_action_cd_description(nr_report_json['request_action_cd']) nr_report_json['nrStateDescription'] = \ ReportResource._get_state_cd_description(nr_report_json['stateCd']) if isXPRO and nr_report_json['nrStateDescription'] == 'Rejected': nr_report_json['nrStateDescription'] = 'Not Approved' if nr_report_json['expirationDate']: nr_report_json[ 'expirationDate'] = nr_model.expirationDate.strftime( '%B %-d, %Y') if nr_report_json['submittedDate']: nr_report_json['submittedDate'] = nr_model.submittedDate.strftime( '%B %-d, %Y') if nr_report_json['applicants']['countryTypeCd']: nr_report_json['applicants']['countryName'] = \ pycountry.countries.search_fuzzy(nr_report_json['applicants']['countryTypeCd'])[0].name actions_obj = ReportResource._get_next_action_text( nr_model.entity_type_cd) if actions_obj: action_text = actions_obj.get(nr_report_json['request_action_cd']) if not action_text: action_text = actions_obj.get('DEFAULT') if action_text: nr_report_json['nextAction'] = action_text return nr_report_json
def get_mapped_entity_and_action_code(cls, request_type): return get_mapped_entity_and_action_code(request_type)
def get(self): try: filters = [] # Validate the request if len(request.args) == 0: raise InvalidInputError( message='No query parameters were specified in the request' ) nr_num_query_str = get_query_param_str('nrNum') email_address_query_str = get_query_param_str('emailAddress') phone_number_query_str = get_query_param_str('phoneNumber') if not nr_num_query_str: raise InvalidInputError(message='An nrNum must be provided') else: if not email_address_query_str and not phone_number_query_str: raise InvalidInputError( message= 'Either an emailAddress or phoneNumber must be provided' ) # Continue nr_num = parse_nr_num(nr_num_query_str) email_address = email_address_query_str phone_number = get_query_param_str('phoneNumber') # Filter on addresses # address_line = get_query_param_str('addrLine1') if nr_num: filters.append(func.lower(Request.nrNum) == nr_num.lower()) if phone_number: strip_phone_number_chars_regex = r"[^0-9]" filters.append( Request.applicants.any( func.regexp_replace( Applicant.phoneNumber, strip_phone_number_chars_regex, '', 'g').contains( re.sub(strip_phone_number_chars_regex, '', phone_number)))) if email_address: filters.append( Request.applicants.any( func.lower(Applicant.emailAddress).startswith( email_address.lower()))) ''' Filter on addresses if address_line: filters.append( Request.applicants.any( func.lower(Applicant.addrLine1).startswith(address_line.lower()) ) ) ''' criteria = RequestQueryCriteria(nr_num=nr_num, filters=filters) results = Request.find_by_criteria(criteria) if not results: results = [] except InvalidInputError as err: return handle_exception(err, err.message, 400) except Exception as err: return handle_exception(err, 'Error retrieving the NR from the db.', 500) if nr_num and len(results) == 1: nr_model = results[0] if nr_model.requestTypeCd and (not nr_model.entity_type_cd or not nr_model.request_action_cd): # If requestTypeCd is set, but a request_entity (entity_type_cd) and a request_action (request_action_cd) # are not, use get_mapped_entity_and_action_code to map the values from the requestTypeCd entity_type, request_action = get_mapped_entity_and_action_code( nr_model.requestTypeCd) nr_model.entity_type_cd = entity_type nr_model.request_action_cd = request_action response_data = nr_model.json() # Add the list of valid Name Request actions for the given state to the response response_data['actions'] = get_nr_state_actions( results[0].stateCd, results[0]) return jsonify(response_data), 200 elif len(results) > 0: # We won't add the list of valid Name Request actions for the given state to the response if we're sending back a list # If the user / client accessing this data needs the Name Request actions, GET the individual record using NameRequest.get # This method, NameRequests.get is for Existing NR Search return jsonify(list(map(lambda result: result.json(), results))), 200 # We won't add the list of valid Name Request actions for the given state to the response if we're sending back a list # If the user / client accessing this data needs the Name Request actions, GET the individual record using NameRequest.get # This method, NameRequests.get is for Existing NR Search return jsonify(results), 200
def get(self): try: if not full_access_to_name_request(request): return {"message": "You do not have access to this NameRequest."}, 403 filters = [] nr_num_query_str = request.headers['Bcreg-Nr'] or request.headers['Bcreg-Nrl'] email_address_query_str = request.headers['Bcreg-User-Email'] phone_number_query_str = request.headers['Bcreg-User-Phone'] if not nr_num_query_str: raise InvalidInputError(message='An nrNum must be provided') else: if not email_address_query_str and not phone_number_query_str: raise InvalidInputError(message='Either an emailAddress or phoneNumber must be provided') # Continue nr_num = parse_nr_num(nr_num_query_str) email_address = email_address_query_str phone_number = phone_number_query_str # Filter on addresses # address_line = get_query_param_str('addrLine1') if nr_num: filters.append(func.lower(Request.nrNum) == nr_num.lower()) if phone_number: strip_phone_number_chars_regex = r"[^0-9]" filters.append( Request.applicants.any( func.regexp_replace(Applicant.phoneNumber, strip_phone_number_chars_regex, '', 'g').contains(re.sub(strip_phone_number_chars_regex, '', phone_number)) ) ) if email_address: filters.append( Request.applicants.any( func.lower(Applicant.emailAddress).startswith(email_address.lower()) ) ) ''' Filter on addresses if address_line: filters.append( Request.applicants.any( func.lower(Applicant.addrLine1).startswith(address_line.lower()) ) ) ''' criteria = RequestQueryCriteria( nr_num=nr_num, filters=filters ) results = Request.find_by_criteria(criteria) if not results: results = [] except InvalidInputError as err: return handle_exception(err, err.message, 400) except Exception as err: return handle_exception(err, 'Error retrieving the NR from the db.', 500) if nr_num and len(results) == 1: nr_model = results[0] if nr_model.requestTypeCd and (not nr_model.entity_type_cd or not nr_model.request_action_cd): # If requestTypeCd is set, but a request_entity (entity_type_cd) and a request_action (request_action_cd) # are not, use get_mapped_entity_and_action_code to map the values from the requestTypeCd entity_type, request_action = get_mapped_entity_and_action_code(nr_model.requestTypeCd) nr_model.entity_type_cd = entity_type nr_model.request_action_cd = request_action response_data = nr_model.json() # If draft, get the wait time and oldest queued request if nr_model.stateCd == 'DRAFT': service = WaitTimeStatsService() wait_time_response = service.get_waiting_time_dict() response_data.update(wait_time_response) # Add the list of valid Name Request actions for the given state to the response response_data['actions'] = get_nr_state_actions(results[0].stateCd, results[0]) return jsonify(response_data), 200 elif len(results) > 0: # We won't add the list of valid Name Request actions for the given state to the response if we're sending back a list # If the user / client accessing this data needs the Name Request actions, GET the individual record using NameRequest.get # This method, NameRequests.get is for Existing NR Search return jsonify(list(map(lambda result: result.json(), results))), 200 # We won't add the list of valid Name Request actions for the given state to the response if we're sending back a list # If the user / client accessing this data needs the Name Request actions, GET the individual record using NameRequest.get # This method, NameRequests.get is for Existing NR Search return jsonify(results), 200