Context
Context is implemented as a separate structure with a relationship to already existing entities. The relationship is the following:
Context Type | Entity |
---|---|
CAMPUS | Geozone |
BUILDING | Floor Plan |
FLOOR | Floor |
ROOM | Zone |
AREA | Zone/Geozone |
Context - Contextual Entity Relationship
When a context is created the CMS makes entities for it and all its children. REST API also supports specifying an already existing entity for a context. In case an entity was created by a context it would have the context name and location. If the created entity is a Floor than it also inherits an image of its context.
If context created without location the CMS can't create an entity for the context. When the context is updated with a location CMS will create a contextual entity.
Updating a context also updates its related entity. The following fields of context propagated to its entity - name, location, image (in case it's a Floor context).
When a context is deleted its contextual entity deleted along with it. All children of the context (with all their entities) removed as well. If Some of the entities can't be removed for some reason meaningful exception will be thrown. One such restriction is that it's prohibited to delete an entity that has devices on itself. Devices should be moved to another entity first. That can be done by assigning them to another context.
Device Assignment
Devices assigned to a context automatically, if the entity they relate to has a context. For example, if a device is located in some geozone and this geozone associated with a context - device considered to be in said context. Search for an appropriate context can go up some levels. E.g. device is in a zone, on some floor in a floor plan that placed in the Geozone A. Neither zone, nor floor plan has an associated context but a geozone A has. So the device considered to be in a context associated with geozone A.
There is a possibility to assign an arbitrary device to a context. It can be an already created device or a device that about to be created. In this case, the CMS finds an entity associated with the requested context and changes the device location to be inside that entity. Then the same automatic device assignment comes to play.
URI Definition
Method | URI and Fields | |
GET | /iap/context | |
Returns all contexts. The response will be almost the same JSON as the request. Null fields will be explicitly stated and id fields added. Sample Response | ||
/iap/context/{id} | ||
Gets the context for the specified ID. All of its children are also included. If the requested context is not top-level it will contain the parentId field with the ID of its parent. Context is a recursive data structure. A parent includes all of its children. This REST endpoint returns array because it's possible to have several distinct context trees. Note: The image field is a base64 encoded image. It is shortened in the following sample response. Example
Sample Response | ||
/iap/context/export | ||
Exports all contexts. ResponseStreaming output of the produced file with all contexts. | ||
POST | /iap/context | |
Creates a context. Several contexts can be created at once, provided they all are part of the same tree. Can also be used to create children for an already existing context. The parentId must be specified in this case. Sample Payload | ||
/iap/context/import | ||
Imports contexts. RequestThe file containing the contexts to be imported. | ||
PUT | /iap/context | |
Updates an already existing context. Must contain the ID field for a context that intends to be updated. Several contexts can be updated at once provided they are all part of the same tree. Can contain new children without an ID field. CMS treats it as a request to create new contexts. So if you intend to update Campus and Building at once, each must have an ID field. If the campus object has an ID field but the building does not, the Campus will be updated and a new Building will be created. If this new Building has a name that is already used by another Building, an exception with a message will be thrown, and nothing will be updated. Sample Payload | ||
/iap/context/assignDevicesTo/{id} | ||
Assigns devices to the context with the specified ID. PayloadThe payload is an array of device IDs to be assigned. Request Body Example[2,3,25] Success Response
| ||
/iap/context/unassignDevices | ||
Unassigns devices from their contexts. Ids of devices to be unassigned are passed as an array in the request body. Request Body Example[42, 68, 70] Success response:[68, 42, 70] | ||
DELETE | /iap/context/{id} | |
Deletes the specified context with all its children and contextual entity. Response
|