Class AbstractServiceCommand
- java.lang.Object
-
- com.atlassian.confluence.core.service.AbstractServiceCommand
-
- All Implemented Interfaces:
ServiceCommand
- Direct Known Subclasses:
AbstractLabelsCommand
,CreateAbstractPageCommandImpl
,CreateCommentCommandImpl
,DeleteBlogPostCommand
,DeleteCommentCommandImpl
,DeletePageCommand
,DeleteSpaceCommand
,EditCommentCommandImpl
,MoveBlogPostToTopOfSpaceCommand
,MovePageAbstractCommand
,RemoveAbstractPageVersionCommand
,RenderContentCommandImpl
,RevertBlogPostCommand
,RevertPageCommand
,RevertPageOrderCommand
,SetPageOrderCommand
,ValidateLabelsCommandImpl
public abstract class AbstractServiceCommand extends Object implements ServiceCommand
Base implementation ofServiceCommand
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
Constructors Constructor Description AbstractServiceCommand()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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 commandCollection<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.
-
-
-
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, thenServiceCommand.execute()
is be expected to perform successfully (unless prevented by some system error). If this method returns false,execute
will fail with aNotValidException
.This method should be called after checking
ServiceCommand.isAuthorized()
. If the current user is not authorized to execute this command, this method must throw aNotAuthorizedException
.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 bygetValidationErrors()
must be empty.- Specified by:
isValid
in interfaceServiceCommand
- Returns:
- true if the command is in a valid state to be executed, false otherwise
-
getValidationErrors
public 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 callingServiceCommand.isValid()
will always return an empty collection.- Specified by:
getValidationErrors
in interfaceServiceCommand
- 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 byAuthenticatedUserThreadLocal.get()
.- Specified by:
isAuthorized
in interfaceServiceCommand
- 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 interfaceServiceCommand
-
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.
-
-