Monday, April 13, 2009

Workshop 3: Online Taxi Booking System: MySQL and Database design

a. Create passengers table


b. Structure of the table passengers


c. Create data 1


d. Create data 2


e. Read


f. Update


g. Destroy



1. Set up the MySQL tools



2. Rails will setup a new application directory for each of your web application projects.



3. One Rails is running you at http://localhost:3000, you need to configure database access. Connect to the database is specified in the config/database.yml file.



MySQL GUI connection settings


MySQL Administror window


Run select SQL command in MySQL GUI

Workshop 4: Riding the Rails with Ruby

To do:

1. Spend some time moving your way through the 46 Ruby coding examples in the Ruby tutorial with code from http://www.fincher.org/tips/Languages/Ruby/

In this website, there are a lot of example for coding with Ruby.

2. What are the syntax difference in the way that Ruby and Javascript use the if statement?

In Javascript, the syntax of the if statement is as follows:

if (condition)
{
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}

Example:
if (time<10)
{
document.write("Good morning");
}
or
if (time==11)
{
document.write("Lunch-time!");
}
or
if(visitor == "teacher"){
document.write("My dog ate my homework...");
}else if(visitor == "principal"){
document.write("What stink bombs?");
} else {
document.write("How do you do?");
}

In Ruby, the if statement is as follow:

if( x < 7 && x > 12 ) { ... }
or
if x.between?(7,12) do ...
or
if income < 10000
rate = 0.02
elsif income < 30000
rate = 0.28
else
rate = 0.5
end

The else if used in the Javascript, in Ruby, it uses elsif. The Ruby language does not requires to user {} mark in beginning and the end of the if statement. There is no function x.between?(7, 12) in Javascript.

3. While Ruby and Python are quite similar, can you find some similarities between Ruby and Javascript?

Both Ruby and Javascript are requiring interpeter to run. Both are object-oriented.
Both language like C++ and Java.

Challenge Problems:

1. Create, test and debug a Ruby program called dognames.rb or catnames.rb to accept 3 names from the keyboard and to display each name on the screen in alphabetical order WITHOUT using a data structure such as a list.

Code of the dognames.rb

def dognames
puts "Enter first dog name : "
name1 = gets
puts "Enter second dog name : "
name2 = gets
puts "Enter third dog name : "
name3 = gets

myarray=[name1,name2,name3]

puts "Sorted dogs names:"
print "First dog is ", myarray.sort[0]
print "Second dog is ", myarray.sort[1]
print "Third dog is ", myarray.sort[2]

end
dognames


2. Write a Ruby program called fizzbuzz.rb that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

Code:
def fizzbuzz
1.upto(100) do |temp|
if temp % 5 == 0 and temp % 3 == 0
puts "FizzBuzz"
elsif temp % 5 == 0
puts "Buzz"
elsif temp % 3 == 0
puts "Fizz"
else
puts temp
end
end
end
fizzbuzz

Result:


3. Compare the Ruby and Python versions of the dog years calculator:

#!/usr/bin/ruby
# The Dog year calculator program called dogyears.rb

def dogyears
# get the original age
puts “Enter your age (in human years): "
age = gets # gets is a method for input from keyboard
puts # is a method or operator for screen output

#do some range checking, then print result
if age < 0
puts "Negative age?!? I don't think so."
elsif age < 3 or age > 110
puts "Frankly, I don't believe you."
else
puts "That's", age*7, "in dog years."
end
dogyears

Python

#!/usr/bin/python
# The Dog year calculator program called dogyears.py

def dogyears():
# get the original age
age = input("Enter your age (in human years): ")
print # print a blank line

# do some range checking, then print result
if age < 0:
print "Negative age?!? I don't think so."
elif age < 3 or age > 110:
print "Frankly, I don't believe you."
else:
print "That's", age*7, "in dog years."

### pause for Return key (so window doesn't disappear)
raw_input('press Return>')

def main():
dogyears()
main()

By comparing both program,
a. The Python version is longer than the Ruby version.
b. The Ruby version does not require to define the main program to call the routine.
c. It is required to provide a mechanism to pause the program to hold teh result in Python while Ruby is not.
d. There is no function parameter required in Ruby program.
e. Line break or no line break output are different reserved word (puts, print) in Ruby.


Reference:

Ruby Tutorial with Code Samples (n.d.), http://www.fincher.org/tips/Languages/Ruby/

