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

Validation NeTEx: seules les erreurs XSD #4172

Merged
merged 1 commit into from
Sep 10, 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
20 changes: 18 additions & 2 deletions apps/transport/lib/validators/netex_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule Transport.Validators.NeTEx do
resource_history.id,
result_url,
%{elapsed_seconds: elapsed_seconds, retries: retries},
errors
demote_non_xsd_errors(errors)
)

:ok
Expand Down Expand Up @@ -76,7 +76,7 @@ defmodule Transport.Validators.NeTEx do
# result_url in metadata?
{:ok,
%{
"validations" => index_messages(errors),
"validations" => errors |> demote_non_xsd_errors() |> index_messages(),
"metadata" => %{elapsed_seconds: elapsed_seconds, retries: retries}
}}

Expand Down Expand Up @@ -344,4 +344,20 @@ defmodule Transport.Validators.NeTEx do
defp client do
Transport.EnRouteChouetteValidClient.Wrapper.impl()
end

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

Map.update!(error, "criticity", fn _ -> criticity end)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ defmodule Transport.Validators.NeTExTest do
setup :verify_on_exit!

@sample_error_messages [
%{
"code" => "xsd-1871",
"criticity" => "error",
"message" =>
"Element '{http://www.netex.org.uk/netex}OppositeDIrectionRef': This element is not expected. Expected is ( {http://www.netex.org.uk/netex}OppositeDirectionRef )."
},
%{
"code" => "uic-operating-period",
"message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod",
Expand Down Expand Up @@ -70,18 +76,26 @@ defmodule Transport.Validators.NeTExTest do
assert multi_validation.metadata.metadata == %{"retries" => 0, "elapsed_seconds" => 31}

assert multi_validation.result == %{
"xsd-1871" => [
%{
"code" => "xsd-1871",
"criticity" => "error",
"message" =>
"Element '{http://www.netex.org.uk/netex}OppositeDIrectionRef': This element is not expected. Expected is ( {http://www.netex.org.uk/netex}OppositeDirectionRef )."
}
],
"uic-operating-period" => [
%{
"code" => "uic-operating-period",
"message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod",
"criticity" => "error"
"criticity" => "warning"
}
],
"valid-day-bits" => [
%{
"code" => "valid-day-bits",
"message" => "Mandatory attribute valid_day_bits not found",
"criticity" => "error"
"criticity" => "warning"
}
],
"frame-arret-resources" => [
Expand Down Expand Up @@ -121,18 +135,26 @@ defmodule Transport.Validators.NeTExTest do
expect_get_messages(validation_id, @sample_error_messages)

validation_result = %{
"xsd-1871" => [
%{
"code" => "xsd-1871",
"criticity" => "error",
"message" =>
"Element '{http://www.netex.org.uk/netex}OppositeDIrectionRef': This element is not expected. Expected is ( {http://www.netex.org.uk/netex}OppositeDirectionRef )."
}
],
"uic-operating-period" => [
%{
"code" => "uic-operating-period",
"message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod",
"criticity" => "error"
"criticity" => "warning"
}
],
"valid-day-bits" => [
%{
"code" => "valid-day-bits",
"message" => "Mandatory attribute valid_day_bits not found",
"criticity" => "error"
"criticity" => "warning"
}
],
"frame-arret-resources" => [
Expand Down Expand Up @@ -160,11 +182,12 @@ defmodule Transport.Validators.NeTExTest do
expect_get_messages(validation_id, @sample_error_message)

validation_result = %{
"uic-operating-period" => [
"xsd-1871" => [
%{
"code" => "uic-operating-period",
"message" => "Resource 23504000009 hasn't expected class but Netex::OperatingPeriod",
"criticity" => "error"
"code" => "xsd-1871",
"criticity" => "error",
"message" =>
"Element '{http://www.netex.org.uk/netex}OppositeDIrectionRef': This element is not expected. Expected is ( {http://www.netex.org.uk/netex}OppositeDirectionRef )."
}
]
}
Expand Down