Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions perllib/Open311/Endpoint/Integration/AlloyV2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ has config => (
default => sub { $_[0]->alloy->config }
);

has api_cache => (
is => 'lazy',
default => sub { {} }
);

sub get_integration {
return $_[0]->alloy;
}
Expand Down Expand Up @@ -456,10 +461,12 @@ sub set_parent_attribute {

my $parent_attribute_id;
if ( $resource_id ) {
## get the attribute id for the parents so alloy checks in the right place for the asset id
my $resource_type = $self->alloy->api_call(
# Store the asset layer item for later use
$self->api_cache->{$resource_id} = $self->alloy->api_call(
call => "item/$resource_id"
)->{item}->{designCode};
);
## get the attribute id for the parents so alloy checks in the right place for the asset id
my $resource_type = $self->api_cache->{$resource_id}->{item}->{designCode};
$parent_attribute_id = $self->alloy->get_parent_attributes($resource_type);

unless ( $parent_attribute_id ) {
Expand Down
16 changes: 16 additions & 0 deletions perllib/Open311/Endpoint/Integration/UK/Dumfries.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ sub process_attributes {
my ($self, $args) = @_;

my $attributes = $self->SUPER::process_attributes($args);
#If there is an asset_resource_id will have cached the call
# for the item in set_parent_attribute
my $asset_attributes = $args->{attributes}->{asset_resource_id}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I've assigned this, I should probably be using $asset_attributes going forward...

? $self->api_cache->{ $args->{attributes}->{asset_resource_id} }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Doesn't work here...

: '';
if (!($asset_attributes && $asset_attributes->{item})) {
$args->{attributes}->{asset_resource_id}
? $self->logger->warn("Failed to fetch highway item " . $args->{attributes}->{asset_resource_id})
: $self->logger->warn("No asset_resource_id in report");
} else {
$asset_attributes = $self->alloy->attributes_to_hash($asset_attributes->{item});
push @$attributes, {
attributeCode => $self->config->{request_to_resource_attribute_manual_mapping}->{customer_enquiry_location_field},
value => $asset_attributes->{ 'attributes_itemsTitle' },
};
}

my $contact_resource_id = $self->_find_or_create_contact($args);
push @$attributes, {
Expand Down
15 changes: 14 additions & 1 deletion t/open311/endpoint/dumfries_alloy.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ $integration->mock('api_call', sub {
} elsif ( $call =~ m{design/designs_seReportedIssueList} ) {
# Getting service list design
$content = '{ "design": { "code": "designs_seReportedIssueList" } }';
} elsif ( $call =~ m{design/Defect} ) {
# Getting parent design
$content = '{ "design": { "attributes": [{ "name": "Defects", "code": "design_parent"}] } }';
} elsif ( $call =~ 'item-log/item/(.*)$' ) {
$content = path(__FILE__)->sibling("json/alloyv2/dumfries/item_log_$1.json")->slurp;
} elsif ( $call =~ m{item/defect_item_1/parents} ) {
Expand Down Expand Up @@ -172,11 +175,12 @@ subtest 'check services use Alloy IDs as service codes' => sub {
'Same subcategory name in different groups gets different service codes';
};

subtest 'send new report to Alloy with contact and service_code' => sub {
subtest 'send new report to Alloy with contact and service_code and asset_resource_id' => sub {
set_fixed_time('2025-12-03T12:00:00Z');

@sent = ();

$item_data{112112112112} = { designCode => 'Defect', attributes => [ { attributeCode => 'attributes_itemsTitle', value => 'High Road' } ]};
my $res = $endpoint->run_test_request(
POST => '/requests.json',
jurisdiction_id => 'dumfries_alloy',
Expand All @@ -198,6 +202,7 @@ subtest 'send new report to Alloy with contact and service_code' => sub {
'attribute[fixmystreet_id]' => 123,
'attribute[easting]' => 300000,
'attribute[northing]' => 600000,
'attribute[asset_resource_id]' => 112112112112
);

ok $res->is_success, 'valid request'
Expand Down Expand Up @@ -243,6 +248,14 @@ subtest 'send new report to Alloy with contact and service_code' => sub {
is_deeply $customer_desc_attr->{value}, "Category: Roads/Pothole\nSummary: Pothole on High Street\nDescription: There is a large pothole",
'customer_description attribute contains formatted category/summary/description';

# Find the street or asset name attribute
my ($road_title_attr) = grep {
$_->{attributeCode} eq 'attributes_serviceEnquiryStreetOrAssetName'
} @{$report_sent->{attributes}};

ok $road_title_attr, 'road title attribute present';
is_deeply $road_title_attr->{value}, "High Road";

is_deeply decode_json($res->content),
[ { service_request_id => 'report_456' } ],
'correct json returned';
Expand Down
1 change: 1 addition & 0 deletions t/open311/endpoint/dumfries_alloy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ request_to_resource_attribute_mapping:
request_to_resource_attribute_manual_mapping:
service_code: attributes_serviceEnquiryReportedIssue
customer_description: attributes_seCustomerDescription
customer_enquiry_location_field: attributes_serviceEnquiryStreetOrAssetName

contact:
code: designs_contacts
Expand Down
Loading