Selina D’S. (n.d.), T New Product Development with Ruby on Rails, Retrieve 10 April 2009 from www.aspiresys.com/WhitePapers/whitepaper_new_product_development-RoR_paper.pdf

w3school (2009), JavaScript If...Else Statements, Retrieve 10 April 2009 from http://www.w3schools.com/JS/js_if_else.asp

Workshop 2: Model View Controller design appraoch

To do:

1. Setup a focus group (like a study group for peer learning) to work on the Ruby on Rails workshops via Interact tools as a class.

A focus group was set for to work on Ruby on Rails workshops at http://ltang18.blogspot.com
I also joined the focus group by Dennis at http://railsfocusgroup.blogspot.com/

2. What is meant by "convention over configuration" and how does it reduce coding?

3. Further work on understanding MVC:
a. See the wiki at http://wiki.rubyonrails.org/rails/pages/UnderstandingMVC
The content does not available!

b. Do the MVC tutorial at http://wiki.squeak.org/squeak/1767
The file MVCTutorial.zip is downloaded and studied.

Challenge Problems:

1. How is Rails structured to follow the MVC pattern?

Model (ActiveRecord ) :
The relationship between Object and Database is maintained by Model. It also handles validation, association and transactions. The tables in the database is binded with the ActiveRecord library inside the Model. It interfaces Ruby program code and table to manipulates database records.

View ( ActionView )
The format for data presentation which is controlled by the controller and usually integrated with AJAX technology.
When connection to Rail application, the embedded Ruby based system inside the ActionView library set templates for displaying data as a view.

Controller ( ActionController ):
Querying models and oranizing the data for different views are handled by controller.

The ActionController inside the controller breaks the data for ActiveRecord (the database interface) and ActionView (the presentation engine). (tutorialspoint.com)


to be continued.
Figure 1. Rails Framework (tutorialspoint.com)

In Rails, the folder structure seperate the model, controller and view as follows:


Figure 2. Rails folder structure to follow the MVC pattern

2. Apply the MVC design approach to our Project: Online Taxi Booking System.


Figure 3. Interface for managing rails applications

Online Taxi Booking System application skeleton is created by applying command:
rails OTBS


Figure 4. The folder structre after applying command in rails_apps folder.

Reference:
tutorialspoint.com (n.d.), Ruby on Rails Framework, Retrieved 12 April 2009 from http://www.tutorialspoint.com/cgi-bin/printversion.cgi?tutorial=ruby-on-rails&file=rails-framework.htm

tutorialspoint.com (n.d.), Ruby on Rails Framework, Retrieved 12 April 2009 from http://www.tutorialspoint.com/ruby-on-rails/rails-framework.htm

RailsGuiders (n.d.), Getting Started with Rails, Retrieved 12 April 2009 from http://guides.rubyonrails.org/getting_started.html

Workshop 1: Setting up the model railway

The Project

a. Login MySQL, create database and passenger_origin


b. Structure of the passenger_origin


c. Create table passenger_destination and list structure


To do:

1. I have subscribed the www.buildingwebapps.com for Learning Rails.

2. I have downloaded and installed the Ruby, RubyGems and Rails from www.rubyonrails.org


Figure 1. Screen Capture of the www.rubyonrails.org

3. Due to the portability of the RoR, I have chosen to use the pre-packaged solutions - Instant Rails for Windows platform instead of the install version of the RoR.

Challlenge Problems:

1. Make a list of all programming languages and Web development tools used by you in prior experiences. describe what you know about Web application frameworks before we begins.

Languages: VisualBASIC, VB.NET, C++, HTML, ASP, ASP.NET

The web application framework I knew is that It is a 2-tier based web application.
The first layer is the web interface interact with the users and the other layer is a server side application where the business logic and database systems are on the server(s).

2. Ruby is "an interpreted scripting language" for quick and easy object-oriented programming". Find out about the Ruby language and discover what this means.

Ruby is a language created by a Japanese - Yukihiro Matsumoto (matz). It is a object-oriented progarmming language with syntax like Perl and Smalltalk. Ruby is named because pearl is the birthstone for the month June and Ruby is the birthstone is July that means Ruby is powerful and as a successor of Perl language. (Wikipedia)

3. What is Rails and how does it work with Ruby?

