org.sandev.basics.util
Class MessageUtil

java.lang.Object
  extended by org.sandev.basics.util.MessageUtil

public class MessageUtil
extends java.lang.Object

General utilities useful when dealing with messages.


Field Summary
static java.lang.String FIELDERROR
          A general code used for all field level errors.
static java.lang.String INVALIDFORM
          A general code used for all general update errors.
static java.lang.String PROB_DELIMITER
          The string used to delimit multiple field problems.
 
Constructor Summary
MessageUtil()
           
 
Method Summary
static void appendError(ErrorInfoCollection eic, java.lang.String errtext)
          Convenience method to append a general error to the given collection.
static java.lang.String appendError(java.lang.String errorText, java.lang.String addText)
          Appends addText to errorText separated by PROB_DELIMITER if errorText was not the empty String.
static void appendFieldError(ErrorInfoCollection eic, java.lang.String field, java.lang.String errtext)
          Convenience method to append a field error the given collection.
static SandCollectionMessage completeCollection(SandQueryMessage sqm, Messageable node)
          A generalized query processing method that will return the entire collection of elements matching the query.
static boolean containsID(SandCollectionMessage coll, long id)
          Return true if the given collection message contains an instance with the given id, false otherwise.
static void defaultUnauthorizedFields(SandInstanceMessage sim, AuthUser user, AuthFilter filter, Logger logger)
          Set any unauthorized fields to their default values.
 boolean hasErrors(AggregateUpdate au)
          Return true if the given AggregateUpdate contains errors.
static java.lang.String infoAsString(ErrorInfo[] eis)
          Return the ErrorInfoCollection contents as a string.
static UIFormContext noteError(UIFormContext uifc, AggregateUpdate au)
          Note the errors from the given AggregateUpdate in the given UIFormContext and return it.
static void verifyAuthUser(ErrorInfoCollection eic, AuthUser user)
          Verify that the username and password fields meet common usage assumptions.
static ErrorInfoCollection verifyFieldsBase(SandInstanceMessage sim)
          Verify that all the fields are valid according to the fieldsValid method of the given SandIntanceMessage.
static ErrorInfoCollection verifyFieldsFull(SandInstanceMessage sim)
          Verify that all the fields are valid according to the fieldsValid method of the given SandIntanceMessage, and the verifyAuthUser method here.
static void verifyTransmission(SandTransmitMessage stm)
          Throw if the transmission status is anything other than normal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROB_DELIMITER

public static final java.lang.String PROB_DELIMITER
The string used to delimit multiple field problems.

See Also:
Constant Field Values

FIELDERROR

public static final java.lang.String FIELDERROR
A general code used for all field level errors.

See Also:
Constant Field Values

INVALIDFORM

public static final java.lang.String INVALIDFORM
A general code used for all general update errors.

See Also:
Constant Field Values
Constructor Detail

MessageUtil

public MessageUtil()
Method Detail

appendError

public static java.lang.String appendError(java.lang.String errorText,
                                           java.lang.String addText)
Appends addText to errorText separated by PROB_DELIMITER if errorText was not the empty String.


infoAsString

public static java.lang.String infoAsString(ErrorInfo[] eis)
Return the ErrorInfoCollection contents as a string.


noteError

public static UIFormContext noteError(UIFormContext uifc,
                                      AggregateUpdate au)
Note the errors from the given AggregateUpdate in the given UIFormContext and return it.


hasErrors

public boolean hasErrors(AggregateUpdate au)
Return true if the given AggregateUpdate contains errors.


verifyFieldsBase

public static ErrorInfoCollection verifyFieldsBase(SandInstanceMessage sim)
Verify that all the fields are valid according to the fieldsValid method of the given SandIntanceMessage. Returns a string with all field errors found, or the empty string if all the fields have valid values.


verifyFieldsFull

public static ErrorInfoCollection verifyFieldsFull(SandInstanceMessage sim)
Verify that all the fields are valid according to the fieldsValid method of the given SandIntanceMessage, and the verifyAuthUser method here. Returns a string with all field errors found, or the empty string if all the fields have valid values.


verifyAuthUser

public static void verifyAuthUser(ErrorInfoCollection eic,
                                  AuthUser user)
Verify that the username and password fields meet common usage assumptions. This is restrictive, basically stating that a username needs to be a valid java identifier, with the exception of allowing an "@" or a "." or "-" so you can use an email address as a username. Spaces and other funny characters are disallowed in both usernames and passwords, and values need to be specified for both fields.

This is intended to provide some default checking functionality and is not a universal solution implementation.


defaultUnauthorizedFields

public static void defaultUnauthorizedFields(SandInstanceMessage sim,
                                             AuthUser user,
                                             AuthFilter filter,
                                             Logger logger)
Set any unauthorized fields to their default values. If the user is not allowed to see a given field, then it is set to its default value in the object representation for that instance. So even if the field somehow becomes visible, it only has the default value.


appendError

public static void appendError(ErrorInfoCollection eic,
                               java.lang.String errtext)
Convenience method to append a general error to the given collection.


appendFieldError

public static void appendFieldError(ErrorInfoCollection eic,
                                    java.lang.String field,
                                    java.lang.String errtext)
Convenience method to append a field error the given collection.


containsID

public static boolean containsID(SandCollectionMessage coll,
                                 long id)
Return true if the given collection message contains an instance with the given id, false otherwise.


verifyTransmission

public static void verifyTransmission(SandTransmitMessage stm)
                               throws SandException
Throw if the transmission status is anything other than normal.

Throws:
SandException

completeCollection

public static SandCollectionMessage completeCollection(SandQueryMessage sqm,
                                                       Messageable node)
                                                throws SandException
A generalized query processing method that will return the entire collection of elements matching the query. Throws if anything goes wrong. This method should be used with caution since the resulting collection will be as large as the total dataset.

Throws:
SandException