Class AbstractServiceCommand

    • 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
      • 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.