ccc.services.ejb3
Class TemplatesEJB

java.lang.Object
  extended by ccc.services.ejb3.TemplatesEJB
All Implemented Interfaces:
Templates

@RolesAllowed(value={})
public final class TemplatesEJB
extends java.lang.Object
implements Templates

EJB implementation of the Templates interface.

Author:
Civic Computing Ltd.

Field Summary
 
Fields inherited from interface ccc.api.core.Templates
NAME
 
Constructor Summary
TemplatesEJB()
          Constructor.
 
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.
 ResourceSummary create(Template template)
          Create a new template in CCC.
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.
 PagedCollection<Template> query(int pageNo, int pageSize)
          List all the templates currently available in CCC.
 Template retrieve(java.util.UUID templateId)
          Retrieve the delta for a template.
 Template retrieveRevision(java.util.UUID templateId, int revision)
          Retrieve a template revision.
protected
<T> T
sudoExecute(Command<T> command, java.util.UUID actorId, java.util.Date happenedOn)
          Execute a command on behalf of another user.
 java.lang.Boolean templateNameExists(java.lang.String templateName)
          Returns true if template name exists in the template folder.
 void update(java.util.UUID templateId, Template delta)
          Update the specified template on the server.
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

TemplatesEJB

public TemplatesEJB()
Constructor.

Method Detail

templateNameExists

@RolesAllowed(value="TEMPLATE_READ")
public java.lang.Boolean templateNameExists(java.lang.String templateName)
Returns true if template name exists in the template folder.

Specified by:
templateNameExists in interface Templates
Parameters:
templateName - The name to look up.
Returns:
True if name exists.

query

@RolesAllowed(value="TEMPLATE_READ")
public PagedCollection<Template> query(int pageNo,
                                                    int pageSize)
List all the templates currently available in CCC.

Specified by:
query in interface Templates
Parameters:
pageNo - The page of results to return.
pageSize - The number of results in a page.
Returns:
A list of templates.

create

@RolesAllowed(value="TEMPLATE_CREATE")
public ResourceSummary create(Template template)
Create a new template in CCC.

Specified by:
create in interface Templates
Parameters:
template - The template's details.
Returns:
A resource summary describing the new template.

update

@RolesAllowed(value="TEMPLATE_UPDATE")
public void update(java.util.UUID templateId,
                                Template delta)
Update the specified template on the server.

Specified by:
update in interface Templates
Parameters:
templateId - The id of the template to update.
delta - The changes to apply.

retrieve

@PermitAll
public Template retrieve(java.util.UUID templateId)
Retrieve the delta for a template.

Specified by:
retrieve in interface Templates
Parameters:
templateId - The template's id.
Returns:
The corresponding delta.

retrieveRevision

@PermitAll
public Template retrieveRevision(java.util.UUID templateId,
                                           int revision)
Description copied from interface: Templates
Retrieve a template revision.

Specified by:
retrieveRevision in interface Templates
Parameters:
templateId - The template's id.
revision - The revision to fetch.
Returns:
The corresponding delta.

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.