groovy

Put a key named metaClass in a Map

Hi, I've written a small Groovy script that exposes a very weird behaviour. can anyone explain it ? // Creating a groovy map def map = [:] // Putting a value in map["a"]="b" // Render it without trouble println map["a"] // Putting another value in (yup, this one has THE name) map["metaClass"]="c" // Failing to render it println m...

Groovy: Handling large amounts of data with StreamingMarkupBuilder

Hello, The scenario is the following. I have a plain text file which contains 2,000,000 lines with an ID. This list of IDs needs to be converted to a simple XML file. The following code works fine as long as there are only some thousand entries in the input file. def xmlBuilder = new StreamingMarkupBuilder() def f = new File(inputFile)...

recurring event logic

Hi, I'm working on a Groovy/Java calendar-type application that allows the user to enter events with a start date and an optional recurrence. If it's a recurring event, it may recurr: monthly on a date of the month that corresponds to the start date weekly on a day of the week of that corresponds to the start date every 2 weeks on a d...

SOAPUI: Can I set up multiple test case responses when I don't know the order the requests will come in

I am using SOAPUI to test an application. To initiate the test, I send a JMS message to the software from SOAPUI. There are multiple hooks in the code that are built to respond to this JMS message, including a few that respond by making web service requests to services I intend to mock with SOAPUI. I cannot predict the order these r...

Which documentation you recommend for JPA and other playframework ecosystem

What documentation (books or online resources) you would recommend for a JPA newbie, which want to program with the play framework? In play you only use annotations and hibernate as JPA implementation, so it would be useful if there would be the focus on. I started with wiki-book, but not sure if it is the best solution. A book for gr...

Unknown type: METHOD_DEF when running a groovy script

The following groovy script doesn't compile import java.util.concurrent.Callable println "b"; Callable<String> callable = new Callable<String>() { String call() { println("C"); return null; } }; This is the error: org.codehaus.groovy.control.MultipleCompilationErrorsException: sta...

"This script or class was runnable but could not be run"

I'm getting this error when running a groovy script (GroovyRuntimeException), and the top Google results are not clear/concise enough. What exactly does this error mean? ...

Is there a "use strict" for Groovy?

I remember from my Perl days the "use strict" statement that cause the runtime to do extra validations. Is there an equivalent for Groovy? I do not enjoy being bitten during runtime by what can be detected on compilation, like passing too few arguments to a constructor. ...

Best practices moving from Java to Groovy

I'm versed in Java, and starting to experiment with Groovy. Because the two are integrated so well, I find myself writing in Java whatever I can because it's so easy. What specific tips can you offer that would speedup my work with Groovy? Meaning - in what areas do groovy excel over java, and where should I stick to Java? ...

Debugging a runnable groovy class via IntelliJ

I'm successfully debugging this script in Intellij: println "a"; println "b"; But, when trying to debug the following script, my breakpoints aren't hit public class Main implements Runnable{ public Main(String[] args) { println("A"); // breakpoint println "B"; } void run() { println "C"; // breakpoint println ...

How can I retrieve an element from Groovy's GPathResult using a string that contains a perioid

def elementPath = "elementA.elementB" xml."${elementPath}".each {} How to make this work? xml.elementA.elementB.each {} works. ...

SpringLayout in Groovy using SwingBuilder

Does anyone have an example of how the Java SpringLayout Layout Manager works with Groovy's SwingBuilder class? SpringLayout handles constraints a bit differently from the other layout managers, so I can't quite figure out how to make it work. Any thoughts, examples, tutorials would be much appreciated! Thanks! ...

Calling a Groovy function from Java

How do you call a function defined in a Groovy script file from Java? Example groovy script: def hello_world() { println "Hello, world!" } I've looked at the GroovyShell, GroovyClassLoader, and GroovyScriptEngine. ...

Converting CruiseControl to Hudson

Hello Everyone, I am currently writing a Perl script that will convert CruiseControl config.xml files to a Hudson config.xml for each project. However I am stuck at one key part: How do I make it so the sub modules of a project also get the goals from there CC config? I can do the root module fine, and set up the configurations fine as...

Grails validation issue on multi-domain association ?

I need to validate save action between 3 domains, here is relationship : User - JobProcess : one-to-many, JobProcess - Heatmap : one-to-many. User { static hasMany = [ jobs : JobProcess ] ... } JobProcess { static hasMany = [ heatmaps : Heatmap ] ... User script ... } Heatmap { static belongsTo = JobProcess ... JobProcess job ... } I...

What does 'private' mean in Groovy?

The following code sets a private method. So how private really is private? public class Person { private String name } def u = new Person(name:"Ron") println u.name ...

Grails/Groovy: URL params (max, offset) NumberFormatException thrown when blank/strings

in the controller params.max = Math.min(params?.max?.toInteger() ?: 10, 20) params.offset = params?.offset?.toInteger() ?: 0 if you enter in the following urls /books?offset=10&max= //error /books?offset=10&max=sdf //error /books?offset=&max=10 //works /books?offset=adsfa&max=10 //error java....

Groovy: sort hash keys by values value

I want to sort a hash of key->value by the values , and get the list of the sorted keys. This seems to work: groovy> def map = [a:5, b:3, c:6, d:4].sort { a, b -> a.value <=> b.value }.keySet() groovy> println map [b, d, a, c] but will it always work? I don't know if the iterator that builds the keySet() will always iterate the...

Trying to compute age in groovy

I have a date object that holds a persons birthday. My code looks like: def getAge(){ //birthday, birthYear, birthMonth, birthDayOfMonth are class level properties def c= new GregorianCalendar(birthYear, birthMonth-1, birthDayOfMonth) birthday = c.time //What do I do now? } I need to return the age of the person. How...

Domain object referring to a reference table in Grails GORM

I have a domain object called User: class User{ String username; String firstName; String lastName; Zipcode zip; } I also have a Zip Code object: class Zipcode { String zip; String city; String state; Float lat; Float long; } The zipcode table should never be modified as it contains static reference data prepopula...