Skip to content

Commit

Permalink
PPR API version upgrade step 2.
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Lovett <[email protected]>
  • Loading branch information
doug-lovett committed Feb 14, 2024
1 parent 94dd475 commit c87490a
Show file tree
Hide file tree
Showing 38 changed files with 646 additions and 646 deletions.
14 changes: 14 additions & 0 deletions ppr-api/src/ppr_api/callback/file_transfer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright © 2019 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.
"""This module holds request non-schema data validation functions and helpers."""
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
"""This class transfers reports to a mail service for printing and mailing."""
from flask import current_app

from ppr_api.callback.utils.exceptions import FileTransferException
from ppr_api.models import utils as model_utils

Expand Down Expand Up @@ -50,6 +49,8 @@ def transfer_file(self, binary_data, file_name: str):
current_app.logger.info(msg)
if not self.mail_host or self.mail_host.strip() == '':
raise FileTransferException('No host configured to transfer files to.')
if not binary_data:
raise FileTransferException('No file data to transfer.')

def get_filename(self, registration_id, party_id):
"""Build a correctly formatted unique name."""
Expand Down
8 changes: 4 additions & 4 deletions ppr-api/src/ppr_api/models/account_bcol_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class AccountBcolId(db.Model):
__tablename__ = 'account_bcol_ids'
CROWN_CHARGE_YES = 'Y'

id = db.Column('id', db.Integer, db.Sequence('account_bcol_id_seq'), primary_key=True)
account_id = db.Column('account_id', db.String(20), nullable=False, index=True)
bconline_account = db.Column('bconline_account', db.Integer, nullable=False)
id = db.mapped_column('id', db.Integer, db.Sequence('account_bcol_id_seq'), primary_key=True)
account_id = db.mapped_column('account_id', db.String(20), nullable=False, index=True)
bconline_account = db.mapped_column('bconline_account', db.Integer, nullable=False)
# Only set when account is a crown charge account.
crown_charge_ind = db.Column('crown_charge_ind', db.String(1), nullable=True)
crown_charge_ind = db.mapped_column('crown_charge_ind', db.String(1), nullable=True)

def save(self):
"""Store the User into the local cache."""
Expand Down
20 changes: 10 additions & 10 deletions ppr-api/src/ppr_api/models/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class Address(db.Model): # pylint: disable=too-many-instance-attributes

__tablename__ = 'addresses'

id = db.Column('id', db.Integer, db.Sequence('address_id_seq'), primary_key=True)
street = db.Column('street', db.String(50), nullable=False) # index=True)
street_additional = db.Column('street_additional', db.String(50), nullable=True)
city = db.Column('city', db.String(40), nullable=False)
region = db.Column('region', db.String(2),
db.ForeignKey('province_types.province_type'), nullable=True)
postal_code = db.Column('postal_code', db.String(15), nullable=False)
country = db.Column('country', db.String(2),
db.ForeignKey('country_types.country_type'), nullable=True)
id = db.mapped_column('id', db.Integer, db.Sequence('address_id_seq'), primary_key=True)
street = db.mapped_column('street', db.String(50), nullable=False) # index=True)
street_additional = db.mapped_column('street_additional', db.String(50), nullable=True)
city = db.mapped_column('city', db.String(40), nullable=False)
region = db.mapped_column('region', db.String(2),
db.ForeignKey('province_types.province_type'), nullable=True)
postal_code = db.mapped_column('postal_code', db.String(15), nullable=False)
country = db.mapped_column('country', db.String(2),
db.ForeignKey('country_types.country_type'), nullable=True)

# parent keys

Expand All @@ -58,7 +58,7 @@ def find_by_id(cls, address_id: int): # -> Address:
"""Return the address matching the id."""
address = None
if address_id:
address = cls.query.get(address_id)
address = db.session.query(Address).filter(Address.id == address_id).one_or_none()
return address

@property
Expand Down
28 changes: 14 additions & 14 deletions ppr-api/src/ppr_api/models/client_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
from __future__ import annotations

from flask import current_app
from sqlalchemy.sql import text

from ppr_api.exceptions import DatabaseException
from sqlalchemy.sql import text

