groovy

How to define factory methods in Groovy/Grails ?

I buid a factory in groovy, this code works, but I think, this code can be improved (or reduced) : abstract class Processing { abstract getDirName(); abstract getFileType(); abstract moveFile(); abstract processFile(); abstract openFile(); abstract closeFile(); } class ProcessingBuilder { def process...

recursion in groovy (grails)

Hello, I am trying to use recursion in groovy to traverse a tree relationship. The below code runs one cycle, upto childNodes && recurClosure(childNodes ) , but doesn't call the closure recurClosure again. At that instant childNodes had two objects (array list) same type as root. In the code, recurClosure is defined and calls with ...

regex in groovy

I need to remove "" from the both ends of the line "/home/srinath/junk/backup" and to display like this /home/srinath/junk/backup How can we achieve this in groovy ? thanks in advance, sri.. ...

shell command in groovy

How to run this command in groovy : /home/srinath/junk/sync.sh > /home/srinath/junk/copy.log This is working when tried on terminal . but fails when used execute in groovy Could any one please help me on this . thanks in advance sri.. ...

Groovy/Grails: How do I make my datePicker blank or null by default instead of showing today's date?

That is basically my question. It is showing me today's date and not a blank or null or '' date, even if I put null or '' it runs perfectly but keeps showing me today's date, not a blank dropdown box. So I want to change the default to being blank when the gsp loads, not with today's date. Thanks -Fernando ...

Grails: Edit and Delete links not working

Hi, I created an extra column and added icons at the end of the list for editing and deleting an event. Here is what I have <g:form value="${it.id}"> <g:hiddenField name="id" value="${it.id}" /> <span class="simple"><g:actionSubmit class="editar" action="edit" value="${message(c...

GORM inheritance issue

I'm blocked on this GORM inheritance problem I have and id appreciate some fresh eyes to have a look over this problem. (Im using Grails 1.3.2) I have a base abstract class... abstract class MaintenanceSchedule { static belongsTo = [ maintenanceTask:MaintenanceTask ] } and I want to extend it like so... class OneOffSchedule exte...

Why does this Java/Groovy code cause heap memory exceptions?

Hi, This 3rd party script keeps causing heap memory exceptions: byte[] forwardMessage(byte[] content) { s = new Socket("172.17.0.30", 10001); s.withStreams {InputStream input, OutputStream output -> output.write content return readRtsData(input) } } byte[] readRtsData(input) { def vplEndByte = 0xff ...

Grails - how to convert the text in an input field into a java date object using a taglib

I am trying to design my own custom set of tags using grails and i am having problems converting my date text into a Date object using the grails taglib. I have only succeeded in rendering already existing dates into a chosen format, but when i try to change the date and save it again, i run into problems ...

Is it possible to automatically preload user classes into the groovy interpreter?

Is there any way to automatically load user classes in the groovy interpreter, the way System.out is automatically loaded (so you don't have to import System.out to use println)? I want to be able to write scripts that employ custom classes and run the scripts in the groovy interpreter without having to import all the classes all the ti...

How do I keep a line number count when using reader.eachLine to read a BufferedInputStream?

How can I keep track of the line number I'm on when using eachLine to read a BufferedInputStream? def input = new GZIPInputStream(new FileInputStream(f)) def reader = new BufferedReader(new InputStreamReader(input)) reader.eachLine { line ->if(line.contains(searchString)){ println "${f} - ${line}" } } ...

Anyone got the Sonar CodeNarc plugin working?

I'm wondering how the development of this plugin is going? I've tried to build the plugin from source (https://svn.codehaus.org/sonar-plugins/trunk/groovyGMNarc) but get get it running within my project. I can install the plugin on Sonar but it fails to run against my Maven project. I get the following error [INFO] [sonar-core:internal...

Load snippet of html in controller

I would like to have a snippet html loaded in the action method of a controller. Is there a way to do this? What I want to accomplish is actually have the Controller action use json as the format to return my response (with error codes and other information) and include a snippet of html loaded from a template file as one part of the js...

getting random records in many-to-many relationship with namedQuery

I have a many-to-many relationship between two objects with a join table. I need to be able to select 5 random children based on Parent and date, excluding some children records. I am stuck. Any ideas? Parent { static hasMany = [children: Child] } Child { Date dob static belongsTo = [Parent] static ha...

Error with two byte UTF-8 character in UPDATE statement for MySQL database

An update-statement seems to work only with one or three byte long UTF-8 characters. My test code def sql = sql.newInstance('jdbc:mysql://.../...?useUnicode=true&characterEncoding=UTF-8', '...', '...', 'com.mysql.jdbc.Driver') String value = 'β' sql.execute('UPDATE Kldb_SynonymVersion SET synonyms=? WHERE id=11940', [value]...

Grails - access only for object's owner

Hi! I'm still working on my first Grails application. This time, my problem is to limit access to some actions for particular users. Assume users add some object, e.g. books. I would like to give access to edit a book only to admin and the user that added the book. I'm currently using Acegi plugin. I know there is newer version of that...

Split collection into sub collections in Groovy

I have an array containing an unknown number of items that I would like to split into separate arrays so that each separate array contains no more than 4 items. What is the best way to do this in Groovy? Thanks! ...

Grails: How do I make my page load a filter when the page loads??

On index.gsp I have this to redirect it to list.gsp so I'm imagining is should be something like this: ${response.sendRedirect("entry/list")} My filter is just one textField and two datePickers with drop down boxes (DD-MMM-YYYY) and they should be by default filtered from today's date to infinity. So it should show me only the events ...

Using UTL_FILE to pull data from an Oracle server to a local file system using JDBC?

I need to consume a file that is being generated on an Oracle server and I have been told to get it using the UTL_FILE package. I intend on consuming the file in a groovy script and have a connection to the database. It is a simple text file and I'd like to pull it down to the server and consume it as I would any other text file but I ...

Groovy XmlUtil.serialze() is throwing a 'Content is not allowed in prolog' error when trying to serialize a GPathResult

Hi all, I've encountered a strange issue with Groovy's (1.7.3) XmlUtil.serialize( GPathResult ) method. It throws a 'Content is not allowed in prolog' error when I call it with a GPathResult, but groovy.util.Node is serializing just fine. Here is the very simple Groovy Script I am trying: import groovy.xml.XmlUtil import groovy.xml....