Friday, November 19, 2010

Generating project structure using Maven

To generate the project structure using maven, we use maven's archetype mechanism. In Maven, an archetype is a template of a project which is combined with some user input to produce a working Maven project that has been tailored to the user's requirements (This help you generate the desired project structure depending on the application that you are trying to build.)


Following I have shown how you can use maven to generate a project structure for simple java application.


mvn archetype:create -DgroupId=org.wso2.carbon -DartifactId=sample -DarchetypeArtifactId=maven-archetype-quickstart


This will generate a project structure as follows



|-- sample
|   |-- pom.xml
|   `-- src
|       |-- main
|       |   `-- java
|       |       `-- org
|       |           `-- wso2
|       |               `-- carbon
|       |                   `-- App.java
|       `-- test
|           `-- java
|               `-- org
|                   `-- wso2
|                       `-- carbon
|                           `-- AppTest.java



This will create App.java with package name as org.wso2.carbon and create default pom.xml as well as AppTest.java class for unit testing.

Friday, November 12, 2010

How to find files in Ubuntu using Terminal

Case insensitive searches can be achieved by using the -iname switch

find /home -iname '*.mpg' -o -iname '*.avi'


Let'search for .avi files bigger than 700M. This can be done with.

find /home/ -name '*.avi' -a -size +700M


Now, let's find the same subset of files that were modified less than 15 days ago

find /home/ -name '*.avi' -a -size +700M -mtime -15

Thursday, November 11, 2010

Creating a simple data service using WSO2 Data Services Server

Here I am going to illustrate, how to use WSO2 Data Services Server for exposing data in a mysql database as a service.

Prerequisites

  • WSO2 Data Services Server - download it from here 

  • MySQL 5 or later version - download it from here

  • JDK 1.5 or Higher

Let's create a database with a single table. Below I have given a mysql script for creating database with some data.


--
-- Create schema AccountDB
--

CREATE DATABASE IF NOT EXISTS AccountDB;
USE AccountDB;

--
-- Definition of table `AccountDB`.`account`
-- 

