Class ErrorCollection

java.lang.Object
com.atlassian.greenhopper.model.validation.ErrorCollection

@ExperimentalApi public class ErrorCollection extends Object
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
  • 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

      public ErrorCollection addContextualError(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:
      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 key
      params - : 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 error
      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 key
      params - : to be passed to i18n
      Throws:
      IllegalArgumentException - if messageKey is null
    • addError

      public ErrorCollection addError(String messageKey, Object... params)
      Add a global error that is not bound to a particular context.
      Parameters:
      messageKey - : the i18n message key
      params - : to be passed to i18n
      Throws:
      IllegalArgumentException - if messageKey is null
    • addError

      public ErrorCollection addError(ErrorCollection.Reason reason, String messageKey, Object... params)
      Add a global error that is not bound to a particular context.
      Parameters:
      reason - : the reason for this error
      messageKey - : the i18n message key
      params - : to be passed to i18n
      Throws:
      IllegalArgumentException - if messageKey is null
    • getErrors

      public List<ErrorCollection.ErrorItem> getErrors()
      Returns:
      all errors, contextual and global
    • clear

      public void clear()
    • addAllErrors

      public ErrorCollection addAllErrors(ErrorCollection toAdd)
    • addAllErrorsWithoutReason

      public ErrorCollection addAllErrorsWithoutReason(ErrorCollection toAdd)
      Add all errors from error collection without adding reasons.
      Parameters:
      toAdd - an error collection which contains errors to add.
    • getContextualErrors

      public List<ErrorCollection.ErrorItem> getContextualErrors(String contextId)
      Get all errors for a particular context
    • getGlobalErrors

      public List<ErrorCollection.ErrorItem> getGlobalErrors()
      Get all errors that are not related to a context
    • getErrorContextIds

      public Set<String> getErrorContextIds()
      Get all contextIDs for which errors exist
    • addReasons

      public ErrorCollection addReasons(Set<ErrorCollection.Reason> reasons)
      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

      public ErrorCollection addReason(ErrorCollection.Reason reason)
      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

      public ErrorCollection setReasons(Set<ErrorCollection.Reason> reasons)
      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

      public Set<ErrorCollection.Reason> 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

      public ErrorCollection.Reason 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

      public String toString()
      Overrides:
      toString in class Object