Bug 37856

Summary: Some SUSHI providers require the platform parameter
Product: Koha Reporter: Pedro Amorim <pedro.amorim>
Component: ERMAssignee: Pedro Amorim <pedro.amorim>
Status: Pushed to oldoldstable --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: belal.ahmadi, david, fridolin.somers, jonathan.druart, jonathan.field, kamalesh.jp, lucas, martin.renvoize, matt.blenkinsop, michaela.sieber, pedro.amorim
Version: MainKeywords: rel_23_11_candidate
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
This enhancement adds a new "platform" field to ERM's usage data providers, allowing the harvest of SUSHI usage data from providers that require this parameter.
Version(s) released in:
24.11.00,24.05.06,23.11.11
Circulation function:
Bug Depends on: 37963    
Bug Blocks: 37526    
Attachments: Bug 37856: [DONT PUSH] dbic changes
Bug 37856: Append platform parameter to SUSHI url if defined
Bug 37856: atomicupdate
Bug 37856: Add service_platform field
Bug 37856: Consider 'Exceptions' not being part of 'Report_Header'
Bug 37856: Consider absence of 'Report_Items'
Bug 37856: Add tests
Bug 37856: [DONT PUSH] dbic changes
Bug 37856: Append platform parameter to SUSHI url if defined
Bug 37856: atomicupdate
Bug 37856: Add service_platform field
Bug 37856: Consider 'Exceptions' not being part of 'Report_Header'
Bug 37856: Consider absence of 'Report_Items'
Bug 37856: Add tests
Bug 37856: [DONT PUSH] dbic changes
Bug 37856: Append platform parameter to SUSHI url if defined
Bug 37856: atomicupdate
Bug 37856: Add service_platform field
Bug 37856: Consider 'Exceptions' not being part of 'Report_Header'
Bug 37856: Consider absence of 'Report_Items'
Bug 37856: Add tests
Bug 37856: (QA follow-up) Tidy
Bug 37856: Fix existing test
Bug 37856: Add new test to test platform is correctly added to build_url
Bug 37856: Update atomicupdate messages

Description Pedro Amorim 2024-09-06 11:27:34 UTC
The harvest_sushi method produces the following URL when harvesting SUSHI data:
<provider_url>/reports/<report_type>?customer_id=<customer_id>&requestor_id=<requestor_id>&api_key=<api_key>&begin_date=<begin_date>&end_date=<end_date>

Some providers require the 'platform' parameter. Docs here:
https://app.swaggerhub.com/apis/COUNTER/counter-sushi_5_0_api/5.0.2#/default/getReportsPR

We need to look for a way to identify when/if a provider requires this parameter, and add it to the URL if so.

The provider in question is ScienceDirect:
https://registry.countermetrics.org/platform/ab4d3560-1165-491d-a67e-9359d02c2a96

The 'platform parameter required' entry is unchecked even though this provider requires it. We should consider using this to identify if the parameter is required or not.
Comment 1 Pedro Amorim 2024-09-18 16:14:08 UTC
Created attachment 171680 [details] [review]
Bug 37856: [DONT PUSH] dbic changes
Comment 2 Pedro Amorim 2024-09-18 16:14:11 UTC
Created attachment 171681 [details] [review]
Bug 37856: Append platform parameter to SUSHI url if defined
Comment 3 Pedro Amorim 2024-09-18 16:14:14 UTC
Created attachment 171682 [details] [review]
Bug 37856: atomicupdate
Comment 4 Pedro Amorim 2024-09-18 16:14:17 UTC
Created attachment 171683 [details] [review]
Bug 37856: Add service_platform field

The change from this patch itself should be self-explanatory.
Testing for this requires credentials to a specific provider.
But the parameter is only added to the URL if defined.

Test plan, ktd, apply patch, run:
$ yarn js:build
$ yarn api:bundle
$ koha-plack --restart kohadev

1) Enable ERMModule
2) Create a new provider, visit:
<staff_url>/cgi-bin/koha/erm/eusage/usage_data_providers/add
3) Ensure 'Service platform' now shows. Create the provider and put something in this field.
4) View the provider, ensure the field is shown, visit:
<staff_url>/cgi-bin/koha/erm/eusage/usage_data_providers/1