from .account_bcol_id import AccountBcolId # noqa: F401 pylint: disable=unused-import
# Needed by the SQLAlchemy relationship
Expand All @@ -43,22 +42,23 @@ class ClientCode(db.Model): # pylint: disable=too-many-instance-attributes
"""This class maintains client party information (registering and secured parties)."""

__tablename__ = 'client_codes'

# key value is generated from a db function tbd. ,default=db.func.get_code_branch_id()
id = db.Column('id', db.Integer, primary_key=True, nullable=False)
head_id = db.Column('head_id', db.Integer, index=True, nullable=False)
name = db.Column('name', db.String(150), index=True, nullable=False)
bconline_account = db.Column('bconline_account', db.Integer, nullable=True)
id = db.mapped_column('id', db.Integer, primary_key=True, nullable=False)
head_id = db.mapped_column('head_id', db.Integer, index=True, nullable=False)
name = db.mapped_column('name', db.String(150), index=True, nullable=False)
bconline_account = db.mapped_column('bconline_account', db.Integer, nullable=True)
# contact info
contact_name = db.Column('contact_name', db.String(100), nullable=False)
contact_area_cd = db.Column('contact_area_cd', db.String(3), nullable=True)
contact_phone_number = db.Column('contact_phone_number', db.String(15), nullable=False)
email_id = db.Column('email_address', db.String(250), nullable=True)
user_id = db.Column('user_id', db.String(7), nullable=True)
date_ts = db.Column('date_ts', db.DateTime, nullable=True)
contact_name = db.mapped_column('contact_name', db.String(100), nullable=False)
contact_area_cd = db.mapped_column('contact_area_cd', db.String(3), nullable=True)
contact_phone_number = db.mapped_column('contact_phone_number', db.String(15), nullable=False)
email_id = db.mapped_column('email_address', db.String(250), nullable=True)
user_id = db.mapped_column('user_id', db.String(7), nullable=True)
date_ts = db.mapped_column('date_ts', db.DateTime, nullable=True)

# parent keys
address_id = db.Column('address_id', db.Integer, db.ForeignKey('addresses.id'), nullable=False, index=True)
users_id = db.Column('users_id', db.Integer, db.ForeignKey('users.id'), nullable=True, index=True)
address_id = db.mapped_column('address_id', db.Integer, db.ForeignKey('addresses.id'), nullable=False, index=True)
users_id = db.mapped_column('users_id', db.Integer, db.ForeignKey('users.id'), nullable=True, index=True)