Rails is a framework for programming web applications. It is developed with Ruby language. With its "Don't Repeat yourself (DRY)" philosohy, Rails allowing the developer to program less code for web application development. (Wikipedia)

4. What is meant by "convertion over configuration" in regards to the use of Rails in Web application development?

The convertion over configuration means the system applies assumption to the components to reduce the developer to change the settings that not involved with the web application. This reduces the developer to tweaking the unconventional parts of the application and architecture. (Jeremy)

5. When did Model-View-Controller begin and where is it used?

The Model-View-Controller (MVC) begins in 1978. It was used to support the
user's mental model to provide information for user checking and editing with its editor. (Trygve)

6. Describe the steps involved with the MVC design approach.

In Model-View-Controller design pattern, the web application is splitted into three seperate parts - Model, View and Controller.

Model is used to handle data and logic where the representation of the data for business are handled.

The View is used to handle the output to users. It retrieves information from model to output for users.

The Controller is used to hand input from users. The input can effect to the model and/or view in order to response to user input.

The relationship of the MVC and it structure is shown as follow:


Figure 2. Model-View-Controller pattern (java.sun.com 2002)

Reference:
About Ruby, Retrived 12 April 2009 from http://www.ruby-lang.org/en/about/

Wikipedia (n.d.), Ruby (programming language), Retrived 12 April 2009 from http://en.wikipedia.org/wiki/Ruby_(programming_language)

Improving designs with the MVC design pattern (2004), Retrived 12 April 2009 from http://java.sun.com/developer/EJTechTips/2004/tt0324.html

Java BluePrints: Model-View-Controller (2002), Retrived 12 April 2009 from http://java.sun.com/blueprints/patterns/MVC-detailed.html

Trygve, M. H. R. (n.d.), MVC XEROX PARC 1978-79, Retrived 12 April 2009 from http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html

Jeremy M. (February 2009), Patterns in Practice: Convention Over Configuration, Retrived 12 April 2009 from http://msdn.microsoft.com/en-us/magazine/dd419655.aspx

Sunday, March 29, 2009

Exercise 9: Web form design and processing: A basis for e-commerce interaction

1. Design the form

"Retrofit the form data string above for buying some French perfume into the HTML fields and submit button on the web page form.

Code of the form:




Display result of the form:


2. Write the script
Script archive exists for PERL, Python and Javascript. Search the Web for a script that processes the HTML forms data. Read the code and list the steps involoved in processing the form.

The source code to process the form is found in the tutorialspoint.com. It uses the PERL as language to process form at server side.


Figure 1. HTML code from tutorialspoint.com


Figure 2. PERL code from tutorialspoint.com

The first line is the header of the program which locates the PERL interpeter.

The second part is to extract the information from the string from the form and put them into variables.

The string send from the FORM to PERL program after clicking submit:
http://127.0.0.1/cgi-bin/checkout.pl?name=Raymond+TANG&email=ray@hotmail.com&item=French+Perfume&qty=2&paym=VISA&cname=Raymond+Tang&cno=00123456789&submit=Checkout

The final part displays the information according to the user to screen as normal webpage.


3. Can you modify the script to process the form?

The script is modified as follows:


Due to the difference in the platform (Operating System), the starting part (Header) for perl language is changed. The perl interpeter in use is called strawberryperl from strawberryperl.com. It is a perl interpeter for Windows platform. The version I used to run the script is 5.10.0.3.

Result of the trial run with the designed form:



Reference:
TutorialsPoint.com (2009), PERL and CGI Tutorial, Retrieved 8 April 2009 from http://www.tutorialspoint.com/perl/perl_cgi.htm

Exercise 10: Application server platfoms in e-commerce

1. Go to the website of IBM, Oracle, Microsoft and Sybase. Is there any mention of e-commerce associated with their database products? What suite or partnership do they list with related e-commerce offerings? How do they compare with open source product like MySQL?

IBM
In the website of IBM, the product associated to e-commerce is WebSphere Commerce.
This product comes with three difference versions: Enterprise, Professional and Express. Each version is designed for difference size of companies and the business use.

The database associated with the WebSphere Commerce is the DB2 database from IBM.
The DB2 is the unique choice for the express version of Websphere. In the Professional and Enterprise version of the WebSphere, Oracle Database can be chosen as the database backend as shown in Figure 1.


Figure 1. Database Choice for Websphere (IBM)

