2.17.2: 2011-06-17

net.sf.basedb.core
Class Project

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<D>
      extended by net.sf.basedb.core.OwnedItem<ProjectData>
          extended by net.sf.basedb.core.Project
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Ownable, Registered, Removable, ToTransferable<ProjectInfo>

public class Project
extends OwnedItem<ProjectData>
implements Nameable, Removable, ToTransferable<ProjectInfo>, Registered

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:

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: 2010-06-22 14:51:41 +0200 (Tue, 22 Jun 2010) $

Nested Class Summary
static class Project.Default
           
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.
 
Field Summary
private  Map<Project.Default,BasicData> defaults
           
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.
 
Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Constructor Summary
Project(ProjectData projectData)
           
 
Method Summary
 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)  BasicData getDefaultData(DbControl dc, Project.Default defaultType)
          Gets the project's default item as a data object.
 BasicItem getDefaultItem(DbControl dc, Project.Default defaultType)
          Gets the project's default item of a certain itemType defined in defaultType.
 RawDataType getDefaultRawDataType()
          Gets the default raw data type for this project.
static Project.Default getDefaultType(Item itemType, Item attachesToType)
          Get the project default entry that is used to attach item of a given itemType to attachesToType.
 String getDescription()
          Get the description for the item.
 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)
          Deprecated. Use getItems(Item, int, int, Permission, Set) instead
 ResultList<Shareable> getItems(Item itemType, int firstItem, int maxItems, Permission permission, Set<Include> include)
           
 ResultList<Shareable> getItems(Set<Item> itemTypes, int firstItem, int maxItems, Permission permission, Set<Include> include)
          Deprecated. In 2.15, use getItems(Set, int, int, Permission, Set, Restriction) instead
 ResultList<Shareable> getItems(Set<Item> itemTypes, int firstItem, int maxItems, Permission permission, Set<Include> include, Restriction restriction)
          Load the items in a project.
 String getName()
          Get the name of the item.
static Project getNew(DbControl dc)
          Create a new Project item.
 Set<Permission> getPermissions(Group group)
          Get the permissions for a group in this project.
 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.
static ItemQuery<Project> getQuery()
          Get a query configured to retrieve projects.
 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.
(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 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 setAutoPermission(Set<Permission> permissions)
          Set the default permissions to use when automatically sharing new item the project when it is the active project.
 void setDefaultItem(DbControl dc, BasicItem defaultItem, Project.Default defaultType)
          Sets item as default for 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 setName(String name)
          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.
 ProjectInfo toTransferable(ProjectInfo info)
          Transfer the internal state to a transferable object.
 
Methods inherited from class net.sf.basedb.core.OwnedItem
getOwner, isOwner, setOwner, takeOwnership, toTransferable
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
 
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.PROJECT, getType()

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.


defaults

private Map<Project.Default,BasicData> defaults
Constructor Detail

Project

Project(ProjectData projectData)
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

getById

public static Project getById(DbControl dc,
                              int id)
                       throws ItemNotFoundException,
                              PermissionDeniedException,
                              BaseException
Get a Project item when you know the ID.

Parameters:
dc - The DbControl 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 found
PermissionDeniedException - If the logged in user doesn't have Permission.READ permission to the item
BaseException - If there is another 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

getDefaultType

public static Project.Default getDefaultType(Item itemType,
                                             Item attachesToType)
Get the project default entry that is used to attach item of a given itemType to attachesToType. Eg. The Project.Default.SAMPLING_PROTOCOL is attaches a Item.PROTOCOL to a Item.SAMPLE.

Parameters:
itemType - The item type that is attached... (eg PROTOCOL)
attachesToType - ... to this item type (eg. SAMPLE)
Returns:
A default entry or null
Since:
2.10

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

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

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

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

onBeforeCommit

void onBeforeCommit(Transactional.Action action)
              throws NotLoggedInException,
                     BaseException
Description copied from class: OwnedItem
Overrides the BasicItem.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 class OwnedItem<ProjectData>
Throws:
NotLoggedInException - If no user is logged in
BaseException - If there is another error
See Also:
Transactional, Core API overview - Transaction handling, Coding rules and guidelines for item classes

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

getPluginPermissions

PluginPermission getPluginPermissions()
Make sure plug-ins always has at least read access to the active project.

Overrides:
getPluginPermissions in class BasicItem<ProjectData>
Since:
2.9

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

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 permission
InvalidDataException - If the permissions are null or empty
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

setPermissions

public void setPermissions(User user,
                           Set<Permission> permissions)
                    throws PermissionDeniedException,
                           InvalidDataException
Grant a user permissions to this project. Use an empty Set or null to remove all permissions for the user.

Parameters:
user - The User
permissions - The permissions to grant, or null to revoke all permissions
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.WRITE permission for the project
InvalidDataException - If the user is null
See Also:
Permission

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()

setPermissions

public void setPermissions(Group group,
                           Set<Permission> permissions)
                    throws PermissionDeniedException,
                           InvalidDataException,
                           BaseException
Grant a group permissions to this project. Use an empty Set or null to remove all permissions for the group. To share to the Group.EVERYONE group Permission.SHARE_TO_EVERYONE is required.

Parameters:
group - The Group
permissions - The permissions to grant, or null to revoke all permissions
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.WRITE permission for the project
InvalidDataException - If the group is null
BaseException - If there is another error
See Also:
Permission

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(Item itemType,
                                      int firstItem,
                                      int maxItems,
                                      Permission permission)
Deprecated. Use getItems(Item, int, int, Permission, Set) instead


getItems

public ResultList<Shareable> getItems(Item itemType,
                                      int firstItem,
                                      int maxItems,
                                      Permission permission,
                                      Set<Include> include)
Since:
2.3.1
See Also:
getItems(Set, int, int, Permission, Set)

getItems

public ResultList<Shareable> getItems(Set<Item> itemTypes,
                                      int firstItem,
                                      int maxItems,
                                      Permission permission,
                                      Set<Include> include)
Deprecated. In 2.15, use getItems(Set, int, int, Permission, Set, Restriction) instead

Since:
2.7.1

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)

setDefaultItem

public void setDefaultItem(DbControl dc,
                           BasicItem defaultItem,
                           Project.Default defaultType)
Sets item as default for project.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
defaultItem - The BasicItem to set as default. Use null when to remove a default value.
defaultType - The Project.Default to be set.

getDefaultItem

public BasicItem getDefaultItem(DbControl dc,
                                Project.Default defaultType)
Gets the project's default item of a certain itemType defined in defaultType. If no item of the specified type is found this will return Null

Parameters:
dc - The DbControl which will be used for permission checking and database access.
defaultType - The project's Default to get.
Returns:
A BasicItem or null if no item was found.

getDefaultData

BasicData getDefaultData(DbControl dc,
                         Project.Default defaultType)
Gets the project's default item as a data object. If no item of the specified type is found this will return Null

Since:
2.9

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.

toTransferable

public ProjectInfo toTransferable(ProjectInfo info)
Description copied from interface: ToTransferable
Transfer the internal state to a transferable object. The method should return the same object that is passed in as an argument.

Specified by:
toTransferable in interface ToTransferable<ProjectInfo>
Parameters:
info - The transferable object to use
Returns:
The transferable object with values set.

2.17.2: 2011-06-17