public class StandardDataFactory extends Object
DataDefinition
s and DataValue
s for
standard vAPI structures, like errors and localizable messages.Modifier and Type | Field and Description |
---|---|
static String |
ALREADY_EXISTS |
static String |
ARGS_FIELD_NAME |
static String |
DATA_FIELD_NAME |
static String |
DEFAUL_MSG_FIELD_NAME |
static String |
ID_FIELD_NAME |
static String |
INTERNAL_SERVER_ERROR |
static String |
INVALID_ARGUMENT |
static String |
MESSAGE_STRUCT_NAME |
static String |
MESSAGES_FIELD_NAME |
static String |
NOT_FOUND |
static String |
OPERATION_NOT_FOUND |
static Map<String,DataDefinition> |
STANDARD_ERROR_FIELDS |
static String |
UNAUTHENTICATED |
static String |
UNEXPECTED_INPUT |
Constructor and Description |
---|
StandardDataFactory() |
Modifier and Type | Method and Description |
---|---|
static ErrorValue |
createErrorValueForMessages(ErrorDefinition errorDef,
List<Message> messages)
Creates instance for given error definition and list of
Messages s. |
static ErrorValue |
createErrorValueForMessages(String errorName,
List<Message> messages)
Creates a standard error
ErrorValue for the given
name list of Messages s. |
static ErrorDefinition |
createStandardErrorDefinition(String errorName)
Factory method for
ErrorDefinition s for standard
vAPI errors. |
static StructDefinition |
getLocalizableMessageDefinition() |
static List<Message> |
getMessagesFromErrorValue(StructValue error)
Returns messages associated with the specified standard error
ErrorValue represented as list of Message s. |
public static final String ALREADY_EXISTS
public static final String INTERNAL_SERVER_ERROR
public static final String OPERATION_NOT_FOUND
public static final String INVALID_ARGUMENT
public static final String NOT_FOUND
public static final String UNAUTHENTICATED
public static final String UNEXPECTED_INPUT
public static final String MESSAGE_STRUCT_NAME
public static final String ID_FIELD_NAME
public static final String DEFAUL_MSG_FIELD_NAME
public static final String ARGS_FIELD_NAME
public static final String MESSAGES_FIELD_NAME
public static final String DATA_FIELD_NAME
public static final Map<String,DataDefinition> STANDARD_ERROR_FIELDS
public static StructDefinition getLocalizableMessageDefinition()
public static ErrorDefinition createStandardErrorDefinition(String errorName)
ErrorDefinition
s for standard
vAPI errors.
Creates instance for the specified name. The name is used as name
of the StructDefinition
represented by the instance.
Additionally, a field named "messages" is added to the
StructDefinition
, the definition of this field is:
ListDefinition StructDefinition id -> StringDefinition default_message -> StringDefinition args -> ListDefinition StringDefinitionThat is a list of localizable messages.
errorName
- the error nameErrorDefinition
isntancepublic static ErrorValue createErrorValueForMessages(String errorName, List<Message> messages)
ErrorValue
for the given
name list of Messages
s.public static ErrorValue createErrorValueForMessages(ErrorDefinition errorDef, List<Message> messages)
Messages
s. The name is used as name of the
StructValue
represented by the instance. Messages are
converted to list of structures and set as "messages" field (of
StructValue
) of this instance. The structure of the
"messages" field is:
ListValue StructValue id -> StringValue default_message -> StringValue args -> ListValue StringValue
errorDef
- error definitionmessages
- the messages for the new ErrorValue
ErrirValue
instanceIllegalArgumentException
- if messages
or
errorDef
is null
or
messages
is empty or contains null
element(s)public static List<Message> getMessagesFromErrorValue(StructValue error)
ErrorValue
represented as list of Message
s.
This method assumes the structure of "messages" field from
createErrorValueForMessages(ErrorDefinition, List)
.
In case this structure is not present - empty list is returned.error
- standard error valueCopyright © 2015. All Rights Reserved.