Skip to content

Commit

Permalink
[N/land] Pass category update from FMS to Alloy
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Dec 3, 2024
1 parent 305a485 commit bbcb9d5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
15 changes: 11 additions & 4 deletions perllib/Open311/Endpoint/Integration/AlloyV2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,8 @@ sub post_service_request {
# extract attribute values
my $resource_id = $args->{attributes}->{asset_resource_id} || '';

my $category = $args->{service_code};
$category =~ s/(_\d+)+$//;
$category =~ s/_/ /g;
$args->{service_code_alloy} = $category;
$args->{service_code_alloy}
= $self->_munge_service_code( $args->{service_code} );

my $resource = {
# This appears to be shared amongst all asset types for now,
Expand Down Expand Up @@ -253,6 +251,15 @@ sub post_service_request {

}

sub _munge_service_code {
my ( $self, $service_code ) = @_;

my $category = $service_code;
$category =~ s/(_\d+)+$//;
$category =~ s/_/ /g;
return $category;
}

sub _update_item {
my ($self, $item_id, $attributes) = @_;

Expand Down
52 changes: 39 additions & 13 deletions perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,42 @@ sub process_attributes {
value => [ $contact_resource_id ],
};

my $category_code = $self->_find_category_code($args->{service_code_alloy});
if (my $group = $args->{attributes}->{group}) {
foreach (keys %{$self->service_whitelist}) {
if (my $alias = $self->service_whitelist->{$_}->{alias}) {
if ($alias eq $group) {
$self->_populate_category_and_group_attr(
$attributes,
$args->{service_code_alloy},
$args->{attributes}{group},
);

return $attributes;
}

sub _populate_category_and_group_attr {
my ( $self, $attr, $service_code, $group ) = @_;

my $category_code = $self->_find_category_code($service_code);
if ($group) {
foreach ( keys %{ $self->service_whitelist } ) {
if ( my $alias = $self->service_whitelist->{$_}->{alias} ) {
if ( $alias eq $group ) {
$group = $_;
}
}
}
my $group_code = $self->_find_group_code($group);
push @$attributes, {
attributeCode => $self->config->{request_to_resource_attribute_manual_mapping}->{group},
value => [ $group_code ],
push @$attr, {
attributeCode =>
$self->config->{request_to_resource_attribute_manual_mapping}
{group},
value => [$group_code],
};
}
push @$attributes, {
attributeCode => $self->config->{request_to_resource_attribute_manual_mapping}->{category},
value => [ $category_code ],
};

return $attributes;
push @$attr, {
attributeCode =>
$self->config->{request_to_resource_attribute_manual_mapping}
{category},
value => [$category_code],
};
}

=head2 update_additional_attributes
Expand All @@ -92,6 +107,9 @@ Adds an update for 'extra_details' field ('FMS Extra Details' on Alloy end).
Adds an update for the assigned user ('Assigned to' on Alloy end).
Adds an update for category ('Request Category' on Alloy end), and group
if applicable.
=cut

sub update_additional_attributes {
Expand Down Expand Up @@ -146,6 +164,14 @@ sub update_additional_attributes {
}
}

if ( my $service_code = $self->_munge_service_code( $args->{service_code} || '' ) ) {
$self->_populate_category_and_group_attr(
$attr,
$service_code,
$args->{attributes}{group},
);
}

return $attr;
}

Expand Down

0 comments on commit bbcb9d5

Please sign in to comment.