Retarded


Will somebody tell these retarded people that, space is not a very special character and its very common in Indian names. Whats worse is that, its an Indian ticket booking site.

Web services and Eclipse BIRT

  1. Create the Java classes from the WSDL, may be using Apache AXIS WSDL2Java. (WSDL Used here -http://soap.amazon.com/schemas2/AmazonWebServices.wsdl)
  2. Create a new BIRT project, named AmazonSearch.




3. After the project is created, create a new blank report.

4. Add a new scripted data source to the report.

5. Add a new dataset to the report.

6. Create the needed columns in the dataset.


7. Add the code for handling open and fetch events of the dataset. This can be done using, either the report script or Java. Here java will be used.



8. Create a class named, AmazonKeywordSearchEventHandler and extend the class "org.eclipse.birt.report.engine.api.script.eventadapter.ScriptedDataSetEventAdapter".



9. Override the methods, open and fetch.




package com.amazon.events;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.api.script.IUpdatableDataSetRow;
import org.eclipse.birt.report.engine.api.script.ScriptException;
import org.eclipse.birt.report.engine.api.script.eventadapter.ScriptedDataSetEventAdapter;
import org.eclipse.birt.report.engine.api.script.instance.IDataSetInstance;

import com.amazon.soap.AmazonSearchBindingStub;
import com.amazon.soap.AmazonSearchServiceLocator;
import com.amazon.soap.Details;
import com.amazon.soap.KeywordRequest;
import com.amazon.soap.ProductInfo;

public class AmazonKeywordSearchEventHandler extends
ScriptedDataSetEventAdapter {

Details[] details;

int currPage;

int totalPages;

int currRow;
String reportParam = "harry potter";

public void open(IDataSetInstance dataSet) {
KeywordRequest keyRequest = new KeywordRequest();
keyRequest.setDevtag("14PXWE73YT3NR4PBEDR2");
keyRequest.setTag("14PXWE73YT3NR4PBEDR2");
keyRequest.setKeyword(reportParam);
keyRequest.setPage("1");
keyRequest.setMode("books");
keyRequest.setType("heavy");


try {
AmazonSearchServiceLocator abv = new AmazonSearchServiceLocator();

AmazonSearchBindingStub abs = (AmazonSearchBindingStub) abv
.getAmazonSearchPort();

ProductInfo pi = abs.keywordSearchRequest(keyRequest);

details = pi.getDetails();
totalPages = Integer.parseInt(pi.getTotalPages());
System.out.println(pi.getTotalPages());
currPage = 1;
currRow = 0;

} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// details = CockpitObjects.getStatusCount();

}

public boolean fetch(IDataSetInstance dataSet, IUpdatableDataSetRow row) {
if (currPage == totalPages) {
return false;
}
if (currRow == details.length)
getMore();

Details node = details[currRow];
try {
row.setColumnValue("ProductName", node.getProductName());
row.setColumnValue("Author", node.getAuthors()[0]);
row.setColumnValue("URL", node.getUrl());
row.setColumnValue("ImageURL", node.getImageUrlSmall());
} catch (ScriptException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

currRow++;
return true;
}

public void getMore() {
currPage++;

KeywordRequest keyRequest = new KeywordRequest();
keyRequest.setDevtag("14PXWE73YT3NR4PBEDR2");
keyRequest.setTag("14PXWE73YT3NR4PBEDR2");
keyRequest.setKeyword(reportParam);
keyRequest.setPage(Integer.toString(currPage));
keyRequest.setMode("books");
keyRequest.setType("heavy");

try {
AmazonSearchServiceLocator abv = new AmazonSearchServiceLocator();

AmazonSearchBindingStub abs = (AmazonSearchBindingStub) abv
.getAmazonSearchPort();

ProductInfo pi = abs.keywordSearchRequest(keyRequest);

details = pi.getDetails();
currRow = 0;

} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}



10. Now attach this class as the event handler for the dataset.

11. Insert the dataset in to the report layout. And modify the report to suit your needs. Thats it. Now its ready to go.

12. Now all we need to do is, make the search string as a parameter to the report.

Once that is done, override the method beforeOpen in the event handler and get the parameter value. Use this value to search for items in Amazon.




public void beforeOpen(IDataSetInstance dataSet,
IReportContext reportContext)
{
reportParam = (String) reportContext.getParameterValue("Keyword");
}