Class GloopMethods


  • public final class GloopMethods
    extends Object
    Contains utility methods for use in Gloop.
    • Constructor Detail

      • GloopMethods

        GloopMethods()
    • Method Detail

      • getSystemProperty

        @GloopParameter(name="systemProperty")
        public static String getSystemProperty​(String name,
                                               String defaultVal)
        Get a Java system property.
        Parameters:
        name - the name of the property to get
        defaultVal - the default value to return if the property isn't set
        Returns:
        the system property value; null if the property isn't set
        See Also:
        System.getProperty(String, String)
      • setSystemProperty

        public static String setSystemProperty​(String name,
                                               String value)
        Set a Java system property.
        Parameters:
        name - the name of the property
        value - the value to assign to the system property
        Returns:
        the previous value of the system property, or null if it did not have one.
        See Also:
        System.setProperty(String, String)
      • runScriptlet

        public static Object runScriptlet​(String scriptlet,
                                          GloopExecutionContext context)
                                   throws Throwable
        Run a piece of Groovy code within the current context.
        Parameters:
        scriptlet - the snippet to execute against the current context
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        the result of the scriptlet
        Throws:
        Throwable
      • runScriptlet

        public static Object runScriptlet​(String language,
                                          String scriptlet,
                                          GloopExecutionContext context)
                                   throws Throwable
        Run a piece of code within the current context.
        Parameters:
        language - the language the snippet is written in
        scriptlet - the snippet to execute against the current context
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        the result of the scriptlet
        Throws:
        Throwable
      • cursorHasNext

        public static boolean cursorHasNext​(GloopCursor cursor)
        Check whether or not the given Gloop cursor has another record.
        Returns:
        true if the cursor has more records; false otherwise
      • cursorNextRecord

        public static void cursorNextRecord​(GloopCursor cursor)
        Move the cursor to the next record.
      • cursorGetValue

        public static Object cursorGetValue​(GloopCursor cursor)
        Get the value of the current record from the cursor.
        Returns:
        the current value of the record the cursor is pointing to
      • cursorAppend

        public static void cursorAppend​(@GloopParameter(allowNull=false)
                                        GloopCursor cursor,
                                        @GloopParameter(allowNull=false)
                                        Object value)
        Add new value(s) to the cursor. If value is a collections, array, or an array of GloopObjects, it will be iterated, and elements will be added individually.
        Parameters:
        value - the value(s) to add to the cursor
      • cursorSize

        public static long cursorSize​(GloopCursor cursor)
        Get the size of a cursor.
        Returns:
        the size of the cursor
      • cursorSkip

        public static int cursorSkip​(GloopCursor cursor,
                                     int skipCount)
        Try to skip the next n records in a cursor.
        Parameters:
        skipCount - how many records to skip over
        Returns:
        how many records were actually skipped
      • cursorLast

        public static int cursorLast​(GloopCursor cursor)
        Iterate through the cursor until the last record is reached.
        Returns:
        the number of records that were skipped over
      • cursorClose

        public static void cursorClose​(GloopCursor cursor)
        Close a cursor.
      • cursorToArray

        @GloopObjectParameter("output{\ncursorValues[]*{\n}\n}")
        public static GloopModel cursorToArray​(GloopCursor cursor)
        Iterate through a cursor, and create an in-memory Gloop model array.
        Returns:
        the model array containing all cursor data
      • contextToJsonString

        public static String contextToJsonString​(GloopExecutionContext context)
        Return a JSON string representation of the current Gloop variable context.
        Parameters:
        context - the Gloop execution context (automatically mapped by Gloop)
        Returns:
        a JSON string representing the Gloop context
      • throwException

        public static void throwException​(@GloopParameter(allowNull=false)
                                          String message)
                                   throws Exception
        Throws an exception with the given message.
        Parameters:
        message - the exception message
        Throws:
        Exception - the to-be-thrown exception
      • dynamicModelToMapModelArray

        @GloopObjectParameter("output{\n  output[]{\n    name\n    value:object\n  }\n}")
        public static GloopModel dynamicModelToMapModelArray​(@GloopParameter
                                                             GloopModel anonymousModel)
        Create an array of models describing the property names and values of a provided model. Each model in the resulting array will have two properties named name and value. This one-liner will create a model for every property in the provided model, and map the property's name to name, and value to value. Consider the following model:
         {
             "TORO": "Cloud",
             "Martini": "Ninja"
         }
         
        By providing this model to this one-liner, the resulting array of models will be:
         [
             {
                 "name": "TORO",
                 "value": "Cloud"
             },
             {
                 "name": "Martini",
                 "value": "Ninja"
             }
         ]
         
        Parameters:
        anonymousModel - the model whose structure will be recreated as an array of name-value pairs
        Returns:
        an array of models describing the property names and values of the model
      • mapModelArrayToDynamicModel

        @GloopParameter
        public static GloopModel mapModelArrayToDynamicModel​(@GloopObjectParameter("model[]{\n  name\n  value:object\n}\n")
                                                             GloopModel mapModelArray)
        Create a new model from an array of Gloop models, which describe each of the new model's property names and values. For example, consider an array of two models, whose names are TORO and Martini, and whose values are Cloud and Ninja respectively.
         [
             {
                 "name": "TORO",
                 "value": "Cloud"
             },
             {
                 "name": "Martini",
                 "value": "Ninja"
             }
         ]
         
        Using this one-liner, the resulting model would be represented in JSON as follows:
         {
             "TORO": "Cloud",
             "Martini": "Ninja"
         }
         
        Parameters:
        mapModelArray - an array of models describing the property names and values of the new model
        Returns:
        new model whose structure is derived from the array of models
      • fromGloopDoc

        public static GloopObject<?> fromGloopDoc​(@GloopParameter(allowNull=false)
                                                  String string)
        Creates a gloop object based from the provided string
        Parameters:
        string - string containing information about the gloop object
        Returns:
        gloop object created from the string