org.opengts.extra.tables
Class DeviceMessage

java.lang.Object
  extended by org.opengts.dbtools.DBRecord<RT>
      extended by org.opengts.db.AccountRecord<RT>
          extended by org.opengts.db.DeviceRecord<DeviceMessage>
              extended by org.opengts.extra.tables.DeviceMessage

public class DeviceMessage
extends DeviceRecord<DeviceMessage>


Nested Class Summary
static class DeviceMessage.Key
           
static class DeviceMessage.MessageComparator
          MessageComparator class for sorting DeviceMessage objects
static class DeviceMessage.MessageType
           
 
Nested classes/interfaces inherited from class org.opengts.db.DeviceRecord
DeviceRecord.DeviceKey<RT extends DBRecord>
 
Nested classes/interfaces inherited from class org.opengts.db.AccountRecord
AccountRecord.AccountKey<RT extends DBRecord>
 
Nested classes/interfaces inherited from class org.opengts.dbtools.DBRecord
DBRecord.DBChangeListener
 
Field Summary
static java.lang.String _TABLE_NAME
           
static java.lang.String CR_NO
           
static java.lang.String CR_OK
           
static java.lang.String CR_READ
           
static java.lang.String CR_TEXT
           
static java.lang.String CR_YES
           
static long DEFAULT_EXPIRATION_DAYS
           
static java.lang.String FLD_ackLatitude
           
static java.lang.String FLD_ackLongitude
           
static java.lang.String FLD_ackResponse
           
static java.lang.String FLD_ackTimestamp
           
static java.lang.String FLD_expireTimestamp
           
static java.lang.String FLD_message
           
static java.lang.String FLD_messageID
           
static java.lang.String FLD_messageSender
           
static java.lang.String FLD_messageTitle
           
static java.lang.String FLD_messageType
           
static java.lang.String FLD_priority
           
static java.lang.String FLD_queueTimestamp
           
static java.lang.String FLD_readTimestamp
           
static java.lang.String FLD_sentTimestamp
           
 
Fields inherited from class org.opengts.db.DeviceRecord
FLD_deviceID
 
Fields inherited from class org.opengts.db.AccountRecord
FLD_accountID, FLD_displayName, FLD_isActive, FLD_notes
 
Fields inherited from class org.opengts.dbtools.DBRecord
errorDescription, excludedUpdateFields, FLD_creationMillis, FLD_creationTime, FLD_description, FLD_lastUpdateAccount, FLD_lastUpdateTime, FLD_lastUpdateUser, hasError, ID_SIZE, isValidating, lastSQLException, NOTIFY_GROUP, PSEUDO_FIELD_CHAR, tempProps
 
Constructor Summary
DeviceMessage()
           
DeviceMessage(DeviceMessage.Key key)
           
 
Method Summary
static long ackMessage(Device dev, java.lang.String msgID, long ackTime, java.lang.String response, GeoPoint gp)
          Acknowledges the specified message.
 java.lang.String formatTimestamp(long timestamp)
          Formats the specified timestamp as a string
 double getAckLatitude()
          Gets the ack latitude
 GeoPoint getAckLocation()
          Gets the ack GeoPoint
 double getAckLongitude()
          Gets the ack longitude
 java.lang.String getAckResponse()
          Gets the acknowledged response
 long getAckTimestamp()
          Gets the time that the message was acknowledged
static DeviceMessage getDeviceMessage(Device dev, java.lang.String msgID)
          Gets an existing DeviceMessage record.
static DeviceMessage getDeviceMessage(Device dev, java.lang.String msgID, boolean create)
          Gets/Creates a DeviceMessage Note: does NOT return null (throws exception if not found)
 long getExpireTimestamp()
          Gets the time that the message expires
 long getExpireTimestamp(long dft)
          Gets the time that the message expires
static DBFactory<DeviceMessage> getFactory()
           
 java.lang.String getMessage()
          Gets the message
 java.lang.String getMessageID()
          Gets the MessageID
static OrderedSet<java.lang.String> getMessageIDsForDevice(Device dev, boolean pendingOnly, long limit)
          Returns a list of MessageIDs owned by the specified Account/Device.