Oracle
In Oracle website, the product found for the e-commerce is E-Business Suite.
However, the E-Business suite provide Oracle's database product to their customers only.

During 2002, Red Hat India partner with Oracle to deploy the products into Linux platform.

There are several partners with Oracle including Independent software vendor, Platform partners, System integrator and reseller and distribution Alliances.

Microsoft

The Micrsoft provide e-commerce solution with Microsoft Commerce Server.

According to Microsoft (2009), the commerce server requires Microsoft SQL server as its database (Figure 2).


Figure 2. Partial requirement of the Commerce Server 2009 (Microsoft MSDN)

Sybase

Sybase provides Sybase Enterprise Application Server as its product for e-commerce.
The database system used by the server is the Sybase Adaptive Server.

The database comes with three editions: express, developer, small business and enterprise (Figure 3).


Figure 3. Sybase Adaptive Server Enterprise Editions (Sybase 2007)

Comparasion between databases:


Figure 4. Hardware requirement of the database (Alesheikh, A. A., Dodge, S.)


Figure 5. Comparasion on features of database (Alesheikh, A. A., Dodge, S.)


Figure 6. Comparasion on database as review (Alesheikh, A. A., Dodge, S.)

MySQL is a free SQL server with minimum system reqirement and resources. Oracle and DB2 and MySQL database can run on all operating systems. By comparing the storage space and easy to use, Microsoft's SQL Server provide friendly-to-use interface while DB2 and Oracle database can support terabytes data. (Alesheikh, A. A., Dodge, S.)

2. Why is the perception getting stronger that integration will become critical factor in coming days? What is the role of AJAX within enterprise software architecture?

The traditional way (Figure 7) which only use the web server to handle the users requests for dynamic information leads heavy server requests. The loading time and response time of the web application become long and may be unacceptable. When there is a web application require user to interact frequently, the web application server and web server may not be able to handle with.

With the use AJAX, the faster response time is made and a large number of the server requests decreases. It is because of the use the AJAX engine. The AJAX engine like a hidden layer to both web server and user interface. It is used to handle the requests which does not transfer back to server, for example, simple data validation and editing data in memory. When there is a request requiring servers' response, the request will be handled asynchronously. (Garrett 2005)


Figure 7. Classic Web Application Architecture (Denis)


Figure 8. The traditional model for web applications (left) compared to the Ajax model (right). (Garrett 2005)


Figure 9. The synchronous interaction pattern of a traditional web application (top) compared with the asynchronous pattern of an Ajax application (bottom). (Garrett 2005)

3. What are the similarities between the object-oriented developemnt using model-view-controller (MVC) in Ruby on Rail 2.0 and Action Script 2.0 (Flash Animations)?

There are several similarities between them:

