<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sword Systems &#187; grails</title>
	<atom:link href="http://swordsystems.com/category/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://swordsystems.com</link>
	<description>Cutting Commentary</description>
	<lastBuildDate>Tue, 15 Jun 2010 13:07:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Validation differences between Grails 1.1 and 1.2</title>
		<link>http://swordsystems.com/2010/06/09/validation-differences-between-grails-1-1-and-1-2/</link>
		<comments>http://swordsystems.com/2010/06/09/validation-differences-between-grails-1-1-and-1-2/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 18:34:44 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[frustration]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=65</guid>
		<description><![CDATA[&#8230;or My Penance For Ignoring Validation Errors&#8230;
We recently updated our app from Grails 1.1.1 to 1.2.2.  (We wanted to move all the way to 1.3.1 but since we build with maven, we finally decided to wait until a new grails-maven plugin is released.  See GRAILS-6327.)  During the upgrade, we hit two particularly [...]]]></description>
			<content:encoded><![CDATA[<h2>&#8230;or My Penance For Ignoring Validation Errors&#8230;</h2>
<p>We recently updated our app from Grails 1.1.1 to 1.2.2.  (We wanted to move all the way to 1.3.1 but since we build with maven, we finally decided to wait until a new grails-maven plugin is released.  See <a href="http://jira.codehaus.org/browse/GRAILS-6327">GRAILS-6327</a>.)  During the upgrade, we hit two particularly annoying issues related to persistence and setting up associations.  </p>
<p>The first involved a <code>belongsTo</code> relation like this:</p>
<pre class="brush: groovy;">class AppUser {
    UserPrefs prefs = new UserPrefs()
}

class UserPrefs {
    static belongsTo = [user: AppUser]
}
</pre>
<p>This worked under Grails 1.1, but under Grails 1.2 the prefs object was not getting persisted when the user was saved.  Other <code>belongsTo</code> relations, both one-to-many and one-to-one worked as expected.  We finally discovered that using the short form of the relation notation did work:</p>
<pre class="brush: groovy;">static belongsTo = AppUser
</pre>
<p>This <a href="http://groovyguts.wordpress.com/2009/10/15/why-belongsto-is-important-for-validation/">post</a> provided a clue as to where the problem may be.  The <code>user</code> property of the Prefs object is not automatically set because the relationship is one-to-one.  (At least, it is not automatically set all the time.  If we load an AppUser object with Hibernate, it appears that the user property is set in the UserPrefs object.  Go figure.)  Under Grails 1.1, having a null user was apparently fine.  My guess (based on the second error we hit, below) is that any validation errors caused by the child object were not stopping the save of the parent object.  Grails 1.2, on the other hand, does care about the child object validation, though I could never get it to report anything in the <code>errors</code> property of either the parent or child object.  </p>
<p>In order to work around the issue, I loosened the constraints on <code>UserPrefs</code> a little:</p>
<pre class="brush: groovy;">class UserPrefs {
    static constraints = {
        user(nullable: true)
    }
    static belongsTo = [user: AppUser]
}
</pre>
<p>With this change, cascading persistence works.  Given, it&#8217;s not an ideal solution, but it does let us have access to the <code>user</code> property if needed.</p>
<p>What made this extra confusing is that we have a similar relationship in another set of classes that worked without a problem.  The only difference there is that the child class is not automatically created with a static initializer as is done in for the <code>prefs</code> property in <code>AppUser</code>.  It is always explicitly set into the owning object.  I&#8217;ve run out of time to pursue this one further, so I don&#8217;t have a final answer.  Anyone else out there have more insight into this?</p>
<p>The second persistence issue related to this section of code in the update method of one of our controllers:</p>
<pre class="brush: groovy;">def update = {
    def hubMap = HubMap.get(params.id);
    hubMap.properties = params;
    if (hubMap.save()) {
        ...add success message to response...
    } else {
        ...add failure message to response...
    }
    ...
}
</pre>
<p>Again, the code worked fine under Grails 1.1.1, but the save call failed under 1.2.2.  Unfortunately, there was a hole in both our unit and integration tests for this method, so we didn&#8217;t catch it until much later in the release cycle.</p>
<p>Was the JSON conversion in the controller&#8217;s <code>get</code> method that generated the original data for the browser different?   Nope.<br />
Had the behaviour of the <code>properties</code> meta-method changed?  Nope.</p>
<p>The difference is in how Grails handles any existing validation errors on a domain object when you call <code>save()</code>.  In our case, the JSON that was being sent to the controller (via a Prototype AJAX call) contained two properties that were references to other objects.  The javascript object conversion in the browser was not setting these properties in a meaningful way for the AJAX call; they were both coming across with the string value <code>[object Object]</code>.  Since these fields are never updated in this particular workflow, we had never checked what was happening to them.  Grails obviously could not convert from the string values to the proper objects, it ignored the values and set two errors on the domain object to record them.  However, we didn&#8217;t check for errors after the <code>properties</code> call.  We went straight to the <code>save</code> call. Under Grails 1.1, deep within the saving sequence in a random class called <code>AbstractDynamicPersistentMethod</code>, you come across this bit of code:</p>
<pre class="brush: groovy;">doInvokeInternal(...) {
    ...
    Errors errors = new BeanPropertyBindingResult(target, target.getClass().getName());
    mc.setProperty(target, ERRORS_PROPERTY, errors);
    ...
}
</pre>
<p>Any existing errors are replaced with a fresh, clean <code>BeanPropertyBindingResult</code> object, wiping out the error information.  We never spotted it because we never expected the properties with errors to change anyway.  That hole has been closed in Grails 1.2:</p>
<pre class="brush: groovy;">doInvokeInternal(...) {
    ...
    Errors errors = setupErrorsProperty(target);
    ...
}
</pre>
<p>The new <code>setupErrorsProperty</code> call will copy out existing errors.  We put in a few adjustments to not attempt to update those properties and all is well.</p>
<p>So there you have it.  A couple of gotchas in the upgrade path for grails.  Hope this saves some folks from banging their head against the wall.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2010/06/09/validation-differences-between-grails-1-1-and-1-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails, Maven, packaging, and skipTests fun</title>
		<link>http://swordsystems.com/2010/04/22/grails-maven-packaging-and-skiptests-fun/</link>
		<comments>http://swordsystems.com/2010/04/22/grails-maven-packaging-and-skiptests-fun/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 16:25:55 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[frustration]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=62</guid>
		<description><![CDATA[The grails maven plugin honors the maven.test.skip option (which turns off compiling and executing tests), but not the skipTests option (which only turns off executing tests).  This means that you cannot easily create a package with test classes in it without running all of the tests.  I finally come up with a close [...]]]></description>
			<content:encoded><![CDATA[<p>The grails maven plugin honors the <code>maven.test.skip</code> option (which turns off compiling and executing tests), but not the <code>skipTests</code> option (which only turns off executing tests).  This means that you cannot easily create a package with test classes in it without running all of the tests.  I finally come up with a close work around:<br />
<code><br />
mvn clean grails:exec install -Dcommand=test-app -Dargs="-unit DoesNotExist" -Dmaven.test.skip=true<br />
</code><br />
By explicitly listing the <code>test-app</code> command but specifying a test that does not exist, I was able to get the unit tests to be compiled.  Since I only needed some common testing files in my package, this works for me.  If someone wanted to package both the unit and integration tests, I don&#8217;t think this would work.  I filed a new issue in the <a href="http://jira.codehaus.org/browse/GRAILS-6188">Grails Jira</a> to try to get a real resolution.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2010/04/22/grails-maven-packaging-and-skiptests-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grails+Maven+GeoTools+PdfBox = PITA</title>
		<link>http://swordsystems.com/2010/03/20/grailsmavengeotoolspdfbox-pita/</link>
		<comments>http://swordsystems.com/2010/03/20/grailsmavengeotoolspdfbox-pita/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 20:35:27 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[frustration]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[geotools]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[pdfbox]]></category>
		<category><![CDATA[xml-api]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=54</guid>
		<description><![CDATA[Overcoming link errors related to XML libraries when using GeoTools and PdfBox]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a bit of maven-voodoo for you.  If you have a Grails (1.1.1) app that is built with Maven (2.1) and you try to link in GeoTools (specifically the gt-xsd-core module) and you try to bring in PdfBox as well, you will get really fascinating class loading and linking problems revolving around various XML pieces.  I finally found two different ways to get rid of the errors.  For those who like to cut to the chase, I&#8217;ll list the solutions first and then explain a bit more what errors I was seeing.</p>
<h3>Solution #1: Exclude, exclude, exclude</h3>
<p>If you don&#8217;t need commons-jxpath, you can add these three exclusions to the gt-xsd-core dependency declaration.</p>
<pre>    &lt;dependency&gt;
        &lt;groupId&gt;org.geotools.xsd&lt;/groupId&gt;
        &lt;artifactId&gt;gt-xsd-core&lt;/artifactId&gt;
        &lt;version&gt;${gt.version}&lt;/version&gt;
        &lt;exclusions&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;commons-jxpath&lt;/groupId&gt;
                &lt;artifactId&gt;commons-jxpath&lt;/artifactId&gt;
            &lt;/exclusion&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;xml-apis&lt;/groupId&gt;
                &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
            &lt;/exclusion&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;xml-apis&lt;/groupId&gt;
                &lt;artifactId&gt;xml-apis-xerces&lt;/artifactId&gt;
            &lt;/exclusion&gt;
        &lt;/exclusions&gt;
    &lt;/dependency&gt;</pre>
<p>This at least works for me given the subset of geotools functionality I am using (primarily encoding and parsing OGC Filter objects to and from XML so I can persist them with Hibernate).  It is still pulling in xercesImpl and that appears to be enough, at least to get my unit and integration tests working.</p>
<h3>Solution #2: Using Dependency Management</h3>
<p>If you need the commons-jxpath functionality in gt-xsd-core, add this to your dependencyManagement section of your POM:</p>
<pre>    &lt;dependencyManagement&gt;
        &lt;dependencies&gt;
            &lt;!-- The gt-xsd-core tries to bring commons-jxpath 1.2 in.  That messes up the maven junitreport plugin for
            some reason (like links to a version of xalan or xml-apis or something.  The 1.3 version doesn't have that
            issue. --&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;commons-jxpath&lt;/groupId&gt;
                &lt;artifactId&gt;commons-jxpath&lt;/artifactId&gt;
                &lt;version&gt;1.3&lt;/version&gt;
            &lt;/dependency&gt;
        &lt;/dependencies&gt;
    &lt;/dependencyManagement&gt;</pre>
<p>and then keep the exclusions for the xml-api artifacts as above:</p>
<pre>    &lt;dependency&gt;
        &lt;groupId&gt;org.geotools.xsd&lt;/groupId&gt;
        &lt;artifactId&gt;gt-xsd-core&lt;/artifactId&gt;
        &lt;version&gt;${gt.version}&lt;/version&gt;
        &lt;exclusions&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;xml-apis&lt;/groupId&gt;
                &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
            &lt;/exclusion&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;xml-apis&lt;/groupId&gt;
                &lt;artifactId&gt;xml-apis-xerces&lt;/artifactId&gt;
            &lt;/exclusion&gt;
        &lt;/exclusions&gt;
    &lt;/dependency&gt;</pre>
<p>This is what I have setup in my POM right now because I think I might need jxpath soon.  I also tried adding a node in dependency management to use the 1.3.03 version of xml-apis rather than 1.0b2 (which is what was pulled in by default), but that doesn&#8217;t appear to make any difference.  I still had to have the 2 exclusions under gt-xsd-core for things to work.</p>
<h2>So what was the problem?</h2>
<p>Now, a little more about the problems I had.  I had two types of errors:</p>
<p><strong>Maven junitreport conflict</strong> &#8211; When I added the dependency for gt-xsd-core and then ran my unit tests using the maven grails plugin (<code>mvn grails:exec -Dcommand=test-app -Dargs="-unit"</code>), my tests would run fine (except for one which I&#8217;ll detail below), but then I would get this error when the junitreport plugin tried to run its XSL transform:</p>
<p><code>Embedded error: java.lang.reflect.InvocationTargetException<br />
Provider org.apache.xalan.processor.TransformerFactoryImpl not found</code></p>
<p>Normally I would suspect that the geotools dependencies brought in some new version of the xalan library and it didn&#8217;t have an old class that the junitreport plugin required.  To check this, I compared the output from both maven dependency:classpath and dependency:tree between my trunk branch and the branch where I had added the geotools dependencies.  The comparision showed that only one one dependency had changed between the branches; a newer version of commons-pool was used.  All other classpath mods were new libraries that were not previously included at all.  In fact, xerces and xalan was not included by the trunk branch at all.  I am sure that someone with more recent experiences with xml-apis, xerces, and xalan knows exactly what was happening.  My guess is that by including the xml-apis-xerces dependency, some piece of the junitreport plugin thought that it could use xalan as opposed to some other XSL lib that it would use when xerces was not present.  This is supported by the fact that if I added xalan as a dependency, the error went away.  If I have time, I&#8217;ll look at the docs for junitreport one of these days and see if that sheds some light on the issue.</p>
<p><strong>PDFImageWriter/NodeList conflict</strong> &#8211; One of the unit tests exercised our use of PDFBox.  If I did not have the above exclusions and I include xalan, this error appeared during the PDFImageWriter constructor:</p>
<p><code>java.lang.LinkageError: loader constraint violation: loader (instance<br />
of &lt;bootloader&gt;) previously initiated loading for a different type with<br />
name "org/w3c/dom/NodeList"</code></p>
<p>I haven&#8217;t tracked down exactly why this linkage conflict occurred.  The bizare thing is that I inserted some link-loading debugging that I used in the past to try to see where NodeList was coming from in both my trunk and geotools-enabled branches:<br />
<code><br />
def clazz =  org.w3c.dom.NodeList.class<br />
def codeSource = clazz.getProtectionDomain().getCodeSource();<br />
println ("Source Location: " + codeSource);<br />
</code></p>
<p>In trunk (i.e. no geotools and working fine), it came back as null; NodeList wasn&#8217;t loaded at all.  In the geotools-enabled branch, it would load (from xerces, I think), but then had that conflict.</p>
<p>At this point, I have a solution (two, actually) and have spend pretty much a whole day researching various paths, so I need to wrap it up and move on.  If anyone has a better solution or thoughts as to why exactly there were problems, feel free to comment.</p>
<p>One last note in case there is any confusion from me mentioning xalan so much &#8211; I did not end up adding a dependency for xalan to my POM.  Just using the exclusion statements listed above solved the issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2010/03/20/grailsmavengeotoolspdfbox-pita/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cruising on other people&#8217;s work</title>
		<link>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/</link>
		<comments>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 14:48:26 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=23</guid>
		<description><![CDATA[I love it when other people do my work for me.  For example, I needed to store a few random settings in a Grails app, such as the last time a service polled an external resource.  So I went to the main Grails Plugin site and, sure enough, someone else has already written a Grails [...]]]></description>
			<content:encoded><![CDATA[<p>I love it when other people do my work for me.  For example, I needed to store a few random settings in a Grails app, such as the last time a service polled an external resource.  So I went to the main <a href="http://grails.org/plugin/category/all" target="_blank">Grails Plugin</a> site and, sure enough, someone else has already written a <a href="http://grails.org/plugin/settings" target="_blank">Grails Settings</a> plugin.  It needs a few enhancements to do what I want, but it&#8217;s better than starting from scratch.  While I was perusing the plugin list, I found a few others that can replace features I had started to sketch out (like <a href="http://grails.org/plugin/taggable" target="_blank">Taggable</a>) and was inspired by yet others that would let me easily add features that I hadn&#8217;t thought of before (like <a href="http://grails.org/plugin/commentable" target="_blank">Commentable </a>and <a href="http://grails.org/plugin/sparkline" target="_blank">Sparkline</a>).</p>
<p>Another example is yet another good <a href=" http://agileice.blogspot.com/2009/09/grails-integration-testing.html" target="_blank">post</a> by my friend and coworker Jeff Erikson detailing his research into problems with Grails config options getting wiped during integration tests.  I had been meaning to write up a note about how the GrailsUnitTestCase class hides the true config settings, so you don&#8217;t want to accidentally use it in integration tests.  Jeff took my little tip a lot farther with his post.  Thanks, Jeff!</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Corrections to Grails Documentation</title>
		<link>http://swordsystems.com/2009/09/05/corrections-to-grails-documentation/</link>
		<comments>http://swordsystems.com/2009/09/05/corrections-to-grails-documentation/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 14:24:44 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[frustration]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[GORM]]></category>
		<category><![CDATA[Persistance]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=20</guid>
		<description><![CDATA[Here are two quick tips for anyone working with Grails 1.1.1:
1) The User Guide has conflicting info about cascading persistence.    Section 5.2.1.2 says &#8220;The default cascading behaviour is to cascade saves and updates, but not deletes unless a belongsTo is also specified.&#8221;  Section 5.3.3 says, &#8220;If you do not define belongsTo then [...]]]></description>
			<content:encoded><![CDATA[<p>Here are two quick tips for anyone working with Grails 1.1.1:</p>
<p>1) The User Guide has conflicting info about cascading persistence.    Section 5.2.1.2 says &#8220;The default cascading behaviour is to cascade saves and updates, but not deletes unless a belongsTo is also specified.&#8221;  Section 5.3.3 says, &#8220;If you do not define belongsTo then no cascades will happen and you will have to manually save each object.&#8221;</p>
<p>The former, 5.2.1.2, is correct.  Create and Update actions are cascaded for one-to-many relations.  However, hey are not cascaded for one-to-one relations.</p>
<p>2) Section 9.1 (Unit Testing) demonstrates how to pass in a list to the mockDomain(clazz, instanceList) call.  It then says that you can check that list to verify that persistence actions behaved as expected.  This is no longer correct.  The list is copied inside the mockDomain call.  To get access to the list of persisted objects for a class, use the MockUtils.TEST_INSTANCES map with the class name as the key.  For example:</p>
<pre>def testInstances = []
mockDomain(Item, testInstances)
def i = new Item(name:"foo").save()
assertEquals 0, testInstances.size()
testInstances = MockUtils.TEST_INSTANCES[Item]
assertEquals 1, testInstances.size()</pre>
<p>And in case you try the same thing as me, the mocking behavior does not support cascades.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/09/05/corrections-to-grails-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importing an existing grails projects into Intellij</title>
		<link>http://swordsystems.com/2009/07/30/importing-an-existing-grails-projects-into-intellij/</link>
		<comments>http://swordsystems.com/2009/07/30/importing-an-existing-grails-projects-into-intellij/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 11:14:00 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Intellij]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[pain]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=16</guid>
		<description><![CDATA[Yesterday I had the fun experience of getting an existing grails project configured in Intellij.  The process required just a few more steps than given in the Intellij documentation, so I added my notes to an existing thread in the Intellij forums on the same topic.  I hope it saves someone else from [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I had the fun experience of getting an existing grails project configured in Intellij.  The process required just a few more steps than given in the Intellij documentation, so I added my notes to an <a href="http://www.jetbrains.net/devnet/message/5242706#5242706">existing thread</a> in the Intellij forums on the same topic.  I hope it saves someone else from denting the wall with their head.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/07/30/importing-an-existing-grails-projects-into-intellij/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
