Class ErrorCollection
java.lang.Object
com.atlassian.greenhopper.model.validation.ErrorCollection
A collection of errors that happen during the processing of a particular code flow. This will be passed back to the caller, rather than throwing
exceptions.
If the caller is a REST service, it will normally render the errors for the client to display.
The ErrorCollection can contain two types of errors: - global errors : these are not bound to a particular context, and will normally be displayed on a neutral, central place on the page - contextual errors : these are bound to a particular context, and the client will decide where to show them (e.g. next to a form field)
- Since:
- 6.7
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic enumCopied from JIRA's ErrorCollection interface. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAllErrors(ErrorCollection toAdd) Add all errors from error collection without adding reasons.addContextualError(ErrorCollection.Reason reason, String contextId, String messageKey, Object... params) Add a contextual error.addContextualError(String contextId, String messageKey, Object... params) Add a contextual error.addError(ErrorCollection.Reason reason, String messageKey, Object... params) Add a global error that is not bound to a particular context.Add a global error that is not bound to a particular context.addReason(ErrorCollection.Reason reason) Add a reason why the function has not been performed.addReasons(Set<ErrorCollection.Reason> reasons) Add reasons why the function has not been performed.voidclear()static ErrorCollectionfromJiraErrorCollection(com.atlassian.jira.util.ErrorCollection jiraErrors) static ErrorCollectionfromJiraErrorCollectionWithReasons(com.atlassian.jira.util.ErrorCollection jiraErrors) getContextualErrors(String contextId) Get all errors for a particular contextReturns the definitive reason, if one exists.Get all contextIDs for which errors existGet all errors that are not related to a contextA set of well known reasons why the function has not been performed.booleanCheck if there are any errors at all, global or contextual.booleanCheck if there are any global errorssetReasons(Set<ErrorCollection.Reason> reasons) Set reasons why the function has not been performed.toString()
-
Constructor Details
-
ErrorCollection
public ErrorCollection()
-
-
Method Details
-
fromJiraErrorCollection
public static ErrorCollection fromJiraErrorCollection(com.atlassian.jira.util.ErrorCollection jiraErrors) -
fromJiraErrorCollectionWithReasons
public static ErrorCollection fromJiraErrorCollectionWithReasons(com.atlassian.jira.util.ErrorCollection jiraErrors) -
hasErrors
public boolean hasErrors()Check if there are any errors at all, global or contextual. -
hasGlobalErrors
public boolean hasGlobalErrors()Check if there are any global errors -
addContextualError
Add a contextual error. This can be, for example, an error that is associated to a particular field of an object.- Parameters:
contextId- : an ID that gives the caller an indication what context this error relates to. An Ajax client will use this to decide where on the page the error should be displayed.messageKey- : the i18n message keyparams- : to be passed to i18n- Throws:
IllegalArgumentException- if messageKey is null
-
addContextualError
public ErrorCollection addContextualError(ErrorCollection.Reason reason, String contextId, String messageKey, Object... params) Add a contextual error. This can be, for example, an error that is associated to a particular field of an object.- Parameters:
reason- the reason for this errorcontextId- : an ID that gives the caller an indication what context this error relates to. An Ajax client will use this to decide where on the page the error should be displayed.messageKey- : the i18n message keyparams- : to be passed to i18n- Throws:
IllegalArgumentException- if messageKey is null
-
addError
Add a global error that is not bound to a particular context.- Parameters:
messageKey- : the i18n message keyparams- : to be passed to i18n- Throws:
IllegalArgumentException- if messageKey is null
-
addError
Add a global error that is not bound to a particular context.- Parameters:
reason- : the reason for this errormessageKey- : the i18n message keyparams- : to be passed to i18n- Throws:
IllegalArgumentException- if messageKey is null
-
getErrors
- Returns:
- all errors, contextual and global
-
clear
public void clear() -
addAllErrors
-
addAllErrorsWithoutReason
Add all errors from error collection without adding reasons.- Parameters:
toAdd- an error collection which contains errors to add.
-
getContextualErrors
Get all errors for a particular context -
getGlobalErrors
Get all errors that are not related to a context -
getErrorContextIds
Get all contextIDs for which errors exist -
addReasons
Add reasons why the function has not been performed. The reasons may be used by callers of services to set return codes etc. for example in REST services.- Parameters:
reasons- a set of well known reasons why the function has not been performed.
-
addReason
Add a reason why the function has not been performed. The reasons may be used by callers of services to set return codes etc. for example in REST services.- Parameters:
reason- a well known reasons why the function has not been performed.
-
setReasons
Set reasons why the function has not been performed. The reasons may be used by callers of services to set return codes etc. for example in REST services.- Parameters:
reasons- a set of well known reasons why the function has not been performed.
-
getReasons
A set of well known reasons why the function has not been performed. The reasons may be used by callers of services to set return codes etc. for example in REST services.- Returns:
- a set of well known reasons why the function has not been performed.
-
getDefinitiveReason
Returns the definitive reason, if one exists. There is an implicit hierarchy amongst the Reason types, and when throwing an Exception for this ErrorCollection, we only care about the "top" reason.- Returns:
- the definitive reason, or null if no reasons are set.
-
toString
-