From 47b4ed43d06e0f14b9d7606d8f955615f028adae Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Tue, 22 Aug 2023 11:33:33 +0100 Subject: [PATCH] [ATAK] Use the ATAK ID for service_request_id 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. --- perllib/Open311/Endpoint/Integration/ATAK.pm | 17 +++++++++--- t/open311/endpoint/brent.t | 29 ++++++++++++-------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/perllib/Open311/Endpoint/Integration/ATAK.pm b/perllib/Open311/Endpoint/Integration/ATAK.pm index 026c8864b..40f3d6167 100644 --- a/perllib/Open311/Endpoint/Integration/ATAK.pm +++ b/perllib/Open311/Endpoint/Integration/ATAK.pm @@ -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', @@ -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) { @@ -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}), ); @@ -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, @@ -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, @@ -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; diff --git a/t/open311/endpoint/brent.t b/t/open311/endpoint/brent.t index ebf919cf8..a812ad86f 100644 --- a/t/open311/endpoint/brent.t +++ b/t/open311/endpoint/brent.t @@ -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'; @@ -772,14 +772,16 @@ 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", @@ -787,7 +789,8 @@ 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": "125" }, { "client_ref": "issue too old", @@ -795,7 +798,8 @@ subtest "GET ATAK service request updates OK" => sub { "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", @@ -803,7 +807,8 @@ subtest "GET ATAK service request updates OK" => sub { "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" } ] }'); @@ -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', @@ -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" } ] }'); @@ -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', @@ -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" } ] }'); @@ -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',