ccc.services.ejb3
Class UsersEJB

java.lang.Object
  extended by ccc.services.ejb3.UsersEJB
All Implemented Interfaces:
Users

@RolesAllowed(value={})
public class UsersEJB
extends java.lang.Object
implements Users

EJB implementation of the Users interface.

Author:
Civic Computing Ltd.

Field Summary
 
Fields inherited from interface ccc.api.core.Users
NAME
 
Constructor Summary
UsersEJB()
           
 
Method Summary
protected  void checkPermission(java.lang.String... permissions)
          Check that the current user has ONE OF the specified permissions.
protected  void checkRead(ResourceEntity r)
          Check that a resource is readable by a user.
protected  void checkWrite(ResourceEntity r)
          Check that a resource is write-able by a user.
 CommandFactory commands()
          Accessor.
 User create(User delta)
          Create a new user in the system.
protected  UserEntity currentUser()
          Accessor.
protected  java.util.UUID currentUserId()
          Accessor.
protected
<T> T
execute(Command<T> command)
          Execute a command on behalf of the current user.
protected  java.util.Collection<? extends ResourceEntity> filterAccessibleTo(UserEntity u, java.util.List<? extends ResourceEntity> resources)
          Filter a collection of resources based on accessibility.
protected  IRepositoryFactory getRepoFactory()
          Accessor.
protected  javax.ejb.TimerService getTimerService()
          Accessor.
 java.util.Collection<java.lang.String> listUserMetadataValuesWithKey(java.lang.String key)
          Query metadata values with given key.
 PagedCollection<User> query(java.lang.String username, java.lang.String email, java.lang.String groups, java.lang.String metadataKey, java.lang.String metadataValue, java.lang.String sort, SortOrder order, int pageNo, int pageSize)
          Query users.
 User retrieve(java.util.UUID userId)
          Retrieve a user.
 User retrieveCurrent()
          Returns currently logged in user.
protected
<T> T
sudoExecute(Command<T> command, java.util.UUID actorId, java.util.Date happenedOn)
          Execute a command on behalf of another user.
 void update(java.util.UUID userId, User delta)
          Updates the user in the system.
 void updateCurrent(User user)
          Update the email and/or password for the current user.
 void updateUserPassword(java.util.UUID userId, User user)
          Update the password for the specified user.
 User userByLegacyId(java.lang.String legacyId)
          Look up the user for a specified legacy id.
protected  UserEntity userForId(java.util.UUID userId)
          Look up the user for the specified ID.
 java.lang.Boolean usernameExists(Username username)
          Query whether the specified username is in use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UsersEJB

public UsersEJB()
Method Detail

create

@RolesAllowed(value="USER_CREATE")
public User create(User delta)
Create a new user in the system.

Specified by:
create in interface Users
Parameters:
delta - The new user details.
Returns:
A user summary describing the new user.

update

@RolesAllowed(value="USER_UPDATE")
public void update(java.util.UUID userId,
                                User delta)
Updates the user in the system.

Specified by:
update in interface Users
Parameters:
userId - The id of the user to update.
delta - The changes to apply.

updateUserPassword

@RolesAllowed(value="USER_UPDATE")
public void updateUserPassword(java.util.UUID userId,
                                            User user)
Update the password for the specified user.

Specified by:
updateUserPassword in interface Users
Parameters:
userId - The user's id.
user - New details for the user.

updateCurrent

@RolesAllowed(value="SELF_UPDATE")
public void updateCurrent(User user)
Update the email and/or password for the current user.

Specified by:
updateCurrent in interface Users
Parameters:
user - New details for the user.

usernameExists

@RolesAllowed(value="USER_READ")
public java.lang.Boolean usernameExists(Username username)
Query whether the specified username is in use.

Specified by:
usernameExists in interface Users
Parameters:
username - The username to check
Returns:
True if the username is in use, false otherwise.

query

