groovy

[Grails] HibernateException: No session currently bound to execution context

I'm trying to create a very basic REST-ish web service with Grails and Postgres. I have the read() & delete() methods working, but I can't get create() to work. Hibernate just gripes, "HibernateException: No session currently bound to execution context." Here's my create method: def create = { def member = new Member(params) member....

How to execute functions in gstring database queries for groovy

I am hoping to use Groovy more as a functional language than I can with Java, but one area that seems to be a problem is when I call to a stored procedure, as I am passing perhaps 40 parameters in a single call, but, I also need to do some prep work, at the moment before I even call. So, for example, I need a time stamp, so I will have ...

Grails: write BufferedImage into response

Hi. I have ImageController with resize method: def resize = { def pht = Photos.findByTypeAndPhotourl(params.type, params.photourl) if (pht != null) { BufferedImage source = ImageIO.read(new File(pht.photo)) ImageResizer imageResizer = new ImageResizer() BufferedImage result = imageResizer.resize(source, Intege...

how to use execute() in groovy to run any command

I usually build my project using these two commands from command line (dos) G:\> cd c: C:\> cd c:\my\directory\where\ant\exists C:\my\directory\where\ant\exists> ant -Mysystem ... ..... build successful What If I want to do the above from groovy instead? groovy has execute() method but following does not work for me: def cd_command =...

how to run existing ant script from groovy

my build is a 3 step process. run ant to build. transfer war to server. touch reload file. I have transfered last two steps in groovy, using antbuilder. However, I am not able to run my existing ant script using groovy. Usually I run it using the following command in dos prompt: ant -Dsystem=mysystem -DsomeotherOption=true from g...

Straight Java/Groovy versus ETL tool (Talend/etc) - what libraries would you use?

Assume you have a small project which on the surface looks like a good match for an ETL tool like Talend. But assume further, that you have never used Talend and furthermore, you do not trust "visual programming" tools in general and would rather code everything the old fashioned way (text on a nice IDE!) with the help of an appropriate...

Result set mapping in Grails / GORM

I want to map the result of a native SQL query to a simple bean in grails, similar to what the @SqlResultSetMapping annotation does. For example, given a query select x.foo, y.bar, z.baz from //etc... map the result to class FooBarBaz { String foo String bar String baz } Can anyone provide an example of how to do this in grai...

how to find if groovy args contains a particular string

println args println args.size() println args.each{arg-> println arg} println args.class if (args.contains("Hello")) println "Found Hello" when ran give following error: [hello, somethingelse] 2 hello somethingelse [hello, somethingelse] class [Ljava.lang.String; Caught: groovy.lang.MissingMethodException: No signature of meth...

soapUI assertion where value is groovy reserved word

I have a response that contains the following: <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"&gt; <env:Header/> <env:Body> <project:loginResponse xmlns:project="http://project.somewhere.com/"&gt; <return>34715527grsbN3C</return> </project:loginResponse> </env:Body> </env:Envelope> I n...

Using groovy ws with enum types?

I'm trying to use groovy ws to call a webservice. One of the properties of the generated class is it's self a class with an enum type. Although the debug messages show that the com.test.FinalActionType is created at runtime when the WSDL is read I can't create an instance of it using code like proxy.create("com.test.FinalActionType") ...

How to get generate WSDL using GroovyWS

I am implementing SOAP web services for a commercial application, and I am using GroovyWS to speed up the development. But, when I deploy it on Tomcat, I am not using Grails, as the software has it's own J2EE framework, so how I do I get it to react to wsdl requests? Do I need to write a groovy-based servlet? Ideally I would like the...

Testing URLs in groovy

Hi all, How can we check whether urls are working or not in groovy? when we click a button, i will get all the urls from existing db from 'urls' table and need to check which url is working Ex: http://baldwinfilter.com/products/start.html - not working http://www.subaru.com/ - working and so many urls from db. My aim is to get all ur...

Is it possible to replace groovy method for existing object?

The following code tried to replace an existing method in a Groovy class: class A { void abc() { println "original" } } x= new A() x.abc() A.metaClass.abc={-> println "new" } x.abc() A.metaClass.methods.findAll{it.name=="abc"}.each { println "Method $it"} new A().abc() And it results in the following output: original or...

Is there an easier way to get start of current day time than this?

I basically want to get zero or beginning hour for currrent day. def today = Calendar.instance today.set(Calendar.HOUR_OF_DAY, 0) today.set(Calendar.MINUTE, 0) today.set(Calendar.SECOND, 0) println today // Mon Mar 15 00:00:00 SGT 2010 ...

attaching multiple files to a domain class

I've seen various Grails plugins which allow easier handling of file uploads, however these tend only to support a single file per form-submit. I'd like a multi-attach form where as soon as you pick one file, an extra field and button is added using JS (various sites do it like this). Do you know of any good plugins which provide elega...

How to search an inner class?

I have these classes. class Author{ Person person } class Person{ String lastName String firstName String middleName } I'd like to query Person and Author. def persons = Person.findAllByLastNameiLike("${a}") but it seems I can't do def authors = Author.findAllByPerson(persons) Any ideas how I'd do this? ...

Scriptom (groovy) leaves Excel process running - am I doing something wrong?

I am using the Scriptom extension to Groovy 1.7.0 to automate some processing using Excel 2007 under Windows XP. This always seems to leave an Excel process running despite my calling quit on the excel activeX object. (There is a passing reference to this phenomenon in the Scriptom example documentation too.) Code looks like: import ...

LBoard; class not found, try compiling it explicitly

Original Question: I am getting the following error when attempting to compile my Groovy project with IntelliJ Groovyc error: LBoard; class not found, try compiling it explicitly However I am unsure of what I need to do to stop this error from happening. The project was working fine but then I tidied up a fair bit of code and t...

Java/Groovy File IO Replacing an Image File with it's own Contents - Why Does This Work?

I have some JPG files that need to be replaced at runtime with a JFIF standardized version of themselves (we are using a vendor that gives us JPG that do not have proper headers so they don't work in certain applications)... I am able to create a new file from the existing image, then get a buffered image from that file and write the con...

Access Relationship Table in Grails

Hi, I have the following domains classes: class Posts{ String Name String Country static hasMany = [tags:Tags] static constraints = { } } class Tags{ String Name static belongsTo = Posts static hasMany = [posts:Posts] static constraints = { } String toString() { "${...