CREATE TABLE  `AccountDB`.`account` (
  `account_no` int(10) unsigned NOT NULL,
  `name` varchar(45) NOT NULL,
  `balance` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `AccountDB`.`account`
--

INSERT INTO `AccountDB`.`account` VALUES  (1,'Michael',2000),
 (2,'David',3000),
 (3,'Kasun',1500),
 (4,'Mike',1500),
 (5,'Lucas',1500),
 (6,'John',1500),
 (7,'Robin',1500),
 (8,'Daniel',1500),
 (9,'Paul',1500),
 (10,'Oliver',1500);

Here I have given the data services configuration file that I used.  You can refer this  documentation for creating the data service using data services server user interface, or you can write the dbs configuration file and upload it to data services server. Since we are using a MySQL database, you should copy mySQL JDBC driver to DSS_HOME/repository/components/lib


Here I have given my data services configuration file

<data name="AccountDataService" enableBatchRequests="false" enableBoxcarring="false" serviceStatus="active">  
   <config id="Account">     
      <property name="org.wso2.ws.dataservice.driver">

          com.mysql.jdbc.Driver
     </property>     
      <property name="org.wso2.ws.dataservice.protocol">

          jdbc:mysql://localhost:3306/AccountDB
     </property>   
      <!-- use your own mysql database username -->      
      <property name="org.wso2.ws.dataservice.user">root</property>    

      <!-- use your own mysql database password -->     
      <property name="org.wso2.ws.dataservice.password">password</property>      </config>  
   <query id="AccountDetails" useConfig="Account">     
      <sql>select account_no, name, balance from account </sql>     
      <result element="account_details" rowName="account"> 

         <!-- mapping database columns to output field-->       
         <element name="accountNo" column="account_no" xsdType="xs:integer" />        
         <element name="name" column="name" xsdType="xs:string" />        
         <element name="balance" column="balance" xsdType="xs:integer" />     
      </result>  
   </query>  
   <operation name="getAccountDetails">     
      <description></description>     
      <call-query href="AccountDetails" />  
   </operation>
</data> 


After uploading the dbs file to the Data Services Server, Now you can see the Newly added AccountDataService in the services page. (Go to Manage->Services->List). Then you can try the service using "Try it".




 

Ubuntu Terminator useful shortcuts


Screenshot of the Terminator 
 

 Ctrl+Shift+X -  Toggle between  showing  all  terminals  and  only  showing  the current 
 one.

 Ctrl+Shift+O - Split terminals Horizontally.

 Ctrl+Shift+E - Split terminals Vertically.

 Ctrl+Shift+Right - Move parent dragbar Right.

 Ctrl+Shift+Left - Move parent dragbar Left.

Ctrl+Shift+Up - Move parent dragbar Up.
Ctrl+Shift+Down - Move parent dragbar Down.
 Ctrl+Shift+W - Close the current terminal.

 Ctrl+Shift+T -   Open new tab

 Ctrl+Plus (+) -  Increase  font  size. Note: this may require you to press shift, depending on your keyboard

 Ctrl+Minus (-) - Decrease font size. Note: this may require you to  press  shift, 
 depending   on your  keyboard
  
 Ctrl+Zero (0) - Restore font size to original setting.

Wednesday, November 10, 2010

InteliJ IDEA shortcut keys

IntelliJ IDEA is a Java IDE by JetBrains, It is more powerful IDE for java developments. Also It has lots of shortcut keys that make developers life easier. Below Image I have shown all most all IDEA shortcut keys.




Friday, November 5, 2010

Useful SVN commands

svn add
svn add - Add files and directories to your working copy and schedule them for addition to the repository. They will be uploaded and added to the repository on your next commit.
svn add --non-recursive testDir - You can add a directory without adding its contents 
svn add * --force - If you want to add every unversioned object in your working copy

svn update 
svn up | svn update - Update your working copy.
svn up -r8000 update your working copy to an older revision (revision 8000)

svn checkout
svn co | svn checkout -  Check out a working copy from a repository.
svn co https://wso2.org/repos/wso2

svn delete
svn del | svn delete - Delete an item from a working copy or the repository.
svn del testDir

svn mkdir
svn mkdir Create a new directory under version control.
svn mkdir testDir

svn commit
svn ci | svn commit - Send changes from your working copy to the repository.
svn ci -m "Added new functionality." 

svn move 
svn move | svn mv — Move a file or directory
$svn mv parentDir/test.txt parentDir/subDir
A         parentDir/subDir/test.txt
D         parentDir/test.txt


svn cleanup
svn cleanup - Recursively clean up the working copy, removing locks resuming unfinished operations. If you ever get a “working copy locked” error, run this command to remove stale locks and get your working copy into a usable state again.

svn blame 
svn blame — Show author and revision information in-line for the specified files or URLs. (This is only for files)
As an example 

svn blame https://wso2.org/repos/wso2/trunk/carbon/core/samples/pom.xml


 15686    saminda <project xmlns="http://maven.apache.org">
 15686    saminda     <parent>
 15686    saminda         <groupId>org.wso2.carbon</groupId>
 15686    saminda         <artifactId>carbon-parent</artifactId>
 72444    ruwan         <version>3.1.0-SNAPSHOT</version>
 15686    saminda     </parent>
 15686    ruwan     <modelVersion>4.0.0</modelVersion>
 15686    saminda     <artifactId>samples</artifactId>
 15686    saminda     <packaging>pom</packaging>
 15686    saminda     <name>samples</name>
 15686    saminda     <description>samples</description>
 15686    saminda     <url>http://wso2.org</url>
 15686    saminda     <modules>
 15687    saminda         <module>org.wso2.carbon.sample</module>
 15686    saminda     </modules>
 15686    saminda </project>

svn diff
svn diff - Display the differences between two paths.
svn diff trunkDir - Compare repository and your working copy.
svn diff  -r 3900 trunkDir - working copy's modifications compare against an older revision
svn diff https://wso2.org/repos/wso2/trunk/carbon/pom.xml@3000  https://wso2.org/repos/wso2/trunk/carbon/pom.xml@3010 - Compare revision 3000 to revision 3010 using “@” syntax

svn cat
svn cat -  Output the contents of the specified files or URLs.
$svn cat https://wso2.org/repos/wso2/trunk/test/readme.txt - you can view readme.txt in your repository without checking it out

svn log
svn log - Display commit log messages.
svn log - sample log is shown below.

------------------------------------------------------------------------
r121 | pradeeban | 2010-10-17 01:13:37 +0530 (Sun, 17 Oct 2010) | 2 lines
Applying the patch for ARCHITECTURE-25 provided by kasunw. BPS loan approval demo was added with necessary documentation with minor change to Account Service client, in this patch. 
------------------------------------------------------------------------
r119 | lahiru | 2010-10-16 23:09:01 +0530 (Sat, 16 Oct 2010) | 2 lines
applying patch from kasun for https://wso2.org/jira/secure/ManageAttachments.jspa?id=25441.
------------------------------------------------------------------------
r118 | lahiru | 2010-10-16 23:07:56 +0530 (Sat, 16 Oct 2010) | 2 lines
applying patch from kasun.
------------------------------------------------------------------------
r117 | lahiru | 2010-10-16 22:42:04 +0530 (Sat, 16 Oct 2010) | 2 lines
adding patch given by kasun.
------------------------------------------------------------------------
r116 | kasunw | 2010-10-15 00:44:58 +0530 (Fri, 15 Oct 2010) | 2 lines
changes to platform demo, using carbon studio, and minor feature adding like automating using ant.

svn revert
svn revert - Undo all local edits.
svn revert foo.java 
svn revert testDir --recursive - If you want to revert a whole directory of files, use the --recursive flag.

svn resolved
svn resolved - Once you've resolved the conflict, run svn resolved to let your working copy know you've taken care of everything

svn list
svn list - List directory entries in the repository.
svn list https://wso2.org/repos/wso2/trunk/carbon
components/
core/
dependencies/
features/
orbit/
pom.xml
products/


Thursday, November 4, 2010

Stream processing on WWW data

This is about my final year project at university of Moratuwa. We named this project as Glutter, the name 'Glutter‘ is the result of a combination of the words 'Clutter‘ and 'Gutter‘. So as the name implies, 'Glutter‘ operates as a gutter which is connected to a clutter of information. In other words, it enables the users to gather information from various sources and then set up rules for how that content should be filtered and modified to fit the requirements of the users.


This projetct is something similar to the Yahoo Pipes, because Yahoo Pipes also works by enabling users to gather information from different sources and then setting up rules on how that content should be modified (Filtering, renaming, truncating , translating etc.). But the main limitation of yahoo pipes is that it is not aware of temporal aspects and causality of events in the web which hinders the usefulness drastically. Therefore as a solution to that we introduce the Glutter. The approach in Glutter is to use Complex Event Processing on web events thus enabling temporal querying and an awareness of causality in its operators. It supports more input and output means such as Twitter, Email, Feeds, Web services, CSV data, XMPP Chats etc, thus making it more connected to the real-time web.


The following video shows the concept of the project.




when a typical internet user steps into the internet, the information keep flowing at him in a real time manner and its difficult for his to keep track of it. also the internet is a huge mess of data and to make things worse, its a dynamically changing mess. Therefore Glutter can acts as an intermediate in between the clutter of information and the web user, so by using Glutter he can get only information that he is interesting, in real time manner.


The main objective of Glutter is to empower the user by allowing him to decide what, when, and how to view and get-notified-of information in the web without the developers designing and deciding it(Without even writing a single line of code). The client is provided a sophisticated workbench to create workflows according to his preference in order to decide 'what‘ to view and when the information should be delivered.


For creating workflows we have given a user interface (Workbench), which allows users to create workflows and run them against web data sources. The workbench consists of a toolbox containing drag and drop components which could be used to construct workflows using a graphical user interface. The main components can be categorized as,

  • Connectors - Connectors are used to establish the connection to various data sources. Currently Glutter consists of 5 connectors which support RSS/ Atom Feeds, EMail (pop/imap), Twitter, CSV, and Pull based Querying of Webservices.
  • Operators - Operators allow the user to perform many different operations on the stream. 
  • Sink - Sinks are the end components of a workflow, and users can get the output of the workflow in many different forms such as an EMail, a Tweet, XMPP Message, or can be viewed in the viewer section.
All components are listed below



Following I have shown a sample workflow


In this scenario, user is interested in particular news, but those news are in different languages, also user is interested to know, which country belongs that news. Then he can use Glutter to do his task. As shown in the above figure. User get feeds in Dutch, Spanish languages and another one from English language. Those news feeds can be fetched using 3 feed connector, then he can use our translate operator to translate news feeds to English language. Now all  different language feeds are converted to English then by using union operator he can get all feeds as one feed. Since he need to view the news based on Geo location, we can use semantic operator to do this task. Because it can analyse the text and can extract geo location within that text semantically, then these Geo location details are added to every news feed item. After that those results are sent to the data sink, so that it can be viewed using Viewer which support map view. 

Following I have shown the map viewer.


This is only one example that I have given to show the power of the Glutter. Bellow I have given other use cases


  • Another possible use case could be redirection of data channels. That means fetch interesting tweets to email or chat, also you can feed your blog to twitter (you could add more filtering operations in between in order to control what gets tweeted from your blog).  
  • Email auto-replier.
  • Send notification emails when price below some level for ebay item.
  • Stock market data related chat notification (when price increase and decrease) (can use pattern recognition operator)
  • When interesting feed comes user can do the google search (using web service operator) based on content of the feed and get addition links for that news.
  • There are many more. It depends on the creativity of the user :) (Since we have given lot of connectors, operators and sinks)
The some of resulting viewers are shown below.

Line Chart

Area Chart

List View