Package net.sf.basedb.core
Class ItemSubtype
java.lang.Object
net.sf.basedb.core.BasicItem
net.sf.basedb.core.ItemSubtype
- All Implemented Interfaces:
AccessControlled
,Identifiable
,Nameable
,Registered
,Removable
,Subtypable
,SystemItem
public class ItemSubtype
extends BasicItem
implements Nameable, Removable, Registered, SystemItem, Subtypable
Item subtypes can be used to classify items into sub-categories.
Subtypes can be defined for all item types that implement the
Subtypable
interface. For a given item type the name
of the subtype should be unique.- Since:
- 3.0
- Author:
- Nicklas
- Last modified
- $Date: 2017-05-22 14:35:27 +0200 (må, 22 maj 2017) $
-
Field Summary
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 TypeMethodDescriptionvoid
checkItemType
(Item itemType) Check if this subtype can be used on items of the given type.getAssociatedDataFileType
(DataFileType fileType, boolean create) Get information about a data file type that has been associated with this item subtype.static ItemSubtype
Get an item subtype object when you know the ID.(package private) ItemSubtypeData
getData()
Get theBasicData
object that holds all data for this item.Get a query returning the data file types that have been associated with this subtype.Get the description for the item.Get the date that the item was registered in the database.Get the subtype of the item.Get the main item type that the subtype belongs to.getName()
Get the name of the item.static ItemSubtype
Create a new item subtype item.Get a query returning all subtypes that have a relation to this subtype.static List<ItemSubtype>
getParentSubtypes
(DbControl dc, Subtypable item, Item parentType) Utility method for locating all subtypes that have a relationship to the subtype of the given item.boolean
If this flag is set, the annotations on items of this subtype can be pushed to the parent item.static ItemQuery<ItemSubtype>
Get a query configured to retrieve item types.getRelatedItems
(Item mainItem) Get a list with (subtypable) items that are related to the given item (which should also be subtypable).static ItemSubtype
getRelatedSubtype
(DbControl dc, Subtypable item, Item... relatedItems) Utility method for locating a subtype that is related to the subtype of a given item.static ItemSubtype
getRelatedSubtype
(DbControl dc, Subtypable item, Item relatedItem, int defaultSubtype) Same asgetRelatedSubtype(DbControl, Subtypable, Item, int, int)
with the same id for the last two parameters.static ItemSubtype
getRelatedSubtype
(DbControl dc, Subtypable item, Item relatedItem, int defaultIfNoSubtype, int defaultIfNoRelated) Utility method for loading a subtype that is related to the subtype of the given item.getRelatedSubtype
(Item itemType) Get a related subtype of another item type.Get a query returning all subtypes that are related to this subtype.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.Get all:Subtypable
items of this subtype.(package private) void
initPermissions
(int granted, int denied) If this is a system protocol type, delete and create permissions are revoked.boolean
isAssociatedDataFileType
(DataFileType fileType) Checks if the given data file type is associated with this subtype or not.boolean
Check if the removed flag is set for this item.boolean
Check if the item is a system item or not.boolean
isUsed()
Checks if: anySubtypable
item is using this subtype.void
removeAssociatedDataFileType
(DataFileType fileType) Remove the association between this subtype and the given data file type.void
removeRelatedSubtype
(Item itemType) Remove the related subtype for the given item type.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
setItemSubtype
(ItemSubtype subtype) Do nothing.private void
setMainItemType
(Item itemType) void
Set the name of the item.void
setOnItem
(Subtypable item) Helper method for implementing theSubtypable.setItemSubtype(ItemSubtype)
method.void
setPushAnnotations
(boolean pushAnnotations) void
setRelatedSubtype
(ItemSubtype subtype) Set a subtype that is related to this subtype.void
setRemoved
(boolean removed) Set the removed flag for this item.static boolean
supportsPushAnnotations
(Item mainItem) Check if the given item type has support for pushing annotations to the parent item or not.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:
-
-
Constructor Details
-
ItemSubtype
ItemSubtype(ItemSubtypeData data)
-
-
Method Details
-
getRelatedItems
Get a list with (subtypable) items that are related to the given item (which should also be subtypable). Typically, if the main item has a many-to-one relatation to another subtypable item, this item type will appear in the list. For example aProtocol
has a link toFile
viaProtocol.getFile()
. Given the subtype of the protocol we can find the desired subtype of the file and check agains the actual subtype:Protocol p = ... ItemSubtype protocolSubtype = p.getItemSubtype(); ItemSubtype desiredFileSubtype = protocolSubtype.getRelatedSubtype(Item.FILE); File f = p.getFile(); ItemSubtype actualFileSubtype = f.getItemSubtype();
- Returns:
- A list with the related items
- See Also:
-
supportsPushAnnotations
Check if the given item type has support for pushing annotations to the parent item or not.- Since:
- 3.1
-
getRelatedSubtype
public static ItemSubtype getRelatedSubtype(DbControl dc, Subtypable item, Item relatedItem, int defaultSubtype) Same asgetRelatedSubtype(DbControl, Subtypable, Item, int, int)
with the same id for the last two parameters. -
getRelatedSubtype
public static ItemSubtype getRelatedSubtype(DbControl dc, Subtypable item, Item relatedItem, int defaultIfNoSubtype, int defaultIfNoRelated) Utility method for loading a subtype that is related to the subtype of the given item. This is more or less equivalent to callingSubtypable.getItemSubtype()
and thengetRelatedSubtype(Item)
but with proper null handling and a possibility to return a default subtype if no related one can be found.- Parameters:
dc
- A DbControl to use for database accessitem
- A subtypable itemrelatedItem
- The main item type of the related subtype we are looking fordefaultIfNoSubtype
- The ID of the subtype to return if the item has no subtypedefaultIfNoRelated
- The ID of the subtype to return if the item has a subtype, but the subtype has no related subtype for the given related item type- Returns:
- An ItemSubtype or null
-
getRelatedSubtype
Utility method for locating a subtype that is related to the subtype of a given item. This method will check each item type in turn and return the first subtype that is found.- Parameters:
dc
- A DbControl to use for database accessitem
- A subtypable itemrelatedItems
- The main item type of the related subtype we are looking for- Returns:
- An ItemSubtype or null
-
getParentSubtypes
Utility method for locating all subtypes that have a relationship to the subtype of the given item. This is more or less equivalent to finding all subtypes were the methodgetRelatedSubtype(Item)
return the subtype of the given subtypable item (optionally restricting to one parent item type).- Parameters:
dc
- A DbControl to use for database accessitem
- A subtypeable itemparentType
- The item type of the subtypes that we want to find or null to find any subtype- Returns:
- A list with the subtypes, or an empty list if none could be found
-
getNew
Create a new item subtype item.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database accessitemType
- The main item type- Returns:
- The new
ItemSubtype
item - Throws:
BaseException
- If there is an error
-
getById
public static ItemSubtype getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException Get an item subtype object when you know the ID.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database access.id
- The system ID of the item to load.- Returns:
- The
ItemSubtype
item - Throws:
ItemNotFoundException
- This exception is thrown if an item with the specified ID is not foundPermissionDeniedException
- This exception is thrown if the logged in user doesn't have read permission to the itemBaseException
- This exception is thrown if there is another error
-
getQuery
Get a query configured to retrieve item types.- Parameters:
itemType
- Optionally filter the query to only return subtypes for the given item type- Returns:
- An
ItemQuery
object
-
getData
ItemSubtypeData 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
-
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
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
-
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
-
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
-
getItemSubtype
Description copied from interface:Subtypable
Get the subtype of the item.- Specified by:
getItemSubtype
in interfaceSubtypable
- Returns:
- A reference to self
- See Also:
-
setItemSubtype
Do nothing.- Specified by:
setItemSubtype
in interfaceSubtypable
- Parameters:
subtype
- A subtype or null- See Also:
-
isUsed
Checks if:- any
Subtypable
item is using this subtype. - For FILE subtypes:
MimeType.getFileType()
andDataFileType.getGenericType()
.
- Overrides:
isUsed
in classBasicItem
- Returns:
- TRUE if this item is used, FALSE otherwise
- Throws:
BaseException
- If not able to tell if item is used or not.- See Also:
- any
-
getUsingItems
Get all:Subtypable
items of this subtype.
- Overrides:
getUsingItems
in classBasicItem
- Returns:
- A set containing proxies for the items, or an empty set if no items are using this item
- See Also:
-
initPermissions
If this is a system protocol type, delete and create permissions are revoked.- 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
-
getMainItemType
Get the main item type that the subtype belongs to. -
setMainItemType
-
getPushAnnotations
public boolean getPushAnnotations()If this flag is set, the annotations on items of this subtype can be pushed to the parent item. Eg. theAnnotatable.getAnnotatableParents()
for an item may return items that are actually child items if they have a subtype with this flag set. For this feature to work it must also be supported by the actual parent item implementation ofAnnotatable.getAnnotatableParents()
which is indicated by annotating theSubtypable.getItemSubtype()
method withSupportsPushAnnotations
.- Returns:
- FALSE to use normal inheritance, TRUE to also inherit to parent items
- Since:
- 3.1
-
setPushAnnotations
public void setPushAnnotations(boolean pushAnnotations) - Since:
- 3.1
- See Also:
-
getRelatedSubtype
Get a related subtype of another item type. For a given main type of items usegetRelatedItems(Item)
to find out which other subtypable items that can be related to this subtype.- Parameters:
itemType
- The other item type (which should also be subtypable)- Returns:
- A subtype or null if no subtype has been configured.
-
setRelatedSubtype
Set a subtype that is related to this subtype. Only one related subtype per item type is allowed. A subtype can't be related to itself.- Parameters:
subtype
- The subtype (null is not allowed)- See Also:
-
removeRelatedSubtype
Remove the related subtype for the given item type.- Parameters:
itemType
- The item type of the related subtype to be removed
-
getRelatedSubtypes
Get a query returning all subtypes that are related to this subtype. -
getParentSubtypes
Get a query returning all subtypes that have a relation to this subtype. -
getDataFileTypes
Get a query returning the data file types that have been associated with this subtype. The association is only used for main item types that implemented theFileStoreEnabled
interface.- Returns:
- A query
-
isAssociatedDataFileType
Checks if the given data file type is associated with this subtype or not.- Parameters:
fileType
- The file type to check- Returns:
- TRUE if the file type is associated, FALSE if not
-
getAssociatedDataFileType
Get information about a data file type that has been associated with this item subtype. The data file type must use the same main item type as this subtype.- Parameters:
fileType
- The file type to get information forcreate
- If TRUE, the file type will be added to the subtype if it doesn't already exists- Returns:
- Null if the file type isn't registered with the subtype (and create is false)
or a
ItemSubtypeFileType
object
-
removeAssociatedDataFileType
Remove the association between this subtype and the given data file type. If the file type is not associated nothing happens.- Parameters:
fileType
- The file type to remove
-
setOnItem
Helper method for implementing theSubtypable.setItemSubtype(ItemSubtype)
method.- Parameters:
item
- The item which must be a subtypeable item
-
checkItemType
Check if this subtype can be used on items of the given type.- Parameters:
itemType
- The item type to check
-