TwinParser Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.deps.serializer.TwinParser


public class TwinParser

Note

This class has been deprecated. As of release 0.4.0, replaced by TwinState

TwinParser Representation including the twin collection and Json serializer and deserializer.

Field Summary

Modifier and Type Field and Description
protected RegisterManagerParser manager
protected TwinProperties properties
protected TwinTags tags

Constructor Summary

Constructor Description
TwinParser()

CONSTRUCTOR Create a TwinParser instance with default values.

TwinParser(TwinChangedCallback onDesiredCallback)

CONSTRUCTOR Create a TwinParser instance with default values.

TwinParser(TwinChangedCallback onDesiredCallback, TwinChangedCallback onReportedCallback)

CONSTRUCTOR Create a TwinParser instance with default values.

Method Summary

Modifier and Type Method and Description
void enableMetadata()

Enable metadata report in the Json.

void enableTags()

Enable tags in the Twin collection and in the Json.

TwinConnectionState getConnectionState()

Getter for connection state

java.lang.String getConnectionStateUpdatedTime()

Getter for connection state updated date and time

java.util.Map<java.lang.String,java.lang.Object> getDesiredPropertyMap()

Return a map with all `desired` properties in the collection.

java.lang.Integer getDesiredPropertyVersion()

Return the `desired` property version.

java.lang.String getDeviceId()

Getter for device name

java.lang.String getETag()

Getter for ETag

java.lang.String getGenerationId()

Getter for device generation name

java.lang.String getLastActivityTime()

Getter for last activity time

java.util.Map<java.lang.String,java.lang.Object> getReportedPropertyMap()

Return a map with all `reported` properties in the collection.

java.lang.Integer getReportedPropertyVersion()

Return the `reported` property version.

TwinStatus getStatus()

Getter for device status

java.lang.String getStatusReason()

Getter for status reason

java.lang.String getStatusUpdatedTime()

Getter for status updated date and time

java.util.Map<java.lang.String,java.lang.Object> getTagsMap()

Return a map with all `tags` in the collection.

java.lang.Integer getVersion()

Getter for Twin version

java.lang.String resetDesiredProperty(Map<String,Object> propertyMap)

Reset the `desired` properties information in the collection, deleting all old properties and add all the new provided ones.

java.lang.String resetReportedProperty(Map<String,Object> propertyMap)

Reset the `reported` properties information in the collection, deleting all old properties and add all the new provided ones.

java.lang.String resetTags(Map<String,Object> tagsMap)

Reset the `tags` information in the collection, deleting all old tags and add all the new provided ones.

void setDesiredCallback(TwinChangedCallback onDesiredCallback)

Set the callback function to report changes on the `Desired` collection when `TwinParser` receives a new json.

void setDeviceId(String deviceId)

Setter for device name

void setETag(String eTag)

Setter for ETag.

void setReportedCallback(TwinChangedCallback onReportedCallback)

Set the callback function to report changes on the `Reported` collection when `TwinParser` receives a new json.

void setTagsCallback(TwinChangedCallback onTagsCallback)

Set the callback function to report changes on the `tags` collection when `TwinParser` receives a new json.

java.lang.String toJson()

Create a String with a json content that represents all the information in the TwinParser class and innerClasses.

com.google.gson.JsonElement toJsonElement()

Create a JsonElement that represents all the information in the TwinParser class and innerClasses.

void updateDesiredProperty(String json)

Update the `desired` properties information in the collection, using the information parsed from the provided json.

java.lang.String updateDesiredProperty(Map<String,Object> propertyMap)

Update the `desired` properties information in the collection, and return a string with a json that contains a sub-collection of added properties, or properties with new value.

java.lang.String updateDeviceManager(String deviceId, TwinStatus status, String statusReason)

Update the device manager information in the collection, and return a string with a json that contains a the new device manager description, including new and old values.

void updateReportedProperty(String json)

Update the `reported` properties information in the collection, using the information parsed from the provided json.

java.lang.String updateReportedProperty(Map<String,Object> propertyMap)

Update the `reported` properties information in the collection, and return a string with a json that contains a sub-collection of added properties, or properties with new value.

java.lang.String updateTags(Map<String,Object> tagsMap)

Update the `tags` information in the collection, and return a string with a json that contains a sub-collection of added tags, or tags with new value.

void updateTwin(String json)

Update the properties information in the collection, using the information parsed from the provided json.

java.lang.String updateTwin(Map<String,Object> desiredPropertyMap, Map<String,Object> reportedPropertyMap, Map<String,Object> tagsMap)

Update properties and tags information in the collection, and return a string with a json that contains a sub-collection of added properties, properties with new value, added tags, and tags with new values.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

manager

protected RegisterManagerParser manager

properties

protected TwinProperties properties

tags

