Skip to content

Commit

Permalink
MR feedback pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
lstod committed Mar 6, 2024
1 parent 4a92e35 commit d09e0e4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@ def _compile_insert_query(number_of_rows_to_insert):
visibility_flags,
oats_document_id,
oats_application_id,
audit_created_by
audit_created_by,
survey_plan_number,
control_number
)
VALUES{documents_to_insert}
ON CONFLICT (oats_document_id, oats_application_id) DO UPDATE SET
notification_uuid = EXCLUDED.notification_uuid,
document_uuid = EXCLUDED.document_uuid,
type_code = EXCLUDED.type_code,
visibility_flags = EXCLUDED.visibility_flags,
audit_created_by = EXCLUDED.audit_created_by;
audit_created_by = EXCLUDED.audit_created_by,
survey_plan_number = EXCLUDED.survey_plan_number,
control_number = EXCLUDED.control_number;
"""


Expand All @@ -124,6 +128,8 @@ def _map_data(row):
"oats_document_id": row["oats_document_id"],
"oats_application_id": row["oats_application_id"],
"audit_created_by": OATS_ETL_USER,
"plan_number": row["plan_no"],
"control_number": row["control_no"],
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
from db import inject_conn_pool
from psycopg2.extras import RealDictCursor
import os

etl_name = "import_srw_documents_from_oats"
logger = setup_and_get_logger(etl_name)
Expand Down Expand Up @@ -132,7 +133,7 @@ def _map_data(row):
"oats_application_id": row["oats_application_id"],
"audit_created_by": OATS_ETL_USER,
"file_key": row["file_key"],
"mime_type": row["mime_type"],
"mime_type": _get_mime_type(row),
"tags": row["tags"],
"system": _map_system(row),
"file_upload_date": _get_upload_date(row),
Expand Down Expand Up @@ -166,6 +167,15 @@ def _get_document_source(data):
return source


def _get_mime_type(data):
file_name = data.get("file_name", "")
extension = os.path.splitext(file_name)[-1].lower().strip()
if extension == ".pdf":
return "application/pdf"
else:
return "application/octet-stream"


@inject_conn_pool
def document_clean(conn=None):
logger.info("Start documents cleaning")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ with oats_documents_to_map as (
publicly_viewable_ind as is_public,
app_lg_viewable_ind as is_app_lg,
od.document_id as oats_document_id,
od.alr_application_id as oats_application_id
od.alr_application_id as oats_application_id,
oaa.plan_no,
oaa.control_no
from oats.oats_documents od
join alcs."document" d on d.oats_document_id = od.document_id::text
join alcs.document_code adc on adc.oats_code = od.document_code
join alcs.notification n on n.file_number = od.alr_application_id::text
JOIN oats.oats_alr_applications oaa ON od.alr_application_id = oaa.alr_application_id
)
select otm.notification_uuid,
otm.document_uuid,
Expand All @@ -25,5 +28,6 @@ select otm.notification_uuid,
) as visibility_flags,
oats_document_id,
oats_application_id,
'oats_etl' as audit_created_by
plan_no,
control_no
from oats_documents_to_map otm

0 comments on commit d09e0e4

Please sign in to comment.