diff options
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Angus.pm | 169 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EastHants.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EmptyHomes.pm | 56 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 11 |
4 files changed, 175 insertions, 66 deletions
diff --git a/perllib/FixMyStreet/SendReport/Angus.pm b/perllib/FixMyStreet/SendReport/Angus.pm new file mode 100644 index 000000000..cab5de173 --- /dev/null +++ b/perllib/FixMyStreet/SendReport/Angus.pm @@ -0,0 +1,169 @@ +package FixMyStreet::SendReport::Angus; + +use Moo; + +BEGIN { extends 'FixMyStreet::SendReport'; } + +use Try::Tiny; +use Encode; +use XML::Simple; +use mySociety::Web qw(ent); + +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 ); + $row->send_method_used('Angus'); + $return = 0; + } + } catch { + my $e = $_; + $self->error( "Error sending to Angus: $e" ); + }; + $self->success( !$return ); + return $return; +} + +1; diff --git a/perllib/FixMyStreet/SendReport/EastHants.pm b/perllib/FixMyStreet/SendReport/EastHants.pm index 3eb8ffcfa..55ec79613 100644 --- a/perllib/FixMyStreet/SendReport/EastHants.pm +++ b/perllib/FixMyStreet/SendReport/EastHants.pm @@ -35,12 +35,12 @@ sub send { # FIXME: should not recreate this each time my $eh_service; - require EastHantsWSDL; + require Integrations::EastHantsWSDL; $h->{category} = 'Customer Services' if $h->{category} eq 'Other'; $h->{message} = construct_message( %$h ); my $return = 1; - $eh_service ||= EastHantsWSDL->on_fault(sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, "\n"; }); + $eh_service ||= Integrations::EastHantsWSDL->on_fault(sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, "\n"; }); try { # ServiceName, RemoteCreatedBy, Salutation, FirstName, Name, Email, Telephone, HouseNoName, Street, Town, County, Country, Postcode, Comments, FurtherInfo, ImageURL my $message = ent(encode_utf8($h->{message})); @@ -52,7 +52,6 @@ sub send { $return = 0 if $result eq 'Report received'; } catch { my $e = $_; - print "Caught an error: $e\n"; $self->error( "Error sending to East Hants: $e" ); }; $self->success( !$return ); diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm deleted file mode 100644 index b5faf8ddc..000000000 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ /dev/null @@ -1,56 +0,0 @@ -package FixMyStreet::SendReport::EmptyHomes; - -use Moo; -use namespace::autoclean; - -use mySociety::MaPit; - -BEGIN { extends 'FixMyStreet::SendReport::Email'; } - -sub build_recipient_list { - my ( $self, $row, $h ) = @_; - - my $all_confirmed = 1; - foreach my $body ( @{ $self->bodies } ) { - my $contact = $row->result_source->schema->resultset("Contact")->find( { - deleted => 0, - body_id => $body->id, - category => 'Empty property', - } ); - - my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); - - unless ($confirmed) { - $all_confirmed = 0; - #$note = 'Council ' . $row->body . ' deleted' - #unless $note; - $body_email = 'N/A' unless $body_email; - #$notgot{$body_email}{$row->category}++; - #$note{$body_email}{$row->category} = $note; - } - - push @{ $self->to }, [ $body_email, $body->name ]; - - my $area_info = mySociety::MaPit::call('area', $body->body_areas->first->area_id); - my $country = $area_info->{country}; - if ($country eq 'W') { - push @{$self->bcc}, 'wales@' . FixMyStreet->config('EMAIL_DOMAIN'); - } elsif ($country eq 'S') { - push @{$self->bcc}, 'scotland@' . FixMyStreet->config('EMAIL_DOMAIN'); - } else { - push @{$self->bcc}, 'eha@' . FixMyStreet->config('EMAIL_DOMAIN'); - } - } - - # Set address email parameter from added data - $h->{address} = $row->extra->{address}; - - return $all_confirmed && @{$self->to}; -} - -sub get_template { - my ( $self, $row ) = @_; - return Utils::read_file( FixMyStreet->path_to( "templates", "email", "emptyhomes", $row->lang, "submit.txt" )->stringify ); -} - -1; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index 4844aa2e9..bf5ed3e30 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -126,8 +126,8 @@ sub send { $revert = 1; } - if ($row->cobrand eq 'fixmybarangay' || $row->bodies_str =~ /$COUNCIL_ID_GREENWICH/) { - # FixMyBarangay endpoints expect external_id as an attribute, as do Greenwich + if ($row->bodies_str =~ /$COUNCIL_ID_GREENWICH/) { + # Greenwich endpoint expects external_id as an attribute $row->set_extra_fields( { 'name' => 'external_id', 'value' => $row->id } ); $revert = 1; } @@ -144,14 +144,11 @@ sub send { $self->success( 1 ); } else { $result *= 1; - # temporary fix to resolve some issues with west berks - if ( $row->bodies_str =~ /2619/ ) { - $result *= 0; - } + $self->error( "Failed to send over Open311\n" ) unless $self->error; + $self->error( $self->error . "\n" . $open311->error ); } } - $self->error( 'Failed to send over Open311' ) unless $self->success; return $result; } |