Both emphize DRY (don't repeat yourself) / code reuse concept.

According to Colin (2004), the classes and interfaces of the mvc in Adobe Actionscript 2.0 are:

View: An interface all views must implement
Controller: An interface all controllers must implement
AbstractView: A generic implementation of the View interface
AbstractController: A generic implementation of the Controller interface

According to Michael (2007), the classes and interfaces of the MVC in Ruby on Rails are:

Controller: Interacts with Model and View.
Model: Data representation and business logic.
View: Rends the Model in to a View

Model: ActiveRecord
Contains business logics

View: ActionView
It is used to renders the view

Controller: ActionController
It is used to control application flow and the view to use

Reference:
IBM (n.d.),
WebSphere Commerce V6.0 software requirements - Windows, Retrieved 10 April 2009 from http://www-01.ibm.com/support/docview.wss?rs=3046&uid=swg27007591

Microsoft (n.d.), Commerce Server 2009, Retieved 10 April 2009 from http://www.microsoft.com/commerceserver/en/us/overview.aspx

Oracle (2002), Red Hat India Partners With Oracle India,
Retrieved 10 April 2009 from http://www.oracle.com/global/in/pressroom/redhatpartner.html

Oracle (n.d.), Oracle E-Business Suite Tools and Technology,
Retrieved 10 April 2009 from http://www.oracle.com/technology/products/applications/ebs/index.html

Sybase (n.d.), Sybase EAServer 6.0 Data Sheet, Retrieved 10 April 2009 from http://www.sybase.com/detail?id=1061861

Sybase (2007), Sybase Adaptive Server Enterprise Editions, Retrieved 10 April 2009 from http://www.sybase.com/files/Data_Sheets/ase_clusters_ds.pdf

Alesheikh, A. A., Dodge, S. (n.d.), Evaluating different approaches of spatial database management for moving objects, Retrieved 10 April 2009 from http://www.gisdevelopment.net/technology/gis/me05_021b.htm

Interakt (10 November 2005), AJAX: Asynchronously Moving Forward, Retrieved 10 April 2009 from http://www.interaktonline.com/support/articles/Details/AJAX%3A+Asynchronously+Moving+Forward-Introduction.html?id_art=36&id_asc=306

Garrett, J. J. (18 February 2005), Retrieved 10 April 2009 from http://www.adaptivepath.com/ideas/essays/archives/000385.php

Denis, H. (n.d.), Software Architecture, Retrieved 10 April 2009 from http://coronet.iicm.tugraz.at/sa/s5/sa_www.html

Colin, M. (2004), Essential ActionScript 2.0 [Electronic verion], O'Reilly, Retrieved 10 April 2009 from http://www.adobe.com/devnet/flash/articles/mv_controller/as2ess_ch18.pdf

Michael P. J. (2007), MVC Demystified: Essence of Ruby on Rails, Retrieved 10 April 2009 from http://www.slideshare.net/codeinmotion/mvc-demystified-essence-of-ruby-on-rails

Exercise 11: XML Introduction

1. Conduct research on the Internet to find out what tools can be used to parse an XML document and encure the document is well formed and valid.

XML parsers are used to paese an XML document. There are two type of parsers, validating and non-validating.

According to the Ken (2000), the two type of parsers are:

"non-validating: the parser does not check a document against any DTD (Document Type Definition); only checks that the document is well-formed (that it is properly markedup according to XML syntax rules)

validating: in addition to checking well-formedness, the parser verifies that the document conforms to a specific DTD (either internal or external to the XML file being parsed)."

There are several tools can be used to parse an XML document and ensure that the document is well formed and valid.

Xerces
There are several version for Xerces which are written in different language for different platforms.

Apache Xerces C++ is written in C++
Apache Xerces2 Java is written in Java
Apache Xerces Perl is written in Perl

IBM's XML Parser for Java
IBM stated that it is a validating XML parser, written in Java to allow applications to read and write XML data.

MSXML
Microsoft XML Core Services (MSXML) allows Microsoft Development tools to run as native XML-based applications.

2. What are the benefits of adopting a schema standardized for a business sector?

The w3schools.com stated that the benefits of using the schema standardized are in FOUR sectors:

a. XML Schemas Support Data Types
By defining the data formats in the schema, the correctness of data can be checked. Some of the restricted information can be restricted from viewing by others. The conversion of the data become easier. (W3schools)

b. XML Schemas use XML Syntax
As the schema uses XML syntax, it is not necessary to learn a new programming language. By changing the content of the schema and parse it, the schema can be converted into other format such as XSLT and XML DOM easily. (W3schools)

c. XML Schemas Secure Data Communication
With the Schema, the information is standardized in a proper format and can easily be understand. For example: the format of the date, in XML data type, the format of date is "YYYY-MM-DD". (W3schools)

d. XML Schemas are Extensible
Due to the fact that the schemas are written in XML, the schema can be reused. Different schemas can be reference to a docuemnt. (W3schools)

3. SMIL is an application of XML. What is the purpose of this technology? Where does it apply?

SMIL is stand for Synchronized Multimedia Integration Language. It is used for presenting and interacting the synchronize multimedia such as video, audio and pictures.
The SMIL control the timing of the medias, produce different versions of products by controlling the bandwidth and languages. (SOA Definitions)

Reference:
Apache.org (27 March 2009), The Apache Xerces Project, Retrieved 10 April 2009 from http://xerces.apache.org/

Ken S. (29 July 2000), XML Software Guide: XML Parsers, Retrieved 10 April 2009 from http://wdvl.internet.com/Software/XML/parsers.html

SOA Definitions (31 July 2001), SMIL, Retrieved 10 April 2009 from http://searchsoa.techtarget.com/sDefinition/0,,sid26_gci214217,00.html

W3Schools (n.d.), Why Use XML Schemas?, Retrieved 10 April 2009 from http://www.w3schools.com/Schema/schema_why.asp