diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm index 9ec5cb2a3e5..4367d3e762a 100644 --- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm +++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm @@ -29,7 +29,7 @@ with 'FixMyStreet::Roles::BoroughEmails'; use SUPER; -use LWP::Simple; +use LWP::UserAgent; use URI; use Try::Tiny; use Utils; @@ -736,48 +736,18 @@ around 'munge_sendreport_params' => sub { sub car_park_wfs_query { my ($self, $row) = @_; - - my $uri = URI->new("https://maps.buckinghamshire.gov.uk/server/services/Transport/Car_Parks/MapServer/WFSServer"); - $uri->query_form( - REQUEST => "GetFeature", - SERVICE => "WFS", - SRSNAME => "urn:ogc:def:crs:EPSG::27700", - TYPENAME => "BC_CAR_PARKS", - VERSION => "1.1.0", - propertyName => 'OBJECTID,Shape', - ); - - try { - return $self->_get($self->_wfs_uri($row, $uri)); - } catch { - # Ignore WFS errors. - return {}; - }; + my $uri = "https://maps.buckinghamshire.gov.uk/server/services/Transport/Car_Parks/MapServer/WFSServer"; + return $self->_wfs_post($uri, $row, 'BC_CAR_PARKS', ['OBJECTID', 'Shape']); } sub speed_limit_wfs_query { my ($self, $row) = @_; - - my $uri = URI->new("https://maps.buckinghamshire.gov.uk/server/services/Transport/OS_Highways_Speed/MapServer/WFSServer"); - $uri->query_form( - REQUEST => "GetFeature", - SERVICE => "WFS", - SRSNAME => "urn:ogc:def:crs:EPSG::27700", - TYPENAME => "OS_Highways_Speed:OS_Highways_Speed", - VERSION => "1.1.0", - propertyName => 'OBJECTID,Shape,speed', - ); - - try { - return $self->_get($self->_wfs_uri($row, $uri)); - } catch { - # Ignore WFS errors. - return {}; - }; + my $uri = "https://maps.buckinghamshire.gov.uk/server/services/Transport/OS_Highways_Speed/MapServer/WFSServer"; + return $self->_wfs_post($uri, $row, 'OS_Highways_Speed:OS_Highways_Speed', ['OBJECTID', 'Shape', 'speed']); } -sub _wfs_uri { - my ($self, $row, $base_uri) = @_; +sub _wfs_post { + my ($self, $uri, $row, $typename, $properties) = @_; # This fn may be called before cobrand has been set in the # reporting flow and local_coords needs it to be set @@ -787,33 +757,39 @@ sub _wfs_uri { my $buffer = 50; # metres my ($w, $s, $e, $n) = ($x-$buffer, $y-$buffer, $x+$buffer, $y+$buffer); - my $filter = " - + $properties = map { "$_" } @$properties; + my $data = < + + $properties + Shape - + $w $s $e $n - "; - $filter =~ s/\n\s+//g; + + + +EOF - # URI encodes ' ' as '+' but arcgis wants it to be '%20' - # Putting %20 into the filter string doesn't work because URI then escapes - # the '%' as '%25' so you get a double encoding issue. - # - # Avoid all of that and just put the filter on the end of the $base_uri - $filter = URI::Escape::uri_escape_utf8($filter); - - return "$base_uri&filter=$filter"; + try { + return $self->_post($uri, $data); + } catch { + # Ignore WFS errors. + return {}; + }; } # Wrapper around LWP::Simple::get to make mocking in tests easier. -sub _get { - my ($self, $uri) = @_; +sub _post { + my ($self, $uri, $data) = @_; - get($uri); + my $ua = LWP::UserAgent->new; + my $res = $ua->post($uri, Content_Type => "text/xml", Content => $data); + return $res->decoded_content; } around 'report_validation' => sub { diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t index 4a889f02d87..262d8de2c35 100644 --- a/t/cobrand/bucks.t +++ b/t/cobrand/bucks.t @@ -404,7 +404,7 @@ my $bucks = Test::MockModule->new('FixMyStreet::Cobrand::Buckinghamshire'); subtest 'Prevents car park reports being made outside a car park' => sub { # Simulate no car parks found - $bucks->mock('_get', sub { "" }); + $bucks->mock('_post', sub { "" }); $mech->get_ok('/report/new?latitude=51.615559&longitude=-0.556903&category=Barrier+problem'); $mech->submit_form_ok({ @@ -419,7 +419,7 @@ subtest 'Prevents car park reports being made outside a car park' => sub { subtest 'Allows car park reports to be made in a car park' => sub { # Now simulate a car park being found - $bucks->mock('_get', sub { + $bucks->mock('_post', sub { " @@ -517,7 +517,7 @@ subtest 'sends grass cutting reports on roads 30mph or more to the council' => s }; subtest "server side speed limit lookup for council grass cutting report" => sub { - $bucks->mock('_get', sub { "60.00000000" }); + $bucks->mock('_post', sub { "60.00000000" }); $mech->get_ok('/report/new?latitude=51.615559&longitude=-0.556903&category=Grass+cutting'); $mech->submit_form_ok({ @@ -536,7 +536,7 @@ subtest "server side speed limit lookup for council grass cutting report" => sub }; subtest "server side speed limit lookup for parish grass cutting report" => sub { - $bucks->mock('_get', sub { "30.00000000" }); + $bucks->mock('_post', sub { "30.00000000" }); $mech->get_ok('/report/new?latitude=51.615559&longitude=-0.556903&category=Grass+cutting'); $mech->submit_form_ok({ @@ -554,7 +554,7 @@ subtest "server side speed limit lookup for parish grass cutting report" => sub }; subtest "server side speed limit lookup with unknown speed limit" => sub { - $bucks->mock('_get', sub { '' }); + $bucks->mock('_post', sub { '' }); $mech->get_ok('/report/new?latitude=51.615559&longitude=-0.556903&category=Grass+cutting'); $mech->submit_form_ok({