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

2024 10 02 addcheck mandatory fk owner fk_operator fk_dataowner fk_provider fix missing references #163

Merged
merged 70 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
715e199
add new check def check_fk_owner_null()
sjib Oct 3, 2024
43adf7d
def check_fk_operator_null
sjib Oct 3, 2024
c6f5220
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2024
037eaba
check_fk_dataowner
sjib Oct 3, 2024
4432a46
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 3, 2024
8702b5c
check_fk_provider
sjib Oct 3, 2024
fe4fbbf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2024
273ff72
add check_fk_owner_null
sjib Oct 3, 2024
259a230
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 3, 2024
094bdb4
add check_fk_operator_null
sjib Oct 3, 2024
e7dfea9
add check_fk_dataowner_null
sjib Oct 3, 2024
ac9bc33
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 3, 2024
a35dd9a
correction
sjib Oct 3, 2024
399fef5
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 3, 2024
47c728b
add if flag_test:
sjib Oct 3, 2024
f1670be
add new functions
sjib Oct 4, 2024
284c8dd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
6b25d3f
take out time.sleep
sjib Oct 4, 2024
71559b9
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
f4c06ce
take out time.sleep
sjib Oct 4, 2024
6effa7e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
5e18a10
correct wrong select statements
sjib Oct 4, 2024
95ba722
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
b1b6f7a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
3b0159b
correct wrong variable names
sjib Oct 4, 2024
7926e28
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
c5bb4b6
correct select statement
sjib Oct 4, 2024
d97d102
correct wrong else statment / testing
sjib Oct 4, 2024
501da3f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
86ed2c9
adapt corrections to all fk checks
sjib Oct 4, 2024
39103f7
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
98dcf98
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
ec0ed08
make check_fk_operator and fk_owner mandatory, else we will get error…
sjib Oct 4, 2024
d20d706
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
cb96bc9
adapt messages to ERROR
sjib Oct 4, 2024
defeda5
adapt error message to be failure
sjib Oct 4, 2024
4bcd24c
fix check_fk_in_subsetid
sjib Oct 4, 2024
5929a6a
fix check_fk_in_subsetid in qgepdss export
sjib Oct 4, 2024
39ded51
fix check_fk_in_subsetid for qgep export
sjib Oct 4, 2024
2b9dbb2
def get_wwtp_structure_ids()
sjib Oct 4, 2024
095f185
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
c55a241
add wwtp_structure_ids
sjib Oct 4, 2024
6146253
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
03c0c3c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
7fc2ddf
from ..utils.ili2db import get_wwtp_structure_ids
sjib Oct 4, 2024
ee5f166
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
18db506
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
7573aa8
wwtp_structure_ids = get_wwtp_structure_ids()
sjib Oct 4, 2024
e6ac9db
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
3fd608b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
243b946
wwtp_structure_ids = get_wwtp_structure_ids() 2nd try
sjib Oct 4, 2024
ecd82b4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
1e9b411
correct wwtp_strucuture to wwtp_structure
sjib Oct 4, 2024
2d5523b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
bb69b21
adapt get_wwtp_structure_ids():
sjib Oct 4, 2024
b509c7a
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
1567caf
change variable name
sjib Oct 4, 2024
790c79c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
28a27fe
rename wwtp_structure_id_list to wastewater_structure_id_sia405abwass…
sjib Oct 4, 2024
5e742a5
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 4, 2024
c621112
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
9ec46e7
update qgep export.py
sjib Oct 10, 2024
924bc15
add empty lines
sjib Oct 10, 2024
071b65d
update qgepdss export.py
sjib Oct 10, 2024
b5a7677
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
56e1af4
adapte logger warning val
sjib Oct 10, 2024
9b70690
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 10, 2024
9c2d502
fix flake8
ponceta Oct 10, 2024
a29eb3f
no f-string, as there are no placeholders
sjib Oct 10, 2024
5a11b83
Merge branch '2024-10-02-addcheck_mandatory_fk_owner_fk_provider' of …
sjib Oct 10, 2024
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
138 changes: 116 additions & 22 deletions qgepqwat2ili/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tempfile

# 12.7.2022 for testing import time
import time
import webbrowser
from types import SimpleNamespace

