Package net.sf.basedb.core
Class Quota
java.lang.Object
net.sf.basedb.core.BasicItem
net.sf.basedb.core.Quota
- All Implemented Interfaces:
AccessControlled
,Identifiable
,Nameable
,Removable
,SystemItem
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:
- A
DiskConsumable
item tells BASE about the number of bytes, type of quota and location of the item. - BASE (via the
OwnedItem
creates aDiskUsage
item to hold that information and links it with theQuota
for the owner of theDiskConsumable
item. - If the quota is exceeded, BASE will throw a
QuotaException
.
- Version:
- 2.0
- Author:
- enell
- See Also:
- Last modified
- $Date: 2019-02-22 08:21:20 +0100 (fre, 22 feb. 2019) $
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
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
Modifier and TypeFieldDescriptionstatic final String
The ID for the system default quota, which is assigned to new users unless another quota is specified.private static final QueryRuntimeFilter
This filter will only return the logged in user's quota unless the logged in user has generic read permission.static final Item
The type of item represented by this class.static final long
Quota is is not defined.static final long
Quota is unlimited.static final String
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic Quota
Get aQuota
item when you know the ID.(package private) QuotaData
getData()
Get theBasicData
object that holds all data for this item.Get the description for the item.getName()
Get the name of the item.static Quota
Create a newQuota
item.getQuery()
Get a query configured to retrieve quota.long
getQuotaValue
(QuotaType quotaType, Location location) Get the quota for the specified type and location.Get the user that flagged this item for removal.Get the system id for the item.getType()
Get the type of item represented by the object.(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
Check if the removed flag is set for this item.boolean
Check if the item is a system item or not.boolean
isUsed()
void
setDescription
(String description) Set the description for the item.void
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
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, 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 Details
-
TYPE
The type of item represented by this class.- See Also:
-
DEFAULT
The ID for the system default quota, which is assigned to new users unless another quota is specified.- See Also:
-
UNRESTRICTED
The ID for the unrestricted quota, which gives users unlimited disk space.- See Also:
-
UNLIMITED
public static final long UNLIMITEDQuota is unlimited.- See Also:
-
UNDEFINED
public static final long UNDEFINEDQuota is is not defined.- See Also:
-
RUNTIME_FILTER
This filter will only return the logged in user's quota unless the logged in user has generic read permission.
-
-
Constructor Details
-
Quota
Quota(QuotaData data) Create a newQuota
item.- Parameters:
data
- The data class for this item.
-
-
Method Details
-
getNew
Create a newQuota
item.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database access.total
- The total size inte bytes of thisQuota
.- Returns:
- The new
Quota
item - Throws:
PermissionDeniedException
- This exception is thrown if the logged in user doesn't haveCREATE
permission for this type of itemsBaseException
- This exception is thrown if there is another error
-
getById
public static Quota getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException Get aQuota
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
Quota
item - Throws:
ItemNotFoundException
- If an item with the specified ID is not foundPermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission to the itemBaseException
- If there is another error
-
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
-
getData
QuotaData getData()Description copied from class:BasicItem
Get theBasicData
object that holds all data for this 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
-
getName
Description copied from interface:Nameable
Get the name of the item. -
setName
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
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
-
isRemoved
public boolean isRemoved()Description copied from interface:Removable
Check if the removed flag is set for this item. -
setRemoved
Description copied from interface:Removable
Set the removed flag for this item.- Specified by:
setRemoved
in interfaceRemovable
- Parameters:
removed
- TRUE if the item should be flagged as removed, FALSE otherwise- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.DELETE
permission for setting the flag to TRUE orPermission.WRITE
permission for setting the flag to FALSE
-
getRemovedBy
Description copied from interface:Removable
Get the user that flagged this item for removal.- Specified by:
getRemovedBy
in interfaceRemovable
- Returns:
- A User object, or null if this item has not been flagged
- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.READ
permission for the userItemNotFoundException
- If the user that removed this item can't be found
-
getSystemId
Description copied from interface:SystemItem
Get the system id for the item.- Specified by:
getSystemId
in interfaceSystemItem
- 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 interfaceSystemItem
- Returns:
- TRUE if this item is a system item, FALSE otherwise
-
isUsed
- Overrides:
isUsed
in classBasicItem
- Returns:
true
if this item is used,false
otherwise- Throws:
BaseException
- If there is another error- See Also:
-
getUsingItems
- Overrides:
getUsingItems
in classBasicItem
- Returns:
- A set containing proxies for the items, or an empty set if no items are using this item
- Since:
- 2.2
- See Also:
-
initPermissions
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 classBasicItem
- Parameters:
granted
- Permissions that have been granted by the subclassdenied
- 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
- TheQuotaType
for thisQuota
location
- The location for thisQuota
bytes
- The maximum number of bytes that can be used, orUNLIMITED
if the quota should be unlimited, orUNDEFINED
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
Get the quota for the specified type and location.
-