org.openanzo.server.repository.structures
Class Role

java.lang.Object
  extended by org.openanzo.server.repository.structures.Role

public class Role
extends java.lang.Object

Provides access to role data stored in the repository. Users have all the privileges of the roles they belong to. Unlike many of the data access objects in anzo, roles are not batched and changes are persisted to the database immediately.

Author:
Joe Betz

Constructor Summary
Role(java.lang.Long id, RepositoryConnection repositoryConnection)
          Builds a role object for the given id.
 
Method Summary
 void addImplicitUser(User user, java.lang.Long modified)
          Add a user to this role
static void addSubRole(RepositoryConnection repositoryConnection, Role parentId, Role childId, java.lang.Long modified)
          Add a child role to a parent role in the database
 boolean addUser(User user, java.lang.Long modified)
          Add a user to this role, and add any implied roles based on role hierarchy
static Role createRole(java.lang.Long id, java.lang.Long modified, RepositoryConnection repositoryConnection)
          Creates a new role.
 boolean equals(java.lang.Object obj)
           
static Role getEveryoneNode(RepositoryConnection repositoryConnection, java.lang.Long modified)
          Get the Role that covers every user
 java.lang.Long getId()
          Unique id for role
 java.util.Set<Role> getParentRoles(java.util.Set<Role> roles)
          Get the roles in the role's hierarchy
 org.openrdf.model.URI getURI()
          URI for role
 int hashCode()
           
 java.util.Iterator<User> listUsers()
          Gets an Iterator for the users in the role.
static Role loadRole(java.lang.Long id, RepositoryConnection repositoryConnection)
          Load a role from the database
 void remove(java.lang.Long modified)
          Remove this Role and any subrole relationships from the database
static void removeSubRole(RepositoryConnection repositoryConnection, Role parent, Role child, java.lang.Long modified)
          Remove a child role from a parent role in the database
 boolean removeUser(User user, java.lang.Long modified)
          Remove user from this role
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Role

public Role(java.lang.Long id,
            RepositoryConnection repositoryConnection)
Builds a role object for the given id. It may not yet exist in the database.

Parameters:
id - The id for the role.
repositoryConnection - Repository connection to run queries against
Method Detail

getEveryoneNode

public static Role getEveryoneNode(RepositoryConnection repositoryConnection,
                                   java.lang.Long modified)
                            throws AnzoException
Get the Role that covers every user

Parameters:
repositoryConnection - Repository connection to run queries against
modified - Timestamp when role should be created if it does not exist
Returns:
Role that covers every user
Throws:
AnzoException

loadRole

public static Role loadRole(java.lang.Long id,
                            RepositoryConnection repositoryConnection)
Load a role from the database

Parameters:
id - The id for the role.
repositoryConnection - Repository connection to run queries against
Returns:
A Role object if it is stored in the database, or null if it is not stored

createRole

public static Role createRole(java.lang.Long id,
                              java.lang.Long modified,
                              RepositoryConnection repositoryConnection)
                       throws AnzoException
Creates a new role.

Parameters:
id - The id for the new role. This id must not already be in use. *
modified - Timestamp when role should be created if it does not exist
repositoryConnection - Repository connection to run queries against
Returns:
The new role.
Throws:
AnzoException - Throws new AnzoException if role is already stored

addSubRole

public static void addSubRole(RepositoryConnection repositoryConnection,
                              Role parentId,
                              Role childId,
                              java.lang.Long modified)
                       throws AnzoException
Add a child role to a parent role in the database

Parameters:
repositoryConnection - Repository connection to run queries against
parentId - Parent role
childId - Child role
modified - Timestamp when role should be created if it does not exist
Throws:
AnzoException - Throw an exception if database insert fails

removeSubRole

public static void removeSubRole(RepositoryConnection repositoryConnection,
                                 Role parent,
                                 Role child,
                                 java.lang.Long modified)
                          throws AnzoException
Remove a child role from a parent role in the database

Parameters:
repositoryConnection - Repository connection to run queries against
parent - Parent role
child - Child role
modified - Timestamp when role should be removed
Throws:
AnzoException - Throw an exception if database remove fails

getParentRoles

public java.util.Set<Role> getParentRoles(java.util.Set<Role> roles)
                                   throws AnzoException
Get the roles in the role's hierarchy

Parameters:
roles - Set of already visited roles
Returns:
Set of roles
Throws:
AnzoException

listUsers

public java.util.Iterator<User> listUsers()
                                   throws AnzoException
Gets an Iterator for the users in the role.

Returns:
A list of users.
Throws:
AnzoException

addImplicitUser

public void addImplicitUser(User user,
                            java.lang.Long modified)
                     throws AnzoException
Add a user to this role

Parameters:
user - User to add to role
modified - Timestamp when user is added to role
Throws:
AnzoException

addUser

public boolean addUser(User user,
                       java.lang.Long modified)
                throws AnzoException
Add a user to this role, and add any implied roles based on role hierarchy

Parameters:
user - User to add to role
modified - Timestamp when user is added to role
Returns:
true if adding user to role was successful
Throws:
AnzoException

removeUser

public boolean removeUser(User user,
                          java.lang.Long modified)
                   throws AnzoException
Remove user from this role

Parameters:
user - User to remove from this role
modified - Timestamp when user was removed from role
Returns:
true if removing the user was successful
Throws:
AnzoException

getId

public java.lang.Long getId()
Unique id for role

Returns:
id for role

getURI

public org.openrdf.model.URI getURI()
URI for role

Returns:
URI for role

remove

public void remove(java.lang.Long modified)
            throws AnzoException
Remove this Role and any subrole relationships from the database

Parameters:
modified - Timestamp when role was removed from database
Throws:
AnzoException

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.