Bug 24321

Summary: Make objects.search use mappings from Koha::Object(s)
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: REST APIAssignee: Tomás Cohen Arazi <tomascohen>
Status: CLOSED FIXED QA Contact: Kyle M Hall <kyle>
Severity: enhancement    
Priority: P5 - low CC: 1joynelson, agustinmoyano, jonathan.druart, josef.moravec, kyle.m.hall, martin.renvoize, nick, tomascohen
Version: master   
Hardware: All   
OS: All   
Change sponsored?: Sponsored Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
This development takes advantage of the mappings that have been added to the Koha::Object level, and refactors the objects.search Mojolicious helper so it uses it internally. This allows us to remove the 'to_model' parameter, and makes the need of any kind of mapping on the controllers irrelevant. All the existing mappings are removed and the controllers simplified in this move.
Version(s) released in:
20.05.00
Bug Depends on: 23893    
Bug Blocks: 18731, 23916, 24356    
Attachments: Bug 24321: Add Koha::Objects->attributes_from_api
Bug 24321: Make dbic_merge_sorting accept a result set as parameter
Bug 24321: Make objects.search use mappings from Koha::Object(s)
Bug 24312: Clean /cities
Bug 24312: Clean /acquisitions/funds
Bug 24312: Clean /acquisitions/vendors
Bug 24321: Clean /libraries
Bug 24321: Clean /checkouts
Bug 24321: Add Koha::Objects->attributes_from_api
Bug 24321: Make dbic_merge_sorting accept a result set as parameter
Bug 24321: Make objects.search use mappings from Koha::Object(s)
Bug 24321: Clean /cities
Bug 24321: Clean /acquisitions/funds
Bug 24321: Clean /acquisitions/vendors
Bug 24321: Clean /libraries
Bug 24321: Clean /checkouts
Bug 24321: Clean /biblios
Bug 24321: Clean /items
Bug 24321: Clean /patrons/{patron_id}/account
Bug 24321: Clean /holds
Bug 24321: Clean /patrons
Bug 24321: Add Koha::Objects->attributes_from_api
Bug 24321: Make dbic_merge_sorting accept a result set as parameter
Bug 24321: Make objects.search use mappings from Koha::Object(s)
Bug 24321: Clean /cities
Bug 24321: Clean /acquisitions/funds
Bug 24321: Clean /acquisitions/vendors
Bug 24321: Clean /libraries
Bug 24321: Clean /checkouts
Bug 24321: Clean /biblios
Bug 24321: Clean /items
Bug 24321: Clean /patrons/{patron_id}/account
Bug 24321: Clean /holds
Bug 24321: Clean /patrons
Bug 24321: Add Koha::Objects->attributes_from_api
Bug 24321: Make dbic_merge_sorting accept a result set as parameter
Bug 24321: Make objects.search use mappings from Koha::Object(s)
Bug 24321: Clean /cities
Bug 24321: Clean /acquisitions/funds
Bug 24321: Clean /acquisitions/vendors
Bug 24321: Clean /libraries
Bug 24321: Clean /checkouts
Bug 24321: Clean /biblios
Bug 24321: Clean /items
Bug 24321: Clean /patrons/{patron_id}/account
Bug 24321: Clean /holds
Bug 24321: Clean /patrons
Bug 24321: (follow-up) Fix number of tests in t/db_dependent/Koha/Objects.t
Bug 24321: Add Koha::Objects->attributes_from_api
Bug 24321: Make dbic_merge_sorting accept a result set as parameter
Bug 24321: Make objects.search use mappings from Koha::Object(s)
Bug 24321: Clean /cities
Bug 24321: Clean /acquisitions/funds
Bug 24321: Clean /acquisitions/vendors
Bug 24321: Clean /libraries
Bug 24321: Clean /checkouts
Bug 24321: Clean /biblios
Bug 24321: Clean /items
Bug 24321: Clean /patrons/{patron_id}/account
Bug 24321: Clean /holds
Bug 24321: Clean /patrons
Bug 24321: (follow-up) Fix number of tests in t/db_dependent/Koha/Objects.t

Description Tomás Cohen Arazi 2019-12-31 11:38:13 UTC
Now Koha::Object(s) implement 'to_api' and 'attributes_from_api' there's no need to implement such mappings on the controllers for simple Koha::Object<->API conversions.

