Skip to content

Commit

Permalink
Merge branch 'bristol-main-alloy-integration' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Feb 7, 2025
2 parents b937f3a + f1f63c9 commit 74b12fe
Show file tree
Hide file tree
Showing 8 changed files with 517 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} || '';

$args->{service_code_alloy}
= $self->_munge_service_code( $args->{service_code} );

Expand All @@ -218,7 +215,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 @@ -306,8 +303,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 @@ -329,12 +328,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
49 changes: 35 additions & 14 deletions perllib/Open311/Endpoint/Integration/UK/Bristol/Alloy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sub process_attributes {
$value = [ $attributes_values->{CleansingTypes}->{$code} ];
}
$args->{service_code_alloy} = 'SC-Street Cleansing';
$args->{service_code} = 'SC-Street_Cleansing_1';

my $myattrib = {
attributeCode => $self->config->{request_to_resource_attribute_manual_mapping}->{$args->{service_code_alloy}}->{'JobType'},
value => $value,
Expand Down 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_road($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_road($args);
$parents->{attributes_defectsAssignableDefects} = [ $road->{itemId} ];
}

return $parents;
}

sub _get_road {
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;
Loading

0 comments on commit 74b12fe

Please sign in to comment.