Interface ValidationResult
-
- All Known Subinterfaces:
MergeValidationResult
- All Known Implementing Classes:
RestValidationResult,SimpleMergeValidationResult,SimpleValidationResult
@ExperimentalApi public interface ValidationResultStores the results after an API Service validateX() method is called.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default ServiceExceptionconvertToServiceException(@Nullable String errorMsg)Converts this validation result into aServiceExceptionwithout throwing.Iterable<ValidationError>getErrors()Returns an iterable of the errors (if any) stored in this result.booleanisAllowedInReadOnlyMode()Checks for allowedInReadOnlyMode status.booleanisAuthorized()Checks for authorization status.default booleanisNotSuccessful()Just a convenience method.default booleanisSuccessful()Checks for both: validity and authorization.default booleanisValid()Checks for validity.default ServiceExceptionthrowIfInvalid()Deprecated.since 5.10 please usethrowIfNotSuccessful()default ServiceExceptionthrowIfInvalid(String msg)Deprecated.since 5.10 please usethrowIfNotSuccessful(String)default voidthrowIfNotSuccessful()Converts this validation result into aServiceExceptionand throws it.default voidthrowIfNotSuccessful(String msg)Converts this validation result into aServiceExceptionand throws it.default voidthrowIfNotValid(String msg)Deprecated.since 5.10 please usethrowIfNotSuccessful(String)
-
-
-
Method Detail
-
isAuthorized
boolean isAuthorized()
Checks for authorization status. Does NOT imply thevalidity check.- Returns:
trueif the current user is permitted to perform the execution that the validation is for,falseotherwise.- See Also:
isValid(),isSuccessful()
-
isAllowedInReadOnlyMode
boolean isAllowedInReadOnlyMode()
Checks for allowedInReadOnlyMode status. Does NOT imply thevalidity check.- Returns:
trueif the current user is allowed to perform the execution in read-only mode that the validation is for,falseotherwise.- Since:
- 6.8.0
- See Also:
isValid(),isSuccessful()
-
isValid
default boolean isValid()
Checks for validity. Does NOT imply theauthorization check.By contract implementations MUST return
falseif there are errors in this ValidationResult. Default implementation is usually enough.- Returns:
trueif there are no errors in this result,falseotherwise.- See Also:
getErrors(),isAuthorized(),isSuccessful()
-
getErrors
Iterable<ValidationError> getErrors()
Returns an iterable of the errors (if any) stored in this result. By contract having any errors here MUST also result inisValid()returningfalse.Default implementation of
isValid()is safe fornullvalues. Be cautious about returningnullif not using the default implementation forisValid().- Returns:
- an iterable of the errors stored in this result.
- See Also:
isValid(),ValidationError
-
isSuccessful
default boolean isSuccessful()
Checks for both: validity and authorization. If we would have any other boolean condition(s) here in the future, default implementation will also check for that one(s) as well.By contract implementations MUST return
trueonly when all the possible ValidationResult checks aretrue. Having any of the checks returnfalsemeans this method should also returnfalse.Default implementation is usually enough.
- Returns:
truein case this validationResult is bothvalidANDauthorized,falseotherwise- See Also:
isValid(),isAuthorized()
-
isNotSuccessful
default boolean isNotSuccessful()
Just a convenience method. Defaults to the negation ofisSuccessful()By contract implementations MUST return negation of the
isSuccessful().- Returns:
- negation of
isSuccessful() - See Also:
isSuccessful()
-
throwIfInvalid
@Deprecated default ServiceException throwIfInvalid(String msg) throws ServiceException
Deprecated.since 5.10 please usethrowIfNotSuccessful(String)Converts this validation result into aServiceExceptionand throws it. Checks for both:isValid()andisAuthorized().Issues:
- Should always throw and never return anything, even though return type is declared.
- Method name suggests only validation check even though two checks are actually performed.
This method is deprecated since 5.10, please use
throwIfNotSuccessful(String)- Returns:
- the exception that will be thrown
- Throws:
ServiceException- See Also:
throwIfNotSuccessful(String)
-
throwIfNotValid
@Deprecated default void throwIfNotValid(String msg) throws ServiceException
Deprecated.since 5.10 please usethrowIfNotSuccessful(String)Converts this validation result into aServiceExceptionand throws it. Checks for both:isValid()andisAuthorized().Issues:
- Method name suggests only validation check even though two checks are actually performed.
This method is deprecated since 5.10, please use
throwIfNotSuccessful(String)- Throws:
ServiceException- See Also:
throwIfNotSuccessful(String)
-
throwIfInvalid
@Deprecated default ServiceException throwIfInvalid() throws ServiceException
Deprecated.since 5.10 please usethrowIfNotSuccessful()Converts this validation result into an Exception and throws it. Should always throw and never return anything, even though return type is declared. Deprecated for that reason.First validation error will be used as message string
This method is deprecated since 5.10, please use
throwIfNotSuccessful()- Returns:
- the exception that will be thrown
- Throws:
ServiceException- See Also:
throwIfNotSuccessful()
-
convertToServiceException
default ServiceException convertToServiceException(@Nullable String errorMsg)
Converts this validation result into aServiceExceptionwithout throwing. Implementations of this method should reasonably analyze the internals of this ValidationResult and return appropriate subclass ofServiceExceptionwhich is most suitable for the case.This method is used internally in the default implementations of
throwIfNotSuccessful()andthrowIfNotSuccessful(String)- Parameters:
errorMsg- message to put in the Exception returned- Returns:
- instance of appropriate
ServiceExceptionsubclass. - See Also:
throwIfNotSuccessful(),throwIfNotSuccessful(String)
-
throwIfNotSuccessful
default void throwIfNotSuccessful(String msg) throws ServiceException
Converts this validation result into aServiceExceptionand throws it. By default provided string will be used as an exception message.By contract implementations MUST throw proper subclass of
ServiceExceptionwhenisNotSuccessful().- Throws:
ServiceException- See Also:
isNotSuccessful(),convertToServiceException(String)
-
throwIfNotSuccessful
default void throwIfNotSuccessful() throws ServiceExceptionConverts this validation result into aServiceExceptionand throws it.By default first validation error (if any) will be used as an exception message.
By contract implementations MUST throw proper subclass of
ServiceExceptionwhenisNotSuccessful().- Throws:
ServiceException- See Also:
isNotSuccessful(),convertToServiceException(String),getErrors(),ValidationError
-
-