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

Feature/alcs 1132 etl and search bonus #980

Merged
merged 5 commits into from
Sep 18, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions bin/migrate-oats-data/applications/app_prep.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from common import (
ALRChangeCode,
AlcsNfuTypeCode,
AlcsNfuSubTypeCode,
OatsCapabilitySourceCode,
OatsAgriCapabilityCodes,
OATS_NFU_SUBTYPES,
AlcsAgCap,
AlcsAgCapSource,
Expand Down Expand Up @@ -47,12 +44,14 @@ class OatsToAlcsAgCap(Enum):
S = AlcsAgCap.Secondary.value
U = AlcsAgCap.Unclassified.value


class OatsLegislationCodes(Enum):
SEC_30_1 = AlcsApplicantType.Land_owner.value
SEC_29_1 = AlcsApplicantType.LFNG.value
SEC_17_3 = AlcsApplicantType.Land_owner.value
SEC_17_1 = AlcsApplicantType.LFNG.value


@inject_conn_pool
def process_alcs_application_prep_fields(conn=None, batch_size=BATCH_UPLOAD_SIZE):
"""
Expand Down Expand Up @@ -242,15 +241,16 @@ def mapOatsToAlcsAppPrep(data):

return data

def mapOatsToAlcsLegislationCode(data):

def mapOatsToAlcsLegislationCode(data):
if data["legislation_code"]:
data["legislation_code"] = str(
OatsLegislationCodes[data["legislation_code"]].value
)

return data


def get_update_query(unique_fields):
# unique_fields takes input from called function and appends to query
query = """
Expand All @@ -271,13 +271,15 @@ def get_update_query(unique_fields):
"""
return query.format(unique_fields=unique_fields)


def get_update_query_for_nfu():
unique_fields = """,
nfu_use_type = %(nonfarm_use_type_code)s,
nfu_use_sub_type = %(nonfarm_use_subtype_code)s,
proposal_end_date = %(nonfarm_use_end_date)s"""
return get_update_query(unique_fields)


def get_update_query_for_nar():
# naruSubtype is a part of submission, import there
unique_fields = """,
Expand Down Expand Up @@ -305,6 +307,7 @@ def get_update_query_for_other():
unique_fields = """"""
return get_update_query(unique_fields)


def map_oats_to_alcs_nfu_subtypes(nfu_type_code, nfu_subtype_code):
for dict_obj in OATS_NFU_SUBTYPES:
if str(dict_obj["type_key"]) == str(nfu_type_code) and str(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .submission_status_email import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from db import inject_conn_pool
import traceback
from common import OATS_ETL_USER


@inject_conn_pool
def process_application_submission_status_emails(conn=None):
update_query = f"""
UPDATE alcs.application_submission_to_submission_status status
SET email_sent_date = '0001-01-01 07:00:00.000 -0700'
FROM alcs.application_submission app_sub
WHERE status.submission_uuid = app_sub.uuid
AND app_sub.audit_created_by = '{OATS_ETL_USER}'
"""

try:
with conn.cursor() as cursor:
cursor.execute(update_query)
except Exception as error:
print("".join(traceback.format_exception(None, error, error.__traceback__)))
cursor.close()
conn.close()


@inject_conn_pool
def clean_notice_of_intent_submission_status_emails(conn=None):
update_query = f"""
UPDATE alcs.application_submission_to_submission_status status
SET email_sent_date = NULL
FROM alcs.application_submission app_sub
WHERE status.submission_uuid = app_sub.uuid
AND app_sub.audit_created_by = '{OATS_ETL_USER}'
"""
try:
with conn.cursor() as cursor:
cursor.execute(update_query)
except Exception as error:
print("".join(traceback.format_exception(None, error, error.__traceback__)))
cursor.close()
conn.close()
1 change: 1 addition & 0 deletions bin/migrate-oats-data/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .oats_application_code_values import *
from .alcs_application_enum import *
from .etl_logger import log_start, log_end
from .constants import *
1 change: 1 addition & 0 deletions bin/migrate-oats-data/common/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OATS_ETL_USER = "oats_etl"
25 changes: 23 additions & 2 deletions bin/migrate-oats-data/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@
process_nois,
clean_nois,
)
from submissions import(
from submissions import (
process_alcs_app_submissions,
clean_application_submission,
)
from constants import BATCH_UPLOAD_SIZE

from applications.application_submission_status_email import (
process_application_submission_status_emails,
clean_notice_of_intent_submission_status_emails,
)
from noi.noi_submission_status_email import (
process_notice_of_intent_submission_status_emails,
clean_application_submission_status_emails,
)

import_batch_size = BATCH_UPLOAD_SIZE

# TODO tidy import menu setup
Expand Down Expand Up @@ -60,6 +69,7 @@ def document_import_command_parser(import_batch_size, subparsers):
)
document_import_command.set_defaults(func=process_documents)


def document_noi_import_command_parser(import_batch_size, subparsers):
document_noi_import_command = subparsers.add_parser(
"document-noi-import",
Expand Down Expand Up @@ -89,6 +99,7 @@ def application_document_import_command_parser(import_batch_size, subparsers):
)
application_document_import_command.set_defaults(func=import_batch_size)


def noi_document_import_command_parser(import_batch_size, subparsers):
noi_document_import_command = subparsers.add_parser(
"noi-document-import",
Expand Down Expand Up @@ -118,6 +129,7 @@ def app_prep_import_command_parser(import_batch_size, subparsers):
)
app_prep_import_command.set_defaults(func=import_batch_size)


def noi_import_command_parser(import_batch_size, subparsers):
noi_import_command = subparsers.add_parser(
"noi-import",
Expand All @@ -132,6 +144,7 @@ def noi_import_command_parser(import_batch_size, subparsers):
)
noi_import_command.set_defaults(func=import_batch_size)


def import_command_parser(subparsers):
import_command = subparsers.add_parser(
"import",
Expand All @@ -146,6 +159,7 @@ def import_command_parser(subparsers):
)
import_command.set_defaults(func=import_batch_size)


def app_sub_import_command_parser(import_batch_size, subparsers):
app_sub_import_command = subparsers.add_parser(
"app-sub-import",
Expand Down Expand Up @@ -218,7 +232,7 @@ def setup_menu_args_parser(import_batch_size):
process_documents(batch_size=import_batch_size)

console.log("Processing NOI specific documents:")
process_documents_noi(batch_size=import_batch_size)
process_documents_noi(batch_size=import_batch_size)

console.log("Processing application documents:")
process_application_documents(batch_size=import_batch_size)
Expand All @@ -232,6 +246,11 @@ def setup_menu_args_parser(import_batch_size):
console.log("Processing application submission:")
process_alcs_app_submissions(batch_size=import_batch_size)

# NOTE: both process_application_submission_status_emails(), process_notice_of_intent_submission_status_emails()
# must be the last ones in the migrate etl
console.log("Processing submission status emails")
process_application_submission_status_emails()
process_notice_of_intent_submission_status_emails()
console.log("Done")
case "clean":
with console.status("[bold green]Cleaning previous ETL...") as status:
Expand All @@ -244,6 +263,8 @@ def setup_menu_args_parser(import_batch_size):
clean_application_submission()
clean_applications()
clean_nois()
clean_notice_of_intent_submission_status_emails(),
clean_notice_of_intent_submission_status_emails(),

console.log("Done")
case "document-import":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .submission_status_email import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from db import inject_conn_pool
import traceback
from common import OATS_ETL_USER


@inject_conn_pool
def process_notice_of_intent_submission_status_emails(conn=None):
update_query = f"""
UPDATE alcs.notice_of_intent_submission_to_submission_status status
SET email_sent_date = '0001-01-01 07:00:00.000 -0700'
FROM alcs.notice_of_intent_submission noi_sub
WHERE status.submission_uuid = noi_sub.uuid
AND noi_sub.audit_created_by = '{OATS_ETL_USER}'
"""

try:
with conn.cursor() as cursor:
cursor.execute(update_query)
except Exception as error:
print("".join(traceback.format_exception(None, error, error.__traceback__)))
cursor.close()
conn.close()


@inject_conn_pool
def clean_application_submission_status_emails(conn=None):
update_query = f"""
UPDATE alcs.notice_of_intent_submission_to_submission_status status
SET email_sent_date = NULL
FROM alcs.notice_of_intent_submission noi_sub
WHERE status.submission_uuid = noi_sub.uuid
AND noi_sub.audit_created_by = '{OATS_ETL_USER}'
"""
try:
with conn.cursor() as cursor:
cursor.execute(update_query)
except Exception as error:
print("".join(traceback.format_exception(None, error, error.__traceback__)))
cursor.close()
conn.close()
1 change: 0 additions & 1 deletion services/apps/alcs/src/alcs/search/search.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export class PagingRequestDto {
export class SearchRequestDto extends PagingRequestDto {
@IsString()
@IsOptional()
@MinLength(3)
fileNumber?: string;

@IsString()
Expand Down