Skip to content

Commit 2a64f6b

Browse files
committed
Merge branch 'master' into staging
2 parents 6b1d453 + 7f46037 commit 2a64f6b

File tree

6 files changed

+28
-44
lines changed

6 files changed

+28
-44
lines changed

perllib/Integrations/Confirm.pm

+1
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ sub get_enquiry_json {
877877

878878
sub documents_for_job {
879879
my ($self, $job_id) = @_;
880+
return unless $job_id;
880881
my $data = $self->json_web_api_call("/jobs/$job_id");
881882
return $data->{documents} || [];
882883
}

perllib/Open311/Endpoint/Integration/AlloyV2.pm

+16-33
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ sub post_service_request {
203203

204204
$args->{service_code_alloy}
205205
= $self->_munge_service_code( $args->{service_code} );
206-
207206
my $rfs_design = $self->config->{rfs_design};
208207
if (ref $rfs_design eq 'HASH') {
209208
$rfs_design = $rfs_design->{$args->{service_code_alloy}} || $rfs_design->{$self->rfs_design_fallback};
@@ -388,37 +387,9 @@ sub _search_for_code_by_argument {
388387
return undef;
389388
}
390389

391-
my $body = $self->find_item_body(
392-
dodi_code => $dodi_code,
393-
attribute_code => $attribute_code,
394-
search_term => $search_term,
395-
);
396-
397-
my $results = $self->alloy->search($body);
398-
399-
return undef unless @$results;
400-
my $result = $results->[0];
401-
402-
# Sanity check that our filtering to one result is the correct result
403-
my $a = $self->alloy->attributes_to_hash( $result );
404-
return undef unless $a->{$attribute_code} && $a->{$attribute_code} eq $search_term;
405-
$result->{attributes} = $a;
406-
407-
return $result;
408-
}
409-
410-
=head2 find_item_body
411-
412-
Builds query body for looking up a specific item in Alloy.
413-
414-
=cut
415-
416-
sub find_item_body {
417-
my ( $self, %params ) = @_;
418-
419-
return {
390+
my $body = {
420391
properties => {
421-
dodiCode => $params{dodi_code},
392+
dodiCode => $dodi_code,
422393
collectionCode => "Live",
423394
attributes => [ 'all' ],
424395
},
@@ -429,19 +400,31 @@ sub find_item_body {
429400
{
430401
type => "Attribute",
431402
properties => {
432-
attributeCode => $params{attribute_code},
403+
attributeCode => $attribute_code,
433404
},
434405
},
435406
{
436407
type => "String",
437408
properties => {
438-
value => [ $params{search_term} ]
409+
value => [ $search_term ]
439410
}
440411
}
441412
]
442413
}
443414
]
444415
};
416+
417+
my $results = $self->alloy->search($body);
418+
419+
return undef unless @$results;
420+
my $result = $results->[0];
421+
422+
# Sanity check that our filtering to one result is the correct result
423+
my $a = $self->alloy->attributes_to_hash( $result );
424+
return undef unless $a->{$attribute_code} && $a->{$attribute_code} eq $search_term;
425+
$result->{attributes} = $a;
426+
427+
return $result;
445428
}
446429

447430
=head2 _create_contact

perllib/Open311/Endpoint/Integration/Confirm.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ sub photo_urls_for_update {
639639
my $integ = $self->get_integration;
640640

641641
my $enquiry = $integ->get_enquiry_json($enquiry_id) or return;
642-
my $job_id = $enquiry->{primaryJobNumber};
642+
my $job_id = $enquiry->{jobNumber};
643643
my $documents = $integ->documents_for_job($job_id) or return;
644644

645645
my @ids = map { $_->{documentNo} } grep { $self->photo_filter($_) } @$documents;

perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm

+8-8
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,21 @@ sub update_additional_attributes {
136136

137137
# Search for existing user
138138
my $mapping = $self->config->{assigned_to_user_mapping};
139-
my $body = $self->find_item_body(
140-
dodi_code => $mapping->{design},
141-
attribute_code => $mapping->{email_attribute},
142-
search_term => $args->{attributes}{assigned_to_user_email},
139+
my $res = $self->_search_for_code_by_argument(
140+
{
141+
dodi_code => $mapping->{design},
142+
attribute => $mapping->{email_attribute},
143+
search => $args->{attributes}{assigned_to_user_email},
144+
}
143145
);
144146

145-
my $res = $self->alloy->search($body);
146-
147147
# We don't update if user does not exist in Alloy
148-
if (@$res) {
148+
if ($res) {
149149
push @$attr, {
150150
attributeCode =>
151151
$self->config->{inspection_attribute_mapping}
152152
{assigned_to_user},
153-
value => [ $res->[0]{itemId} ],
153+
value => [ $res->{itemId} ],
154154
};
155155
}
156156
} else {

t/open311/endpoint/confirm.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ subtest "fetching of completion photos" => sub {
779779
$lwp->mock(request => sub {
780780
my ($ua, $req) = @_;
781781
return HTTP::Response->new(200, 'OK', [], '{"access_token":"123","expires_in":3600}') if $req->uri =~ /oauth\/token/;
782-
return HTTP::Response->new(200, 'OK', [], '{"primaryJobNumber":"432"}') if $req->uri =~ /enquiries\/2020/;
782+
return HTTP::Response->new(200, 'OK', [], '{"jobNumber":"432"}') if $req->uri =~ /enquiries\/2020/;
783783
return HTTP::Response->new(200, 'OK', [], '{"documents":[
784784
{"documentNo":1,"fileName":"photo1.jpeg","documentNotes":"Before"},
785785
{"documentNo":2,"fileName":"photo2.jpeg","documentNotes":"After"}

t/open311/endpoint/lincolnshire.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ subtest "looking up of completion photos" => sub {
7676
$lwp->mock(request => sub {
7777
my ($ua, $req) = @_;
7878
return HTTP::Response->new(200, 'OK', [], '{"access_token":"123","expires_in":3600}') if $req->uri =~ /oauth\/token/;
79-
return HTTP::Response->new(200, 'OK', [], '{"primaryJobNumber":"432"}') if $req->uri =~ /enquiries\/2020/;
79+
return HTTP::Response->new(200, 'OK', [], '{"jobNumber":"432"}') if $req->uri =~ /enquiries\/2020/;
8080
return HTTP::Response->new(200, 'OK', [], '{"documents":[
8181
{"documentNo":1,"fileName":"photo1.jpeg","documentNotes":"Before"},
8282
{"documentNo":2,"fileName":"photo2.jpeg","documentNotes":"After"}

0 commit comments

Comments
 (0)