Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22431 update to use v2 of legal api #2886

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""
from __future__ import annotations

import base64
from datetime import datetime
from http import HTTPStatus
from pathlib import Path
Expand Down Expand Up @@ -214,3 +215,26 @@ def get_jurisdictions(identifier: str, token: str) -> dict:
except Exception: # noqa B902; pylint: disable=W0703;
current_app.logger.error('Failed to get MRAS response')
return None


def get_filing_document(business_identifier, filing_id, document_type, token):
"""Get the filing documents."""
headers = {
'Accept': 'application/pdf',
'Authorization': f'Bearer {token}'
}

document = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business_identifier}/filings/{filing_id}'
f'/documents/{document_type}', headers=headers
)

if document.status_code != HTTPStatus.OK:
current_app.logger.error('Failed to get %s pdf for filing: %s', document_type, filing_id)
return None
try:
filing_pdf_encoded = base64.b64encode(document.content)
return filing_pdf_encoded
except Exception: # noqa B902; pylint: disable=W0703;
current_app.logger.error('Failed to get document response')
return None
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
from jinja2 import Template
from legal_api.models import Business, Filing

from entity_emailer.email_processors import get_filing_info, get_recipient_from_auth, substitute_template_parts
from entity_emailer.email_processors import (
get_filing_document,
get_filing_info,
get_recipient_from_auth,
substitute_template_parts,
)


