
Chad is a simple voting service. It provides methods to create a poll, vote for a particular poll and query the results of a particular poll.
To build the samples you need the Apache Ant build tool.
TUNGSTEN_HOME/samples/Chad.ant at the command prompt.Now you will have the Chad service deployed on WSO2 Tungsten server. You can check this by going to the AJAX Tungsten Management Console and clicking on the "Services" link on the left menu.
There are two ways that the Chad service can be invoked.
Chad Voting Application
-----------------------
Select option
1. Create Poll- Will allow you to create a poll. Note
that once a poll is created it becomes automatically open for voting and does
not need to be started using option 6
2. List All Polls- Will list title, ID, Description, Type
(single or multiple), poll status (open for vote or voting is stopped) and
choices to vote for of each poll created.
3. List Started Polls - Lists the above details of the
polls that are open for voting
4. List Stopped Polls -Lists the above details of polls
that have been closed for voting
5. Stop Poll- closes poll for voting, in other words, once
a poll is stopped one cannot vote for that particular poll
6. Start Poll- reopens a poll that is closed for voting
7. Vote Single - vote for single choice
8. Vote Multiple -vote for multiple (one or more)
choices
9. Get Result- query the results of a poll
10. Exit- exits Chad service
:
Let's consider some examples.
Example1: Single Vote (Can only vote for single choice)
Select option
1. Create Poll
...
...
9. Get Result
10. Exit
: 1
Create Poll
-----------
Poll title : Who will win the football world cup 2006?
Poll description : Find the favourite team for the football world cup 2006
Is single vote? (true/false) [false] : true
Choices (comma separated) : Brazil,France,Germany,England,Argentina
Chad poll with ID urn:uuid:89DFA56A7F11FAF640114811032495784 successfully create
d.
Select option
..
..
7. Vote Single
8. Vote Multiple
9. Get Result
10. Exit
: 7
Poll ID : urn:uuid:89DFA56A7F11FAF640114811032495784
Choice : Brazil
Vote successful
Select option
1. Create Poll
...
...
9. Get Result
10. Exit
:9
Poll ID : urn:uuid:89DFA56A7F11FAF640114810746430416
Poll Result
-----------
Poll ID =urn:uuid:89DFA56A7F11FAF640114810746430416
Title =Who will win the football world cup 2006?
Description =Find the favourite team for the football world cup 2006
Total Num of votes =1
Choices :-
Brazil - 1 (100.0%)
Argentina - 0 (0.0%)
England - 0 (0.0%)
Germany - 0 (0.0%)
France - 0 (0.0%)
Example2: Multiple Vote (Can vote for multiple choices)
Note that in this example when creating a poll, for the request, 'Is single vote? (true/false) [false]:' if you do not give an answer, it will be considered as a multiple vote as 'false' is default.
Select option
1. Create Poll
...
...
10. Exit
: 1
Create Poll
-----------
Poll title : Who's the favourite actor in Hollywood?
Poll description : Selecting the most popular actor in Hollywood
Is single vote? (true/false) [false] :
Choices (comma separated) : Brad Pitt,Tom Cruise,Heath Ledger,John Travolta,Mel G
ibson
Chad poll with ID urn:uuid:89DFA56A7F11FAF640114810862756635 successfully create
d.
Select option
1. Create Poll
2. List All Polls
...
...
10. Exit
: 2
Chad polls :
------------
Poll ID=urn:uuid:89DFA56A7F11FAF640114810862756635
Title=Who's the favourite actor in Hollywood?
Description=Selecting the most popular actor in Hollywood
Is single vote=false
Is stopped=false
Choices : Brad Pitt,Tom Cruise,Heath Ledger,John Travolta,Mel Gibson,
---------------------------------------------------
Poll ID=urn:uuid:89DFA56A7F11FAF640114810746430416
Title=Who will win the football world cup 2006?
Description=Find the favourite team for the football world cup 2006
Is single vote=true
Is stopped=false
Choices : France,Germany,England,Argentina,Brazil,
---------------------------------------------------
Select option
...
...
8. Vote Multiple
9. Get Result
10. Exit
: 8
Poll ID : urn:uuid:89DFA56A7F11FAF640114810862756635
Choices (comma separated) : Mel Gibson
Select option
...
...
7. Vote Single
8. Vote Multiple
9. Get Result
10. Exit
: 8
Poll ID : urn:uuid:89DFA56A7F11FAF640114810862756635
Choices (comma separated) : Mel Gibson,John Travolta
Select option
...
...
9. Get Result
10. Exit
: 9
Poll ID : urn:uuid:89DFA56A7F11FAF640114810862756635
Poll Result
-----------
Poll ID =urn:uuid:89DFA56A7F11FAF640114810862756635
Title =Who's the favourite actor in Hollywood?
Description =Selecting the most popular actor in Hollywood
Total Num of votes =3
Choices :-
Mel Gibson - 2 (66.67%)
John Travolta - 1 (33.33%)
Heath Ledger - 0 (0.0%)
Tom Cruise - 0 (0.0%)
Brad Pitt - 0 (0.0%)

Vote types available are 'Single Choice' where one can only vote for a single choice and 'Multiple Choice' where one can vote for one or more choices.
Note: Once a poll is created it is automatically open for voting. Voting is open until explicitly closed using stop option

To see Poll results click on the particular poll listed on any of the Polls lists pages. You will get a page as shown below.

Using the Stop action you can close voting after which one cannot vote for that particular poll. Once stopped, the Start link will appear under 'Actions' column replacing both Stop and Vote action links.
Start action reopens a poll for voting.
Vote action will take you to a page as shown below from which one can vote for his/her preferred choice. This can happen for either a single type vote or a multiple type vote.
For single type vote:

For multiple type vote:
