<?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>The Kaptain on ... stuff &#187; Apache</title>
	<atom:link href="http://www.kellyrob99.com/blog/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kellyrob99.com/blog</link>
	<description>Tales of development, life and the folly that goes along with both</description>
	<lastBuildDate>Sun, 04 Dec 2011 21:51:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Grails-UI DataTable using XML for a model</title>
		<link>http://www.kellyrob99.com/blog/2009/10/25/grails-ui-datatable-using-xml-for-a-model/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=grails-ui-datatable-using-xml-for-a-model</link>
		<comments>http://www.kellyrob99.com/blog/2009/10/25/grails-ui-datatable-using-xml-for-a-model/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 07:06:05 +0000</pubDate>
		<dc:creator>TheKaptain</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Crucible]]></category>
		<category><![CDATA[DataTable]]></category>
		<category><![CDATA[Fisheye]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[google-charts]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[HTTPBuilder]]></category>
		<category><![CDATA[HttpClient]]></category>
		<category><![CDATA[Jira]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTClient]]></category>
		<category><![CDATA[theKaptain]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.kellyrob99.com/blog/?p=836</guid>
		<description><![CDATA[I had a great chance to play with some new stuff this weekend, namely Grails 1.2-M3, the new Grails REST plugin and Groovy in general. Awhile back I wrote some Groovy code to explore the various Jira, Fisheye and Crucible REST api&#8217;s using Apache HttpClient directly, and I wanted to see what it would like [...]
Related posts:<ol>
<li><a href='http://www.kellyrob99.com/blog/2010/06/02/a-grails-app-demoing-the-stackexchange-api/' rel='bookmark' title='A Grails App Demoing the StackExchange API'>A Grails App Demoing the StackExchange API</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/10/24/groovy-reverse-map-sort-done-easy/' rel='bookmark' title='Groovy reverse map sort done easy'>Groovy reverse map sort done easy</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/12/16/jira-grails-plugin/' rel='bookmark' title='Jira Grails Plugin'>Jira Grails Plugin</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I had a great chance to play with some new stuff this weekend, namely <a href="http://grails.org/1.2-M3+Release+Notes">Grails 1.2-M3</a>, the new <a href="http://grails.org/plugin/rest">Grails REST plugin</a> and Groovy in general. Awhile back I wrote some Groovy code to explore the various Jira, Fisheye and Crucible REST api&#8217;s using Apache HttpClient directly, and I wanted to see what it would like abstracted behind <a href="http://groovy.codehaus.org/modules/http-builder/">HTTPBuilder</a>. With the help of the <a href="http://grails.org/GrailsUI+Plugin">Grails-UI</a> and <a href="http://grails.org/plugin/google-chart">Google-charts</a> plugins, I got some pretty nice views of the data as well.</p>
<p>First off, dealing with a RESTful call was about as simple as I&#8217;ve ever seen. This is the entire code that deals with creating the connection, authenticating, executing a GET, and parsing the returned XML into a &#8216;data&#8217; property on the response.</p>
<pre class="brush: groovy; title: ; notranslate">
    private withFisheye(String url, Map args) {
        withRest(uri: url) {
            auth.basic userName, password
            return get(query: args)
        }
    }
</pre>
<p>Getting XML using <a href="http://www.jroller.com/aalmiray/">Andres&#8217;</a> plugin is extremely simple and we can achieve some pretty nice visualizations of the resulting data very easily as well. In particular I wanted to share how to use an XML response as a backing model for DataTable. The excellent examples provided by <a href="http://weblog.dangertree.net/tag/grailsui/">Matthew Taylor on his blog</a> seemed to concentrate on using GORM to load and sort domain objects to utilize as data models. When using XML as an alternative way to represent the data, and using RESTful calls to populate that data, the available sorting options on a DataTable weren&#8217;t able to function properly without a little extra help.</p>
<p>Consider an list of XML elements like this, which represents a single review in Crucible.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;reviewdata&gt;
    &lt;allowreviewerstojoin&gt;false&lt;/allowreviewerstojoin&gt;
    &lt;author&gt;
        &lt;displayname&gt;Kelly Robinson&lt;/displayname&gt;
        &lt;username&gt;TheKaptain&lt;/username&gt;
    &lt;/author&gt;
    &lt;closedate&gt;20010101T00::00.0000000&lt;/closedate&gt;
    &lt;createdate&gt;20010101T00::00.0000000&lt;/createdate&gt;
    &lt;creator&gt;
        &lt;displayname&gt;Kelly Robinson&lt;/displayname&gt;
        &lt;username&gt;TheKaptain&lt;/username&gt;
    &lt;/creator&gt;
    &lt;description&gt;
        Test review
    &lt;/description&gt;
    &lt;moderator&gt;
        &lt;displayname&gt;Kelly Robinson&lt;/displayname&gt;
        &lt;username&gt;TheKaptain&lt;/username&gt;
    &lt;/moderator&gt;
    &lt;name&gt;
        Test review
    &lt;/name&gt;
    &lt;permaid&gt;
        &lt;id&gt;CR1&lt;/id&gt;
    &lt;/permaid&gt;
    &lt;projectkey&gt;CR&lt;/projectkey&gt;
    &lt;state&gt;Closed&lt;/state&gt;
    &lt;summary&gt;
      Test review
    &lt;/summary&gt;
&lt;/reviewdata&gt;
</pre>
<p>You can leverage this list as a DataTable model by extracting specific elements from the XML, and providing a sorting mechanism based on dynamic map value lookups.</p>
<pre class="brush: groovy; title: ; notranslate">
    private def createReviewDataJson(HttpServletResponse response, Map params, reviews) {
        def list = []
        response.setHeader(&quot;Cache-Control&quot;, &quot;no-store&quot;)
       //build a List of Maps, one for each row in the DataTable
        reviews.reviewData.each {
            list &lt;&lt; [
                    id: it.permaId.id.text(),
                    author: it.author.displayName.text(),
                    creator: it.creator.displayName.text(),
                    moderator: it.moderator.displayName.text(),
                    description: it.description.text(),
                    state: it.state.text()
            ]
        }
       //sort by the 'order' and 'sort' parameters passed in by DataTable
        switch (params.order) {
            case 'asc':
                list.sort { it.&quot;${params.sort}&quot; } //sort by value where key == params.sort
                break
            case 'desc':
                list.sort {a, b -&gt; b.&quot;${params.sort}&quot; &lt;=&gt; a.&quot;${params.sort}&quot; } //reverse sort by value
                break
        }
       //the entire model
        def data = [totalRecords: list.size(), results: list]
        render data as JSON
    }
</pre>
<p>This model can then be rendered using the <gui :datatable=""> tag. Note that this is pretty much a direct copy of a provided example, nothing fancy here.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;gui:datatable id=&quot;statDataTable&quot; draggablecolumns=&quot;true&quot; columndefs=&quot;[
        [id:'id', sortable:true, resizeable:true],
        [author:'author', sortable:true, resizeable:true],
        [creator:'creator', sortable:true, resizeable:true],
        [moderator:'moderator',  sortable:true, resizeable:true],
        [description:'description', sortable:true, resizeable:true, formatter:'textarea'],
        [state:'state', sortable:true, resizeable:true]
    ]&quot; paginatorconfig=&quot;[
        template:'{PreviousPageLink} {PageLinks} {NextPageLink} {CurrentPageReport}',
        pageReportTemplate:'{totalRecords} total records'
    ]&quot; sortedby=&quot;id&quot; controller=&quot;fisheye&quot; action=&quot;${action}&quot; resultslist=&quot;results&quot; rowsperpage=&quot;10&quot;&gt;
</pre>
<p>So for very little work you get a sortable, paginated DataTable, complete with column resizing and dragging. The DataTable is also being rendered using a template, allowing it to be used arbitrarily by controller methods that populate the model with different reviews. Pretty cool if you ask me. I also used the same backing XML model to drive some PieCharts, but that&#8217;s perhaps a topic for another post.</p>
<p> <img src='http://www.kellyrob99.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
</gui></p>
<!-- AdSense Now! V1.95 -->
<!-- Post[count: 2] -->
<div class="adsense adsense-leadout" style="float:right;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-6955914197200080";
/* 728x90, created 8/3/09 */
google_ad_slot = "4051815125";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Related posts:<ol>
<li><a href='http://www.kellyrob99.com/blog/2010/06/02/a-grails-app-demoing-the-stackexchange-api/' rel='bookmark' title='A Grails App Demoing the StackExchange API'>A Grails App Demoing the StackExchange API</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/10/24/groovy-reverse-map-sort-done-easy/' rel='bookmark' title='Groovy reverse map sort done easy'>Groovy reverse map sort done easy</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/12/16/jira-grails-plugin/' rel='bookmark' title='Jira Grails Plugin'>Jira Grails Plugin</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kellyrob99.com/blog/2009/10/25/grails-ui-datatable-using-xml-for-a-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy CliBuilder with multiple arguments</title>
		<link>http://www.kellyrob99.com/blog/2009/10/04/groovy-clibuilder-with-multiple-arguments/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=groovy-clibuilder-with-multiple-arguments</link>
		<comments>http://www.kellyrob99.com/blog/2009/10/04/groovy-clibuilder-with-multiple-arguments/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 23:30:07 +0000</pubDate>
		<dc:creator>TheKaptain</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[CliBuilder]]></category>
		<category><![CDATA[command line interface]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[theKaptain]]></category>

		<guid isPermaLink="false">http://www.kellyrob99.com/blog/?p=797</guid>
		<description><![CDATA[I&#8217;ve been writing a lot of Groovy scripts lately and have developed quite a fondness for the CliBuilder along the way. There&#8217;s lots of great examples on the internet, but I could only find one place that demonstrated how to easily consume an unknown number of parameters as a List and that was a copy [...]
Related posts:<ol>
<li><a href='http://www.kellyrob99.com/blog/2009/11/21/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier/' rel='bookmark' title='Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;'>Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;</a></li>
<li><a href='http://www.kellyrob99.com/blog/2011/03/27/hooking-into-the-jenkinshudson-api/' rel='bookmark' title='Hooking into the Jenkins(Hudson) API'>Hooking into the Jenkins(Hudson) API</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/10/25/grails-ui-datatable-using-xml-for-a-model/' rel='bookmark' title='Grails-UI DataTable using XML for a model'>Grails-UI DataTable using XML for a model</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing a lot of Groovy scripts lately and have developed quite a fondness for the CliBuilder along the way.<br />
There&#8217;s lots of great examples on the internet, but I could only find one place that demonstrated how to easily consume an unknown number of parameters as a List and that was a copy of the <a href="http://www.koders.com/noncode/fidDB2306122CA9674CE22373B7C018173B53BF66A2.aspx">CliBuilderTest I found on Koders</a>.  There&#8217;s also some explanation for the different behavior inherent in the <a href="http://commons.apache.org/cli/">Apache Commons Cli</a> libraries V1.0 and V1.1 that CliBuilder encapsulates(there is a 1.2 version, but from the documentation it seems CliBuilder may not be fully compatible with it).</p>
<p>Here&#8217;s a GroovyTestCase that exercises CliBuilder with multiple arguments.</p>
<div>
<pre class="brush: groovy; title: ; notranslate">
package org.kar
import org.apache.commons.cli.Option
/**
 * Demonstrates usage of the CliBuilder with multiple arguments to create a List.
 */
class CliBuilderDemoTest
extends GroovyTestCase {
    /**
     * You can specify multiple arguments one at a time.
     */
    void testMultiOption() {
        CliBuilder cli = new CliBuilder()
        cli.with {
            a longOpt: 'arguments', args: 2, required: true, 'Two arguments'
        }
        def args = ['-a', 'arg1', '-a', 'arg2']
        def options = cli.parse(args)

        assert (options)
        assertEquals('First arg is available with the -a option. ', 'arg1', options.a)
        assertEquals('Should be two args, in order, available with the addition of an &quot;s&quot; to the option.',
                ['arg1', 'arg2'], options.as)
    }

    /**
     * You can specify multiple arguments together in a block, with a defined separator(in this case a comma).
     */
    void testMultiOptionWithSeparator() {
        CliBuilder cli = new CliBuilder()
        cli.with {
            a longOpt: 'arguments', args: 2, required: true, valueSeparator: ',' as char,
                    'Two arguments, separated by a comma'
        }
        def args = ['-a', 'arg1,arg2']
        def options = cli.parse(args)

        assert (options)
        assertEquals('First arg is available with the -a option. ', 'arg1', options.a)
        assertEquals('Should be two args, in order.', ['arg1', 'arg2'], options.as)
    }

    /**
     * You can also have any number of arguments by specifying UNLIMITED_VALUES.
     */
    void testUnlimitedArgs() {
        CliBuilder cli = new CliBuilder()
        cli.with {
            a longOpt: 'arguments', args: Option.UNLIMITED_VALUES, required: true, valueSeparator: ',' as char,
                    'Two arguments, separated by a comma'
        }
        def args = ['-a', 'arg1,arg2,arg3']
        def options = cli.parse(args)

        assert (options)
        assertEquals('First arg is available with the -a option. ', 'arg1', options.a)
        assertEquals('Should be a list of args, in order.', ['arg1', 'arg2', 'arg3'], options.as)

        def args2 = ['-a', 'argOnly']
        def options2 = cli.parse(args2)

        assert (options)
        assertEquals('First arg is available with the -a option.', 'argOnly', options2.a)
        assertEquals('Should be a list of args, with a single entry.', ['argOnly'], options2.as)

        def args3 = []
        //this will automagically print the usage string and any validation errors to System.out
        def options3 = cli.parse(args3)
        assertNull(options3)
    }
}
</pre>
</div>
<p>Anyhow, hope that the next guy finds this info useful &#8211; it certainly has made my recent work writing Groovy scripts much easier!</p>
<p>Related posts:<ol>
<li><a href='http://www.kellyrob99.com/blog/2009/11/21/different-flavors-of-embedded-groovy-in-java-apps-or-how-to-make-your-java-groovier/' rel='bookmark' title='Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;'>Different Flavors of Embedded Groovy in Java Apps or &#8220;How To Make your Java Groovier!&#8221;</a></li>
<li><a href='http://www.kellyrob99.com/blog/2011/03/27/hooking-into-the-jenkinshudson-api/' rel='bookmark' title='Hooking into the Jenkins(Hudson) API'>Hooking into the Jenkins(Hudson) API</a></li>
<li><a href='http://www.kellyrob99.com/blog/2009/10/25/grails-ui-datatable-using-xml-for-a-model/' rel='bookmark' title='Grails-UI DataTable using XML for a model'>Grails-UI DataTable using XML for a model</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kellyrob99.com/blog/2009/10/04/groovy-clibuilder-with-multiple-arguments/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Going old school &#8211; Apache Camel mailing lists ftw!</title>
		<link>http://www.kellyrob99.com/blog/2009/07/16/going-old-school-apache-camel-mailing-lists-ftw/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=going-old-school-apache-camel-mailing-lists-ftw</link>
		<comments>http://www.kellyrob99.com/blog/2009/07/16/going-old-school-apache-camel-mailing-lists-ftw/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 03:52:04 +0000</pubDate>
		<dc:creator>TheKaptain</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Apache Camel]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mailing list]]></category>

		<guid isPermaLink="false">http://www.kellyrob99.com/blog/?p=484</guid>
		<description><![CDATA[I&#8217;ve been learning a lot about Apache Camel at work recently and am so very glad that I signed up for the mailing list a couple of weeks back. Was scratching my head recently about why my headers were mysteriously disappearing from some messages and fortunately I read the mailing list before deep diving into [...]
Related posts:<ol>
<li><a href='http://www.kellyrob99.com/blog/2009/04/19/groovy-and-glazed-lists-with-grape/' rel='bookmark' title='Groovy and Glazed Lists with Grape'>Groovy and Glazed Lists with Grape</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been learning a lot about <a class="zem_slink" title="Apache Camel" rel="homepage" href="http://activemq.apache.org/camel">Apache Camel</a> at work recently and am so very glad that I signed up for the mailing list a couple of weeks back.</p>
<p>Was scratching my head recently about why my headers were mysteriously disappearing from some messages and fortunately I read the mailing list before deep diving into the Camel source to find the problem. Somebody else came across this exact problem and <a href="http://www.nabble.com/HTTP-component-and-IN-head-loss-to24393415.html">pointed it out on the mailing list</a>. In a beautiful display of same day service, a response was posted back to the forum by one of the developers. He <a href="https://issues.apache.org/activemq/browse/CAMEL-1813">filed a bug report</a> and committed a fix within hours. Nice job <a href="http://willemjiang.blogspot.com/">Willen Jiang</a>!</p>
<p>This is a great example of <a class="zem_slink" title="Open Source" rel="wikinvest" href="http://www.wikinvest.com/concept/Open_Source">open source</a> collaboration, as far as I&#8217;m concerned &#8211; and it saved me a lot of debugging thank-you-very-much!  This kind of care and attention in the community surrounding Camel makes me feel a lot more comfortable about leveraging it to solve some tricky integration problems at work. And the mailing list has been a wealth of knowledge in many other ways as well, guiding me to a lot of resources that I wouldn&#8217;t have otherwise known about.</p>
<p>If you&#8217;re a developer using Camel I highly recommend <a href="http://camel.apache.org/mailing-lists.html">signing up for the mailing list</a>.</p>
<div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/3b02082a-3838-4555-a5a2-de47ea1eecd5/"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_c.png?x-id=3b02082a-3838-4555-a5a2-de47ea1eecd5" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<p>Related posts:<ol>
<li><a href='http://www.kellyrob99.com/blog/2009/04/19/groovy-and-glazed-lists-with-grape/' rel='bookmark' title='Groovy and Glazed Lists with Grape'>Groovy and Glazed Lists with Grape</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kellyrob99.com/blog/2009/07/16/going-old-school-apache-camel-mailing-lists-ftw/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