# Relationships
address = db.relationship('Address', foreign_keys=[address_id], uselist=False,
Expand Down
33 changes: 17 additions & 16 deletions ppr-api/src/ppr_api/models/client_code_historical.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
from __future__ import annotations

from enum import Enum
from ppr_api.utils.base import BaseEnum

# Needed by the SQLAlchemy relationship
from .address import Address # noqa: F401 pylint: disable=unused-import
Expand All @@ -27,31 +27,32 @@
class ClientCodeHistorical(db.Model): # pylint: disable=too-many-instance-attributes
"""This class maintains client party information: history of name and address changes."""

class HistoricalTypes(Enum):
class HistoricalTypes(BaseEnum):
"""Render an Enum of the historical types."""

ADDRESS = 'A'
BOTH = 'B'
NAME = 'N'

__tablename__ = 'client_codes_historical'
id = db.Column('id', db.Integer, db.Sequence('historical_head_id_seq'), primary_key=True)
head_id = db.Column('head_id', db.Integer, index=True, nullable=False)
name = db.Column('name', db.String(150), index=True, nullable=False)
historical_type = db.Column('historical_type', db.String(1), nullable=False)
bconline_account = db.Column('bconline_account', db.Integer, nullable=True)

id = db.mapped_column('id', db.Integer, db.Sequence('historical_head_id_seq'), primary_key=True)
head_id = db.mapped_column('head_id', db.Integer, index=True, nullable=False)
name = db.mapped_column('name', db.String(150), index=True, nullable=False)
historical_type = db.mapped_column('historical_type', db.String(1), nullable=False)
bconline_account = db.mapped_column('bconline_account', db.Integer, nullable=True)
# contact info
contact_name = db.Column('contact_name', db.String(100), nullable=False)
contact_area_cd = db.Column('contact_area_cd', db.String(3), nullable=True)
contact_phone_number = db.Column('contact_phone_number', db.String(15), nullable=False)
email_id = db.Column('email_addresss', db.String(250), nullable=True)
user_id = db.Column('user_id', db.String(7), nullable=True)
date_ts = db.Column('date_ts', db.DateTime, nullable=True)
contact_name = db.mapped_column('contact_name', db.String(100), nullable=False)
contact_area_cd = db.mapped_column('contact_area_cd', db.String(3), nullable=True)
contact_phone_number = db.mapped_column('contact_phone_number', db.String(15), nullable=False)
email_id = db.mapped_column('email_addresss', db.String(250), nullable=True)
user_id = db.mapped_column('user_id', db.String(7), nullable=True)
date_ts = db.mapped_column('date_ts', db.DateTime, nullable=True)

# parent keys
branch_id = db.Column('branch_id', db.Integer, db.ForeignKey('client_codes.id'), nullable=False, index=True)
address_id = db.Column('address_id', db.Integer, db.ForeignKey('addresses.id'), nullable=False, index=True)
users_id = db.Column('users_id', db.Integer, db.ForeignKey('users.id'), nullable=True, index=True)
branch_id = db.mapped_column('branch_id', db.Integer, db.ForeignKey('client_codes.id'), nullable=False, index=True)
address_id = db.mapped_column('address_id', db.Integer, db.ForeignKey('addresses.id'), nullable=False, index=True)
users_id = db.mapped_column('users_id', db.Integer, db.ForeignKey('users.id'), nullable=True, index=True)

# Relationships
address = db.relationship('Address', foreign_keys=[address_id], uselist=False,
Expand Down
21 changes: 11 additions & 10 deletions ppr-api/src/ppr_api/models/court_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ class CourtOrder(db.Model): # pylint: disable=too-many-instance-attributes

__tablename__ = 'court_orders'

id = db.Column('id', db.Integer, db.Sequence('court_order_id_seq'), primary_key=True)
order_date = db.Column('order_date', db.DateTime, nullable=False)
court_name = db.Column('court_name', db.String(256), nullable=False)
court_registry = db.Column('court_registry', db.String(64), nullable=False)
file_number = db.Column('file_number', db.String(20), nullable=False)
effect_of_order = db.Column('effect_of_order', db.String(512), nullable=True)
id = db.mapped_column('id', db.Integer, db.Sequence('court_order_id_seq'), primary_key=True)
order_date = db.mapped_column('order_date', db.DateTime, nullable=False)
court_name = db.mapped_column('court_name', db.String(256), nullable=False)
court_registry = db.mapped_column('court_registry', db.String(64), nullable=False)
file_number = db.mapped_column('file_number', db.String(20), nullable=False)
effect_of_order = db.mapped_column('effect_of_order', db.String(512), nullable=True)

# parent keys
registration_id = db.Column('registration_id', db.Integer, db.ForeignKey('registrations.id'), nullable=False,
index=True)
registration_id = db.mapped_column('registration_id', db.Integer, db.ForeignKey('registrations.id'),
nullable=False,
index=True)

# Relationships - Registration
registration = db.relationship('Registration', foreign_keys=[registration_id],
Expand All @@ -57,7 +58,7 @@ def find_by_id(cls, court_order_id: int = None):
"""Return an expiry object by expiry ID."""
expiry = None
if court_order_id:
expiry = cls.query.get(court_order_id)
expiry = db.session.query(CourtOrder).filter(CourtOrder.id == court_order_id).one_or_none()

return expiry

Expand All @@ -66,7 +67,7 @@ def find_by_registration_id(cls, registration_id: int = None):
"""Return a list of expiry objects by registration number."""
expiry = None
if registration_id:
expiry = cls.query.filter(CourtOrder.registration_id == registration_id).one_or_none()
expiry = db.session.query(CourtOrder).filter(CourtOrder.registration_id == registration_id).one_or_none()

return expiry

Expand Down
Loading

0 comments on commit c87490a

Please sign in to comment.