Skip to content

Commit

Permalink
Merge branch 'develop' into main-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Haselhan committed Mar 4, 2024
2 parents b5512e8 + 48d4ea4 commit 9424d3d
Show file tree
Hide file tree
Showing 86 changed files with 1,880 additions and 473 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,11 @@ export interface AssignedToMeFile {
})
export class AssignedTableComponent {
@Input() assignedFiles: AssignedToMeFile[] = [];
displayedColumns = ['highPriority', 'title', 'type', 'activeDays', 'stage'];

constructor(private router: Router) {}

async onSelectCard(card: CardDto) {
await this.router.navigateByUrl(`/board/${card.boardCode}?card=${card.uuid}&type=${card.type}`);
}

get displayedColumns(): string[] {
// Include all default columns
const columns = ['highPriority', 'title', 'type', 'activeDays', 'stage'];

// Check if any file has type 'NOTI'
const hasNoti = this.assignedFiles.some(file => file.type === 'NOTI');

// If 'NOTI' type exists, remove 'activeDays' column
if (hasNoti) {
const index = columns.indexOf('activeDays');
if (index !== -1) {
columns.splice(index, 1);
}
}

return columns;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class SubtaskTableComponent {
@Input() subtasks: HomepageSubtaskDto[] = [];
@Input() users: AssigneeDto[] = [];

displayedColumns = ['highPriority', 'title', 'type', 'activeDays', 'stage', 'assignee', 'action'];

MODIFICATION_TYPE_LABEL = MODIFICATION_TYPE_LABEL;
PLANNING_TYPE_LABEL = PLANNING_TYPE_LABEL;
Expand All @@ -39,6 +38,23 @@ export class SubtaskTableComponent {
private cardSubtaskService: CardSubtaskService,
) {}

get displayedColumns(): string[] {
// Include all default columns
const columns = ['highPriority', 'title', 'type', 'activeDays', 'stage', 'assignee', 'action'];

// Check if any file has type 'NOTI'
const hasNoti = this.subtasks.some(task => task.parentType === 'notification');
// If 'NOTI' type exists, remove 'activeDays' column
if (hasNoti) {
const index = columns.indexOf('activeDays');
if (index !== -1) {
columns.splice(index, 1);
}
}

return columns;
}

filterAssigneeList(term: string, item: AssigneeDto) {
const termLower = term.toLocaleLowerCase();
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class ApplicationSearchTableComponent {
this.pageIndex = 0;
this.sortDirection = sort.direction;
this.sortField = sort.active;
this.onTableChange();
}

private mapApplications(applications: ApplicationSearchResultDto[]): SearchResult[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class NonApplicationSearchTableComponent {
this.pageIndex = 0;
this.sortDirection = sort.direction;
this.sortField = sort.active;
this.onTableChange();
}

onSelectRecord(record: SearchResult) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .boundary_amendments import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .application_boundary_amendments_insert import (
clean_boundary_amendments,
insert_application_boundary_amendments,
)
from .application_boundary_amendments_to_components import (
link_application_boundary_amendments,
clean_linked_boundary_amendments,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from common import (
setup_and_get_logger,
BATCH_UPLOAD_SIZE,
OATS_ETL_USER,
)
from db import inject_conn_pool
from psycopg2.extras import RealDictCursor

etl_name = "import_application_boundary_amendments"
logger = setup_and_get_logger(etl_name)


@inject_conn_pool
def insert_application_boundary_amendments(conn=None, batch_size=BATCH_UPLOAD_SIZE):
logger.info(f"Start {etl_name}")
with conn.cursor(cursor_factory=RealDictCursor) as cursor:
with open(
"applications/post_launch/sql/application_components/boundary_amendments/application_boundary_amendments_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 applications data to insert: {count_total}")

failed_inserts_count = 0
successful_inserts_count = 0
last_component_id = 0

with open(
"applications/post_launch/sql/application_components/boundary_amendments/application_boundary_amendments.sql",
"r",
encoding="utf-8",
) as sql_file:
application_sql = sql_file.read()
while True:
cursor.execute(
f"""{application_sql}
AND oaac.alr_appl_component_id > {last_component_id} ORDER BY oaac.alr_appl_component_id;"""
)

rows = cursor.fetchmany(batch_size)

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

_insert_records(conn, cursor, rows)

successful_inserts_count = (
successful_inserts_count + records_to_be_inserted_count
)

last_record = dict(rows[-1])
last_component_id = last_record["alr_appl_component_id"]

logger.debug(
f"retrieved/updated items count: {records_to_be_inserted_count}; total successfully insert applications boundary amendments so far {successful_inserts_count}; last updated {last_component_id}"
)
except Exception as err:
logger.exception(err)
conn.rollback()
failed_inserts_count = count_total - successful_inserts_count
last_component_id = last_component_id + 1

logger.info(
f"Finished {etl_name}: total amount of successful inserts {successful_inserts_count}, total failed inserts {failed_inserts_count}"
)


def _insert_records(conn, cursor, rows):
number_of_rows_to_insert = len(rows)

if number_of_rows_to_insert > 0:
insert_query = _compile_insert_query(number_of_rows_to_insert)
rows_to_insert = _prepare_data_to_insert(rows)
cursor.execute(insert_query, rows_to_insert)
conn.commit()


def _compile_insert_query(number_of_rows_to_insert):
amendments_to_insert = ",".join(["%s"] * number_of_rows_to_insert)
return f"""
INSERT INTO alcs.application_boundary_amendment(
file_number,
type,
area,
year,
period,
oats_component_id,
audit_created_by
)
VALUES{amendments_to_insert}
ON CONFLICT DO NOTHING;
"""


def _prepare_data_to_insert(rows):
row_without_last_element = []
for row in rows:
mapped_row = _map_data(row)
row_without_last_element.append(tuple(mapped_row.values()))

return row_without_last_element


def _map_data(row):
return {
"file_number": row["file_number"],
"type": row["application_decision_component_type_code"],
"area": row["alr_area"],
"year": row["amendment_year"],
"period": row["amendment_period"],
"oats_component_id": row["alr_appl_component_id"],
"audit_created_by": OATS_ETL_USER,
}


@inject_conn_pool
def clean_boundary_amendments(conn=None):
logger.info("Start application boundary amendment cleaning")
with conn.cursor() as cursor:
cursor.execute(
f"DELETE FROM alcs.application_boundary_amendment aba WHERE aba.audit_created_by = '{OATS_ETL_USER}' AND aba.audit_updated_by IS NULL"
)
logger.info(f"Deleted items count = {cursor.rowcount}")
conn.commit()
logger.info("Done application boundary amendment cleaning")
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
from common import (
setup_and_get_logger,
BATCH_UPLOAD_SIZE,
OATS_ETL_USER,
)
from db import inject_conn_pool
from psycopg2.extras import RealDictCursor

etl_name = "link_application_boundary_amendments_to_components"
logger = setup_and_get_logger(etl_name)


@inject_conn_pool
def link_application_boundary_amendments(conn=None, batch_size=BATCH_UPLOAD_SIZE):
logger.info(f"Start {etl_name}")
with conn.cursor(cursor_factory=RealDictCursor) as cursor:
with open(
"applications/post_launch/sql/application_components/boundary_amendments/link_application_boundary_amendments_to_components_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 applications data to insert: {count_total}")

failed_inserts_count = 0
successful_inserts_count = 0
last_component_id = 0

with open(
"applications/post_launch/sql/application_components/boundary_amendments/link_application_boundary_amendments_to_components.sql",
"r",
encoding="utf-8",
) as sql_file:
application_sql = sql_file.read()
while True:
cursor.execute(
f"""{application_sql}
WHERE aba.oats_component_id > {last_component_id} ORDER BY aba.oats_component_id;"""
)

rows = cursor.fetchmany(batch_size)

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

_insert_records(conn, cursor, rows)

successful_inserts_count = (
successful_inserts_count + records_to_be_inserted_count
)

last_record = dict(rows[-1])
last_component_id = last_record["oats_component_id"]

logger.debug(
f"retrieved/updated items count: {records_to_be_inserted_count}; total successfully insert applications boundary amendments so far {successful_inserts_count}; last updated {last_component_id}"
)
except Exception as err:
logger.exception(err)
conn.rollback()
failed_inserts_count = count_total - successful_inserts_count
last_component_id = last_component_id + 1

logger.info(
f"Finished {etl_name}: total amount of successful inserts {successful_inserts_count}, total failed inserts {failed_inserts_count}"
)


def _insert_records(conn, cursor, rows):
number_of_rows_to_insert = len(rows)

if number_of_rows_to_insert > 0:
insert_query = _compile_insert_query(number_of_rows_to_insert)
rows_to_insert = _prepare_data_to_insert(rows)
cursor.execute(insert_query, rows_to_insert)
conn.commit()


def _compile_insert_query(number_of_rows_to_insert):
amendments_to_insert = ",".join(["%s"] * number_of_rows_to_insert)
return f"""
INSERT INTO alcs.application_boundary_amendments_to_components(
application_boundary_amendment_uuid,
application_decision_component_uuid
)
VALUES{amendments_to_insert}
ON CONFLICT DO NOTHING;
"""


def _prepare_data_to_insert(rows):
row_without_last_element = []
for row in rows:
mapped_row = _map_data(row)
row_without_last_element.append(tuple(mapped_row.values()))

return row_without_last_element


def _map_data(row):
return {
"application_boundary_amendment_uuid": row["boundary_uuid"],
"application_decision_component_uuid": row["component_uuid"],
}


@inject_conn_pool
def clean_linked_boundary_amendments(conn=None):
logger.info("Start application boundary amendment link cleaning")
with conn.cursor() as cursor:
cursor.execute(
f"DELETE FROM alcs.application_boundary_amendments_to_components aba"
)
logger.info(f"Deleted items count = {cursor.rowcount}")
conn.commit()
logger.info("Done application boundary amendment link cleaning")
9 changes: 8 additions & 1 deletion bin/migrate-oats-data/applications/post_launch/clean.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
from .application_components.boundary_amendments import (
clean_boundary_amendments,
clean_linked_boundary_amendments,
)


def clean_alcs_applications():
return
clean_linked_boundary_amendments()
clean_boundary_amendments()
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from .application_components.boundary_amendments import (
insert_application_boundary_amendments,
link_application_boundary_amendments,
)


def process_application_etl(batch_size):
# nothing
return
insert_application_boundary_amendments(batch_size)
link_application_boundary_amendments(batch_size)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SELECT
a.file_number,
adc.alr_area,
adc.application_decision_component_type_code,
oaac.amendment_year,
oaac.amendment_period,
oaac.alr_appl_component_id
FROM
oats.oats_alr_appl_components oaac
JOIN alcs.application_decision_component adc ON oaac.alr_appl_component_id = adc.oats_alr_appl_component_id
JOIN alcs.application_decision ad ON adc.application_decision_uuid = ad."uuid"
JOIN alcs.application a ON ad.application_uuid = a."uuid"
WHERE
oaac.amendment_year IS NOT NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT
count(*)
FROM
oats.oats_alr_appl_components oaac
JOIN alcs.application_decision_component adc ON oaac.alr_appl_component_id = adc.oats_alr_appl_component_id
JOIN alcs.application_decision ad ON adc.application_decision_uuid = ad."uuid"
JOIN alcs.application a ON ad.application_uuid = a."uuid"
WHERE
oaac.amendment_year IS NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT
aba."uuid" AS boundary_uuid,
adc."uuid" AS component_uuid,
aba.oats_component_id
FROM
alcs.application_boundary_amendment aba
JOIN alcs.application_decision_component adc ON aba.oats_component_id = adc.oats_alr_appl_component_id
Loading

0 comments on commit 9424d3d

Please sign in to comment.