public interface ServiceCommand
AbstractServiceCommand
, 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:
Service commands are not thread-safe.
Modifier and Type | Method and 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.
|
boolean isValid()
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 isAuthorized()
. If the current user is not
authorized to execute this command, this method must throw a NotAuthorizedException
.
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 by
getValidationErrors()
must be empty.
NotAuthorizedException
- if calling isValid()
on the command would return false.Collection<ValidationError> getValidationErrors()
isValid()
will always return an empty collection.ValidationError
objects describing why command validation failedboolean isAuthorized()
AuthenticatedUserThreadLocal.get()
.void execute()
NotAuthorizedException
- if calling isAuthorized()
on this command would return falseNotValidException
- if calling isValid()
on this command would return falseIllegalStateException
- if the command has already been executedCopyright © 2003–2021 Atlassian. All rights reserved.