@@ -30,10 +30,6 @@ def __init__(self):
30
30
self .error_list_view .setModel (self .error_list_model )
31
31
self .validate_button .clicked .connect (self .validate )
32
32
33
- def update_errors (self , errors : list [str ]):
34
- """Updates the list view with the provided validation errors."""
35
- self .error_list_model .setStringList (errors )
36
-
37
33
def validate (self ):
38
34
"""Handles the button press to trigger the validation process."""
39
35
active_plan_id = get_active_plan_id ()
@@ -44,36 +40,39 @@ def validate(self):
44
40
self .lambda_service .validate_plan (active_plan_id )
45
41
46
42
def list_validation_errors (self , validation_json ):
47
- """Slot for listing validation errors."""
43
+ """Slot for listing validation errors and warnings ."""
48
44
if not validation_json :
49
- iface .messageBar ().pushMessage ("Virhe" , "Ei virheitä havaittu ." , level = 1 )
45
+ iface .messageBar ().pushMessage ("Virhe" , "Validaatio json puuttuu ." , level = 1 )
50
46
return
47
+ # Clear the existing errors from the list view
48
+ self .error_list_model .setStringList ([])
51
49
52
- current_errors = self .error_list_model .stringList ()
53
50
new_errors = []
54
51
55
- for plan_id , error_data in validation_json .items ():
56
- if isinstance (error_data , str ):
57
- new_errors .append (f"Validaatio epäonnistui Kaavalle id { plan_id } : { error_data } " )
58
- elif isinstance (error_data , dict ):
59
- title = error_data .get ("title" , "Tuntematon virhe" )
60
- status = error_data .get ("status" , "Tuntematon status" )
61
- detail = error_data .get ("detail" , "Tietoja ei saatavilla" )
62
- new_errors .append (f"Virhe kaavalla: { plan_id } - { title } ({ status } ): { detail } " )
52
+ if not validation_json :
53
+ # If no errors or warnings, display a message and exit
54
+ iface .messageBar ().pushMessage ("Virhe" , "Ei virheitä havaittu." , level = 1 )
55
+ return
63
56
57
+ for error_data in validation_json .values ():
58
+ if isinstance (error_data , dict ):
59
+ # Get the errors for this plan
64
60
errors = error_data .get ("errors" , [])
65
61
for error in errors :
66
62
rule_id = error .get ("ruleId" , "Tuntematon sääntö" )
67
63
message = error .get ("message" , "Ei viestiä" )
68
- instance = error .get ("instance" , "Tuntematon instanssi " )
69
- error_message = f" Sääntö: { rule_id } , Viesti: { message } , Tapaus/instanssi : { instance } "
64
+ instance = error .get ("instance" , "Tuntematon instance " )
65
+ error_message = f"Validointivirhe - Sääntö: { rule_id } , Viesti: { message } , Instance : { instance } "
70
66
new_errors .append (error_message )
71
67
68
+ # Get any warnings for this plan using list comprehension
72
69
warnings = error_data .get ("warnings" , [])
73
70
new_errors .extend ([f"Varoitus: { warning } " for warning in warnings ])
74
71
75
- # Append the new errors to the existing list
76
- current_errors .extend (new_errors )
72
+ # If no errors or warnings, display a message
73
+ if not new_errors :
74
+ new_errors .append ("Kaava on validi. Ei virheitä tai varoituksia havaittu." )
75
+ return
77
76
78
- # Update the model with the combined list of errors
79
- self .error_list_model .setStringList (current_errors )
77
+ # Update the list view with the new errors and warnings
78
+ self .error_list_model .setStringList (new_errors )
0 commit comments