Ensure all tests are still passing:
$ cypress run --spec t/cypress/integration/ERM/DataProviders_spec.ts
$ prove t/db_dependent/api/v1/erm_usage_*
Comment 5 Pedro Amorim 2024-09-19 14:25:52 UTC
Created attachment 171773 [details] [review]
Bug 37856: Consider 'Exceptions' not being part of 'Report_Header'

When fixing the issue around the missing platform parameter, we
noticed this particular provider also returns 'Exceptions' as
its own thing, not part of 'Report_Header', despite documentation:
https://countermetrics.stoplight.io/docs/counter-sushi-api/7cp0h7n1hm2en-tr-j1-journal-requests-controlled

From the link above, search for 'Exceptions'. Notice it should be under 'Report_Header'.
Either way, this patch accounts for this possibility.
Comment 6 Pedro Amorim 2024-09-19 14:25:55 UTC
Created attachment 171774 [details] [review]
Bug 37856: Consider absence of 'Report_Items'

The SUSHI provider in question for this patchset also does not return any
Report_Items entry. This patch accounts for that.
Comment 7 Pedro Amorim 2024-09-19 14:25:58 UTC
Created attachment 171775 [details] [review]
Bug 37856: Add tests

This is using the groundwork from bug 37963.
This is testing the specific error this bug is addressing:
Required parameter Platform is missing

It is also testing that the error message is correctly shown as a background
job report message to the user

Test plan:
prove t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t
Comment 8 David Nind 2024-09-23 20:09:00 UTC
Created attachment 171893 [details] [review]
Bug 37856: [DONT PUSH] dbic changes

Signed-off-by: David Nind <david@davidnind.com>
Comment 9 David Nind 2024-09-23 20:09:04 UTC
Created attachment 171894 [details] [review]
Bug 37856: Append platform parameter to SUSHI url if defined

Signed-off-by: David Nind <david@davidnind.com>
Comment 10 David Nind 2024-09-23 20:09:07 UTC
Created attachment 171895 [details] [review]
Bug 37856: atomicupdate

Signed-off-by: David Nind <david@davidnind.com>
Comment 11 David Nind 2024-09-23 20:09:10 UTC
Created attachment 171896 [details] [review]
Bug 37856: Add service_platform field

The change from this patch itself should be self-explanatory.
Testing for this requires credentials to a specific provider.
But the parameter is only added to the URL if defined.

Test plan, ktd, apply patch, run:
$ yarn js:build
$ yarn api:bundle
$ koha-plack --restart kohadev

1) Enable ERMModule
2) Create a new provider, visit:
<staff_url>/cgi-bin/koha/erm/eusage/usage_data_providers/add
3) Ensure 'Service platform' now shows. Create the provider and put something in this field.
4) View the provider, ensure the field is shown, visit:
<staff_url>/cgi-bin/koha/erm/eusage/usage_data_providers/1

Ensure all tests are still passing:
$ cypress run --spec t/cypress/integration/ERM/DataProviders_spec.ts
$ prove t/db_dependent/api/v1/erm_usage_*

Signed-off-by: David Nind <david@davidnind.com>
Comment 12 David Nind 2024-09-23 20:09:13 UTC
Created attachment 171897 [details] [review]
Bug 37856: Consider 'Exceptions' not being part of 'Report_Header'

When fixing the issue around the missing platform parameter, we
noticed this particular provider also returns 'Exceptions' as
its own thing, not part of 'Report_Header', despite documentation:
https://countermetrics.stoplight.io/docs/counter-sushi-api/7cp0h7n1hm2en-tr-j1-journal-requests-controlled

From the link above, search for 'Exceptions'. Notice it should be under 'Report_Header'.
Either way, this patch accounts for this possibility.

Signed-off-by: David Nind <david@davidnind.com>
Comment 13 David Nind 2024-09-23 20:09:16 UTC
Created attachment 171898 [details] [review]
Bug 37856: Consider absence of 'Report_Items'

The SUSHI provider in question for this patchset also does not return any
Report_Items entry. This patch accounts for that.

Signed-off-by: David Nind <david@davidnind.com>
Comment 14 David Nind 2024-09-23 20:09:19 UTC
Created attachment 171899 [details] [review]
Bug 37856: Add tests

