aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/Open311')
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm60
-rw-r--r--perllib/Open311/PopulateServiceList.pm2
2 files changed, 46 insertions, 16 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 27cb21c3a..e4416f792 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -11,6 +11,9 @@ has end_date => ( is => 'ro', default => undef );
has suppress_alerts => ( is => 'rw', default => 0 );
has verbose => ( is => 'ro', default => 0 );
+Readonly::Scalar my $AREA_ID_BROMLEY => 2482;
+Readonly::Scalar my $AREA_ID_OXFORDSHIRE => 2237;
+
sub fetch {
my $self = shift;
@@ -31,11 +34,16 @@ sub fetch {
jurisdiction => $body->jurisdiction,
);
- if ( $body->areas->{2482} ) {
+ # custom endpoint URLs because these councils have non-standard paths
+ if ( $body->areas->{$AREA_ID_BROMLEY} ) {
my $endpoints = $o->endpoints;
$endpoints->{update} = 'update.xml';
$endpoints->{service_request_updates} = 'update.xml';
$o->endpoints( $endpoints );
+ } elsif ( $body->areas->{$AREA_ID_OXFORDSHIRE} ) {
+ my $endpoints = $o->endpoints;
+ $endpoints->{service_request_updates} = 'open311_service_request_update.cgi';
+ $o->endpoints( $endpoints );
}
$self->suppress_alerts( $body->suppress_alerts );
@@ -55,7 +63,7 @@ sub update_comments {
push @args, $self->start_date;
push @args, $self->end_date;
# default to asking for last 2 hours worth if not Bromley
- } elsif ( ! $body_details->{areas}->{2482} ) {
+ } elsif ( ! $body_details->{areas}->{$AREA_ID_BROMLEY} ) {
my $end_dt = DateTime->now();
my $start_dt = $end_dt->clone;
$start_dt->add( hours => -2 );
@@ -79,13 +87,15 @@ sub update_comments {
# what problem it belongs to so just skip
next unless $request_id;
- my $problem =
- FixMyStreet::App->model('DB::Problem')
- ->search( {
- external_id => $request_id,
- # XXX This assumes that areas will actually only be one area.
- bodies_str => { like => '%' . join(",", keys %{$body_details->{areas}}) . '%' },
- } );
+ my $problem;
+ my $criteria = { external_id => $request_id };
+ if ($open311->jurisdiction =~ /^fixmybarangay_(dps|dpwh|depw)$/i) { # use jurisdiction (not area_id) for FMB bodies
+ $criteria->{ external_body } = uc $1;
+ } else {
+ # XXX This assumes that areas will actually only be one area.
+ $criteria->{ bodies_str } = { like => '%' . join(",", keys %{$body_details->{areas}}) . '%' };
+ }
+ $problem = FixMyStreet::App->model('DB::Problem')->search( $criteria );
if (my $p = $problem->first) {
my $c = $p->comments->search( { external_id => $request->{update_id} } );
@@ -113,12 +123,14 @@ sub update_comments {
# do not change the status of the problem as it's
# tricky to determine the right thing to do.
if ( $comment->created_local > $p->lastupdate_local ) {
- if ( $p->is_open and lc($request->{status}) eq 'closed' ) {
- $p->state( 'fixed - council' );
- $comment->problem_state( 'fixed - council' );
- } elsif ( ( $p->is_closed || $p->is_fixed ) and lc($request->{status}) eq 'open' ) {
- $p->state( 'confirmed' );
- $comment->problem_state( 'confirmed' );
+ my $state = $self->map_state( $request->{status} );
+
+ # don't update state unless it's an allowed state and it's
+ # actually changing the state of the problem
+ if ( FixMyStreet::DB::Result::Problem->council_states()->{$state} && $p->state ne $state &&
+ !( $p->is_fixed && FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ) ) {
+ $p->state($state);
+ $comment->problem_state($state);
}
}
@@ -146,4 +158,22 @@ sub update_comments {
return 1;
}
+sub map_state {
+ my $self = shift;
+ my $incoming_state = shift;
+
+ $incoming_state = lc($incoming_state);
+ $incoming_state =~ s/_/ /g;
+
+ my %state_map = (
+ fixed => 'fixed - council',
+ 'not councils responsibility' => 'not responsible',
+ 'no further action' => 'unable to fix',
+ open => 'confirmed',
+ closed => 'fixed - council'
+ );
+
+ return $state_map{$incoming_state} || $incoming_state;
+}
+
1;
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index bd90e10e9..57ef90ecb 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -22,6 +22,7 @@ sub process_bodies {
while ( my $body = $self->bodies->next ) {
next unless $body->endpoint;
next unless lc($body->send_method) eq 'open311';
+ next if $body->jurisdiction =~ /^fixmybarangay_\w+$/; # FMB depts. not using service discovery yet
$self->_current_body( $body );
$self->process_body;
}
@@ -29,7 +30,6 @@ sub process_bodies {
sub process_body {
my $self = shift;
-
my $open311 = Open311->new(
endpoint => $self->_current_body->endpoint,
jurisdiction => $self->_current_body->jurisdiction,