static OrderedSet<java.lang.String> getMessageIDsForDevice(java.lang.String acctId, java.lang.String devId, boolean pendingOnly, long limit)
          Returns a list of MessageIDs owned by the specified Account/Device.
 java.lang.String getMessageSender()
          Gets the message sender
static DeviceMessage[] getMessagesForDevice(Device dev, long lastUpdTS, boolean pendingOnly, boolean nonExpiredOnly, long limit)
          Returns a list of Messages owned by the specified Account/Device.
 java.lang.String getMessageTitle()
          Gets the message title
 int getMessageType()
          Gets the enumerated message type
static DeviceMessage.MessageType getMessageType(DeviceMessage dmi)
          Returns the defined MessageType for the specified DeviceMessageInterface.
static DeviceMessage[] getPendingMessagesForDevice(Device dev, long limit)
          Returns a list of pending Messages owned by the specified Account/Device.
 int getPriority()
          Gets the message priority
 long getQueueTimestamp()
          Gets the time that the message was initially queued
 long getReadTimestamp()
          Gets the time that the message was initially read
 long getSentTimestamp()
          Gets the time that the message was initially sent
static java.lang.String getTableDescription(java.util.Locale loc)
           
 boolean hasAckLocation()
          Returns true if ack location has been defined
static boolean hasPendingMessagesForDevice(Device dev)
          Returns true if the specified Account/Device has pending messages.
 void insert()
          Insert this DBRecord in the database.
An exception will be throw if the record already exists
 boolean isAcknowledged()
          Returns true if message has acknowledged by device
 boolean isRead()
          Returns true if message has read by device
 boolean isSent()
          Returns true if message has been sent to device
static void main(java.lang.String[] argv)
           
 void setAckLatitude(double v)
          Gets the ack latitude
 void setAckLocation(GeoPoint gp)
          Sets the ack GeoPoint
 void setAckLongitude(double v)
          Sets the ack longitude
 void setAckResponse(java.lang.String v)
          Sets the acknowledged response
 void setAckTimestamp(long v)
          Sets the time that the message was acknowledged
 void setCreationDefaultValues()
          Override to set default values
 void setExpireTimestamp(long v)
          Sets the time that the message expires
 void setMessage(java.lang.String v)
          Sets the message
 void setMessageID(long v)
          Sets the MessageID as a long value
 void setMessageID(java.lang.String v)
          Sets the MessageID
 void setMessageSender(java.lang.String v)
          Sets the message sender
 void setMessageTitle(java.lang.String v)
          Sets the message title
 void setMessageType(DeviceMessage.MessageType v)
          Sets the enumerated message type
 void setMessageType(int v)
          Sets the enumerated message type
 void setPriority(int v)
          Sets the message priority
 void setQueueTimestamp(long v)
          Sets the time that the message was initially queued
 void setReadTimestamp(long v)
          Sets the time that the message was initially read
 void setSent(long sentTime, boolean update)
          Sets this DeviceMessage as sent, and optionally updates the record
 void setSentTimestamp(long v)
          Sets the time that the message was initially sent
static java.lang.String TABLE_NAME()
           
 void update(java.util.Set<java.lang.String> updFldSet)
          Updates the specified fields in this DBRecord.
 
Methods inherited from class org.opengts.db.DeviceRecord
getDevice, getDeviceDescription, getDeviceID, getDeviceVIN, hasDevice, newField_deviceID, newField_deviceID, newField_deviceID, newField_deviceID, setDevice, setDeviceID
 
Methods inherited from class org.opengts.db.AccountRecord
createSystemAdminAccount, getAccount, getAccountDescription, getAccountID, getDisplayName, getFilteredID, getFilteredID, getIsActive, getNotes, GetSimpleLocalString, getSystemAdminAccount, getSystemAdminAccountID, hasAccount, hasSystemAdminAccountID, isAccountManager, isActive, isSystemAdmin, isSystemAdmin, isSystemAdminAccountID, isValidID, newField_accountID, newField_accountID, newField_displayName, newField_displayName, newField_isActive, newField_isActive, newField_notes, newField_notes, setAccount, setDisplayName, setIsActive, setNotes, setRuntimeDefaultValues
 
Methods inherited from class org.opengts.dbtools.DBRecord
_getFactory, _reload, addChangedNotification, addExcludedUpdateFields, adjustStringLength_1, adjustStringLength, appendFieldValues, clearChanged, clearError, clearExcludedUpdateFields, clearLastCaughtSQLException, equals, excludeFieldFromUpdate, excludeFieldFromUpdate, fireChangeNotification, geKeyValue, getCreationDateTime, getCreationMillis, getCreationTime, GetCurrentAccount, GetCurrentUser, getDefaultFieldValueKey, getDescription, getErrorDescription, getFactory, getFactory, getField, getFieldBoolean, getFieldDateTime, getFieldDouble, getFieldFloat, getFieldInt, getFieldLong, getFieldName, getFieldString, getFieldValue, getFieldValue, getFieldValue, getFieldValue, getFieldValue, getFieldValue, getFieldValue, getFieldValue, getFieldValue, getKeyValue, getLastCaughtSQLException, getLastUpdateAccount, getLastUpdateTime, getLastUpdateTime, getLastUpdateUser, getNextGroup, getOptionalFieldValue, getOptionalFieldValue, getOptionalFieldValue, getOptionalFieldValue, getOptionalFieldValue, getOptionalFieldValue, getOptionalFieldValue, getOptionalFieldValue, getOptionalFieldValue, getRecordCount, getRecordCount, getRecordCount, getRecordCount, getRecordCount, getRecordKey, getRecords, getRecords, getTemporaryProperties, getValue, getVirtual, hasChanged, hasError, hasField, hasFieldValue, hasOptionalFieldValue, hasTemporaryProperties, isFieldUnsigned, isLastCaughtSQLExceptionErrorCode, isOkToReload, isOkToSave, isValidating, isVirtual, lock, lockRead, lockWrite, newField_creationMillis, newField_creationTime, newField_creationTime, newField_description, newField_description, newField_lastUpdateAccount, newField_lastUpdateAccount, newField_lastUpdateTime, newField_lastUpdateUser, newField_lastUpdateUser, printXML, printXML, printXML, printXML, printXML, printXML, recordDidInsert, recordDidUpdate, recordWillInsert, recordWillUpdate, reload, reload, removeChangedNotification, save, select, select, select, setAllFieldValues, setAllFieldValues, setAllFieldValues, setAllFieldValues, setChanged, setChanged, setCreationMillis, setCreationTime, SetCurrentAccount, SetCurrentUser, setDescription, setError, setError, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setFieldValue, setIgnoreInvalidFields, setKeyValue, setLastCaughtSQLException, setLastUpdateAccount, setLastUpdateTime, setLastUpdateUser, setOptionalFieldValue, setOptionalFieldValue, setOptionalFieldValue, setOptionalFieldValue, setOptionalFieldValue, setOptionalFieldValue, setOptionalFieldValue, setOptionalFieldValue, setValidating, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setVirtual, toString, toXML, toXML, toXML, toXML, toXML, unlock, update, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_EXPIRATION_DAYS

public static final long DEFAULT_EXPIRATION_DAYS
See Also:
Constant Field Values

CR_READ

public static final java.lang.String CR_READ
See Also:
Constant Field Values

CR_OK

public static final java.lang.String CR_OK
See Also:
Constant Field Values

CR_YES

public static final java.lang.String CR_YES
See Also:
Constant Field Values

CR_NO

public static final java.lang.String CR_NO
See Also:
Constant Field Values

CR_TEXT

public static final java.lang.String CR_TEXT
See Also:
Constant Field Values

_TABLE_NAME

public static final java.lang.String _TABLE_NAME
See Also:
Constant Field Values

FLD_messageID

public static final java.lang.String FLD_messageID
See Also:
Constant Field Values

FLD_queueTimestamp

public static final java.lang.String FLD_queueTimestamp
See Also:
Constant Field Values

FLD_messageSender

public static final java.lang.String FLD_messageSender
See Also:
Constant Field Values

FLD_messageTitle

public static final java.lang.String FLD_messageTitle
See Also:
Constant Field Values

FLD_message

public static final java.lang.String FLD_message
See Also:
Constant Field Values