This is using the groundwork from bug 37963.
This is testing the specific error this bug is addressing:
Required parameter Platform is missing

It is also testing that the error message is correctly shown as a background
job report message to the user

Test plan:
prove t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t

Signed-off-by: David Nind <david@davidnind.com>
Comment 15 David Nind 2024-09-23 20:18:01 UTC
I've signed off, but wasn't really able to test steps 3 and 4 for the 'Add service_platform' patch, and the 'Consider 'Exceptions' not being part of 'Report_Header'' patch.

The tests all pass, and as I understand it the tests mock these.

Testing notes (using KTD):

1. Run databaseupdate and restart_all, after applying the patches and running yarn js:build and yarn api:bundle.
Comment 16 Nick Clemens (kidclamp) 2024-09-26 19:21:58 UTC
Created attachment 172040 [details] [review]
Bug 37856: [DONT PUSH] dbic changes

Signed-off-by: David Nind <david@davidnind.com>
Comment 17 Nick Clemens (kidclamp) 2024-09-26 19:22:01 UTC
Created attachment 172042 [details] [review]
Bug 37856: Append platform parameter to SUSHI url if defined

Signed-off-by: David Nind <david@davidnind.com>
Comment 18 Nick Clemens (kidclamp) 2024-09-26 19:22:03 UTC
Created attachment 172043 [details] [review]
Bug 37856: atomicupdate

Signed-off-by: David Nind <david@davidnind.com>
Comment 19 Nick Clemens (kidclamp) 2024-09-26 19:22:06 UTC
Created attachment 172044 [details] [review]
Bug 37856: Add service_platform field

The change from this patch itself should be self-explanatory.
Testing for this requires credentials to a specific provider.
But the parameter is only added to the URL if defined.

Test plan, ktd, apply patch, run:
$ yarn js:build
$ yarn api:bundle
$ koha-plack --restart kohadev

1) Enable ERMModule
2) Create a new provider, visit:
<staff_url>/cgi-bin/koha/erm/eusage/usage_data_providers/add
3) Ensure 'Service platform' now shows. Create the provider and put something in this field.
4) View the provider, ensure the field is shown, visit:
<staff_url>/cgi-bin/koha/erm/eusage/usage_data_providers/1

Ensure all tests are still passing:
$ cypress run --spec t/cypress/integration/ERM/DataProviders_spec.ts
$ prove t/db_dependent/api/v1/erm_usage_*

Signed-off-by: David Nind <david@davidnind.com>
Comment 20 Nick Clemens (kidclamp) 2024-09-26 19:22:08 UTC
Created attachment 172045 [details] [review]
Bug 37856: Consider 'Exceptions' not being part of 'Report_Header'

When fixing the issue around the missing platform parameter, we
noticed this particular provider also returns 'Exceptions' as
its own thing, not part of 'Report_Header', despite documentation:
https://countermetrics.stoplight.io/docs/counter-sushi-api/7cp0h7n1hm2en-tr-j1-journal-requests-controlled

From the link above, search for 'Exceptions'. Notice it should be under 'Report_Header'.
Either way, this patch accounts for this possibility.

Signed-off-by: David Nind <david@davidnind.com>
Comment 21 Nick Clemens (kidclamp) 2024-09-26 19:22:10 UTC
Created attachment 172046 [details] [review]
Bug 37856: Consider absence of 'Report_Items'

The SUSHI provider in question for this patchset also does not return any
Report_Items entry. This patch accounts for that.

Signed-off-by: David Nind <david@davidnind.com>
Comment 22 Nick Clemens (kidclamp) 2024-09-26 19:22:13 UTC
Created attachment 172047 [details] [review]
Bug 37856: Add tests

This is using the groundwork from bug 37963.
This is testing the specific error this bug is addressing:
Required parameter Platform is missing

It is also testing that the error message is correctly shown as a background
job report message to the user

Test plan:
prove t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t

