Skip to content
Draft
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
18 changes: 18 additions & 0 deletions conf/council-rutland_confirm.yml-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"logfile": ""
"min_log_level": ""

"endpoint_url": ""
"username": ""
"password": ""
"tenant_id": ""

"cutoff_enquiry_date": ""
"enquiry_method_code": ""
"point_of_contact_code": ""
"server_timezone": ""

"service_whitelist": {}

"forward_status_mapping": {}

"reverse_status_mapping": {}
12 changes: 9 additions & 3 deletions perllib/Integrations/Confirm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ has ua => (

If the Confirm endpoint requires a particular EnquiryMethodCode for NewEnquiry
requests, override this in the subclass. Valid values can be found by calling
the GetCustomerLookup method on the endpoint.
the GetCustomerLookups method on the endpoint.

=cut

Expand All @@ -64,7 +64,7 @@ has 'enquiry_method_code' => (

Similar to enquiry_method_code, if the Confirm endpoint requires a particular
PointOfContactCode for NewEnquiry requests, override this in the subclass.
Valid values can be found by calling the GetCustomerLookup method on the endpoint.
Valid values can be found by calling the GetCustomerLookups method on the endpoint.

=cut

Expand All @@ -78,7 +78,7 @@ has 'point_of_contact_code' => (

Similar to enquiry_method_code/point_of_contact_code, if the Confirm endpoint requires a particular
CustomerTypeCode for NewEnquiry requests, override this in the subclass.
Valid values can be found by calling the GetCustomerLookup method on the endpoint.
Valid values can be found by calling the GetCustomerLookups method on the endpoint.

=cut

Expand Down Expand Up @@ -874,6 +874,12 @@ sub GetEnquiries {
return @enquiries;
}

sub GetCustomerLookups {
my $self = shift;
my $lookups = $self->perform_request(\SOAP::Data->name('GetCustomerLookups'));
return $lookups;
}

sub GetEnquiryLookups {
my $self = shift;

Expand Down
8 changes: 7 additions & 1 deletion perllib/Integrations/SalesForce/Rutland.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use Moo;
extends 'Integrations::SalesForce::Base';

use JSON::MaybeXS;
use Try::Tiny;

has 'requests_endpoint' => (
is => 'ro',
Expand Down Expand Up @@ -118,7 +119,12 @@ sub get_services {
$self->logger->debug("No memcached entry found for $key. Fetching services from Salesforce");

$services = [];
my $response = $self->get($self->services_endpoint . '?summary');
my $response;
try {
$response = $self->get($self->services_endpoint . '?summary');
} catch {
return ();
};
for my $service (@{ $response->{CategoryInformation} }) {
push @$services, $service;
}
Expand Down
9 changes: 7 additions & 2 deletions perllib/Open311/Endpoint.pm
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,13 @@ sub format_service_requests {
),
(
map {
my $value = $request->$_->[0];
$_ => $value || '';
my $value;
if (scalar @{ $request->$_ } <= 1) {
$value = $request->$_->[0] || '';
} else {
$value = $request->@{$_};
}
$_ => $value;
}
qw/
media_url
Expand Down
5 changes: 3 additions & 2 deletions perllib/Open311/Endpoint/Integration/Confirm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ sub get_service_request_updates {
my $job_photos = @{ $integ->enquiry_update_job_photo_statuses };
my $defect_photos = @{ $integ->enquiry_update_defect_photo_statuses };

my $documents = 'documents { url documentName documentDate }';
my $documents = 'documents { url documentName documentDate docTypeCode}';
my $job_documents = $job_photos ? $documents : "";
my $defect_documents = $defect_photos ? $documents : "";

Expand Down Expand Up @@ -1834,7 +1834,8 @@ sub _parse_graphql_docs {
return map { {
URL => $_->{url},
Name => $_->{documentName},
Date => $self->date_parser->parse_datetime($_->{documentDate})
Date => $self->date_parser->parse_datetime($_->{documentDate}),
ClassificationCode => $_->{docTypeCode} || '',
} } @$docs;
}

Expand Down
2 changes: 0 additions & 2 deletions perllib/Open311/Endpoint/Integration/Multi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ sub get_token {
sub post_service_request_update {
my ($self, $args) = @_;

# Cobrand needs to send the service_code through with updates
# (see Bexley's open311_munge_update_params in FMS for example)
my ($integration, $service_code) = $self->_map_from_new_id($args->{service_code}, 'service');
my ($integration2, $service_request_id) = $self->_map_from_new_id($args->{service_request_id}, 'request');
die "$integration did not equal $integration2\n" if $integration ne $integration2;
Expand Down
31 changes: 19 additions & 12 deletions perllib/Open311/Endpoint/Integration/UK/Rutland.pm
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package Open311::Endpoint::Integration::UK::Rutland;
use parent 'Open311::Endpoint::Integration::SalesForce::Rutland';

use Moo;
extends 'Open311::Endpoint::Integration::Multi';

use Module::Pluggable
search_path => ['Open311::Endpoint::Integration::UK::Rutland'],
instantiate => 'new';

has jurisdiction_id => (
is => 'ro',
default => 'rutland',
);

sub reverse_status_mapping {
my ($self, $status) = @_;
sub service_request_content {
'/open311/service_request_extended'
}

my %valid_status = map { my $no_spaces = $_; $no_spaces =~ s/\s+/_/g; $_ => $no_spaces; } (
'open', 'investigating', 'in progress', 'planned', 'action scheduled',
'no further action', 'not councils responsibility', 'duplicate', 'internal referral',
'fixed', 'closed',
);
=pod

$valid_status{'not responsible'} = 'not_councils_responsibility';
Rutland was previously only a Salesforce backend in open311-adapter, so we
maintain its categories/IDs without any backend prefix as any updates on pre-multi
reports will be looking for the id without the prefix

return $valid_status{lc($status)} || 'open';
}
=cut

has integration_without_prefix => (
is => 'ro',
default => 'SalesForce',
);

1;
__PACKAGE__->run_if_script;
39 changes: 39 additions & 0 deletions perllib/Open311/Endpoint/Integration/UK/Rutland/Confirm.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package Open311::Endpoint::Integration::UK::Rutland::Confirm;

use Moo;
extends 'Open311::Endpoint::Integration::Confirm';

use Open311::Endpoint::Service::UKCouncil::Confirm;

around BUILDARGS => sub {
my ($orig, $class, %args) = @_;
$args{jurisdiction_id} = 'rutland_confirm';
$args{publish_service_update_text} = 1;
return $class->$orig(%args);
};

=head2 filter_photos_graphql

Rutland want us to return photos with specific classification
tag.

=cut

around filter_photos_graphql => sub {
my ($orig, $self, @photos) = @_;
my @filtered = $self->$orig(@photos);
return grep { $_->{ClassificationCode} && $_->{ClassificationCode} eq 'DT20' } @filtered;
};

around _parse_enquiry_status_log => sub {
my ($orig, $self) = (shift, shift);
my $status_log = $_[0];

unless ($status_log->{EnquiryStatusCode} eq 'FMS') {
$status_log->{StatusLogNotes} = '';
};

$self->$orig(@_);
};

1;
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
package Open311::Endpoint::Integration::SalesForce::Rutland;

use Moo;
extends 'Open311::Endpoint';
with 'Open311::Endpoint::Role::mySociety';
package Open311::Endpoint::Integration::UK::Rutland::SalesForce;

use Open311::Endpoint::Service::UKCouncil::Rutland;
use Open311::Endpoint::Service::Request::SalesForce;
Expand All @@ -15,6 +11,34 @@ use Encode qw(encode_utf8);
use Digest::MD5 qw(md5_hex);
use DateTime::Format::Strptime;

use Moo;
extends 'Open311::Endpoint';
with 'Open311::Endpoint::Role::mySociety';

has jurisdiction_id => (
is => 'ro',
default => 'rutland_salesforce',
);

has 'whitelist' => (
is => 'ro',
is => 'lazy',
default => sub { shift->get_integration->config->{whitelist} || {} }
);

sub reverse_status_mapping {
my ($self, $status) = @_;

my %valid_status = map { my $no_spaces = $_; $no_spaces =~ s/\s+/_/g; $_ => $no_spaces; } (
'open', 'investigating', 'in progress', 'planned', 'action scheduled',
'no further action', 'not councils responsibility', 'duplicate', 'internal referral',
'fixed', 'closed',
);

$valid_status{'not responsible'} = 'not_councils_responsibility';
return $valid_status{lc($status)} || 'open';
}

sub service_request_content {
'/open311/service_request_extended'
}
Expand All @@ -37,8 +61,6 @@ sub parse_datetime {
return $strp->parse_datetime($time);
}

sub reverse_status_mapping {}

has '+request_class' => (
is => 'ro',
default => 'Open311::Endpoint::Service::Request::SalesForce',
Expand Down Expand Up @@ -180,6 +202,7 @@ sub services {
my ($self, $args) = @_;

my @services = $self->get_integration->get_services($args);
@services = grep { $self->whitelist->{ $_->{name} } || $_->{hasChildren} eq 'true' } @services;

my %service_lookup = map { $_->{serviceid} => $_ } @services;

Expand Down Expand Up @@ -214,6 +237,7 @@ sub service {

my $meta = $self->get_integration->get_service($id, $args);
my @services = $self->get_integration->get_services($args);
@services = grep { $self->whitelist->{ $_->{name} } || $_->{hasChildren} eq 'true' } @services;

my %service_lookup = map { $_->{serviceid} => $_ } @services;
my $srv = $service_lookup{$id};
Expand Down Expand Up @@ -256,25 +280,24 @@ sub service {
}

my %options = (
code => 'notice',
required => 0,
variable => 0,
datatype => 'string',
automated => 'server_set',
);

push @{ $service->attributes }, Open311::Endpoint::Service::Attribute->new(
code => 'hint',
description => $hint,
%options,
);

push @{ $service->attributes }, Open311::Endpoint::Service::Attribute->new(
code => 'group_hint',
description => $group_hint,
%options,
);
if ($hint || $group_hint) {
my $description = $group_hint ? '<p>' . $group_hint . '</p>' : '';
$description .= $hint ? '<p>' . $hint . '</p>' : '';
if ($description) {
push @{ $service->attributes }, Open311::Endpoint::Service::Attribute->new(
description => $description,
%options,
);
};
};

return $service;
}

__PACKAGE__->run_if_script;
1;
20 changes: 17 additions & 3 deletions perllib/Open311/Endpoint/Role/Photos.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,25 @@ around dispatch_request => sub {
);
};

# Handle being given a multi's jurisdiction_id directly
sub get_photo {
my ($self, $args) = @_;
$self->_call('get_photo', $args->{jurisdiction_id}, $args)
or [ 400, [ 'Content-type', 'text/plain' ], [ 'Bad request' ] ];
my $jurisdiction_id = $args->{jurisdiction_id};

foreach ($self->plugins) {
if ($_->jurisdiction_id eq $jurisdiction_id) {
return $_->get_photo($args);
}
if ($_->isa('Open311::Endpoint::Integration::Multi')) {
foreach ($_->plugins) {
if ($_->jurisdiction_id eq $jurisdiction_id) {
return $_->get_photo($args);
}
}
}
}

[ 400, [ 'Content-type', 'text/plain' ], [ 'Bad request' ] ];
}


1;
15 changes: 11 additions & 4 deletions perllib/Open311/Endpoint/Role/mySociety.pm
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,13 @@ sub format_updates {
),
(
map {
my $value = $update->$_->[0];
$_ => $value || '';
my $value;
if (scalar @{ $update->$_ } <= 1) {
$value = $update->$_->[0] || '';
} else {
$value = $update->@{$_};
}
$_ => $value;
}
qw/
media_url
Expand Down Expand Up @@ -326,6 +331,7 @@ sub learn_additional_types {
my ($self, $schema) = @_;
$schema->learn_type( 'tag:wiki.open311.org,GeoReport_v2:rx/status_extended',
Open311::Endpoint::Schema->enum('//str',
'unchanged',
'open',
'closed',
'fixed',
Expand All @@ -346,6 +352,7 @@ sub learn_additional_types {
);
$schema->learn_type( 'tag:wiki.open311.org,GeoReport_v2:rx/status_extended_upper',
Open311::Endpoint::Schema->enum('//str',
'UNCHANGED',
'OPEN',
'CLOSED',
'FIXED',
Expand Down Expand Up @@ -373,7 +380,7 @@ sub learn_additional_types {
status => '/open311/status_extended',
updated_datetime => '/open311/datetime',
description => '//str',
media_url => '//str',
media_url => { type => '//any', of => [ { type => '//str' }, { type => '//arr', contents => '//str' } ] },
},
optional => {
external_status_code => '//str',
Expand Down Expand Up @@ -401,7 +408,7 @@ sub learn_additional_types {
zipcode => '//str',
lat => '//num',
long => '//num',
media_url => '//str',
media_url => { type => '//any', of => [ { type => '//str' }, { type => '//arr', contents => '//str' } ] },
},
optional => {
title => '//str',
Expand Down
Loading
Loading