Archive | Data Intelligence RSS feed for this section

Pentaho – Quick Start

This goal of this post is to walk you through an awesome business intelligent framework named “Pentaho”. I believe the philosophy of “Learn by Practice”. So, I will show you the steps to get pentaho up and run for a fictitious company. Along with this exercise, you should be able to understand how Pentaho works and what features it provides. Lets start. :)

Installation of Pentaho

  1. Download Pentaho Demo (PCI) here
  2. Read Pentaho Quick Start and the Creating Pentaho Solutions pdf documents. You can get those documents from the download center above as well.
  3. Unzip the download file will result in a pentaho-demo directory. This is the server root, and it is commonly referred to as the PCI root or PCI install directory or something similar. To start the server, windows users run start-pentaho.bat; *nix users run start-pentaho.sh.
  4. Open an internet browser, and navigate to:http://localhost:8080/. This may take a little while – the server needs to warm up.
  5. Now you should see the pentaho web front. Try this sample out to make sure the setup is correctly done.
  6. When you’re done with pentaho, locate the stop-pentaho script in the PCI installation directory. Execute the script to stop de server.
  7. For more info of how to set up PCI as server and how to configure email service. Take a look at Roland blog.

Create a new sample

  1. Start pentaho demo as stated above.
  2. Create a folder named “MySQL” under %PCI%/pentaho-solutions/samples/mysql.
  3. To make mysql folder to display at the entry page. We need to put index.xml in the mysql folder. You may notice that we are using variables for name and description. The value of the variables are defined using index.properties under the same folder. The reason to do that is to support internationalization because you can define index_cn.properties for Chinese wording. Note: Click “Update Solution Repository” under Admin tab to refresh the change.
  4. Download MySQL Sample database - sakila. Here is the schema view.
  5. <index>
          <name>%directory_name</name>
          <description>%directory_description</description>
          <icon>folder.png|dashboard.jpg</icon>
          <visible>true</visible>
          <display-type>list</display-type>
    </index>

  6. Download mysql v5 database and its jdbc driver.
  7. Run sakila_data.sql and sakila_schema.sql against MySql database. Now you have your sample movie database ready.
  8. Create a file named mysql-ds.xml in $DEMO_BASE/jboss/server/default/deploy/

  9. <?xml version=”1.0″ encoding=”UTF-8″?>
    <datasources>
          <local-tx-datasource>
          <jndi-name>sakila</jndi-name>
          <connection-url>jdbc:mysql://localhost/sakila</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>root</user-name>
          <password>honr</password>
          </local-tx-datasource>
    </datasources>

  10.  Edit the file $DEMO_BASE/jboss/server/default/deploy/pentaho.war/WEB-INF/web.xml. Add the following right below solution5 resource-ref entry

    <resource-ref>
          <description>sakila</description>
          <res-ref-name>jdbc/sakila</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
    </resource-ref>

  11.  Edit the file $DEMO_BASE/jboss/server/default/deploy/pentaho.war/WEB-INF/jboss-web.xml. Add the following right below the solution5 entry.

    <resource-ref>
          <res-ref-name>jdbc/sakila</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <jndi-name>java:/sakila</jndi-name>
    </resource-ref>

  12. Copy your mysql jdbc driver library in the following directory: $DEMO_BASE/jboss/server/default/lib
  13. Create your own myFirst.xaction file.
  14. <?xml version=”1.0″ encoding=”UTF-8″?>
    <action-sequence>
          <name>myFirst.xaction</name>
          <title>%title</title>
          <version>1</version>
          <logging-level>debug</logging-level>
          <documentation>
               <author>Raymond Hon</author>
               <description>%description</description>
               <help/>
               <result-type>rule</result-type>
               <icon>SQL_Datasource.png</icon>
         </documentation>
         <inputs/>
         <outputs>
               <rule-result>
                   <type>list</type>
               </rule-result>
         </outputs>
         <resources/>
         <actions>
               <action-definition>
                      <action-outputs>
                             <rule-result type=”list” />
                      </action-outputs>
                      <component-name>SQLLookupRule</component-name>
                      <action-type>rule</action-type>
                      <component-definition>
                             <jndi>sakila</jndi>
                             <query>
                                    <![CDATA[select * from actor where actor_id = 1]]>
                            </query>
                     </component-definition>
              </action-definition>
         </actions>
    </action-sequence>

  15. Create your own myFirst.properties with title and description.
  16. Restart pentaho
  17. Open up Firefox (cough IE) and hit the following URL: http://localhost:8080/pentaho/ViewAction?&solution=samples&path=mysql&action=myFirst.xaction
  18. That’s it! :)
Leave a comment Continue Reading →

