Skip to content

Commit

Permalink
[Bromley] Include Veolia Notes in update if provided.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Dec 11, 2024
1 parent fbbc68c commit 856bed4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
36 changes: 21 additions & 15 deletions perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ appropriately.
sub open311_get_update_munging {
my ($self, $comment, $state, $request) = @_;

# An update from Bromley with a special referral state
# An update from Bromley with a special referral state, means "resend to Echo"
if ($state eq 'referred to veolia streets') {
my $problem = $comment->problem;
# Do we want to store the old category somewhere for display?
Expand All @@ -430,24 +430,28 @@ sub open311_get_update_munging {
return;
}

# An update from Echo with resolution code 1252
# Fetch any outgoing notes on the Echo event
# If we pulled the update, we already have it, otherwise look it up
my $event = $request->{echo_event} || do {
my $echo = $self->feature('echo');
$echo = Integrations::Echo->new(%$echo);
my $event = $echo->GetEvent($request->{service_request_id}); # From the event, not the report
$echo->log($event->{Data});
$event;
};
my $data = Integrations::Echo::force_arrayref($event->{Data}, 'ExtensibleDatum');
my $notes = "";
foreach (@$data) {
$notes = $_->{Value} if $_->{DatatypeName} eq 'Veolia Notes';
}

# An update from Echo with resolution code 1252 means "refer to Bromley"
my $code = $comment->get_extra_metadata('external_status_code') || '';
if ($code eq '1252') {
my $problem = $comment->problem;
$problem->category(REFERRED_TO_BROMLEY); # Will be LBB_RRE_FROM_VEOLIA_STREETS
$problem->state('in progress');
$comment->problem_state('in progress');

# Fetch outgoing notes
my $echo = $self->feature('echo');
$echo = Integrations::Echo->new(%$echo);
my $event = $echo->GetEvent($request->{service_request_id}); # From the event, not the report
$echo->log($event->{Data});
my $data = Integrations::Echo::force_arrayref($event->{Data}, 'ExtensibleDatum');
my $notes = "";
foreach (@$data) {
$notes = $_->{Value} if $_->{DatatypeName} eq 'Veolia Notes';
}
$problem->set_extra_metadata(handover_notes => $notes);

if (my $original_external_id = $problem->get_extra_metadata('original_bromley_external_id')) {
Expand All @@ -456,14 +460,16 @@ sub open311_get_update_munging {
$comment->problem_state(REFERRED_TO_BROMLEY);
$comment->send_state('unprocessed');
} elsif ($self->_has_report_been_sent_to_echo($problem)) {
# Resending report from Echo to Bromley, don't need comment to be public
# Resending report from Echo to Bromley for first time, don't need comment to be public
$comment->state('hidden');
$problem->resend;
} else {
# Assume has already been sent to Bromley, no need to resend report
# Assume it has already been sent to Bromley, no need to resend report
$comment->problem_state(REFERRED_TO_BROMLEY);
$comment->send_state('unprocessed');
}
} elsif ($notes) {
$comment->text($notes . "\n\n" . $comment->text);
}
}

Expand Down
1 change: 1 addition & 0 deletions perllib/FixMyStreet/Roles/Cobrand/Echo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ sub waste_fetch_events {
(my $external_id = $report->external_id) =~ s/^Echo-//;
my $event = $cfg->{echo}->GetEvent($external_id);
my $request = $self->construct_waste_open311_update($cfg, $event) or next;
$request->{echo_event} = $event;

next if !$request->{status} || $request->{status} eq 'confirmed'; # Still in initial state
next unless $self->waste_check_last_update(
Expand Down
2 changes: 1 addition & 1 deletion t/cobrand/bromley.t
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ subtest 'redirecting of reports between backends' => sub {
is $report->state, 'fixed - council', 'A state change';
is $report->get_extra_metadata('external_status_code'), 67;
my $comment = FixMyStreet::DB->resultset("Comment")->search(undef, { order_by => { -desc => 'id' } })->first;
is $comment->text, 'Template text';
is $comment->text, "Outgoing notes from Echo\n\nTemplate text";
};

subtest "Echo then redirect it back to Confirm" => sub {
Expand Down

0 comments on commit 856bed4

Please sign in to comment.