Skip to content

Commit

Permalink
[Bexley] Spot updates on container requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Nov 5, 2024
1 parent 98f269b commit 68a3ded
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ C<0001-01-01T00:00:00> represents an undefined date in Whitespace.

use constant WHITESPACE_UNDEF_DATE => '0001-01-01T00:00:00';
use constant MISSED_COLLECTION_SERVICE_PROPERTY_ID => 68;
use constant REQUEST_SERVICE_PROPERTY_ID => 69;

sub waste_fetch_events {
my ( $self, $params ) = @_;
Expand All @@ -63,14 +64,14 @@ sub waste_fetch_events {
system_user => $self->body->comment_user,
);

my $missed_collection_reports = $self->problems->search(
my $reports = $self->problems->search(
{ external_id => { like => 'Whitespace%' },
state => [ FixMyStreet::DB::Result::Problem->open_states() ],
},
{ order_by => 'id' },
);

while ( my $report = $missed_collection_reports->next ) {
while ( my $report = $reports->next ) {
print 'Fetching data for report ' . $report->id . "\n" if $params->{verbose};

my $worksheet_id = $report->external_id =~ s/Whitespace-//r;
Expand Down Expand Up @@ -102,29 +103,34 @@ sub construct_waste_open311_update {

$worksheet = $self->whitespace->GetFullWorksheetDetails($worksheet->{id});

my ($service_id, $config_key);
if ($report->category eq 'Report missed collection') {
$service_id = MISSED_COLLECTION_SERVICE_PROPERTY_ID;
$config_key = 'missed_collection_state_mapping';
} else {
$service_id = REQUEST_SERVICE_PROPERTY_ID;

Check warning on line 111 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L111

Added line #L111 was not covered by tests
if ($report->category eq 'Request new container') {
$config_key = 'container_delivery_state_mapping';

Check warning on line 113 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L113

Added line #L113 was not covered by tests
} elsif ($report->category eq 'Request container removal') {
$config_key = 'container_removal_state_mapping';

Check warning on line 115 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L115

Added line #L115 was not covered by tests
}
}

# Get info for missed collection
my $missed_collection_properties;
my $properties;
for my $service_properties (
@{ $worksheet->{WSServiceProperties}{WorksheetServiceProperty}
// []
}
) {
next
unless $service_properties->{ServicePropertyID}
== MISSED_COLLECTION_SERVICE_PROPERTY_ID;

$missed_collection_properties = $service_properties;
next unless $service_properties->{ServicePropertyID} == $service_id;
$properties = $service_properties;
}

my $whitespace_state_string
= $missed_collection_properties
? $missed_collection_properties->{ServicePropertyValue}
: '';
my $whitespace_state_string = $properties->{ServicePropertyValue} || '';

my $config = $self->feature('whitespace');
my $new_state
= $config->{missed_collection_state_mapping}
{$whitespace_state_string};
my $new_state = $config->{$config_key}{$whitespace_state_string};
unless ($new_state) {
print " No new state, skipping\n" if $params->{verbose};
return;
Expand Down

0 comments on commit 68a3ded

Please sign in to comment.