Expand All @@ -27,6 +26,10 @@
from ..qgepsia405.export import qgep_export as qgepsia405_export
from ..qgepsia405.import_ import qgep_import as qgepsia405_import
from ..utils.ili2db import ( # neu 22.7.2022; get_xtf_model,; neu 31.3.2023; neu 12.4.2023
check_fk_dataowner_null,
check_fk_operator_null,
check_fk_owner_null,
check_fk_provider_null,
check_identifier_null,
check_organisation_subclass_data,
check_wastewater_structure_subclass_data,
Expand Down Expand Up @@ -98,7 +101,7 @@ def action_do_importc():
progress_dialog.show()
progress_dialog.setLabelText("waiting...")
# delays the execution for 5.5 secs.
time.sleep(5.5)
# time.sleep(5.5)
progress_dialog.close
# end action_do_importc

Expand Down Expand Up @@ -356,7 +359,7 @@ def action_import(plugin):
# 31.5.2024 should not be needed anymore
# progress_dialog.setLabelText("Set main_cover manually after import if vw_qgep_wastewater_structure does not display correctly!")

time.sleep(2)
# time.sleep(2)
# to add option to run main_cover.sql manually - see postimport.py

# 24.7.2022 / moved to end
Expand Down Expand Up @@ -462,26 +465,117 @@ def action_do_export():
return

# 3. identifier check check_identifier_null
check_identifier = False
check_identifier = check_identifier_null()
if check_identifier:
print("OK: Integrity checks identifiers not isNull")
show_success(
"Sucess",
"OK: Integrity checks identifiers not isNull",
None,
)
if flag_test:
check_identifier = False
check_identifier = check_identifier_null()
if check_identifier:
print("OK: Integrity checks identifiers not isNull")
show_success(
"Sucess",
"OK: Integrity checks identifiers not isNull",
None,
)

else:
progress_dialog.close()
print("INFO: missing identifiers")
show_hint(
"INFO: Missing identifiers in schema qgep_od",
"Add missing identifiers to get a valid INTERLIS export file. See qgep logs tab for details.",
None,
)
# just show hint, but continue
# return
else:
progress_dialog.close()
print("INFO: missing identifiers")
show_hint(
"INFO: Missing identifiers in schema qgep_od",
"Add missing identifiers to get a valid INTERLIS export file. See qgep logs tab for details.",
None,
)
# just show hint, but continue
# return

# 4. relation check check_fk_owner_null
if flag_test:
check_fk_owner = False
check_fk_owner = check_fk_owner_null()
if check_fk_owner:
print("OK: Integrity checks fk_owner not isNull")
show_success(
"Sucess",
"OK: Integrity checks fk_owner not isNull",
None,
)

else:
progress_dialog.close()
print("ERROR: missing MANDATORY fk_owner")
show_failure(
"ERROR: Missing MANDATORY fk_owner in schema qgep_od",
"Add missing MANDATORY fk_owner to get a valid INTERLIS export file. See qgep logs tab for details.",
None,
)
# make mandatory
return

# 5. relation check check_fk_operator_null
check_fk_operator = False
check_fk_operator = check_fk_operator_null()
if check_fk_operator:
print("OK: Integrity checks fk_operator not isNull")
show_success(
"Sucess",
"OK: Integrity checks fk_operator not isNull",
None,
)

else:
progress_dialog.close()
print("ERROR: missing MANDATORY fk_operator")
show_failure(
"ERROR: Missing MANDATORY fk_operator in schema qgep_od",
"Add missing MANDATORY fk_operator to get a valid INTERLIS export file. See qgep logs tab for details.",
None,
)
# make mandatory
return

# 6. relation check check_fk_dataowner_null
if flag_test:
check_fk_dataowner = False
check_fk_dataowner = check_fk_dataowner_null()
if check_fk_dataowner:
print("OK: Integrity checks fk_dataowner not isNull")
show_success(
"Sucess",
"OK: Integrity checks fk_dataowner not isNull",
None,
)

else:
progress_dialog.close()
print("INFO: missing fk_dataowner")
show_hint(
"INFO: Missing fk_dataowner in schema qgep_od",
"Add missing fk_dataowner to get a valid INTERLIS export file when converting to Release 2020 (will bei MANDATORY). See qgep logs tab for details.",
None,
)
# just show hint, but continue
# return

# 6. relation check check_fk_provider_null
check_fk_provider = False
check_fk_provider = check_fk_provider_null()
if check_fk_provider:
print("OK: Integrity checks fk_provider not isNull")
show_success(
"Sucess",
"OK: Integrity checks fk_provider not isNull",
None,
)

else:
progress_dialog.close()
print("INFO: missing fk_provider")
show_hint(
"INFO: Missing fk_provider in schema qgep_od",
"Add missing fk_provider to get a valid INTERLIS export file when converting to Release 2020 (will bei MANDATORY). See qgep logs tab for details.",
None,
)
# just show hint, but continue
# return

# Prepare the temporary ili2pg model
progress_dialog.setLabelText("Creating ili schema..." + emodel)
Expand Down
32 changes: 26 additions & 6 deletions qgepqwat2ili/qgep/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from sqlalchemy.sql import text

from .. import utils

# 4.10.2024
from ..utils.ili2db import skip_wwtp_structure_ids
from ..utils.various import logger
from .model_abwasser import get_abwasser_model
from .model_qgep import get_qgep_model
Expand Down Expand Up @@ -36,6 +39,15 @@ def qgep_export(selection=None, labels_file=None, orientation=None):
filtered = selection is not None
subset_ids = selection if selection is not None else []

# get list of id's of class wwtp_structure (ARABauwerk) to be able to check if fk_wastewater_structure references to wwtp_structure

wastewater_structure_id_sia405abwasser_list = None
wastewater_structure_id_sia405abwasser_list = skip_wwtp_structure_ids()

logger.info(
f"wastewater_structure_id_sia405abwasser_list : {wastewater_structure_id_sia405abwasser_list}",
)

# Orientation
oriented = orientation is not None
if oriented:
Expand Down Expand Up @@ -90,7 +102,9 @@ def truncate(val, max_length):
if val is None:
return None
if len(val) > max_length:
logger.warning(f"Value '{val}' exceeds expected length ({max_length})", stacklevel=2)
# _log() got an unexpected keyword argument 'stacklevel'
# logger.warning(f"Value '{val}' exceeds expected length ({max_length})", stacklevel=2)
logger.warning(f"Value '{val}' exceeds expected length ({max_length})")
return val[0:max_length]

def modulo_angle(val):
Expand Down Expand Up @@ -130,10 +144,13 @@ def check_fk_in_subsetid(subset, relation):
logger.info(f"check_fk_in_subsetid - tid = '{tid_maker.tid_for_row(relation)}' ")
return tid_maker.tid_for_row(relation)
else:
logger.info(
f"check_fk_in_subsetid - '{fremdschluesselstr}' is not in subset - replaced with None instead!"
)
return None
if filtered:
logger.info(
f"check_fk_in_subsetid - '{fremdschluesselstr}' is not in subset - replaced with None instead!"
)
return None
else:
return tid_maker.tid_for_row(relation)

def create_metaattributes(row):
metaattribute = ABWASSER.metaattribute(
Expand Down Expand Up @@ -208,7 +225,10 @@ def wastewater_networkelement_common(row):
"""

return {
"abwasserbauwerkref": get_tid(row.fk_wastewater_structure__REL),
# "abwasserbauwerkref": get_tid(row.fk_wastewater_structure__REL),
"abwasserbauwerkref": check_fk_in_subsetid(
wastewater_structure_id_sia405abwasser_list, row.fk_wastewater_structure__REL
),
"bemerkung": truncate(emptystr_to_null(row.remark), 80),
"bezeichnung": null_to_emptystr(row.identifier),
}
Expand Down
23 changes: 19 additions & 4 deletions qgepqwat2ili/qgepdss/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from sqlalchemy.sql import text

from .. import utils

# 4.10.2024
from ..utils.ili2db import skip_wwtp_structure_ids
from ..utils.various import logger
from .model_abwasser import get_abwasser_model
from .model_qgep import get_qgep_model
Expand Down Expand Up @@ -43,6 +46,15 @@ def qgep_export(selection=None, labels_file=None, orientation=None):
# Logging for debugging
logger.info(f"print subset_ids '{subset_ids}'")

# get list of id's of class wwtp_structure (ARABauwerk) to be able to check if fk_wastewater_structure references to wwtp_structure

wastewater_structure_id_sia405abwasser_list = None
wastewater_structure_id_sia405abwasser_list = skip_wwtp_structure_ids()

logger.info(
f"wastewater_structure_id_sia405abwasser_list : {wastewater_structure_id_sia405abwasser_list}",
)

# Orientation
oriented = orientation is not None
if oriented:
Expand Down Expand Up @@ -140,10 +152,13 @@ def check_fk_in_subsetid(subset, relation):
logger.info(f"check_fk_in_subsetid - tid = '{tid_maker.tid_for_row(relation)}' ")
return tid_maker.tid_for_row(relation)
else:
logger.info(
f"check_fk_in_subsetid - '{fremdschluesselstr}' is not in subset - replaced with None instead!"
)
return None
if filtered:
logger.info(
f"check_fk_in_subsetid - '{fremdschluesselstr}' is not in subset - replaced with None instead!"
)
return None
else:
return tid_maker.tid_for_row(relation)

def create_metaattributes(row):
metaattribute = ABWASSER.metaattribute(
Expand Down
33 changes: 27 additions & 6 deletions qgepqwat2ili/qgepsia405/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from sqlalchemy.sql import text

from .. import utils

# 4.10.2024
from ..utils.ili2db import skip_wwtp_structure_ids
from ..utils.various import logger
from .model_abwasser import get_abwasser_model
from .model_qgep import get_qgep_model
Expand Down Expand Up @@ -36,6 +39,15 @@ def qgep_export(selection=None, labels_file=None, orientation=None):
filtered = selection is not None
subset_ids = selection if selection is not None else []

# get list of id's of class wwtp_structure (ARABauwerk) to be able to check if fk_wastewater_structure references to wwtp_structure

wastewater_structure_id_sia405abwasser_list = None
wastewater_structure_id_sia405abwasser_list = skip_wwtp_structure_ids()

logger.info(
f"wastewater_structure_id_sia405abwasser_list : {wastewater_structure_id_sia405abwasser_list}",
)

# Orientation
oriented = orientation is not None
if oriented:
Expand All @@ -49,6 +61,7 @@ def get_tid(relation):
"""
if relation is None:
return None

return tid_maker.tid_for_row(relation)

def get_vl(relation):
Expand Down Expand Up @@ -90,7 +103,9 @@ def truncate(val, max_length):
if val is None:
return None
if len(val) > max_length:
logger.warning(f"Value '{val}' exceeds expected length ({max_length})", stacklevel=2)
# _log() got an unexpected keyword argument 'stacklevel'
# logger.warning(f"Value '{val}' exceeds expected length ({max_length})", stacklevel=2)
logger.warning(f"Value '{val}' exceeds expected length ({max_length})")
return val[0:max_length]

def modulo_angle(val):
Expand Down Expand Up @@ -130,10 +145,13 @@ def check_fk_in_subsetid(subset, relation):
logger.info(f"check_fk_in_subsetid - tid = '{tid_maker.tid_for_row(relation)}' ")
return tid_maker.tid_for_row(relation)
else:
logger.info(
f"check_fk_in_subsetid - '{fremdschluesselstr}' is not in subset - replaced with None instead!"
)
return None
if filtered:
logger.info(
f"check_fk_in_subsetid - '{fremdschluesselstr}' is not in subset - replaced with None instead!"
)
return None
else:
return tid_maker.tid_for_row(relation)

def create_metaattributes(row):
metaattribute = ABWASSER.metaattribute(
Expand Down Expand Up @@ -205,7 +223,10 @@ def wastewater_networkelement_common(row):
"""

return {
"abwasserbauwerkref": get_tid(row.fk_wastewater_structure__REL),
# "abwasserbauwerkref": get_tid(row.fk_wastewater_structure__REL),
"abwasserbauwerkref": check_fk_in_subsetid(
wastewater_structure_id_sia405abwasser_list, row.fk_wastewater_structure__REL
),
"bemerkung": truncate(emptystr_to_null(row.remark), 80),
"bezeichnung": null_to_emptystr(row.identifier),
}
Expand Down
Loading