diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Angus.pm | 132 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Angus.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Angus.pm | 167 |
3 files changed, 0 insertions, 317 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Angus.pm b/perllib/FixMyStreet/Cobrand/Angus.pm deleted file mode 100644 index 87dcc1d96..000000000 --- a/perllib/FixMyStreet/Cobrand/Angus.pm +++ /dev/null @@ -1,132 +0,0 @@ -package FixMyStreet::Cobrand::Angus; -use parent 'FixMyStreet::Cobrand::UKCouncils'; - -use strict; -use warnings; - -sub council_area_id { return 2550; } -sub council_area { return 'Angus'; } -sub council_name { return 'Angus Council'; } -sub council_url { return 'angus'; } - -sub base_url { - my $self = shift; - return $self->next::method() if FixMyStreet->config('STAGING_SITE'); - return 'https://fix.angus.gov.uk'; -} - -sub enter_postcode_text { - my ($self) = @_; - return 'Enter an Angus postcode, or street name and area'; -} - -sub example_places { - return ( 'DD8 3AP', "Canmore Street" ); -} - -sub map_type { 'Angus' } - -sub default_show_name { 0 } - -sub disambiguate_location { - my $self = shift; - my $string = shift; - - return { - %{ $self->SUPER::disambiguate_location() }, - town => 'Angus', - centre => '56.7240845983561,-2.91774391131183', - span => '0.525195055746977,0.985870680170788', - bounds => [ 56.4616875530489, -3.40703662677109, 56.9868826087959, -2.4211659466003 ], - }; -} - -sub pin_colour { - my ( $self, $p, $context ) = @_; - return 'grey' if $p->state eq 'not responsible'; - return 'green' if $p->is_fixed || $p->is_closed; - return 'red' if $p->state eq 'confirmed'; - return 'yellow'; -} - -sub contact_email { - my $self = shift; - return join( '@', 'accessline', 'angus.gov.uk' ); -} - -=head2 temp_email_to_update, temp_update_contacts - -Temporary helper routines to update the extra for potholes (temporary setup -hack, cargo-culted from Harrogate, may in future be superseded either by -Open311/integration or a better mechanism for manually creating rich contacts). - -Can run with a script or command line like: - - bin/cron-wrapper perl -MFixMyStreet::App -MFixMyStreet::Cobrand::Angus -e \ - 'FixMyStreet::Cobrand::Angus->new({c => FixMyStreet::App->new})->temp_update_contacts' - -=cut - -sub temp_update_contacts { - my $self = shift; - - my $contact_rs = $self->{c}->model('DB::Contact'); - - my $body = FixMyStreet::DB->resultset('Body')->for_areas($self->council_area_id)->first; - - my $_update = sub { - my ($category, $field, $category_details) = @_; - # NB: we're accepting just 1 field, but supply as array [ $field ] - - my $contact = $contact_rs->find_or_create( - { - body => $body, - category => $category, - %{ $category_details || {} }, - }, - { - key => 'contacts_body_id_category_idx' - } - ); - - my %default = ( - variable => 'true', - order => '1', - required => 'no', - datatype => 'string', - datatype_description => 'a string', - ); - - if ($field->{datatype} || '' eq 'boolean') { - my $description = $field->{description}; - %default = ( - %default, - datatype => 'singlevaluelist', - datatype_description => 'Yes or No', - values => { value => [ - { key => ['No'], name => ['No'] }, - { key => ['Yes'], name => ['Yes'] }, - ] }, - ); - } - - $contact->update({ - # XXX: we're just setting extra with the expected layout, - # this could be encapsulated more nicely - extra => { _fields => [ { %default, %$field } ] }, - confirmed => 1, - deleted => 0, - editor => 'automated script', - whenedited => \'NOW()', - note => 'Edited by script as per requirements Jan 2016', - }); - }; - - $_update->( 'Street lighting', { - code => 'column_id', - description => 'Lamp post number', - }); - -} - -1; diff --git a/perllib/FixMyStreet/Map/Angus.pm b/perllib/FixMyStreet/Map/Angus.pm deleted file mode 100644 index 98f5373c1..000000000 --- a/perllib/FixMyStreet/Map/Angus.pm +++ /dev/null @@ -1,18 +0,0 @@ -# FixMyStreet:Map::Angus -# More JavaScript, for street assets - -package FixMyStreet::Map::Angus; -use base 'FixMyStreet::Map::FMS'; - -use strict; - -sub map_javascript { [ - '/vendor/OpenLayers/OpenLayers.angus.js', - '/js/map-OpenLayers.js', - '/js/map-bing-ol.js', - '/js/map-fms.js', - '/cobrands/fixmystreet/assets.js', - '/cobrands/angus/js.js', -] } - -1; diff --git a/perllib/FixMyStreet/SendReport/Angus.pm b/perllib/FixMyStreet/SendReport/Angus.pm deleted file mode 100644 index 4ba5f3070..000000000 --- a/perllib/FixMyStreet/SendReport/Angus.pm +++ /dev/null @@ -1,167 +0,0 @@ -package FixMyStreet::SendReport::Angus; - -use Moo; - -BEGIN { extends 'FixMyStreet::SendReport'; } - -use Try::Tiny; -use Encode; -use XML::Simple; - -sub get_auth_token { - my ($self, $authxml) = @_; - - my $xml = new XML::Simple; - my $obj; - - eval { - $obj = $xml->parse_string( $authxml ); - }; - - my $success = $obj->{success}; - $success =~ s/^\s+|\s+$//g if defined $success; - my $token = $obj->{AuthenticateResult}; - $token =~ s/^\s+|\s+$//g if defined $token; - - if (defined $success && $success eq 'True' && defined $token) { - return $token; - } else { - $self->error("Couldn't authenticate against Angus endpoint."); - } -} - -sub get_external_id { - my ($self, $resultxml) = @_; - - my $xml = new XML::Simple; - my $obj; - - eval { - $obj = $xml->parse_string( $resultxml ); - }; - - my $success = $obj->{success}; - $success =~ s/^\s+|\s+$//g if defined $success; - my $external_id = $obj->{CreateRequestResult}->{RequestId}; - - if (defined $success && $success eq 'True' && defined $external_id) { - return $external_id; - } else { - $self->error("Couldn't find external id in response from Angus endpoint."); - return undef; - } -} - -sub crm_request_type { - my ($self, $row, $h) = @_; - return 'StLight'; # TODO: Set this according to report category -} - -sub jadu_form_fields { - my ($self, $row, $h) = @_; - my $xml = XML::Simple->new( - NoAttr=> 1, - KeepRoot => 1, - SuppressEmpty => 0, - ); - my $metas = $row->get_extra_fields(); - my %extras; - foreach my $field (@$metas) { - $extras{$field->{name}} = $field->{value}; - } - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new(); - my $output = $xml->XMLout({ - formfields => { - formfield => [ - { - name => 'RequestTitle', - value => $h->{title} - }, - { - name => 'RequestDetails', - value => $h->{detail} - }, - { - name => 'ReporterName', - value => $h->{name} - }, - { - name => 'ReporterEmail', - value => $h->{email} - }, - { - name => 'ReporterAnonymity', - value => $row->anonymous ? 'True' : 'False' - }, - { - name => 'ReportedDateTime', - value => $h->{confirmed} - }, - { - name => 'ColumnId', - value => $extras{'column_id'} || '' - }, - { - name => 'ReportId', - value => $h->{id} - }, - { - name => 'ReportedNorthing', - value => $h->{northing} - }, - { - name => 'ReportedEasting', - value => $h->{easting} - }, - { - name => 'Imageurl1', - value => $row->photos->[0] ? ($cobrand->base_url . $row->photos->[0]->{url_full}) : '' - }, - { - name => 'Imageurl2', - value => $row->photos->[1] ? ($cobrand->base_url . $row->photos->[1]->{url_full}) : '' - }, - { - name => 'Imageurl3', - value => $row->photos->[2] ? ($cobrand->base_url . $row->photos->[2]->{url_full}) : '' - } - ] - } - }); - # The endpoint crashes if the JADUFormFields string has whitespace between XML elements, so strip it out... - $output =~ s/>[\s\n]+</></g; - return $output; -} - -sub send { - my ( $self, $row, $h ) = @_; - - # FIXME: should not recreate this each time - my $angus_service; - - require Integrations::AngusSOAP; - - my $return = 1; - $angus_service ||= Integrations::AngusSOAP->on_fault(sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, "\n"; }); - try { - my $authresult = $angus_service->AuthenticateJADU(); - my $authtoken = $self->get_auth_token( $authresult ); - # authenticationtoken, CallerId, CallerAddressId, DeliveryId, DeliveryAddressId, CRMRequestType, JADUXFormRef, PaymentRef, JADUFormFields - my $result = $angus_service->CreateServiceRequest( - $authtoken, '1', '1', '1', '1', $self->crm_request_type($row, $h), - 'FMS', '', $self->jadu_form_fields($row, $h) - ); - my $external_id = $self->get_external_id( $result ); - if ( $external_id ) { - $row->external_id( $external_id ); - $return = 0; - } - } catch { - my $e = $_; - $self->error( "Error sending to Angus: $e" ); - }; - $self->success( !$return ); - return $return; -} - -1; |