getItem method Null safety
- GlpiItemType itemtype,
- int id,
- {bool expandDropdowns = false,
- bool getHateoas = true,
- bool getSha1 = false,
- bool withDevices = false,
- bool withDisks = false,
- bool withSoftwares = false,
- bool withConnections = false,
- bool withNetworkPorts = false,
- bool withInfoComs = false,
- bool withContracts = false,
- bool withDocuments = false,
- bool withTickets = false,
- bool withProblems = false,
- bool withChanges = false,
- bool withNotes = false,
- bool withLogs = false,
- List<
String> ? addKeysNames}
override
Return an item identified by the id
and of type itemType
Will throw an Exception if the request fails or if the selected id is incorrect.
withDevices
will be ignored if the itemtype
isn't GlpiItemType.Computer,GlpiItemType.NetworkEquipment,GlpiItemType.Peripheral,GlpiItemType.Phone or GlpiItemType.Printer.
withDisks
, withSoftwares
, withConnections
will be ignored if the itemtype
isn't GlpiItemType.Computer.
Reference: https://github.com/glpi-project/glpi/blob/master/apirest.md#get-an-item
Implementation
@override
Future<Map<String, dynamic>> getItem(GlpiItemType itemtype, int id,
{bool expandDropdowns = false,
bool getHateoas = true,
bool getSha1 = false,
bool withDevices = false,
bool withDisks = false,
bool withSoftwares = false,
bool withConnections = false,
bool withNetworkPorts = false,
bool withInfoComs = false,
bool withContracts = false,
bool withDocuments = false,
bool withTickets = false,
bool withProblems = false,
bool withChanges = false,
bool withNotes = false,
bool withLogs = false,
List<String>? addKeysNames}) async {
if (sessionToken!.isEmpty) {
throw Exception('No session token, initSession first');
}
final Map<String, String> headers = {
'Session-Token': sessionToken!,
'Content-Type': 'application/json',
...?appToken != null ? {'App-Token': appToken!} : null,
};
String uriStr =
'$host/${itemtype.toString().split('.').last}/$id?expand_dropdowns=$expandDropdowns&get_hateoas=$getHateoas&get_sha1=$getSha1&with_networkports=$withNetworkPorts&';
if (itemtype == GlpiItemType.Computer) {
uriStr =
'$uriStr&with_devices=$withDevices&with_disks=$withDisks&with_softwares=$withSoftwares&with_connections=$withConnections';
} else if (itemtype == GlpiItemType.NetworkEquipment ||
itemtype == GlpiItemType.Peripheral ||
itemtype == GlpiItemType.Phone ||
itemtype == GlpiItemType.Printer) {
uriStr = '$uriStr&with_devices=$withDevices';
}
final uri = Uri.parse(uriStr);
if (addKeysNames != null) {
for (var key in addKeysNames) {
uri.queryParameters.addAll({'add_keys_names[]': key});
}
}
final response = await _innerClient.get(uri, headers: headers);
if (response.statusCode != 200) {
throw GlpiException.fromResponse(
response.statusCode, json.decode(response.body));
}
return Future.value(json.decode(response.body));
}