Indicia-Team / warehouse

GNU General Public License v3.0
5 stars 3 forks source link

Adding a verbose param to the REST locations endpoint #430

Closed kazlauskis closed 9 months ago

kazlauskis commented 2 years ago

The REST docs lists the verbose param but it doesn't work with the BRC's warehouse1. We are working on a project that would benefit from this being enabled/fixed.

Add &verbose to the URL to retrieve attribute values as an array with additional information including the attribute ID, caption, data type, value ID and raw value information as shown in the following example response (shortened)

200 OK
{
"values": {
"id": "3",
...
"locAttr:1": [{
"attribute_id": "1",
"value_id": "4",
"caption": "Count",
"data_type": "I",
"value": "4 - 6",
"raw_value": "4",
"upper_value": 6
}],
...
}
}
JimBacon commented 2 years ago

@kazlauskis Is this needed to meet https://github.com/BiologicalRecordsCentre/ABLE/milestone/14? @DavidRoy Shall I take this on?

kazlauskis commented 2 years ago

Yep, exactly.

DavidRoy commented 2 years ago

@JimBacon - yes please

JimBacon commented 2 years ago

Released in warehouse v8.1.0

kazlauskis commented 2 years ago

@JimBacon thanks!

@Vilius-Stankaitis can you please check this is working in the warehouse1 as expected now?

JimBacon commented 2 years ago

I followed the pattern already present in the code, to preserve backwards compatibility, which you might not guess from the documentation. Only multi-value attributes return an array. E.g. in abridged form:

"locAttr:306": [
    {"multi_value": "t"},
    {"multi_value": "t"}
],
"locAttr:330": 
    {"multi_value": "f"}
kazlauskis commented 2 years ago

@JimBacon thanks again for implementing this. It works fine with one exception. When these is no locations then an Unable to Complete Request page is returned instead of an empty array. It works fine without the verbose flag.

JimBacon commented 2 years ago

Thanks, @kazlauskis. Fixed in https://github.com/Indicia-Team/warehouse/commit/a4b2d3b1ddc33eb58bafb9400610c059f17dbc7e

kazlauskis commented 9 months ago

From here.

@JimBacon, do you know why this is returning a "Unable to Complete Request" HTML page now? It works fine without the verbose flag.

curl --location 'https://warehouse1.indicia.org.uk/index.php/services/rest/locations?location_type_id=18879&public=false&verbose=1' \ --header 'authorization: Bearer JWT_TOKEN'

JimBacon commented 9 months ago

The warehouse logs an error:

16:20:27 error #2: Error in Rest API report request. Undefined array key 336821 at line 323 in file /srv/sites/warehouse1.indicia.org.uk/modules/rest_api/helpers/rest_crud.php
16:20:27 debug Stack trace:
/srv/sites/warehouse1.indicia.org.uk/modules/rest_api/helpers/rest_crud.php - line 323 - indicia_error_handler
/srv/sites/warehouse1.indicia.org.uk/modules/rest_api/controllers/services/rest.php - line 3227 - readList
/srv/sites/warehouse1.indicia.org.uk/modules/rest_api/controllers/services/rest.php - line 949 - locationsGet
Unknown file - line Unknown - __call
/srv/sites/warehouse1.indicia.org.uk/system/core/Kohana.php - line 291 - invokeArgs
/srv/sites/warehouse1.indicia.org.uk/system/core/Event.php - line 209 - instance
/srv/sites/warehouse1.indicia.org.uk/system/core/Bootstrap.php - line 55 - run
/srv/sites/warehouse1.indicia.org.uk/index.php - line 112 - require

John modified this code a couple of days ago https://github.com/Indicia-Team/warehouse/commit/8316722ee22d829f5bafa248dbf1b416002e99d1 and I guess he has introduced a bug.

I'll see if I can work out what he was trying to do and whether I can fix it.

JimBacon commented 9 months ago

I've applied a fix which I hope solves your problem.

What changed is that basic attribute values are now returned by default, without needing the verbose option. Using the verbose option provides more information about the attributes.

kazlauskis commented 9 months ago

Works well, thanks Jim.