Class Project
- All Implemented Interfaces:
AccessControlled
,Annotatable
,Identifiable
,Nameable
,Ownable
,Registered
,Removable
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:
- Last modified
- $Date: 2021-12-13 14:30:22 +0100 (Mon, 13 Dec 2021) $
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
A runtime filter implementation that limits 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. -
Field Summary
Modifier and TypeFieldDescriptionprivate static final QueryRuntimeFilter
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.static final Item
The type of item represented by this class.Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDefaultItem
(BasicItem defaultItem) Add an item as a default project item.findAllDefaultData
(Item itemType, ItemSubtypeData subtype, boolean strict) Find all default items in this project of the given item type (required) and subtype (optional).(package private) BasicData
findDefaultData
(DbControl dc, String subtypeId, boolean strict) (package private) BasicData
findDefaultData
(Item itemType, ItemSubtypeData subtype, boolean strict) Find a default item in this project of the given item type (required) and subtype (optional).findDefaultItems
(DbControl dc, Item itemType, boolean strict) Find the default items of the given item type.findDefaultItems
(DbControl dc, ItemSubtype subtype, boolean strict) Find the default (subtypable) items that has the given subtype.findDefaultItemsOfRelatedSubtype
(DbControl dc, ItemSubtype subtype, Item relatedType) Utility method for finding default items of the given relatedType.(package private) BasicData
findDefaultRelatedData
(DbControl dc, Subtypable item, Item relatedItemType, boolean strict) static Project
Get the currently active project if any.Get all parents objects which are annotatable and the logged in user has read permission to.Get the annotation set containing the annotations for this item.The permissions to use when automatically sharing new items to the project when it is the active project.static Project
Get aProject
item when you know the ID.(package private) ProjectData
getData()
Get theBasicData
object that holds all data for this item.Get a list with all default items added to this project.getDefaultItems
(DbControl dc, Item itemType) Get a list with all default items of a given item type added to this project.Gets the default raw data type for this project.Get the description for the item.Get the date that the item was registered in the database.Get a query that returns the groups that are members of this project.getItems
(Set<Item> itemTypes, int firstItem, int maxItems, Permission permission, Set<Include> include, Restriction restriction) Load the items in a project.getItems
(Item itemType, int firstItem, int maxItems, Permission permission, Set<Include> include) getName()
Get the name of the item.static Project
Create a newProject
item.getPermissions
(Group group) Get the permissions for a group in this project.getPermissions
(User user) Get the permissions for a user in this project.Get the permission template that is used to share new items when this project is active.(package private) PluginPermission
Make sure plug-ins always has at least read access to the active project.Default implementation returns null.getQuery()
Get a query configured to retrieve projects.Get the user that flagged this item for removal.getType()
Get the type of item represented by the object.getUsers()
Get a query that returns the users that are members of this project.boolean
hasDefaultForItem
(BasicItem item) Check if the project has a default item that has the same class and subtype as the given item.boolean
hasDefaultOfType
(Item itemType, ItemSubtype subtype) Check if the project has a default item of the given item type and (optional) subtype.(package private) void
initPermissions
(int granted, int denied) If the logged in user is a member of this project, read or use permission is granted.boolean
Check if this item has an annotation set.boolean
isDefaultItem
(BasicItem item) Check if the given item is a default item in this project.boolean
Check if the removed flag is set for this item.(package private) void
onBeforeCommit
(Transactional.Action action) Overrides theBasicItem.onBeforeCommit(Transactional.Action)
method.void
Remove all annotations from this item, by deleting the annotation set.void
removeDefaultItem
(BasicItem defaultItem) Remove an item from the list of default items for this project.void
replaceDefaultItem
(BasicItem newItem) Replace an existing default that has the same class and subtype as the given item with the given item.void
setAutoPermission
(Set<Permission> permissions) Set the default permissions to use when automatically sharing new item the project when it is the active project.void
setDefaultRawDataType
(RawDataType rawDataType) Sets a raw data type to be used as default for a project.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
Set the name of the item.void
setPermissions
(Group group, Set<Permission> permissions) Grant a group permissions to this project.void
setPermissions
(User user, Set<Permission> permissions) Grant a user permissions to this project.void
setPermissionTemplate
(PermissionTemplate template) Set the permission template that should be used to share new items when this project is active.void
setRemoved
(boolean removed) Set the removed flag for this item.Methods inherited from class net.sf.basedb.core.OwnedItem
getOwner, isOwner, setOwner, takeOwnership
Methods inherited from class net.sf.basedb.core.BasicItem
addAnnotatableParents, addUsingItems, addUsingItems, breakCircularReferences, checkBatchAnnotatableUsage, checkPermission, equals, getBasicData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, 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:
-
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 Details
-
Project
Project(ProjectData projectData)
-
-
Method Details
-
getNew
Create a newProject
item.- Parameters:
dc
- TheDbControl
which will be used for permission checking and database access.- Returns:
- The new
Project
item - Throws:
BaseException
- If there is an error
-
getActive
Get the currently active project if any. Return null if no project is active.- Since:
- 3.19.1
-
getById
public static Project getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException Get aProject
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
Project
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 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
-
getData
ProjectData 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
-
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
-
getAnnotationSet
Description copied from interface:Annotatable
Get the annotation set containing the annotations for this item. If the item doesn't have any annotations a new annotation set is created and automatically saved to the database whenDbControl.commit()
is called. To check if an item has annotations without creating a new annotation set use theAnnotatable.isAnnotated()
method.- Specified by:
getAnnotationSet
in interfaceAnnotatable
- Returns:
- An
AnnotationSet
- Throws:
PermissionDeniedException
- If the logged in user doesn't have enough permissionsBaseException
- If there is another error
-
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 interfaceAnnotatable
- Returns:
- TRUE if an annotation set exists, FALSE otherwise
-
removeAnnotations
Description copied from interface:Annotatable
Remove all annotations from this item, by deleting the annotation set.- Specified by:
removeAnnotations
in interfaceAnnotatable
- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionBaseException
- If there is another error
-
getProtocol
Default implementation returns null. Should be overriden by subclasses that has protocols.- Specified by:
getProtocol
in interfaceAnnotatable
- Returns:
- Always null
-
getAnnotatableParents
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 aSubtypable
item that has a subtype with theItemSubtype.getPushAnnotations()
flag set.- Specified by:
getAnnotatableParents
in interfaceAnnotatable
- Returns:
- Always null
- Throws:
BaseException
- If there is an error
-
onBeforeCommit
Description copied from class:OwnedItem
Overrides theBasicItem.onBeforeCommit(Transactional.Action)
method. It sets the owner of the new item to the logged in user, unless it has already been specified.- Overrides:
onBeforeCommit
in classOwnedItem
- Throws:
NotLoggedInException
- If no user is logged inBaseException
- If there is another error- See Also:
-
initPermissions
If the logged in user is a member of this project, read or use permission is granted.- Overrides:
initPermissions
in classOwnedItem
- 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
-
getPluginPermissions
PluginPermission getPluginPermissions()Make sure plug-ins always has at least read access to the active project.- Overrides:
getPluginPermissions
in classBasicItem
- Since:
- 2.9
-
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
-
setAutoPermission
public void setAutoPermission(Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException Set the default permissions to use when automatically sharing new item the project when it is the active project. Note that this setting is ignored when a permission template is used (getPermissionTemplate()
).- Parameters:
permissions
- The permissions, must not be null or empty- Throws:
PermissionDeniedException
- If the logged in user doesn't have write permissionInvalidDataException
- If the permissions are null or empty- Since:
- 2.10
-
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
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
-
setPermissions
public void setPermissions(User user, Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException Grant a user permissions to this project. Use an emptySet
or null to remove all permissions for the user.- Parameters:
user
- TheUser
permissions
- The permissions to grant, or null to revoke all permissions- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.WRITE
permission for the projectInvalidDataException
- If the user is null- See Also:
-
getPermissions
Get the permissions for a user in this project.- Parameters:
user
- TheUser
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:
-
getUsers
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:
-
setPermissions
public void setPermissions(Group group, Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException, BaseException Grant a group permissions to this project. Use an emptySet
or null to remove all permissions for the group. To share to theGroup.EVERYONE
groupPermission.SHARE_TO_EVERYONE
is required.- Parameters:
group
- TheGroup
permissions
- The permissions to grant, or null to revoke all permissions- Throws:
PermissionDeniedException
- If the logged in user doesn't havePermission.WRITE
permission for the projectInvalidDataException
- If the group is nullBaseException
- If there is another error- See Also:
-
getPermissions
Get the permissions for a group in this project.- Parameters:
group
- TheGroup
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:
-
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:
-
getItems
public ResultList<Shareable> getItems(Item itemType, int firstItem, int maxItems, Permission permission, Set<Include> include) - Since:
- 2.3.1
- See Also:
-
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 typesfirstItem
- The index of the first item to return (0-based)maxItems
- The maximum number of items to return, or 0 to return all itemspermission
- The permission the logged in user must have on the iteminclude
- Options for which items that should be included/excluded from the result, or null to include all non-removed itemsrestriction
- 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:
-
addDefaultItem
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
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
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
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 accessitemType
- 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 BasicItem> List<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 accesssubtype
- The requested subtypestrict
- 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 BasicItem> List<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 iffindDefaultItems(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 iffindDefaultItems(DbControl, ItemSubtype, boolean)
was called with the related subtype and strict=false.- Parameters:
dc
- A DbControl for database accesssubtype
- The main subtyperelatedType
- 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
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
Get a list with all default items of a given item type added to this project.- Parameters:
dc
- A DbControl for database accessitemType
- The type of the default item or null to return all default items- Returns:
- A list with the default items
- Since:
- 3.0
-
isDefaultItem
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
Check if the project has a default item of the given item type and (optional) subtype.- Parameters:
itemType
- The item type to look forsubtype
- 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
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
-
findDefaultRelatedData
BasicData findDefaultRelatedData(DbControl dc, Subtypable item, Item relatedItemType, boolean strict) -
findDefaultData
-
findDefaultData
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 forsubtype
- The subtype of the item we are looking for (optional)strict
- TRUE if the subtype must match- Since:
- 3.0
-
findAllDefaultData
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 forsubtype
- The subtype of the item we are looking for (optional)strict
- TRUE if the subtype must match- Since:
- 3.0
-
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
Sets a raw data type to be used as default for a project. The default value will be reset ifrawDataType
is Null- Parameters:
rawDataType
- theRawDataType
to use as default.
-