protected TwinTags tags

Constructor Details

TwinParser

public TwinParser()

CONSTRUCTOR Create a TwinParser instance with default values. set OnDesiredCallback as null set OnReportedCallback as null set Tags as null

TwinParser

public TwinParser(TwinChangedCallback onDesiredCallback)

CONSTRUCTOR Create a TwinParser instance with default values. set OnReportedCallback as null set Tags as null

Parameters:

onDesiredCallback -
  • Callback function to report changes on the Desired collection.

TwinParser

public TwinParser(TwinChangedCallback onDesiredCallback, TwinChangedCallback onReportedCallback)

CONSTRUCTOR Create a TwinParser instance with default values. set Tags as null

Parameters:

onDesiredCallback -
  • Callback function to report changes on the Desired collection.
onReportedCallback -
  • Callback function to report changes on the Reported collection.

Method Details

enableMetadata

public void enableMetadata()

Enable metadata report in the Json.

enableTags

public void enableTags()

Enable tags in the Twin collection and in the Json.

getConnectionState

public TwinConnectionState getConnectionState()

Getter for connection state

Returns:

The connectionState string

getConnectionStateUpdatedTime

public String getConnectionStateUpdatedTime()

Getter for connection state updated date and time

Returns:

The string containing the time when the connectionState parameter was updated

getDesiredPropertyMap

public Map getDesiredPropertyMap()

Return a map with all `desired` properties in the collection.

Returns:

A map with all desired properties in the collection (it can be null).

getDesiredPropertyVersion

public Integer getDesiredPropertyVersion()

Return the `desired` property version.

Returns:

Integer that contains the desired property version (it can be null).

getDeviceId

public String getDeviceId()

Getter for device name

Returns:

Device name A case-sensitive string (up to 128 char long) of ASCII 7-bit alphanumeric chars
  • {'-', ':', '.', '+', '%', '_', '#', '*', '?', '!', '(', ')', ',', '=', '@', ';', '$', '''}.

getETag

public String getETag()

Getter for ETag

Returns:

A string representing a weak ETAG version of this JSON description. This is a hash.

getGenerationId

public String getGenerationId()

Getter for device generation name

Returns:

Device generation Id

getLastActivityTime

public String getLastActivityTime()

Getter for last activity time

Returns:

The string containing the time when the lastActivity parameter was updated

getReportedPropertyMap

public Map getReportedPropertyMap()

Return a map with all `reported` properties in the collection.

Returns:

A map with all reported properties in the collection (it can be null).

getReportedPropertyVersion

public Integer getReportedPropertyVersion()

Return the `reported` property version.

Returns:

Integer that contains the reported property version (it can be null).

getStatus

public TwinStatus getStatus()

Getter for device status

Returns:

"enabled", "disabled". If "enabled", this device is authorized to connect. If "disabled" this device cannot receive or send messages, and statusReason must be set.

getStatusReason

public String getStatusReason()

Getter for status reason

Returns:

A 128 char long string storing the reason of suspension. (all UTF-8 chars allowed).

getStatusUpdatedTime

public String getStatusUpdatedTime()

Getter for status updated date and time

Returns:

Datetime of last time the state was updated.

getTagsMap

public Map getTagsMap()

Return a map with all `tags` in the collection.

Returns:

A map with all tags in the collection (it can be null).

Throws:

java.io.IOException - This exception is thrown if tags the is not enabled.

getVersion

public Integer getVersion()

Getter for Twin version

Returns:

A Integer representing a twin tags and properties version in the JSON. It can be null

resetDesiredProperty

public String resetDesiredProperty(Map propertyMap)

Reset the `desired` properties information in the collection, deleting all old properties and add all the new provided ones. Return a string with a json that contains a sub-collection of added properties.

Parameters:

propertyMap -
  • Map of desired property to change the collection.

Returns:

Json with added properties

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the properties in the map do not fits the requirements.

resetReportedProperty

public String resetReportedProperty(Map propertyMap)

Reset the `reported` properties information in the collection, deleting all old properties and add all the new provided ones. Return a string with a json that contains a sub-collection of added properties.

Parameters:

propertyMap -
  • Map of reported property to change the collection.

Returns:

Json with added properties

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the properties in the map do not fits the requirements.

resetTags

public String resetTags(Map tagsMap)

Reset the `tags` information in the collection, deleting all old tags and add all the new provided ones. Return a string with a json that contains a sub-collection of added tags.

Parameters:

tagsMap -
  • Map of tags to change the collection.

Returns:

Json with added tags

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the tags in the map do not fits the requirements.
java.io.IOException - This exception is thrown if the tags in the map do not fits the requirements.

setDesiredCallback

public void setDesiredCallback(TwinChangedCallback onDesiredCallback)

Set the callback function to report changes on the `Desired` collection when `TwinParser` receives a new json.

Parameters:

onDesiredCallback -
  • Callback function to report changes on the Desired collection.

setDeviceId

public void setDeviceId(String deviceId)

Setter for device name

Parameters:

deviceId - device id A case-sensitive string (up to 128 char long) of ASCII 7-bit alphanumeric chars
  • {'-', ':', '.', '+', '%', '_', '#', '*', '?', '!', '(', ')', ',', '=', '@', ';', '$', '''}

