ccc.services.ejb3
Class ResourcesEJB

java.lang.Object
  extended by ccc.services.ejb3.ResourcesEJB
All Implemented Interfaces:
Resources, ActionExecutor, ResourcesExt

@RolesAllowed(value={})
public class ResourcesEJB
extends java.lang.Object
implements Resources, ResourcesExt

EJB implementation of the ResourcesExt interface.

Author:
Civic Computing Ltd.

Field Summary
 
Fields inherited from interface ccc.api.core.Resources
NAME
 
Constructor Summary
ResourcesEJB()
           
 
Method Summary
 ACL acl(java.util.UUID resourceId)
          Get the access control list for a resource.
 void applyWorkingCopy(java.util.UUID resourceId)
          Apply a resource's working copy.
 Duration cacheDuration(java.util.UUID resourceId)
          Retrieve resource's cache duration.
 void changeAcl(java.util.UUID resourceId, ACL acl)
          Change the access control list for a resource.
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.
 void clearWorkingCopy(java.util.UUID resourceId)
          Delete the working copy for a page.
 CommandFactory commands()
          Accessor.
 Template computeTemplate(java.util.UUID resourceId)
          Returns summary of the template assigned for a resource.
 void createLogEntry(java.util.UUID resourceId, java.lang.String action, java.lang.String detail)
          Create a new log entry for the resource.
 ResourceSummary createSearch(java.util.UUID parentId, java.lang.String title)
          Creates a new search.
 void createWorkingCopy(java.util.UUID resourceId, long index)
          Create a working copy for the specified resource, using the specified log entry.
 void createWorkingCopy(java.util.UUID resourceId, Resource pu)
          Create a working copy for the specified resource, using the specified revision.
protected  UserEntity currentUser()
          Accessor.
protected  java.util.UUID currentUserId()
          Accessor.
 void delete(java.util.UUID resourceId)
          Delete the resource located at the specified path.
 void deleteCacheDuration(java.util.UUID id)
          Clear the cache duration for the specified resource.
 void excludeFromMainMenu(java.util.UUID resourceId)
          Specify whether a resource should not be included in a site's main menu.
protected
<T> T
execute(Command<T> command)
          Execute a command on behalf of the current user.
 void executeAction(java.util.UUID actionId)
          Execute the specified action.
 boolean exists(java.util.UUID resourceId)
          Does a resource with the specified ID exist.
 java.lang.String fileContentsFromPath(java.lang.String absolutePath, java.lang.String charset)
          Look up the contents of a file as a String.
protected  java.util.Collection<? extends ResourceEntity> filterAccessibleTo(UserEntity u, java.util.List<? extends ResourceEntity> resources)
          Filter a collection of resources based on accessibility.
 java.lang.String getAbsolutePath(java.util.UUID resourceId)
          Determine the absolute path to a resource.
protected  IRepositoryFactory getRepoFactory()
          Accessor.
protected  javax.ejb.TimerService getTimerService()
          Accessor.
 PagedCollection<Revision> history(java.util.UUID resourceId)
          Retrieve the history of a resource.
 void includeInMainMenu(java.util.UUID resourceId)
          Specify that a resource should be included in a site's main menu.
 void includeInMainMenu(java.util.UUID resourceId, boolean include)
          Specify whether a resource should be included in a site's main menu.
 PagedCollection<ResourceSummary> list(ResourceCriteria criteria, int pageNo, int pageSize)
          List existing resources.
 PagedCollection<ResourceSummary> list(java.util.UUID parent, java.lang.String tag, java.lang.Long before, java.lang.Long after, java.lang.String mainMenu, java.lang.String type, java.lang.String locked, java.lang.String published, java.lang.String sort, SortOrder order, int pageNo, int pageSize)
          List existing resources.
 void lock(java.util.UUID resourceId)
          Lock the specified resource.
 java.util.Map<java.lang.String,java.lang.String> metadata(java.util.UUID resourceId)
          Retrieve the metadata for a resource.
 void move(java.util.UUID resourceId, java.util.UUID newParentId)
          Changes a resource's parent.
 ResourceSummary publish(java.util.UUID resourceId)
          Publish the specified resource.
 void rename(java.util.UUID resourceId, java.lang.String name)
          Rename resource.
 ResourceSummary resourceForLegacyId(java.lang.String legacyId)
          Look up the resource for a specified legacy id.
 PagedCollection<ResourceSummary> resourceForMetadataKey(java.lang.String key)
          Look up the resources for a specified metadata key.
 ResourceSummary resourceForPath(java.lang.String rootPath)
          Look up the resource for a specified path.
 Resource resourceForPathSecure(java.lang.String rootPath)
          Look up the resource for a specified path.
 ResourceSummary retrieve(java.util.UUID resourceId)
          Get the resource located at the specified path.
 Resource revisionForPath(java.lang.String path, int version)
          Look up the resource for a specified path.