The to_api mappings have already been moved to Koha::Object level. It is time for the to_model ones.
Comment 1 Tomás Cohen Arazi 2019-12-31 14:52:15 UTC Comment hidden (obsolete)
Comment 2 Tomás Cohen Arazi 2019-12-31 14:52:18 UTC Comment hidden (obsolete)
Comment 3 Tomás Cohen Arazi 2019-12-31 14:52:21 UTC Comment hidden (obsolete)
Comment 4 Tomás Cohen Arazi 2019-12-31 14:52:24 UTC Comment hidden (obsolete)
Comment 5 Tomás Cohen Arazi 2019-12-31 14:52:27 UTC Comment hidden (obsolete)
Comment 6 Tomás Cohen Arazi 2019-12-31 14:52:30 UTC Comment hidden (obsolete)
Comment 7 Tomás Cohen Arazi 2019-12-31 14:52:34 UTC Comment hidden (obsolete)
Comment 8 Tomás Cohen Arazi 2019-12-31 14:52:37 UTC Comment hidden (obsolete)
Comment 9 Tomás Cohen Arazi 2019-12-31 14:57:19 UTC Comment hidden (obsolete)
Comment 10 Tomás Cohen Arazi 2019-12-31 14:57:22 UTC Comment hidden (obsolete)
Comment 11 Tomás Cohen Arazi 2019-12-31 14:57:25 UTC Comment hidden (obsolete)
Comment 12 Tomás Cohen Arazi 2019-12-31 14:57:29 UTC Comment hidden (obsolete)
Comment 13 Tomás Cohen Arazi 2019-12-31 14:57:32 UTC Comment hidden (obsolete)
Comment 14 Tomás Cohen Arazi 2019-12-31 14:57:35 UTC Comment hidden (obsolete)
Comment 15 Tomás Cohen Arazi 2019-12-31 14:57:39 UTC Comment hidden (obsolete)
Comment 16 Tomás Cohen Arazi 2019-12-31 14:57:42 UTC Comment hidden (obsolete)
Comment 17 Tomás Cohen Arazi 2019-12-31 15:30:27 UTC Comment hidden (obsolete)
Comment 18 Tomás Cohen Arazi 2019-12-31 15:32:06 UTC Comment hidden (obsolete)
Comment 19 Tomás Cohen Arazi 2019-12-31 15:36:01 UTC Comment hidden (obsolete)
Comment 20 Tomás Cohen Arazi 2019-12-31 15:53:42 UTC Comment hidden (obsolete)
Comment 21 Tomás Cohen Arazi 2020-01-02 14:04:37 UTC Comment hidden (obsolete)
Comment 22 Tomás Cohen Arazi 2020-01-02 14:07:53 UTC
Full test plan:
- Apply this patchset and run:
  $ kshell
 k$ prove t/db_dependent/Koha/Objects.t \
          t/Koha/REST/Plugin/Query.t \
          t/db_dependent/Koha/REST/Plugin/Objects.t \
          t/db_dependent/api/v1
=> SUCCESS: Tests pass!
Comment 23 Tomás Cohen Arazi 2020-01-06 15:32:30 UTC
Created attachment 96840 [details] [review]
Bug 24321: Add Koha::Objects->attributes_from_api

This patch makes the 'attributes_from_api' method from the singular
class available from the result set class.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
4. Sign off :-D
5. Yeah, I skipped 3 :-P
Comment 24 Tomás Cohen Arazi 2020-01-06 15:32:33 UTC
Created attachment 96841 [details] [review]
Bug 24321: Make dbic_merge_sorting accept a result set as parameter

This patch makes dbic_merge_sorting accept a result set as parameter and
solves a FIXME in _build_order_atom.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/Koha/REST/Plugin/Query.t
=> SUCCESS: Tests pass!
3. Sign off :-D
Comment 25 Tomás Cohen Arazi 2020-01-06 15:32:38 UTC
Created attachment 96842 [details] [review]
Bug 24321: Make objects.search use mappings from Koha::Object(s)

This patch simplifies the objects.search helper so it relies entirely on
the result set object for the attribute mappings.

