com.atlassian.greenhopper.model.validation
Class ErrorCollection

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

public class ErrorCollection
extends java.lang.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)

See Also:
AbstractResultBuilder

Nested Class Summary
static class ErrorCollection.ErrorItem
           
static class ErrorCollection.Reason
          Copied from JIRA's ErrorCollection interface.
 
Constructor Summary
ErrorCollection()
           
ErrorCollection(com.atlassian.jira.util.ErrorCollection jiraErrors)
           
 
Method Summary
 ErrorCollection addAllErrors(ErrorCollection toAdd)
           
 ErrorCollection addAllJiraErrors(com.atlassian.jira.util.ErrorCollection toAdd)
           
 ErrorCollection addContextualError(ErrorCollection.Reason reason, java.lang.String contextId, java.lang.String messageKey, java.lang.Object... params)
          Add a contextual error.
 ErrorCollection addContextualError(java.lang.String contextId, java.lang.String messageKey, java.lang.Object... params)
          Add a contextual error.
 ErrorCollection addError(ErrorCollection.Reason reason, java.lang.String messageKey, java.lang.Object... params)
          Add a global error that is not bound to a particular context.
 ErrorCollection addError(java.lang.String messageKey, java.lang.Object... params)
          Add a global error that is not bound to a particular context.
 ErrorCollection addReason(ErrorCollection.Reason reason)
          Add a reason why the function has not been performed.
 ErrorCollection addReasons(java.util.Set<ErrorCollection.Reason> reasons)
          Add reasons why the function has not been performed.
 void addToGadgetValidationErrors(java.util.Collection<ValidationError> validationErrors, java.lang.String fieldName)
           
 ErrorCollection addWarning(java.lang.String messageKey, java.lang.Object... params)
           
 void checkErrors(I18n2 i18n)
          Checks for errors and throws an exception if encountered.
 void clear()
           
 java.util.List<ErrorCollection.ErrorItem> getContextualErrors(java.lang.String contextId)
          Get all errors for a particular context
 ErrorCollection.Reason getDefinitiveReason()
          Returns the definitive reason, if one exists.
 java.util.Set<java.lang.String> getErrorContextIds()
          Get all contextIDs for which errors exist
 java.util.List<ErrorCollection.ErrorItem> getErrors()
           
 java.util.List<ErrorCollection.ErrorItem> getGlobalErrors()
          Get all errors that are not related to a context
 java.util.Set<ErrorCollection.Reason> getReasons()
          A set of well known reasons why the function has not been performed.
 boolean hasErrors()
          Check if there are any errors at all, global or contextual.
 boolean hasGlobalErrors()
          Check if there are any global errors
 ErrorCollection setReasons(java.util.Set<ErrorCollection.Reason> reasons)
          Set reasons why the function has not been performed.
 com.atlassian.jira.util.ErrorCollection toJiraErrorCollection(I18n2 i18n)
           
 JiraCopiedRestErrorCollection toRestErrorCollection(I18n2 i18n)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ErrorCollection

public ErrorCollection()

ErrorCollection

public ErrorCollection(com.atlassian.jira.util.ErrorCollection jiraErrors)
Method Detail

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(java.lang.String contextId,
                                          java.lang.String messageKey,
                                          java.lang.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:
java.lang.IllegalArgumentException - if messageKey is null

addContextualError

public ErrorCollection addContextualError(ErrorCollection.Reason reason,
                                          java.lang.String contextId,
                                          java.lang.String messageKey,
                                          java.lang.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:
java.lang.IllegalArgumentException - if messageKey is null

addError

public ErrorCollection addError(java.lang.String messageKey,
                                java.lang.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:
java.lang.IllegalArgumentException - if messageKey is null

addError

public ErrorCollection addError(ErrorCollection.Reason reason,
                                java.lang.String messageKey,
                                java.lang.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:
java.lang.IllegalArgumentException - if messageKey is null

addWarning

public ErrorCollection addWarning(java.lang.String messageKey,
                                  java.lang.Object... params)

getErrors

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

clear

public void clear()

addAllErrors

public ErrorCollection addAllErrors(ErrorCollection toAdd)

addAllJiraErrors

public ErrorCollection addAllJiraErrors(com.atlassian.jira.util.ErrorCollection toAdd)

toJiraErrorCollection

public com.atlassian.jira.util.ErrorCollection toJiraErrorCollection(I18n2 i18n)

toRestErrorCollection

public JiraCopiedRestErrorCollection toRestErrorCollection(I18n2 i18n)

addToGadgetValidationErrors

public void addToGadgetValidationErrors(java.util.Collection<ValidationError> validationErrors,
                                        java.lang.String fieldName)

getContextualErrors

public java.util.List<ErrorCollection.ErrorItem> getContextualErrors(java.lang.String contextId)
Get all errors for a particular context


getGlobalErrors

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


getErrorContextIds

public java.util.Set<java.lang.String> getErrorContextIds()
Get all contextIDs for which errors exist


addReasons

public ErrorCollection addReasons(java.util.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(java.util.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 java.util.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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

checkErrors

public void checkErrors(I18n2 i18n)
Checks for errors and throws an exception if encountered.



Copyright © 2007-2012 Atlassian. All Rights Reserved.