diff --git a/perllib/Open311/Endpoint/Integration/AlloyV2.pm b/perllib/Open311/Endpoint/Integration/AlloyV2.pm index 89d0aa0a..b5a3367c 100644 --- a/perllib/Open311/Endpoint/Integration/AlloyV2.pm +++ b/perllib/Open311/Endpoint/Integration/AlloyV2.pm @@ -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, @@ -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) = @_; diff --git a/perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm b/perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm index fb1c33c0..f8c2c02d 100644 --- a/perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm +++ b/perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm @@ -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 @@ -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 { @@ -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; }