Package de.xima.fc.gui.common.utils
Class RemoteCommandUtils
java.lang.Object
de.xima.fc.gui.common.utils.RemoteCommandUtils
Helper methods for
<p:remoteCommand>
, such as reading parameters and returning a value.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Sets the success return value tofalse
and also add the error message as a return parameter.static void
addReturnValue
(String paramName, boolean value) Adds a return value for the remote command with the given parameter name.static void
addReturnValue
(String paramName, int value) Adds a return value for the remote command with the given parameter name.static void
addReturnValue
(String paramName, long value) Adds a return value for the remote command with the given parameter name.static void
addReturnValue
(String paramName, Object value) Adds a return value for the remote command with the given parameter name.static void
Sets the success return parameter totrue
.static void
delayResponse
(String delayId) Can be used when the response to a remote command cannot be computed synchronously.static boolean
getBoolean
(String paramName) getBooleanOptional
(String paramName) static <T extends Enum<T>>
Tstatic OptionalInt
static int
static <T> List<T>
getJsonArray
(String paramName, Class<T> clazz) static com.alibaba.fastjson.JSONObject
getJsonObject
(String paramName) static com.alibaba.fastjson.JSONObject
getJsonObject
(String paramName, com.alibaba.fastjson.JSONObject defaultValue) static <T> T
getJsonObject
(String paramName, Class<T> clazz) static <T> T
getJsonObject
(String paramName, Class<T> clazz, T defaultValue) static List<com.alibaba.fastjson.JSONObject>
getListOfJsonObjects
(String paramName) static <T> List<T>
getListOfJsonObjects
(String paramName, Class<T> clazz) getListOfLongs
(String paramName) getListOfStrings
(String paramName) static Locale
static Locale
static OptionalLong
static long
static Optional<com.vdurmont.semver4j.Semver>
static com.vdurmont.semver4j.Semver
getSemver
(String paramName, com.vdurmont.semver4j.Semver.SemverType type, com.vdurmont.semver4j.Semver defaultValue) getSetOfStrings
(String paramName) static String
static String
getStringOptional
(String paramName) static void
resolveDelayed
(String delayId) Marks the response as the result for the given delay ID.
-
Method Details
-
addError
Sets the success return value tofalse
and also add the error message as a return parameter.- Parameters:
e
- Exception that occurred.
-
addReturnValue
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue
.- Parameters:
paramName
- Name of the parameter, can be used on the client to access the parameter.value
- Boolean value to be returned.
-
addReturnValue
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue
.- Parameters:
paramName
- Name of the parameter, can be used on the client to access the parameter.value
- Integer value to be returned.
-
addReturnValue
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue
.- Parameters:
paramName
- Name of the parameter, can be used on the client to access the parameter.value
- Long value to be returned.
-
addReturnValue
Adds a return value for the remote command with the given parameter name. Also sets the success return parameter totrue
.- Parameters:
paramName
- Name of the parameter, can be used on the client to access the parameter.value
- Value to be returned. This value is stringified.
-
addSuccess
public static void addSuccess()Sets the success return parameter totrue
. -
delayResponse
Can be used when the response to a remote command cannot be computed synchronously. Must be given a delay ID that should be passed toresolveDelayed(String)
.- Parameters:
delayId
- The delay ID that must be used to resolve the delayed remote command. Must be passed toresolveDelayed(String)
or the client-side promise will never resolve
-
getBoolean
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The boolean value of the parameter,
false
when the parameter is not present.
-
getBooleanOptional
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The boolean value of the parameter, empty optional when the parameter is not present.
-
getEnum
- Type Parameters:
T
- Type of the enum.- Parameters:
paramName
- Name of the parameter to read.enumType
- Type of the enum.- Returns:
- The enum value of the parameter, or
null
when the parameter is not present or no such enum constant exists.
-
getInt
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The int value of the parameter, empty if no such parameter exists or it its not a valid int.
-
getInt
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist or is not a valid int.- Returns:
- The int value of the parameter, default value if no such parameter exists or it its not a valid int.
-
getJsonArray
- Type Parameters:
T
- Type to create from the JSON.- Parameters:
paramName
- Name of the parameter to read.clazz
- Type to create from the JSON.- Returns:
- The value of the parameter parsed as a deserialized list, empty list if no such parameter exists or it is invalid.
-
getJsonObject
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The value of the parameter parsed as a JSON object, empty object if no such parameter exists or it is invalid.
-
getJsonObject
- Type Parameters:
T
- Type to create from the JSON.- Parameters:
paramName
- Name of the parameter to read.clazz
- Type to create from the JSON.- Returns:
- The value of the parameter parsed as a deserialized object, null if no such parameter exists or it is invalid.
-
getJsonObject
- Type Parameters:
T
- Type to create from the JSON.- Parameters:
paramName
- Name of the parameter to read.clazz
- Type to create from the JSON.defaultValue
- Default value to return when the parameter could not be read.- Returns:
- The value of the parameter parsed as a deserialized object, default value if no such parameter exists or it is invalid.
-
getJsonObject
public static com.alibaba.fastjson.JSONObject getJsonObject(String paramName, com.alibaba.fastjson.JSONObject defaultValue) - Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist or is invalid.- Returns:
- The value of the parameter parsed as a JSON object, default value if no such parameter exists or it is invalid.
-
getListOfJsonObjects
- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.- Returns:
- A list of all values for the given parameter, parsed as a JSON object of the given class.
-
getListOfJsonObjects
- Type Parameters:
T
- Type to create from the JSON.- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.clazz
- Type to create from the JSON.- Returns:
- A list of all values for the given parameter, parsed as a JSON object of the given class.
-
getListOfLongs
- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.- Returns:
- A list of all values for the given parameter.
-
getListOfStrings
- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.- Returns:
- A list of all values for the given parameter.
-
getLocale
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The locale indicated by the parameter, or
null
if no such parameter exists.
-
getLocale
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist.- Returns:
- The locale indicated by the parameter, or the default value if no such parameter exists.
-
getLong
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The long value of the parameter, empty if no such parameter exists or it its not a valid long.
-
getLong
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist or is not a valid long.- Returns:
- The long value of the parameter, default value if no such parameter exists or it its not a valid long.
-
getSemver
public static Optional<com.vdurmont.semver4j.Semver> getSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type) - Parameters:
paramName
- Name of the parameter to read.type
- Semver type to use for parsing.- Returns:
- The boolean value of the parameter,
false
when the parameter is not present.
-
getSemver
public static com.vdurmont.semver4j.Semver getSemver(String paramName, com.vdurmont.semver4j.Semver.SemverType type, com.vdurmont.semver4j.Semver defaultValue) - Parameters:
paramName
- Name of the parameter to read.type
- Semver type to use for parsing.defaultValue
- Default used when the value cannot be parsed as a semver.- Returns:
- The boolean value of the parameter,
false
when the parameter is not present.
-
getSetOfStrings
- Parameters:
paramName
- Name of the parameter to read. Nevernull
, only empty.- Returns:
- A set of all values for the given parameter.
-
getString
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The string value of the parameter, empty string if no such parameter exists.
-
getString
- Parameters:
paramName
- Name of the parameter to read.defaultValue
- Default value used when parameter does not exist.- Returns:
- The string value of the parameter, or the default value if no such parameter exists.
-
getStringOptional
- Parameters:
paramName
- Name of the parameter to read.- Returns:
- The string value of the parameter, empty optional if no such parameter exists.
-
resolveDelayed
Marks the response as the result for the given delay ID. Must be called after all other calls that add values, such asaddSuccess()
,addError(Throwable)
,addReturnValue(String, boolean)
etc.- Parameters:
delayId
- The delay ID that was passed todelayResponse(String)
.
-