def get(name_or_code): """Get a list of client parties (registering or secured parties) associated with a head office code or name.""" try: if name_or_code is None: return resource_utils.path_param_error_response('nameOrCode') fuzzy_param = request.args.get(FUZZY_NAME_SEARCH_PARAM) # Quick check: must be staff or provide an account ID. account_id = resource_utils.get_account_id(request) if not is_staff(jwt) and account_id is None: return resource_utils.account_required_response() # Verify request JWT and account ID if not authorized(account_id, jwt): return resource_utils.unauthorized_error_response(account_id) # Try to fetch client parties: no results is an empty list. current_app.logger.debug( f'Getting {account_id} head office party codes searching on {name_or_code}.' ) parties = ClientCode.find_by_head_office(name_or_code, fuzzy_param) # if not parties: # return resource_utils.not_found_error_response('party', code) return jsonify(parties), HTTPStatus.OK except BusinessException as exception: return resource_utils.business_exception_response(exception) except Exception as default_exception: # noqa: B902; return nicer default error return resource_utils.default_exception_response(default_exception)
def get(code): """Get a preset registering or secured party by client code.""" try: if code is None: return resource_utils.path_param_error_response('code') # Quick check: must be staff or provide an account ID. account_id = resource_utils.get_account_id(request) if not is_staff(jwt) and account_id is None: return resource_utils.account_required_response() # Verify request JWT and account ID if not authorized(account_id, jwt): return resource_utils.unauthorized_error_response(account_id) # Try to fetch client party by code current_app.logger.debug( f'Getting party code for account {account_id} with code = {code}.' ) party = ClientCode.find_by_code(code) if not party: return resource_utils.not_found_error_response('party', code) return party, HTTPStatus.OK except BusinessException as exception: return resource_utils.business_exception_response(exception) except Exception as default_exception: # noqa: B902; return nicer default error return resource_utils.default_exception_response(default_exception)
def post(search_id): """Execute a search detail request using selection choices in the request body.""" try: if search_id is None: return resource_utils.path_param_error_response('search ID') # Quick check: must be staff or provide an account ID. account_id = resource_utils.get_account_id(request) if not is_staff(jwt) and account_id is None: return resource_utils.account_required_response() # Verify request JWT and account ID if not authorized(account_id, jwt): return resource_utils.unauthorized_error_response(account_id) request_json = request.get_json(silent=True) # Validate schema. valid_format, errors = schema_utils.validate( request_json, 'searchSummary', 'ppr') if not valid_format: return resource_utils.validation_error_response( errors, VAL_ERROR) # Perform any extra data validation such as start and end dates here search_detail = SearchResult.validate_search_select( request_json, search_id) # Save the search query selection and details that match the selection. search_detail.update_selection(request_json) if not search_detail.search_response: return resource_utils.unprocessable_error_response( 'search result details') response_data = search_detail.json if resource_utils.is_pdf(request): token = g.jwt_oidc_token_info # Return report if request header Accept MIME type is application/pdf. return get_pdf(response_data, account_id, ReportTypes.SEARCH_DETAIL_REPORT.value, token['name']) return jsonify(response_data), HTTPStatus.OK except BusinessException as exception: return resource_utils.business_exception_response(exception) except Exception as default_exception: # noqa: B902; return nicer default error return resource_utils.default_exception_response(default_exception)
def put(search_id): """Execute a search selection update request replacing the current value with the request body contents.""" try: if search_id is None: return resource_utils.path_param_error_response('search ID') # Quick check: must be staff or provide an account ID. account_id = resource_utils.get_account_id(request) if account_id is None: return resource_utils.account_required_response() # Verify request JWT and account ID if not authorized(account_id, jwt): return resource_utils.unauthorized_error_response(account_id) request_json = request.get_json(silent=True) # Validate schema. valid_format, errors = schema_utils.validate( request_json, 'searchSummary', 'ppr') if not valid_format: return resource_utils.validation_error_response( errors, VAL_ERROR) search_request = SearchRequest.find_by_id(search_id) if not search_request: return resource_utils.not_found_error_response( 'searchId', search_id) # Save the updated search selection. search_request.update_search_selection(request_json) return jsonify( search_request.updated_selection), HTTPStatus.ACCEPTED except BusinessException as exception: return resource_utils.business_exception_response(exception) except Exception as default_exception: # noqa: B902; return nicer default error return resource_utils.default_exception_response(default_exception)
def get(search_id): """Get search detail information for a previous search.""" try: if search_id is None: return resource_utils.path_param_error_response('search ID') # Quick check: must have an account ID. account_id = resource_utils.get_account_id(request) if account_id is None: return resource_utils.account_required_response() # Verify request JWT and account ID if not authorized(account_id, jwt): return resource_utils.unauthorized_error_response(account_id) # Try to fetch search detail by search id. current_app.logger.info(f'Fetching search detail for {search_id}.') search_detail = SearchResult.find_by_search_id(search_id, True) if not search_detail: return resource_utils.not_found_error_response( 'searchId', search_id) response_data = search_detail.json if resource_utils.is_pdf(request): token = g.jwt_oidc_token_info # Return report if request header Accept MIME type is application/pdf. return get_pdf(response_data, account_id, ReportTypes.SEARCH_DETAIL_REPORT.value, token['name']) return jsonify(response_data), HTTPStatus.OK except BusinessException as exception: return resource_utils.business_exception_response(exception) except Exception as default_exception: # noqa: B902; return nicer default error return resource_utils.default_exception_response(default_exception)