Pentaho Reporting Framework – Architecture

I am looking into Pentaho currently for my project. It looks very promising so far. Here is the video that talks about the architecure of it. Enjoy.

Leave a comment Continue Reading →

Flex – Event Propagation

There are different kinds of events in the Flex world. An event can be generated from user gesture, return of requests and component lifecycle. Use event is a two step process, (1) You need to write the handler (2) You need to register the handler to the event hook. To register event, there are two different ways:

Inline MXML way:

<mx:Button id=”myButton” click=”myhandler(event)”/>

Actionscript way:

myButton.addEventListener(MouseEvent.CLICK, myhandler);

The code above does the same job.  However, addEventListener provides more advanced control like event propagation and event priority. Event in Flex can be dispatched implicitly (user clicks on a button, the event is dispatched by the system) and explicitly (you can programmatically trigger an event).

Event propagation is an important topic for Flex programming. So, I will try to talk about what I have known on this topic here. Feel free to correct me if I am wrong. As I know, event propagation has three phases. They are capturing, at target, and bubbling. If you have an Application A contains a VBox B that has a Button C. When an user clicks the Button C, it first goes through “capturing phase”. In this phase, the event propagation through the topmost parent of C (ie. stage) and continue walk down the display object hierarchy until it reaches the original target (ie. C). The path for capturing phase is stage -> root -> A -> B -> C. When the event reaches C, the “at target phase” will be started and it just involves one object (ie. C). After that, the event bubbles up following the reverse path of the capturing phase and walk its way back up to root (C -> B -> A -> root -> stage). This is called “bubbling phase”.

fig02.jpg

As the event makes its way though each phase and each object within those phases, it calls all of the listener functions that were added for that event. This means that clicking on the Button C doesn’t limit the event to C, A and B also receive the event. Actually, they receive the event twice, once in the capturing phase and once in the bubbling phase.

However, by default, listener cannot receive event in capturing phase because the capability is turned off. To enable it, we need to set “true” to the third parameter in “addEventListener”, the “useCapture” parameter. If you don’t do that, listener would just listen to event in the “at target” or “bubbling” phase. However, it is an exclusion setting. Once you set the “useCapture” to true, it will not receive event in other phases. To get around this, you need to use “addEventListener” twice, once with “useCapture” set to false (or omitted) and once with “useCapture” set to true.  On the other hand, any listener along the path can stop the event propagation.

In the Event object, the “target” attributed is the component where the event originated (ie. C in this example) whereas “currentTarget” attribute is the component that event currently reaches. So, this attribute’s value will be changed along the propagation path. Apart from these two properties, Event object also contains properties like type (String), eventPhase (int), bubbles (boolean), and cancelable (boolean).

Leave a comment Continue Reading →

Flex – Looking into Metatag

Have you ever used [Bindable] in Flex? Do you know it is metatag? Apart from this, there are 12 more documented metatag in Flex framework. I will list them all out here for your reference:

ArrayElementType
Data type restriction like Java Generic

[ArrayElementType("String")]
public var arrayOfStrings:Array;

Bindable
Allows for easy data synchronization within the components. Bindable can be used to bind simple data, classes, complex data, functions and event. I will talk about this metatag in more detail later.

[Bindable]
[Bindable(event="eventname")]

DefaultProperty
The DefaultProperty metadata tag is used to set a single property as a default property of a class. The 3 label controls are equivalent with “text” defined as default property in the component, so you don’t need to put <text> tag around it.

<mx:label text=”Hello”></mx:label>
<mx:label>
<mx:text>Hello</mx:text>
</mx:label>
<mx:label>Hello</mx:label>

Embed
The Embed metadata tag is used to import images into your application. There are two ways to use Embed. You can either embed the image in ActionScript and assign it to a variable. Button 1 and 2 below do the same.

[Embed(source="myIcon.gif")]
[Bindable]
public var myIcon:Class;

<mx:Button label=”Icon Button 1″ icon=”{myIcon}”/>
<mx:Button label=”Icon Button 2″ icon=”@Embed(source=’myIcon.gif’)”/>

Event
The Event metadata tag is used to declare events that will be dispatched by your custom class. Adding this metadata tag to your class definition allows you to add an event handler function to the MXML tag used to instantiate your custom class. You insert the [Event] metadata tag before the class definition in an ActionScript file, or in the <mx:Metadata> block in an MXML file.

In Actionscript:
[Event(name="myClickEvent", type="flash.events.Event")]

In MXML:
<?xml version=”1.0″?>
<mx:TextArea xmlns:mx=”http://www.adobe.com/2006/mxml”>
<mx:Metadata>
[Event(name="myEnableEvent", type="flash.events.Event")]
</mx:Metadata>
….
</mx:TextArea>

