Bug 11491

Summary: Extending report service to be annotated
Product: Koha Reporter: Mark Tompsett <mtompset>
Component: Web servicesAssignee: Mark Tompsett <mtompset>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: chris, dcook, gmcharlt, h.meissner.82, katrin.fischer, kyle
Version: master   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 11491 - Old License and strict, warnings
Bug 11491 - Missing header fields in JSON data
Bug 11491 - Old License and strict, warnings
Bug 11491 - Missing header fields in JSON data
Bug 11491 - Old License and strict, warnings
Bug 11491 - Missing field names in JSON data
Bug 11491 - Old License and strict, warnings
Bug 11491 - Missing field names in JSON data
Bug 11491 - Old License and strict, warnings
Bug 11491 - Missing field names in JSON data
Bug 11491 - Old License and strict, warnings
Bug 11491 - Old License and strict, warnings
Bug 11491 - Missing field names in JSON data
Bug 11491 - Old License and strict, warnings
24923: Bug 11491 - Missing field names in JSON data
24924: Bug 11491 - Old License and strict, warnings

Description Mark Tompsett 2014-01-07 23:22:54 UTC
The report service URL generates JSON, but has no header information. It would be nice to have:
    https://.../cgi-bin/koha/svc/report?id=15
Return just the JSON with no header entry, and:
    https://.../cgi-bin/koha/svc/report?id=15&header=1
Return the JSON with the first entry as a header entry.

And while I'm at it, I'll update the license and strict/warnings to Modern::Perl.
Comment 1 Mark Tompsett 2014-01-07 23:37:45 UTC Comment hidden (obsolete)
Comment 2 Mark Tompsett 2014-01-07 23:39:21 UTC Comment hidden (obsolete)
Comment 3 Mark Tompsett 2014-01-07 23:39:23 UTC Comment hidden (obsolete)
Comment 4 Holger Meißner 2014-01-30 14:51:34 UTC
In the test plans, did you mean:
https://.../cgi-bin/koha/opac/svc/report?id=##

Not:
https://.../cgi-bin/koha/svc/report?id=##
?

Or should kohaclone/svc/report also add headers?
Comment 5 Mark Tompsett 2014-01-30 19:56:51 UTC
The ... is the OPAC reference, so the svc maps accordingly based on the Apache configuration.

There is no reason to do it for the staff client, since I don't expect people to try to make public reports run from the staff client.
Comment 6 Katrin Fischer 2014-01-30 21:33:42 UTC
Is there a reason that private reports should not have headers? :)
Comment 7 Katrin Fischer 2014-01-30 21:43:21 UTC
Hm, I just double checked - it's possible to run the report from the staff URL, so you will only get access to the data when you are logged in. I can see use cases for that when you want to make sensitive data available to another service.
I think it would make sense to add the headers to both.

Example URL:
<staffurl>/cgi-bin/koha/svc/report?id=3
Comment 8 Mark Tompsett 2014-01-30 22:27:13 UTC Comment hidden (obsolete)
Comment 9 Mark Tompsett 2014-01-30 22:27:20 UTC Comment hidden (obsolete)
Comment 10 Chris Cormack 2014-01-30 22:38:42 UTC
I think changing it to be

my $lines     = $sth->fetchall_arrayref({});

Which hands back an array of hashrefs is nicer, the JSON output of it is also a lot nicer and a lot easier to deal with in Javascript.

Shall I do a counter patch?
Comment 11 Mark Tompsett 2014-01-31 03:31:05 UTC Comment hidden (obsolete)
Comment 12 Mark Tompsett 2014-01-31 03:31:16 UTC Comment hidden (obsolete)
Comment 13 Mark Tompsett 2014-01-31 03:51:42 UTC Comment hidden (obsolete)
Comment 14 Mark Tompsett 2014-01-31 03:51:49 UTC Comment hidden (obsolete)
Comment 15 Mark Tompsett 2014-01-31 04:13:15 UTC
Created attachment 24915 [details] [review]
Bug 11491 - Missing field names in JSON data

