From 00381ebba85d70a6a149fd9c25b606a7a69f9415 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Thu, 2 Nov 2023 12:11:11 +0100 Subject: [PATCH 1/9] PAGOPA-1239 fixing iban due_date and iban master description --- .../utils/pythonExportIban/exporterIbanMasterToCsv.py | 10 +++++++++- scripts/utils/pythonExportIban/exporterIbanToCsv.py | 2 +- scripts/utils/pythonExportIban/exportingIbanToDB.py | 2 +- scripts/utils/pythonExportIban/populate_tables.sh | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py b/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py index 40001816f..99e41e75d 100644 --- a/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py @@ -1,8 +1,15 @@ import csv import os +import sys import oracledb +dictDescriptionIbanPa = {} +with open(sys.argv[1]) as csv_file: + csv_reader = csv.reader(csv_file, delimiter=';') + for row in csv_reader: + dictDescriptionIbanPa.update({(row[1], row[3]): row[7]}) + connection = oracledb.connect( dsn=os.environ['SPRING_DATASOURCE_HOST'], port=os.environ['SPRING_DATASOURCE_PORT'], @@ -20,7 +27,8 @@ result_set = cursor.fetchall() if(result_set == ''): print(f"Problem with {row[1]}") - rowToWrite = [row[4], result_set[0][0], row[1], "ENABLED", row[2], row[3]] + continue + rowToWrite = [dictDescriptionIbanPa.get((result_set[0][0], row[1])), result_set[0][0], row[1], "ENABLED", row[2], row[3]] csvwriter.writerow(rowToWrite) cursor.close() diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index 95fd2e8ec..fa028f0c1 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -31,6 +31,6 @@ d = datetime.strptime(thisdictDate.get(row[2]), "%Y-%m-%d %H:%M:%S") new_date = d.strftime("%Y-%m-%d %H:%M:%S") if(thisdictPa.get(row[2]) != None): - rowToWrite = [row[2], thisdictPa.get(row[2]), row[0], new_date] + rowToWrite = [row[2], thisdictPa.get(row[2]), row[0]] thisdictPa.pop(row[2], None) csvwriter.writerow(rowToWrite) diff --git a/scripts/utils/pythonExportIban/exportingIbanToDB.py b/scripts/utils/pythonExportIban/exportingIbanToDB.py index 751b028a5..9d1b5a1a6 100644 --- a/scripts/utils/pythonExportIban/exportingIbanToDB.py +++ b/scripts/utils/pythonExportIban/exportingIbanToDB.py @@ -15,7 +15,7 @@ data = list(csv.reader(csv_file)) cursor.executemany(""" INSERT INTO NODO4_CFG.IBAN (IBAN, FISCAL_CODE, DESCRIPTION, DUE_DATE) - VALUES (:1, :2, :3, to_timestamp(:4,'YYYY-MM-DD HH24:MI:SS.FF6'))""", data) + VALUES (:1, :2, :3, ADD_MONTHS(CURRENT_TIMESTAMP, 12))""", data) connection.commit() cursor.close() connection.close() diff --git a/scripts/utils/pythonExportIban/populate_tables.sh b/scripts/utils/pythonExportIban/populate_tables.sh index 1e36542f5..c822b12f2 100755 --- a/scripts/utils/pythonExportIban/populate_tables.sh +++ b/scripts/utils/pythonExportIban/populate_tables.sh @@ -16,7 +16,7 @@ sed -i "s/[']//g" ./IbanCsv/IbanView.csv echo "All ' eliminated" -python3 exporterIbanMasterToCsv.py +python3 exporterIbanMasterToCsv.py $PDA_CSV_FILE python3 exporterIbanToCsv.py From 62bf7393b20bdd86aa939a824700655ce670d332 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:37:11 +0100 Subject: [PATCH 2/9] PAGOPA-1239 changing description source abd status --- .../exporterIbanMasterToCsv.py | 6 ++++-- .../pythonExportIban/exporterIbanToCsv.py | 21 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py b/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py index 99e41e75d..2f7e07618 100644 --- a/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py @@ -23,12 +23,14 @@ csvwriter = csv.writer(result, delimiter=',') # Process data rows for row in csvreader: - cursor.execute(f"Select id_dominio from NODO4_CFG.pa where obj_id={row[0]}") + cursor.execute(""" + Select id_dominio from NODO4_CFG.pa where obj_id=:obj_id + """, obj_id=row[0]) result_set = cursor.fetchall() if(result_set == ''): print(f"Problem with {row[1]}") continue - rowToWrite = [dictDescriptionIbanPa.get((result_set[0][0], row[1])), result_set[0][0], row[1], "ENABLED", row[2], row[3]] + rowToWrite = [dictDescriptionIbanPa.get((result_set[0][0], row[1])), result_set[0][0], row[1], "N/A", row[2], row[3]] csvwriter.writerow(rowToWrite) cursor.close() diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index fa028f0c1..f2ddf6e38 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -20,17 +20,28 @@ thisdictDate.update({row[2]: row[4]}) thisdictPa.update({row[2]: row[1]}) +connection = oracledb.connect( + dsn=os.environ['SPRING_DATASOURCE_HOST'], + port=os.environ['SPRING_DATASOURCE_PORT'], + user=os.environ['SPRING_DATASOURCE_USERNAME'], + password=os.environ['SPRING_DATASOURCE_PASSWORD'] +) +cursor = connection.cursor() + with open('./IbanCsv/Iban_Master_output.csv', 'r', newline='') as source, open('./IbanCsv/Iban_output.csv', 'w', newline='') as result: csvreader = csv.reader(source, delimiter=',') csvwriter = csv.writer(result, delimiter=',') # Process data rows for row in csvreader: - new_date = '' - if(row[4] != ''): - d = datetime.strptime(thisdictDate.get(row[2]), "%Y-%m-%d %H:%M:%S") - new_date = d.strftime("%Y-%m-%d %H:%M:%S") if(thisdictPa.get(row[2]) != None): - rowToWrite = [row[2], thisdictPa.get(row[2]), row[0]] + cursor.execute(""" + Select descrizione from NODO4_CFG.pa where id_dominio=:id_dominio + """, id_dominio=row[1]) + result_set = cursor.fetchall() + rowToWrite = [row[2], thisdictPa.get(row[2]), result_set[0][0]] thisdictPa.pop(row[2], None) csvwriter.writerow(rowToWrite) + +cursor.close() +connection.close() From fa986a4351031c8479489186dbc950a5ddcb1513 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:40:15 +0100 Subject: [PATCH 3/9] PAGOPA-1239 adding import --- scripts/utils/pythonExportIban/exporterIbanToCsv.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index f2ddf6e38..3c7ad2fea 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -1,6 +1,8 @@ import csv from datetime import datetime +import oracledb + thisdictDate = {} thisdictPa = {} entries = [] From e2469cde0a282f4b99af4aa123c72a270ebb7b40 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:40:53 +0100 Subject: [PATCH 4/9] PAGOPA-1239 adding import --- scripts/utils/pythonExportIban/exporterIbanToCsv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index 3c7ad2fea..67679517b 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -1,6 +1,6 @@ import csv from datetime import datetime - +import os import oracledb thisdictDate = {} From d89221b7aab8c10f4585a676402feb5a33a96773 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:17:31 +0100 Subject: [PATCH 5/9] PAGOPA-1239 refactoring ragione sociale --- .../pythonExportIban/exporterIbanMasterToCsv.py | 2 +- .../utils/pythonExportIban/exporterIbanToCsv.py | 15 +-------------- .../pythonExportIban/exportingIbanMastertoDB.py | 7 ++++--- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py b/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py index 2f7e07618..9967a3382 100644 --- a/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanMasterToCsv.py @@ -30,7 +30,7 @@ if(result_set == ''): print(f"Problem with {row[1]}") continue - rowToWrite = [dictDescriptionIbanPa.get((result_set[0][0], row[1])), result_set[0][0], row[1], "N/A", row[2], row[3]] + rowToWrite = [dictDescriptionIbanPa.get((result_set[0][0], row[1])), result_set[0][0], row[1], "N/A", row[2], row[3], row[4]] csvwriter.writerow(rowToWrite) cursor.close() diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index 67679517b..c624d7710 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -1,7 +1,5 @@ import csv from datetime import datetime -import os -import oracledb thisdictDate = {} thisdictPa = {} @@ -22,13 +20,6 @@ thisdictDate.update({row[2]: row[4]}) thisdictPa.update({row[2]: row[1]}) -connection = oracledb.connect( - dsn=os.environ['SPRING_DATASOURCE_HOST'], - port=os.environ['SPRING_DATASOURCE_PORT'], - user=os.environ['SPRING_DATASOURCE_USERNAME'], - password=os.environ['SPRING_DATASOURCE_PASSWORD'] -) -cursor = connection.cursor() with open('./IbanCsv/Iban_Master_output.csv', 'r', newline='') as source, open('./IbanCsv/Iban_output.csv', 'w', newline='') as result: csvreader = csv.reader(source, delimiter=',') @@ -37,11 +28,7 @@ # Process data rows for row in csvreader: if(thisdictPa.get(row[2]) != None): - cursor.execute(""" - Select descrizione from NODO4_CFG.pa where id_dominio=:id_dominio - """, id_dominio=row[1]) - result_set = cursor.fetchall() - rowToWrite = [row[2], thisdictPa.get(row[2]), result_set[0][0]] + rowToWrite = [row[2], thisdictPa.get(row[2]), row[6]] thisdictPa.pop(row[2], None) csvwriter.writerow(rowToWrite) diff --git a/scripts/utils/pythonExportIban/exportingIbanMastertoDB.py b/scripts/utils/pythonExportIban/exportingIbanMastertoDB.py index 2ee93c730..3639aecde 100644 --- a/scripts/utils/pythonExportIban/exportingIbanMastertoDB.py +++ b/scripts/utils/pythonExportIban/exportingIbanMastertoDB.py @@ -1,6 +1,6 @@ import csv import os - +import numpy as np import oracledb connection = oracledb.connect( @@ -12,10 +12,11 @@ cursor = connection.cursor() data = [] with open('./IbanCsv/Iban_Master_output.csv') as csv_file: - data = list(csv.reader(csv_file)) + data = np.array(list(csv.reader(csv_file))) +data_slice = data[:, :6] cursor.executemany(""" INSERT INTO NODO4_CFG.iban_master (description, fk_pa, fk_iban, state, validity_date, inserted_date) - VALUES (:1, (Select obj_id from NODO4_CFG.pa where id_dominio = :2), (Select obj_id from NODO4_CFG.iban where iban = :3), :4,to_timestamp(:5,'YYYY-MM-DD HH24:MI:SS'), to_timestamp(:6,'YYYY-MM-DD HH24:MI:SS'))""", data) + VALUES (:1, (Select obj_id from NODO4_CFG.pa where id_dominio = :2), (Select obj_id from NODO4_CFG.iban where iban = :3), :4,to_timestamp(:5,'YYYY-MM-DD HH24:MI:SS'), to_timestamp(:6,'YYYY-MM-DD HH24:MI:SS'))""", data_slice.tolist()) connection.commit() cursor.close() connection.close() From 0d51ebe28e09ffb1e8a091897b6af2be53fd146f Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:20:24 +0100 Subject: [PATCH 6/9] PAGOPA-1239 minor removal --- scripts/utils/pythonExportIban/exporterIbanToCsv.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index c624d7710..7b17090d5 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -31,6 +31,3 @@ rowToWrite = [row[2], thisdictPa.get(row[2]), row[6]] thisdictPa.pop(row[2], None) csvwriter.writerow(rowToWrite) - -cursor.close() -connection.close() From 456be599d4b6d918fe4df697505d391ee33ce5f4 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Fri, 3 Nov 2023 09:31:38 +0100 Subject: [PATCH 7/9] PAGOPA-1239 logic about one line --- scripts/utils/pythonExportIban/exporterIbanToCsv.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index 7b17090d5..0ada1cba2 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -9,16 +9,13 @@ csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 for row in csv_reader: - if line_count == 0: - line_count += 1 - else: - if(thisdictDate.get(row[2]) != None): - if(datetime.strptime(thisdictDate.get(row[2]), "%Y-%m-%d %H:%M:%S") > datetime.strptime((row[4]), "%Y-%m-%d %H:%M:%S")): - thisdictDate.update({row[2]: row[4]}) - thisdictPa.update({row[2]: row[1]}) - else: + if(thisdictDate.get(row[2]) != None): + if(datetime.strptime(thisdictDate.get(row[2]), "%Y-%m-%d %H:%M:%S") > datetime.strptime((row[4]), "%Y-%m-%d %H:%M:%S")): thisdictDate.update({row[2]: row[4]}) thisdictPa.update({row[2]: row[1]}) + else: + thisdictDate.update({row[2]: row[4]}) + thisdictPa.update({row[2]: row[1]}) with open('./IbanCsv/Iban_Master_output.csv', 'r', newline='') as source, open('./IbanCsv/Iban_output.csv', 'w', newline='') as result: From af228ed772383bbe755a3eb474a2a5a1d70ceaf1 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Fri, 3 Nov 2023 09:48:40 +0100 Subject: [PATCH 8/9] PAGOPA-1239 minor code cleaning --- scripts/utils/pythonExportIban/exporterIbanToCsv.py | 3 --- scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/utils/pythonExportIban/exporterIbanToCsv.py b/scripts/utils/pythonExportIban/exporterIbanToCsv.py index 0ada1cba2..f7ace80b0 100644 --- a/scripts/utils/pythonExportIban/exporterIbanToCsv.py +++ b/scripts/utils/pythonExportIban/exporterIbanToCsv.py @@ -3,11 +3,8 @@ thisdictDate = {} thisdictPa = {} -entries = [] -duplicate_entries = [] with open('./IbanCsv/Iban_Master_output.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') - line_count = 0 for row in csv_reader: if(thisdictDate.get(row[2]) != None): if(datetime.strptime(thisdictDate.get(row[2]), "%Y-%m-%d %H:%M:%S") > datetime.strptime((row[4]), "%Y-%m-%d %H:%M:%S")): diff --git a/scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py b/scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py index 458f9f19c..e083b03a9 100644 --- a/scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py +++ b/scripts/utils/pythonExportIban/exportingIbanAttributesToDB.py @@ -1,7 +1,5 @@ import os -import csv import oracledb -import sys connection = oracledb.connect( dsn=os.environ['SPRING_DATASOURCE_HOST'], @@ -11,7 +9,7 @@ ) cursor = connection.cursor() -cursor.execute(f"INSERT INTO NODO4_CFG.iban_attributes (ATTRIBUTE_NAME, ATTRIBUTE_DESCRIPTION) VALUES ('0201138TS', 'Canone Unico Patrimoniale - CORPORATE (0201138TS)')") +cursor.execute("INSERT INTO NODO4_CFG.iban_attributes (ATTRIBUTE_NAME, ATTRIBUTE_DESCRIPTION) VALUES ('0201138TS', 'Canone Unico Patrimoniale - CORPORATE (0201138TS)')") connection.commit() cursor.close() From 5090bf9867d1f186eba8398f8c450680610d1f02 Mon Sep 17 00:00:00 2001 From: FedericoRuzzier <49512050+FedericoRuzzier@users.noreply.github.com> Date: Fri, 3 Nov 2023 10:00:25 +0100 Subject: [PATCH 9/9] PAGOPA-1239 adding attributes in scripts --- scripts/utils/pythonExportIban/populate_tables.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/utils/pythonExportIban/populate_tables.sh b/scripts/utils/pythonExportIban/populate_tables.sh index c822b12f2..3cbc344e6 100755 --- a/scripts/utils/pythonExportIban/populate_tables.sh +++ b/scripts/utils/pythonExportIban/populate_tables.sh @@ -30,7 +30,9 @@ python3 exportingIbanMastertoDB.py echo "Populated Iban Master table" -python3 exportingIbanAttributesToDB.py $PDA_CSV_FILE +python3 exportingIbanAttributesToDB.py + +python3 exportingIbanAttributesMasterToDB.py $PDA_CSV_FILE echo "Populated Iban Attributes and Iban Attributes Master table"