public final class GloopMethods extends Object
Constructor and Description |
---|
GloopMethods() |
Modifier and Type | Method and Description |
---|---|
static String |
contextToJsonString(io.toro.gloop.engine.GloopExecutionContext context)
Return a JSON string representation of the current Gloop variable context.
|
static void |
cursorAppend(io.toro.gloop.object.cursor.GloopCursor cursor,
Object value)
Add new value(s) to the cursor.
|
static void |
cursorClose(io.toro.gloop.object.cursor.GloopCursor cursor)
Close a cursor.
|
static Object |
cursorGetValue(io.toro.gloop.object.cursor.GloopCursor cursor)
Get the value of the current record from the cursor.
|
static boolean |
cursorHasNext(io.toro.gloop.object.cursor.GloopCursor cursor)
Check whether or not the given Gloop cursor has another record.
|
static int |
cursorLast(io.toro.gloop.object.cursor.GloopCursor cursor)
Iterate through the cursor until the last record is reached.
|
static void |
cursorNextRecord(io.toro.gloop.object.cursor.GloopCursor cursor)
Move the cursor to the next record.
|
static long |
cursorSize(io.toro.gloop.object.cursor.GloopCursor cursor)
Get the size of a cursor.
|
static int |
cursorSkip(io.toro.gloop.object.cursor.GloopCursor cursor,
int skipCount)
Try to skip the next n records in a cursor.
|
static io.toro.gloop.object.property.GloopModel |
cursorToArray(io.toro.gloop.object.cursor.GloopCursor cursor)
Iterate through a cursor, and create an in-memory Gloop model array.
|
static io.toro.gloop.object.property.GloopModel |
dynamicModelToMapModelArray(io.toro.gloop.object.property.GloopModel anonymousModel)
Create an array of models describing the property names and values of a provided model.
|
static io.toro.gloop.object.property.GloopObject |
fromGloopDoc(String string)
Creates a gloop object based from the provided
string |
static String |
getSystemProperty(String name,
String defaultVal)
Get a Java system property.
|
static long |
getSystemTime()
Get the current system time in milliseconds.
|
static void |
loadContextFromAvro(List<String> names,
byte[] data,
io.toro.gloop.engine.GloopExecutionContext context)
Saves the properties with the given names from the context to an output stream, in the
Apache Avro data file format.
|
static io.toro.gloop.object.property.GloopModel |
mapModelArrayToDynamicModel(io.toro.gloop.object.property.GloopModel mapModelArray)
Create a new model from an array of Gloop models,
which describe each of the new model's property names and values.
|
static Object |
runScriptlet(String scriptlet,
io.toro.gloop.engine.GloopExecutionContext context)
Run a piece of Groovy code within the current context.
|
static Object |
runScriptlet(String language,
String scriptlet,
io.toro.gloop.engine.GloopExecutionContext context)
Run a piece of code within the current context.
|
static void |
saveContextAsAvro(List<String> names,
OutputStream outputStream,
io.toro.gloop.engine.GloopExecutionContext context)
Saves the properties with the given names from the context to an output stream, in the Apache Avro data file format.
|
static String |
setSystemProperty(String name,
String value)
Set a Java system property.
|
static void |
throwApiException(io.toro.gloop.object.property.GloopModel exception)
Throws the provided exception.
|
static void |
throwException(String message)
Throws an exception with the given message.
|
static void |
throwException(String message,
Throwable cause)
Throws an exception with the given message and cause.
|
(package private) static void |
throwException(Throwable cause) |
@GloopParameter(name="systemTime") public static long getSystemTime()
System.currentTimeMillis()
@GloopParameter(name="systemProperty") public static String getSystemProperty(String name, String defaultVal)
name
- the name of the property to getdefaultVal
- the default value to return if the property isn't setnull
if the property isn't setSystem.getProperty(String, String)
public static String setSystemProperty(String name, String value)
name
- the name of the propertyvalue
- the value to assign to the system propertynull
if it did not have one.System.setProperty(String, String)
public static Object runScriptlet(String scriptlet, io.toro.gloop.engine.GloopExecutionContext context) throws Throwable
scriptlet
- the snippet to execute against the current contextcontext
- the Gloop execution context (automatically mapped by Gloop)Throwable
public static Object runScriptlet(String language, String scriptlet, io.toro.gloop.engine.GloopExecutionContext context) throws Throwable
language
- the language the snippet is written inscriptlet
- the snippet to execute against the current contextcontext
- the Gloop execution context (automatically mapped by Gloop)Throwable
public static boolean cursorHasNext(io.toro.gloop.object.cursor.GloopCursor cursor)
public static void cursorNextRecord(io.toro.gloop.object.cursor.GloopCursor cursor)
public static Object cursorGetValue(io.toro.gloop.object.cursor.GloopCursor cursor)
public static void cursorAppend(@GloopParameter(allowNull=false) io.toro.gloop.object.cursor.GloopCursor cursor, @GloopParameter(allowNull=false) Object value)
value
is a collections, array, or an array of GloopObject
s, it will be iterated,
and elements will be added individually.value
- the value(s) to add to the cursorpublic static long cursorSize(io.toro.gloop.object.cursor.GloopCursor cursor)
public static int cursorSkip(io.toro.gloop.object.cursor.GloopCursor cursor, int skipCount)
skipCount
- how many records to skip overpublic static int cursorLast(io.toro.gloop.object.cursor.GloopCursor cursor)
public static void cursorClose(io.toro.gloop.object.cursor.GloopCursor cursor)
@GloopObjectParameter(value="output{\ncursorValues[]*{\n}\n}") public static io.toro.gloop.object.property.GloopModel cursorToArray(io.toro.gloop.object.cursor.GloopCursor cursor)
public static String contextToJsonString(io.toro.gloop.engine.GloopExecutionContext context)
context
- the Gloop execution context (automatically mapped by Gloop)public static void throwException(@GloopParameter(allowNull=false) String message) throws Exception
message
- the exception messageException
- the to-be-thrown exceptionpublic static void throwException(@GloopParameter(value="Exception Message") String message, @GloopParameter(value="Cause") Throwable cause) throws Exception
Exception
- the to-be-thrown exceptionstatic void throwException(@GloopParameter(value="Cause") Throwable cause) throws Exception
Exception
public static void throwApiException(@GloopObjectParameter(value="apiException#io.toro.martini.api.APIException{\n}") @GloopParameter(allowNull=false) io.toro.gloop.object.property.GloopModel exception) throws APIException
exception
- to throwAPIException
@GloopObjectParameter(value="output{\n output[]{\n name\n value:object\n }\n}") public static io.toro.gloop.object.property.GloopModel dynamicModelToMapModelArray(@GloopParameter(allowExtraProperties=true) io.toro.gloop.object.property.GloopModel anonymousModel)
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" } ]
anonymousModel
- the model whose structure will be recreated as an array of name-value pairs@GloopParameter(allowExtraProperties=true) public static io.toro.gloop.object.property.GloopModel mapModelArrayToDynamicModel(@GloopObjectParameter(value="model[]{\n name\n value:object\n}\n") io.toro.gloop.object.property.GloopModel mapModelArray)
name
s are TORO and Martini,
and whose value
s 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" }
mapModelArray
- an array of models describing the property names and values of the new modelpublic static io.toro.gloop.object.property.GloopObject fromGloopDoc(@GloopParameter(allowNull=false) String string)
string
string
- string containing information about the gloop objectpublic static void saveContextAsAvro(List<String> names, @GloopParameter(allowNull=false) OutputStream outputStream, io.toro.gloop.engine.GloopExecutionContext context) throws IOException
names
- root-level properties to save. If null or empty, all properties will be savedoutputStream
- where to write the Avro data tocontext
- Gloop Execution ContextIOException
loadContextFromAvro(java.util.List, byte[], io.toro.gloop.engine.GloopExecutionContext)
public static void loadContextFromAvro(List<String> names, @GloopParameter(allowNull=false) byte[] data, io.toro.gloop.engine.GloopExecutionContext context) throws IOException
names
- root-level properties to save, if null or empty, all properties will be saveddata
- where to read the avro data fromcontext
- Gloop Execution ContextIOException
saveContextAsAvro(java.util.List, java.io.OutputStream,
io.toro.gloop.engine.GloopExecutionContext)
Copyright © 2020. All rights reserved.