Package net.sf.basedb.core
Class UserDevice
- java.lang.Object
-
- net.sf.basedb.core.BasicItem
-
- net.sf.basedb.core.UserDevice
-
- All Implemented Interfaces:
AccessControlled
,Identifiable
,Nameable
,Registered
public class UserDevice extends BasicItem implements Registered, Nameable
A user device represents a verified device a user may use for accessing BASE.- Since:
- 3.12
- Author:
- Nicklas
-
-
Field Summary
Fields Modifier and Type Field Description static Item
TYPE
The type of item represented by this class.-
Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
-
-
Constructor Summary
Constructors Constructor Description UserDevice(UserDeviceData deviceData)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static UserDevice
getById(DbControl dc, int id)
Get aUserDevice
item when you know the ID.Client
getClient()
Get the client application the user was using with this device.(package private) UserDeviceData
getData()
Get theBasicData
object that holds all data for this item.String
getDescription()
Get the description for the item.Date
getEntryDate()
Get the date that the item was registered in the database.String
getLastRemoteId()
Get the remote ID of the host the user used for this device the last time.Date
getLastUsed()
Get the date and time the user last used this device.String
getLocation()
Get the last known location of the device.Float
getLocationLatitude()
Get the last known location latitude of the device.Float
getLocationLongitude()
Get the last known location longitude of the device.String
getName()
Get the name of the item.static ItemQuery<UserDevice>
getQuery(User user)
Get a query configured to retrieve devices for the specified user.Item
getType()
Get the type of item represented by the object.User
getUser()
Get the user that owns this device.String
getUserAgent()
Get the user agent string of this device.(package private) void
initPermissions(int granted, int denied)
DELETE permission is granted if the logged in user is the owner of this device.void
setDescription(String description)
Set the description for the item.void
setEntryDate(Date entryDate)
Set the date the entry was registered in the database.void
setName(String name)
Set the name of the item.-
Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, validate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
-
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
-
-
-
-
Field Detail
-
TYPE
public static final Item TYPE
The type of item represented by this class.- See Also:
Item.USERDEVICE
,getType()
-
-
Constructor Detail
-
UserDevice
UserDevice(UserDeviceData deviceData)
-
-
Method Detail
-
getById
public static UserDevice getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
Get aUserDevice
item when you know the ID.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database access.id
- The ID of the item to load- Returns:
- The
UserDevice
item - Throws:
ItemNotFoundException
PermissionDeniedException
BaseException
-
getQuery
public static ItemQuery<UserDevice> getQuery(User user)
Get a query configured to retrieve devices for the specified user.- Parameters:
user
- The user to retreive devices for, null is allowed if the logged in user has generic READ permission for devices in which case all devices will be returned- Returns:
- An
ItemQuery
object
-
getData
UserDeviceData getData()
Description copied from class:BasicItem
Get theBasicData
object that holds all data for this item.
-
getType
public Item getType()
Description copied from interface:Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in theItem
enumeration.- Specified by:
getType
in interfaceIdentifiable
- Returns:
- A value indicating the type of item
-
initPermissions
void initPermissions(int granted, int denied) throws BaseException
DELETE permission is granted if the logged in user is the owner of this device.- Overrides:
initPermissions
in classBasicItem
- Parameters:
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclass- Throws:
BaseException
- If the permissions couldn't be initialised
-
getEntryDate
public Date getEntryDate()
Description copied from interface:Registered
Get the date that the item was registered in the database.- Specified by:
getEntryDate
in interfaceRegistered
- Returns:
- A date or null if this is not known
-
setEntryDate
public void setEntryDate(Date entryDate)
Description copied from interface:Registered
Set the date the entry was registered in the database. Implementations should only allow this property to be set before the item is first stored in the database. The intention of this method is to facilitate export/import of data between server.- Specified by:
setEntryDate
in interfaceRegistered
- Parameters:
entryDate
- A date or null to use today's date
-
getName
public String getName()
Description copied from interface:Nameable
Get the name of the item.
-
setName
public void setName(String name) throws PermissionDeniedException, InvalidDataException
Description copied from interface:Nameable
Set the name of the item. The name cannot be null and mustn't be longer than the value specified by theNameable.MAX_NAME_LENGTH
constant.- Specified by:
setName
in interfaceNameable
- Parameters:
name
- The new name for the item- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the name is null or longer than specified by theNameable.MAX_NAME_LENGTH
constant
-
getDescription
public String getDescription()
Description copied from interface:Nameable
Get the description for the item.- Specified by:
getDescription
in interfaceNameable
- Returns:
- A
String
with a description of the item
-
setDescription
public void setDescription(String description) throws PermissionDeniedException, InvalidDataException
Description copied from interface:Nameable
Set the description for the item. The description can be null but mustn't be longer than the value specified by theNameable.MAX_DESCRIPTION_LENGTH
constant.- Specified by:
setDescription
in interfaceNameable
- Parameters:
description
- The new description for the item- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the description longer than specified by theNameable.MAX_DESCRIPTION_LENGTH
constant
-
getUser
public User getUser() throws PermissionDeniedException, BaseException
Get the user that owns this device.- Returns:
- The
User
item - Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.READ
permissionBaseException
- If there is another error
-
getClient
public Client getClient() throws PermissionDeniedException, BaseException
Get the client application the user was using with this device.- Returns:
- A
Client
item, or null if not known - Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.READ
permissionBaseException
- If there is another error
-
getLastUsed
public Date getLastUsed()
Get the date and time the user last used this device.- Returns:
- A
Date
object with the date and time
-
getUserAgent
public String getUserAgent()
Get the user agent string of this device.
-
getLastRemoteId
public String getLastRemoteId()
Get the remote ID of the host the user used for this device the last time. Typically it is the IP-address of the user's computer.- Returns:
- A
String
object with remote ID
-
getLocation
public String getLocation()
Get the last known location of the device.- Returns:
- A
String
object with location or null if not known
-
getLocationLatitude
public Float getLocationLatitude()
Get the last known location latitude of the device.- Returns:
- A
Float
object with latitude or null if not known
-
getLocationLongitude
public Float getLocationLongitude()
Get the last known location longitude of the device.- Returns:
- A
Float
object with longitude or null if not known
-
-