public class Project extends OwnedItem implements Nameable, Removable, Registered, Annotatable
While working with BASE it is possible to set one project as the active project. This enables some useful functionality in the core:
Shareable
item the user creates is automatically
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.
Role
,
Project
,
SessionControl.setActiveProject(Project)
Modifier and Type | Class and Description |
---|---|
private static class |
Project.QueryRuntimeFilterImpl
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.
|
Modifier and Type | Field and Description |
---|---|
private static 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.
|
static Item |
TYPE
The type of item represented by this class.
|
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
Constructor and Description |
---|
Project(ProjectData projectData) |
Modifier and Type | Method and Description |
---|---|
void |
addDefaultItem(BasicItem defaultItem)
Add an item as a default project item.
|
(package private) java.util.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).
|
(package private) BasicData |
findDefaultData(DbControl dc,
java.lang.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).
|
java.util.List<? extends BasicItem> |
findDefaultItems(DbControl dc,
Item itemType,
boolean strict)
Find the default items of the given item type.
|
java.util.List<? extends BasicItem> |
findDefaultItems(DbControl dc,
ItemSubtype subtype,
boolean strict)
Find the default (subtypable) items that has the given subtype.
|
java.util.List<? extends BasicItem> |
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) |
java.util.Set<Annotatable> |
getAnnotatableParents()
Get all parents objects which are annotatable and the logged in
user has read permission to.
|
AnnotationSet |
getAnnotationSet()
Get the annotation set containing the annotations for this item.
|
java.util.Set<Permission> |
getAutoPermission()
The permissions to use when automatically sharing new items to
the project when it is the active project.
|
static Project |
getById(DbControl dc,
int id)
Get a
Project item when you know the ID. |
(package private) ProjectData |
getData()
Get the
BasicData object that holds all data for this item. |
java.util.List<BasicItem> |
getDefaultItems(DbControl dc)
Get a list with all default items added to this project.
|
java.util.List<BasicItem> |
getDefaultItems(DbControl dc,
Item itemType)
Get a list with all default items of a given item type
added to this project.
|
RawDataType |
getDefaultRawDataType()
Gets the default raw data type for this project.
|
java.lang.String |
getDescription()
Get the description for the item.
|
java.util.Date |
getEntryDate()
Get the date that the item was registered in the database.
|
ItemQuery<Group> |
getGroups()
Get a query that returns the groups that
are members of this project.
|
ResultList<Shareable> |
getItems(Item itemType,
int firstItem,
int maxItems,
Permission permission,
java.util.Set<Include> include) |
ResultList<Shareable> |
getItems(java.util.Set<Item> itemTypes,
int firstItem,
int maxItems,
Permission permission,
java.util.Set<Include> include,
Restriction restriction)
Load the items in a project.
|
java.lang.String |
getName()
Get the name of the item.
|
static Project |
getNew(DbControl dc)
Create a new
Project item. |
java.util.Set<Permission> |
getPermissions(Group group)
Get the permissions for a group in this project.
|
java.util.Set<Permission> |
getPermissions(User user)
Get the permissions for a user in this project.
|
PermissionTemplate |
getPermissionTemplate()
Get the permission template that is used to share new items when this project
is active.
|
(package private) PluginPermission |
getPluginPermissions()
Make sure plug-ins always has at least read access to the active project.
|
Protocol |
getProtocol()
Default implementation returns null.
|
static ItemQuery<Project> |
getQuery()
Get a query configured to retrieve projects.
|
User |
getRemovedBy()
Get the user that flagged this item for removal.
|
Item |
getType()
Get the type of item represented by the object.
|
ItemQuery<User> |
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 |
isAnnotated()
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 |
isRemoved()
Check if the removed flag is set for this item.
|
(package private) void |
onBeforeCommit(Transactional.Action action)
Overrides the
BasicItem.onBeforeCommit(Transactional.Action)
method. |
void |
removeAnnotations()
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(java.util.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(java.lang.String description)
Set the description for the item.
|
void |
setEntryDate(java.util.Date entryDate)
Set the date the entry was registered in the database.
|
void |
setName(java.lang.String name)
Set the name of the item.
|
void |
setPermissions(Group group,
java.util.Set<Permission> permissions)
Grant a group permissions to this project.
|
void |
setPermissions(User user,
java.util.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.
|
getOwner, isOwner, setOwner, takeOwnership
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getId, getVersion
checkPermission, getPermissions, hasPermission
public static final Item TYPE
Item.PROJECT
,
getType()
private static final QueryRuntimeFilter RUNTIME_FILTER
Project(ProjectData projectData)
public static Project getNew(DbControl dc) throws BaseException
Project
item.dc
- The DbControl
which will be used for
permission checking and database access.Project
itemBaseException
- If there is an errorpublic static Project getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
Project
item when you know the ID.dc
- The DbControl
which will be used for
permission checking and database access.id
- The ID of the item to loadProject
itemItemNotFoundException
- If an item with the specified
ID is not foundPermissionDeniedException
- If the logged in user doesn't
have Permission.READ
permission to the itemBaseException
- If there is another errorpublic static ItemQuery<Project> getQuery()
ItemQuery
objectProjectData getData()
BasicItem
BasicData
object that holds all data for this item.public Item getType()
Identifiable
Item
enumeration.getType
in interface Identifiable
public java.lang.String getName()
Nameable
public void setName(java.lang.String name) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_NAME_LENGTH
constant.setName
in interface Nameable
name
- The new name for the itemPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the name is null or longer
than specified by the Nameable.MAX_NAME_LENGTH
constantpublic java.lang.String getDescription()
Nameable
getDescription
in interface Nameable
String
with a description of the itempublic void setDescription(java.lang.String description) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_DESCRIPTION_LENGTH
constant.setDescription
in interface Nameable
description
- The new description for the itemPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the description longer
than specified by the Nameable.MAX_DESCRIPTION_LENGTH
constantpublic boolean isRemoved()
Removable
public void setRemoved(boolean removed) throws PermissionDeniedException
Removable
setRemoved
in interface Removable
removed
- TRUE if the item should be flagged as removed,
FALSE otherwisePermissionDeniedException
- 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 FALSEpublic User getRemovedBy() throws PermissionDeniedException, ItemNotFoundException
Removable
getRemovedBy
in interface Removable
PermissionDeniedException
- If the logged in user doesn't have
Permission.READ
permission for the userItemNotFoundException
- If the user that removed this item
can't be foundpublic java.util.Date getEntryDate()
Registered
getEntryDate
in interface Registered
public void setEntryDate(java.util.Date entryDate)
Registered
setEntryDate
in interface Registered
entryDate
- A date or null to use today's datepublic AnnotationSet getAnnotationSet() throws PermissionDeniedException, BaseException
Annotatable
DbControl.commit()
is
called. To check if an item has annotations without creating a new
annotation set use the Annotatable.isAnnotated()
method.getAnnotationSet
in interface Annotatable
AnnotationSet
PermissionDeniedException
- If the logged in user doesn't have
enough permissionsBaseException
- If there is another errorpublic boolean isAnnotated()
Annotatable
isAnnotated
in interface Annotatable
public void removeAnnotations() throws PermissionDeniedException, BaseException
Annotatable
removeAnnotations
in interface Annotatable
PermissionDeniedException
- If the logged in user doesn't have
write permissionBaseException
- If there is another errorpublic Protocol getProtocol()
getProtocol
in interface Annotatable
public java.util.Set<Annotatable> getAnnotatableParents() throws BaseException
Annotatable
Subtypable
item that has a subtype
with the ItemSubtype.getPushAnnotations()
flag set.getAnnotatableParents
in interface Annotatable
BaseException
- If there is an errorvoid onBeforeCommit(Transactional.Action action) throws NotLoggedInException, BaseException
OwnedItem
BasicItem.onBeforeCommit(Transactional.Action)
method. It sets the owner of the new item to the logged in user, unless
it has already been specified.onBeforeCommit
in class OwnedItem
NotLoggedInException
- If no user is logged inBaseException
- If there is another errorTransactional
,
Developer documentation: Transactions,
Developer documentation: Coding rules and guidelines for item classesvoid initPermissions(int granted, int denied) throws BaseException
initPermissions
in class OwnedItem
granted
- Permissions that have been granted by the subclassdenied
- Permissions that have been denied by the subclassBaseException
- If the permissions couldn't be initialisedPluginPermission getPluginPermissions()
getPluginPermissions
in class BasicItem
public java.util.Set<Permission> getAutoPermission()
getPermissionTemplate()
).public void setAutoPermission(java.util.Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException
getPermissionTemplate()
).permissions
- The permissions, must not be null or emptyPermissionDeniedException
- If the logged in user doesn't
have write permissionInvalidDataException
- If the permissions are null or emptypublic PermissionTemplate getPermissionTemplate()
public void setPermissionTemplate(PermissionTemplate template)
template
- A permission template, or null to not use any templatepublic void setPermissions(User user, java.util.Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException
Set
or null
to remove all permissions for the user.user
- The User
permissions
- The permissions to grant, or null to revoke all permissionsPermissionDeniedException
- If the logged in user doesn't have
Permission.WRITE
permission for the projectInvalidDataException
- If the user is nullPermission
public java.util.Set<Permission> getPermissions(User user) throws InvalidDataException
user
- The User
for which we want to get the permissionSet
containing the granted permissions, or an
empty set if no permissions have been grantedInvalidDataException
- If the user is nullPermission
public ItemQuery<User> getUsers() throws BaseException
BaseException
- If the query couldn't be created or configured.User.getQuery()
public void setPermissions(Group group, java.util.Set<Permission> permissions) throws PermissionDeniedException, InvalidDataException, BaseException
Set
or null
to remove all permissions for the group. To share to the Group.EVERYONE
group Permission.SHARE_TO_EVERYONE
is required.group
- The Group
permissions
- The permissions to grant, or null to revoke all permissionsPermissionDeniedException
- If the logged in user doesn't have
Permission.WRITE
permission for the projectInvalidDataException
- If the group is nullBaseException
- If there is another errorPermission
public java.util.Set<Permission> getPermissions(Group group) throws InvalidDataException
group
- The Group
for which we want to get the permissionEnumSet
containing the granted permissions, or an
empty set if no permissions have been grantedInvalidDataException
- If the group is nullPermission
public ItemQuery<Group> getGroups()
Group.getQuery()
public ResultList<Shareable> getItems(Item itemType, int firstItem, int maxItems, Permission permission, java.util.Set<Include> include)
getItems(Set, int, int, Permission, Set, Restriction)
public ResultList<Shareable> getItems(java.util.Set<Item> itemTypes, int firstItem, int maxItems, Permission permission, java.util.Set<Include> include, Restriction restriction)
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 listSessionControl.setActiveProject(Project)
public void addDefaultItem(BasicItem defaultItem)
defaultItem
- The item to make defaultpublic void replaceDefaultItem(BasicItem newItem)
newItem
- The new item to make defaultpublic void removeDefaultItem(BasicItem defaultItem)
defaultItem
- The item to removepublic java.util.List<? extends BasicItem> findDefaultItems(DbControl dc, Item itemType, boolean strict)
dc
- A DbControl for database accessitemType
- The type of item to findpublic java.util.List<? extends BasicItem> findDefaultItems(DbControl dc, ItemSubtype subtype, boolean strict)
dc
- A DbControl for database accesssubtype
- The requested subtypestrict
- TRUE to strictly match the subtype, FALSE to also
search for items without subtypepublic java.util.List<? extends BasicItem> findDefaultItemsOfRelatedSubtype(DbControl dc, ItemSubtype subtype, Item relatedType)
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.dc
- A DbControl for database accesssubtype
- The main subtyperelatedType
- The related item type that we are interested inpublic java.util.List<BasicItem> getDefaultItems(DbControl dc)
dc
- A DbControl for database accesspublic java.util.List<BasicItem> getDefaultItems(DbControl dc, Item itemType)
dc
- A DbControl for database accessitemType
- The type of the default item or null to return all default itemspublic boolean isDefaultItem(BasicItem item)
item
- The item to checkpublic boolean hasDefaultOfType(Item itemType, ItemSubtype subtype)
itemType
- The item type to look forsubtype
- The subtype to look for, or null to ignore subtypespublic boolean hasDefaultForItem(BasicItem item)
item
- The item to checkBasicData findDefaultRelatedData(DbControl dc, Subtypable item, Item relatedItemType, boolean strict)
BasicData findDefaultData(Item itemType, ItemSubtypeData subtype, boolean strict)
If more than one item matches the critera, the first one found is returned.
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 matchjava.util.List<BasicData> findAllDefaultData(Item itemType, ItemSubtypeData subtype, boolean strict)
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 matchpublic RawDataType getDefaultRawDataType()
RawDataType
objectpublic void setDefaultRawDataType(RawDataType rawDataType)
rawDataType
is NullrawDataType
- the RawDataType
to use as default.