Skip to content

Commit

Permalink
Merge pull request #1334 from bcgov/develop
Browse files Browse the repository at this point in the history
Deployment PR - 872
  • Loading branch information
dhaselhan authored Jan 25, 2024
2 parents 61e7983 + 6ea0c48 commit 5f42516
Show file tree
Hide file tree
Showing 41 changed files with 391 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<section>
<app-decision-v1 *ngIf="application?.source === APPLICATION_SYSTEM_SOURCE_TYPES.ALCS"></app-decision-v1>
<app-decision-v2 *ngIf="application?.source === APPLICATION_SYSTEM_SOURCE_TYPES.APPLICANT"></app-decision-v2>
<app-decision-v2 *ngIf="application && application.source !== APPLICATION_SYSTEM_SOURCE_TYPES.ALCS"></app-decision-v2>
<div class="child-content">
<router-outlet></router-outlet>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h5>Submitted to ALC</h5>
[required]="true"
></app-inline-datepicker>
</div>
<div *ngIf="application?.source === APPLICATION_SYSTEM_SOURCE_TYPES.APPLICANT">
<div *ngIf="application && application.source !== APPLICATION_SYSTEM_SOURCE_TYPES.ALCS">
<h5>Payment</h5>
<div class="payment-section">
<div>
Expand Down Expand Up @@ -41,7 +41,7 @@ <h5>Payment</h5>
</div>
</div>
</div>
<div *ngIf="application?.source !== APPLICATION_SYSTEM_SOURCE_TYPES.APPLICANT">
<div *ngIf="application?.source === APPLICATION_SYSTEM_SOURCE_TYPES.ALCS">
<h5>Payment Date</h5>
<app-inline-datepicker
[value]="application?.feePaidDate"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h3>Application Prep</h3>
<section *ngIf="application?.source === APPLICATION_SYSTEM_SOURCE_TYPES.APPLICANT">
<section *ngIf="application && application.source !== APPLICATION_SYSTEM_SOURCE_TYPES.ALCS">
<h5>Proposal Components - {{ application?.type?.label }}</h5>
<div class="input-table">
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h3>Notice of Intent Prep</h3>
<section *ngIf="noticeOfIntent?.source === APPLICATION_SYSTEM_SOURCE_TYPES.APPLICANT">
<section *ngIf="noticeOfIntent && noticeOfIntent.source !== APPLICATION_SYSTEM_SOURCE_TYPES.ALCS">
<h5>Proposal Components - {{ noticeOfIntent?.type?.label }}</h5>
<div class="input-table">
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _get_insert_query():
%(created_at)s,
%(date)s,
%(decision_description)s,
false,
true,
false,
%(outcome_code)s,
%(rescinded_comment)s,
Expand All @@ -133,6 +133,9 @@ def _get_insert_query():
rescinded_comment = COALESCE(EXCLUDED.rescinded_comment, alcs.application_decision.rescinded_comment),
rescinded_date = COALESCE(EXCLUDED.rescinded_date, alcs.application_decision.rescinded_date),
is_subject_to_conditions = COALESCE(EXCLUDED.is_subject_to_conditions, alcs.application_decision.is_subject_to_conditions),
was_released = True,
is_draft = False,
chair_review_required = COALESCE(EXCLUDED.chair_review_required, true),
oats_alr_appl_decision_id = EXCLUDED.oats_alr_appl_decision_id;
"""
return query
Expand Down
4 changes: 4 additions & 0 deletions bin/migrate-oats-data/applications/migrate_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@
)

from .set_application_visibility import set_application_visibility

from .update_app_created_date import update_application_created_date

from .application_decision_date import process_alcs_application_decision_date


def process_application_etl(batch_size):
process_alcs_application_prep_fields(batch_size)
update_application_date_rx_all_items(batch_size)
update_application_created_date(batch_size)
process_alcs_app_submissions(batch_size)
update_application_submissions()
insert_application_submission_review(batch_size)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT oaa.created_date, oaa.alr_application_id, a.audit_created_by, oaa.when_created
FROM oats.oats_alr_applications oaa
JOIN alcs.application a ON a.file_number = oaa.alr_application_id::TEXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT count(*)
FROM oats.oats_alr_applications oaa
JOIN alcs.application a ON a.file_number = oaa.alr_application_id::TEXT
116 changes: 116 additions & 0 deletions bin/migrate-oats-data/applications/update_app_created_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from common import (
setup_and_get_logger,
add_timezone_and_keep_date_part,
BATCH_UPLOAD_SIZE
)
from db import inject_conn_pool
from psycopg2.extras import RealDictCursor, execute_batch

etl_name = "update_application_created_date"
logger = setup_and_get_logger(etl_name)


@inject_conn_pool
def update_application_created_date(conn=None, batch_size=BATCH_UPLOAD_SIZE):
"""
This function is responsible for updating existing the application created_at_date in ALCS.
Args:
conn (psycopg2.extensions.connection): PostgreSQL database connection. Provided by the decorator.
batch_size (int): The number of items to process at once. Defaults to BATCH_UPLOAD_SIZE.
"""

logger.info(f"Start {etl_name}")
with conn.cursor(cursor_factory=RealDictCursor) as cursor:
with open(
"applications/sql/application_created_date_update_count.sql",
"r",
encoding="utf-8",
) as sql_file:
count_query = sql_file.read()
cursor.execute(count_query)
count_total = dict(cursor.fetchone())["count"]
logger.info(f"Total Application data to be updated: {count_total}")

failed_updates_count = 0
successful_updates_count = 0
last_application_id = 0

with open(
"applications/sql/application_created_date_update.sql",
"r",
encoding="utf-8",
) as sql_file:
query = sql_file.read()
while True:
cursor.execute(
f"""{query}
WHERE oaa.alr_application_id > {last_application_id} ORDER BY oaa.alr_application_id;"""
)

rows = cursor.fetchmany(batch_size)

if not rows:
break
try:
conditions_to_be_updated_count = len(rows)

_update_application_created_at_date(conn, batch_size, cursor, rows)

successful_updates_count = (
successful_updates_count + conditions_to_be_updated_count
)
last_application_id = dict(rows[-1])["alr_application_id"]

logger.debug(
f"retrieved/updated items count: {conditions_to_be_updated_count}; total successfully updated applications so far {successful_updates_count}; last updated application: {last_application_id}"
)
except Exception as err:
logger.exception(err)
conn.rollback()
failed_updates_count = count_total - successful_updates_count
last_application_id = last_application_id + 1

logger.info(
f"Finished {etl_name}: total amount of successful updates {successful_updates_count}, total failed updates {failed_updates_count}"
)


def _update_application_created_at_date(conn, batch_size, cursor, rows):
data = _prepare_oats_alr_applications_data(rows)

if len(data) > 0:
execute_batch(
cursor,
_get_update_query(),
data,
page_size=batch_size,
)

conn.commit()


def _get_update_query():
query = f"""
UPDATE alcs.application
SET created_at = %(date_to_insert)s
WHERE alcs.application.file_number = %(alr_application_id)s::TEXT;
"""
return query


def _prepare_oats_alr_applications_data(row_data_list):
data_list = []
date_to_insert = None
for row in row_data_list:
if row.get("created_date"):
date_to_insert = row.get("created_date")
else:
date_to_insert = row.get("when_created")
mapped_row = {
"date_to_insert": add_timezone_and_keep_date_part(date_to_insert),
"alr_application_id": row.get("alr_application_id"),
}
data_list.append(mapped_row)

return data_list
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OATS_ETL_USER,
setup_and_get_logger,
add_timezone_and_keep_date_part,
BATCH_UPLOAD_SIZE
BATCH_UPLOAD_SIZE,
)
from db import inject_conn_pool
from psycopg2.extras import RealDictCursor, execute_batch
Expand Down Expand Up @@ -133,6 +133,8 @@ def _get_insert_query():
rescinded_comment = COALESCE(EXCLUDED.rescinded_comment, alcs.notice_of_intent_decision.rescinded_comment),
rescinded_date = COALESCE(EXCLUDED.rescinded_date, alcs.notice_of_intent_decision.rescinded_date),
is_subject_to_conditions = COALESCE(EXCLUDED.is_subject_to_conditions, alcs.notice_of_intent_decision.is_subject_to_conditions),
was_released = True,
is_draft = False,
oats_alr_appl_decision_id = EXCLUDED.oats_alr_appl_decision_id;
"""
return query
Expand Down
3 changes: 3 additions & 0 deletions bin/migrate-oats-data/noi/notice_of_intent_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .oats_to_alcs_notice_of_intent_table_etl.notice_of_intent_rx_all_items import (
update_notice_of_intent_date_rx_all_items,
)
from .oats_to_alcs_notice_of_intent_table_etl.update_notice_of_intent_created_date import update_noi_created_date

