Class ItemSubtype

    • Method Detail

      • 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 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
      • 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
      • 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
      • 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
      • 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
      • 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
      • 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