Skip to content

Commit c7ab270

Browse files
authored
Merge pull request #4268 from hove-io/nav-2811-sa-formatting
NAV-2811: Add logging for whitespace deletion
2 parents 8936579 + 38c9d17 commit c7ab270

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

source/ed/connectors/gtfs_parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ nt::Type_e get_type_enum(const std::string& str) {
7070
if ("stop_time" == str) {
7171
return nt::Type_e::StopTime;
7272
}
73-
LOG4CPLUS_WARN(log4cplus::Logger::getInstance("log"), "unkown navitia type: " << str);
73+
LOG4CPLUS_WARN(log4cplus::Logger::getInstance("log"), "unknown navitia type: " << str);
7474
return nt::Type_e::Unknown;
7575
}
7676

source/ed/data.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ void Data::add_feed_info(const std::string& key, const std::string& value) {
6666
}
6767

6868
void Data::normalize_uri() {
69-
::ed::normalize_uri(networks);
70-
::ed::normalize_uri(companies);
71-
::ed::normalize_uri(commercial_modes);
72-
::ed::normalize_uri(lines);
73-
::ed::normalize_uri(line_groups);
74-
::ed::normalize_uri(physical_modes);
75-
::ed::normalize_uri(stop_areas);
76-
::ed::normalize_uri(stop_points);
77-
::ed::normalize_uri(vehicle_journeys);
78-
::ed::normalize_uri(validity_patterns);
79-
::ed::normalize_uri(calendars);
80-
::ed::normalize_uri(access_points);
69+
::ed::normalize_uri(networks, true);
70+
::ed::normalize_uri(companies, true);
71+
::ed::normalize_uri(commercial_modes, true);
72+
::ed::normalize_uri(lines, true);
73+
::ed::normalize_uri(line_groups, true);
74+
::ed::normalize_uri(physical_modes, true);
75+
::ed::normalize_uri(stop_areas, true);
76+
::ed::normalize_uri(stop_points, false);
77+
::ed::normalize_uri(vehicle_journeys, true);
78+
::ed::normalize_uri(validity_patterns, true);
79+
::ed::normalize_uri(calendars, true);
80+
::ed::normalize_uri(access_points, true);
8181
}
8282

8383
void Data::build_block_id() {
@@ -296,7 +296,7 @@ void Data::complete() {
296296
shift_stop_times();
297297
finalize_frequency();
298298

299-
::ed::normalize_uri(routes);
299+
::ed::normalize_uri(routes, true);
300300

301301
// set StopPoint from old zonal ODT to is_zonal
302302
for (const auto* vj : vehicle_journeys) {

source/ed/data.h

+14-3
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,28 @@ www.navitia.io
4444
#include "fare/fare.h"
4545
#include "type/datetime.h"
4646
#include "type/address_from_ntfs.h"
47+
#include "utils/logger.h"
4748

4849
namespace nt = navitia::type;
4950
/** Ce namespace contient toutes les structures de données \b temporaires, à remplir par le connecteur */
5051
namespace ed {
5152

5253
template <typename T>
53-
void normalize_uri(std::vector<T*>& vec) {
54+
void normalize_uri(std::vector<T*>& vec, bool remove_whitespaces) {
5455
std::string prefix = navitia::type::static_data::get()->captionByType(T::type);
56+
5557
for (auto* element : vec) {
56-
// Suppression des espaces de l'URI
57-
boost::algorithm::replace_all(element->uri, " ", "");
58+
if (element->uri.find(' ') != std::string::npos) {
59+
if (!remove_whitespaces) {
60+
LOG4CPLUS_ERROR(log4cplus::Logger::getInstance("log"),
61+
"Keeping spaces for: " << prefix << ":" << element->uri);
62+
} else {
63+
// Suppression des espaces de l'URI
64+
LOG4CPLUS_ERROR(log4cplus::Logger::getInstance("log"),
65+
"Removing spaces for: " << prefix << ":" << element->uri);
66+
boost::algorithm::replace_all(element->uri, " ", "");
67+
}
68+
}
5869
element->uri = prefix + ":" + element->uri;
5970
}
6071
}

source/ed/tests/ed2nav_test.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,30 @@ BOOST_AUTO_TEST_CASE(throw_on_save) {
8787
DataThrowOnSave data(0);
8888
BOOST_CHECK_EQUAL(ed::try_save_file(filename, data), false);
8989
}
90+
91+
struct SA {
92+
std::string uri;
93+
const static nt::Type_e type = nt::Type_e::StopArea;
94+
};
95+
struct SP {
96+
std::string uri;
97+
const static nt::Type_e type = nt::Type_e::StopPoint;
98+
};
99+
100+
BOOST_AUTO_TEST_CASE(normalize_uri) {
101+
std::vector<SA*> stopAreasToNormalize;
102+
stopAreasToNormalize.push_back(new SA{"AMI:SP:VENUS 1"});
103+
104+
ed::normalize_uri(stopAreasToNormalize, true);
105+
for (auto* ptr : stopAreasToNormalize) {
106+
BOOST_CHECK_EQUAL(ptr->uri, "stop_area:AMI:SP:VENUS1");
107+
}
108+
109+
std::vector<SP*> stopPointsNotToNormalize;
110+
stopPointsNotToNormalize.push_back(new SP{"AMI:SP:VENUS 1"});
111+
112+
ed::normalize_uri(stopPointsNotToNormalize, false);
113+
for (auto* ptr : stopPointsNotToNormalize) {
114+
BOOST_CHECK_EQUAL(ptr->uri, "stop_point:AMI:SP:VENUS 1");
115+
}
116+
}

0 commit comments

Comments
 (0)