Added a parameter (annotated), which when non-empty will generate
an array of hashes that include the field names as keys, not
the typical array of field values, for the JSON output.

Added functionality to staff svc/report as well.

Moved code around to make diffs between svc/report and
opac/svc/report smaller.

TEST PLAN
---------
 1) Log into staff client
 2) Reports
 3) Used save reports
 4) Click the Action button on any report
     WITHOUT PARAMETERS.
    -- with parameters blows up in master and this.
 5) Click Edit
 6) Make the report public
 7) Update the SQL
 8) Note the ID number of the report
 9) Note the ID number of a non-public report
10) Make up a crazy ID number for a non-existant report
11) In a new tab (with the appropriate edits)
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 8
    -- JSON data has arrays of field values.
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 8&annotated=1
    -- JSON data has arrays of field values.
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 9
    -- Software error: Sorry this report is not public
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 9&annotated=1
    -- Software error: Sorry this report is not public
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 10
    -- Software error: Sorry this report is not public
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 10&annotated=1
    -- Software error: Sorry this report is not public
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 8
    -- JSON data has arrays of field values.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 8&annotated=1
    -- JSON data has arrays of field values.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 9
    -- JSON data has arrays of field values.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 9&annotated=1
    -- JSON data has arrays of field values.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 10
    -- Software error: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /usr/share/perl5/JSON.pm line 154.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 10&annotated=1
    -- Software error: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /usr/share/perl5/JSON.pm line 154.

12) Apply the patch
13) ~/qa-test-tools/koha-qa.pl -v 2 -c 2
    -- There should be no problems. All OK.

14) In a new tab (with the appropriate edits)
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 8
    -- JSON data has arrays of field values.
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 8&annotated=1
    -- JSON data has arrays of hashes with field names as keys
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 9
    -- Software error: Sorry this report is not public
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 9&annotated=1
    -- Software error: Sorry this report is not public
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 10
    -- Software error: There is no such report.
     https://OPAC/cgi-bin/koha/svc/report?id=# from step 10&annotated=1
    -- Software error: There is no such report.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 8
    -- JSON data has arrays of field values.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 8&annotated=1
    -- JSON data has arrays of hashes with field names as keys
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 9
    -- JSON data has arrays of field values.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 9&annotated=1
    -- JSON data has arrays of hashes with field names as keys
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 10
    -- Software error: There is no such report.
     https://STAFF/cgi-bin/koha/svc/report?id=# from step 10&annotated=1
    -- Software error: There is no such report.
Comment 16 Mark Tompsett 2014-01-31 04:13:20 UTC Comment hidden (obsolete)
Comment 17 Mark Tompsett 2014-01-31 04:14:50 UTC Comment hidden (obsolete)
Comment 18 Mark Tompsett 2014-01-31 04:15:43 UTC
Test plans for each patch are in the patch. See comment 15 and comment 17.
Comment 19 Holger Meißner 2014-01-31 10:01:06 UTC Comment hidden (obsolete)
Comment 20 Holger Meißner 2014-01-31 10:01:10 UTC Comment hidden (obsolete)
Comment 21 Holger Meißner 2014-01-31 10:08:05 UTC
Works as described.
Comment 22 Kyle M Hall 2014-01-31 17:24:12 UTC
Created attachment 24960 [details] [review]
24923: Bug 11491 - Missing field names in JSON data
Comment 23 Kyle M Hall 2014-01-31 17:24:36 UTC
Created attachment 24961 [details] [review]
24924: Bug 11491 - Old License and strict, warnings
Comment 24 Galen Charlton 2014-01-31 20:32:03 UTC
Pushed to master.  Thanks, Mark!
Comment 25 David Cook 2020-08-24 07:14:23 UTC
*** Bug 26286 has been marked as a duplicate of this bug. ***