Class Project

  • All Implemented Interfaces:
    AccessControlled, Annotatable, Identifiable, Nameable, Ownable, Registered, Removable

    public class Project
    extends OwnedItem
    implements Nameable, Removable, Registered, Annotatable
    This class is used to represent projects. A project is used to collect items of particular interest in one place. Users and groups can also be granted access to projects, allowing everyone easy access to shared items within the project.

    While working with BASE it is possible to set one project as the active project. This enables some useful functionality in the core:

    • Every Shareable item the user creates is automatically shared to the project.
    • All queries defaults to only return items that are shared to the project.

    It is also possible to add an item to other projects, or remove it completely from all projects. Every member of a project has a special project permission which gives the highest permission for accessing items in the project. Normally this permission is Permission.USE. One person might be assigned administrator of the project and given higher permissions.

    Items may also be given a permission within the project. The normal is to give full access, but it may also be set to for example Permission.READ. Then, not even the project administrator will get more than read permissions to the item. This feature can for example be used when a project needs to access data from a user that is not a member of the project.

    Version:
    2.0
    Author:
    Nicklas
    See Also:
    Role, Project, SessionControl.setActiveProject(Project)
    Last modified
    $Date: 2019-02-26 11:10:15 +0100 (tis, 26 feb. 2019) $
    • Field Detail

      • RUNTIME_FILTER

        private static final QueryRuntimeFilter RUNTIME_FILTER
        This filter will limit a query to only return projects where the logged in user is a member or owner unless the logged in user has generic read permission.
    • Constructor Detail

    • Method Detail

      • getNew

        public static Project getNew​(DbControl dc)
                              throws BaseException
        Create a new Project item.
        Parameters:
        dc - The DbControl which will be used for permission checking and database access.
        Returns:
        The new Project item
        Throws:
        BaseException - If there is an error
      • getQuery

        public static ItemQuery<Project> getQuery()
        Get a query configured to retrieve projects. If the logged in user doesn't have generic permission to all projects, only projects the user has access to are returned.
        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
      • 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
      • 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
      • 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
      • isAnnotated

        public boolean isAnnotated()
        Description copied from interface: Annotatable
        Check if this item has an annotation set. The annotation set may be empty.
        Specified by:
        isAnnotated in interface Annotatable
        Returns:
        TRUE if an annotation set exists, FALSE otherwise
      • getProtocol

        public Protocol getProtocol()
        Default implementation returns null. Should be overriden by subclasses that has protocols.
        Specified by:
        getProtocol in interface Annotatable
        Returns:
        Always null
      • getAnnotatableParents

        public Set<Annotatable> getAnnotatableParents()
                                               throws BaseException
        Description copied from interface: Annotatable
        Get all parents objects which are annotatable and the logged in user has read permission to. If the item doesn't have any annotatable parents, it may return null or an empty set. The method should only return the immediate parent(s), not parents to parents, etc. As of BASE 3.1 this method may also return child items if the child item is a Subtypable item that has a subtype with the ItemSubtype.getPushAnnotations() flag set.
        Specified by:
        getAnnotatableParents in interface Annotatable
        Returns:
        Always null
        Throws:
        BaseException - If there is an error
      • initPermissions

        void initPermissions​(int granted,
                             int denied)
                      throws BaseException
        If the logged in user is a member of this project, read or use permission is granted.
        Overrides:
        initPermissions in class OwnedItem
        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
      • getAutoPermission

        public Set<Permission> getAutoPermission()
        The permissions to use when automatically sharing new items to the project when it is the active project. The default is READ, USE, WRITE and DELETE. Note that this setting is ignored when a permission template is used (getPermissionTemplate()).
        Since:
        2.10
      • getPermissionTemplate

        public PermissionTemplate getPermissionTemplate()
        Get the permission template that is used to share new items when this project is active. Note that if a permission template is used the new items are only shared to the active project if the project is part of the template.
        Returns:
        A permission template or null if no template has been specified
        Since:
        2.16
      • setPermissionTemplate

        public void setPermissionTemplate​(PermissionTemplate template)
        Set the permission template that should be used to share new items when this project is active.
        Parameters:
        template - A permission template, or null to not use any template
        Since:
        2.16
      • getPermissions

        public Set<Permission> getPermissions​(User user)
                                       throws InvalidDataException
        Get the permissions for a user in this project.
        Parameters:
        user - The User for which we want to get the permission
        Returns:
        A Set containing the granted permissions, or an empty set if no permissions have been granted
        Throws:
        InvalidDataException - If the user is null
        See Also:
        Permission
      • getUsers

        public ItemQuery<User> getUsers()
                                 throws BaseException
        Get a query that returns the users that are members of this project. This query excludes users that the logged in user doesn't have permission to read.
        Returns:
        A restricted item query.
        Throws:
        BaseException - If the query couldn't be created or configured.
        See Also:
        User.getQuery()
      • getPermissions

        public Set<Permission> getPermissions​(Group group)
                                       throws InvalidDataException
        Get the permissions for a group in this project.
        Parameters:
        group - The Group for which we want to get the permission
        Returns:
        An EnumSet containing the granted permissions, or an empty set if no permissions have been granted
        Throws:
        InvalidDataException - If the group is null
        See Also:
        Permission
      • getGroups

        public ItemQuery<Group> getGroups()
        Get a query that returns the groups that are members of this project. This query excludes groups that the logged in user doesn't have permission to read.
        See Also:
        Group.getQuery()
      • getItems

        public ResultList<Shareable> getItems​(Set<Item> itemTypes,
                                              int firstItem,
                                              int maxItems,
                                              Permission permission,
                                              Set<Include> include,
                                              Restriction restriction)
        Load the items in a project. If this project is the active project it will load all items in the project. If this project isn't the active project it will only load items that the logged in user owns.
        Parameters:
        itemTypes - Limit the list to only return items of the specified types, use null or an empty set to return items of all types
        firstItem - The index of the first item to return (0-based)
        maxItems - The maximum number of items to return, or 0 to return all items
        permission - The permission the logged in user must have on the item
        include - Options for which items that should be included/excluded from the result, or null to include all non-removed items
        restriction - An optional restriction that is applied to the queries to further reduce the list
        Returns:
        A list containing shareable items
        Since:
        2.15
        See Also:
        SessionControl.setActiveProject(Project)
      • addDefaultItem

        public void addDefaultItem​(BasicItem defaultItem)
        Add an item as a default project item. If the item is already a default item of the project, nothing is done.
        Parameters:
        defaultItem - The item to make default
        Since:
        3.0
      • replaceDefaultItem

        public void replaceDefaultItem​(BasicItem newItem)
        Replace an existing default that has the same class and subtype as the given item with the given item.
        Parameters:
        newItem - The new item to make default
        Since:
        3.2
      • removeDefaultItem

        public void removeDefaultItem​(BasicItem defaultItem)
        Remove an item from the list of default items for this project. If the given item is not a default item nothing is done.
        Parameters:
        defaultItem - The item to remove
        Since:
        3.0
      • findDefaultItems

        public <T extends BasicItemList<T> findDefaultItems​(DbControl dc,
                                                              Item itemType,
                                                              boolean strict)
        Find the default items of the given item type. If the strict parameter is true, the search will only match items without a subtype. If strict is false, the search ignore the subtype.
        Parameters:
        dc - A DbControl for database access
        itemType - The type of item to find
        Returns:
        A list with the items that was found (empty if no item was found)
        Since:
        3.0
      • findDefaultItems

        public <T extends BasicItemList<T> findDefaultItems​(DbControl dc,
                                                              ItemSubtype subtype,
                                                              boolean strict)
        Find the default (subtypable) items that has the given subtype. If the strict parameter is true, an exact match must be found, otherwise the search is repeated to find an item without a subtype. The search will never match an item that has a different subtype.
        Parameters:
        dc - A DbControl for database access
        subtype - The requested subtype
        strict - TRUE to strictly match the subtype, FALSE to also search for items without subtype
        Returns:
        A list with the items that was found (empty if no item was found)
        Since:
        3.0
      • findDefaultItemsOfRelatedSubtype

        public <T extends BasicItemList<T> findDefaultItemsOfRelatedSubtype​(DbControl dc,
                                                                              ItemSubtype subtype,
                                                                              Item relatedType)
        Utility method for finding default items of the given relatedType. If a subtype is given this method first try to find the related subtype for the given relatedType. If no subtype is given or if no related subtype is found, this method behaves as if findDefaultItems(DbControl, Item, boolean) was called with strict=true (eg. it will only find items that doesn't have a subtype). If a related subtype is found this method behaves as if findDefaultItems(DbControl, ItemSubtype, boolean) was called with the related subtype and strict=false.
        Parameters:
        dc - A DbControl for database access
        subtype - The main subtype
        relatedType - The related item type that we are interested in
        Returns:
        A list with the items that was found (empty if no item was found)
        Since:
        3.0
      • getDefaultItems

        public List<BasicItem> getDefaultItems​(DbControl dc)
        Get a list with all default items added to this project.
        Parameters:
        dc - A DbControl for database access
        Returns:
        A list with the default items
        Since:
        3.0
      • getDefaultItems

        public <T extends BasicItemList<T> getDefaultItems​(DbControl dc,
                                                             Item itemType)
        Get a list with all default items of a given item type added to this project.
        Parameters:
        dc - A DbControl for database access
        itemType - The type of the default item or null to return all default items
        Returns:
        A list with the default items
        Since:
        3.0
      • isDefaultItem

        public boolean isDefaultItem​(BasicItem item)
        Check if the given item is a default item in this project.
        Parameters:
        item - The item to check
        Returns:
        TRUE if the item is a default item, FALSE if not
        Since:
        3.0
      • hasDefaultOfType

        public boolean hasDefaultOfType​(Item itemType,
                                        ItemSubtype subtype)
        Check if the project has a default item of the given item type and (optional) subtype.
        Parameters:
        itemType - The item type to look for
        subtype - The subtype to look for, or null to ignore subtypes
        Returns:
        TRUE if a matching default item is found, FALSE if not
        Since:
        3.0
      • hasDefaultForItem

        public boolean hasDefaultForItem​(BasicItem item)
        Check if the project has a default item that has the same class and subtype as the given item.
        Parameters:
        item - The item to check
        Returns:
        TRUE if a matching default item is found, FALSE if not
        Since:
        3.0
      • findDefaultData

        BasicData findDefaultData​(Item itemType,
                                  ItemSubtypeData subtype,
                                  boolean strict)
        Find a default item in this project of the given item type (required) and subtype (optional). This method will first try to locate an exact match for the given item type and subtype. If no items are found and strict is false, a second attempt is made to match items as follows: If a subtype is given it will match items WITHOUT a subtype (items with a different subtype are not matched). If no subtype is given, the search ignore the subtype on the other items.

        If more than one item matches the critera, the first one found is returned.

        Parameters:
        itemType - The main item type of the item we are looking for
        subtype - The subtype of the item we are looking for (optional)
        strict - TRUE if the subtype must match
        Since:
        3.0
      • findAllDefaultData

        List<BasicData> findAllDefaultData​(Item itemType,
                                           ItemSubtypeData subtype,
                                           boolean strict)
        Find all default items in this project of the given item type (required) and subtype (optional). If a subtype is given, this method first try to match exactly. If no item is found, and strict is false, a second attempt is made to match against items WITHOUT subtype (items with a different subtype are never matched).
        Parameters:
        itemType - The main item type of the item we are looking for
        subtype - The subtype of the item we are looking for (optional)
        strict - TRUE if the subtype must match
        Since:
        3.0
      • getDefaultRawDataType

        public RawDataType getDefaultRawDataType()
        Gets the default raw data type for this project. If no default value has been set for raw data type this will return Null.
        Returns:
        A RawDataType object
      • setDefaultRawDataType

        public void setDefaultRawDataType​(RawDataType rawDataType)
        Sets a raw data type to be used as default for a project. The default value will be reset if rawDataType is Null
        Parameters:
        rawDataType - the RawDataType to use as default.