public abstract class AbstractServiceCommand extends Object implements ServiceCommand
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 and Description |
---|
AbstractServiceCommand() |
Modifier and Type | Method and 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 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.
|
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.
|
public final boolean isValid()
ServiceCommand
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.
isValid
in interface ServiceCommand
public Collection<ValidationError> getValidationErrors()
ServiceCommand
ServiceCommand.isValid()
will always return an empty collection.getValidationErrors
in interface ServiceCommand
ValidationError
objects describing why command validation failedpublic final boolean isAuthorized()
ServiceCommand
AuthenticatedUserThreadLocal.get()
.isAuthorized
in interface ServiceCommand
public final void execute()
ServiceCommand
execute
in interface ServiceCommand
protected final com.atlassian.user.User getCurrentUser()
protected abstract void validateInternal(ServiceCommandValidator validator)
Implementations can assume that if this method is called, authorization was already successful.
protected abstract boolean isAuthorizedInternal()
protected abstract void executeInternal()
Copyright © 2003–2017 Atlassian. All rights reserved.