ccc.services.ejb3
Class ActionsEJB

java.lang.Object
  extended by ccc.services.ejb3.ActionsEJB
All Implemented Interfaces:
Actions, Scheduler

@RolesAllowed(value={})
@RunAs(value="ACTION_EXECUTE")
public class ActionsEJB
extends java.lang.Object
implements Actions

EJB implementation of the Actions.

Author:
Civic Computing Ltd.

Field Summary
 
Fields inherited from interface ccc.api.core.Actions
NAME
 
Constructor Summary
ActionsEJB()
          Constructor.
 
Method Summary
 void cancel(java.util.UUID actionId)
          Cancel a scheduled action.
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.
 ActionSummary create(Action action)
          Create a new scheduled action.
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.
 void executeAll()
          Executes all available actions whose 'execute after' date is in the past.
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.
 boolean isRunning()
          Query whether the scheduler is running.
 PagedCollection<ActionSummary> listCompletedActions(java.lang.String sort, SortOrder sortOrder, int pageNo, int pageSize)
          List all CCC actions that have been executed.
 PagedCollection<ActionSummary> listPendingActions(java.lang.String sort, SortOrder sortOrder, int pageNo, int pageSize)
          List all CCC actions that haven't yet been executed.
 ActionSummary retrieve(java.util.UUID actionId)
          Find the action with the specified ID.
 void run(javax.ejb.Timer timer)
          Run the scheduled action.
 void start()
          Start the scheduler running.
 void stop()
          Stop the scheduler running.
protected
<T> T
sudoExecute(Command<T> command, java.util.UUID actorId, java.util.Date happenedOn)
          Execute a command on behalf of another user.
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

ActionsEJB

public ActionsEJB()
Constructor.

Method Detail

executeAll

@RolesAllowed(value="ACTION_EXECUTE")
public void executeAll()
Executes all available actions whose 'execute after' date is in the past.

Specified by:
executeAll in interface Actions

listPendingActions

@RolesAllowed(value="ACTION_LIST")
public PagedCollection<ActionSummary> listPendingActions(java.lang.String sort,
                                                                      SortOrder sortOrder,
                                                                      int pageNo,
                                                                      int pageSize)
List all CCC actions that haven't yet been executed.

Specified by:
listPendingActions in interface Actions
Parameters:
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 collection of action summaries, one per outstanding action.

listCompletedActions

@RolesAllowed(value="ACTION_LIST")
public PagedCollection<ActionSummary> listCompletedActions(java.lang.String sort,
                                                                        SortOrder sortOrder,
                                                                        int pageNo,
                                                                        int pageSize)
List all CCC actions that have been executed.

Specified by:
listCompletedActions in interface Actions
Parameters:
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 collection of action summaries, one per completed action.

cancel

@RolesAllowed(value="ACTION_CANCEL")
public void cancel(java.util.UUID actionId)
Cancel a scheduled action.

Specified by:
cancel in interface Actions
Parameters:
actionId - The id of the action to cancel.

create

@RolesAllowed(value="ACTION_CREATE")
public ActionSummary create(Action action)
Create a new scheduled action.

Specified by:
create in interface Actions
Parameters:
action - The action to create.
Returns:
A summary of the new action.

retrieve

@RolesAllowed(value="ACTION_LIST")
public ActionSummary retrieve(java.util.UUID actionId)
Find the action with the specified ID.

Specified by:
retrieve in interface Actions
Parameters:
actionId - The action's ID.
Returns:
A summary of the action.

start

@RolesAllowed(value="ACTION_SCHEDULE")
public void start()
Start the scheduler running.

Specified by:
start in interface Scheduler

stop

@RolesAllowed(value="ACTION_SCHEDULE")
public void stop()
Stop the scheduler running.

Specified by:
stop in interface Scheduler

isRunning

@RolesAllowed(value="ACTION_SCHEDULE")
public boolean isRunning()
Query whether the scheduler is running.

Specified by:
isRunning in interface Scheduler
Returns:
True if the scheduler is running; false otherwise.

run

public void run(javax.ejb.Timer timer)
Run the scheduled action.

Parameters:
timer - The timer that called this method.

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.