FLD_messageType

public static final java.lang.String FLD_messageType
See Also:
Constant Field Values

FLD_priority

public static final java.lang.String FLD_priority
See Also:
Constant Field Values

FLD_expireTimestamp

public static final java.lang.String FLD_expireTimestamp
See Also:
Constant Field Values

FLD_sentTimestamp

public static final java.lang.String FLD_sentTimestamp
See Also:
Constant Field Values

FLD_readTimestamp

public static final java.lang.String FLD_readTimestamp
See Also:
Constant Field Values

FLD_ackTimestamp

public static final java.lang.String FLD_ackTimestamp
See Also:
Constant Field Values

FLD_ackLatitude

public static final java.lang.String FLD_ackLatitude
See Also:
Constant Field Values

FLD_ackLongitude

public static final java.lang.String FLD_ackLongitude
See Also:
Constant Field Values

FLD_ackResponse

public static final java.lang.String FLD_ackResponse
See Also:
Constant Field Values
Constructor Detail

DeviceMessage

public DeviceMessage()

DeviceMessage

public DeviceMessage(DeviceMessage.Key key)
Method Detail

getMessageType

public static DeviceMessage.MessageType getMessageType(DeviceMessage dmi)
Returns the defined MessageType for the specified DeviceMessageInterface.

Parameters:
dmi - The DeviceMessageInterface from which the MessageType will be obtained. If null, the default MessageType will be returned.
Returns:
The MessageType

TABLE_NAME

public static java.lang.String TABLE_NAME()

getFactory

public static DBFactory<DeviceMessage> getFactory()

getTableDescription

public static java.lang.String getTableDescription(java.util.Locale loc)

update

public void update(java.util.Set<java.lang.String> updFldSet)
            throws DBException
Updates the specified fields in this DBRecord.

Overrides:
update in class DBRecord<DeviceMessage>
Parameters:
updFldSet - A Set of fields to update.
Throws:
DBException - if a database error occurs.

insert

public void insert()
            throws DBException
Insert this DBRecord in the database.
An exception will be throw if the record already exists

Overrides:
insert in class DBRecord<DeviceMessage>
Throws:
DBException - if a database error occurs.

getMessageID

public java.lang.String getMessageID()
Gets the MessageID


setMessageID

public void setMessageID(long v)
Sets the MessageID as a long value


setMessageID

public void setMessageID(java.lang.String v)
Sets the MessageID


getQueueTimestamp

public long getQueueTimestamp()
Gets the time that the message was initially queued


setQueueTimestamp

public void setQueueTimestamp(long v)
Sets the time that the message was initially queued


getExpireTimestamp

public long getExpireTimestamp()
Gets the time that the message expires


setExpireTimestamp

public void setExpireTimestamp(long v)
Sets the time that the message expires


getExpireTimestamp

public long getExpireTimestamp(long dft)
Gets the time that the message expires


getSentTimestamp

public long getSentTimestamp()
Gets the time that the message was initially sent


setSentTimestamp

public void setSentTimestamp(long v)
Sets the time that the message was initially sent


isSent

public boolean isSent()
Returns true if message has been sent to device


setSent

public void setSent(long sentTime,
                    boolean update)
             throws DBException
Sets this DeviceMessage as sent, and optionally updates the record

Throws:
DBException

getReadTimestamp

public long getReadTimestamp()
Gets the time that the message was initially read


setReadTimestamp

public void setReadTimestamp(long v)
Sets the time that the message was initially read


isRead

public boolean isRead()
Returns true if message has read by device


getMessageSender

public java.lang.String getMessageSender()
Gets the message sender


setMessageSender

public void setMessageSender(java.lang.String v)
Sets the message sender


getMessageTitle

public java.lang.String getMessageTitle()
Gets the message title


setMessageTitle

public void setMessageTitle(java.lang.String v)
Sets the message title


getMessage

public java.lang.String getMessage()
Gets the message


setMessage

public void setMessage(java.lang.String v)
Sets the message


getMessageType

public int getMessageType()
Gets the enumerated message type


setMessageType

public void setMessageType(int v)
Sets the enumerated message type


setMessageType

