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 Details

    • TYPE

      public static final Item TYPE
      The type of item represented by this class.
      See Also:
      Item.USERDEVICE, getType()
    • RUNTIME_FILTER

      private static final QueryRuntimeFilter RUNTIME_FILTER
      This filter will limit a query to only return devices for the logged in user unless the logged in user has generic read permission.
  • Constructor Details

  • Method Details

    • getById

      public static UserDevice getById​(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
      Get a UserDevice item when you know the ID.
      Parameters:
      dc - The DbControl 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 the BasicData object that holds all data for this item.
      Specified by:
      getData in class BasicItem
    • 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 the Item enumeration.
      Specified by:
      getType in interface Identifiable
      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 class BasicItem
      Parameters:
      granted - Permissions that have been granted by the subclass
      denied - 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 interface Registered
      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 interface Registered
      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.
      Specified by:
      getName in interface Nameable
      Returns:
      A String with 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 the Nameable.MAX_NAME_LENGTH constant.
      Specified by:
      setName in interface Nameable
      Parameters:
      name - The new name for the item
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the name is null or longer than specified by the Nameable.MAX_NAME_LENGTH constant
    • getDescription

      public String getDescription()
      Description copied from interface: Nameable
      Get the description for the item.
      Specified by:
      getDescription in interface Nameable
      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 the Nameable.MAX_DESCRIPTION_LENGTH constant.
      Specified by:
      setDescription in interface Nameable
      Parameters:
      description - The new description for the item
      Throws:
      PermissionDeniedException - If the logged in user doesn't have write permission
      InvalidDataException - If the description longer than specified by the Nameable.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 have Permission.READ permission
      BaseException - 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 have Permission.READ permission
      BaseException - 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
    • isVerified

      public boolean isVerified()
      Has this device been verified or not? Verification is done by requesting a code via email.
      Since:
      3.17
    • getSessions

      public ItemQuery<Session> getSessions()
      Get a query for loading login session from this device.
      Since:
      3.17