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

21845 NRO Decommision #1557

Merged
merged 3 commits into from
Jul 24, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ api - the core API service
solr - solr is used as a search service providing advanced semantic support
solr-feeder
solr-synonyms-api

nro-update - updates the legacy database, used as an integration point for downstream systems
nro-extractor - pulling incoming requests from the legacy systems

nro-legacy - scripts to manage integration objects with the legacy Oracle DB
```

## Deployment (Local Development)
Expand Down
1 change: 0 additions & 1 deletion api/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,4 @@ MRAS_SVC_URL=
MRAS_SVC_API_KEY=

# Local development only
DISABLE_NAMEREQUEST_NRO_UPDATES=1
DISABLE_NAMEREQUEST_SOLR_UPDATES=1
18 changes: 1 addition & 17 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class Config(object):

ENTITY_SVC_URL = f'{os.getenv("LEGAL_API_URL", None)}{os.getenv("LEGAL_API_VERSION", "/api/v1")}'

NRO_EXTRACTOR_URI = f'{os.getenv("NAMEX_API_URL", None)}{os.getenv("NAMEX_API_VERSION", None)}/nro-extract/nro-requests'


NAME_REQUEST_URL = os.getenv('NAME_REQUEST_URL', '')
NAMES_INFORMATION_URL = os.getenv('NAMES_INFORMATION_URL',
'https://www2.gov.bc.ca/gov/content/employment-business/business/managing-a-business/\
Expand All @@ -72,13 +69,6 @@ class Config(object):
DB_PORT = os.getenv('NAMEX_DATABASE_PORT', '5432')
SQLALCHEMY_DATABASE_URI = f'postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{int(DB_PORT)}/{DB_NAME}'

# ORACLE - LEGACY NRO NAMESDB
NRO_USER = os.getenv('NRO_USER', '')
NRO_PASSWORD = os.getenv('NRO_PASSWORD', '')
NRO_DB_NAME = os.getenv('NRO_DB_NAME', '')
NRO_HOST = os.getenv('ORACLE_HOST', '')
NRO_PORT = int(os.getenv('ORACLE_PORT', '1521'))

# KEYCLOAK & JWT_OIDC Settings
JWT_OIDC_WELL_KNOWN_CONFIG = os.getenv('JWT_OIDC_WELL_KNOWN_CONFIG')
JWT_OIDC_ALGORITHMS = os.getenv('JWT_OIDC_ALGORITHMS')
Expand All @@ -100,8 +90,6 @@ class Config(object):
PAYMENT_SVC_AUTH_CLIENT_ID = os.getenv('NAME_REQUEST_SERVICE_ACCOUNT_CLIENT_ID', '')
PAYMENT_SVC_CLIENT_SECRET = os.getenv('NAME_REQUEST_SERVICE_ACCOUNT_CLIENT_SECRET', '')

# You can disable NRO updates for Name Requests by setting the variable in your .env / OpenShift configuration
DISABLE_NAMEREQUEST_NRO_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_NRO_UPDATES', 0))
DISABLE_NAMEREQUEST_SOLR_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0))


Expand Down Expand Up @@ -129,8 +117,6 @@ class DevConfig(Config):
TESTING = False,
DEBUG = True

# We can't run NRO locally unless you're provisioned, you can disable NRO updates for Name Requests by setting the variable in your .env
DISABLE_NAMEREQUEST_NRO_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_NRO_UPDATES', 0))
DISABLE_NAMEREQUEST_SOLR_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0))


Expand All @@ -145,7 +131,7 @@ class TestConfig(Config):
DB_NAME = os.getenv('DATABASE_TEST_NAME', '')
DB_HOST = os.getenv('DATABASE_TEST_HOST', '')
DB_PORT = os.getenv('DATABASE_TEST_PORT', '5432')
# Allows for NRO add / update bypass if necessary (for local development)

LOCAL_DEV_MODE = os.getenv('LOCAL_DEV_MODE', False)
# Set this in your .env to debug SQL Alchemy queries (for local development)
SQLALCHEMY_ECHO = 'debug' if os.getenv('DEBUG_SQL_QUERIES', False) else False
Expand All @@ -158,8 +144,6 @@ class TestConfig(Config):
)
EMAILER_TOPIC = os.getenv('NAMEX_MAILER_TOPIC', '')

# We can't run NRO locally for running our tests
DISABLE_NAMEREQUEST_NRO_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_NRO_UPDATES', 1))
DISABLE_NAMEREQUEST_SOLR_UPDATES = int(os.getenv('DISABLE_NAMEREQUEST_SOLR_UPDATES', 0))

# JWT OIDC settings
Expand Down
2 changes: 1 addition & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.1.60'
__version__ = '1.2.0'

4 changes: 0 additions & 4 deletions api/namex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@

from namex.services.cache import cache
from namex.services.lookup import nr_filing_actions
from namex.services.nro import NROServices

from .services import queue

nro = NROServices()
from namex import models
from namex.models import db, ma
from namex.resources import api
Expand Down Expand Up @@ -65,7 +62,6 @@ def create_app(run_mode=os.getenv('FLASK_ENV', 'production')):
api.init_app(app)
setup_jwt_manager(app, jwt)

nro.init_app(app)
cache.init_app(app)
nr_filing_actions.init_app(app)

Expand Down
1 change: 0 additions & 1 deletion api/namex/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class ValidLocations(AbstractEnum):
class ValidSources(AbstractEnum):
NAMEX = 'NAMEX'
NAMEREQUEST = 'NAMEREQUEST'
NRO = 'NRO'
SO = 'SO'


Expand Down
1 change: 0 additions & 1 deletion api/namex/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from .user import User, UserSchema

from .decision_reason import DecisionReason
from .nro_sync_tables import NRONamesSyncJob, NRONamesSyncJobDetail, NRONamesSyncJobStatus
from .admin_tables import DecisionReasonAudit, RestrictedConditionAudit
from .word_classification import WordClassification, WordClassificationSchema
from .virtual_word_condition import VirtualWordCondition
Expand Down
6 changes: 2 additions & 4 deletions api/namex/models/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Name(db.Model):
commentId = db.Column('comment_id', db.Integer, db.ForeignKey('comments.id'))
# nameRequest = db.relationship('Request')

# if a comment is added during decision, link it to the name record to be sent back to NRO
comment = db.relationship("Comment", backref=backref("related_name", uselist=False), foreign_keys=[commentId])

# Required for name request name analysis
Expand Down Expand Up @@ -136,15 +135,14 @@ def update_nr_name_search(mapper, connection, target):
current_app.logger\
.debug('name_consume_history check - nrNum: {}, consumptionDate: {}, corpNum: {}, state: {}'
.format(nr.nrNum, name.consumptionDate, name.corpNum, name.state))
# Note: we cannot just check for a corpNum addition due to some Society change of name NRs coming over from
# NRO extractor providing a value for the corpNum field.

# Note: do we need to validate corpNum?
if len(name_consume_history.added) \
and name.consumptionDate \
and name.corpNum \
and name.state in ['APPROVED', 'CONDITION']:
# Adding an after_flush_postexec to avoid connection and transaction closed issue's
# Creating one time execution event when ever corpNum is added to a name
# corpNum sets from nro-extractor job
@event.listens_for(db.session, 'after_flush_postexec', once=True)
def receive_after_flush_postexec(session, flush_context):
nr = Request.find_by_id(name.nrId)
Expand Down
37 changes: 0 additions & 37 deletions api/namex/models/nro_sync_tables.py

This file was deleted.

16 changes: 0 additions & 16 deletions api/namex/models/nwpta.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@ def save_to_db(self):
def delete_from_db(self):
pass

# used by NRO extractor
def set_requested_flag(self):
try:
# NAS (Numbered Assumed) types have blank data but are not requested
if self.partnerNameTypeCd == 'NAS':
self.requested = False

# if all data is blank (except type and jurisdiction) then the customer has requested nwpta
elif self.partnerNameNumber in ['', None] and self.partnerName in ['', None] and self.partnerNameDate in ['', None]:
self.requested = True

else:
self.requested = False
except:
pass


class PartnerNameSystemSchema(ma.SQLAlchemySchema):
class Meta:
Expand Down
6 changes: 3 additions & 3 deletions api/namex/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Request(db.Model):
_request_action_cd = db.Column('request_action_cd', db.String(10))
_entity_type_cd = db.Column('entity_type_cd', db.String(10))
consent_dt = db.Column('consent_dt', db.DateTime(timezone=True))
_source = db.Column('source', db.String(15), default=ValidSources.NRO.value)
_source = db.Column('source', db.String(15))
tradeMark = db.Column('trade_mark', db.String(100))

# Check-In / Check-Out (for INPROGRESS)
Expand Down Expand Up @@ -265,7 +265,7 @@ def get_queued_oldest(cls, userObj, priority_queue):

if existing_nr:
current_app.logger.info('Existing NR found, returning: {}'.format(existing_nr.nrNum))
return existing_nr, False
return existing_nr

# this will error if there's nothing in the queue - likelihood ~ 0
result = None
Expand Down Expand Up @@ -293,7 +293,7 @@ def get_queued_oldest(cls, userObj, priority_queue):

db.session.add(result)
db.session.commit()
return result, True
return result

@classmethod
def get_oldest_draft(cls):
Expand Down
75 changes: 44 additions & 31 deletions api/namex/resources/name_requests/abstract_nr_resource.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
from flask import current_app
from typing import Callable

from namex.models import Request, State
from namex.services.name_request.generate_new_nr_number import NRNumberService
from namex.utils.logging import setup_logging
from namex.services.name_request.utils import is_temp_nr_num
from namex.services.name_request import NameRequestService
from namex.services.name_request.exceptions import NameRequestException
from namex.services.virtual_word_condition import VirtualWordConditionService

from .abstract_nro_resource import AbstractNROResource
from .abstract_solr_resource import AbstractSolrResource


setup_logging() # Important to do this first


class AbstractNameRequestResource(AbstractNROResource, AbstractSolrResource):
class AbstractNameRequestResource(AbstractSolrResource):
_request_data = None
_nr_action = None
_nr_service = None

@property
def request_data(self):
Expand All @@ -30,6 +36,17 @@ def nr_action(self):
def nr_action(self, nr_action):
self._nr_action = nr_action

@property
def nr_service(self):
try:
if not self._nr_service:
self._nr_service = NameRequestService()
self._nr_service.virtual_wc_service = VirtualWordConditionService()
except Exception as err:
raise NameRequestException(err, message='Error initializing NameRequestService')

return self._nr_service

def update_nr(self, nr_model: Request, new_state, on_state_changed: Callable) -> Request:
"""
Call this method in inheriting classes to update an NR (Request).
Expand Down Expand Up @@ -148,51 +165,47 @@ def save_nr(nr: Request, svc) -> Request:
# Return the updated name request
return nr

def add_records_to_network_services(self, nr_model: Request, update_solr=False) -> Request:
def add_new_nr_number(self, nr_model: Request, update_solr=False) -> Request:
is_temp_nr = is_temp_nr_num(nr_model.nrNum)
temp_nr_num = None

if nr_model.stateCd in [State.PENDING_PAYMENT,
State.DRAFT,
State.COND_RESERVE,
State.RESERVED,
State.CONDITIONAL,
State.APPROVED] and nr_model.nrNum.startswith('NR L'):
existing_nr_num = nr_model.nrNum
# This updates NRO, it should return the nr_model with the updated nrNum, which we save back to postgres in the save_nr handler
print('Adding request to NRO')
nr_model = self.add_request_to_nro(nr_model, self.save_nr)
print('NR is using the temporary NR Number {num}'.format(num=nr_model.nrNum))
State.APPROVED] and is_temp_nr:
temp_nr_num = nr_model.nrNum

nr_num = NRNumberService.get_new_nr_num()
nr_model.nrNum = nr_num
current_app.logger.debug('NR is using the temporary NR Number {num}'.format(num=nr_num))

# Set the temp NR number if its different
if nr_model.nrNum != existing_nr_num:
temp_nr_num = existing_nr_num
print('Replacing temporary NR Number {temp} -> {new}'.format(temp=temp_nr_num, new=nr_model.nrNum))
current_app.logger.debug('Replacing temporary NR Number {temp} -> {new}'.format(temp=temp_nr_num, new=nr_model.nrNum))

print(repr(nr_model))
current_app.logger.debug(repr(nr_model))

# Update SOLR
if update_solr:
self.update_solr_service(nr_model, temp_nr_num)

return nr_model

def update_records_in_network_services(self, nr_model: Request, update_solr=False) -> Request:
temp_nr_num = None
if nr_model.stateCd in [State.PENDING_PAYMENT, State.DRAFT, State.CONDITIONAL, State.APPROVED, State.CANCELLED, State.INPROGRESS]:
existing_nr_num = nr_model.nrNum
# This updates NRO, it should return the nr_model with the updated nrNum, which we save back to postgres in the save_nr handler
print('Updating request in NRO')
nr_model = self.update_request_in_nro(nr_model, self.save_nr)

# Set the temp NR number if its different
if nr_model.nrNum != existing_nr_num:
temp_nr_num = existing_nr_num
print('Replacing temporary NR Number {temp} -> {new}'.format(temp=temp_nr_num, new=nr_model.nrNum))

print(repr(nr_model))

# Update SOLR
if update_solr:
self.update_solr_service(nr_model, temp_nr_num)
def update_solr(self, nr_model: Request) -> Request:
# List of states that require SOLR update
states_to_update = [
State.PENDING_PAYMENT,
State.DRAFT,
State.CONDITIONAL,
State.APPROVED,
State.CANCELLED,
State.INPROGRESS
]

# Check if the current state of the request is in the list of states to update
if nr_model.stateCd in states_to_update:
self.update_solr_service(nr_model)

return nr_model

Expand Down
Loading