<?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>Intelligrape  Groovy &#38; Grails Blogs</title>
	<atom:link href="http://www.intelligrape.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.intelligrape.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 23 May 2013 06:06:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
<image>
			<title>Intelligrape  Groovy &amp; Grails Blogs</title>
			<url>http://www.intelligrape.com/blog/wp-content/uploads/2011/05/favicon2.ico</url>
			<link>http://www.intelligrape.com/blog</link>
			<width></width>
			<height></height>
			<description></description>
		</image>		<item>
		<title>Node.js: Unit Testing with Jasmine framework</title>
		<link>http://www.intelligrape.com/blog/2013/05/14/node-js-unit-testing-with-jasmine-framework/</link>
		<comments>http://www.intelligrape.com/blog/2013/05/14/node-js-unit-testing-with-jasmine-framework/#comments</comments>
		<pubDate>Tue, 14 May 2013 05:00:16 +0000</pubDate>
		<dc:creator>Sahil</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[jasmine]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=10357</guid>
		<description><![CDATA[Jasmine is a framework which is used for testing node.js code or javascript code. Installation To install the latest official version, use NPM: npm install jasmine-node -g Write the specifications for your code in *.js and *.coffee files in the spec/ directory Execution After installing the npm package, you can run it with: jasmine-node spec/filename.js [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left"><strong>Jasmine</strong> is a framework which is used for testing <strong>node.js</strong> code or <strong>javascript</strong> code.</p>
<p><strong>Installation</strong></p>
<p>To install the latest official version, use <strong>NPM:</strong><br />
<strong></strong></p>
<pre class="brush: jscript;">npm install jasmine-node -g</pre>
<p>Write the specifications for your code in *.js and *.coffee files in the spec/ directory</p>
<p><strong>Execution</strong></p>
<p>After installing the npm package, you can run it with:</p>
<pre class="brush: jscript;">jasmine-node spec/filename.js
jasmine-node spec/filename.coffee</pre>
<p>For executing multiple test files you can provide multiple filenames as an argument to jasmine-node command.</p>
<p><strong></strong><br />
<strong>Key features :</strong></p>
<ol>
<li>Behavior driven.</li>
<li>It does not require DOM for testing.</li>
<li>Clean and obvious syntax.</li>
</ol>
<p><strong>Test Cases :<br />
</strong></p>
<p><strong>SUITES</strong><br />
Call to a global function <strong>&#8216;describe&#8217;</strong> which takes arguments a String and function. The function is a block of code that implements the suite.The String describes the title for the suit.</p>
<p><strong>SPECS</strong><br />
Call to global Jasmine function <strong>&#8216;it&#8217;,</strong> which like &#8216;describe&#8217; takes a string and a function. The string is a title for this spec and the function is the spec, or test. A spec contains one or more expectations that examine the state of the code under test,their can be as many &#8216;it&#8217; functions in describe block.</p>
<p><strong>EXPECTATION</strong><br />
Expectation in jasmine is an assertion which results either true or false. Their can be as many assertions in a spec. Expectations are genrated with the function <strong>&#8216;expect&#8217;</strong> which takes an argument which is the actual value. It is chained with a Matcher function, which takes the expected value.</p>
<p><strong>MATCHERS</strong></p>
<p>Each matcher implements the Boolean comparison between actual and expected value. Matchers are used to compare both the values and if all matchers matches or return true only then test is considered as passed else it is considered as failure. Some of the matchers functions are &#8216;toBe&#8217;, &#8216;toBeTruthy&#8217; etc.<br />
Some examples are as follows:</p>
<pre class="brush: jscript;">expect(x).toEqual(y); // compares objects or primitives x and y and passes if they are equivalent
expect(x).toBe(y); // compares objects or primitives x and y and passes if they are the same object
expect(x).toMatch(pattern); //compares x to string or regular expression pattern and passes if they match</pre>
<p><strong>beforeEach() and afterEach()</strong></p>
<p>Function <strong>&#8216;beforeEach&#8217;</strong> performs task that is to be performed before test begins and <strong>&#8216;afterEach&#8217;</strong> performs task that is to be performed after test finished execution.</p>
<p><strong>Sample test</strong></p>
<pre class="brush: jscript;">
describe(&quot;A suite&quot;, function() {
var a;

it(&quot;A spec&quot;, function() {
a = true;

expect(a).toBe(true);
expect(a).not.toBe(false);
});
});
</pre>
<p>Sahil Chitkara<br />
Software Trainee<br />
Intelligrape Software</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/05/14/node-js-unit-testing-with-jasmine-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reading Google Drive Spreadsheet in Grails Application</title>
		<link>http://www.intelligrape.com/blog/2013/05/13/authentication-using-oauth-for-google-drive-application/</link>
		<comments>http://www.intelligrape.com/blog/2013/05/13/authentication-using-oauth-for-google-drive-application/#comments</comments>
		<pubDate>Mon, 13 May 2013 13:01:42 +0000</pubDate>
		<dc:creator>paridhi</dc:creator>
				<category><![CDATA[Google Web Tools]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Drive]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[OAuth2.0]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=10283</guid>
		<description><![CDATA[OAuth is a secure mechanism to access google drive. In order to access google drive in your application you need to register your application at the google API console at Google API Console. Read the blog  Integrating Google plus in grails application by Vishal Sahu to see how to get client ID, client secret and [...]]]></description>
			<content:encoded><![CDATA[<p style="padding-top: 5px">OAuth is a secure mechanism to access google drive. In order to access google drive in your application you need to register your application at the google API console at <a title="https://code.google.com/apis/console/" href="https://code.google.com/apis/console/" target="_blank">Google API Console</a>. Read the blog  <a title="http://www.intelligrape.com/blog/2011/12/06/integrating-google-plus-in-grails-application/" href="http://www.intelligrape.com/blog/2011/12/06/integrating-google-plus-in-grails-application/" target="_blank">Integrating Google plus in grails application</a> by Vishal Sahu to see how to get client ID, client secret and redirect URL but in order to read google drive spreadsheets select Drive API in the services pane while registering your project.</p>
<p style="padding-top: 5px">Now to access your Google drive in your grails application you may save the client ID, client secret and redirect URL in Config.groovy like this:</p>
<pre class="brush: groovy;"> googleDrive{
  redirectURL = &quot;Redirect Url&quot;
  clientId  = &quot;Client Id&quot;
  clientSecret= &quot;Client Secret&quot;
}
</pre>
<p>Add following  dependencies in BuildConfig.groovy to import jars for accessing google documents and OAuth authorization:</p>
<pre class="brush: groovy;">

compile &quot;com.google.gdata:core:1.47.1&quot;
compile &quot;com.google.apis:google-api-services-drive:v2-rev72-1.14.2-beta&quot;
compile &quot;com.google.http-client:google-http-client-jackson:1.14.1-beta&quot;

</pre>
<p>To access authorized user&#8217;s google drive, you need to get an authorization URL. User of the application must access this URL to authorize the application with Google and generate the authorization code. Following sample action generates the required authorization URL:</p>
<pre class="brush: groovy;">

def index = {
   String clientId = grailsApplication.config.googleDrive.clientId
   String redirectURL = grailsApplication.config.googleDrive.redirectURL
   //List of scopes for which to request access
   List scopes =[&quot;https://spreadsheets.google.com/feeds&quot;, &quot;https://docs.google.com/feeds&quot;];
   String authorizationUrl =
   new GoogleAuthorizationCodeRequestUrl(clientId , redirectURL, scopes).build();
   redirect(url: authorizationUrl)
 }

</pre>
<p>The browser will redirect to the URL you specified in the redirectUrl parameter with the authorization code. Here is a sample redirect action which sets the authorization code in session.</p>
<pre class="brush: groovy;">

def callback(String code) {
  HttpSession session = request.getSession();
  session.code = code;
  setCredential()
}

</pre>
<p>The setCredential() method generates the access token and sets its value in the session.</p>
<pre class="brush: groovy;">
def setCredential() {
  HttpTransport transport = new NetHttpTransport()
  JacksonFactory jsonFactory = new JacksonFactory()
  String clientId = grailsApplication.config.googleDrive.clientId
  String clientSecret = grailsApplication.config.googleDrive.clientSecret
  String redirectUrl = grailsApplication.config.googleDrive.redirectURL
  GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest
  (transport, jsonFactory, clientId, clientSecret,session.code, redirectUrl).execute();
  GoogleCredential accessToken = new GoogleCredential.Builder()
  .setClientSecrets(clientId, clientSecret)
  .setJsonFactory(jsonFactory).setTransport(transport).build()
  .setAccessToken(response.getAccessToken()).setRefreshToken(response.getRefreshToken());
  session.accessToken = accessToken
}

</pre>
<p>Once you have the access token you may access google drive. Following code snippet returns a list of all spreadsheets. Now you can view, edit, delete and manipulate your spreadsheets using <a title=" https://developers.google.com/google-apps/spreadsheets/" href="https://developers.google.com/google-apps/spreadsheets/">Google Spreadsheet API.</a></p>
<pre class="brush: groovy;">

SpreadsheetService service = new SpreadsheetService(&quot;MySpreadsheetService&quot;);
service.setOAuth2Credentials(session.accessToken)
URL sheetFeedUrl = new URL(&quot;https://spreadsheets.google.com/feeds/spreadsheets/private/full&quot;)
SpreadsheetFeed feed = service.getFeed(sheetFeedUrl,SpreadsheetFeed.class);
List spreadsheets = feed.getEntries()

</pre>
<p>Following is the code for reading data from first spreadsheet from the list retrieved above:</p>
<pre class="brush: groovy;">

List worksheets = spreadsheets.get(0).getWorksheets();
worksheets.each{worksheet-&gt;
URL listFeedUrl = worksheet.getListFeedUrl();
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class);
listFeed.entries.each{row-&gt;
row.customElements.tags.each{tag-&gt;
   println &quot;Column: ${tag} -- Value: ${row.getCustomElements().getValue(tag)}&quot;
  }
 }
}
</pre>
<p>Helpful links:</p>
<p><a title="https://code.google.com/apis/console/" href="https://code.google.com/apis/console/">https://code.google.com/apis/console/</a></p>
<p><a title="https://developers.google.com/google-apps/spreadsheets/" href="https://developers.google.com/google-apps/spreadsheets/" target="_blank">https://developers.google.com/google-apps/spreadsheets/</a></p>
<p>Hope it helps!!<br />
Paridhi Goel<br />
paridhi@intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/05/13/authentication-using-oauth-for-google-drive-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create Basic HTTP Server with Node.js</title>
		<link>http://www.intelligrape.com/blog/2013/05/10/create-basic-http-server-with-node-js/</link>
		<comments>http://www.intelligrape.com/blog/2013/05/10/create-basic-http-server-with-node-js/#comments</comments>
		<pubDate>Fri, 10 May 2013 17:49:31 +0000</pubDate>
		<dc:creator>Amit Kumar</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=10246</guid>
		<description><![CDATA[Like other languages(Java, php), we do not need to set up any Apache HTTP server. With Node, things are a bit different, with Node.js, we not only implement our application, we also implement the whole HTTP server. In fact, our web application and its web server are basically the same. Lets create a basic Node [...]]]></description>
			<content:encoded><![CDATA[<p>Like other languages(Java, php), we do not need to set up any <strong>Apache</strong> <strong>HTTP</strong> <strong>server</strong>. With <strong>Node</strong>, things are a bit different, with <strong>Node.js</strong>, we not only implement our application, we also implement the whole <strong>HTTP</strong> <strong>server</strong>. In fact, our web application and its web <strong>server</strong> are basically the same. Lets create a basic <strong>Node</strong> <strong>HTTP</strong> <strong>server</strong>. First let&#8217;s create a main file called <strong>server.js</strong> in the root directory which we use to start our application, and a module file where our <strong>HTTP</strong> <strong>server</strong> code lives, and fill it with the code given below:</p>
<pre class="brush: jscript;">
var http = require(&quot;http&quot;);
var requestHandler = function(request, response) {
  console.log(&quot;Request received.&quot;);
  response.writeHead(200, {&quot;Content-Type&quot;: &quot;text/plain&quot;});
  response.write(&quot;Hello World&quot;);
  response.end();
};
var server = http.createServer(requestHandler);
server.listen(9999);
console.log(&quot;Server has started.&quot;);
</pre>
<p style="padding:10px">
<p>Now run the code. To run the <strong>server.js</strong> script with <strong>Node.js</strong> type below command:</p>
<pre class="brush: bash;">
node server.js
</pre>
<p style="padding:10px">
<p>Now open your favorite browser and hit it at http://localhost:9999/. This should display a web page that says <strong>&#8220;Hello World!&#8221;</strong>. Well, now lets analyze what&#8217;s actually going on here.</p>
<p style="padding:10px">
<p>1. The first line <strong>requires</strong> the <strong>http</strong> module that ships with <strong>Node.js</strong> and makes it accessible through the variable <strong>http</strong>.<br />
2. We definded a <strong>requestHandler</strong> funciton to handle all the requests.<br />
3. We called one of the functions that <strong>http</strong> module offers: <strong>createServer</strong>. This function returns an object, which we store in server.<br />
4. This(<strong>server</strong>) object has a method named <strong>listen</strong>, and takes a numeric value which indicates the port number our <strong>HTTP</strong> <strong>server</strong> is going to <strong>listen</strong>.</p>
<p style="padding:10px">
<p style="padding:10px">
<p>Now lets analyze the, how <strong>requestHandler</strong> handling the requests. Whenever a request received, <strong>requestHandler</strong> function gets triggered and two parameters are passed into it, <strong>request</strong> and <strong>response</strong>.</p>
<p style="padding:10px">
<p>1. <strong>response.writeHead()</strong> send an HTTP status and content-type in the <strong>HTTP</strong> <strong>response</strong> header.<br />
2. <strong>response.write()</strong> send the text <strong>“Hello World”</strong> in the <strong>HTTP</strong> <strong>response</strong> body.<br />
3. <strong>response.end()</strong> finish <strong>response</strong>.</p>
<p style="padding:10px">
<p style="padding:10px">
<p>Amit Kumar<br />
<a href="http://www.intelligrape.com/blog/author/amit.kumar/">amit.kumar@intelligrape.com</a><br />
<a href="http://in.linkedin.com/in/amitkumar0110">in.linkedin.com/in/amitkumar0110</a><br />
<a href="https://twitter.com/amit_kumar0110">twitter.com/amit_kumar0110</a><br />
<strong><a href="http://www.intelligrape.com/blog/author/amit-kumar/">More Blogs by Me</a></strong></p>
<p style="padding:10px">
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/05/10/create-basic-http-server-with-node-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AngularJS : Getting started with Directives</title>
		<link>http://www.intelligrape.com/blog/2013/04/25/angularjs-getting-started-with-directives/</link>
		<comments>http://www.intelligrape.com/blog/2013/04/25/angularjs-getting-started-with-directives/#comments</comments>
		<pubDate>Thu, 25 Apr 2013 11:36:57 +0000</pubDate>
		<dc:creator>Suroor Wijdan</dc:creator>
				<category><![CDATA[Javascript/Ajax/JQuery]]></category>
		<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[directives]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=10226</guid>
		<description><![CDATA[In this post we will go through an important aspect of AngularJS i.e., Directives. Directives helps us do things in a better and cleaner way. Lets get into the code rather going into theoretical explanations, which will make it more clear what actually directives do. We have written a simple directive below which shows some HTML when [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify">In this post we will go through an important aspect of AngularJS i.e., <strong>Directives</strong>.</p>
<p style="text-align: justify">Directives helps us do things in a better and cleaner way. Lets get into the code rather going into theoretical explanations, which will make it more clear what actually directives do.</p>
<p style="text-align: justify">We have written a simple directive below which shows some HTML when the element being created is encountered.</p>
<pre class="brush: xml;">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Testing Directive&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div ng-app=&quot;FirstDirective&quot;&gt;
    &lt;mytag&gt;&lt;/mytag&gt;
&lt;/div&gt;

&lt;script&gt;

myApp = angular.module(&quot;FirstDirective&quot;,[]);

myApp.directive('mytag',function(){
    return {
        restrict: &quot;E&quot;,
        template: &quot;&lt;strong&gt;This is a great First Directive&lt;/strong&gt;&quot;,
        replace: true,
    }
})

&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p style="text-align: justify">In the above code, we have &#8220;mytag&#8221; element which when encountered in HTML renders the corresponding template.  Lets see what the code does,</p>
<p style="text-align: justify"><strong>myApp.directive()</strong> is another syntax that we have to remember. The first argument in this is the name of the tag that you want, in our case its <strong>&#8220;mytag&#8221;</strong>. Second thing is a factory function which returns an object that defines the directive properties.</p>
<p style="text-align: justify">In this object we have set <strong>&#8220;restrict&#8221;</strong> as E which makes it an Element that can be used like any of HTML tags. The second option <strong>&#8220;template&#8221;</strong> defines the HTML template to be loaded and the third option <strong>&#8220;replace&#8221;</strong> if set to true replaces the current element with the template.</p>
<p style="text-align: justify">We will learn more about other options available to us in the next post.</p>
<p style="text-align: justify">Hope it Helps! Feel free to ask if you have any queries.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/04/25/angularjs-getting-started-with-directives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Ftp with Grails</title>
		<link>http://www.intelligrape.com/blog/2013/04/04/using-ftp-with-grails/</link>
		<comments>http://www.intelligrape.com/blog/2013/04/04/using-ftp-with-grails/#comments</comments>
		<pubDate>Thu, 04 Apr 2013 09:56:42 +0000</pubDate>
		<dc:creator>Puneet Behl</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[jcraft]]></category>
		<category><![CDATA[Jsch]]></category>
		<category><![CDATA[sftp]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=10074</guid>
		<description><![CDATA[In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project &#8220;grails-app/conf/BuildConfig.groovy&#8221; file dependencies { compile 'com.jcraft:jsch:0.1.49' } 2. Create a class for adding ftp credentials information. e.g. &#8220;FtpCredentail&#8221; class FtpCredential { [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my Grails project I need to drop files over ftp server. Using <a title="JSch" href="http://www.jcraft.com/jsch/" target="_blank">JSch</a> one can easily transfer files over sftp. Just follow the below steps.<br />
1. Add the below dependency to Grails project <em>&#8220;grails-app/conf/BuildConfig.groovy&#8221;</em> file</p>
<pre class="brush: groovy;">
dependencies {
        compile 'com.jcraft:jsch:0.1.49'
    }
</pre>
<p>2. Create a class for adding ftp credentials information. e.g. &#8220;FtpCredentail&#8221;</p>
<pre class="brush: groovy;">
class FtpCredential {

    String server
    String username
    String password
    String remoteBaseDir
    Integer port
}
</pre>
<p>3. Create a service named &#8220;FtpService&#8221; and add the following code into it</p>
<pre class="brush: groovy;">
import com.jcraft.jsch.Channel
import com.jcraft.jsch.ChannelSftp
import com.jcraft.jsch.JSch
import com.jcraft.jsch.Session

class FtpService {
    def grailsApplication

    static transactional = true

    def save(InputStream inputStream, String fileName, FtpCredential ftpCredential) {
        connect(ftpCredential) { ChannelSftp sftp -&gt;
            sftp.put inputStream, fileName
        }
    }

    def load(String fileName, FtpCredential ftpCredential) {
        connect(ftpCredential, { ChannelSftp sftp -&gt;
            File outputFile = File.createTempFile(fileName,'')
            outputFile?.newOutputStream() &lt;&lt; sftp.get(fileName)
            outputFile
        }, false)
    }

    def delete(String fileName, FtpCredential ftpCredential) throws Throwable {
        connect(ftpCredential) { ChannelSftp sftp -&gt;
            sftp.rm fileName
        }
    }

    def makeDir(String directoryName, FtpCredential ftpCredential) {
        connect(ftpCredential) { ChannelSftp sftp -&gt;
            sftp.mkdir directoryName
        }
    }

    private def connect(FtpCredential ftpCredential, Closure c, boolean disconnectOnFinish = true) {
        Session session = null
        ChannelSftp sftp = null
        try {
            JSch jSch = new JSch()
            session = jSch.getSession username, ftpCredential?.server, ftpCredential?.port
            session.setConfig &quot;StrictHostKeyChecking&quot;, &quot;no&quot;
            File keyFile = new File(&quot;${grailsApplication.config.pathToKeyFile}&quot;)
            if (ftpCredential?.password) {
                session.password = ftpCredential?.password
            } else {
                jSch.addIdentity(keyFile?.absolutePath)
            }
            session.connect()
            Channel sFtpChannel = session.openChannel &quot;sftp&quot;
            sFtpChannel.connect()
            sftp = sFtpChannel as ChannelSftp
            sftp.cd ftpCredential?.remoteBaseDir
            c.call sftp
        } catch (Exception ex) {
            ex.printStackTrace()
        } finally {
            if (disconnectOnFinish) {
                sftp?.exit()
                session?.disconnect()
            }
        }
    }
}
</pre>
<p><strong>Note:</strong> In the above code at <em>line number 44</em>.</p>
<pre class="brush: groovy;">
File keyFile = new File(&quot;${grailsApplication.config.pathToKeyFile}&quot;)
</pre>
<p>The code looks for private key provided by ftp server for password-less log in. One should define the property named &#8220;<em>pathToKeyFile</em>&#8221; in &#8220;<em>grails-app/conf/Config.groovy</em>&#8221; with value equals to the path of key file.<br />
<br />
Now you are ready to use the newly created FtpService service methods. Such as:</p>
<ol>
<li><em>save(inputStream, fileName, ftpCredential)</em> for saving file over ftp.</li>
<li><em>load(fileName, ftpCredential)</em> for getting file from ftp.</li>
<li><em>delete(fileName, ftpCredential)</em> for deleting file over ftp.</li>
<li><em>makeDir(directoryName, ftpCredential)</em> for creating directory over ftp.</li>
</ol>
<h2>Example</h2>
<p>For saving file over ftp one can use FtpService <strong>save</strong> method as shown below</p>
<pre class="brush: groovy;">
 File file = File.createTempFile(&quot;temp&quot;,&quot;txt&quot;)
 FtpCredential ftpCredential = new FtpCredential(server: &lt;server&gt;, username: &lt;username&gt;, password: &lt;password&gt;, port: &lt;server_port&gt;, remoteBaseDir: &lt;remote_base_directory&gt;)
 InputStream inputStream = new BufferedInputStream(new FileInputStream(file))
 ftpService.save(inputStream, &quot;fileNameToBeSavedOverFTPServer&quot;, ftpCredential)
</pre>
<p>
<em>Please share your feedback and suggestions.</em></p>
<hr />
<p style="text-align: right"><strong><em><a title="JSch Examples" href="http://www.jcraft.com/jsch/examples/" target="_blank">Click here to read more <em>JSch</em> examples »</a></em></strong></p>
<p><br/><br />
<a href="http://www.intelligrape.com/blog/author/puneet.behl/" target="_blank">Puneet Behl</a><br />
<a href="mailto:puneet.behl@intelligrape.com">puneet.behl@intelligrape.com</a><br />
<a href="https://twitter.com/puneetbhl" target="_blank">https://twitter.com/puneetbhl</a><br />
<a href="http://in.linkedin.com/in/puneetbhl" target="_blank">http://in.linkedin.com/in/puneetbhl</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/04/04/using-ftp-with-grails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Determine Average in MongoDB</title>
		<link>http://www.intelligrape.com/blog/2013/04/02/average-in-mongodb/</link>
		<comments>http://www.intelligrape.com/blog/2013/04/02/average-in-mongodb/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 11:12:26 +0000</pubDate>
		<dc:creator>Sakshi Tyagi</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[average]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[groupby]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=10162</guid>
		<description><![CDATA[MongoDB provides several ways of computing the average value of a group in a collection. One of the simplest ways of determining average is using the method db.collection.group(). The method db.collection.group() bunches the documents of a collection on the basis of the keys mentioned and executes aggregation functions on them. This method can be used [...]]]></description>
			<content:encoded><![CDATA[<p>MongoDB provides several ways of computing the average value of a group in a collection. One of the simplest ways of determining average is using the method<strong> db.collection.group()</strong>.<br />
<br />
The method db.collection.group() bunches the documents of a collection on the basis of the keys mentioned and executes aggregation functions on them. This method can be used for performing several operations, including count and addition. In order words, the method performs functionality similar to that of the SQL’s Select-Group By combination.<br />
<br />
The implementation and working of the method db.collection.group() for determining the average of a field in a collection is illustrated here using the example of a collection ‘userquestions’. The query, which can be used to find average, is as follows -</p>
<pre class="brush: bash;">

var reduceFunction = function(currentDocument, previousDocument) {
     previousDocument.totalRating += currentDocument.rating; previousDocument.count += 1
};

var finalizeFunction = function(currentDocument) {
     currentDocument.average = currentDocument.totalRating/currentDocument.count;
     delete currentDocument.totalRating;
     delete currentDocument.count;
};

db.userquestions.group({
     key: {'quesId': true},
     initial: {totalRating: 0, count:0},
     reduce: reduceFunction,
     finalize:finalizeFunction
});

</pre>
<p>In the present context, the value of the ‘key’ is the field ‘quesId’. Documents are grouped together on the basis of this key. The initial values for the parameters ‘count’ and ‘totalRating’ are set to zero. Besides these, two functions are declared and defined in the query. The function <strong>reduce</strong> totals the value of the ‘rating’ and saves it in ‘totalRating’. In addition to this, it also maintains the count of documents processed.<br />
<br />
On the other hand, the function ‘finalize’ determines the average value of rating by dividing the value of ‘totalRating’ by the count.The execution of this query returns an array containing different ‘quesId’, which represents the different groups and the corresponding average rating for each of these groups.<br />
<br />
Hope this will help. <img src='http://www.intelligrape.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Thanks,<br />
Sakshi Tyagi<br />
sakshi@intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/04/02/average-in-mongodb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy: Ways to represent String</title>
		<link>http://www.intelligrape.com/blog/2013/04/02/groovy-ways-to-represent-string/</link>
		<comments>http://www.intelligrape.com/blog/2013/04/02/groovy-ways-to-represent-string/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 08:32:21 +0000</pubDate>
		<dc:creator>vivek.garg</dc:creator>
				<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=9994</guid>
		<description><![CDATA[Compared to Java we have a lot of  ways to represent strings : GString, single quote, double quotes, slashy and dollar slashy. &#160; 1.GString: A GString is just like a normal String, except that it evaluates expression that are embedded with in string in the form ${..}. String demo=&#34;Brother&#34; String doubleQuotes= &#34;Hello ${demo}&#34; println doubleQuotes [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>
Compared to Java we have a lot of  ways to represent <a title="http://groovy.codehaus.org/JN1525-Strings" href="http://groovy.codehaus.org/JN1525-Strings">strings</a> : <a title="http://groovy.codehaus.org/api/groovy/lang/GString.html" href="http://groovy.codehaus.org/api/groovy/lang/GString.html">GString</a>, single quote, double quotes, slashy and dollar slashy.
</li>
</ul>
<p>&nbsp;<br />
<strong>1.GString</strong>: A <a title="http://groovy.codehaus.org/api/groovy/lang/GString.html" href="http://groovy.codehaus.org/api/groovy/lang/GString.html">GString</a> is just like a normal String, except that it evaluates expression that are embedded with in string in the form ${..}.</p>
<pre class="brush: java;">
String demo=&quot;Brother&quot;
String doubleQuotes= &quot;Hello ${demo}&quot;
println doubleQuotes   //Output:Hello Brother

String slashy= /Hello ${demo}/
println slashy   //Output:Hello Brother

String dollarSlashy= $/Hello ${demo}/$
println dollarSlashy   //Output:Hello Brother
</pre>
<p><strong>2.Single Quote</strong>:Groovy Treats a String created using single quotes as a pure literal.</p>
<pre class="brush: java;">
String demo=&quot;World&quot;
println 'Hello &quot;${demo}&quot;'   //Output: Hello &quot;${demo}&quot;

//To expand an expression Groovy uses double quotes, slashy and dollar slashy.

String multiLine='''With three  Single Quotes
In Groovy we can write
Multi-Line-String'''
</pre>
<p><strong>3.Double Quotes</strong>:These are often used to define String expression.</p>
<pre class="brush: java;">
int value=12
println &quot;He bought ${value} egg &quot;   //Output: He bought 12 egg

println &quot;He paid \$${value} for that&quot;   //Output: He paid $12 for that

//I have used the escape  character to print $ symbol since groovy uses that for embedding expressions.you don't have to escape $ if you use slashes, as you'll see soon.

String multiLine=&quot;&quot;&quot;With three  Double Quotes
In Groovy we can write
Multi-Line-String&quot;&quot;&quot;
</pre>
<p><strong>4.Slashy:</strong>These are often used for regular expression.</p>
<pre class="brush: java;">

int value=12
String demo=/he paid $${value} for that/
println demo   //Output: he paid $12 for that

//Look here we don't have to escape $ symbol

String multiLine=/With slashy string
In Groovy we can write
Multi-Line-String/

</pre>
<p><strong>5.Dollar Slashy:</strong>It is almost same as slashy string but with slightly different escaping rules .The biggest advantage of this is that we don&#8217;t even have to escape slash(&#8216;/&#8217;) which results in a much cleaner regular expressions but you can use &#8216;$$&#8217; to escape a &#8216;$&#8217; or &#8216;$/&#8217; to escape a slash if needed.</p>
<pre class="brush: java;">

int value=12
String demo=$/he paid $ ${value} for one orange/$
println demo   // Output :he paid $ 12 for one orange

String demo1=$/he paid $$ ${value} for one orange/$
println demo1   // Output: he paid $ 12 for one orange

String demo2=$/Here evaluation will not take place $${value}, as we have escaped $ with $ /$
println demo2  
// Output: Here evaluation will not take place ${value}, as we have escaped $ with $

String demo3=$/what would you like to have tea/coffee/$
println demo3   //Output:what would you like to have tea/coffee

String demo4=$/what would you like to have tea$/coffee/$
println demo4   //Output:what would you like to have tea/coffee

//you can see that we can have a much cleaner Regex using dollar-slashy string.

String multiLine=$/With dollar-slashy string
In Groovy we can write
Multi-Line-String/$
</pre>
<p>I hope it helps, feel free to ask if you have any queries</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/04/02/groovy-ways-to-represent-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento Sending Custom Email</title>
		<link>http://www.intelligrape.com/blog/2013/04/01/magento-sending-custom-email/</link>
		<comments>http://www.intelligrape.com/blog/2013/04/01/magento-sending-custom-email/#comments</comments>
		<pubDate>Mon, 01 Apr 2013 08:43:15 +0000</pubDate>
		<dc:creator>amatya</dc:creator>
				<category><![CDATA[CMS]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=10107</guid>
		<description><![CDATA[By default magento sends emails on its certain events like customer registration, order creation etc. Also you can customize or change these email templates from admin &#62; System &#62; Transaction Email. What if you want add your own custom email template or if you want to add email feature in your custom module. This blog [...]]]></description>
			<content:encoded><![CDATA[<p>
By default magento sends emails on its certain events like customer registration, order creation etc. Also you can customize or change these email templates from admin &gt; System &gt; Transaction Email. What if you want add your own custom email template or if you want to add email feature in your custom module. This blog helps you in achieving this. Following are steps :
</p>
<p>
First of all create your email template test.html under following directory.
</p>
<p>
app\locale\en_US\template\email. Where en_US is your default language pack. You can replace it with your own.
</p>
<pre class="brush: php;">
&lt;!--@subject Custom Email for {{var customVariable}} @--&gt;
&lt;!--@vars
{&quot;store url=\&quot;\&quot;&quot;:&quot;Store Url&quot;,
&quot;var logo_url&quot;:&quot;Email Logo Image Url&quot;,
&quot;var logo_alt&quot;:&quot;Email Logo Image Alt&quot;,
}
@--&gt;
&lt;!--@styles
body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
@--&gt;
&lt;body style=&quot;background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;&quot;&gt;
&lt;div style=&quot;background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;&quot;&gt;
Hello {{var custName}}&lt;br&gt;
Thank you. Your logo path is {{var logo_url}}
&lt;/div&gt;
&lt;/body&gt;
</pre>
<p>
&lt;!&#8211;@subject : In this tag you can define subject line of your email.<br />
&lt;!&#8211;@vars : In vars section you can define your custom variable.<br />
&lt;!&#8211;@styles : In this tag section you can add custom style for your email template.<br />
{{var custName}} : By using {{var custName}} you can add your custom variable in your email template.
</p>
<p>
Now add following code in your module&#8217;s config.xml file&#8217;s global node.
</p>
<pre class="brush: php;">
&lt;template&gt;
&lt;email&gt;
&lt;test_email_template&quot;&gt;
&lt;label&gt;Test Email&lt;/label&gt;
&lt;file&gt;test.html&lt;/file&gt;
&lt;type&gt;html&lt;/type&gt;
&lt;/test_email_template&gt;
&lt;/email&gt;
&lt;/template&gt;
</pre>
<p>
Now clear magento cache and go to <strong><em>admin &gt; Transactional Email &gt; Add New Template</em></strong>. From here you can load your cuatom email template
</p>
<p>
Add the following code in your controller&#8217;s action from where you want to send your email.
</p>
<pre class="brush: php;">
&lt;?php
$templateId = 25 //your email template id;
$sender = Array('name' =&gt; 'Sender's Name',
'email' =&gt; 'test@test.com');
//recepient
$email = 'abc@test.com';
$emaiName = 'Sender's Name';
$vars = Array();
$vars = Array('customVariable'=&gt;$yourCustomVarialbe,
);*/
$storeId = Mage::app()-&gt;getStore()-&gt;getId();
$translate = Mage::getSingleton('core/translate');
Mage::getModel('core/email_template')
-&gt;sendTransactional($templateId, $sender, $email, $emailName, $vars, $storeId);
$translate-&gt;setTranslateInline(true);
?&gt;
</pre>
<p>
That&#8217;s it. Hope this will help you <img src='http://www.intelligrape.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p>
<br />
Regards,<br />
Amatya Trivedi<br />
amatya@intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/04/01/magento-sending-custom-email/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enabling SSL for particular page in magento</title>
		<link>http://www.intelligrape.com/blog/2013/03/19/enabling-ssl-for-particular-page-in-magento/</link>
		<comments>http://www.intelligrape.com/blog/2013/03/19/enabling-ssl-for-particular-page-in-magento/#comments</comments>
		<pubDate>Tue, 19 Mar 2013 08:03:35 +0000</pubDate>
		<dc:creator>amatya</dc:creator>
				<category><![CDATA[CMS]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=9979</guid>
		<description><![CDATA[To enable SSL for particular page in magento first open .htaccess file of your magento and include following code in it. RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^your-page-url/?$ https://%{HTTP_HOST}/your-page-url [R,L] Now flush the cache and check. Regards, Amatya Trivedi amatya@intelligrape.com]]></description>
			<content:encoded><![CDATA[<p>
To enable SSL for particular page in magento first open .htaccess file of your magento and include following code in it.
</p>
<pre class="brush: php;">
RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^your-page-url/?$ https://%{HTTP_HOST}/your-page-url [R,L]
</pre>
<p>
Now flush the cache and check.
</p>
<p>
<br />
Regards,<br />
Amatya Trivedi<br />
amatya@intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/03/19/enabling-ssl-for-particular-page-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell script to control the brightness of display</title>
		<link>http://www.intelligrape.com/blog/2013/03/18/shell-script-to-control-the-brightness-of-display/</link>
		<comments>http://www.intelligrape.com/blog/2013/03/18/shell-script-to-control-the-brightness-of-display/#comments</comments>
		<pubDate>Mon, 18 Mar 2013 10:54:24 +0000</pubDate>
		<dc:creator>Manvendra Singh</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[brightness]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[xbacklight]]></category>
		<category><![CDATA[xrandr]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=9941</guid>
		<description><![CDATA[The problem I was facing for sometime is setting brightness of my laptop that is running Ubuntu 12.10. Unfortunately this function is not  available in my laptop. So I started my investigation to get this functionality. Then I found the xrandr command. A similar is xbacklight command, but it&#8217;s not of much use. xrandr is [...]]]></description>
			<content:encoded><![CDATA[<p>The problem I was facing for sometime is setting brightness of my laptop that is running Ubuntu 12.10. Unfortunately this function is not  available in my laptop. So I started my investigation to get this functionality. Then I found the <strong>xrandr</strong> command. A similar is <strong>xbacklight</strong> command, but it&#8217;s not of much use. <strong>xrandr</strong> is very typical to use, believe me it&#8217;s not handy to use for a day to day practice. So I wrote a shell script to use <strong>xrandr</strong> command easily.</p>
<p style="margin:5px">
<p>You can clone the shell script from <strong>git@github.com:manvendrasinghig/brightness.git</strong> using the standard <strong>git clone <em>url</em></strong> command from a terminal.</p>
<p style="margin:15px">
<p>Manvendra Singh<br />
manvendra@intelligrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2013/03/18/shell-script-to-control-the-brightness-of-display/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
