Working with directories
Directories are the first grouping mechanism available in Bosch IoT Manager, followed by tags and filters. Directories can be used to organize devices hierarchically and include them in mass management actions.
A device can belong to only one directory at a time but can be moved between directories at any time.
The following examples show you how to create a directory and subdirectories, how to list all created directories or get a particular one, how to move a device into a directory, as well as how to list all devices in a directory.
List the devices of a directory - from the directory object directly
List the devices of a directory - using DeviceInventory and ready-to-use filters in Criteria class
Create a directory
The following code snippet demonstrates how to create a directory with the name myDirectory. The new directory will be created under the root group ('/').
deviceInventory.createDirectory(DirectoryParameters.newBuilder().name(
"myDirectory"
).build());
Create a subdirectory
Create a subdirectory of myDirectory from the example above:
deviceInventory.createDirectory(DirectoryParameters.newBuilder().parentPath(
"/myDirectory"
).name(
"subdirectory"
).build());
Get a directоry
Get the newly created myDirectory from the example above:
deviceInventory.directory(
"/myDirectory"
);
List directories
List all existing directories on pages of 10 elements each:
deviceInventory.directories(
10
);
Move a directоry
Move the newly created myDirectory into another directory e.g. newContainerDir:
deviceInventory.moveDirectory(
"/myDirectory"
,
"/newContainerDir"
);
Move a device to a directory
Move a device with a particular deviceId to a particular directory, for example myDirectory:
deviceInventory.moveDevice(deviceId,
"/myDirectory"
);
List the devices of a directory - from the directory object directly
List all devices contained in myDirectory, including its subdirectories, which have been set a particular attribute, for example myAttribute:
directory.devices(
Filter.newBuilder()
.query(
"exists(attributes/myAttribute)"
)
.build(),
/* Page size */
10
,
/* include subdirectories */
true
);
List the devices of a directory - using DeviceInventory and ready-to-use filters in Criteria class
List all devices included in myDirectory:
deviceInventory.devices(
Filter.newBuilder()
.query(Criteria.inDirectory(
"/myDirectory"
))
.build(),
10
);
Directories can have attributes, described in more detail in Working with attributes.