yUML is only for simple UML class diagrams

I sat down for a while and extended the Grails Create Domain UML Plugin that I wrote about a couple month ago in this post. This plugin helps to generate UML class diagrams with yUML from a Grails domain model. Unfortunately the diagrams don’t show aggregations or compositions and the associations don’t have a name. I fixed that, but the generated diagrams are not really useable, because yUML is only for very simple UML class diagrams as you can see in the following pictures.

Neat top down

Neat left right

Conclusion: yUML looks nice, but is only usable for very simple diagrams.

Remove user from cache in Grails app using Acegi Plugin

The Grails Acegi Plugin has user caching activated by default. If you make any changes to a user those changes won’t be available immediately. Here are two solutions to change this behavior.

Remove the user from cache

The Acegi plugin provides a userCache bean which can be injected automatically. With a removeUserFromCache method call on the userCache bean a user can be removed from the cache.  The next time the user is requested by the system the user will be retrieved from the database and all updates to the instance are available immediately. Following code fragment shows the described solution.

def userCache

def someAction = {
	GrailsUser user = authenticateService.principal() as GrailsUser
	userCache.removeUserFromCache(user)
}

Disable the cache

The second solution is to simply disable the cache. This should not have any impact on applications with little usage. This of cause increases the communication between your application and a database server. To disable the cache add the following line of code to the <app-root>/grails-app/conf/SecurityConfig.groovy file.

cacheUsers = false

Disable Ehcaches UpdateChecker in Grails application

I found it pretty annoying that Ehcache always reminded me that there is an update to a newer version of its framework available. After searching the web I found an interesting thread in the Terracotta forum saying that the UpdateChecker is not only looking for updates. In addition it also submits information about the applications environment to Terracotta by default. And that is not a good thing in my opinion.

Here you can see youself: http://svn.terracotta.org/svn/ehcache/tags/ehcache-1.7.1/core/src/main/java/net/sf/ehcache/util/UpdateChecker.java

Fortunately you can disable this behavior by adding an Ehcache configuration to your Grails application. I have tested this with a Grails 1.2.0 application which includes Ehcache 1.7.1.

Simply place an ehcache.xml file in your <app-root>/grails-app/conf folder containing your Ehcache configuration. For this post I am using the configuration that ships with Ehcache as default (ehcache-failsafe.xml) and modify it.

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false">

    <diskStore path="java.io.tmpdir"/>

    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />

</ehcache>

With the attribute updateCheck=”false” in the root tag the haunting is gone.

XML Schema for Ehcache config can be found here: http://ehcache.org/ehcache.xsd

More Information about Ehcache configuration: http://ehcache.org/documentation/configuration.html

Generating UML class diagrams from Grails domain model

Today I tried some Grails plugins that generate UML class diagrams from the existing domain model in an Grails application. I found the following two plugins in the offical Grails plugin repository to play with.

The application I used is a small book management app that manages a couple hundred books at my workplace.

Continue reading

Using storeXPath() in your Grails Webtest

Today I had to figure out how to save some content from a site during a running Webtest so that I am able to restore all changed data afterwards. Luckily Webtest provides the step storeXPath() which does the job.

But it was not that easy to realize my task due to the lack of good documentation and finding the correct xpath expression.

The following code snippet grabs the text value from a text input field with the id surname and saves it in the ant property xyz.

def testSomething() {
   webtest('Some description') {

      // saving initial value
      storeXPath(xpath: "id('surname')/@value", property: "xyz")

      // restore initial value
      setInputField(name: "surname", value: "#{xyz}")

   }
}

Pretty simple in the end, but it took a while till I got it. Maybe it helps someone.