diff options
-rw-r--r-- | perllib/Open311/Endpoint/Integration/Exor.pm | 67 | ||||
-rw-r--r-- | perllib/Open311/Endpoint/Integration/Warwick.pm | 38 | ||||
-rw-r--r-- | t/open311/endpoint/Endpoint_Warwick.pm | 5 | ||||
-rw-r--r-- | t/open311/endpoint/exor/DBD/Oracle.pm | 8 | ||||
-rw-r--r-- | t/open311/endpoint/warwick.t | 374 | ||||
-rw-r--r-- | t/open311/endpoint/warwick_dbd.t | 17 |
6 files changed, 291 insertions, 218 deletions
diff --git a/perllib/Open311/Endpoint/Integration/Exor.pm b/perllib/Open311/Endpoint/Integration/Exor.pm index 5e0077c3e..0d5264115 100644 --- a/perllib/Open311/Endpoint/Integration/Exor.pm +++ b/perllib/Open311/Endpoint/Integration/Exor.pm @@ -6,6 +6,7 @@ with 'Open311::Endpoint::Role::ConfigFile'; use DBI; use MooX::HandlesVia; use DateTime::Format::Oracle; # default format 'YYYY-MM-DD HH24:MI:SS' # NB: hh24 (not hh) +use Encode qw(from_to); # declare our constants, as we may not be able to easily install DBD::Oracle # on a development system! @@ -14,7 +15,9 @@ use DateTime::Format::Oracle; # default format 'YYYY-MM-DD HH24:MI:SS' # NB: hh2 sub ORA_DATE (); sub ORA_NUMBER (); sub ORA_VARCHAR2 (); +no warnings 'redefine'; use DBD::Oracle qw(:ora_types); + BEGIN { *ORA_DATE = *ORA_NUMBER = *ORA_VARCHAR2 = sub () { 1 } unless $DBD::Oracle::VERSION; @@ -22,7 +25,10 @@ BEGIN { has ora_dt => ( is => 'lazy', - default => sub { 'DateTime::Format::Oracle' }, + default => sub { + $ENV{NLS_DATE_FORMAT} = 'YYYY-MM-DD HH24:MI'; + return 'DateTime::Format::Oracle' + }, # NB: we just return the class name. This is to smooth over odd API, # for consistency with w3_dt ); @@ -43,6 +49,11 @@ has max_limit => ( default => 1000, ); +has encode_to_win1252 => ( + is => 'ro', + default => 1, +); + has _connection_details => ( is => 'lazy', default => sub { @@ -104,6 +115,36 @@ has testing => ( default => 0, ); +has ce_cat => ( + is => 'ro', + default => 'DEF', +); + +has ce_class => ( + is => 'ro', + default => 'N/A', +); + +has ce_cpr_id => ( + is => 'ro', + default => 5, +); + +has ce_contact_type => ( + is => 'ro', + default => 'PU', +); + +has ce_status_code => ( + is => 'ro', + default => 'RE', +); + +has ce_compl_user_type => ( + is => 'ro', + default => 'USER', +); + #------------------------------------------------------------------ # pem_field_types # return hash of types by field name: any not explicitly set here @@ -152,11 +193,8 @@ sub pem_field_type { } -sub sanitize_text { - my ($self, $text) = @_; -} - sub services { + # not currently used as Warwick.pm uses a hardcoded list. die "TODO"; } @@ -187,7 +225,6 @@ sub strip { $text = _strip_ruthless($text); } } - # from_to($s, 'utf8', 'Windows-1252') if $ENCODE_TO_WIN1252; # separate into own method return $max_len ? substr($text, 0, $max_len) : $text; } @@ -212,16 +249,17 @@ sub post_service_request { my %bindings; # comments here are suggested values # field lengths are from OCC's Java portlet - # fixed values - $bindings{":ce_cat"} = 'REQS'; # or REQS ? - $bindings{":ce_class"} = 'SERV'; # 'FRML' ? - $bindings{":ce_contact_type"} = 'ENQUIRER'; # 'ENQUIRER' - $bindings{":ce_status_code"} = 'RE'; # RE=received (?) - $bindings{":ce_compl_user_type"}= 'USER'; # 'USER' + # fixed values (configurable via config) + $bindings{":ce_cat"} = $self->ce_cat; + $bindings{":ce_class"} = $self->ce_class; + $bindings{":ce_contact_type"} = $self->ce_contact_type; + $bindings{":ce_status_code"} = $self->ce_status_code; + $bindings{":ce_compl_user_type"}= $self->ce_compl_user_type; + $bindings{":ce_cpr_id"} = $self->ce_cpr_id; # ce_incident_datetime is *not* an optional param, but FMS isn't sending it at the moment $bindings{":ce_incident_datetime"}=$args->{requested_datetime} - || $self->w3_dt->format_datetime( DateTime->now ); + || $self->ora_dt->format_datetime( DateTime->now ); # especially FMS-specific: $bindings{":ce_source"} = "FMS"; # important, and specific to this script! @@ -287,6 +325,7 @@ sub insert_into_db { PEM.create_enquiry( ce_cat => :ce_cat, ce_class => :ce_class, + ce_cpr_id => :ce_cpr_id, ce_forename => :ce_forename, ce_surname => :ce_surname, ce_contact_type => :ce_contact_type, @@ -328,8 +367,6 @@ sub insert_into_db { # $sth->bind_param(":ce_building_name", $undef); # 'CLIFTON HEIGHTS' # $sth->bind_param(":ce_street", $undef); # 'HIGH STREET' # $sth->bind_param(":ce_town", $undef); # 'BRSITOL' - # $sth->bind_param(":ce_enquiry_type", $undef); # 'CD' , ce_source => 'T' - # $sth->bind_param(":ce_cpr_id", $undef); # '5' (priority) # $sth->bind_param(":ce_rse_he_id", $undef); #> nm3net.get_ne_id('1200D90970/09001','L') # $sth->bind_param(":ce_compl_target", $undef); # '08-JAN-2004' # $sth->bind_param(":ce_compl_corresp_date",$undef); # '02-JAN-2004' diff --git a/perllib/Open311/Endpoint/Integration/Warwick.pm b/perllib/Open311/Endpoint/Integration/Warwick.pm index 0680f7ba1..bc57a8e8c 100644 --- a/perllib/Open311/Endpoint/Integration/Warwick.pm +++ b/perllib/Open311/Endpoint/Integration/Warwick.pm @@ -10,26 +10,26 @@ has '+default_service_notice' => ( sub services { # TODO, get this from ::Exor my @services = ( - [ BR => 'Bridges' ], - [ CD => 'Carriageway Defect' ], - [ CD => 'Roads/Highways' ], - [ DR => 'Drainage' ], - [ DS => 'Debris/Spillage' ], - [ FE => 'Fences' ], - [ 'F D' => 'Pavements' ], - [ GC => 'Gully & Catchpits' ], - [ IS => 'Ice/Snow' ], - [ MD => 'Mud & Debris' ], - [ MH => 'Manhole' ], - [ OS => 'Oil Spillage' ], - [ OT => 'Other' ], + # [ BR => 'Bridges' ], + # [ CD => 'Carriageway Defect' ], + # [ CD => 'Roads/Highways' ], + # [ DR => 'Drainage' ], + # [ DS => 'Debris/Spillage' ], + # [ FE => 'Fences' ], + # [ 'F D' => 'Pavements' ], + # [ GC => 'Gully & Catchpits' ], + # [ IS => 'Ice/Snow' ], + # [ MD => 'Mud & Debris' ], + # [ MH => 'Manhole' ], + # [ OS => 'Oil Spillage' ], + # [ OT => 'Other' ], [ PO => 'Pothole' ], - [ PD => 'Property Damage' ], - [ RM => 'Road Marking' ], - [ SN => 'Road traffic signs' ], - [ SP => 'Traffic' ], - [ UT => 'Utilities' ], - [ VG => 'Vegetation' ], + # [ PD => 'Property Damage' ], + # [ RM => 'Road Marking' ], + # [ SN => 'Road traffic signs' ], + # [ SP => 'Traffic' ], + # [ UT => 'Utilities' ], + # [ VG => 'Vegetation' ], ); return map { my ($code, $name) = @$_; diff --git a/t/open311/endpoint/Endpoint_Warwick.pm b/t/open311/endpoint/Endpoint_Warwick.pm index f4710f63b..c097f177e 100644 --- a/t/open311/endpoint/Endpoint_Warwick.pm +++ b/t/open311/endpoint/Endpoint_Warwick.pm @@ -1,11 +1,6 @@ package t::open311::endpoint::Endpoint_Warwick; use Web::Simple; -use Module::Loaded; -BEGIN { - mark_as_loaded('DBD::Oracle'); -} - our %BINDINGS; our $UPDATES_SQL; diff --git a/t/open311/endpoint/exor/DBD/Oracle.pm b/t/open311/endpoint/exor/DBD/Oracle.pm new file mode 100644 index 000000000..d84580d10 --- /dev/null +++ b/t/open311/endpoint/exor/DBD/Oracle.pm @@ -0,0 +1,8 @@ +package DBD::Oracle; # test +use strict; use warnings; + +sub ORA_DATE () { 2 }; +sub ORA_NUMBER () { 3 } ; +sub ORA_VARCHAR2 () { 5 }; + +1; diff --git a/t/open311/endpoint/warwick.t b/t/open311/endpoint/warwick.t index 8d0b7284b..e144b745a 100644 --- a/t/open311/endpoint/warwick.t +++ b/t/open311/endpoint/warwick.t @@ -8,7 +8,12 @@ use Data::Dumper; use JSON; use FixMyStreet::App; + +use Module::Loaded; +BEGIN { mark_as_loaded('DBD::Oracle') } + use t::open311::endpoint::Endpoint_Warwick; + use LWP::Protocol::PSGI; use Open311::PopulateServiceList; use Open311::GetServiceRequestUpdates; @@ -23,123 +28,6 @@ subtest "GET Service List" => sub { <?xml version="1.0" encoding="utf-8"?> <services> <service> - <description>Bridges</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>BR</service_code> - <service_name>Bridges</service_name> - <type>realtime</type> - </service> - <service> - <description>Carriageway Defect</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>CD</service_code> - <service_name>Carriageway Defect</service_name> - <type>realtime</type> - </service> - <service> - <description>Roads/Highways</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>CD</service_code> - <service_name>Roads/Highways</service_name> - <type>realtime</type> - </service> - <service> - <description>Drainage</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>DR</service_code> - <service_name>Drainage</service_name> - <type>realtime</type> - </service> - <service> - <description>Debris/Spillage</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>DS</service_code> - <service_name>Debris/Spillage</service_name> - <type>realtime</type> - </service> - <service> - <description>Fences</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>FE</service_code> - <service_name>Fences</service_name> - <type>realtime</type> - </service> - <service> - <description>Pavements</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>F D</service_code> - <service_name>Pavements</service_name> - <type>realtime</type> - </service> - <service> - <description>Gully & Catchpits</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>GC</service_code> - <service_name>Gully & Catchpits</service_name> - <type>realtime</type> - </service> - <service> - <description>Ice/Snow</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>IS</service_code> - <service_name>Ice/Snow</service_name> - <type>realtime</type> - </service> - <service> - <description>Mud & Debris</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>MD</service_code> - <service_name>Mud & Debris</service_name> - <type>realtime</type> - </service> - <service> - <description>Manhole</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>MH</service_code> - <service_name>Manhole</service_name> - <type>realtime</type> - </service> - <service> - <description>Oil Spillage</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>OS</service_code> - <service_name>Oil Spillage</service_name> - <type>realtime</type> - </service> - <service> - <description>Other</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>OT</service_code> - <service_name>Other</service_name> - <type>realtime</type> - </service> - <service> <description>Pothole</description> <group>highways</group> <keywords></keywords> @@ -148,60 +36,6 @@ subtest "GET Service List" => sub { <service_name>Pothole</service_name> <type>realtime</type> </service> - <service> - <description>Property Damage</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>PD</service_code> - <service_name>Property Damage</service_name> - <type>realtime</type> - </service> - <service> - <description>Road Marking</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>RM</service_code> - <service_name>Road Marking</service_name> - <type>realtime</type> - </service> - <service> - <description>Road traffic signs</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>SN</service_code> - <service_name>Road traffic signs</service_name> - <type>realtime</type> - </service> - <service> - <description>Traffic</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>SP</service_code> - <service_name>Traffic</service_name> - <type>realtime</type> - </service> - <service> - <description>Utilities</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>UT</service_code> - <service_name>Utilities</service_name> - <type>realtime</type> - </service> - <service> - <description>Vegetation</description> - <group>highways</group> - <keywords></keywords> - <metadata>true</metadata> - <service_code>VG</service_code> - <service_name>Vegetation</service_name> - <type>realtime</type> - </service> </services> XML is $res->content, $expected @@ -237,18 +71,19 @@ subtest "POST OK" => sub { ':ce_y' => '100', ':ce_x' => '100', ':ce_work_phone' => '', - ':ce_contact_type' => 'ENQUIRER', + ':ce_contact_type' => 'PU', ':ce_source' => 'FMS', ':ce_doc_reference' => '1001', ':ce_enquiry_type' => 'PO', ':ce_email' => '', ':ce_description' => '', ':ce_location' => '22 Acacia Avenue', - ':ce_incident_datetime' => '2014-01-01T12:00:00Z', - ':ce_class' => 'SERV', + ':ce_incident_datetime' => '2014-01-01 12:00', + ':ce_class' => 'N/A', + ':ce_cpr_id' => 5, ':ce_compl_user_type' => 'USER', ':ce_status_code' => 'RE', - ':ce_cat' => 'REQS', + ':ce_cat' => 'DEF', ':ce_forename' => 'BOB' }, 'bindings as expected'; @@ -280,11 +115,11 @@ SELECT * FROM ( SELECT row_id, service_request_id, - to_char(updated_timedate, 'YYYY-MM-DD HH24:MI:SS'), + to_char(updated_timedate, 'YYYY-MM-DD HH24:MI'), status, description FROM higatlas.fms_update - WHERE updated_timedate >= to_date(2013-12-31 12:00:00, YYYY-MM-DD HH24:MI:SS) AND (status='OPEN' OR status='CLOSED') + WHERE updated_timedate >= to_date(2013-12-31 12:00, YYYY-MM-DD HH24:MI) AND (status='OPEN' OR status='CLOSED') ORDER BY updated_timedate DESC) WHERE ROWNUM <= 1000 SQL @@ -343,7 +178,7 @@ subtest "End to end" => sub { my $p = Open311::PopulateServiceList->new( bodies => $bodies, verbose => 0 ); $p->process_bodies; - is $body->contacts->count, 19, 'Categories imported from Open311'; + is $body->contacts->count, 1, 'Categories imported from Open311'; }; set_fixed_time('2014-07-20T15:05:00Z'); @@ -378,7 +213,14 @@ subtest "End to end" => sub { ALLOWED_COBRANDS => [ 'fixmystreet' ], SEND_REPORTS_ON_STAGING => 1, }, sub { - self_rs($problem)->send_reports; + ## we can't (yet) just do following due to + ## https://github.com/mysociety/fixmystreet/issues/893 + # self_rs($problem)->send_reports; + + ## instead, as we are in a transaction, we'll just delete everything else. + my $rs = FixMyStreet::App->model('DB::Problem'); + $rs->search({ id => { '!=', $problem->id } })->delete; + $rs->send_reports; }; $problem->discard_changes; @@ -425,3 +267,177 @@ sub self_rs { # create a result-set with just this body (see also DBIx::Class::Helper::Row::SelfResultSet) return $row->result_source->resultset->search( $row->ident_condition ); } + +__END__ + <service> + <description>Bridges</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>BR</service_code> + <service_name>Bridges</service_name> + <type>realtime</type> + </service> + <service> + <description>Carriageway Defect</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>CD</service_code> + <service_name>Carriageway Defect</service_name> + <type>realtime</type> + </service> + <service> + <description>Roads/Highways</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>CD</service_code> + <service_name>Roads/Highways</service_name> + <type>realtime</type> + </service> + <service> + <description>Drainage</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>DR</service_code> + <service_name>Drainage</service_name> + <type>realtime</type> + </service> + <service> + <description>Debris/Spillage</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>DS</service_code> + <service_name>Debris/Spillage</service_name> + <type>realtime</type> + </service> + <service> + <description>Fences</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>FE</service_code> + <service_name>Fences</service_name> + <type>realtime</type> + </service> + <service> + <description>Pavements</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>F D</service_code> + <service_name>Pavements</service_name> + <type>realtime</type> + </service> + <service> + <description>Gully & Catchpits</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>GC</service_code> + <service_name>Gully & Catchpits</service_name> + <type>realtime</type> + </service> + <service> + <description>Ice/Snow</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>IS</service_code> + <service_name>Ice/Snow</service_name> + <type>realtime</type> + </service> + <service> + <description>Mud & Debris</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>MD</service_code> + <service_name>Mud & Debris</service_name> + <type>realtime</type> + </service> + <service> + <description>Manhole</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>MH</service_code> + <service_name>Manhole</service_name> + <type>realtime</type> + </service> + <service> + <description>Oil Spillage</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>OS</service_code> + <service_name>Oil Spillage</service_name> + <type>realtime</type> + </service> + <service> + <description>Other</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>OT</service_code> + <service_name>Other</service_name> + <type>realtime</type> + </service> + + <service> + <description>Property Damage</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>PD</service_code> + <service_name>Property Damage</service_name> + <type>realtime</type> + </service> + <service> + <description>Road Marking</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>RM</service_code> + <service_name>Road Marking</service_name> + <type>realtime</type> + </service> + <service> + <description>Road traffic signs</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>SN</service_code> + <service_name>Road traffic signs</service_name> + <type>realtime</type> + </service> + <service> + <description>Traffic</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>SP</service_code> + <service_name>Traffic</service_name> + <type>realtime</type> + </service> + <service> + <description>Utilities</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>UT</service_code> + <service_name>Utilities</service_name> + <type>realtime</type> + </service> + <service> + <description>Vegetation</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>VG</service_code> + <service_name>Vegetation</service_name> + <type>realtime</type> + </service> diff --git a/t/open311/endpoint/warwick_dbd.t b/t/open311/endpoint/warwick_dbd.t new file mode 100644 index 000000000..9120c6467 --- /dev/null +++ b/t/open311/endpoint/warwick_dbd.t @@ -0,0 +1,17 @@ +use strict; use warnings; + +=head1 NAME + +warwick_dbd.t - test that Oracle constants can be imported if present + +=cut + +use Test::More; + +use lib 't/open311/endpoint/exor/'; + +use DBD::Oracle; # fake from above test lib (or real if installed) +use t::open311::endpoint::Endpoint_Warwick; + +ok 1; +done_testing; |