Cumulocity API Services / com.softwareag.jc.cumulocity.services.models.extension / PropertiesBase

PropertiesBase

open class PropertiesBase

Manages custom attributes found in ManageObject and allows them to be referenced via a properties map keyed by the name of the found custom attribute e.g.

{
     ...
     "xSimple_custom_attribute": "12345",
     "complex_custom_attribute: {
         "name": "test",
         "value": {
             "label": "Can be nested too!"
             }
         }
     }
     ...
}

becomes

properties["xSimple_custom_attribute"] = "12345"
properties["complex_custom_attribute.name"] = "test"
properties["complex_custom_attribute.value.label"] = "Can be nested too!"

You can create your own custom classes and register them here if your structures are too complex to be easily managed as above e.g.

PropertiesBase.registerCustomAttributeClass("complex_custom_attribute", "your.package.class")

val myCustomAttrib: <class> = properties["complex_custom_attribute"] as <class>

Your class will need to provide a constructor that takes a single JSON object as input, with JSON object being the root element representing the custom structure. Your constructor can then decide how to decompose the values in the structure and what properties to expose and how. e.g.

class MyCustomAttribClass(o: JSONObject): JsonSerializable {

 val name: String?

 init {
     name = o.getString("name")
     ...
 }
 ...
 /**
 Only required if you want to send this custom attribute for update when sending ManagedObjects
 to Cumulocity
 */
 override fun toJSONString(): String {
     return JsonSerializable.toJSONString(this)
 }
}

You can also group simple custom attributes together via your own custom classes by prefixing them with the name of the custom label e.g.

{
 ...
     "xPlanningDate": "11-12-20",
     "xPlanningInfo": "this is a test"
 ...
 }

could be processed as

PropertiesBase.registerCustomAttributeClass("xPlanning", "your.package.class")

val myCustomAttrib: <class> = properties["xPlanning"] as <class>

As above your class needs to provide a constructor to take the JSONObject, however in this case it will be provided with the JSON root node containing the first attribute starting with "xPlanning"... Your constructor will then have to extract the relevant attributes and assign them to the appropriate properties such as date() and info()

Constructors

<init>

PropertiesBase(json: JSONObject?, excludeTopLevel: Boolean)

Manages custom attributes found in ManageObject and allows them to be referenced via a properties map keyed by the name of the found custom attribute e.g.

Properties

properties

val properties: HashMap<String, Any>

Collection of any custom attributes found in the ManageObject structure

Companion Object Functions

registerCustomAttributeClass

fun registerCustomAttributeClass(name: String, namespaceForPackageAndClass: String): Unit

Allows you to register your own custom classes to manage custom structures found in Cumulocity assets.

Inheritors

Hardware

class Hardware : PropertiesBase, JsonSerializable

Collection of properties to identify the device type

ManagedObject

data class ManagedObject : PropertiesBase, JsonSerializable

This is the single most important asset type referenced by Cumulocity. Principally identifies the devices to be managed, but can be used to define any required asset type, such as groups, buildings, rooms etc. etc.