def get_documents(identifier: str, filing_id: int, legal_filing_name: str = None): """Return a JSON object with meta information about the Service.""" # basic checks if not authorized(identifier, jwt, [ 'view', ]): return jsonify(message=get_error_message(ErrorCode.NOT_AUTHORIZED, **{ 'identifier': identifier })), HTTPStatus.UNAUTHORIZED if identifier.startswith('T'): filing_model = FilingModel.get_temp_reg_filing(identifier) business = Business.find_by_internal_id(filing_model.business_id) else: business = Business.find_by_identifier(identifier) if not business and not identifier.startswith('T'): return jsonify(message=get_error_message(ErrorCode.MISSING_BUSINESS, ** {'identifier': identifier })), HTTPStatus.NOT_FOUND if not (filing := Filing.get(identifier, filing_id)): return jsonify(message=get_error_message( ErrorCode.FILING_NOT_FOUND, **{ 'filing_id': filing_id, 'identifier': identifier })), HTTPStatus.NOT_FOUND
def get_single_filing(identifier: str, filing_id: int): """Return a single filing and all of its components.""" original_filing = str(request.args.get('original', None)).lower() == 'true' rv = CoreFiling.get(identifier, filing_id) if not rv: return jsonify({'message': f'{identifier} no filings found' }), HTTPStatus.NOT_FOUND if original_filing: return jsonify(rv.redacted(rv.raw, jwt)) if rv.filing_type == CoreFiling.FilingTypes.CORRECTION.value: # This is required until #5302 ticket implements rv.storage._filing_json['filing']['correction']['diff'] = rv.json[ 'filing']['correction']['diff'] # pylint: disable=protected-access; # noqa: E501; if str(request.accept_mimetypes) == 'application/pdf': report_type = request.args.get('type', None) return legal_api.reports.get_pdf(rv.storage, report_type) filing_json = rv.json if documents := DocumentMetaService().get_documents(filing_json): filing_json['filing']['documents'] = documents
def get(identifier, filing_id=None): # pylint: disable=too-many-return-statements,too-many-branches; # fix this while refactoring this whole module """Return a JSON object with meta information about the Service.""" original_filing = str(request.args.get('original', None)).lower() == 'true' if identifier.startswith('T'): rv = CoreFiling.get(identifier, filing_id) if not rv.storage: return jsonify({'message': f'{identifier} no filings found' }), HTTPStatus.NOT_FOUND if str(request.accept_mimetypes ) == 'application/pdf' and filing_id: if rv.filing_type == 'incorporationApplication': return legal_api.reports.get_pdf(rv.storage, None) if original_filing: filing_json = rv.raw else: filing_json = rv.json filing_json['filing']['documents'] = DocumentMetaService( ).get_documents(filing_json) if filing_json['filing']['header'][ 'status'] == Filing.Status.PENDING.value: try: headers = { 'Authorization': f'Bearer {jwt.get_token_auth_header()}', 'Content-Type': 'application/json' } payment_svc_url = current_app.config.get('PAYMENT_SVC_URL') pay_response = requests.get( url= f'{payment_svc_url}/{filing_json["filing"]["header"]["paymentToken"]}', headers=headers) pay_details = { 'isPaymentActionRequired': pay_response.json().get('isPaymentActionRequired', False), 'paymentMethod': pay_response.json().get('paymentMethod', '') } filing_json['filing']['header'].update(pay_details) except (exceptions.ConnectionError, exceptions.Timeout) as err: current_app.logger.error( f'Payment connection failure for getting {identifier} filing payment details. ', err) return jsonify(filing_json) business = Business.find_by_identifier(identifier) if not business: return jsonify(filings=[]), HTTPStatus.NOT_FOUND if filing_id: rv = CoreFiling.get(identifier, filing_id) if not rv: return jsonify({'message': f'{identifier} no filings found' }), HTTPStatus.NOT_FOUND if str(request.accept_mimetypes) == 'application/pdf': report_type = request.args.get('type', None) if rv.filing_type == CoreFiling.FilingTypes.CORRECTION.value: # This is required until #5302 ticket implements rv.storage._filing_json['filing']['correction'][ 'diff'] = rv.json['filing']['correction']['diff'] # pylint: disable=protected-access; # noqa: E501; return legal_api.reports.get_pdf(rv.storage, report_type) return jsonify(rv.raw if original_filing else rv.json) # Does it make sense to get a PDF of all filings? if str(request.accept_mimetypes) == 'application/pdf': return jsonify({'message': _('Cannot return a single PDF of multiple filing submissions.')}),\ HTTPStatus.NOT_ACCEPTABLE rv = [] filings = CoreFiling.get_filings_by_status( business.id, [Filing.Status.COMPLETED.value, Filing.Status.PAID.value]) for filing in filings: filing_json = filing.raw filing_json['filing']['documents'] = DocumentMetaService( ).get_documents(filing_json) rv.append(filing_json) return jsonify(filings=rv)