protected
<T> T
sudoExecute(Command<T> command, java.util.UUID actorId, java.util.Date happenedOn)
          Execute a command on behalf of another user.
 void unlock(java.util.UUID resourceId)
          Unlock the specified Resource.
 void unpublish(java.util.UUID resourceId)
          Unpublish the specified resource.
 void updateCacheDuration(java.util.UUID resourceId, Duration duration)
          Update the period that a resource should be cached for.
 void updateCacheDuration(java.util.UUID resourceId, Resource pu)
          Update the period that a resource should be cached for.
 void updateMetadata(java.util.UUID resourceId, Resource resource)
          Update metadata of the resource.
 void updateMetadata(java.util.UUID resourceId, java.lang.String title, java.lang.String description, java.util.Set<java.lang.String> tags, java.util.Map<java.lang.String,java.lang.String> metadata)
          Update metadata of the resource.
 void updateResourceTemplate(java.util.UUID resourceId, Resource pu)
          Update the specified resource's template on the server.
 void updateResourceTemplate(java.util.UUID resourceId, java.util.UUID templateId)
          Update the specified resource's template on the server.
protected  UserEntity userForId(java.util.UUID userId)
          Look up the user for the specified ID.
 Resource workingCopyForPath(java.lang.String rootPath)
          Look up the working copy for a specified path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourcesEJB

public ResourcesEJB()
Method Detail

executeAction

@RolesAllowed(value="ACTION_EXECUTE")
public void executeAction(java.util.UUID actionId)
Execute the specified action.

Specified by:
executeAction in interface ActionExecutor
Parameters:
actionId - The action to execute.

lock

@PermitAll
public void lock(java.util.UUID resourceId)
Lock the specified resource. The resource will be locked by the currently logged in user. If the resource is already locked a CCCException will be thrown.

Specified by:
lock in interface Resources
Parameters:
resourceId - The uuid of the resource to lock.

move

@RolesAllowed(value="RESOURCE_MOVE")
public void move(java.util.UUID resourceId,
                              java.util.UUID newParentId)
Changes a resource's parent.

Specified by:
move in interface Resources
Parameters:
resourceId - The id of the resource to move.
newParentId - The id of the folder to which the resource should be moved.

publish

@PermitAll
public ResourceSummary publish(java.util.UUID resourceId)
Publish the specified resource.

Specified by:
publish in interface Resources
Parameters:
resourceId - The id of the resource to update.

rename

@RolesAllowed(value="RESOURCE_RENAME")
public void rename(java.util.UUID resourceId,
                                java.lang.String name)
Rename resource.

Specified by:
rename in interface Resources
Parameters:
resourceId - The id of the resource to rename.
name - The new name.

unlock

@PermitAll
public void unlock(java.util.UUID resourceId)
Unlock the specified Resource. Unlocking an unlocked resource has no effect.

Specified by:
unlock in interface Resources
Parameters:
resourceId - The resource to unlock.

unpublish

@RolesAllowed(value="RESOURCE_UNPUBLISH")
public void unpublish(java.util.UUID resourceId)
Unpublish the specified resource.

