Skip to content

Commit c410993

Browse files
authored
Résultats de validation sérializable (#4923)
1 parent fcf2b5d commit c410993

File tree

10 files changed

+83
-62
lines changed

10 files changed

+83
-62
lines changed

apps/transport/lib/transport_web/templates/dataset/_resource_validation_summary_gtfs.html.heex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<%= if GTFSTransport.mine?(@validation) do %>
22
<div class="pb-24">
33
<% link = resource_path(@conn, :details, @resource.id) <> "#validation-report" %>
4-
<% {severity, count} = GTFSTransport.count_max_severity(@validation.result) %>
4+
<% %{"max_level" => severity, "worst_occurrences" => count} =
5+
GTFSTransport.count_max_severity(@validation.result) %>
56
<a href={link}>
67
<span class={summary_class(%{severity: severity, count_errors: count})}>
78
<%= if GTFSTransport.no_error?(severity) do %>

apps/transport/lib/transport_web/templates/dataset/_resource_validation_summary_netex.html.heex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<div class="pb-24">
33
<% link = resource_path(@conn, :details, @resource.id) <> "#validation-report" %>
44
<% results_adapter = Transport.Validators.NeTEx.ResultsAdapter.resolve(@validation.validator_version) %>
5-
<% {severity, count} = results_adapter.count_max_severity(@validation.result) %>
5+
<% %{"max_level" => severity, "worst_occurrences" => count} =
6+
results_adapter.count_max_severity(@validation.result) %>
67
<a href={link}>
78
<span class={summary_class(%{severity: String.capitalize(severity), count_errors: count})}>
89
<%= if results_adapter.no_error?(severity) do %>

apps/transport/lib/transport_web/templates/resource/_netex_validation_errors_v0_2_x.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% {max_level, worst_occurrences} = @max_severity %>
1+
<% %{"max_level" => max_level, "worst_occurrences" => worst_occurrences} = @max_severity %>
22
<% current_category = @conn.params["issues_category"] || "" %>
33

44
<h4><%= @results_adapter.format_severity(max_level, worst_occurrences) |> String.capitalize() %></h4>

apps/transport/lib/transport_web/templates/resource/_validation_summary.html.heex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div id="issues" class="validation-navigation">
22
<nav class="issues-list validation" role="navigation">
3-
<%= for {severity, issues} <- @validation_summary do %>
3+
<%= for %{"severity" => severity, "issues" => issues} <- @validation_summary do %>
44
<%= if Map.get(@severities_count, severity, 0) > 0 do %>
55
<div class="validation-issue">
66
<h4><%= @results_adapter.format_severity(severity, @severities_count[severity]) %></h4>
77
<ul>
8-
<%= for {key, issue} <- issues do %>
8+
<%= for %{"key" => key, "issue" => issue} <- issues do %>
99
<li>
10-
<%= if issue.count > 0 do %>
10+
<%= if issue["count"] > 0 do %>
1111
<%= link(
12-
"#{issue.title} (#{issue.count})",
12+
"#{issue["title"]} (#{issue["count"]})",
1313
to:
1414
"#{current_url(@conn, %{"issue_type" => key, "token" => @token} |> Map.reject(fn {_, v} -> is_nil(v) end))}#issues",
1515
class: if(key == @results_adapter.issue_type(@issues.entries), do: "active")

apps/transport/lib/transport_web/templates/validation/show_netex_v0_2_x.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<div class="validation-content">
2020
<div id="issues" class="container">
21-
<% {_, worst_occurrences} = @max_severity %>
21+
<% %{"worst_occurrences" => worst_occurrences} = @max_severity %>
2222
<% current_category = @conn.params["issues_category"] || "" %>
2323
<div id="issues" class="validation-navigation">
2424
<nav class="issues-list validation" role="navigation">

apps/transport/lib/transport_web/views/resource_view.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ defmodule TransportWeb.ResourceView do
321321
~H"""
322322
<ul class="summary">
323323
<.netex_errors_category
324-
:for={{category, stats} <- @validation_summary}
324+
:for={%{"category" => category, "stats" => stats} <- @validation_summary}
325325
conn={@conn}
326326
results_adapter={@results_adapter}
327327
category={category}
@@ -357,15 +357,15 @@ defmodule TransportWeb.ResourceView do
357357
defp netex_errors_category(%{conn: _, category: _, stats: _, token: _, results_adapter: _} = assigns) do
358358
~H"""
359359
<li>
360-
<.validity_icon errors={@stats[:count]} />
360+
<.validity_icon errors={@stats["count"]} />
361361
<div class="selector">
362-
<%= compatibility_filter(@conn, @category, @token, @stats[:count]) %>
363-
<.stats :if={@stats[:count] > 0} stats={@stats} results_adapter={@results_adapter} />
362+
<%= compatibility_filter(@conn, @category, @token, @stats["count"]) %>
363+
<.stats :if={@stats["count"] > 0} stats={@stats} results_adapter={@results_adapter} />
364364
</div>
365365
<p :if={netex_category_description(@category)}>
366366
<%= netex_category_description(@category) %>
367367
</p>
368-
<.category_hints :if={netex_category_hints(@category) && @stats[:count] > 0} category={@category} />
368+
<.category_hints :if={netex_category_hints(@category) && @stats["count"] > 0} category={@category} />
369369
</li>
370370
"""
371371
end
@@ -379,7 +379,7 @@ defmodule TransportWeb.ResourceView do
379379

380380
defp stats(%{stats: _, results_adapter: _} = assigns) do
381381
~H"""
382-
(<%= @results_adapter.format_severity(@stats[:criticity], @stats[:count]) %>)
382+
(<%= @results_adapter.format_severity(@stats["criticity"], @stats["count"]) %>)
383383
"""
384384
end
385385

apps/transport/lib/validators/gtfs_transport_validator.ex

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ defmodule Transport.Validators.GTFSTransport do
134134
iex> validation_result = %{"tooClose" => [%{"severity" => "Warning"}], "funnyName" => [%{"severity" => "Information"}]}
135135
iex> summary(validation_result)
136136
[
137-
{"Warning", [{"tooClose", %{count: 1, severity: "Warning", title: nil}}]},
138-
{"Information", [{"funnyName", %{count: 1, severity: "Information", title: nil}}]}
137+
%{"severity" => "Warning", "issues" => [%{"key" => "tooClose", "issue" => %{"count" => 1, "severity" => "Warning", "title" => nil}}]},
138+
%{"severity" => "Information", "issues" => [%{"key" => "funnyName", "issue" => %{"count" => 1, "severity" => "Information", "title" => nil}}]}
139139
]
140140
iex> summary(%{})
141141
[]
@@ -146,14 +146,19 @@ defmodule Transport.Validators.GTFSTransport do
146146
|> Enum.map(fn {key, issues} ->
147147
{key,
148148
%{
149-
count: Enum.count(issues),
150-
title: issues_short_translation()[key],
151-
severity: issues |> List.first() |> Map.fetch!("severity")
149+
"count" => Enum.count(issues),
150+
"title" => issues_short_translation()[key],
151+
"severity" => issues |> List.first() |> Map.fetch!("severity")
152152
}}
153153
end)
154-
|> Map.new()
155-
|> Enum.group_by(fn {_, issue} -> issue.severity end)
154+
|> Enum.group_by(fn {_, issue} -> issue["severity"] end)
156155
|> Enum.sort_by(fn {severity, _} -> severity_level(severity) end)
156+
|> Enum.map(fn {severity, issues} ->
157+
%{
158+
"severity" => severity,
159+
"issues" => issues |> Enum.map(fn {key, issue} -> %{"key" => key, "issue" => issue} end)
160+
}
161+
end)
157162
end
158163

159164
@doc """
@@ -180,19 +185,22 @@ defmodule Transport.Validators.GTFSTransport do
180185
181186
iex> validation_result = %{"tooClose" => [%{"severity" => "Warning"}], "funnyName" => [%{"severity" => "Information"}, %{"severity" => "Information"}], "NullDuration" => [%{"severity" => "Warning"}]}
182187
iex> count_max_severity(validation_result)
183-
{"Warning", 2}
188+
%{"max_level" => "Warning", "worst_occurrences" => 2}
184189
iex> count_max_severity(%{})
185-
{"NoError", 0}
190+
%{"max_level" => "NoError", "worst_occurrences" => 0}
186191
"""
187192
@spec count_max_severity(map()) :: {binary(), integer()}
188193
def count_max_severity(validation_result) when validation_result == %{} do
189-
{@no_error, 0}
194+
%{"max_level" => @no_error, "worst_occurrences" => 0}
190195
end
191196

192197
def count_max_severity(%{} = validation_result) do
193-
validation_result
194-
|> count_by_severity()
195-
|> Enum.min_by(fn {severity, _count} -> severity |> severity_level() end)
198+
{max_level, worst_occurrences} =
199+
validation_result
200+
|> count_by_severity()
201+
|> Enum.min_by(fn {severity, _count} -> severity |> severity_level() end)
202+
203+
%{"max_level" => max_level, "worst_occurrences" => worst_occurrences}
196204
end
197205

198206
def no_error?(severity), do: @no_error == severity
@@ -216,8 +224,8 @@ defmodule Transport.Validators.GTFSTransport do
216224
"""
217225
@spec get_max_severity_error(any) :: binary() | nil
218226
def get_max_severity_error(%{} = validations) do
219-
{severity, _} = count_max_severity(validations)
220-
severity
227+
%{"max_level" => max_level} = count_max_severity(validations)
228+
max_level
221229
end
222230

223231
def get_max_severity_error(_), do: nil

apps/transport/lib/validators/netex/results_adapters/v0_1_0.ex

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_1_0 do
1616
1717
iex> validation_result = %{"uic-operating-period" => [%{"criticity" => "error"}], "valid-day-bits" => [%{"criticity" => "error"}], "frame-arret-resources" => [%{"criticity" => "warning"}]}
1818
iex> count_max_severity(validation_result)
19-
{"error", 2}
19+
%{"max_level" => "error", "worst_occurrences" => 2}
2020
iex> validation_result = %{"frame-arret-resources" => [%{"criticity" => "warning"}]}
2121
iex> count_max_severity(validation_result)
22-
{"warning", 1}
22+
%{"max_level" => "warning", "worst_occurrences" => 1}
2323
iex> count_max_severity(%{})
24-
{"NoError", 0}
24+
%{"max_level" => "NoError", "worst_occurrences" => 0}
2525
"""
2626
@impl Transport.Validators.NeTEx.ResultsAdapter
2727
def count_max_severity(validation_result) when validation_result == %{} do
28-
{@no_error, 0}
28+
%{"max_level" => @no_error, "worst_occurrences" => 0}
2929
end
3030

3131
@impl Transport.Validators.NeTEx.ResultsAdapter
3232
def count_max_severity(%{} = validation_result) do
33-
validation_result
34-
|> count_by_severity()
35-
|> Enum.min_by(fn {severity, _count} -> severity |> severity_level() end)
33+
{max_level, worst_occurrences} =
34+
validation_result
35+
|> count_by_severity()
36+
|> Enum.min_by(fn {severity, _count} -> severity |> severity_level() end)
37+
38+
%{"max_level" => max_level, "worst_occurrences" => worst_occurrences}
3639
end
3740

3841
@impl Transport.Validators.NeTEx.ResultsAdapter
@@ -92,11 +95,11 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_1_0 do
9295
iex> validation_result = %{"uic-operating-period" => [%{"code" => "uic-operating-period", "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", "criticity" => "error"}], "valid-day-bits" => [%{"code" => "valid-day-bits", "message" => "Mandatory attribute valid_day_bits not found", "criticity" => "error"}], "frame-arret-resources" => [%{"code" => "frame-arret-resources", "message" => "Tag frame_id doesn't match ''", "criticity" => "warning"}]}
9396
iex> summary(validation_result)
9497
[
95-
{"error", [
96-
{"uic-operating-period", %{count: 1, criticity: "error", title: "UIC operating period"}},
97-
{"valid-day-bits", %{count: 1, criticity: "error", title: "Valid day bits"}}
98+
%{"severity" => "error", "issues" => [
99+
%{"key" => "uic-operating-period", "issue" => %{"count" => 1, "criticity" => "error", "title" => "UIC operating period"}},
100+
%{"key" => "valid-day-bits", "issue" => %{"count" => 1, "criticity" => "error", "title" => "Valid day bits"}}
98101
]},
99-
{"warning", [{"frame-arret-resources", %{count: 1, criticity: "warning", title: "Frame arret resources"}}]}
102+
%{"severity" => "warning", "issues" => [%{"key" => "frame-arret-resources", "issue" => %{"count" => 1, "criticity" => "warning", "title" => "Frame arret resources"}}]}
100103
]
101104
iex> summary(%{})
102105
[]
@@ -107,13 +110,19 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_1_0 do
107110
|> Enum.map(fn {code, errors} ->
108111
{code,
109112
%{
110-
count: length(errors),
111-
criticity: errors |> hd() |> Map.get("criticity"),
112-
title: issues_short_translation_per_code(code)
113+
"count" => length(errors),
114+
"criticity" => errors |> hd() |> Map.get("criticity"),
115+
"title" => issues_short_translation_per_code(code)
113116
}}
114117
end)
115-
|> Enum.group_by(fn {_, details} -> details.criticity end)
118+
|> Enum.group_by(fn {_, details} -> details["criticity"] end)
116119
|> Enum.sort_by(fn {criticity, _} -> severity_level(criticity) end)
120+
|> Enum.map(fn {severity, issues} ->
121+
%{
122+
"severity" => severity,
123+
"issues" => issues |> Enum.map(fn {key, issue} -> %{"key" => key, "issue" => issue} end)
124+
}
125+
end)
117126
end
118127

119128
@spec issues_short_translation_per_code(binary()) :: binary()

apps/transport/lib/validators/netex/results_adapters/v0_2_0.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_2_0 do
3434
"""
3535
@spec get_max_severity_error(map()) :: binary()
3636
def get_max_severity_error(validation_result) do
37-
{severity, _} = validation_result |> count_max_severity()
37+
%{"max_level" => severity} = validation_result |> count_max_severity()
3838
severity
3939
end
4040

@@ -43,12 +43,12 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_2_0 do
4343
4444
iex> validation_result = %{"xsd-schema" => [%{"criticity" => "error"}], "french-profile" => [%{"criticity" => "error"}], "frame-arret-resources" => [%{"criticity" => "warning"}]}
4545
iex> count_max_severity(validation_result)
46-
{"error", 2}
46+
%{"max_level" => "error", "worst_occurrences" => 2}
4747
iex> validation_result = %{"french-profile" => [%{"criticity" => "warning"}]}
4848
iex> count_max_severity(validation_result)
49-
{"warning", 1}
49+
%{"max_level" => "warning", "worst_occurrences" => 1}
5050
iex> count_max_severity(%{})
51-
{"NoError", 0}
51+
%{"max_level" => "NoError", "worst_occurrences" => 0}
5252
"""
5353
@impl Transport.Validators.NeTEx.ResultsAdapter
5454
defdelegate count_max_severity(validation_result), to: V0_1_0
@@ -126,13 +126,13 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_2_0 do
126126
iex> validation_result = %{"xsd-schema" => [%{"code" => "xsd-123", "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", "criticity" => "error"}], "base-rules" => [%{"code" => "valid-day-bits", "message" => "Mandatory attribute valid_day_bits not found", "criticity" => "error"}]}
127127
iex> summary(validation_result)
128128
[
129-
{"xsd-schema", %{count: 1, criticity: "error"}},
130-
{"base-rules", %{count: 1, criticity: "error"}}
129+
%{"category" => "xsd-schema", "stats" => %{"count" => 1, "criticity" => "error"}},
130+
%{"category" => "base-rules", "stats" => %{"count" => 1, "criticity" => "error"}}
131131
]
132132
iex> summary(%{})
133133
[
134-
{"xsd-schema", %{count: 0, criticity: "NoError"}},
135-
{"base-rules", %{count: 0, criticity: "NoError"}}
134+
%{"category" => "xsd-schema", "stats" => %{"count" => 0, "criticity" => "NoError"}},
135+
%{"category" => "base-rules", "stats" => %{"count" => 0, "criticity" => "NoError"}}
136136
]
137137
"""
138138
@impl Transport.Validators.NeTEx.ResultsAdapter
@@ -146,9 +146,9 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_2_0 do
146146
|> Enum.map(fn error -> Map.get(error, "criticity", @no_error) end)
147147
|> Enum.min_by(&severity_level/1, fn -> @no_error end)
148148

149-
stats = %{count: length(errors), criticity: worst_criticity}
149+
stats = %{"count" => length(errors), "criticity" => worst_criticity}
150150

151-
{category, stats}
151+
%{"category" => category, "stats" => stats}
152152
end)
153153
end
154154

apps/transport/lib/validators/netex/results_adapters/v0_2_1.ex

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_2_1 do
7373
iex> validation_result = %{"xsd-schema" => [%{"code" => "xsd-123", "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", "criticity" => "error"}], "french-profile"=>[%{"code"=>"pan:french_profile:123", "criticity" => "error"}], "base-rules" => [%{"code" => "valid-day-bits", "message" => "Mandatory attribute valid_day_bits not found", "criticity" => "error"}]}
7474
iex> summary(validation_result)
7575
[
76-
{"xsd-schema", %{count: 1, criticity: "error"}},
77-
{"french-profile", %{count: 1, criticity: "error"}},
78-
{"base-rules", %{count: 1, criticity: "error"}}
76+
%{"category" => "xsd-schema", "stats" => %{"count" => 1, "criticity" => "error"}},
77+
%{"category" => "french-profile", "stats" => %{"count" => 1, "criticity" => "error"}},
78+
%{"category" => "base-rules", "stats" => %{"count" => 1, "criticity" => "error"}}
7979
]
8080
iex> summary(%{})
8181
[
82-
{"xsd-schema", %{count: 0, criticity: "NoError"}},
83-
{"french-profile", %{count: 0, criticity: "NoError"}},
84-
{"base-rules", %{count: 0, criticity: "NoError"}}
82+
%{"category" => "xsd-schema", "stats" => %{"count" => 0, "criticity" => "NoError"}},
83+
%{"category" => "french-profile", "stats" => %{"count" => 0, "criticity" => "NoError"}},
84+
%{"category" => "base-rules", "stats" => %{"count" => 0, "criticity" => "NoError"}}
8585
]
8686
"""
8787
@impl Transport.Validators.NeTEx.ResultsAdapter
@@ -95,9 +95,9 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_2_1 do
9595
|> Enum.map(fn error -> Map.get(error, "criticity", @no_error) end)
9696
|> Enum.min_by(&severity_level/1, fn -> @no_error end)
9797

98-
stats = %{count: length(errors), criticity: worst_criticity}
98+
stats = %{"count" => length(errors), "criticity" => worst_criticity}
9999

100-
{category, stats}
100+
%{"category" => category, "stats" => stats}
101101
end)
102102
end
103103

@@ -114,6 +114,8 @@ defmodule Transport.Validators.NeTEx.ResultsAdapters.V0_2_1 do
114114
[]
115115
iex> get_issues(validation_result, nil)
116116
[%{"code" => "xsd-123", "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", "criticity" => "error"}]
117+
iex> get_issues(validation_result, %{})
118+
[%{"code" => "xsd-123", "message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod", "criticity" => "error"}]
117119
iex> get_issues(%{}, nil)
118120
[]
119121
iex> get_issues([], nil)

0 commit comments

Comments
 (0)