from .notice_of_intent_submissions.parcels import (
init_notice_of_intent_parcels,
Expand Down Expand Up @@ -131,6 +132,8 @@ def process_notice_of_intent(batch_size):

update_notice_of_intent_date_rx_all_items(batch_size)

update_noi_created_date(batch_size)

process_alcs_notice_of_intent_decision_date(batch_size)

init_notice_of_intent_submissions(batch_size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
process_alcs_notice_of_intent_base_fields,
)
from .notice_of_intent_rx_all_items import update_notice_of_intent_date_rx_all_items
from .update_notice_of_intent_created_date import update_noi_created_date
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
from common import (
setup_and_get_logger,
add_timezone_and_keep_date_part,
BATCH_UPLOAD_SIZE
)
from db import inject_conn_pool
from psycopg2.extras import RealDictCursor, execute_batch

etl_name = "update_notice_of_intent_created_date"
logger = setup_and_get_logger(etl_name)


@inject_conn_pool
def update_noi_created_date(conn=None, batch_size=BATCH_UPLOAD_SIZE):
"""
This function is responsible for updating existing the notice_of_intent created_at_date in ALCS.
Args:
conn (psycopg2.extensions.connection): PostgreSQL database connection. Provided by the decorator.
batch_size (int): The number of items to process at once. Defaults to BATCH_UPLOAD_SIZE.
"""

logger.info(f"Start {etl_name}")
with conn.cursor(cursor_factory=RealDictCursor) as cursor:
with open(
"noi/sql/notice_of_intent_base/notice_of_intent_created_date_update_count.sql",
"r",
encoding="utf-8",
) as sql_file:
count_query = sql_file.read()
cursor.execute(count_query)
count_total = dict(cursor.fetchone())["count"]
logger.info(f"Total Notice of Intent data to be updated: {count_total}")

failed_updates_count = 0
successful_updates_count = 0
last_application_id = 0

with open(
"noi/sql/notice_of_intent_base/notice_of_intent_created_date_update.sql",
"r",
encoding="utf-8",
) as sql_file:
query = sql_file.read()
while True:
cursor.execute(
f"""{query}
WHERE oaa.alr_application_id > {last_application_id} ORDER BY oaa.alr_application_id;"""
)

rows = cursor.fetchmany(batch_size)

if not rows:
break
try:
conditions_to_be_updated_count = len(rows)

_update_notice_of_intent_created_at_date(conn, batch_size, cursor, rows)

successful_updates_count = (
successful_updates_count + conditions_to_be_updated_count
)
last_application_id = dict(rows[-1])["alr_application_id"]

logger.debug(
f"retrieved/updated items count: {conditions_to_be_updated_count}; total successfully updated notice of intents so far {successful_updates_count}; last updated notice of intent: {last_application_id}"
)
except Exception as err:
logger.exception(err)
conn.rollback()
failed_updates_count = count_total - successful_updates_count
last_application_id = last_application_id + 1

logger.info(
f"Finished {etl_name}: total amount of successful updates {successful_updates_count}, total failed updates {failed_updates_count}"
)


def _update_notice_of_intent_created_at_date(conn, batch_size, cursor, rows):
data = _prepare_oats_alr_notice_of_intents_data(rows)

if len(data) > 0:
execute_batch(
cursor,
_get_update_query(),
data,
page_size=batch_size,
)

conn.commit()


def _get_update_query():
query = f"""
UPDATE alcs.notice_of_intent
SET created_at = %(date_to_insert)s
WHERE alcs.notice_of_intent.file_number = %(alr_application_id)s::TEXT;
"""
return query


def _prepare_oats_alr_notice_of_intents_data(row_data_list):
data_list = []
date_to_insert = None
for row in row_data_list:
if row.get("created_date"):
date_to_insert = row.get("created_date")
else:
date_to_insert = row.get("when_created")
mapped_row = {
"date_to_insert": add_timezone_and_keep_date_part(date_to_insert),
"alr_application_id": row.get("alr_application_id"),
}
data_list.append(mapped_row)

return data_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT oaa.created_date, oaa.alr_application_id, oaa.when_created
FROM oats.oats_alr_applications oaa
JOIN alcs.notice_of_intent noi ON noi.file_number = oaa.alr_application_id::TEXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT count(*)
FROM oats.oats_alr_applications oaa
JOIN alcs.notice_of_intent noi ON noi.file_number = oaa.alr_application_id::TEXT
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h3>3. Primary Contact</h3>
</div>
<div class="subheading2 grid-1">Phone</div>
<div class="grid-double">
{{ primaryContact?.phoneNumber }}
{{ primaryContact?.phoneNumber ?? '' | mask : '(000) 000-0000' }}
<app-no-data [showRequired]="showErrors" *ngIf="!primaryContact?.phoneNumber"></app-no-data>
<app-validation-error *ngIf="!(primaryContact?.phoneNumber || '' | phoneValid)"
>Invalid Format</app-validation-error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ <h5 *ngIf="parcel.ownershipTypeCode === PARCEL_OWNERSHIP_TYPES.CROWN">Government
</div>
<div class="subheading2 grid-1" *ngIf="parcel.ownershipTypeCode === PARCEL_OWNERSHIP_TYPES.CROWN">Phone</div>
<div class="grid-double">
{{ parcel.owners[0].phoneNumber }}
{{ parcel.owners[0].phoneNumber ?? '' | mask : '(000) 000-0000' }}
<app-no-data [showRequired]="showErrors" *ngIf="!parcel.owners[0].phoneNumber"></app-no-data>
</div>
<div class="subheading2 grid-1" *ngIf="parcel.ownershipTypeCode === PARCEL_OWNERSHIP_TYPES.CROWN">Email</div>
Expand Down Expand Up @@ -170,7 +170,7 @@ <h5 *ngIf="parcel.ownershipTypeCode === PARCEL_OWNERSHIP_TYPES.CROWN">Government
<span *ngIf="owner.organizationName"></span>{{ owner.organizationName }}
<app-no-data [showRequired]="false" *ngIf="!owner.organizationName"></app-no-data>
</div>
<div>{{ owner.phoneNumber }}</div>
<div>{{ owner.phoneNumber ?? '' | mask : '(000) 000-0000' }}</div>
<div>{{ owner.email }}</div>
<div *ngIf="parcel.ownershipTypeCode !== PARCEL_OWNERSHIP_TYPES.CROWN">
<a *ngIf="owner.corporateSummary" (click)="onOpenFile(owner.corporateSummary.uuid)">{{
Expand Down
Loading

0 comments on commit 5f42516

Please sign in to comment.