Class RemoteCommandUtils


  • public final class RemoteCommandUtils
    extends Object
    Helper methods for <p:remoteCommand>, such as reading parameters and returning a value.
    Since:
    7.0.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • addError

        public static void addError​(Throwable e)
        Sets the success return value to false and also add the error message as a return parameter.
        Parameters:
        e - Exception that occurred.
      • addReturnValue

        public static void addReturnValue​(String paramName,
                                          boolean value)
        Adds a return value for the remote command with the given parameter name. Also sets the success return parameter to true.
        Parameters:
        paramName - Name of the parameter, can be used on the client to access the parameter.
        value - Boolean value to be returned.
      • addReturnValue

        public static void addReturnValue​(String paramName,
                                          int value)
        Adds a return value for the remote command with the given parameter name. Also sets the success return parameter to true.
        Parameters:
        paramName - Name of the parameter, can be used on the client to access the parameter.
        value - Integer value to be returned.
      • addReturnValue

        public static void addReturnValue​(String paramName,
                                          long value)
        Adds a return value for the remote command with the given parameter name. Also sets the success return parameter to true.
        Parameters:
        paramName - Name of the parameter, can be used on the client to access the parameter.
        value - Long value to be returned.
      • addReturnValue

        public static void addReturnValue​(String paramName,
                                          Object value)
        Adds a return value for the remote command with the given parameter name. Also sets the success return parameter to true.
        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 to true.
      • delayResponse

        public static String delayResponse()
        Can be used when the response to a remote command cannot be computed synchronously. Returns a delay ID that should be passed to resolveDelayed(String).
        Returns:
        The delay ID that must be used to resolve the delayed remote command. Must be passed to resolveDelayed(String) or the client-side promise will never resolve
      • getBoolean

        public static boolean getBoolean​(String paramName)
        Parameters:
        paramName - Name of the parameter to read.
        Returns:
        The boolean value of the parameter, false when the parameter is not present.
      • getBooleanOptional

        public static Optional<Boolean> getBooleanOptional​(String paramName)
        Parameters:
        paramName - Name of the parameter to read.
        Returns:
        The boolean value of the parameter, empty optional when the parameter is not present.
      • getEnum

        public static <T extends Enum<T>> T getEnum​(String paramName,
                                                    Class<T> enumType)
        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.
      • getJsonArray

        public static <T> List<T> getJsonArray​(String paramName,
                                               Class<T> clazz)
        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

        public static com.alibaba.fastjson.JSONObject getJsonObject​(String paramName)
        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

        public static <T> T getJsonObject​(String paramName,
                                          Class<T> clazz)
        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

        public static <T> T getJsonObject​(String paramName,
                                          Class<T> clazz,
                                          T defaultValue)
        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.
      • getListOfLongs

        public static Optional<List<Long>> getListOfLongs​(String paramName)
        Parameters:
        paramName - Name of the parameter to read. Never null, only empty.
        Returns:
        A list of all values for the given parameter.
      • getListOfStrings

        public static List<String> getListOfStrings​(String paramName)
        Parameters:
        paramName - Name of the parameter to read. Never null, only empty.
        Returns:
        A list of all values for the given parameter.
      • getLocale

        public static Locale getLocale​(String paramName)
        Parameters:
        paramName - Name of the parameter to read.
        Returns:
        The locale indicated by the parameter, or null if no such parameter exists.
      • getLocale

        public static Locale getLocale​(String paramName,
                                       Locale defaultValue)
        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

        public static OptionalLong getLong​(String paramName)
        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

        public static long getLong​(String paramName,
                                   long defaultValue)
        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

        public static Set<String> getSetOfStrings​(String paramName)
        Parameters:
        paramName - Name of the parameter to read. Never null, only empty.
        Returns:
        A set of all values for the given parameter.
      • getString

        public static String getString​(String paramName)
        Parameters:
        paramName - Name of the parameter to read.
        Returns:
        The string value of the parameter, empty string if no such parameter exists.
      • getString

        public static String getString​(String paramName,
                                       String defaultValue)
        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

        public static Optional<String> getStringOptional​(String paramName)
        Parameters:
        paramName - Name of the parameter to read.
        Returns:
        The string value of the parameter, empty optional if no such parameter exists.