Specified by:
unpublish in interface Resources
Parameters:
resourceId - The id of the resource to update.

createWorkingCopy

@RolesAllowed(value="RESOURCE_UPDATE")
public void createWorkingCopy(java.util.UUID resourceId,
                                           long index)
Create a working copy for the specified resource, using the specified log entry.

Specified by:
createWorkingCopy in interface ResourcesExt
Parameters:
resourceId - The id of the resource.
index - The index number of the log entry.

createWorkingCopy

@RolesAllowed(value="RESOURCE_UPDATE")
public void createWorkingCopy(java.util.UUID resourceId,
                                           Resource pu)
Create a working copy for the specified resource, using the specified revision.

Specified by:
createWorkingCopy in interface Resources
Parameters:
resourceId - The id of the resource.
pu - The DTO specifying the number of the revision to use.

updateResourceTemplate

@RolesAllowed(value="RESOURCE_UPDATE")
public void updateResourceTemplate(java.util.UUID resourceId,
                                                java.util.UUID templateId)
Update the specified resource's template on the server.

Specified by:
updateResourceTemplate in interface ResourcesExt
Parameters:
resourceId - The id of the resource to update.
templateId - The new template to set for the resource.

updateResourceTemplate

@RolesAllowed(value="RESOURCE_UPDATE")
public void updateResourceTemplate(java.util.UUID resourceId,
                                                Resource pu)
Update the specified resource's template on the server.

Specified by:
updateResourceTemplate in interface Resources
Parameters:
resourceId - The id of the resource to update.
pu - DTO specifying the new template to set for the resource.

includeInMainMenu

@RolesAllowed(value="RESOURCE_MM")
public void includeInMainMenu(java.util.UUID resourceId,
                                           boolean include)
Specify whether a resource should be included in a site's main menu.

Specified by:
includeInMainMenu in interface ResourcesExt
Parameters:
resourceId - The id of the resource to update.
include - True if the resource should be included, false otherwise.

includeInMainMenu

@RolesAllowed(value="RESOURCE_MM")
public void includeInMainMenu(java.util.UUID resourceId)
Specify that a resource should be included in a site's main menu.

Specified by:
includeInMainMenu in interface Resources
Parameters:
resourceId - The id of the resource to update.

excludeFromMainMenu

@RolesAllowed(value="RESOURCE_MM")
public void excludeFromMainMenu(java.util.UUID resourceId)
Specify whether a resource should not be included in a site's main menu.

Specified by:
excludeFromMainMenu in interface Resources
Parameters:
resourceId - The id of the resource to update.

updateMetadata

@RolesAllowed(value="RESOURCE_UPDATE")
public void updateMetadata(java.util.UUID resourceId,
                                        Resource resource)
Update metadata of the resource.

Specified by:
updateMetadata in interface Resources
Parameters:
resourceId - The id of the resource to update.
resource - The resource containing new metadata.

updateMetadata

@RolesAllowed(value="RESOURCE_UPDATE")
public void updateMetadata(java.util.UUID resourceId,
                                        java.lang.String title,
                                        java.lang.String description,
                                        java.util.Set<java.lang.String> tags,
                                        java.util.Map<java.lang.String,java.lang.String> metadata)
Update metadata of the resource.

Specified by:
updateMetadata in interface ResourcesExt
Parameters:
resourceId - The id of the resource to update.
title - The new title to set.
description - The new description to set.
tags - The new tags to set.
metadata - The metadata to update.

createSearch

@RolesAllowed(value="SEARCH_CREATE")
public ResourceSummary createSearch(java.util.UUID parentId,
                                                 java.lang.String title)
Creates a new search.

Specified by:
createSearch in interface Resources
Parameters:
parentId - The parent folder where the search should be created.
title - The title of the search.
Returns:
A summary of the newly created search.

changeAcl

@RolesAllowed(value="RESOURCE_ACL_UPDATE")
public void changeAcl(java.util.UUID resourceId,
                                   ACL acl)
Change the access control list for a resource.

Specified by:
changeAcl in interface Resources
Parameters:
resourceId - The resource to update.
acl - The access control list for the specified resource.

applyWorkingCopy

@RolesAllowed(value="RESOURCE_UPDATE")
public void applyWorkingCopy(java.util.UUID resourceId)
Apply a resource's working copy.

Specified by:
applyWorkingCopy in interface Resources
Parameters:
resourceId - The id of the resource.

updateCacheDuration

@RolesAllowed(value="RESOURCE_CACHE_UPDATE")
public void updateCacheDuration(java.util.UUID resourceId,
                                             Duration duration)
Update the period that a resource should be cached for.

Specified by:
updateCacheDuration in interface ResourcesExt
Parameters:
resourceId - The resource to update.
duration - The cache duration.

updateCacheDuration

@RolesAllowed(value="RESOURCE_CACHE_UPDATE")
public void updateCacheDuration(java.util.UUID resourceId,
                                             Resource pu)
Update the period that a resource should be cached for.

Specified by:
updateCacheDuration in interface Resources
Parameters:
resourceId - The resource to update.
pu - DTO specifying the cache duration.

clearWorkingCopy

@RolesAllowed(value="RESOURCE_UPDATE")
public void clearWorkingCopy(java.util.UUID resourceId)
Delete the working copy for a page.

Specified by:
clearWorkingCopy in interface Resources
Parameters:
resourceId - The id of the page with a working copy.

deleteCacheDuration

@RolesAllowed(value="RESOURCE_CACHE_UPDATE")
public void deleteCacheDuration(java.util.UUID id)
Clear the cache duration for the specified resource.

Specified by:
deleteCacheDuration in interface Resources
Parameters:
id - The id of the resource to update.

delete

@RolesAllowed(value="RESOURCE_DELETE")
public void delete(java.util.UUID resourceId)
Delete the resource located at the specified path.

Specified by:
delete in interface Resources
Parameters:
resourceId - The id of the existing resource.

history

@RolesAllowed(value="RESOURCE_READ")
public PagedCollection<Revision> history(java.util.UUID resourceId)
Retrieve the history of a resource.

Specified by:
history in interface Resources
Parameters:
resourceId - The id of the resource whose history we will look up.
Returns:
The list of resources.

acl

@RolesAllowed(value="RESOURCE_READ")
public ACL acl(java.util.UUID resourceId)
Get the access control list for a resource.

Specified by:
acl in interface Resources
Parameters:
resourceId - The resource's id.
Returns:
The access control list for the specified resource.

cacheDuration

@RolesAllowed(value="RESOURCE_READ")
public Duration cacheDuration(java.util.UUID resourceId)
Retrieve resource's cache duration.

Specified by:
cacheDuration in interface Resources
Parameters:
resourceId - The id of the resource.
Returns:
Duration.

computeTemplate

@RolesAllowed(value="RESOURCE_READ")
public Template computeTemplate(java.util.UUID resourceId)
Returns summary of the template assigned for a resource.

Specified by:
computeTemplate in interface Resources
Parameters:
resourceId - Id of the resource.
Returns:
TemplateSummary.

resourceForPath

@RolesAllowed(value="RESOURCE_READ")
public ResourceSummary resourceForPath(java.lang.String rootPath)
Look up the resource for a specified path.

Specified by:
resourceForPath in interface Resources
Parameters:
rootPath - The absolute path.
Returns:
A summary of the corresponding resource.

resourceForMetadataKey

@PermitAll
public PagedCollection<ResourceSummary> resourceForMetadataKey(java.lang.String key)
Look up the resources for a specified metadata key.

Specified by:
resourceForMetadataKey in interface Resources
Parameters:
key - The legacy id of the resource.
Returns:
A summary of the corresponding resource.

resourceForLegacyId

@PermitAll
public ResourceSummary resourceForLegacyId(java.lang.String legacyId)
Look up the resource for a specified legacy id.

Specified by:
resourceForLegacyId in interface Resources
Parameters:
legacyId - The legacy id of the resource.
Returns:
A summary of the corresponding resource.

