Skip to content

Commit

Permalink
[Bristol] Default parent to road network item.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Feb 7, 2025
1 parent dab250d commit d0d7b16
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
16 changes: 7 additions & 9 deletions perllib/Open311/Endpoint/Integration/AlloyV2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ sub post_service_request {
# this is a display only thing for the website
delete $args->{attributes}->{emergency};

# extract attribute values
my $resource_id = $args->{attributes}->{asset_resource_id} || '';

my $category = $args->{service_code};
$category =~ s/(_\d+)+$//;
$category =~ s/_/ /g;
Expand All @@ -219,7 +216,7 @@ sub post_service_request {
designCode => $rfs_design,
};

$self->_set_parent_attribute($resource, $resource_id);
$resource->{parents} = $self->set_parent_attribute($args);

# The Open311 attributes received from FMS may not include all the
# the attributes we need to fully describe the Alloy resource,
Expand Down Expand Up @@ -298,8 +295,10 @@ sub _update_item {
return $update;
}

sub _set_parent_attribute {
my ($self, $resource, $resource_id) = @_;
sub set_parent_attribute {
my ($self, $args) = @_;

my $resource_id = $args->{attributes}->{asset_resource_id} || '';

my $parent_attribute_id;
if ( $resource_id ) {
Expand All @@ -321,12 +320,11 @@ sub _set_parent_attribute {
# It's a list so perhaps an inspection can be linked to many
# assets, and maybe even many different asset types, but for
# now one is fine.
$resource->{parents} = {
return {
$parent_attribute_id => [ $resource_id ],
};
} else {
$resource->{parents} = {};
}
return {};
}

=head2 _find_or_create_contact
Expand Down
47 changes: 34 additions & 13 deletions perllib/Open311/Endpoint/Integration/UK/Bristol/Alloy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,13 @@ sub process_attributes {
push @$attributes, $myattrib;
};

my $usrn = $args->{attributes}->{'usrn'};

if (length($usrn) == 7) {
$usrn = "0" . $usrn;
};
my $locality_name = $self->_search_for_code_by_argument(
{
'dodi_code' => $self->config->{street_cleaning_network_details}->{code},
'attribute' => $self->config->{street_cleaning_network_details}->{attribute},
"search" => $usrn,
}
);
my $road = $args->{attributes}->{road_alloy} || $self->_get_usrn($args);

my $locality = $self->_search_for_code_by_argument(
{
'dodi_code' => $self->config->{locality_list_details}->{code},
'attribute' => $self->config->{locality_list_details}->{attribute},
"search" => $locality_name->{attributes}->{ $self->config->{locality_attribute_field} },
"search" => $road->{attributes}->{ $self->config->{locality_attribute_field} },
}
);

Expand All @@ -108,4 +97,36 @@ sub process_attributes {
return $attributes;
}

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

my $parents = $self->SUPER::set_parent_attribute($args);

if (!%$parents) {
# Default to the road
my $road = $self->_get_usrn($args);
$parents->{attributes_defectsAssignableDefects} = [ $road->{itemId} ];
}

return $parents;
}

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

my $usrn = $args->{attributes}->{'usrn'};
if (length($usrn) == 7) {
$usrn = "0" . $usrn;
};

my $road = $self->_search_for_code_by_argument({
'dodi_code' => $self->config->{street_cleaning_network_details}->{code},
'attribute' => $self->config->{street_cleaning_network_details}->{attribute},
"search" => $usrn,
});

$args->{attributes}->{road_alloy} = $road;
return $road;
}

1;
1 change: 1 addition & 0 deletions t/open311/endpoint/bristol_alloy.t
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ for my $test (

my $sent = pop @sent;
is $sent->{designCode}, $test->{expected_design}, "Correct designCode selected";
is $sent->{parents}{attributes_defectsAssignableDefects}[0], '5ddbe900ca314f0de0ec691f';
my %sent_data = map { $_->{attributeCode}, $_->{value} } @{$sent->{attributes}};
$test->{description} = "Correct attribute populated with correct data";
for my $key (keys %{$test->{expected}}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"pageSize": 1,
"results": [
{
"itemId" : "5ddbe900ca314f0de0ec691f",
"attributes" : [
{
"attributeCode" : "attributes_streetCleansingNetworkUSRN_5ddbe6adca315006c08f40fb",
Expand All @@ -16,4 +17,3 @@
}
]
}

0 comments on commit d0d7b16

Please sign in to comment.