groovy

jsecurity : how to setup permission from database ?

Hi, I'm using Jsecurity plugins on Grails and I would like to know how to setup permission for each page from the database if possible. it's like to store the following rules: /home/edit/* for Admin /home/* for Users /administrator/* for Admin /menu/* for Admin, Staff Admin etc ... at the moment, we did it in the c...

What function is meant to format/substitute {0} {1} parameters in an string in Grails/Groovy?

I'm just getting started with Groovy/Grails I noticed the error messages you get when you validate a form look like this: Property [{0}] of class [{1}] cannot be blank For example this code to dump the errors to the console s.errors.allErrors.each { println it.defaultMessage } Now, it.arguments ...

Client socket read "freezes"

I want to write a simple web proxy, for exercise. Here's the code I have so far: def g = new Proxy() g.serverPort = 9000 println "starting" g.eachClient { Socket client -> println "got a client" try { client.withStreams { input,output -> String text = input.text println "received $text from clien...

GetOpts for Groovy?

Is there a standard or recommended getopts library for Groovy that will allow me to quickly process long and short command line arguements in Groovy? groovy foo.groovy --fname=foo.txt --output=foo.html --verbose ...

Types of dynamic types in Groovy

Main question: What operators, properties, etc. can be used to determine the type of variables in Groovy? Background: I have an arbitrarily deeply-nested dictionary data structure. It is the result of calling request.JSON in a Grails controller. I would first like to verify certain keys are in the dictionary, with the appropriate types...

How do I insert a record with a many-to-one foreign key with grails?

I've been stuck on this for a day now! I'm just getting started with Grails/Groovy. I have two Domain classes with a simple Many-to-one foreign key. Simplified a bit, they are "Company" class Company { String name String city String state String ticker static constraints = { name(unique:true, maxSize:40) ...

Groovy/Java process management intercept/listen output.

Hello everyone. Groovy has a nice process execution engine and I'd like to use it. There is a method consumeProcessOutput that does all the necessary work. But what I want is to inject my additional functionality every time when consumeProcessOutput call append or something on the out instance. public class ProcessExecutor { static p...

calculate frequency on certain range

Hi, I have maths problem ... (at the moment i solved it using manual iteration which is pretty slow) ... For example if an employee got paid weekly (it can be fortnightly / every 2 weeks and monthly) with certain date (let's call the employee got paid every tuesday and for monthly the employee paid on certain date). I have date range...

Java and JVM confusion (if Java can handle a large string why can't groovy?)

I recently ran into an issue with Groovy where I was attempting to deal with a very large string (100k characters). I got an error that said the string could not be more than 65,535 characters. I did some searches to try to find out more info and ran across this link that said the problem was with the JVM - http://jira.codehaus.org/bro...

How can I intercept this constructor call in Groovy?

In a script a method receives a parameter of type File, and sends it to the constructor of File. This blows up because File doesn't have a constructor that takes another file as a parameter. How can I intercept this call, and modify the parameter to parameter.absolutePath ? For example : def x = new File("some_file") ... def meth(de...

Grails filter syntax, or, How to call a Grails Filter outside Grails

Grails provides filters that run before your controllers. They're defined in classes that look like this: class SecurityFilters { def filters = { myFilter(controller:'*', action:'*') { // What are those weird colons?? print "I'm filtering!" // Code that does the filtering goes here } } } These...

Please help me figure out what's wrong with this web proxy code

I want to write a web proxy for exercise, and this is the code I have so far: // returns a map that contains the port and the host def parseHostAndPort(String data) { def objMap // this has host and port as keys data.eachLine { line -> if(line =~ /^(?i)get|put|post|head|trace|delete/) { println line ...

Has groovy an include mechanism?

We are searching for an include mechanism for groovy scripts to have space for cross-cutting-concerns. In my example we have, web service endpoints as groovy scripts and want to log to our web service protocol. for that we use our implicit object (getting from our framework) to create the logging statement. But this is boilerplate code...

Groovy type conversion

Hi, In Groovy you can do surprising type conversions using either the as operator or the asType method. Examples include Short s = new Integer(6) as Short List collection = new HashSet().asType(List) I'm surprised that I can convert from an Integer to a Short and from a Set to a List, because there is no "is a" relationship between t...

How do I get access to domain objects from a Quartz job?

What would be the best way to go about doing this? ...

maven groovy stub generation

I'm using the GMAven plugin to create Java stubs which successfully compiles my project (Java code that references Groovy). After the stubs have generated I create an Eclipse project (mvn eclipse:eclipse) but the stubs are included on the classpath so rather than my Groovy getting executed (when debugging in Eclipse) the Java stubs are ...

SwingBuilder: scrollPane

Hi, What's the proper way to set up a scroll pane using groovy's SwingBuilder? I'm using griffon and I'm having a hard time adding and removing components dynamically... Here's a snippet I've tried within SwingPad. It works ok, but the remove only take immediate effect if my scroll pane has scrollbars. If not, it takes 4-5 secs. Here'...

Sorting a referenced list in grails

Lets say I have some simple classes for a twitter-like app: User Post A user hasMany posts, and a post belongsTo a user. Now, I'm trying to get a list of posts for a specific user in order of date. I know I can get a list of all posts (for all users) by: def posts = Post.list([sort: 'dateCreated', order: 'asc', max:10]) But to l...

Groovy equivalent to Python's exec statement?

In Python I can execute arbitrary code using exec(string). How can I do this in Groovy? I'd like the code to execute in the context of my currently running application, not as if I were using the Groovy shell. ...

[grails] how to create dummy data for unit test ?

Hi, I need to insert dummy data on test environtment so that I can run unit test on it but I don't know how to declare it on BootStrap (just for testing, not for all environtment) can you help me ? thank you in advance ...