From 338ce754202d066376bc32efef0b231a510cbf87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Menou?= Date: Tue, 6 Aug 2024 14:28:21 +0200 Subject: [PATCH 1/3] Dead code --- apps/transport/lib/db/resource.ex | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/transport/lib/db/resource.ex b/apps/transport/lib/db/resource.ex index 93cf5c4b9f..cbdc76bca0 100644 --- a/apps/transport/lib/db/resource.ex +++ b/apps/transport/lib/db/resource.ex @@ -90,9 +90,6 @@ defmodule DB.Resource do query |> where([resource: r], r.dataset_id == ^dataset_id) end - @spec endpoint() :: binary() - def endpoint, do: Application.fetch_env!(:transport, :gtfs_validator_url) <> "/validate" - def changeset(resource, params) do resource |> cast( From b7e8defe3c0d38063dd6875df20f488f5eadc5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Menou?= Date: Wed, 21 Aug 2024 12:34:19 +0200 Subject: [PATCH 2/3] Document GTFS validator helpers --- .../lib/validators/gtfs_transport_validator.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/transport/lib/validators/gtfs_transport_validator.ex b/apps/transport/lib/validators/gtfs_transport_validator.ex index 116118a70b..75c44584c3 100644 --- a/apps/transport/lib/validators/gtfs_transport_validator.ex +++ b/apps/transport/lib/validators/gtfs_transport_validator.ex @@ -105,6 +105,16 @@ defmodule Transport.Validators.GTFSTransport do def get_issues(_, _), do: [] + @doc """ + iex> validation_result = %{"tooClose" => [%{"severity" => "Warning"}], "funnyName" => [%{"severity" => "Information"}]} + iex> summary(validation_result) + [ + {"Warning", [{"tooClose", %{count: 1, severity: "Warning", title: nil}}]}, + {"Information", [{"funnyName", %{count: 1, severity: "Information", title: nil}}]} + ] + iex> summary(%{}) + [] + """ @spec summary(map) :: list def summary(%{} = validation_result) do validation_result From 92414392c15127ef71c7b2db0040e3a2434fc2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Menou?= Date: Thu, 22 Aug 2024 12:23:58 +0200 Subject: [PATCH 3/3] Setup NeTEx validation: renaming of GTFS templates GTFS validation assumed it was the only validation done this way. This won't be the case anymore with NeTEx coming soon and this commit pave the future by renaming some templates with an explicit prefix. --- ...heex => _gtfs_coordinates_issue.html.heex} | 0 ...s_duplicate_stop_sequence_issue.html.heex} | 0 ... => _gtfs_duplicate_stops_issue.html.heex} | 0 ....heex => _gtfs_extra_file_issue.html.heex} | 0 ...tml.heex => _gtfs_generic_issue.html.heex} | 0 ...=> _gtfs_invalid_shape_id_issue.html.heex} | 0 ...eex => _gtfs_missing_file_issue.html.heex} | 0 ....heex => _gtfs_missing_id_issue.html.heex} | 0 ...eex => _gtfs_missing_name_issue.html.heex} | 0 ...fs_negative_stop_duration_issue.html.heex} | 0 ....html.heex => _gtfs_speed_issue.html.heex} | 0 ...l.heex => _gtfs_subfolder_issue.html.heex} | 0 ...=> _gtfs_unloadable_model_issue.html.heex} | 0 ...eex => _gtfs_unused_shape_issue.html.heex} | 0 ...heex => _gtfs_unused_stop_issue.html.heex} | 0 .../templates/resource/gtfs_details.html.heex | 2 +- .../templates/validation/show.html.heex | 2 +- .../lib/transport_web/views/resource_view.ex | 53 ++++++++++--------- .../transport_web/views/validation_view.ex | 2 +- 19 files changed, 31 insertions(+), 28 deletions(-) rename apps/transport/lib/transport_web/templates/resource/{_coordinates_issue.html.heex => _gtfs_coordinates_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_duplicate_stop_sequence_issue.html.heex => _gtfs_duplicate_stop_sequence_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_duplicate_stops_issue.html.heex => _gtfs_duplicate_stops_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_extra_file_issue.html.heex => _gtfs_extra_file_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_generic_issue.html.heex => _gtfs_generic_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_invalid_shape_id_issue.html.heex => _gtfs_invalid_shape_id_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_missing_file_issue.html.heex => _gtfs_missing_file_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_missing_id_issue.html.heex => _gtfs_missing_id_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_missing_name_issue.html.heex => _gtfs_missing_name_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_negative_stop_duration_issue.html.heex => _gtfs_negative_stop_duration_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_speed_issue.html.heex => _gtfs_speed_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_subfolder_issue.html.heex => _gtfs_subfolder_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_unloadable_model_issue.html.heex => _gtfs_unloadable_model_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_unused_shape_issue.html.heex => _gtfs_unused_shape_issue.html.heex} (100%) rename apps/transport/lib/transport_web/templates/resource/{_unused_stop_issue.html.heex => _gtfs_unused_stop_issue.html.heex} (100%) diff --git a/apps/transport/lib/transport_web/templates/resource/_coordinates_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_coordinates_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_coordinates_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_coordinates_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_duplicate_stop_sequence_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_duplicate_stop_sequence_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_duplicate_stop_sequence_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_duplicate_stop_sequence_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_duplicate_stops_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_duplicate_stops_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_duplicate_stops_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_duplicate_stops_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_extra_file_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_extra_file_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_extra_file_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_extra_file_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_generic_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_generic_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_generic_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_generic_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_invalid_shape_id_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_invalid_shape_id_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_invalid_shape_id_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_invalid_shape_id_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_missing_file_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_missing_file_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_missing_file_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_missing_file_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_missing_id_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_missing_id_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_missing_id_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_missing_id_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_missing_name_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_missing_name_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_missing_name_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_missing_name_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_negative_stop_duration_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_negative_stop_duration_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_negative_stop_duration_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_negative_stop_duration_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_speed_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_speed_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_speed_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_speed_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_subfolder_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_subfolder_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_subfolder_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_subfolder_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_unloadable_model_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_unloadable_model_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_unloadable_model_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_unloadable_model_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_unused_shape_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_unused_shape_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_unused_shape_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_unused_shape_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/_unused_stop_issue.html.heex b/apps/transport/lib/transport_web/templates/resource/_gtfs_unused_stop_issue.html.heex similarity index 100% rename from apps/transport/lib/transport_web/templates/resource/_unused_stop_issue.html.heex rename to apps/transport/lib/transport_web/templates/resource/_gtfs_unused_stop_issue.html.heex diff --git a/apps/transport/lib/transport_web/templates/resource/gtfs_details.html.heex b/apps/transport/lib/transport_web/templates/resource/gtfs_details.html.heex index 0289ffe5de..b7099eaf3a 100644 --- a/apps/transport/lib/transport_web/templates/resource/gtfs_details.html.heex +++ b/apps/transport/lib/transport_web/templates/resource/gtfs_details.html.heex @@ -112,7 +112,7 @@ associated_netex = get_associated_netex(@related_files) %> path: &resource_path/4, action: :details ) %> - <%= render(template(@issues), issues: @issues || [], conn: @conn) %> + <%= render(gtfs_template(@issues), issues: @issues || [], conn: @conn) %> <% end %>

diff --git a/apps/transport/lib/transport_web/templates/validation/show.html.heex b/apps/transport/lib/transport_web/templates/validation/show.html.heex index 29c713a3ec..d3ad86ac72 100644 --- a/apps/transport/lib/transport_web/templates/validation/show.html.heex +++ b/apps/transport/lib/transport_web/templates/validation/show.html.heex @@ -40,7 +40,7 @@ path: &validation_path/4, action: :show ) %> - <%= render(template(@issues), issues: @issues || [], conn: @conn) %> + <%= render(gtfs_template(@issues), issues: @issues || [], conn: @conn) %>

<%= pagination_links(@conn, @issues, [@validation_id], issue_type: issue_type(@issues.entries), diff --git a/apps/transport/lib/transport_web/views/resource_view.ex b/apps/transport/lib/transport_web/views/resource_view.ex index b7c06cd9d2..16962cb3b6 100644 --- a/apps/transport/lib/transport_web/views/resource_view.ex +++ b/apps/transport/lib/transport_web/views/resource_view.ex @@ -24,31 +24,34 @@ defmodule TransportWeb.ResourceView do def issue_type([]), do: nil def issue_type([h | _]), do: h["issue_type"] - def template(issues) do - Map.get( - %{ - "UnloadableModel" => "_unloadable_model_issue.html", - "DuplicateStops" => "_duplicate_stops_issue.html", - "DuplicateStopSequence" => "_duplicate_stop_sequence_issue.html", - "ExtraFile" => "_extra_file_issue.html", - "MissingFile" => "_missing_file_issue.html", - "NullDuration" => "_speed_issue.html", - "ExcessiveSpeed" => "_speed_issue.html", - "NegativeTravelTime" => "_speed_issue.html", - "Slow" => "_speed_issue.html", - "UnusedStop" => "_unused_stop_issue.html", - "InvalidCoordinates" => "_coordinates_issue.html", - "MissingCoordinates" => "_coordinates_issue.html", - "UnusedShapeId" => "_unused_shape_issue.html", - "InvalidShapeId" => "_invalid_shape_id_issue.html", - "MissingId" => "_missing_id_issue.html", - "MissingName" => "_missing_name_issue.html", - "SubFolder" => "_subfolder_issue.html", - "NegativeStopDuration" => "_negative_stop_duration_issue.html" - }, - issue_type(issues.entries), - "_generic_issue.html" - ) + def gtfs_template(issues) do + template = + Map.get( + %{ + "UnloadableModel" => "_unloadable_model_issue.html", + "DuplicateStops" => "_duplicate_stops_issue.html", + "DuplicateStopSequence" => "_duplicate_stop_sequence_issue.html", + "ExtraFile" => "_extra_file_issue.html", + "MissingFile" => "_missing_file_issue.html", + "NullDuration" => "_speed_issue.html", + "ExcessiveSpeed" => "_speed_issue.html", + "NegativeTravelTime" => "_speed_issue.html", + "Slow" => "_speed_issue.html", + "UnusedStop" => "_unused_stop_issue.html", + "InvalidCoordinates" => "_coordinates_issue.html", + "MissingCoordinates" => "_coordinates_issue.html", + "UnusedShapeId" => "_unused_shape_issue.html", + "InvalidShapeId" => "_invalid_shape_id_issue.html", + "MissingId" => "_missing_id_issue.html", + "MissingName" => "_missing_name_issue.html", + "SubFolder" => "_subfolder_issue.html", + "NegativeStopDuration" => "_negative_stop_duration_issue.html" + }, + issue_type(issues.entries), + "_generic_issue.html" + ) + + "_gtfs#{template}" end @spec action_path(Plug.Conn.t()) :: any diff --git a/apps/transport/lib/transport_web/views/validation_view.ex b/apps/transport/lib/transport_web/views/validation_view.ex index 8d449969c9..1ac865d3f3 100644 --- a/apps/transport/lib/transport_web/views/validation_view.ex +++ b/apps/transport/lib/transport_web/views/validation_view.ex @@ -1,7 +1,7 @@ defmodule TransportWeb.ValidationView do use TransportWeb, :view import Phoenix.Controller, only: [current_url: 1] - import TransportWeb.ResourceView, only: [issue_type: 1, template: 1] + import TransportWeb.ResourceView, only: [issue_type: 1, gtfs_template: 1] import TransportWeb.PaginationHelpers def render("_" <> _ = partial, assigns) do