com.atlassian.confluence.core.service
Class AbstractServiceCommand

java.lang.Object
  extended by com.atlassian.confluence.core.service.AbstractServiceCommand
All Implemented Interfaces:
ServiceCommand
Direct Known Subclasses:
AbstractLabelsCommand, CreateAbstractPageCommandImpl, CreateCommentCommandImpl, DeleteBlogPostCommand, DeleteCommentCommandImpl, DeletePageCommand, DeleteProfilePictureCommandImpl, DeleteSpaceCommand, EditCommentCommandImpl, MovePageCommandImpl, MovePageToTopOfSpaceCommand, RemovePageVersionCommand, RenderContentCommandImpl, RevertBlogPostCommand, RevertPageCommand, RevertPageOrderCommand, SetPageOrderCommand, SetProfilePictureFromFilenameCommand, SetProfilePictureFromImageCommandImpl, TrashPageCommandImpl, ValidateLabelsCommandImpl

public abstract class AbstractServiceCommand
extends java.lang.Object
implements ServiceCommand

Base implementation of ServiceCommand that takes care of the internal logic related to the order in which the various operations must be performed.

To enforce the contract of ServiceCommand, the non-abstract methods of this class are declared as final, and template methods are provided for implementors to provide custom authorization, validation and execution code.


Constructor Summary
AbstractServiceCommand()
           
 
Method Summary
 void execute()
          Execute the command.
protected abstract  void executeInternal()
          Template method for implementations to perform command execution.
protected  com.atlassian.user.User getCurrentUser()
          Gets the user responsible for executing this command
 java.util.Collection<ValidationError> getValidationErrors()
          Gets the list of errors that are preventing the command from being executed.
 boolean isAuthorized()
          Determine if the current user is authorized to execute this command.
protected abstract  boolean isAuthorizedInternal()
          Template method for implementations to perform authorization.
 boolean isValid()
          Determine if the command is in a valid state to be executed.
protected abstract  void validateInternal(ServiceCommandValidator validator)
          Template method for implementations to perform validation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractServiceCommand

public AbstractServiceCommand()
Method Detail

isValid

public final boolean isValid()
Description copied from interface: ServiceCommand
Determine if the command is in a valid state to be executed. If this method returns true, then ServiceCommand.execute() is be expected to perform successfully (unless prevented by some system error). If this method returns false, execute will fail with a NotValidException.

This method should be called after checking ServiceCommand.isAuthorized(). If the current user is not authorized to execute this command, this method must throw a NotAuthorizedException.

If this method returns false, then ServiceCommand.getValidationErrors() must return a non-empty list of errors explaining why the command was not valid. If this method returns true, the collection returned by getValidationErrors() must be empty.

Specified by:
isValid in interface ServiceCommand
Returns:
true if the command is in a valid state to be executed, false otherwise

getValidationErrors

public java.util.Collection<ValidationError> getValidationErrors()
Description copied from interface: ServiceCommand
Gets the list of errors that are preventing the command from being executed. Calling this method before calling ServiceCommand.isValid() will always return an empty collection.

Specified by:
getValidationErrors in interface ServiceCommand
Returns:
a collection of ValidationError objects describing why command validation failed

isAuthorized

public final boolean isAuthorized()
Description copied from interface: ServiceCommand
Determine if the current user is authorized to execute this command. The "current user" for a command is the user returned by AuthenticatedUserThreadLocal.get().

Specified by:
isAuthorized in interface ServiceCommand
Returns:
true if the current user is authorized to execute this command, false otherwise.

execute

public final void execute()
Description copied from interface: ServiceCommand
Execute the command. After execution, the command should offer any indication of the results or products of the command as implementation-specific getter methods.

Specified by:
execute in interface ServiceCommand

getCurrentUser

protected final com.atlassian.user.User getCurrentUser()
Gets the user responsible for executing this command

Returns:
the user under which this command is being executed

validateInternal

protected abstract void validateInternal(ServiceCommandValidator validator)
Template method for implementations to perform validation. Implementations should add validation errors using the provided methods. Validation will succeed or fail based on whether the list of validation errors is empty at the end of this method.

Implementations can assume that if this method is called, authorization was already successful.


isAuthorizedInternal

protected abstract boolean isAuthorizedInternal()
Template method for implementations to perform authorization.

Returns:
true if the current user is authorized to perform this command, false otherwise

executeInternal

protected abstract void executeInternal()
Template method for implementations to perform command execution. Implementations can assume that if this method is called, both authorization and validation have already been completed successfully.



Copyright © 2003-2014 Atlassian. All Rights Reserved.