Effect
The Effect metadata tag is used to define a custom effect that will be dispatched when an event occurs. An effect is paired with a trigger that invokes the effect. A trigger is an event, such as a mouse click on a component, a component getting focus, or a component becoming visible. An effect is a visible or audible change to the component that occurs over a period of time. You insert the [Effect] metadata tag before the class definition in an ActionScript file, or in the <mx:Metadata> block in an MXML file. Same as Event syntax above.

[Effect(name="darkenEffect", event="darken")]

IconFile
IconFile is used to identify the filename of a jpg, gif, or png file that will be used as the icon for your custom class. While the [Embed] meta tag can be used to embed images files, SWF files, music files, video files, etc, IconFile is only used to embed a file that will be used as the icon for the custom class.

[IconFile("icon.png")]
public class CustomButton extends Button
{}

Inspectable
The Inspectable metadata tag is used to define the attributes of your custom component that you would like to display in the code hints and property inspector of Flex Builder 2.

InstanceType
The [InstanceType] metadata tag specifies the allowed data type of a property. Example below shows that you can only assign instance data type “mx.controls.Label” to variable topRow of type IDeferredInstance.

[InstanceType("mx.controls.Label")]
public var topRow:IDeferredInstance;

NonCommittingChangeEvent
TBA

RemoteClass
TBA

Style
The Style metadata tag is used to define custom style properties for your components. Simply add the Style metadata tag or tags to your class definition and then use the getStyle method to retrieve its value. I will talk about this metatag in more detail later.

Leave a comment Continue Reading →

Flex Architecture – MVCS

I have come across an excellent article from Joe Berkovitz that talks about a “right” way to architect your application. I like this article a lot. It gives me a good refresh of what I have learnt in these years. I decide to spend a little time to go over some of the key points from this article.

Isolation and encapsulation are the keys. Isolating concerns opens the door to accommodating change, because it puts boundaries on the ripple effects of changes within the code. Isolation makes modular development and testing easy. Isolation makes it easy to have different people work on different pieces. Finally, isolation makes it easier to envision ways of improving the user experience that are generalized and powerful.

The first rule I learnt in component design is “Reduce coupling and increase cohesion”. The goal of this is to reduce the amount of interactions among components and in turn promote reusability and reduce complexity. This concept proven to be useful in my career life. The tricky part of it is to draw a line around a component and provide a clear responsibilities (ie. via interface) and interactions of it (ie. communication). A good architect can make it very clean and simple whereas a novice designer cannot make a component reusable without associated with different dependencies. In this article, the author focuses on the design in UI, but the rules apply to all aspects of design. A term “MVCS” is mentioned that adds “Services” to the common known MVC pattern. Service is responsible to encapsulate the communication with the external world. Here is the diagram of the MVCS:

MVCS

In MVCS, Model captures the state of the application. It doesn’t know any of the non-Model classes and it carries no intelligence (ie. no function but read/write for properties). According to the author:

In general, avoid functions, since they introduce more complexity, and stray interactions with non-Model objects can creep in. Complex logic for model objects usually belongs in the Controller.

However, from what I have learnt, there are certainly logics belongs to the model classes. A domain model without any behavior is termed as “Anemic Domain Model” by Martin Fowler. “…this is an anti-pattern because it’s so contrary to the basic idea of object-oriented design; which is to combine data and process together.” When I look closer, this is the model that supports the UI but not the domain model in the server side. Is the same rule applied in this area as well? On the other hand, how the model notifies the View if its state is changed? In Flex, you can define your properties as “Bindable”. Whenever the state of the model is change, an event will be fired to notify the associated View.

View references objects in Model via data binding. Bindings are used to move data from sources that change into destinations that need to be change-aware. Besides,View captures users interaction (via event handler registration) and hands off action to Controller (via calling Controller’s function in event handler). Controller, like Session, is application-wide object that should be obtained through a static instance variable to avoid having to pass all such objects all over the application.

Controller is the center of the application. It is the place where application logic and behavior are implemented. It is the only part of the architecture that communicates with all the other parts, thus relieving the View, Model, and Service packages from needing to know too much about each other.

Service objects make up a layer of objects that handle all communication with the outside world like Web Service and Http calls. Besides, Services act as factories for Operation objects; it is actually these Operations that do the work of communication by initiating requests, handling responses, and dispatching status and completion events. Why not just do it internally rather than generate the Operation for controller to call? According to the author, it gives more flexibility. However, I don’t see such much usage of this flexibility. So, I still prefer doing simple Service’s method call… :)

 

fig_09.gif

Leave a comment Continue Reading →