diff options
-rwxr-xr-x | bin/send-reports | 68 | ||||
-rw-r--r-- | perllib/BarnetWSDL.pm | 105 |
2 files changed, 172 insertions, 1 deletions
diff --git a/bin/send-reports b/bin/send-reports index 22bd12732..61aad69e7 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -21,6 +21,7 @@ use CronFns; use FixMyStreet::App; +use BarnetWSDL; use EastHantsWSDL; use Utils; use mySociety::Config; @@ -30,6 +31,10 @@ use mySociety::Web qw(ent); use Open311; +# specific council numbers +use constant COUNCIL_ID_BARNET => 2489; +use constant COUNCIL_ID_EAST_HANTS => 2330; + # Set up site, language etc. my ($verbose, $nomail) = CronFns::options(); my $base_url = mySociety::Config::get('BASE_URL'); @@ -133,9 +138,12 @@ while (my $row = $unsent->next) { foreach my $council (@councils) { my $name = $areas_info->{$council}->{name}; push @dear, $name; - if ($council == 2330) { # E. Hants have a web service + if ($council == COUNCIL_ID_EAST_HANTS) { # E. Hants have a web service $send_web = 'easthants'; $h{category} = 'Customer Services' if $h{category} eq 'Other'; + } elsif ($council == COUNCIL_ID_BARNET) { # Barnet have a web service + $send_web = 'barnet'; + $h{category} = 'BARNET CRM'; # FIXME force category (by arrangement with Barnet) } elsif ($areas_info->{$council}->{type} eq 'LBO') { # London $send_web = 'london'; } elsif ( my $endpoint = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first ) { @@ -248,6 +256,11 @@ while (my $row = $unsent->next) { if (!$nomail) { $result *= post_easthants_message(%h); } + } elsif ($send_web eq 'barnet') { + $h{message} = construct_barnet_message(%h); + if (!$nomail) { + $result *= post_barnet_message(%h); + } } elsif ($send_web eq 'london') { $h{message} = construct_london_message(%h); if (!$nomail) { @@ -390,6 +403,59 @@ sub post_easthants_message { return $return; } +# TODO: currently just blind copy of construct_easthants_message, normally all Barnet reports will go via the web service (?) +sub construct_barnet_message { + my %h = @_; + my $message = ''; + $message .= "[ This report was also sent to the district council covering the location of the problem, as the user did not categorise it; please ignore if you're not the correct council to deal with the issue. ]\n\n" + if $h{multiple}; + $message .= <<EOF; +Subject: $h{title} + +Details: $h{detail} + +$h{fuzzy}, or to provide an update on the problem, please visit the following link: + +$h{url} + +$h{closest_address} +EOF + return $message; +} + +my $barnet_service; +sub post_barnet_message { + my %h = @_; + my $return = 1; + $barnet_service ||= BarnetWSDL->on_fault(sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, "\n"; }); + try { + my $kbid = $h{category}; # TODO: KBID is 50-char category ID: map our category -> Barnet KBID + # TODO: certainly won't validate until we are using KBID values provided by Barnet + my $message = ent(encode_utf8($h{message})); + my $name = ent(encode_utf8($h{name})); + my $location = $h{easting_northing}; # TODO: need to construct complex type for this: it's actually GEOCODE within BAPI_TTET_ADDRESS_COM: + # comprising: COUNTRY2, REGION, COUNTY, CITY, POSTALCODE, STREET, STREETNUMBER, GEOCODE + + # TODO: username/password authentication will be required to access the webservice + + my $result = $barnet_service->Z_CRM_SERVICE_ORDER_CREATE( + '', # ET_RETURN (?) + $message, # IT_PROBLEM_DESC (SAP defines this as a table of text lines: might need this broken up?) + $h{email}, # IV_CUST_EMAIL + $name, # IV_CUST_NAME + $kbid, # IV_KBID + $h{id}, # IV_PROBLEM_ID + $location, # IV_PROBLEM_LOC (see above) + '', # IV_PROBLEM_SUB (?) + ); + $return = 0 if $result eq 'Report received'; + } otherwise { + my $e = shift; + print "Caught an error: $e\n"; # anticipate: DUPLICATE_ORDER + }; + return $return; +} + # London sub construct_london_message { diff --git a/perllib/BarnetWSDL.pm b/perllib/BarnetWSDL.pm new file mode 100644 index 000000000..842e55c40 --- /dev/null +++ b/perllib/BarnetWSDL.pm @@ -0,0 +1,105 @@ +package BarnetWSDL; + +# Generated by SOAP::Lite (v0.710.08) for Perl -- soaplite.com +# Copyright (C) 2000-2006 Paul Kulchenko, Byrne Reese +# -- generated at [Fri Apr 1 16:57:04 2011] +# -- generated from http://fury.ukcod.org.uk/~dave/barnet_wsdl_2.xml (provided by email from Logica) + +my %methods = ( +Z_CRM_SERVICE_ORDER_CREATE => { + endpoint => 'http://lbbcrmdev.barnet.gov.uk:8000/sap/bc/srt/rfc/sap/zlbb_service_order/200/zlbb_service_order/zlbb_service_order', + soapaction => '', + namespace => 'urn:sap-com:document:sap:rfc:functions', + parameters => [ + SOAP::Data->new(name => 'ET_RETURN', type => 'tns:TABLE_OF_BAPIRET2', attr => {}), + SOAP::Data->new(name => 'IT_PROBLEM_DESC', type => 'tns:TABLE_OF_CRMT_SERVICE_REQUEST_TEXT', attr => {}), + SOAP::Data->new(name => 'IV_CUST_EMAIL', type => 'tns:char241', attr => {}), + SOAP::Data->new(name => 'IV_CUST_NAME', type => 'tns:char50', attr => {}), + SOAP::Data->new(name => 'IV_KBID', type => 'tns:char50', attr => {}), + SOAP::Data->new(name => 'IV_PROBLEM_ID', type => 'tns:char35', attr => {}), + SOAP::Data->new(name => 'IV_PROBLEM_LOC', type => 'tns:BAPI_TTET_ADDRESS_COM', attr => {}), + SOAP::Data->new(name => 'IV_PROBLEM_SUB', type => 'tns:char40', attr => {}), + ], # end parameters + }, # end Z_CRM_SERVICE_ORDER_CREATE +); # end my %methods + +use SOAP::Lite; +use Exporter; +use Carp (); + +use vars qw(@ISA $AUTOLOAD @EXPORT_OK %EXPORT_TAGS); +@ISA = qw(Exporter SOAP::Lite); +@EXPORT_OK = (keys %methods); +%EXPORT_TAGS = ('all' => [@EXPORT_OK]); + +sub _call { + my ($self, $method) = (shift, shift); + my $name = UNIVERSAL::isa($method => 'SOAP::Data') ? $method->name : $method; + my %method = %{$methods{$name}}; + $self->proxy($method{endpoint} || Carp::croak "No server address (proxy) specified") + unless $self->proxy; + my @templates = @{$method{parameters}}; + my @parameters = (); + foreach my $param (@_) { + if (@templates) { + my $template = shift @templates; + my ($prefix,$typename) = SOAP::Utils::splitqname($template->type); + my $method = 'as_'.$typename; + # TODO - if can('as_'.$typename) {...} + my $result = $self->serializer->$method($param, $template->name, $template->type, $template->attr); + push(@parameters, $template->value($result->[2])); + } + else { + push(@parameters, $param); + } + } + $self->endpoint($method{endpoint}) + ->ns($method{namespace}) + ->on_action(sub{qq!"$method{soapaction}"!}); + $self->serializer->register_ns("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd","wsu"); + $self->serializer->register_ns("http://schemas.xmlsoap.org/ws/2004/09/policy","wsp"); + $self->serializer->register_ns("http://schemas.xmlsoap.org/wsdl/mime/","mime"); + $self->serializer->register_ns("http://schemas.xmlsoap.org/wsdl/soap/","soap"); + $self->serializer->register_ns("http://schemas.xmlsoap.org/wsdl/","wsdl"); + $self->serializer->register_ns("http://schemas.xmlsoap.org/wsdl/http/","http"); + $self->serializer->register_ns("http://www.w3.org/2001/XMLSchema","xsd"); + $self->serializer->register_ns("urn:sap-com:document:sap:rfc:functions","tns"); + my $som = $self->SUPER::call($method => @parameters); + if ($self->want_som) { + return $som; + } + UNIVERSAL::isa($som => 'SOAP::SOM') ? wantarray ? $som->paramsall : $som->result : $som; +} + +sub BEGIN { + no strict 'refs'; + for my $method (qw(want_som)) { + my $field = '_' . $method; + *$method = sub { + my $self = shift->new; + @_ ? ($self->{$field} = shift, return $self) : return $self->{$field}; + } + } +} +no strict 'refs'; +for my $method (@EXPORT_OK) { + my %method = %{$methods{$method}}; + *$method = sub { + my $self = UNIVERSAL::isa($_[0] => __PACKAGE__) + ? ref $_[0] + ? shift # OBJECT + # CLASS, either get self or create new and assign to self + : (shift->self || __PACKAGE__->self(__PACKAGE__->new)) + # function call, either get self or create new and assign to self + : (__PACKAGE__->self || __PACKAGE__->self(__PACKAGE__->new)); + $self->_call($method, @_); + } +} + +sub AUTOLOAD { + my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::') + 2); + return if $method eq 'DESTROY' || $method eq 'want_som'; + die "Unrecognized method '$method'. List of available method(s): @EXPORT_OK\n"; +} + +1; |