Skip to content

Commit

Permalink
[ATAK] Use the ATAK ID for service_request_id
Browse files Browse the repository at this point in the history
This was using the FixMyStreet external ID as the service_request_id,
which meant it wasn't getting matched when the updates were pulled into
FMS.

Use the ATAK ID rather than the FMS reference as the service_request_id.
  • Loading branch information
chrismytton committed Aug 30, 2023
1 parent 95abd9b commit 47b4ed4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
17 changes: 13 additions & 4 deletions perllib/Open311/Endpoint/Integration/ATAK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Integrations::ATAK;
use JSON::MaybeXS;
use DateTime::Format::W3CDTF;
use Path::Tiny;
use Data::Dumper;
use Try::Tiny;

has jurisdiction_id => (
is => 'ro',
Expand Down Expand Up @@ -133,7 +133,14 @@ sub get_service_request_updates {
my $end_time = $w3c->parse_datetime($args->{end_date})->epoch;

my $update_storage_raw = path($self->endpoint_config->{update_storage_file})->slurp_raw;
my $updates = decode_json($update_storage_raw);
my $updates;
try {
$updates = decode_json($update_storage_raw);
} catch {
$self->logger->error("[ATAK] Error parsing update storage file: $_");
$updates = [];
};

my @updates_to_send;

foreach my $update (@$updates) {
Expand All @@ -144,7 +151,7 @@ sub get_service_request_updates {
status => $update->{fms_status},
external_status_code => $update->{atak_status},
update_id => $update->{issue_reference} . '_' . $update->{time},
service_request_id => $update->{issue_reference},
service_request_id => $update->{task_id},
description => $update->{description},
updated_datetime => DateTime->from_epoch(epoch => $update->{time}),
);
Expand Down Expand Up @@ -322,6 +329,7 @@ sub _fetch_and_apply_updated_issues_info {

unless ($existing_tracking && $existing_tracking->{atak_status} eq $atak_status) {
$tracked_statuses->{issues}->{$issue_reference} = {
task_id => $issue->{task_p_id},
fms_status => $mapped_fms_status,
atak_status => $atak_status,
issue_reference => $issue_reference,
Expand All @@ -330,6 +338,7 @@ sub _fetch_and_apply_updated_issues_info {
description => $description || '',
};
my $update = {
task_id => $issue->{task_p_id},
fms_status => $mapped_fms_status,
atak_status => $atak_status,
issue_reference => $issue_reference,
Expand All @@ -338,7 +347,7 @@ sub _fetch_and_apply_updated_issues_info {
};
$self->logger->debug(sprintf(
"[ATAK] Adding new update:\n%s",
Dumper($update)
encode_json($update)
));

push @updates, $update;
Expand Down
29 changes: 18 additions & 11 deletions t/open311/endpoint/brent.t
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ subtest "POST Parks littering ATAK service request OK" => sub {
is $data->{project_name}, 'LB BRENT';
is $data->{project_code}, 'C123';
is $data->{taken_on}, '2023-07-27T12:00:00Z';
is $data->{location_name}, '';
is $data->{location_name}, 'Location name';
is $data->{caller}, '';
is $data->{resolve_by}, '';
is $data->{location}->{type}, 'Point';
Expand Down Expand Up @@ -772,38 +772,43 @@ subtest "GET ATAK service request updates OK" => sub {
"task_d_created": "2023-08-01T00:00:00Z",
"task_d_planned": "2023-08-01T00:00:00Z",
"task_d_completed": "2023-08-01T00:00:00Z",
"task_d_approved": "2023-08-01T00:00:00Z"
"task_d_approved": "2023-08-01T00:00:00Z",
"task_p_id": "123"
},
{
"client_ref": "missing created time",
"task_comments": "Closed - Completed",
"task_d_planned": "2023-08-01T00:00:00Z",
"task_d_completed": "2023-08-01T00:00:00Z",
"task_d_approved": "2023-08-01T00:00:00Z"
"task_d_approved": "2023-08-01T00:00:00Z",
"task_p_id": "124"
},
{
"client_ref": "unknown state",
"task_comments": "Closed - Unknown",
"task_d_created": "2023-08-01T00:00:00Z",
"task_d_planned": "2023-08-01T00:00:00Z",
"task_d_completed": "2023-08-01T00:00:00Z",
"task_d_approved": "2023-08-01T00:00:00Z"
"task_d_approved": "2023-08-01T00:00:00Z",
"task_p_id": "125"
},
{
"client_ref": "issue too old",
"task_comments": "Closed - Completed",
"task_d_created": "2022-08-01T00:00:00Z",
"task_d_planned": "2023-08-01T00:00:00Z",
"task_d_completed": "2023-08-01T00:00:00Z",
"task_d_approved": "2023-08-01T00:00:00Z"
"task_d_approved": "2023-08-01T00:00:00Z",
"task_p_id": "126"
},
{
"client_ref": "test",
"task_comments": "Closed - Passed to Brent",
"task_d_created": "2023-08-01T00:00:00Z",
"task_d_planned": "2023-08-01T01:00:00Z",
"task_d_completed": "2023-08-01T02:00:00Z",
"task_d_approved": "2023-08-01T03:00:00Z"
"task_d_approved": "2023-08-01T03:00:00Z",
"task_p_id": "127"
}
]
}');
Expand All @@ -818,7 +823,7 @@ subtest "GET ATAK service request updates OK" => sub {
{
description => '',
media_url => '',
service_request_id => 'ATAK-test',
service_request_id => 'ATAK-127',
status => 'internal_referral',
update_id => 'ATAK-test_1690858800',
updated_datetime => '2023-08-01T03:00:00Z',
Expand All @@ -843,7 +848,8 @@ subtest "GET ATAK service request updates OK" => sub {
"task_d_created": "2023-08-01T00:00:00Z",
"task_d_planned": "2023-08-02T01:00:00Z",
"task_d_completed": "2023-08-02T02:00:00Z",
"task_d_approved": "2023-08-02T03:00:00Z"
"task_d_approved": "2023-08-02T03:00:00Z",
"task_p_id": "128"
}
]
}');
Expand All @@ -859,7 +865,7 @@ subtest "GET ATAK service request updates OK" => sub {
{
description => "",
media_url => '',
service_request_id => 'ATAK-test',
service_request_id => 'ATAK-127',
status => 'internal_referral',
update_id => 'ATAK-test_1690858800',
updated_datetime => '2023-08-01T03:00:00Z',
Expand All @@ -884,7 +890,8 @@ subtest "GET ATAK service request updates OK" => sub {
"task_d_created": "2023-08-01T00:00:00Z",
"task_d_planned": "2023-08-03T01:00:00Z",
"task_d_completed": "2023-08-03T02:00:00Z",
"task_d_approved": "2023-08-03T03:00:00Z"
"task_d_approved": "2023-08-03T03:00:00Z",
"task_p_id": "129"
}
]
}');
Expand All @@ -899,7 +906,7 @@ subtest "GET ATAK service request updates OK" => sub {
{
description => "description",
media_url => '',
service_request_id => 'ATAK-test',
service_request_id => 'ATAK-129',
status => 'fixed',
update_id => 'ATAK-test_1691031600',
updated_datetime => '2023-08-03T03:00:00Z',
Expand Down

0 comments on commit 47b4ed4

Please sign in to comment.