Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Surrey][Boomi] Fetch job updates #356

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions perllib/Integrations/Surrey/Boomi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ Returns the ID of the created or updated ticket.
=cut

sub getHighwaysTicketUpdates {
my ($self, $start, $end) = @_;
my ($self, $integration_id, $start, $end) = @_;

my $resp = $self->get('getHighwaysTicketUpdates', {
from => format_datetime($start),
to => format_datetime($end),
integration_id => $self->config->{integration_ids}->{getHighwaysTicketUpdates},
integration_id => $integration_id,
});

if (my $errors = $resp->{errors}) {
Expand Down
31 changes: 25 additions & 6 deletions perllib/Open311/Endpoint/Integration/Boomi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -217,31 +217,50 @@ sub _get_service_requests_for_integration_id {
return @requests;
}



sub get_service_request_updates {
my ($self, $args) = @_;

my $integration_ids = $self->endpoint_config->{integration_ids}->{getHighwaysTicketUpdates};
return () unless $integration_ids;
$integration_ids = [ $integration_ids ] unless ref $integration_ids eq 'ARRAY';

my @updates;
foreach (@$integration_ids) {
push @updates, $self->_get_service_request_updates_for_integration_id($_, $args);
}

return @updates;
}

sub _get_service_request_updates_for_integration_id {
my ($self, $integration_id, $args) = @_;

my $start = DateTime::Format::W3CDTF->parse_datetime($args->{start_date});
my $end = DateTime::Format::W3CDTF->parse_datetime($args->{end_date});

my $results = $self->boomi->getHighwaysTicketUpdates($start, $end);
my $results = $self->boomi->getHighwaysTicketUpdates($integration_id, $start, $end);
my $w3c = DateTime::Format::W3CDTF->new;

my @updates;

for my $update (@$results) {
my $log = $update->{confirmEnquiryStatusLog};
my $enquiry_update = $update->{confirmEnquiryStatusLog} ? 1 : 0;
my $log = $enquiry_update ? $update->{confirmEnquiryStatusLog} : $update->{confirmJobStatusLog};
my $fms = $update->{fmsReport};

my $id = $log->{enquiry}->{externalSystemReference} . "_" . $log->{logNumber};
my $id = $enquiry_update
? $log->{enquiry}->{externalSystemReference} . "_" . $log->{logNumber}
: $log->{job}->{jobNumber} . "_" . $log->{logNumber};
my $service_request_id = $enquiry_update
? "Zendesk_" . $log->{enquiry}->{externalSystemReference}
: "Zendesk_JOB_" . $log->{job}->{jobNumber};
my $status = lc $fms->{status}->{state};
$status =~ s/ /_/g;

push @updates, Open311::Endpoint::Service::Request::Update::mySociety->new(
status => $status,
update_id => $id,
service_request_id => "Zendesk_" . $log->{enquiry}->{externalSystemReference},
service_request_id => $service_request_id,
description => $fms->{status}->{label},
updated_datetime => $w3c->parse_datetime( $log->{loggedDate} )->truncate( to => 'second' ),
);
Expand Down
100 changes: 67 additions & 33 deletions t/open311/endpoint/surrey_boomi.t
Original file line number Diff line number Diff line change
Expand Up @@ -141,46 +141,72 @@ $lwp->mock(request => sub {
return HTTP::Response->new(200, 'OK', [], encode_json({"ticket" => { system => "Zendesk", id => 1234 }}));
}
} elsif ($req->uri =~ /getHighwaysTicketUpdates/) {
my %query = $req->uri->query_form;
is $req->method, 'GET', "Correct method used";
return HTTP::Response->new(200, 'OK', [], encode_json({
"executionId" => "execution-7701f16b-036c-4e6e-8e14-998f81f5b6b8-2024.06.27",
"results" => [
{
"confirmEnquiryStatusLog" => {
"loggedDate" => "2024-05-01T09:07:47.000Z",
"logNumber" => 11,
"statusCode" => "5800",
"enquiry" => {
"enquiryNumber" => 129293,
"externalSystemReference" => "2929177"
if ($query{integration_id} eq 'Integration.2') {
return HTTP::Response->new(200, 'OK', [], encode_json({
"executionId" => "execution-7701f16b-036c-4e6e-8e14-998f81f5b6b8-2024.06.27",
"results" => [
{
"confirmEnquiryStatusLog" => {
"loggedDate" => "2024-05-01T09:07:47.000Z",
"logNumber" => 11,
"statusCode" => "5800",
"enquiry" => {
"enquiryNumber" => 129293,
"externalSystemReference" => "2929177"
}
},
"fmsReport" => {
"status" => {
"state" => "Closed",
"label" => "Enquiry closed"
}
}
},
"fmsReport" => {
"status" => {
"state" => "Closed",
"label" => "Enquiry closed"
}
}
},
{
"confirmEnquiryStatusLog" => {
"loggedDate" => "2024-05-01T09:10:41.000Z",
"logNumber" => 7,
"statusCode" => "3200",
"enquiry" => {
"enquiryNumber" => 132361,
"externalSystemReference" => "2939061"
{
"confirmEnquiryStatusLog" => {
"loggedDate" => "2024-05-01T09:10:41.000Z",
"logNumber" => 7,
"statusCode" => "3200",
"enquiry" => {
"enquiryNumber" => 132361,
"externalSystemReference" => "2939061"
}
},
"fmsReport" => {
"status" => {
"state" => "Action scheduled",
"label" => "Assessed - scheduling a repair within 5 Working Days"
}
}
},
"fmsReport" => {
"status" => {
"state" => "Action scheduled",
"label" => "Assessed - scheduling a repair within 5 Working Days"
]
}));
} elsif ($query{integration_id} eq 'Integration.5') {
return HTTP::Response->new(200, 'OK', [], encode_json({
"executionId" => "execution-7701f16b-036c-4e6e-8e14-998f81f5b6b8-2024.06.27",
"results" => [
{
"confirmJobStatusLog" => {
"loggedDate" => "2024-08-09T11:23:10.000Z",
"logNumber" => 2,
"statusCode" => "2000",
"job" => {
"jobNumber" => 569276
}
},
"fmsReport" => {
"externalId" => "569276",
"status" => {
"state" => "Action scheduled",
"label" => "Assessed - scheduling a repair within 5 Working Days"
}
}
}
},
]
}));
]
}));
}
} elsif ($req->uri =~ /getNewHighwaysTickets/) {
is $req->method, 'GET', "Correct method used";
my %query = $req->uri->query_form;
Expand Down Expand Up @@ -367,6 +393,14 @@ subtest "GET Service Request Updates" => sub {
"status" => "action_scheduled",
"update_id" => "2939061_7",
"updated_datetime" => "2024-05-01T09:10:41Z",
},
{
"update_id" => "569276_2",
"service_request_id" => "Zendesk_JOB_569276",
"description" => "Assessed - scheduling a repair within 5 Working Days",
"media_url" => "",
"updated_datetime" => "2024-08-09T11:23:10Z",
"status" => "action_scheduled"
}
];
};
Expand Down
4 changes: 3 additions & 1 deletion t/open311/endpoint/surrey_boomi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ api_url: http://localhost/ws/simple/

integration_ids:
upsertHighwaysTicket: "Integration.1"
getHighwaysTicketUpdates: "Integration.2"
getHighwaysTicketUpdates:
- "Integration.2"
- "Integration.5"
getNewHighwaysTickets:
- "Integration.3"
- "Integration.4"
Loading