Skip to content

Commit

Permalink
fix type, member call deleted to prior merge (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwolpert authored Jul 13, 2021
1 parent 5377705 commit 0a7ff3f
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/namex/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def json(self):
'checkedOutBy': self.checkedOutBy,
'checkedOutDt': self.checkedOutDt
}
if nr_actions := nr_filing_actions(self.requestTypeCd):
if nr_actions := nr_filing_actions.get_actions(self.requestTypeCd):
nr_json['legalType'] = nr_actions.get('legalType')
nr_json['filingName'] = nr_actions.get('filingName')
nr_json['target'] = nr_actions.get('legalType')
Expand Down
4 changes: 1 addition & 3 deletions api/namex/services/lookup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.
"""Holds all the lookup services."""

from .nr_filing_actions import NameRequestFilingActions

__all__ = ('NameRequestFilingActions',)
from .name_request_filing_actions import NameRequestFilingActions

nr_filing_actions = NameRequestFilingActions()
146 changes: 146 additions & 0 deletions api/namex/services/lookup/name_request_filing_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Copyright © c2021 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Name Request lookup values."""
from typing import Optional

from flask import Flask, current_app
from werkzeug.utils import cached_property

class NameRequestFilingActions:
"""Manages the mapping between NR types and the actions allowed in the target systems.
This support the service signatures for Flask, but doesn't do anything special with it.
"""

def __init__(self, app:Flask =None):
"""Initializer, supports setting the app context on instantiation."""
if app is not None:
self.init_app(app)

def init_app(self, app: Flask):
"""Setup the extension.
:param app: Flask app
:return: naked
"""
self.app = app
app.teardown_appcontext(self.teardown)

def teardown(self, exception):
"""Remove and cleanup after this service."""
# the oracle session pool will clean up after itself
# ctx = _app_ctx_stack.top
# if hasattr(ctx, 'nro_oracle_pool'):


# This is the raw mapping data.
# This list will be collapsed to a dict type
# multiple target systems is not supported
# multiple filing actions per nr_type is supported
# NR Type', 'LegalTypeCd', 'LegalTypeName', 'Filing Name', 'Target', 'entitiesFilingName', 'URL', 'learTemplate
raw_nr_to_action_mapping =[
('CR', 'BC', 'B.C. Company', 'Incorporation', 'colin', None, None, None),
('CR', 'BC', 'B.C. Company', 'Amalgamation', 'colin', None, None, None),
('CCR', 'BC', 'B.C. Company', 'Change of Name', 'colin', None, None, None),
('CT', 'BC', 'B.C. Company', 'Continuation In', 'colin', None, None, None),
('RCR', 'BC', 'B.C. Company', 'Restoration', 'static', None, 'https://www2.gov.bc.ca/gov/content/employment-business/business/managing-a-business/permits-licences/businesses-incorporated-companies/forms-corporate-registry#information-packages', None),
('XCR', 'XP', 'Corporation (Foreign)', 'Extraprovincial Registration', 'colin', None, None, None),
('XCR', 'XP', 'Corporation (Foreign)', 'Extraprovincial Amalgamation', 'static', None, 'https://www2.gov.bc.ca/gov/content/employment-business/business/managing-a-business/permits-licences/businesses-incorporated-companies/forms-corporate-registry#forms', None),
('XCCR', 'XP', 'Corporation (Foreign)', 'Extraprovincial Change of Name', 'colin', None, None, None),
('XRCR', 'XP', 'Corporation (Foreign)', 'Extraprovincial Reinstatement', 'static', None, 'https://www2.gov.bc.ca/gov/content/employment-business/business/managing-a-business/permits-licences/businesses-incorporated-companies/forms-corporate-registry#information-packages', None),
('AS', 'XP', 'Corporation (Foreign)', 'Extraprovincial Assumed Name', 'static', None, 'https://www2.gov.bc.ca/gov/content/employment-business/business/managing-a-business/permits-licences/businesses-incorporated-companies/forms-corporate-registry#forms', None),
('LC', 'LLC', 'Extraprovincial Limited Liability Company', 'Extraprovincial Registration', 'static', None, 'https://www2.gov.bc.ca/assets/gov/employment-business-and-economic-development/business-management/permits-licences-and-registration/registries-packages/pack_33_xco_-_registration_statement_and_business_number_request.pdf', None),
('CLC', 'LLC', 'Extraprovincial Limited Liability Company', 'Extraprovincial Change of Name', 'static', None, 'https://www2.gov.bc.ca/assets/gov/employment-business-and-economic-development/business-management/permits-licences-and-registration/registries-forms/form_37_xco_-_name_change.pdf', None),
('RLC', 'LLC', 'Extraprovincial Limited Liability Company', 'Extraprovincial Reinstatement', 'static', None, 'https://www2.gov.bc.ca/gov/content/employment-business/business/managing-a-business/permits-licences/businesses-incorporated-companies/forms-corporate-registry#information-packages', None),
('AL', 'LLC', 'Extraprovincial Limited Liability Company', 'Extraprovincial Assumed Name', 'static', None, 'https://www2.gov.bc.ca/assets/gov/employment-business-and-economic-development/business-management/permits-licences-and-registration/registries-forms/form_37_xco_-_name_change.pdf', None),
('FR', 'GP', 'General Partnership/Sole Proprietorship/DBA', 'Registration', 'onestop', None, None, None),
('CFR', 'GP', 'General Partnership/Sole Proprietorship/DBA', 'Change of Name', 'onestop', None, None, None),
('LL', 'LL', 'Limited Liability Partnership', 'Registration', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('CLL', 'LL', 'Limited Liability Partnership', 'Change of Name', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('XLL', 'XP', 'Extraprovincial Limited Liability Partnership', 'Registration', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('XCLL', 'XP', 'Extraprovincial Limited Liability Partnership', 'Change of Name', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('LP', 'LP', 'Limited Partnership', 'Registration', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('CLP', 'LP', 'Limited Partnership', 'Change of Name', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('XLP', 'XL', 'Extraprovincial Limited Partnership', 'Registration', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('XCLP', 'XL', 'Extraprovincial Limited Partnership', 'Change of Name', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('CP', 'CP', 'Cooperative', 'Incorporation', 'lear', 'incorporationApplication', None, "{'filing': {'header': {'name': {entitiesFilingName} }, '{entitiesFilingName}': {'nameRequest': {'nrNumber': '{nrNumber}', 'legalName': '{legalName}', 'legalType': '{legalType}'}}}}"),
('CP', 'CP', 'Cooperative', 'Amalgamation', 'lear', 'manual', None, None),
('CCP', 'CP', 'Cooperative', 'Change of Name', 'lear', 'changeOfName', None, "{'filing': {'header': {'name': {entitiesFilingName} }, '{entitiesFilingName}': {'nameRequest': {'nrNumber': '{nrNumber}', 'legalName': '{legalName}', 'legalType': '{legalType}'}}}}"),
('CTC', 'CP', 'Cooperative', 'Continuation In', 'lear', 'manual', None, None),
('RCP', 'CP', 'Cooperative', 'Restoration', 'lear', 'manual', None, None),
('XCP', 'XCP', 'Extraprovincial Cooperative', 'Incorporation', 'lear', 'manual', None, None),
('XCP', 'XCP', 'Extraprovincial Cooperative', 'Amalgamation', 'lear', 'manual', None, None),
('XCCP', 'XCP', 'Extraprovincial Cooperative', 'Change of Name', 'lear', 'manual', None, None),
('XRCP', 'XCP', 'Extraprovincial Cooperative', 'Restoration', 'lear', 'manual', None, None),
('CC', 'CCC', 'Community Contribution Co.', 'Incorporation', 'colin', None, None, None),
('CC', 'CCC', 'Community Contribution Co.', 'Amalgamation', 'colin', None, None, None),
('CCV', 'CCC', 'Community Contribution Co.', 'BC to CCC Conversion', 'colin', None, None, None),
('CCC', 'CCC', 'Community Contribution Co.', 'Change of Name', 'colin', None, None, None),
('CCCT', 'CCC', 'Community Contribution Co.', 'Continuation In', 'colin', None, None, None),
('RCC', 'CCC', 'Community Contribution Co.', 'Restoration', 'static', None, 'https://www2.gov.bc.ca/gov/content/employment-business/business/managing-a-business/permits-licences/businesses-incorporated-companies/forms-corporate-registry#information-packages', None),
('UL', 'ULC', 'Unlimited Liability Co.', 'Incorporation', 'colin', None, None, None),
('UL', 'ULC', 'Unlimited Liability Co.', 'Amalgamation', 'colin', None, None, None),
('UC', 'ULC', 'Unlimited Liability Co.', 'BC to ULC Conversion', 'colin', None, None, None),
('CUL', 'ULC', 'Unlimited Liability Co.', 'Change of Name', 'colin', None, None, None),
('ULCT', 'ULC', 'Unlimited Liability Co.', 'Continuation In', 'colin', None, None, None),
('RUL', 'ULC', 'Unlimited Liability Co.', 'Restoration', 'static', None, 'https://www2.gov.bc.ca/gov/content/employment-business/business/managing-a-business/permits-licences/businesses-incorporated-companies/forms-corporate-registry#information-packages', None),
('UA', 'A', 'Extraprovincial Unlimited Liability Company', 'Assumed', 'colin', None, None, None),
('XUL', 'A', 'Extraprovincial Unlimited Liability Company', 'Incorporation', 'colin', None, None, None),
('XCUL', 'A', 'Extraprovincial Unlimited Liability Company', 'Amalgamation', 'colin', None, None, None),
('XRUL', 'A', 'Extraprovincial Unlimited Liability Company', 'Restoration', 'colin', None, None, None),
('FI', 'FI', 'Financial Institution (BC)', 'Incorporation', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('CFI', 'FI', 'Financial Institution (BC)', 'Change of Name', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('RFI', 'FI', 'Financial Institution (BC)', 'Restoration', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('PA', 'PA', 'Private Act', 'Incorporation', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('PAR', 'PAR', 'Parish', 'Incorporation', 'static', None, 'https://www2.gov.bc.ca/gov/content/governments/organizational-structure/ministries-organizations/ministries/citizens-services/bc-registries-online-services', None),
('BC', 'BEN', 'BC Benefit Company Incorporation', 'Incorporation', 'lear', 'incorporationApplication', None, "{'filing': {'header': {'name': {entitiesFilingName} }, '{entitiesFilingName}': {'nameRequest': {'nrNumber': '{nrNumber}', 'legalName': '{legalName}', 'legalType': '{legalType}'}}}}"),
('BEAM', 'BEN', 'BC Benefit Company Incorporation', 'Amalgamation', 'lear', None, None, None),
('BEC', 'BEN', 'BC Benefit Company Incorporation', 'Change of Name', 'lear', 'alteration', None, "{'filing': {'header': {'name': {entitiesFilingName} }, '{entitiesFilingName}': {'nameRequest': {'nrNumber': '{nrNumber}', 'legalName': '{legalName}', 'legalType': '{legalType}'}}}}"),
('BECT', 'BEN', 'BC Benefit Company Incorporation', 'Continuation In', 'lear', None, None, None),
('BERE', 'BEN', 'BC Benefit Company Incorporation', 'Restoration', 'lear', None, None, None),
('BECV', 'BEN', 'BC Benefit Company Incorporation', 'Alteration', 'lear', 'alteration', None, "{'filing': {'header': {'name': {entitiesFilingName} }, '{entitiesFilingName}': {'nameRequest': {'nrNumber': '{nrNumber}', 'legalName': '{legalName}', 'legalType': '{legalType}'}}}}"),
('BECR', 'BEN', 'BC Benefit Company Incorporation', 'Convert to BC', 'lear', 'alteration', None, "{'filing': {'header': {'name': {entitiesFilingName} }, '{entitiesFilingName}': {'nameRequest': {'nrNumber': '{nrNumber}', 'legalName': '{legalName}', 'legalType': '{legalType}'}}}}"),
]

@cached_property
def get_dict(self) -> dict:
"""Return a dict of nr types to the target and filing actions.
This takes the raw filing data and creates a dict."""
current_app.logger.debug ('creating nr_filing_actions')
d={}
for (nr_type, legalType, legalTypeName, filingName, target, entitiesFilingName, URL, learTemplate) in self.raw_nr_to_action_mapping: # pylint: disable=W0612
if nr_type not in d:
d[nr_type] = {'legalType': legalType, 'target': target}

actions = d[nr_type].get('actions', [])
actions.append({'filingName': filingName, 'entitiesFilingName': entitiesFilingName, 'URL': URL, 'learTemplate': learTemplate})
d[nr_type]['actions'] = actions

current_app.logger.debug ('completed creating nr_filing_actions')
return d

def get_actions(self, nr_type: str) -> Optional[dict]:
"""Return the target system and filing actions that a nr_type can be used for.
Returns a dict with the following values:
legalType: the short common legal types code, eg. 'BC', 'BEN'
legalTypeName: convenience field with the legalType expanded
filingName: common short filing name
target: target system that provides the service
actions: an Array of actions that the nr_type can be used for
entitiesFilingName: business-schema name for the filing
URL: the location of the service
learTemplate: the templat that can be used to create a draft filing.
"""
return self.get_dict.get(nr_type)
1 change: 1 addition & 0 deletions api/tests/python/models/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_get_queued_oldest_multirow(client, app):

# Tests ####
assert nr_first.nrNum == nr_oldest.nrNum
assert nr_oldest.json()


def test_get_queued_empty_queue(client, app):
Expand Down
3 changes: 1 addition & 2 deletions api/tests/python/services/lookup/test_nr_filing_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from flask import Flask

from namex.services.lookup import NameRequestFilingActions
from namex.services.lookup import nr_filing_actions

def test_nr_filing_actions(caplog):
"""Assert that the nr_filing_actions is created and cached."""
Expand All @@ -28,7 +28,6 @@ def test_nr_filing_actions(caplog):
with app.app_context():
with caplog.at_level(logging.DEBUG):

nr_filing_actions = NameRequestFilingActions()
nr_filing_actions.get_actions(nr_type_cd)
assert nr_filing_actions_debug_msg in [rec.message for rec in caplog.records]

Expand Down

0 comments on commit 0a7ff3f

Please sign in to comment.