ccc.services.ejb3
Class CommentsEJB

java.lang.Object
  extended by ccc.services.ejb3.CommentsEJB
All Implemented Interfaces:
Comments

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

EJB implementation of the Comments interface.

Author:
Civic Computing Ltd.

Field Summary
 
Fields inherited from interface ccc.api.core.Comments
NAME
 
Constructor Summary
CommentsEJB()
           
 
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.
 Comment create(Comment comment)
          Create a new comment in CCC.
protected  UserEntity currentUser()
          Accessor.
protected  java.util.UUID currentUserId()
          Accessor.
 void delete(java.util.UUID commentId)
          Delete an existing comment.
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.
 PagedCollection<Comment> query(java.util.UUID resourceId, CommentStatus status, java.lang.String sort, SortOrder sortOrder, int pageNo, int pageSize)
          List existing comments.
 Comment retrieve(java.util.UUID commentId)
          Retrieve the comment using its ID.
protected
<T> T
sudoExecute(Command<T> command, java.util.UUID actorId, java.util.Date happenedOn)
          Execute a command on behalf of another user.
 Comment update(java.util.UUID commentId, Comment comment)
          Update the specified comment.
protected  UserEntity userForId(java.util.UUID userId)
          Look up the user for the specified ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommentsEJB

public CommentsEJB()
Method Detail

create

@RolesAllowed(value="COMMENT_CREATE")
public Comment create(Comment comment)
Create a new comment in CCC.

Specified by:
create in interface Comments
Parameters:
comment - The comment to create.
Returns:
Return the newly created comment.

retrieve

@RolesAllowed(value="COMMENT_READ")
public Comment retrieve(java.util.UUID commentId)
Retrieve the comment using its ID.

Specified by:
retrieve in interface Comments
Parameters:
commentId - The comment's ID.
Returns:
Return the corresponding comment.

update

@RolesAllowed(value="COMMENT_UPDATE")
public Comment update(java.util.UUID commentId,
                                   Comment comment)
Update the specified comment.

Specified by:
update in interface Comments
Parameters:
commentId - The comment's ID.
comment - The updated comment.
Returns:
The updated comment.

delete

@RolesAllowed(value="COMMENT_DELETE")
public void delete(java.util.UUID commentId)
Delete an existing comment.

Specified by:
delete in interface Comments
Parameters:
commentId - The comment's ID.

query

@RolesAllowed(value="COMMENT_READ")
public PagedCollection<Comment> query(java.util.UUID resourceId,
                                                   CommentStatus status,
                                                   java.lang.String sort,
                                                   SortOrder sortOrder,
                                                   int pageNo,
                                                   int pageSize)
List existing comments.

Specified by:
query in interface Comments
Parameters:
resourceId - Filter comments by resource. NULL will return all.
status - Filter comments based on status. NULL will return all.
sort - The field to sort on.
sortOrder - The order results be sorted in.
pageNo - The page of results to return.
pageSize - The number of results in a page.
Returns:
A list of comments.

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.