![]() You can then insert the results from the second query into the map using the same key format. You can place the results from the first query into a map using either the StormWorks ID or component name as key. Maps are also useful when two separate Data API queries have been used to pull back different information about the same components, and the two separate datasets need to be merged. If the results returned from a Data API call were to be a String with the meaning of the status, and there was a requirement to convert this to the corresponding numeric value, the following map syntax could be used:ĭef meaning = if an enumeration for a port state might be 1=Up, 2=Down, 3=Testing, 4=Failed. For example, this means it can be used to hold the values associated with enumerations, e.g. One array list can be appended to another:Ī.addAll(b) … the result would be Īn element of an ArrayList can be obtained using its index:Ī map, also known as an associative array, contains a list of data types that can be indexed by a key, which in turn can be any fundamental data type. You can instantiate an empty ArrayList as follows:Īn ArrayList can be populated during instantiation:Īn ArrayList can have elements added after instantiation:Ī.add(3) … the result would be an ArrayList containing Ī.add(0,9) … this syntax specifies where to add the new element, in this case at the beginning The records returned from the Report Query to the main report are usually in the form of an ArrayList. The Entuity Data API returns a collection of components as an ArrayList. Technically, it is not essential that every element of an ArrayList have the same data type, but in most applications there is uniformity across the elements. You can collect data together using an ArrayList, which is a linear list of variables. If variable a were a null string, then b would be set to a null rather than raising a runtime error. This can be handled using the following syntax: If an attempt were to be made to convert this empty string to a Float using the toFloat() method, then a runtime error would be raised and the report would crash. If the mean utilization of a port were requested by a query for a period of time during which the device were totally unreachable, the mean utilization would be returned as an empty string. For example, a very common requirement when writing reports is to protect against empty/null values being returned by the Data API queries. When a decision needs to be made as to what to write to a variable, a ternary operator can often be used to shorten the syntax. The case may also be followed by a closure rather than just a static value, so more sophisticated testing can be performed in a Java switch structure.Ī ternary operator is a shorcut expression that is equivalent to an if/else branch assigning some value to a variable. In a switch structure, the Variable may be any data type including Strings. Note, S tatement can be a single statement or multiple statements separated either by semicolons and/or new line, all enclosed in : The value of a Boolean variable can be inverted by preceding with with a "!".Įntuity supports the following standard operators: The following Boolean statements are valid: These display the supplied string as either with or without an appended newline, respectively. To print to screen, use either of the following: ![]() ![]() When debugging a script, it can be useful to print arbitrary information to a screen, for example the value of a variable at an intermediate stage of its processing. To avoid confusion between Floats and Doubles, the standard Entuity reports force all floating point variables to be Floats. ![]() Variables should also be initialized during instantiation: To instantiate a variable (i.e., create a variable at runtime), the def keyword is used. For example, the following two lines are both valid and functionally identical:Įntuity recommends that you place each Groovy statement on its own line, because this will make the code easier to read. Statements placed on their own line do not require an end of statement delimiter, but you can use one. The second delimiter is not required, but for consistency you might want to include it. If you place two Groovy statements on the same line, they require a delimiter (semi-colon) to separate them, e.g.: You can also refer to the online Groovy console facility at, which allows you to experiment and test Groovy syntax without having to install anything locally on your own system. ![]() For a full introduction to Groovy, please refer to. This article identifies Groovy concepts that are useful when developing Groovy scripts. The Entuity server includes a Groovy installation that runs these scripts when they are loaded to the server. In Entuity, you can develop Groovy scripts for use with the Event Management System (EMS), Reports and Configuration Management. Referencing fields within an object safelyĬontrolling the numeric precision of floating point numbers ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |