ccc.services.ejb3
Class MigrationEJB

java.lang.Object
  extended by ccc.services.ejb3.MigrationEJB
All Implemented Interfaces:
Migration

@RolesAllowed(value="MIGRATE")
public class MigrationEJB
extends java.lang.Object
implements Migration

EJB3 implementation of the Migration API.

Author:
Civic Computing Ltd.

Field Summary
 
Fields inherited from interface ccc.services.Migration
NAME
 
Constructor Summary
MigrationEJB()
           
 
Method Summary
 void applyWorkingCopy(java.util.UUID resourceId, java.util.UUID userId, java.util.Date happenedOn, boolean isMajorEdit, java.lang.String comment)
          Apply a resource's working copy.
 void changeAcl(java.util.UUID resourceId, ACL acl, java.util.UUID actorId, java.util.Date happenedOn)
          Change the ACL 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.
 CommandFactory commands()
          Accessor.
 ResourceSummary createFolder(java.util.UUID parentId, java.lang.String name, java.lang.String title, boolean publish, java.util.UUID actorId, java.util.Date happenedOn)
          Create a folder with the specified name and title.
 ResourceSummary createPage(java.util.UUID parentId, Page delta, boolean publish, java.util.UUID actorId, java.util.Date happenedOn)
          Creates a new page.
protected  UserEntity currentUser()
          Accessor.
protected  java.util.UUID currentUserId()
          Accessor.
 void deleteResource(java.util.UUID resourceId, java.util.UUID actorId, java.util.Date happenedOn)
          Delete a resource.
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.
 void includeInMainMenu(java.util.UUID resourceId, boolean include, java.util.UUID actorId, java.util.Date happenedOn)
          Specify whether a resource should be included in a site's main menu.
 void lock(java.util.UUID resourceId, java.util.UUID actorId, java.util.Date happenedOn)
          Lock the specified resource.
 void publish(java.util.UUID resourceId, java.util.UUID userId, java.util.Date date)
          Publish the specified resource.
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, java.util.UUID actorId, java.util.Date happenedOn)
          Unlock the specified Resource.
 void unpublish(java.util.UUID resourceId, java.util.UUID userId, java.util.Date publishDate)
          Unpublish the specified 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, java.util.UUID actorId, java.util.Date happenedOn)
          Update metadata of the resource.
 void updatePage(java.util.UUID pageId, Page delta, java.util.UUID actorId, java.util.Date happenedOn)
          Update the specified page on the server.
 void updateResourceTemplate(java.util.UUID resourceId, java.util.UUID templateId, java.util.UUID actorId, java.util.Date happenedOn)
          Update the specified resource's 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

MigrationEJB

public MigrationEJB()
Method Detail

createFolder

public ResourceSummary createFolder(java.util.UUID parentId,
                                    java.lang.String name,
                                    java.lang.String title,
                                    boolean publish,
                                    java.util.UUID actorId,
                                    java.util.Date happenedOn)
Create a folder with the specified name and title.

Specified by:
createFolder in interface Migration
Parameters:
parentId - The folder in which the new folder should be created.
name - The name of the new folder.
title - The title of the folder.
publish - True if the title should be published, false otherwise.
actorId - The user id of the actor.
happenedOn - When the command happened.
Returns:
A resource summary describing the new folder.

createPage

public ResourceSummary createPage(java.util.UUID parentId,
                                  Page delta,
                                  boolean publish,
                                  java.util.UUID actorId,
                                  java.util.Date happenedOn)
Creates a new page.

Specified by:
createPage in interface Migration
Parameters:
parentId - The folder in which the page will be created.
delta - The page's details.
publish - True if the folder should be published, false otherwise.
actorId - The user id of the actor.
happenedOn - When the command happened.
Returns:
A resource summary describing the new page.

updatePage

public void updatePage(java.util.UUID pageId,
                       Page delta,
                       java.util.UUID actorId,
                       java.util.Date happenedOn)