public void setMessageType(DeviceMessage.MessageType v)
Sets the enumerated message type


getPriority

public int getPriority()
Gets the message priority


setPriority

public void setPriority(int v)
Sets the message priority


getAckTimestamp

public long getAckTimestamp()
Gets the time that the message was acknowledged


setAckTimestamp

public void setAckTimestamp(long v)
Sets the time that the message was acknowledged


isAcknowledged

public boolean isAcknowledged()
Returns true if message has acknowledged by device


getAckLatitude

public double getAckLatitude()
Gets the ack latitude

Returns:
The ack latitude

setAckLatitude

public void setAckLatitude(double v)
Gets the ack latitude

Parameters:
v - The ack latitude

getAckLongitude

public double getAckLongitude()
Gets the ack longitude

Returns:
The ack longitude

setAckLongitude

public void setAckLongitude(double v)
Sets the ack longitude

Parameters:
v - The ack longitude

hasAckLocation

public boolean hasAckLocation()
Returns true if ack location has been defined

Returns:
True if ack location has been defined

getAckLocation

public GeoPoint getAckLocation()
Gets the ack GeoPoint

Returns:
The ack GeoPoint, null if not defined/invalid

setAckLocation

public void setAckLocation(GeoPoint gp)
Sets the ack GeoPoint


getAckResponse

public java.lang.String getAckResponse()
Gets the acknowledged response


setAckResponse

public void setAckResponse(java.lang.String v)
Sets the acknowledged response


setCreationDefaultValues

public void setCreationDefaultValues()
Override to set default values

Overrides:
setCreationDefaultValues in class DBRecord<DeviceMessage>

formatTimestamp

public java.lang.String formatTimestamp(long timestamp)
Formats the specified timestamp as a string


getDeviceMessage

public static DeviceMessage getDeviceMessage(Device dev,
                                             java.lang.String msgID)
                                      throws DBException
Gets an existing DeviceMessage record. Returns null if not found

Throws:
DBException

getDeviceMessage

public static DeviceMessage getDeviceMessage(Device dev,
                                             java.lang.String msgID,
                                             boolean create)
                                      throws DBException
Gets/Creates a DeviceMessage Note: does NOT return null (throws exception if not found)

Throws:
DBException

ackMessage

public static long ackMessage(Device dev,
                              java.lang.String msgID,
                              long ackTime,
                              java.lang.String response,
                              GeoPoint gp)
                       throws DBException
Acknowledges the specified message.

Returns:
The acknowledge timestamp if successfully acknowledged, otherwise returns 0 is the message does not exist, or if the message is already acknowledged.
Throws:
DBException

getMessageIDsForDevice

public static OrderedSet<java.lang.String> getMessageIDsForDevice(Device dev,
                                                                  boolean pendingOnly,
                                                                  long limit)
                                                           throws DBException
Returns a list of MessageIDs owned by the specified Account/Device. Does not return null

Throws:
DBException

getMessageIDsForDevice

public static OrderedSet<java.lang.String> getMessageIDsForDevice(java.lang.String acctId,
                                                                  java.lang.String devId,
                                                                  boolean pendingOnly,
                                                                  long limit)
                                                           throws DBException
Returns a list of MessageIDs owned by the specified Account/Device. Does not return null

Throws:
DBException

hasPendingMessagesForDevice

public static boolean hasPendingMessagesForDevice(Device dev)
                                           throws DBException
Returns true if the specified Account/Device has pending messages.

Throws:
DBException

getPendingMessagesForDevice

public static DeviceMessage[] getPendingMessagesForDevice(Device dev,
                                                          long limit)
                                                   throws DBException
Returns a list of pending Messages owned by the specified Account/Device. Will return null if there are no pending messages.

Throws:
DBException

getMessagesForDevice

public static DeviceMessage[] getMessagesForDevice(Device dev,
                                                   long lastUpdTS,
                                                   boolean pendingOnly,
                                                   boolean nonExpiredOnly,
                                                   long limit)
                                            throws DBException
Returns a list of Messages owned by the specified Account/Device. Will return null if there are no pending messages.

Throws:
DBException

main

public static void main(java.lang.String[] argv)