Sunday, May 25, 2008

Webmethod and database (Experience part 2)

I think this is quite interesting regarding webmethod usage. As you know, webmethod provides you a custom flow steps through Java source code. Currently, I am doing research on how to webmethod connects to database. I am not sure if webmethod has provided you flow steps to do this. but currently I am using Java source to connect to database.

There are several way to get connection to db:
1. Using JDBC code. May be this way is a standard way for all of Java programmer. You can find this way in many resources in internet.
2. A class provided by webmethod. This class acts as an intermediary to connect to DB. Even this class uses JDBC to connect. I assume this class uses JDBC driver and bundle several steps in one method called getConnection(url, username, password, drivername). This method is located at DBConnection class.

For example:
If I use JDBC driver, I need to write the following steps:
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/confluence28?user=root&password=arie");

But if we use the webmethod class, we only need to specify one line:
DBConnection dbConnect = db.getConnection("jdbc:mysql://localhost/confluence28", "root", "arie", "com.mysql.jdbc.Driver");

Saturday, May 24, 2008

Experience on WebMethod (Part 1)

Several days ago, my boss (read: my company) gave me a short course on webmethod. This tool is used for integration. Very nice word, it sounds so elegant. However, in the first time I learn this tool, I felt so difficult to learn. Why? because I was not really familiar with the documentation. Besides, there are not a lot of people using this tool. After several days struggling on getting familiar with the flow steps, I can finish all of the exercises that I got from my company.

Last night, I was doing research on how to integrate with flow steps written in Java. Damn, I get an error message saying that no compiler found (this is not the real message). After reading, I found that I need to put a path to the compiler in system path. After making changes on it, I get another error message saying that I need to compile the resource (What the heck !!!!). I was desperate. I thought I had put the correct path and the previous error had been solved. After several hours playing around with the compiler path, I found that I have to use WM compiler instead of my own compiler which is a java compiler that I installed on my PC. Huuuuhh.... succkksss....

In order to make your Java code compiled and run correctly, you need to put compiler bundled by WM. It is located at /jvm/win142/bin. Just put the path into your System path. Then everything works fine.

Wednesday, May 14, 2008

Getting the result of all filter in JIRA

Today, I get another new knowledge regarding JIRA stuff. Currently, I am developing a report plugin in JIRA. This afternoon, I got a problem on populating a value of all saved filters in JIRA. These values are used for specifying parameter in the report plugin. However, after doing some research on JIRA source code. I found the following source code which is used for populating parameters in report plugin.

List savedFiltersList = ManagerFactory.getSearchRequestManager().getVisibleRequests(user);
savedFilters = new HashMap();

for (Iterator iterator = savedFiltersList.iterator(); iterator.hasNext();)
{
GenericValue request = (GenericValue) iterator.next();
savedFilters.put(request.getLong("id").toString(), request.getString("name"));
}


By returning variable savedFilters, then JIRA will populate the value of select component automatically.

SQL Updating certain pattern of text in MySQL

There are a way to update a text in some database with certain pattern. Today I get a case regarding this problem. In order to update a content in a column of a table, you can use the following command:

mysql> update bodycontent SET body = REPLACE ( `body` ,'google.com','arie.ganten
g.com');

The above query will update table bodycontent, body column which content is google.com, to arie.ganteng.com.

Sunday, May 4, 2008

Experience on Apache POI

Today, I am doing experiment on Apache POI. Company asked me to create plugin for JIRA which is not within my scope as Confluence support engineer. However, I really enjoy it. One feature that I create in the plugin is an ability to convert data within JIRA to excel file. Actually, there are several options that I can use to export to excel file. I have searched through several websites where another peoples have done some research on it and they come with the conclusion that Apache POI is better than the other.

The most important thing on Apache POI is HSSFWorkbook object. This object represents one excel file. One workbook consists of one or several sheets. And one sheet contains several rows and columns.

Below is an example on how to create workbook:

HSSFWorkbook workBook = new HSSFWorkbook();
sheet = workBook.createSheet("Product");
HSSFRow row = sheet.createRow(1);
HSSFCell cell = row.createCell((short) (1));

What a simple code...... hehehe.... Note that the second line is used for creating a sheet named Product and POI will start the index of row and column with 0 instead of 1. Thus the above code will create object row in line 2 (in the excel file, row is started from 1 instead of 0) and will create a cell in column B(in the excel file, column is started from A instead of 0).

In order to fill in the value in the cell, POI has provided you a method setCellValue(). Please take a look at the API documentation for detail information regarding this method.

Another thing that I really like with POI is the ability to manipulate style in every cell. The style is including a way to format the data inside cell. In the plugin that I create, I use an ability of POI to manipulate border of each cell in the sheet. Below is an example to use HSSFCellStyle:
HSSFCellStyle style = workBook.createCellStyle();
style.setBorderTop(style.BORDER_THIN);
style.setBorderBottom(style.BORDER_THIN);
style.setBorderLeft(style.BORDER_THIN);
style.setBorderRight(style.BORDER_THIN);
style.setAlignment(style.ALIGN_CENTER);
style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

In order to apply the style on each cell, POI has provided us a method named cell.setCellStyle(style). This method has a parameter HSSFCellStyle which you has manipulated in the previous example.