@RolesAllowed(value="USER_READ")
public PagedCollection<User> query(java.lang.String username,
                                                java.lang.String email,
                                                java.lang.String groups,
                                                java.lang.String metadataKey,
                                                java.lang.String metadataValue,
                                                java.lang.String sort,
                                                SortOrder order,
                                                int pageNo,
                                                int pageSize)
Query users.

Specified by:
query in interface Users
Parameters:
username - The username criteria.
email - The email criteria.
groups - The groups criteria.
metadataKey - The metadata key criteria.
metadataValue - The metadata value criteria.
sort - The column to sort.
order - The sort order (ASC/DESC).
pageNo - The page to display.
pageSize - The number of results per page.
Returns:
Returns list of users.

retrieve

@RolesAllowed(value="USER_READ")
public User retrieve(java.util.UUID userId)
Retrieve a user.

Specified by:
retrieve in interface Users
Parameters:
userId - The user's id.
Returns:
The corresponding delta.

userByLegacyId

@RolesAllowed(value="USER_READ")
public User userByLegacyId(java.lang.String legacyId)
Look up the user for a specified legacy id.

Specified by:
userByLegacyId in interface Users
Parameters:
legacyId - The legacy id of the user.
Returns:
A summary of the corresponding user.

listUserMetadataValuesWithKey

@RolesAllowed(value="USER_READ")
public java.util.Collection<java.lang.String> listUserMetadataValuesWithKey(java.lang.String key)
Query metadata values with given key.

Specified by:
listUserMetadataValuesWithKey in interface Users
Parameters:
key - The key as a string.
Returns:
Returns list of users.

retrieveCurrent

@PermitAll
public User retrieveCurrent()
Returns currently logged in user.

Specified by:
retrieveCurrent in interface Users
Returns:
UserDTO

getRepoFactory

protected IRepositoryFactory getRepoFactory()
Accessor.

Returns:
Returns the repository factory.

commands

public CommandFactory commands()
Accessor.

Returns:
Returns the command factory.

getTimerService

protected final javax.ejb.TimerService getTimerService()
Accessor.

Returns:
The timer service for this EJB.

sudoExecute

protected final <T> T sudoExecute(Command<T> command,
                                  java.util.UUID actorId,
                                  java.util.Date happenedOn)
Execute a command on behalf of another user.

Type Parameters:
T - The command's return type.
Parameters:
command - The command to execute.
actorId - The actor executing the command.
happenedOn - When the command was executed.
Returns:
The command's return value.

execute

protected final <T> T execute(Command<T> command)
Execute a command on behalf of the current user.

Type Parameters:
T - The command's return type.
Parameters:
command - The command to execute.
Returns:
The command's return value.

userForId

protected UserEntity userForId(java.util.UUID userId)
Look up the user for the specified ID.

Parameters:
userId - The user's ID.
Returns:
The corresponding user.

currentUser

protected UserEntity currentUser()
Accessor. TODO: Throw 'invalid session exception instead.

Returns:
The currently logged in user.

currentUserId

protected java.util.UUID currentUserId()
Accessor.

Returns:
The currently logged in user's ID.

checkRead

protected void checkRead(ResourceEntity r)
Check that a resource is readable by a user.

Parameters:
r - The resource to check.

checkWrite

protected void checkWrite(ResourceEntity r)
Check that a resource is write-able by a user.

Parameters:
r - The resource to check.

checkPermission

protected void checkPermission(java.lang.String... permissions)
Check that the current user has ONE OF the specified permissions.

Parameters:
permissions - The permissions to check.

filterAccessibleTo

protected java.util.Collection<? extends ResourceEntity> filterAccessibleTo(UserEntity u,
                                                                            java.util.List<? extends ResourceEntity> resources)
Filter a collection of resources based on accessibility.

Parameters:
u - The user reading the collection.
resources - The un-filtered collection.
Returns:
Subset of the input collection, accessible to the specified user.


Copyright © 2010. All Rights Reserved.