getAbsolutePath

@PermitAll
public java.lang.String getAbsolutePath(java.util.UUID resourceId)
Determine the absolute path to a resource.

Specified by:
getAbsolutePath in interface Resources
Parameters:
resourceId - The id of the resource.
Returns:
The absolute path as a string.

resourceForPathSecure

@PermitAll
public Resource resourceForPathSecure(java.lang.String rootPath)
Look up the resource for a specified path.

Specified by:
resourceForPathSecure in interface Resources
Parameters:
rootPath - The absolute path.
Returns:
A summary of the corresponding resource.

workingCopyForPath

@PermitAll
public Resource workingCopyForPath(java.lang.String rootPath)
Look up the working copy for a specified path.

Specified by:
workingCopyForPath in interface Resources
Parameters:
rootPath - The absolute path.
Returns:
A summary of the corresponding resource.

revisionForPath

@PermitAll
public Resource revisionForPath(java.lang.String path,
                                          int version)
Look up the resource for a specified path.

Specified by:
revisionForPath in interface Resources
Parameters:
path - The absolute path.
version - The version number of the resource to retrieve.
Returns:
A summary of the corresponding resource.

fileContentsFromPath

@PermitAll
public java.lang.String fileContentsFromPath(java.lang.String absolutePath,
                                                       java.lang.String charset)
Look up the contents of a file as a String. FIXME: Move to files.

Specified by:
fileContentsFromPath in interface Resources
Parameters:
absolutePath - The absolute path to the resource.
charset - The character set for the file.
Returns:
The contents as a string.

metadata

@PermitAll
public java.util.Map<java.lang.String,java.lang.String> metadata(java.util.UUID resourceId)
Retrieve the metadata for a resource.

Specified by:
metadata in interface Resources
Parameters:
resourceId - The id of the resource.
Returns:
The metadata in a hashmap.

retrieve

@PermitAll
public ResourceSummary retrieve(java.util.UUID resourceId)
Get the resource located at the specified path.

Specified by:
retrieve in interface Resources
Parameters:
resourceId - The id of the existing resource.
Returns:
A summary of the resource.

exists

@PermitAll
public boolean exists(java.util.UUID resourceId)
Does a resource with the specified ID exist.

Specified by:
exists in interface Resources
Parameters:
resourceId - The id of the resource.
Returns:
True if it exists, false otherwise

createLogEntry

@PermitAll
public void createLogEntry(java.util.UUID resourceId,
                                     java.lang.String action,
                                     java.lang.String detail)
Create a new log entry for the resource.

Specified by:
createLogEntry in interface Resources
Parameters:
resourceId - The id of the resource to create log entry for.
action - The action for the log entry.
detail - The details for the log entry.

list

@PermitAll
public PagedCollection<ResourceSummary> list(java.util.UUID parent,
                                                       java.lang.String tag,
                                                       java.lang.Long before,
                                                       java.lang.Long after,
                                                       java.lang.String mainMenu,
                                                       java.lang.String type,
                                                       java.lang.String locked,
                                                       java.lang.String published,
                                                       java.lang.String sort,
                                                       SortOrder order,
                                                       int pageNo,
                                                       int pageSize)
List existing resources. Leave field to null if not applicable.

Specified by:
list in interface Resources
Parameters:
parent - Filter resources by parent.
tag - Filter resources by tag.
before - Include only resources created before this date.
after - Include only resources created after this date.
mainMenu - Filter resources by 'included in main menu'.
type - Filter resources by type.
locked - Filter resources by locked (true or null).
published - Filter resources by published (true or null).
sort - The field results be sorted on.
order - 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 resources.

list

@PermitAll
public PagedCollection<ResourceSummary> list(ResourceCriteria criteria,
                                                       int pageNo,
                                                       int pageSize)
List existing resources.

Specified by:
list in interface Resources
Parameters:
criteria - The criteria by which to filter resources.
pageNo - The page of results to return.
pageSize - The number of results in a page.
Returns:
A list of resources.

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.