Update the specified page on the server.

Specified by:
updatePage in interface Migration
Parameters:
pageId - The id of the page to update.
delta - The changes to apply.
actorId - The user id of the actor.
happenedOn - When the command happened.

lock

public void lock(java.util.UUID resourceId,
                 java.util.UUID actorId,
                 java.util.Date happenedOn)
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 Migration
Parameters:
resourceId - The uuid of the resource to lock.
actorId - The user id of the actor.
happenedOn - When the command happened.

publish

public void publish(java.util.UUID resourceId,
                    java.util.UUID userId,
                    java.util.Date date)
Publish the specified resource.

Specified by:
publish in interface Migration
Parameters:
resourceId - The id of the resource to update.
userId - The id of the publishing user.
date - The date the resource was published.

unlock

public void unlock(java.util.UUID resourceId,
                   java.util.UUID actorId,
                   java.util.Date happenedOn)
Unlock the specified Resource. If the logged in user does not have privileges to unlock this resource a CCCException will be thrown. Unlocking an unlocked resource has no effect.

Specified by:
unlock in interface Migration
Parameters:
resourceId - The resource to unlock.
actorId - The user id of the actor.
happenedOn - When the command happened.

unpublish

public void unpublish(java.util.UUID resourceId,
                      java.util.UUID userId,
                      java.util.Date publishDate)
Unpublish the specified resource.

Specified by:
unpublish in interface Migration
Parameters:
resourceId - The id of the resource to update.
userId - The id of the un-publishing user.
publishDate - The date the resource was un-published.

updateResourceTemplate

public void updateResourceTemplate(java.util.UUID resourceId,
                                   java.util.UUID templateId,
                                   java.util.UUID actorId,
                                   java.util.Date happenedOn)
Update the specified resource's template on the server.

Specified by:
updateResourceTemplate in interface Migration
Parameters:
resourceId - The id of the resource to update.
templateId - The new template to set for the resource.
actorId - The user id of the actor.
happenedOn - When the command happened.

includeInMainMenu

public void includeInMainMenu(java.util.UUID resourceId,
                              boolean include,
                              java.util.UUID actorId,
                              java.util.Date happenedOn)
Specify whether a resource should be included in a site's main menu.

Specified by:
includeInMainMenu in interface Migration
Parameters:
resourceId - The id of the resource to update.
include - True if the resource should be included, false otherwise.
actorId - The user id of the actor.
happenedOn - When the command happened.

updateMetadata

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,
                           java.util.UUID actorId,
                           java.util.Date happenedOn)
Update metadata of the resource.

Specified by:
updateMetadata in interface Migration
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.
actorId - The user id of the actor.
happenedOn - When the command happened.

changeAcl

public void changeAcl(java.util.UUID resourceId,
                      ACL acl,
                      java.util.UUID actorId,
                      java.util.Date happenedOn)
Change the ACL for a resource.

Specified by:
changeAcl in interface Migration
Parameters:
resourceId - The resource to update.
acl - The access control list for this resource.
actorId - The user id of the actor.
happenedOn - When the command happened.

applyWorkingCopy

public void applyWorkingCopy(java.util.UUID resourceId,
                             java.util.UUID userId,
                             java.util.Date happenedOn,
                             boolean isMajorEdit,
                             java.lang.String comment)
Apply a resource's working copy.

Specified by:
applyWorkingCopy in interface Migration
Parameters:
resourceId - The id of the resource.
userId - The user applying the working copy.
happenedOn - When the command happened.
isMajorEdit - Was this a major change.
comment - A comment describing the change.

deleteResource

public void deleteResource(java.util.UUID resourceId,
                           java.util.UUID actorId,
                           java.util.Date happenedOn)
Delete a resource.

Specified by:
deleteResource in interface Migration
Parameters:
resourceId - The id of the existing resource.
actorId - The user id of the actor.
happenedOn - When the command happened.

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.