2.17.2: 2011-06-17

net.sf.basedb.core
Class Quota

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<QuotaData>
      extended by net.sf.basedb.core.Quota
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Removable, SystemItem

public class Quota
extends BasicItem<QuotaData>
implements Nameable, SystemItem, Removable

This class is used to represent disk quota settings for users and groups. All users must have a quota that can be either assigned directly to the user or via a group where the user is a member.

Quota can be specified as a total for all types/locations, or with individual settings for each type/location.

Quota is handled like this:

  1. A DiskConsumable item tells BASE about the number of bytes, type of quota and location of the item.
  2. BASE (via the OwnedItem creates a DiskUsage item to hold that information and links it with the Quota for the owner of the DiskConsumable item.
  3. If the quota is exceeded, BASE will throw a QuotaException.

Version:
2.0
Author:
enell
See Also:
QuotaData
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Nested Class Summary
private static class Quota.QueryRuntimeFilterImpl
          A runtime filter implementation that limits a query to only return the quota assigned to the logged in user unless the logged in user has generic read permission.
 
Field Summary
static String DEFAULT
          The ID for the system default quota, which is assigned to new users unless another quota is specified.
private static QueryRuntimeFilter RUNTIME_FILTER
          This filter will only return the logged in user's quota unless the logged in user has generic read permission.
static Item TYPE
          The type of item represented by this class.
static long UNDEFINED
          Quota is is not defined.
static long UNLIMITED
          Quota is unlimited.
static String UNRESTRICTED
          The ID for the unrestricted quota, which gives users unlimited disk space.
 
Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Fields inherited from interface net.sf.basedb.core.SystemItem
MAX_SYSTEM_ID_LENGTH
 
Constructor Summary
Quota(QuotaData data)
          Create a new Quota item.
 
Method Summary
static Quota getById(DbControl dc, int id)
          Get a Quota item when you know the ID.
 String getDescription()
          Get the description for the item.
 String getName()
          Get the name of the item.
static Quota getNew(DbControl dc, long total)
          Create a new Quota item.
static ItemQuery<Quota> getQuery()
          Get a query configured to retrieve quota.
 long getQuotaValue(QuotaType quotaType, Location location)
          Get the quota for the specified type and location.
 String getSystemId()
          Get the system id for the item.
 Item getType()
          Get the type of item represented by the object.
 Set<ItemProxy> getUsingItems()
          Get all: User:s assigned to this quota Group:s assigned to this quota
(package private)  void initPermissions(int granted, int denied)
          The logged in user has read permission to the quota assigned to him/her, directly or through group quota.
 boolean isRemoved()
          Check if the removed flag is set for this item.
 boolean isSystemItem()
          Check if the item is a system item or not.
 boolean isUsed()
          Checks if: a Group has been assigned this quota a User has been assigned this quota
 void setDescription(String description)
          Set the description for the item.
 void setName(String name)
          Set the name of the item.
 void setQuotaValue(QuotaType quotaType, Location location, long bytes)
          Set the quota for the specified type, location and size.
 void setRemoved(boolean removed)
          Set the removed flag for this item.
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
 
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
ITEM.QUOTA, getType()

DEFAULT

public static final String DEFAULT
The ID for the system default quota, which is assigned to new users unless another quota is specified.

See Also:
Constant Field Values

UNRESTRICTED

public static final String UNRESTRICTED
The ID for the unrestricted quota, which gives users unlimited disk space.

See Also:
Constant Field Values

UNLIMITED

public static final long UNLIMITED
Quota is unlimited.

See Also:
Constant Field Values

UNDEFINED

public static final long UNDEFINED
Quota is is not defined.

See Also:
Constant Field Values

RUNTIME_FILTER

private static final QueryRuntimeFilter RUNTIME_FILTER
This filter will only return the logged in user's quota unless the logged in user has generic read permission.

Constructor Detail

Quota

Quota(QuotaData data)
Create a new Quota item.

Parameters:
data - The data class for this item.
Method Detail

getNew

public static Quota getNew(DbControl dc,
                           long total)
                    throws BaseException
Create a new Quota item.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
total - The total size inte bytes of this Quota.
Returns:
The new Quota item
Throws:
PermissionDeniedException - This exception is thrown if the logged in user doesn't have CREATE permission for this type of items
BaseException - This exception is thrown if there is another error

getById

public static Quota getById(DbControl dc,
                            int id)
                     throws ItemNotFoundException,
                            PermissionDeniedException,
                            BaseException
Get a Quota 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 Quota item
Throws:
ItemNotFoundException - If an item with the specified ID is not found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another error

getQuery

public static ItemQuery<Quota> getQuery()
Get a query configured to retrieve quota. If the logged in user has generic READ permission all items are returned, otherwise only the quota item that is assigned to the logged in user.

Returns:
An ItemQuery object

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

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

isRemoved

public boolean isRemoved()
Description copied from interface: Removable
Check if the removed flag is set for this item.

Specified by:
isRemoved in interface Removable
Returns:
TRUE if the item is flagged as removed, FALSE otherwise

setRemoved

public void setRemoved(boolean removed)
                throws PermissionDeniedException
Description copied from interface: Removable
Set the removed flag for this item.

Specified by:
setRemoved in interface Removable
Parameters:
removed - TRUE if the item should be flagged as removed, FALSE otherwise
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.DELETE permission for setting the flag to TRUE or Permission.WRITE permission for setting the flag to FALSE

getSystemId

public String getSystemId()
Description copied from interface: SystemItem
Get the system id for the item.

Specified by:
getSystemId in interface SystemItem
Returns:
The id of the item or null if it is not a system item

isSystemItem

public boolean isSystemItem()
Description copied from interface: SystemItem
Check if the item is a system item or not. A system item have a non-null value for the system id.

Specified by:
isSystemItem in interface SystemItem
Returns:
TRUE if this item is a system item, FALSE otherwise

isUsed

public boolean isUsed()
               throws BaseException
Checks if:

Overrides:
isUsed in class BasicItem<QuotaData>
Returns:
true if this item is used, false otherwise
Throws:
BaseException - If there is another error
See Also:
BasicItem.getUsingItems()

getUsingItems

public Set<ItemProxy> getUsingItems()
Get all:

initPermissions

void initPermissions(int granted,
                     int denied)
               throws BaseException
The logged in user has read permission to the quota assigned to him/her, directly or through group quota. If this is a system item, delete and create permissions are denied.

Overrides:
initPermissions in class BasicItem<QuotaData>
Parameters:
granted - Permissions that have been granted by the subclass
denied - Permissions that have been denied by the subclass
Throws:
BaseException - If there is an error

setQuotaValue

public void setQuotaValue(QuotaType quotaType,
                          Location location,
                          long bytes)
                   throws InvalidDataException,
                          PermissionDeniedException
Set the quota for the specified type, location and size.

Parameters:
quotaType - The QuotaType for this Quota
location - The location for this Quota
bytes - The maximum number of bytes that can be used, or UNLIMITED if the quota should be unlimited, or UNDEFINED if the quota setting should be removed
Throws:
InvalidDataException - If any of the parameters is wrong.
PermissionDeniedException - If the user has no write permissions.

getQuotaValue

public long getQuotaValue(QuotaType quotaType,
                          Location location)
Get the quota for the specified type and location.

Parameters:
quotaType - The @link QuotaType QuotaType}
location - The location of the quota
Returns:
The maximum number of bytes that can be used, or UNLIMITED if the quota is unlimited or UNDEFINED if the quota is not defined

2.17.2: 2011-06-17