Package com.gears42.iot.webthing
Class DatabaseHandlerImpl
- java.lang.Object
-
- android.database.sqlite.SQLiteOpenHelper
-
- com.gears42.iot.webthing.DatabaseHandlerImpl
-
- All Implemented Interfaces:
DatabaseHandlerI
,java.lang.AutoCloseable
public class DatabaseHandlerImpl extends android.database.sqlite.SQLiteOpenHelper implements DatabaseHandlerI
Manages Database operations of the Framework.
-
-
Constructor Summary
Constructors Constructor Description DatabaseHandlerImpl(android.content.Context context)
Clean compliance data based on intersection of current and old compliance job.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addComplianceConfig(java.lang.String thingId, java.lang.String ruleName, java.lang.String deviceProperty, java.lang.String ruleCondition, int duration, java.lang.String ruleValue, java.lang.String pollingType)
Add compliance configuration.void
addComplianceProperty(java.lang.String thingId, java.lang.String property, java.lang.String value, java.lang.String type)
Add compliance property data.void
addEvent(java.lang.String requestId, java.lang.String data)
Add a compliance event.void
addJobXML(java.lang.String thingId, java.lang.String jobXML)
Add JobXML.void
addOrUpdateCompianceProperty(java.lang.String thingId, java.lang.String property, java.lang.String value, java.lang.String type)
Add or update compliance property data.void
addOrUpdateComplianceConfig(java.lang.String thingId, java.lang.String ruleName, java.lang.String deviceProperty, java.lang.String ruleCondition, int duration, java.lang.String ruleValue, java.lang.String pollingType)
Add or update compliance configuration based on existence.void
addOrUpdateJobXML(java.lang.String thingId, java.lang.String jobXML)
Add or Update JobXML.boolean
cleanDB(java.lang.String thingId, java.util.List<java.lang.String> properties)
Clean compliance DB data based on intersection of current and old compliance job.void
deleteCompliance(java.lang.String thingId)
Delete compliance for a thing.boolean
deleteComplianceConfig(java.lang.String thingId, java.lang.String property)
Delete compliance configuration for a property.boolean
deleteComplianceProperty(java.lang.String thingId, java.lang.String property)
Delete compliance data for a property.void
deleteEvent(java.lang.String requestId)
Delete a compliance event.void
deleteJobXML(java.lang.String thingId)
Delete JobXML.org.json.JSONObject
getAllConfig()
Get compliance configuration for all properties.org.json.JSONObject
getAllEvents()
Get all compliance events.org.json.JSONObject
getAllPendingEvents()
Get all pending compliance events.org.json.JSONArray
getComplianceProperties()
Get all compliance properties data.org.json.JSONObject
getConfigForProperty(java.lang.String thingId, java.lang.String property)
Get compliance configuration for a property.java.util.List<java.lang.String>
getConfigPropertyNames(java.lang.String thingId, boolean onlyNormalPoll)
List of compliance configured properties.java.lang.String
getJobXML(java.lang.String thingId)
Get JobXML.java.util.List<java.lang.String>
getThingIDs()
List of thingIds on which the compliance is configured.boolean
isCompliancePropertyExists(java.lang.String thingId, java.lang.String property)
Check if compliance data of a property exists.void
onCreate(android.database.sqlite.SQLiteDatabase db)
void
onUpgrade(android.database.sqlite.SQLiteDatabase db, int oldVersion, int newVersion)
void
setCompliance(java.lang.String thingId, java.lang.String property, int isCompliant, long complianceTime)
Set compliance status of a property.void
setNixNotify(java.lang.String requestId, int nixNotified, int notifyCount)
Set nix notify status of a property.void
updateComplianceConfig(java.lang.String thingId, java.lang.String ruleName, java.lang.String deviceProperty, java.lang.String ruleCondition, int duration, java.lang.String ruleValue, java.lang.String pollingType)
Update compliance configuration based on existence.void
updateComplianceProperty(java.lang.String thingId, java.lang.String property, java.lang.String value)
Update compliance property data.void
updateJobXML(java.lang.String thingId, java.lang.String jobXML)
Update JobXML.
-
-
-
Method Detail
-
onCreate
public void onCreate(android.database.sqlite.SQLiteDatabase db)
- Specified by:
onCreate
in classandroid.database.sqlite.SQLiteOpenHelper
-
onUpgrade
public void onUpgrade(android.database.sqlite.SQLiteDatabase db, int oldVersion, int newVersion)
- Specified by:
onUpgrade
in classandroid.database.sqlite.SQLiteOpenHelper
-
addOrUpdateComplianceConfig
public void addOrUpdateComplianceConfig(java.lang.String thingId, java.lang.String ruleName, java.lang.String deviceProperty, java.lang.String ruleCondition, int duration, java.lang.String ruleValue, java.lang.String pollingType)
Add or update compliance configuration based on existence.- Specified by:
addOrUpdateComplianceConfig
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.ruleName
- Name of the rule.deviceProperty
- Compliance configured property.ruleCondition
- Condition to decide compliance.duration
- Duration till which the property should stay out of compliance to decide it as the later.ruleValue
- Threshold value.pollingType
- Property polling type.
-
addComplianceConfig
public void addComplianceConfig(java.lang.String thingId, java.lang.String ruleName, java.lang.String deviceProperty, java.lang.String ruleCondition, int duration, java.lang.String ruleValue, java.lang.String pollingType)
Add compliance configuration.- Specified by:
addComplianceConfig
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.ruleName
- Name of the rule.deviceProperty
- Compliance configured property.ruleCondition
- Condition to decide compliance.duration
- Duration till which the property should stay out of compliance to decide it as the later.ruleValue
- Threshold value.pollingType
- Property polling type.
-
updateComplianceConfig
public void updateComplianceConfig(java.lang.String thingId, java.lang.String ruleName, java.lang.String deviceProperty, java.lang.String ruleCondition, int duration, java.lang.String ruleValue, java.lang.String pollingType)
Update compliance configuration based on existence.- Specified by:
updateComplianceConfig
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.ruleName
- Name of the rule.deviceProperty
- Compliance configured property.ruleCondition
- Condition to decide compliance.duration
- Duration till which the property should stay out of compliance to decide it as the later.ruleValue
- Threshold value.pollingType
- Property polling type.
-
cleanDB
public boolean cleanDB(java.lang.String thingId, java.util.List<java.lang.String> properties)
Clean compliance DB data based on intersection of current and old compliance job.- Specified by:
cleanDB
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.properties
- List of current job properties.- Returns:
- is cleanDB success.
-
getThingIDs
public java.util.List<java.lang.String> getThingIDs()
List of thingIds on which the compliance is configured.- Specified by:
getThingIDs
in interfaceDatabaseHandlerI
- Returns:
- List of thingIds.
-
getConfigPropertyNames
public java.util.List<java.lang.String> getConfigPropertyNames(java.lang.String thingId, boolean onlyNormalPoll)
List of compliance configured properties.- Specified by:
getConfigPropertyNames
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.onlyNormalPoll
- Property polling type.- Returns:
- List of Property names.
-
addOrUpdateCompianceProperty
public void addOrUpdateCompianceProperty(java.lang.String thingId, java.lang.String property, java.lang.String value, java.lang.String type)
Add or update compliance property data.- Specified by:
addOrUpdateCompianceProperty
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.property
- property name.value
- Latest value of the property.type
- Value type of the property.
-
addComplianceProperty
public void addComplianceProperty(java.lang.String thingId, java.lang.String property, java.lang.String value, java.lang.String type)
Add compliance property data.- Specified by:
addComplianceProperty
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.property
- property name.value
- Latest value of the property.type
- Value type of the property.
-
updateComplianceProperty
public void updateComplianceProperty(java.lang.String thingId, java.lang.String property, java.lang.String value)
Update compliance property data.- Specified by:
updateComplianceProperty
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.property
- property name.value
- Latest value of the property.
-
isCompliancePropertyExists
public boolean isCompliancePropertyExists(java.lang.String thingId, java.lang.String property)
Check if compliance data of a property exists.- Specified by:
isCompliancePropertyExists
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.property
- property name.- Returns:
- true if compliance data of a property exists.
-
getComplianceProperties
public org.json.JSONArray getComplianceProperties()
Get all compliance properties data.- Specified by:
getComplianceProperties
in interfaceDatabaseHandlerI
- Returns:
- All compliance properties data.
-
getConfigForProperty
public org.json.JSONObject getConfigForProperty(java.lang.String thingId, java.lang.String property)
Get compliance configuration for a property.- Specified by:
getConfigForProperty
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.property
- property name.- Returns:
- Compliance configuration for a property.
-
getAllConfig
public org.json.JSONObject getAllConfig()
Get compliance configuration for all properties.- Specified by:
getAllConfig
in interfaceDatabaseHandlerI
- Returns:
- Compliance configuration for all properties.
-
setCompliance
public void setCompliance(java.lang.String thingId, java.lang.String property, int isCompliant, long complianceTime)
Set compliance status of a property.- Specified by:
setCompliance
in interfaceDatabaseHandlerI
- Parameters:
thingId
- Id of the thing.property
- property name.isCompliant
- compliant status.complianceTime
- Time of compliance status change.
-
deleteCompliance
public void deleteCompliance(java.lang.String thingId)
Delete compliance for a thing.- Specified by:
deleteCompliance
in interfaceDatabaseHandlerI
- Parameters:
thingId
- thingId.
-
deleteComplianceConfig
public boolean deleteComplianceConfig(java.lang.String thingId, java.lang.String property)
Delete compliance configuration for a property.- Specified by:
deleteComplianceConfig
in interfaceDatabaseHandlerI
- Parameters:
thingId
- thingId.property
- compliance property.- Returns:
- true if successful, false otherwise.
-
deleteComplianceProperty
public boolean deleteComplianceProperty(java.lang.String thingId, java.lang.String property)
Delete compliance data for a property.- Specified by:
deleteComplianceProperty
in interfaceDatabaseHandlerI
- Parameters:
thingId
- thingId.property
- compliance property.- Returns:
- true if successful, false otherwise.
-
addEvent
public void addEvent(java.lang.String requestId, java.lang.String data)
Add a compliance event.- Specified by:
addEvent
in interfaceDatabaseHandlerI
- Parameters:
requestId
- Event requestId.data
- Event data.
-
deleteEvent
public void deleteEvent(java.lang.String requestId)
Delete a compliance event.- Specified by:
deleteEvent
in interfaceDatabaseHandlerI
- Parameters:
requestId
- Event requestId.
-
setNixNotify
public void setNixNotify(java.lang.String requestId, int nixNotified, int notifyCount)
Set nix notify status of a property.- Specified by:
setNixNotify
in interfaceDatabaseHandlerI
- Parameters:
requestId
- requestId of event.nixNotified
- Nix notified status.notifyCount
- notify try count.
-
getAllPendingEvents
public org.json.JSONObject getAllPendingEvents()
Get all pending compliance events.- Specified by:
getAllPendingEvents
in interfaceDatabaseHandlerI
- Returns:
- Pending events.
-
getAllEvents
public org.json.JSONObject getAllEvents()
Get all compliance events.- Specified by:
getAllEvents
in interfaceDatabaseHandlerI
- Returns:
- All compliance events.
-
deleteJobXML
public void deleteJobXML(java.lang.String thingId)
Delete JobXML.- Specified by:
deleteJobXML
in interfaceDatabaseHandlerI
- Parameters:
thingId
- thingId.
-
addOrUpdateJobXML
public void addOrUpdateJobXML(java.lang.String thingId, java.lang.String jobXML)
Add or Update JobXML.- Specified by:
addOrUpdateJobXML
in interfaceDatabaseHandlerI
- Parameters:
thingId
- thingId.jobXML
- jobXML.
-
addJobXML
public void addJobXML(java.lang.String thingId, java.lang.String jobXML)
Add JobXML.- Specified by:
addJobXML
in interfaceDatabaseHandlerI
- Parameters:
thingId
- thingId.jobXML
- jobXML.
-
updateJobXML
public void updateJobXML(java.lang.String thingId, java.lang.String jobXML)
Update JobXML.- Specified by:
updateJobXML
in interfaceDatabaseHandlerI
- Parameters:
thingId
- thingId.jobXML
- jobXML.
-
getJobXML
public java.lang.String getJobXML(java.lang.String thingId)
Get JobXML.- Specified by:
getJobXML
in interfaceDatabaseHandlerI
- Parameters:
thingId
- thingId.- Returns:
- jobXML.
-
-