Last update: 2011-06-23

org.proteios.core
Class Project

java.lang.Object
  extended by org.proteios.core.BasicItem<D>
      extended by org.proteios.core.OwnedItem<ProjectData>
          extended by org.proteios.core.Project
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Ownable, Removable

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

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 Proteios 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: 2009-09-07 11:06:52 +0200 (Mon, 07 Sep 2009) $

Field Summary
static Item TYPE
          The type of item represented by this class.
 
Fields inherited from interface org.proteios.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Method Summary
 int fetchProjectDirectoryId()
          Fetches the project directory id.
static Project getById(DbControl dc, int id)
          Get a Project item when you know the ID.
 String getDescription()
          Get the description for the item.
 ItemQuery<Group> getGroups()
          Get a query that returns the groups that are members of this project.
 String getName()
          Get the name of the 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.
 Directory getProjectDirectory()
           
 int getProjectType()
           
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.
 boolean isClosed()
           
 boolean isRemoved()
          Check if the removed flag is set for this item.
 boolean isUsed()
          Always return FALSE.
 void setClosed(boolean closed)
           
 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 setProjectDirectory(Directory projectDirectory)
           
 void setProjectType(int projectType)
           
 void setRemoved(boolean removed)
          Set the removed flag for this item.
 
Methods inherited from class org.proteios.core.OwnedItem
getOwner, setOwner
 
Methods inherited from class org.proteios.core.BasicItem
checkPermission, equals, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.proteios.core.Identifiable
getId, getVersion
 
Methods inherited from interface org.proteios.core.AccessControlled
checkPermission, hasPermission
 

Field Detail

TYPE

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

See Also:
Item.PROJECT, getType()
Method Detail

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

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

getProjectType

public int getProjectType()

setProjectType

public void setProjectType(int projectType)

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

isUsed

public boolean isUsed()
               throws BaseException
Always return FALSE. A project can be referenced from users, groups and project keys, but those references are automatically deleted if the project is deleted and aren't inclued in this check.

Specified by:
isUsed in class BasicItem<ProjectData>
Returns:
TRUE if this item is used, FALSE otherwise
Throws:
BaseException

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.

Throws:
BaseException
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()

fetchProjectDirectoryId

public int fetchProjectDirectoryId()
Fetches the project directory id. This method does not need to create any directory item, as the id value is stored in the database.

Returns:
int The project directory id.

getProjectDirectory

public Directory getProjectDirectory()

setProjectDirectory

public void setProjectDirectory(Directory projectDirectory)

isClosed

public boolean isClosed()

setClosed

public void setClosed(boolean closed)

Last update: 2011-06-23