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 Details

  • Constructor Details

  • Method Details

    • getRelatedItems

      public static List<Item> getRelatedItems​(Item mainItem)
      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 a Protocol has a link to File via Protocol.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:
      getRelatedSubtype(Item)
    • supportsPushAnnotations

      public static boolean supportsPushAnnotations​(Item mainItem)
      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 as getRelatedSubtype(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 calling Subtypable.getItemSubtype() and then getRelatedSubtype(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 access
      item - A subtypable item
      relatedItem - The main item type of the related subtype we are looking for
      defaultIfNoSubtype - The ID of the subtype to return if the item has no subtype
      defaultIfNoRelated - 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

      public 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. 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 access
      item - A subtypable item
      relatedItems - The main item type of the related subtype we are looking for
      Returns:
      An ItemSubtype or null
    • getParentSubtypes

      public 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. This is more or less equivalent to finding all subtypes were the method getRelatedSubtype(Item) return the subtype of the given subtypable item (optionally restricting to one parent item type).
      Parameters:
      dc - A DbControl to use for database access
      item - A subtypeable item
      parentType - 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

      public static ItemSubtype getNew​(DbControl dc, Item itemType) throws BaseException
      Create a new item subtype item.
      Parameters:
      dc - The DbControl which will be used for permission checking and database access
      itemType - 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 - The DbControl 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 found
      PermissionDeniedException - This exception is thrown if the logged in user doesn't have read permission to the item
      BaseException - This exception is thrown if there is another error
    • getQuery

      public static ItemQuery<ItemSubtype> getQuery​(Item itemType)
      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 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
    • 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
    • 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
    • getRemovedBy

      public User getRemovedBy() throws PermissionDeniedException, ItemNotFoundException
      Description copied from interface: Removable
      Get the user that flagged this item for removal.
      Specified by:
      getRemovedBy in interface Removable
      Returns:
      A User object, or null if this item has not been flagged
      Throws:
      PermissionDeniedException - If the logged in user doesn't have Permission.READ permission for the user
      ItemNotFoundException - If the user that removed this item can't be found
    • 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
    • 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
    • getItemSubtype

      public ItemSubtype getItemSubtype()
      Description copied from interface: Subtypable
      Get the subtype of the item.
      Specified by:
      getItemSubtype in interface Subtypable
      Returns:
      A reference to self
      See Also:
      SubtypableRelatedItems
    • setItemSubtype

      public void setItemSubtype​(ItemSubtype subtype)
      Do nothing.
      Specified by:
      setItemSubtype in interface Subtypable
      Parameters:
      subtype - A subtype or null
      See Also:
      setOnItem(Subtypable)
    • isUsed

      public boolean isUsed() throws BaseException
      Checks if:
      Overrides:
      isUsed in class BasicItem
      Returns:
      TRUE if this item is used, FALSE otherwise
      Throws:
      BaseException - If not able to tell if item is used or not.
      See Also:
      BasicItem.getUsingItems()
    • getUsingItems

      public Set<ItemProxy> getUsingItems()
      Get all:
      Overrides:
      getUsingItems in class BasicItem
      Returns:
      A set containing proxies for the items, or an empty set if no items are using this item
      See Also:
      BasicItem.addUsingItems(Set, Item, org.hibernate.query.Query)
    • initPermissions

      void initPermissions​(int granted, int denied) throws BaseException
      If this is a system protocol type, delete and create permissions are revoked.
      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
    • getMainItemType

      public Item getMainItemType()
      Get the main item type that the subtype belongs to.
    • setMainItemType

      private void setMainItemType​(Item itemType)
    • getPushAnnotations

      public boolean getPushAnnotations()
      If this flag is set, the annotations on items of this subtype can be pushed to the parent item. Eg. the Annotatable.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 of Annotatable.getAnnotatableParents() which is indicated by annotating the Subtypable.getItemSubtype() method with SupportsPushAnnotations.
      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:
      getPushAnnotations()
    • getRelatedSubtype

      public ItemSubtype getRelatedSubtype​(Item itemType)
      Get a related subtype of another item type. For a given main type of items use getRelatedItems(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

      public void setRelatedSubtype​(ItemSubtype subtype)
      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:
      getRelatedSubtype(Item)
    • removeRelatedSubtype

      public void removeRelatedSubtype​(Item itemType)
      Remove the related subtype for the given item type.
      Parameters:
      itemType - The item type of the related subtype to be removed
    • getRelatedSubtypes

      public ItemQuery<ItemSubtype> getRelatedSubtypes()
      Get a query returning all subtypes that are related to this subtype.
    • getParentSubtypes

      public ItemQuery<ItemSubtype> getParentSubtypes()
      Get a query returning all subtypes that have a relation to this subtype.
    • getDataFileTypes

      public ItemQuery<ItemSubtypeFileType> 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 the FileStoreEnabled interface.
      Returns:
      A query
    • isAssociatedDataFileType

      public boolean isAssociatedDataFileType​(DataFileType fileType)
      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

      public ItemSubtypeFileType getAssociatedDataFileType​(DataFileType fileType, boolean create)
      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 for
      create - 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

      public void removeAssociatedDataFileType​(DataFileType fileType)
      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

      public void setOnItem​(Subtypable item)
      Helper method for implementing the Subtypable.setItemSubtype(ItemSubtype) method.
      Parameters:
      item - The item which must be a subtypeable item
    • checkItemType

      public void checkItemType​(Item itemType)
      Check if this subtype can be used on items of the given type.
      Parameters:
      itemType - The item type to check