The result is no more to_api or to_model mappings are passed. The
controllers need to be cleaned up after this patch.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Note: the original version of this helpers accepted arbitrary mappings
and are now constrianed to real mappings on the Koha::Object level. As
such, the number of tests got reduced.
Comment 26 Tomás Cohen Arazi 2020-01-06 15:32:42 UTC
Created attachment 96843 [details] [review]
Bug 24321: Clean /cities
Comment 27 Tomás Cohen Arazi 2020-01-06 15:32:46 UTC
Created attachment 96844 [details] [review]
Bug 24321: Clean /acquisitions/funds
Comment 28 Tomás Cohen Arazi 2020-01-06 15:32:50 UTC
Created attachment 96845 [details] [review]
Bug 24321: Clean /acquisitions/vendors
Comment 29 Tomás Cohen Arazi 2020-01-06 15:32:54 UTC
Created attachment 96846 [details] [review]
Bug 24321: Clean /libraries
Comment 30 Tomás Cohen Arazi 2020-01-06 15:32:59 UTC
Created attachment 96847 [details] [review]
Bug 24321: Clean /checkouts
Comment 31 Tomás Cohen Arazi 2020-01-06 15:33:02 UTC
Created attachment 96848 [details] [review]
Bug 24321: Clean /biblios
Comment 32 Tomás Cohen Arazi 2020-01-06 15:33:06 UTC
Created attachment 96849 [details] [review]
Bug 24321: Clean /items
Comment 33 Tomás Cohen Arazi 2020-01-06 15:33:10 UTC
Created attachment 96850 [details] [review]
Bug 24321: Clean /patrons/{patron_id}/account
Comment 34 Tomás Cohen Arazi 2020-01-06 15:33:14 UTC
Created attachment 96851 [details] [review]
Bug 24321: Clean /holds
Comment 35 Tomás Cohen Arazi 2020-01-06 15:33:17 UTC
Created attachment 96852 [details] [review]
Bug 24321: Clean /patrons
Comment 36 Tomás Cohen Arazi 2020-01-06 15:37:31 UTC
Rebased on top of bug 21684 which is in master
Comment 37 Josef Moravec 2020-01-07 11:33:51 UTC
Created attachment 96874 [details] [review]
Bug 24321: Add Koha::Objects->attributes_from_api

This patch makes the 'attributes_from_api' method from the singular
class available from the result set class.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
4. Sign off :-D
5. Yeah, I skipped 3 :-P

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 38 Josef Moravec 2020-01-07 11:33:57 UTC
Created attachment 96875 [details] [review]
Bug 24321: Make dbic_merge_sorting accept a result set as parameter

This patch makes dbic_merge_sorting accept a result set as parameter and
solves a FIXME in _build_order_atom.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/Koha/REST/Plugin/Query.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 39 Josef Moravec 2020-01-07 11:34:02 UTC
Created attachment 96876 [details] [review]
Bug 24321: Make objects.search use mappings from Koha::Object(s)

This patch simplifies the objects.search helper so it relies entirely on
the result set object for the attribute mappings.

The result is no more to_api or to_model mappings are passed. The
controllers need to be cleaned up after this patch.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Note: the original version of this helpers accepted arbitrary mappings
and are now constrianed to real mappings on the Koha::Object level. As
such, the number of tests got reduced.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 40 Josef Moravec 2020-01-07 11:34:07 UTC
Created attachment 96877 [details] [review]
Bug 24321: Clean /cities

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 41 Josef Moravec 2020-01-07 11:34:12 UTC
Created attachment 96878 [details] [review]
Bug 24321: Clean /acquisitions/funds

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 42 Josef Moravec 2020-01-07 11:34:17 UTC
Created attachment 96879 [details] [review]
Bug 24321: Clean /acquisitions/vendors

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 43 Josef Moravec 2020-01-07 11:34:23 UTC
Created attachment 96880 [details] [review]
Bug 24321: Clean /libraries

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 44 Josef Moravec 2020-01-07 11:34:28 UTC
Created attachment 96881 [details] [review]
Bug 24321: Clean /checkouts

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 45 Josef Moravec 2020-01-07 11:34:33 UTC
Created attachment 96882 [details] [review]
Bug 24321: Clean /biblios

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 46 Josef Moravec 2020-01-07 11:34:37 UTC
Created attachment 96883 [details] [review]
Bug 24321: Clean /items

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 47 Josef Moravec 2020-01-07 11:34:41 UTC
Created attachment 96884 [details] [review]
Bug 24321: Clean /patrons/{patron_id}/account

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 48 Josef Moravec 2020-01-07 11:34:46 UTC
Created attachment 96885 [details] [review]
Bug 24321: Clean /holds

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 49 Josef Moravec 2020-01-07 11:34:50 UTC
Created attachment 96886 [details] [review]
Bug 24321: Clean /patrons

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 50 Josef Moravec 2020-01-07 11:34:54 UTC
Created attachment 96887 [details] [review]
Bug 24321: (follow-up) Fix number of tests in t/db_dependent/Koha/Objects.t