Signed-off-by: David Nind <david@davidnind.com>
Comment 23 Nick Clemens (kidclamp) 2024-09-26 19:22:15 UTC
Created attachment 172048 [details] [review]
Bug 37856: (QA follow-up) Tidy
Comment 24 Pedro Amorim 2024-09-27 09:58:28 UTC
Thanks for QA, Nick.
Adding 24.05 and 23.11 release candidate keywords as this improves how the SUSHI response is handled widening the pool of providers Koha is able to work with.
Comment 25 Katrin Fischer 2024-09-27 15:56:17 UTC
The way the database update outputs messages is a bit non-standard. I fixed the messages (we are not mentioning the bug number every time for example), but I didn't change the structure.
I think what it should have done was printing different messages in case of the column already existing or not, but the "Done" seems not quite right.
Not terribly important overall, just noting for future.
Comment 26 Katrin Fischer 2024-09-27 17:41:27 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 27 Pedro Amorim 2024-09-27 18:43:14 UTC
Created attachment 172155 [details] [review]
Bug 37856: Fix existing test

A service_platform value was being randomly to 'service_platform' as is a new attribute.
Assign undef to that to fix existing test
Comment 28 Pedro Amorim 2024-09-27 18:43:17 UTC
Created attachment 172156 [details] [review]
Bug 37856: Add new test to test platform is correctly added to build_url

prove t/db\_dependent/Koha/ERM/EUsage/UsageDataProvider.t
Comment 29 Pedro Amorim 2024-09-27 18:44:05 UTC
Added 2 follow-up test patches to fix existing tests and add a new one. Adding additional_work_needed keyword to notify Katrin of these 2 follow-ups.
Comment 30 Jonathan Druart 2024-09-30 08:04:59 UTC
19         say_success( $out, "Done" );

Is this expected? "Done"?
Comment 31 Pedro Amorim 2024-09-30 08:30:45 UTC
Created attachment 172215 [details] [review]
Bug 37856: Update atomicupdate messages

(In reply to Katrin Fischer from comment #25)
> The way the database update outputs messages is a bit non-standard. I fixed
> the messages (we are not mentioning the bug number every time for example),
> but I didn't change the structure.
> I think what it should have done was printing different messages in case of
> the column already existing or not, but the "Done" seems not quite right.
> Not terribly important overall, just noting for future.

(In reply to Jonathan Druart from comment #30)
> 19         say_success( $out, "Done" );
>
> Is this expected? "Done"?

The original patch:
https://github.com/Koha-Community/Koha/commit/2e4b1ca42f7a940e8329ed860dda102deb629db0#diff-661419b80761834f79ce9100a1f2a132b804ee7cdf4efffe14c29d93bec810e4R17

Had:
say_success( $out, "Bug 37856 - Done" );

I wanted to provide indication that the update of that particular bug was done, regardless if a change on the database happened or not.
This is clearly causing confusion, this is now showing messages more in line with standard I believe.
Comment 32 Pedro Amorim 2024-10-04 08:34:25 UTC
*** Bug 37058 has been marked as a duplicate of this bug. ***
Comment 33 Lucas Gass (lukeg) 2024-10-25 21:46:46 UTC
Too many merge conflicts in ErmSushiHarvester.t for me to solve, not knowing how this code works.
Comment 34 Pedro Amorim 2024-10-28 09:27:52 UTC
(In reply to Lucas Gass (lukeg) from comment #33)
> Too many merge conflicts in ErmSushiHarvester.t for me to solve, not knowing
> how this code works.

Looking here to provide patches for 24.05
Comment 35 Pedro Amorim 2024-10-28 09:52:12 UTC
(In reply to Lucas Gass (lukeg) from comment #33)
> Too many merge conflicts in ErmSushiHarvester.t for me to solve, not knowing
> how this code works.

Last follow-up patch here wasn't applying (and wasn't pushed to main) so I made it obsolete.
The reason you're getting the conflicts is because bug 37963 needs to be applied before this one, I believe.
Comment 36 Lucas Gass (lukeg) 2024-12-05 19:08:57 UTC
Backported to 24.05.x for upcoming 24.05.06
Comment 37 Fridolin Somers 2024-12-18 09:27:46 UTC
Pushed to 23.11.x for 23.11.11

Note that in 24.05.x the commit message has wrong bug id :
5eed8269b2 Bug 37526: DBIC Schema updates

This may need to be fixed in release notes ;)