Throws:

java.lang.IllegalArgumentException - if the provided device Id is not valid.

setETag

public void setETag(String eTag)

Setter for ETag.

Parameters:

eTag - is a string representing a weak ETAG version of this JSON description. This is a hash.

Throws:

java.lang.IllegalArgumentException - if the provided eTag Id is not valid.

setReportedCallback

public void setReportedCallback(TwinChangedCallback onReportedCallback)

Set the callback function to report changes on the `Reported` collection when `TwinParser` receives a new json.

Parameters:

onReportedCallback -
  • Callback function to report changes on the Reported collection.

setTagsCallback

public void setTagsCallback(TwinChangedCallback onTagsCallback)

Set the callback function to report changes on the `tags` collection when `TwinParser` receives a new json.

Parameters:

onTagsCallback -
  • Callback function to report changes on the Reported collection.

toJson

public String toJson()

Create a String with a json content that represents all the information in the TwinParser class and innerClasses.

Returns:

String with the json content.

toJsonElement

public JsonElement toJsonElement()

Create a JsonElement that represents all the information in the TwinParser class and innerClasses.

Returns:

JsonElement with the Twin information.

updateDesiredProperty

public void updateDesiredProperty(String json)

Update the `desired` properties information in the collection, using the information parsed from the provided json. It will fire a callback if any property was added, excluded, or had its value updated.

Parameters:

json -
  • Json with desired property to change the collection.

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the Json is not well formed.

updateDesiredProperty

public String updateDesiredProperty(Map propertyMap)

Update the `desired` properties information in the collection, and return a string with a json that contains a sub-collection of added properties, or properties with new value.

Parameters:

propertyMap -
  • Map of desired property to change the collection.

Returns:

Json with added or changed properties

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the properties in the map do not fits the requirements.

updateDeviceManager

public String updateDeviceManager(String deviceId, TwinStatus status, String statusReason)

Update the device manager information in the collection, and return a string with a json that contains a the new device manager description, including new and old values.

Parameters:

deviceId -
  • Device name
status -
  • Device status("enabled", "disabled")
statusReason -
  • A 128 char long string storing the reason of suspension (for status="disabled").

Returns:

Json with the manager description. Null if nothing change.

Throws:

java.lang.IllegalArgumentException - This exception is thrown if there are any inconsistent in the provided description.

updateReportedProperty

public void updateReportedProperty(String json)

Update the `reported` properties information in the collection, using the information parsed from the provided json. It will fire a callback if any property was added, excluded, or had its value updated.

Parameters:

json -
  • Json with reported property to change the collection.

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the Json is not well formed.

updateReportedProperty

public String updateReportedProperty(Map propertyMap)

Update the `reported` properties information in the collection, and return a string with a json that contains a sub-collection of added properties, or properties with new value.

Parameters:

propertyMap -
  • Map of reported property to change the collection.

Returns:

Json with added or changed properties

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the properties in the map do not fits the requirements.

updateTags

public String updateTags(Map tagsMap)

Update the `tags` information in the collection, and return a string with a json that contains a sub-collection of added tags, or tags with new value.

Parameters:

tagsMap -
  • Map of tags to change the collection.

Returns:

Json with added or changed tags

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the tags in the map do not fits the requirements.
java.io.IOException - This exception is thrown if the tags in the map do not fits the requirements.

updateTwin

public void updateTwin(String json)

Update the properties information in the collection, using the information parsed from the provided json. It will fire a callback if any property was added, excluded, or had its value updated.

Parameters:

json -
  • Json with property to change the collection.

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the Json is not well formed.

updateTwin

public String updateTwin(Map desiredPropertyMap, Map reportedPropertyMap, Map tagsMap)

Update properties and tags information in the collection, and return a string with a json that contains a sub-collection of added properties, properties with new value, added tags, and tags with new values.

Parameters:

desiredPropertyMap -
  • Map of desired property to change the collection.
reportedPropertyMap -
  • Map of reported property to change the collection.
tagsMap -
  • Map of tags to change the collection.

Returns:

Json with added or changed properties and tags

Throws:

java.lang.IllegalArgumentException - This exception is thrown if the properties or tags in the maps do not fits the requirements.
java.io.IOException - This exception is thrown if the properties or tags in the maps do not fits the requirements.

Applies to