Test plan:
prove t/db_dependent/Koha/Objects.t

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Comment 51 Kyle M Hall 2020-01-07 18:49:44 UTC
Created attachment 96939 [details] [review]
Bug 24321: Add Koha::Objects->attributes_from_api

This patch makes the 'attributes_from_api' method from the singular
class available from the result set class.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass!
4. Sign off :-D
5. Yeah, I skipped 3 :-P

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 52 Kyle M Hall 2020-01-07 18:50:03 UTC
Created attachment 96940 [details] [review]
Bug 24321: Make dbic_merge_sorting accept a result set as parameter

This patch makes dbic_merge_sorting accept a result set as parameter and
solves a FIXME in _build_order_atom.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/Koha/REST/Plugin/Query.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 53 Kyle M Hall 2020-01-07 18:50:07 UTC
Created attachment 96941 [details] [review]
Bug 24321: Make objects.search use mappings from Koha::Object(s)

This patch simplifies the objects.search helper so it relies entirely on
the result set object for the attribute mappings.

The result is no more to_api or to_model mappings are passed. The
controllers need to be cleaned up after this patch.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Note: the original version of this helpers accepted arbitrary mappings
and are now constrianed to real mappings on the Koha::Object level. As
such, the number of tests got reduced.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 54 Kyle M Hall 2020-01-07 18:50:10 UTC
Created attachment 96942 [details] [review]
Bug 24321: Clean /cities

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 55 Kyle M Hall 2020-01-07 18:50:14 UTC
Created attachment 96943 [details] [review]
Bug 24321: Clean /acquisitions/funds

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 56 Kyle M Hall 2020-01-07 18:50:18 UTC
Created attachment 96944 [details] [review]
Bug 24321: Clean /acquisitions/vendors

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 57 Kyle M Hall 2020-01-07 18:50:22 UTC
Created attachment 96945 [details] [review]
Bug 24321: Clean /libraries

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 58 Kyle M Hall 2020-01-07 18:50:25 UTC
Created attachment 96946 [details] [review]
Bug 24321: Clean /checkouts

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 59 Kyle M Hall 2020-01-07 18:50:29 UTC
Created attachment 96947 [details] [review]
Bug 24321: Clean /biblios

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 60 Kyle M Hall 2020-01-07 18:50:33 UTC
Created attachment 96948 [details] [review]
Bug 24321: Clean /items

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 61 Kyle M Hall 2020-01-07 18:50:37 UTC
Created attachment 96949 [details] [review]
Bug 24321: Clean /patrons/{patron_id}/account

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 62 Kyle M Hall 2020-01-07 18:50:40 UTC
Created attachment 96950 [details] [review]
Bug 24321: Clean /holds

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 63 Kyle M Hall 2020-01-07 18:50:44 UTC
Created attachment 96951 [details] [review]
Bug 24321: Clean /patrons

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 64 Kyle M Hall 2020-01-07 18:50:47 UTC
Created attachment 96952 [details] [review]
Bug 24321: (follow-up) Fix number of tests in t/db_dependent/Koha/Objects.t

Test plan:
prove t/db_dependent/Koha/Objects.t

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 65 Martin Renvoize 2020-01-08 14:43:50 UTC
Nice work everyone!

Pushed to master for 20.05
Comment 66 Joy Nelson 2020-01-18 16:15:09 UTC
Tomas this would not apply to the 19.11.x branch.  Can you assist me if you need this backported?

error: could not apply fabcedca05... Bug 24321: Add Koha::Objects->attributes_from_api
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
Comment 67 Joy Nelson 2020-02-08 00:16:37 UTC
enhancement not backported to 19.11.x
Comment 68 Tomás Cohen Arazi 2021-01-27 11:05:19 UTC
*** Bug 19250 has been marked as a duplicate of this bug. ***