Interface ServiceCommand
-
- All Known Subinterfaces:
AddLabelsCommand
,CommentCommand
,CreateBlogPostCommand
,CreateCommentCommand
,CreatePageCommand
,DeleteCommentCommand
,DeleteProfilePictureCommand
,EditCommentCommand
,MovePageCommand
,RemoveLabelCommand
,RenderContentCommand
,SetProfilePictureCommand
,ValidateLabelsCommand
- All Known Implementing Classes:
AbstractLabelsCommand
,AbstractServiceCommand
,AddLabelsCommandImpl
,CreateAbstractPageCommandImpl
,CreateBlogPostCommandImpl
,CreateCommentCommandImpl
,CreateCommentFromEditorCommand
,CreatePageCommandImpl
,CreatePageFromExistingCommandImpl
,DeleteBlogPostCommand
,DeleteCommentCommandImpl
,DeletePageCommand
,DeleteSpaceCommand
,EditCommentCommandImpl
,EditCommentFromEditorCommand
,LongRunningTaskMovePageCommandDecorator
,MoveBlogPostToTopOfSpaceCommand
,MovePageAbstractCommand
,MovePageCommandImpl
,MovePageToTopOfSpaceCommand
,RemoveAbstractPageVersionCommand
,RemoveBlogPostVersionCommand
,RemoveLabelCommandImpl
,RemovePageVersionCommand
,RenderContentCommandImpl
,RevertBlogPostCommand
,RevertPageCommand
,RevertPageOrderCommand
,RunAsUserCommand
,SetPageOrderCommand
,ValidateLabelsCommandImpl
@Transactional(noRollbackFor={NotValidException.class,NotAuthorizedException.class}) public interface ServiceCommand
A command forming part of Confluence's service layer. Command instances are retrieved from service interfaces (you should never instantiate a command object directly). For more information about the service layer, see the documentation below. If you are creating a new service command, it is best to extendAbstractServiceCommand
, as it enforces much of the contract that a command must obey.The ServiceCommand interface is designed such that commands can be executed in two modes: either by calling the authorize/validate/execute methods separately, or by calling execute directly and dealing with authorization or validation failures as exceptions.
A well-behaved service command implementation must:
- Accept all parameter input in its constructor
- Only mutate its internal state in response to the methods defined on this interface
Service commands are not thread-safe.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
execute()
Execute the command.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.boolean
isValid()
Determine if the command is in a valid state to be executed.
-
-
-
Method Detail
-
isValid
@Transactional(readOnly=true, noRollbackFor={NotValidException.class,NotAuthorizedException.class}) boolean isValid()
Determine if the command is in a valid state to be executed. If this method returns true, thenexecute()
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
isAuthorized()
. If the current user is not authorized to execute this command, this method must throw aNotAuthorizedException
.If this method returns false, then
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.- Returns:
- true if the command is in a valid state to be executed, false otherwise
- Throws:
NotAuthorizedException
- if callingisValid()
on the command would return false.
-
getValidationErrors
Collection<ValidationError> getValidationErrors()
Gets the list of errors that are preventing the command from being executed. Calling this method before callingisValid()
will always return an empty collection.- Returns:
- a collection of
ValidationError
objects describing why command validation failed
-
isAuthorized
@Transactional(readOnly=true, noRollbackFor={NotValidException.class,NotAuthorizedException.class}) boolean isAuthorized()
Determine if the current user is authorized to execute this command. The "current user" for a command is the user returned byAuthenticatedUserThreadLocal.get()
.- Returns:
- true if the current user is authorized to execute this command, false otherwise.
-
execute
void execute()
Execute the command. After execution, the command should offer any indication of the results or products of the command as implementation-specific getter methods.- Throws:
NotAuthorizedException
- if callingisAuthorized()
on this command would return falseNotValidException
- if callingisValid()
on this command would return falseIllegalStateException
- if the command has already been executed
-
-