Specifications Inventory

Main objective

Realize the selection/list of objects via generic methods.

TODO
  • Refactoring methodListInventoryObjects with itemtype input option
  • Adding methodGetInventoryObject with param (itemtype and searchOptions)
  • Turn methodGetComputer to deprecated method
  • Turn methodListComputers to deprecated method
  • Turn methodGetNetworkEquipment to deprecated method

Methods

glpi.listInventoryObjects

Return list of inventory objects

Input : a hastable

  • itemtype (mandatory) : option to filter the itemtype (computer, monitor, printer...)
  • name (optional) : name or part of the name
  • serial (optional) : serial number or part of it
  • otherserial (optional) : inventory number or part of it
  • location_id (optional) : the id of location
  • columns (optional) : columns to retrieve separated by comma (default : name,id,entities_name,entities_id,serial,otherserial)
  • help (optional) : option to get usage information
  • count , start, limit (optional) : option for do additional filters

Remi : about loc_*
We probaly don't want to rewrite the search engine... (even it will be great to be able to reuse it...)

I think, we should only accept field of the table (so locations_id), to be as generic as possible
If need to search on room number
call glpi.listInventoryObjects with (itemtype=Location, room=foo)
get id in the result
call glpi.listInventoryObjects with (itemtype=Computer, locations_id)
Yeti : Yes, it's a great idea :-)

Return : an array of hashtable

  • id : id
  • name : name or part of the name
  • entities_name : entities name
  • entities_id : entities id
  • serial : serial number
  • otherserial : inventory number
  • loc_name : location name
  • loc_building : building location number
  • loc_room : room location number

About loc_* again
ouput will contains locations_id (if column exists) and locations_name (id id2name option)

If need, add a with_location option which will retrieve the full glpi_locations entry (a sub entry on the result).. (well in getObject, not in listObjects...)

  • ---- FOR EACH columns who's been selected ----
  • column_name : value for this column
  • ---- END FOR EACH FIELDS columns ----
  • itemtype : the itemtype of the object
  • itemtype_name : the translation name for this itemtype

Walid : why not to keep the current system : field=value ?

Walid : I don't understand what is the value for field_1_searchOptions ? the field name or his id in the searchOptions tab ?

Yeti : The current system of the return list doesn't change. For example (with --itemtype=computer), the value of "field_1_searchOptions" can be : "name" or "id" or "serial" or "entities_id"...or other field who list in getSearchOptions function (in glpi/inc/computer.class.php). I'm not sure to be very clear, is it easier to understand with that example?

Remi: So, call with use, for example : --name='toto' ?

Remi: Add a columns option (list of column to retrieve) and a id2name

Which default colums (all but comment ?) ?

Yeti : Ok, I understand what do you expect, and I have corrected it in the "input" list options.

Walid : seems ok to me now

Search algorithm and returns data
For make the query we use getSearchOptions method.

glpi.getInventoryObject

Return all informations for a particular item

input a hastable
  • itemtype (mandatory) : option to filter the itemtype (computer, monitor, printer...)
  • id (mandatory) : the id of the object
  • id2name (optional) : option to enable id to name translation of dropdown fields
  • with_doc (optional) : show the associated documents in the return array
  • with_contract (optional) : show the associated contracts in the return array
  • with_infocom (optional) : show the financial information in the return array
  • with_reservation (optional) : show the reservations (future and past) in the return array
  • with_ticket (optional) : show tickets on linked in the return array
  • with_link (optional) : show external links in the return array
  • with_netport (optional) : show networking port(s) in the return array
  • help (optional) : option to get usage information

Walid : in 0.78 no possible to use a generic function to check types because of : #2485.

Remi: must retrieve a "single" object, so search field could only be a "unique" criterion (only id in most case), so search_field and search_value could be remplace by "id"
Yeti : Ok, I understand what do you expect, and I have corrected it in the "input" list options.

Remi: Should use type array from define.php
  • with_doc => if in $CFG_GLPI["doc_types"]
  • with_contract => if in $CFG_GLPI["contract_types"]
  • with_infocom => if in $CFG_GLPI["infocom_types"]
  • with_reservation => if in $CFG_GLPI["reservation_types"]
  • with_ticket => if in $CFG_GLPI["helpdesk_types"]
  • with_link => if in $CFG_GLPI["link_types"] (perhaps not usefull)
  • with_netport => if in $CFG_GLPI["netport_types"]
    Walid : yes
    Walid : what about getting plugins informations related to this object ? add a new function like plugin_datainjection_xxx_ItemForWebservices ?
    Yeti : Ok, I have added it in the "input" list options.
  • could use getDbRelations() ?
    Walid : look at the searchOption for each field. If field == name and table is not the itemtype table, then retrieve the dropdown label and add it to the list of returned fields (using the previous proposition)
    Walid : it seems ok to me

return an array of hashtable

The complete list of all searchOptions for Object who's been selected

  • fields of glpi_computers
  • fields of glpi_docs if appropriate option is enabled
  • fields of glpi_contract if appropriate option is enabled
  • fields of glpi_infocoms if appropriate option is enabled
  • fields of glpi_reservations if appropriate option is enabled and if item is present in glpi_reservationitems table
  • fields of glpi_tracking if appropriate option is enabled and followups an array of hasble : fields of glpi_followups
  • list links if appropriate option is enabled and if ( (glpi_links is not enmpty) AND (itemtype is in glpi_links_itemtypes) )
  • fields of glpi_networkports, glpi_netpoints and glpi_vlans, if appropriate option is enabled

Example

Call example for get item informations on Computer

Step 1 : get the list of all computers

$ php testxmlrpc.php --session=57fc8f3c79f4e44b6c41af8c72d5aa8a --method=glpi.listInventoryObjects --itemtype=computer
+ Calling 'glpi.listInventoryObjects' on http://localhost//glpi_078RC3/plugins/webservices/xmlrpc.php?session=57fc8f3c79f4e44b6c41af8c72d5aa8a
+ Response: Array
(
    [0] => Array
        (
            // List of all searchOptions possibilities for Computer 1
            [field_searchOptions_1] => value_1
            [field_searchOptions_2] => value_2
            ..........
            [field_searchOptions_X] => value_X
            [itemtype] => Computer
            [itemtype_name] => Ordinateur
        )
    [1] => Array
        (
            // List of all searchOptions possibilities for Computer 2
            [field_searchOptions_1] => value_1
            [field_searchOptions_2] => value_2
            ..........
            [field_searchOptions_X] => value_X
            [itemtype] => Computer
            [itemtype_name] => Ordinateur
        )
)

Step 2 : get a computer with searchOptions

$ php testxmlrpc.php --session=57fc8f3c79f4e44b6c41af8c72d5aa8a --method=glpi.getInventoryObject --itemtype=computer --search_field=id --search_value=1
+ Calling 'glpi.getInventoryObject' on http://localhost//glpi_078RC3/plugins/webservices/xmlrpc.php?session=57fc8f3c79f4e44b6c41af8c72d5aa8a
+ Response: Array
(
    [0] => Array
        (
            // List of all searchOptions for Computer 1
            [field_searchOptions_1] => value_1
            [field_searchOptions_2] => value_2
            ..........
            [field_searchOptions_X] => value_X
            [itemtype] => Computer
            [itemtype_name] => Ordinateur
        )
)