groovy

Null Safe dereferencing in Java like ?. in Groovy using Maybe monad

I'm working on a codebase ported from Objective C to Java. There are several usages of method chaining without nullchecks dog.collar().tag().name() I was looking for something similar to safe-dereferencing operator ?. in Groovy instead of having nullchecks dog.collar?.tag?.name This led to Maybe monad to have the notion of Nothing ...

How to upload a directory via Grails or Java ?

What is the best way to upload a directory in grails ? I try this code : def upload = { if(request.method == 'POST') { Iterator itr = request.getFileNames(); while(itr.hasNext()) { MultipartFile file = request.getFile(itr.next()); File destination = new File(file.getOriginalFilename()) ...

How can I print directly to printer using jasper reports and grails?

Hi, Can someone please help me. I'm using grails and jasper grails plugin. I would like to send a jasper report directly to the printer from a click on my webpage. Can someone please point me to the right direction? ...

grails metaprogramming

Hi, My understanding is that there are two obvious places in a Grails app where one can do meta-programming: The init closure of Bootstrap.groovy The doWithDynamicMethods closure of a plugin The meta-programming I'm referring to here should be visible throughout the metaprogramming, typical examples include adding (or replacing) met...

Running single integration test quickly in Grails

Is it possible to quickly run single/all integration test in a class quickly in Grails. The test-app comes with heavy baggage of clearing of all compiled files and generating cobertura reports hence even if we run single integration test, the entire code base is compiled,instrumented and the cobertura report is getting generated. For our...

groovy regexpression

Hi, How to get file name from these lines using groovy . File file = new File(SOURCE_FILE_NAME).eachLine{line-> println line } getting line like this : /usr/local/ /usr/local/testing.groovy /usr/local/picture.jpg expecting output: testing.groovy picture.jpg thanks ...

Translation of a RoR view to Java

Hi, for some reasons I am trying to translate the following RoR view code to a GSP view: List<Object> objectscontains the data I want to display in 3 columns <% modulo_objects = @objects.length % 3 base = @objects.length / 3 base = base.ceil case modulo_objects when 0 cols = [base, base, base] when 1 cols = [base, base + 1, base...

Grails , how do I get an object NOT to save

Hello I am new to grails and trying to create a form which allows a user to change the email address associated with his/her account for a site I am creating. It asks for the user for their current password and also for the new email address they want to use. If the user enters the wrong password or an invalid email address then it sho...

groovy bash command

I need to run this command in Groovy when click on button bash copy.txt > copy.log I tried with execute but not worked out . Could any one please help me thanks in advance sri.. ...

g:countrySelect with full country name as value

I want to store the exact country name using g:countrySelect. Example Germany instead of DEU. It is the value in the drop down menu. The drop down text is Germany but when it saves it to the database it changes back to the country code. Sorry if I am somewhat naive but I have been searching for almost 3 hours for solutions and it isn...

How to copy a subset from an array of strings to an array of ints using Groovy?

I have a String array in a Groovy class (args to a main method): String[] args I'd like to convert the 3rd to the last element into a new array of ints. Is there an easier way to do this in Groovy other than: final int numInts = args.length - 2 final int [] intArray = new int[numInts] for (int i = 2; i < args.length; i++) { intA...

How to parallelize this groovy code?

I'm trying to write a reusable component in Groovy to easily shoot off emails from some of our Java applications. I would like to pass it a List, where Email is just a POJO(POGO?) with some email info. I'd like it to be multithreaded, at least running all the email logic in a second thread, or make one thread per email. I am really ...

Grails UrlMappings with .html

I'm developing a Grails web application (mainly as a learning exercise). I have previously written some standard Grails apps, but in this case I wanted to try creating a controller that would intercept all requests (including static html) of the form: <a href="/testApp/testJsp.jsp">test 1</a> <a href="/testApp/testGsp.gsp">test 2</a> ...

Adding business logic to a domain class using a getter style method name

I'm attempting to add a method to a grails domain class, e.g. class Item { String name String getReversedName() { name.reverse() } } When I attempt to load the application using grails console I get the following error: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '...

grails mockFor closure wierdness

Right, so when I set up my mock using the testing plugin's mockFor method, I expect a method that returns null. If I do myControl.demand.theMethod {return null} in the debugger, the value that I set the 'theMethod' call result to is some closure in the debugger. If I do myControl.demand.theMethod {->return null} the value is null...

How to Parse multiple classes from groovy file

Is there a way to parse all all the classes in a groovy script? To Parse ONE clase right now: java.lang.Class clazz = groovyClassLoader.parseClass(new File("MainApp.groovy")) MainApp.groovy: class MainApp { def doIt() {} } class OtherMainApp { def doTheRest() {} } This will return only MainApp. I would like something like this:...

How to remove adornments like [exec] when using groovy's AntBuilder

Hi! I'm using Groovy's AntBuilder to execute Ant tasks: def ant = new AntBuilder() ant.sequential { ant.exec(executable: "cmd", dir: "..", resultproperty: "exec-ret-code") { arg(value: "/c") arg(line: "dir") } } The output lines are prefixed by: [exec] Using Ant on the command line, this is turned off by "em...

Building json from folder structure and vice versa

Hi, I'm trying to generate a json representation from a folder structure. Examplee folder/file structure: folder |_ meta.xml |_ subdir1 |_ textfile1.txt |_ subdir2 |_ textfile2.txt Manually generate the json representation of this structure: def builder = new net.sf.json.groovy.JsonGroovyBuilder() def json = builder.dir { ...

Groovy built-in to split an array into equal sized subarrays?

If I have this: def array = [1,2,3,4,5,6] Is there some built-in which allows me to do this ( or something similar ): array.split(2) and get: [[1,2],[3,4],[5,6]] ? ...

Working with the Grails g:timeZoneSelect tag?

I am wanting to use the g:timeZoneSelect tag within my application, problem is im finding the resulting html select to be quite overwhelming. Over 600 options are being displayed, IMHO this is to much to display to the user. Maybe someone could point me to an example of a much more manageable list of timezones? Maybe you have seen a si...