def _get_pdfs(
Expand All @@ -44,14 +49,9 @@ def _get_pdfs(
}

# add filing pdf
filing_pdf = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=letterOfAgmExtension', headers=headers
)
if filing_pdf.status_code != HTTPStatus.OK:
logger.error('Failed to get pdf for filing: %s', filing.id)
else:
filing_pdf_encoded = base64.b64encode(filing_pdf.content)
filing_pdf_type = 'letterOfAgmExtension'
filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token)
if filing_pdf_encoded:
pdfs.append(
{
'fileName': 'Letter of AGM Extension Approval.pdf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
from jinja2 import Template
from legal_api.models import Business, Filing

from entity_emailer.email_processors import get_filing_info, get_recipient_from_auth, substitute_template_parts
from entity_emailer.email_processors import (
get_filing_document,
get_filing_info,
get_recipient_from_auth,
substitute_template_parts,
)


def _get_pdfs(
Expand All @@ -44,14 +49,9 @@ def _get_pdfs(
}

# add filing pdf
filing_pdf = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=letterOfAgmLocationChange', headers=headers
)
if filing_pdf.status_code != HTTPStatus.OK:
logger.error('Failed to get pdf for filing: %s', filing.id)
else:
filing_pdf_encoded = base64.b64encode(filing_pdf.content)
filing_pdf_type = 'letterOfAgmLocationChange'
filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token)
if filing_pdf_encoded:
pdfs.append(
{
'fileName': 'Letter of AGM Location Change Approval.pdf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from entity_emailer.email_processors import (
get_entity_dashboard_url,
get_filing_document,
get_filing_info,
get_recipients,
substitute_template_parts,
Expand All @@ -52,14 +53,9 @@ def _get_pdfs(

if status == Filing.Status.PAID.value:
# add filing pdf
filing_pdf = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}',
headers=headers
)
if filing_pdf.status_code != HTTPStatus.OK:
logger.error('Failed to get pdf for filing: %s', filing.id)
else:
filing_pdf_encoded = base64.b64encode(filing_pdf.content)
filing_pdf_type = 'amalgamationApplication'
filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token)
if filing_pdf_encoded:
pdfs.append(
{
'fileName': f'{amalgamation_application_name}.pdf',
Expand Down Expand Up @@ -97,15 +93,9 @@ def _get_pdfs(
attach_order += 1
elif status == Filing.Status.COMPLETED.value:
# add certificate of amalgamation
certificate = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=certificateOfAmalgamation',
headers=headers
)
if certificate.status_code != HTTPStatus.OK:
logger.error('Failed to get corrected registration statement pdf for filing: %s', filing.id)
else:
certificate_encoded = base64.b64encode(certificate.content)
certificate_pdf_type = 'certificateOfAmalgamation'
certificate_encoded = get_filing_document(business['identifier'], filing.id, certificate_pdf_type, token)
if certificate_encoded:
pdfs.append(
{
'fileName': 'Certificate Of Amalgamation.pdf',
Expand All @@ -116,15 +106,9 @@ def _get_pdfs(
)
attach_order += 1
# add notice of articles
noa = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=noticeOfArticles',
headers=headers
)
if noa.status_code != HTTPStatus.OK:
logger.error('Failed to get noa pdf for filing: %s', filing.id)
else:
noa_encoded = base64.b64encode(noa.content)
noa_pdf_type = 'noticeOfArticles'
noa_encoded = get_filing_document(business['identifier'], filing.id, noa_pdf_type, token)
if noa_encoded:
pdfs.append(
{
'fileName': 'Notice of Articles.pdf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
from jinja2 import Template
from legal_api.models import Business, Filing, UserRoles

from entity_emailer.email_processors import get_filing_info, get_user_email_from_auth, substitute_template_parts
from entity_emailer.email_processors import (
get_filing_document,
get_filing_info,
get_user_email_from_auth,
substitute_template_parts,
)


def _get_pdfs(
Expand All @@ -46,15 +51,9 @@ def _get_pdfs(

if status == Filing.Status.PAID.value:
# add filing pdf
filing_pdf = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
f'?type=changeOfRegistration',
headers=headers
)
if filing_pdf.status_code != HTTPStatus.OK:
logger.error('Failed to get pdf for filing: %s', filing.id)
else:
filing_pdf_encoded = base64.b64encode(filing_pdf.content)
filing_pdf_type = 'changeOfRegistration'
filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token)
if filing_pdf_encoded:
pdfs.append(
{
'fileName': 'Change of Registration.pdf',
Expand Down Expand Up @@ -93,15 +92,9 @@ def _get_pdfs(
attach_order += 1
elif status == Filing.Status.COMPLETED.value:
# add amended registration statement
certificate = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=amendedRegistrationStatement',
headers=headers
)
if certificate.status_code != HTTPStatus.OK:
logger.error('Failed to get amended registration statement pdf for filing: %s', filing.id)
else:
certificate_encoded = base64.b64encode(certificate.content)
certificate_pdf_type = 'amendedRegistrationStatement'
certificate_encoded = get_filing_document(business['identifier'], filing.id, certificate_pdf_type, token)
if certificate_encoded:
pdfs.append(
{
'fileName': 'AmendedRegistrationStatement.pdf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
from jinja2 import Template
from legal_api.models import Business, Filing, UserRoles

from entity_emailer.email_processors import get_filing_info, get_recipient_from_auth, substitute_template_parts
from entity_emailer.email_processors import (
get_filing_document,
get_filing_info,
get_recipient_from_auth,
substitute_template_parts,
)


def _get_pdfs(
Expand All @@ -44,14 +49,9 @@ def _get_pdfs(
}

# add filing pdf
filing_pdf = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=letterOfConsent', headers=headers
)
if filing_pdf.status_code != HTTPStatus.OK:
logger.error('Failed to get pdf for filing: %s', filing.id)
else:
filing_pdf_encoded = base64.b64encode(filing_pdf.content)
filing_pdf_type = 'letterOfConsent'
filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token)
if filing_pdf_encoded:
pdfs.append(
{
'fileName': 'Letter of Consent.pdf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from entity_emailer.email_processors import (
get_entity_dashboard_url,
get_filing_document,
get_filing_info,
get_recipients,
substitute_template_parts,
Expand All @@ -51,14 +52,9 @@ def _get_pdfs(

if status == Filing.Status.PAID.value:
# add filing pdf
filing_pdf = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}',
headers=headers
)
if filing_pdf.status_code != HTTPStatus.OK:
logger.error('Failed to get pdf for filing: %s', filing.id)
else:
filing_pdf_encoded = base64.b64encode(filing_pdf.content)
filing_pdf_type = 'continuationIn'
filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token)
if filing_pdf_encoded:
pdfs.append(
{
'fileName': 'Continuation Application.pdf',
Expand Down Expand Up @@ -96,15 +92,9 @@ def _get_pdfs(
attach_order += 1
elif status == Filing.Status.COMPLETED.value:
# add certificate of continuation
certificate = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=certificateOfContinuation',
headers=headers
)
if certificate.status_code != HTTPStatus.OK:
logger.error('Failed to get certificate of continuation for filing: %s', filing.id)
else:
certificate_encoded = base64.b64encode(certificate.content)
certificate_pdf_type = 'certificateOfContinuation'
certificate_encoded = get_filing_document(business['identifier'], filing.id, certificate_pdf_type, token)
if certificate_encoded:
pdfs.append(
{
'fileName': 'Certificate of Continuation.pdf',
Expand All @@ -115,15 +105,9 @@ def _get_pdfs(
)
attach_order += 1
# add notice of articles
noa = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=noticeOfArticles',
headers=headers
)
if noa.status_code != HTTPStatus.OK:
logger.error('Failed to get noa pdf for filing: %s', filing.id)
else:
noa_encoded = base64.b64encode(noa.content)
noa_pdf_type = 'noticeOfArticles'
noa_encoded = get_filing_document(business['identifier'], filing.id, noa_pdf_type, token)
if noa_encoded:
pdfs.append(
{
'fileName': 'Notice of Articles.pdf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from legal_api.core.filing_helper import is_special_resolution_correction_by_filing_json
from legal_api.models import Filing

from entity_emailer.email_processors import get_filing_info, substitute_template_parts
from entity_emailer.email_processors import get_filing_document, get_filing_info, substitute_template_parts
from entity_emailer.email_processors.special_resolution_helper import get_completed_pdfs


Expand All @@ -54,15 +54,9 @@ def _get_pdfs(

if status == Filing.Status.PAID.value:
# add filing pdf
filing_pdf = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
f'?type=correction',
headers=headers
)
if filing_pdf.status_code != HTTPStatus.OK:
logger.error('Failed to get pdf for filing: %s', filing.id)
else:
filing_pdf_encoded = base64.b64encode(filing_pdf.content)
filing_pdf_type = 'correction'
filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token)
if filing_pdf_encoded:
pdfs.append(
{
'fileName': 'Register Correction Application.pdf',
Expand Down Expand Up @@ -101,15 +95,9 @@ def _get_pdfs(
elif status == Filing.Status.COMPLETED.value:
if legal_type in ('SP', 'GP'):
# add corrected registration statement
certificate = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=correctedRegistrationStatement',
headers=headers
)
if certificate.status_code != HTTPStatus.OK:
logger.error('Failed to get corrected registration statement pdf for filing: %s', filing.id)
else:
certificate_encoded = base64.b64encode(certificate.content)
certificate_pdf_type = 'correctedRegistrationStatement'
certificate_encoded = get_filing_document(business['identifier'], filing.id, certificate_pdf_type, token)
if certificate_encoded:
pdfs.append(
{
'fileName': 'Corrected - Registration Statement.pdf',
Expand All @@ -121,15 +109,9 @@ def _get_pdfs(
attach_order += 1
elif legal_type in ('BC', 'BEN', 'CC', 'ULC'):
# add notice of articles
noa = requests.get(
f'{current_app.config.get("LEGAL_API_URL")}/businesses/{business["identifier"]}/filings/{filing.id}'
'?type=noticeOfArticles',
headers=headers
)
if noa.status_code != HTTPStatus.OK:
logger.error('Failed to get noa pdf for filing: %s', filing.id)
else:
noa_encoded = base64.b64encode(noa.content)
noa_pdf_type = 'noticeOfArticles'
noa_encoded = get_filing_document(business['identifier'], filing.id, noa_pdf_type, token)
if noa_encoded:
pdfs.append(
{
'fileName': 'Notice of Articles.pdf',
Expand Down
Loading
Loading