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

Validateur NeTEx : Support des erreurs sans code #4179

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 24 additions & 15 deletions apps/transport/lib/validators/netex_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,15 @@ defmodule Transport.Validators.NeTEx do

iex> index_messages([%{"code"=>"a", "id"=> 1}, %{"code"=>"a", "id"=> 2}, %{"code"=>"b", "id"=> 3}])
%{"a"=>[%{"code"=>"a", "id"=> 1}, %{"code"=>"a", "id"=> 2}], "b"=>[%{"code"=>"b", "id"=> 3}]}

Sometimes the message has no code
iex> index_messages([%{"code"=>"a", "id"=> 1}, %{"code"=>"b", "id"=> 2}, %{"id"=> 3}])
%{"a"=>[%{"code"=>"a", "id"=> 1}], "b"=>[%{"code"=>"b", "id"=> 2}], "unknown-code"=>[%{"id"=> 3}]}
"""
def index_messages(messages) do
messages |> Enum.group_by(fn %{"code" => code} -> code end)
end
def index_messages(messages), do: Enum.group_by(messages, &get_code/1)

defp get_code(%{"code" => code}), do: code
defp get_code(%{}), do: "unknown-code"

# This will change with an actual versioning of the validator
def validator_version, do: "saas-production"
Expand Down Expand Up @@ -298,7 +303,8 @@ defmodule Transport.Validators.NeTEx do
"longitude-mandatory" => dgettext("netex-validator", "Longitude mandatory"),
"uic-operating-period" => dgettext("netex-validator", "UIC operating period"),
"valid-day-bits" => dgettext("netex-validator", "Valid day bits"),
"version-any" => dgettext("netex-validator", "Version any")
"version-any" => dgettext("netex-validator", "Version any"),
"unknown-code" => dgettext("netex-validator", "Unspecified error")
}

@doc """
Expand Down Expand Up @@ -347,17 +353,20 @@ defmodule Transport.Validators.NeTEx do

defp demote_non_xsd_errors(errors), do: Enum.map(errors, &demote_non_xsd_error(&1))

defp demote_non_xsd_error(%{"criticity" => criticity, "code" => code} = error) do
criticity =
if String.starts_with?(code, "xsd-") do
criticity
else
case criticity do
"error" -> "warning"
_ -> criticity
end
end
defp demote_non_xsd_error(error) do
code = Map.get(error, "code", "")

Map.update!(error, "criticity", fn _ -> criticity end)
if String.starts_with?(code, "xsd-") do
error
else
Map.update!(error, "criticity", &demote_error/1)
end
end

defp demote_error(criticity) do
case criticity do
"error" -> "warning"
_ -> criticity
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "warnings"
msgstr ""

#, elixir-autogen, elixir-format
msgid "Unspecified error"
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "warnings"
msgstr "avertissements"

#, elixir-autogen, elixir-format
msgid "Unspecified error"
msgstr ""
4 changes: 4 additions & 0 deletions apps/transport/priv/gettext/netex-validator.pot
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "warnings"
msgstr ""

#, elixir-autogen, elixir-format
msgid "Unspecified error"
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ defmodule Transport.Validators.NeTExTest do
"code" => "frame-arret-resources",
"message" => "Tag frame_id doesn't match ''",
"criticity" => "warning"
},
%{
"message" => "Reference MOBIITI:Quay:104325 doesn't match any existing Resource",
"criticity" => "error"
}
]

Expand Down Expand Up @@ -104,6 +108,12 @@ defmodule Transport.Validators.NeTExTest do
"message" => "Tag frame_id doesn't match ''",
"criticity" => "warning"
}
],
"unknown-code" => [
%{
"message" => "Reference MOBIITI:Quay:104325 doesn't match any existing Resource",
"criticity" => "warning"
}
]
}
end
Expand Down Expand Up @@ -163,6 +173,12 @@ defmodule Transport.Validators.NeTExTest do
"message" => "Tag frame_id doesn't match ''",
"criticity" => "warning"
}
],
"unknown-code" => [
%{
"message" => "Reference MOBIITI:Quay:104325 doesn't match any existing Resource",
"criticity" => "warning"
}
]
}

Expand Down