Wednesday, November 27, 2013

RTC Java API - Get list of projectAreas

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

import com.ibm.team.process.client.IProcessItemService;
import com.ibm.team.process.common.IProjectArea;
import com.ibm.team.repository.client.ILoginHandler2;
import com.ibm.team.repository.client.ILoginInfo2;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.client.login.UsernameAndPasswordLoginInfo;
import com.ibm.team.repository.common.TeamRepositoryException;

public class ProjectAreas {

public static void main(String[] args) {
IProgressMonitor monitor = new NullProgressMonitor();
final String userId = "username";
final String password = "password";
String repoUri = "https://RTCSERVER/jazz";

TeamPlatform.startup();
try {
// Login to the repository using the provided credentials
ITeamRepository repo = TeamPlatform.getTeamRepositoryService().getTeamRepository(repoUri);
repo.registerLoginHandler(new ILoginHandler2() {
@Override
public ILoginInfo2 challenge(ITeamRepository repo) {
return new UsernameAndPasswordLoginInfo(userId, password);
}
});
repo.login(monitor);

IProcessItemService connect = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
List p = connect.findAllProjectAreas(null, monitor);

repo.logout();
} catch (TeamRepositoryException e) {
/* Handle repository exceptions such as login problems here. */
} finally {
TeamPlatform.shutdown();
}

}

}

Tuesday, July 16, 2013

IBatis log all SQL queries

Use the following log4j configuration to print all the queries getting executed by IBatis

log4j.rootLogger=INFO, CA
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.ibatis.SQL Map.engine.impl.SQL MapClientDelegate=DEBUG
 
log4j.logger.com.ibatis=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=INFO

Friday, July 12, 2013

RTC Rest API

Setup

Use a REST client, add headers as mentioned along the requests.

Get Root services

https://[RTCSERVER]/jazz/rootservices

Get a list of projects on the RTC server

https://[RTCSERVER]/jazz/oslc/workitems/catalog

Workitems

Fetch list of all workitems for a project, without details.

Headers
Accept: application/xml
OSLC-Core-Version: 2.0

https://[RTCSERVER]/jazz/oslc/contexts/[PROJECT_UUID]/workitems


Fetch list of all workitems for a project, with all details.

Headers
Accept: application/xml

https://[RTCSERVER]/jazz/oslc/contexts/[PROJECT_UUID]/workitems

Fetch all workitems for a project, specify the attributes that should be returned by the API, select

Headers
Accept: application/xml
OSLC-Core-Version: 2.0

https://[RTCSERVER]/jazz/oslc/contexts/[PROJECT_UUID]/workitems?oslc.select=dcterms:identifier,dcterms:title,dcterms:description,dcterms:type,dcterms:contributor,rtc_ext:com.ibm.team.apt.attribute.complexity,rtc_ext:groomed,rtc_cm:com.ibm.team.workitem.linktype.parentworkitem.parent,rtc_cm:plannedFor,oslc_cmx:priority,rtc_cm:state,oslc_cmx:project,rtc_cm:filedAgainst,rtc_ext:release_ticket_ID&oslc.pageSize=100

RTC 4.x and above API throttles the data to 50 records by default and a max of 100.
If you don't use OSLC-Core-Version header then the API won't recognize the where clause.

Fetch workitems by type and iteration

https://[RTCSERVER]/jazz/oslc/contexts/[PROJECT_UUID]/workitems?oslc.where=rtc_cm:type in ["com.ibm.team.apt.workItemType.story","task"] and rtc_cm:plannedFor="[ITERATION_UUID]"&oslc.select=dcterms:identifier,dcterms:title,dcterms:description,dcterms:type,dcterms:contributor,rtc_ext:com.ibm.team.apt.attribute.complexity,rtc_ext:groomed,rtc_cm:com.ibm.team.workitem.linktype.parentworkitem.parent,rtc_cm:plannedFor,oslc_cmx:priority,rtc_cm:state,oslc_cmx:project,rtc_cm:filedAgainst,rtc_ext:release_ticket_ID,dcterms:created,oslc_cm:closeDate&oslc.pageSize=100

Project Area > Workflow (States, Action, etc.) details

https://[RTCSERVER]/jazz/service/com.ibm.team.workitem.service.process.internal.rest.IWorkItemConfigRestService/workflows?projectAreaItemId=[PROJECT_UUID]

Fetch Actions:

https://[RTCSERVER]/jazz/oslc/workflows/[PROJECT_UUID]/actions?type=com.ibm.team.apt.workItemType.story&oslc_cm.properties=dc%3Aidentifier%2Crtc_cm%3AresultState%2Cdc%3Atitle

Reportable API


Get details of a sign-off workitem using Reportable API 
https://[RTCSERVER]/jazz/rpt/repository/workitem?fields=workitem/workItem[id=[WORITEMID]]/(projectArea/name|target/name|tags|id|summary|priority/name|owner/name|creationDate|resolutionDate|type/(id|name)|state/name|approvals/(stateIdentifier|approver/(userId|name)|stateDate)|approvalDescriptors/(id|typeIdentifier|name|cumulativeStateIdentifier|dueDate))

Java Questions

  1. Java
    1. How does exception handling in Java work, tell me about the different types of exceptions in Java.
    2. What is Polymorphism ?
    3. What is hashcode ?
    4. How are hashcode and equals related ?
    5. How do threads communicate ?
    6. Write a code to iterate through a map and print its values.
    7. You have data that needs to be displayed on a webpage, exported to PDF and exported to XLS, how would you go about the implementation.
    8. What are generics ?
    9. What is the difference between protected and default scope ?
    10. How would you create a servlet ?
    11. What are filters used for?
    12. How do we take the thread dump?
  2. Java-script
    1. What is a JQuery selector ?
    2. Among the frameworks like Angular/extJs, etc which one do you prefer to use in a new project and why ?
    3. Do you know about closures in Javascript ?
  3. Database
    1. Tell me any area where you feel MySQL is better than Oracle ?
  4. General
    1. Tell me about your best career achievement.


Friday, July 5, 2013

Learning Oracle - Basics

Create a new user:
CREATE USER amit
    IDENTIFIED BY abcdef
    DEFAULT TABLESPACE users
 
Grant the new user permissions so that he can login to database:
 Grant create session to amit;
 
create table student(
    name varchar(20), 
    rollno number primary key,
    dateofbirth date,
    standard number
);

create table subject(
    id number primary key,
    title varchar(20)
);

create table student_marks(
    subject_id references subject,
    student_id references student,
    marks number
);

insert into student values ('Amit Kumar', 1, TO_DATE('18-JAN-1980'), 10);
insert into student values ('Charu Kush', 2, TO_DATE('01-APR-1982'), 10);

insert into subject values (1, 'Maths');
insert into subject values (2, 'Science');

insert into student_marks values (1, 1, 45);
insert into student_marks values (2, 1, 55);

insert into student_marks values (1, 2, 55);
insert into student_marks values (2, 2, 65);
 



Places to play Badminton in Boston


Where to play ?

The first thing to try is to register at "Boston Badminton" meetup.com group, this meetup helps quickly get in touch with Badminton enthusiasts.
Some of the nice places that I have discovered are:

  • Westborough - You need a car to get here and is like 45 mins drive from Boston, but the best courts in this area.
  • Malden - I will add the exact address of the location, but there is a nice place to play badminton in Malden.
  • China Town YMCA - (Close to Tuffts Medical) The have badminton, 3 courts, only one of them has lines.
  • Boston University - This is with Meetup.com


Where to get racket and shuttlecocks ?

  • Westborough has everything you need.
  • Online : www.badmintonexpress.com 

Thursday, November 8, 2012

Monday, July 23, 2012

Ub city

Went there this last Friday, the place has a class of it's own. I was however disappointed as I was expecting it to be a big mall where as it had only two floors for shopping and rest was office space.

Saturday, June 30, 2012

How much I hate shopping for clothes

This is one area that I am really bad at.
Not sure if it is only me or is it something that a lot of people face in their life - I like wearing new clothes but the endless process of section and trials haunts me like anything.


Friday, June 29, 2012

To office on a bicycle

An amazing start of the day as I came to office on a bicycle for the first time.
At first I was kinda scared that 20 kilometers will be too much for me but it went prity fine. At this point I am not exactly sure if I can come regularly like this but for sure if I can do this even two three times a week it will bring a drastic improvement in my fitness and stamina.
Few things that I feel are important ...
The office bag should be as light in weight as possible
Tyre air pressure should be perfect
Helmet is a must for safety
At least 500 ml water glucose mixed
Should be wearing shorts and t shirt

Thursday, June 7, 2012

Corporate lies

Have you ever seen attrition statistics of a company, no I am not saying they are made up numbers, they are real. but there is a lot of interesting things that go behind the scene.
Generally a company will list only those people who quite their organization and join some other organization under attrition figures. The rest of the people are the ones who left the organization due to health/personal reasons or higher studies etc.
This point also all these figures are correct and there is nothing wrong here. The interesting part of the story starts when we learn that even though a large chunk of people who said that they are leaving due to  personal/health reasons were actually joining other organizations.
What could have made them tell lies.
Company will generally have a notice period, this can range from one to three or more months, and generally the candidate who is leaving wants it to be as short as possible, and the easiest way to make it short is to say that you want to quite due to health reasons or you want to go for higher studies.
The company is also happy that such candidates are not getting counted in their attrition rate, candidates are also happy that they are getting relieved quickly. :)

Monday, June 4, 2012

Drupal 6 to Drupal 7

These are the steps I followed to upgrade my Drupal 6 website to Drupal 7
1.Take backup of the live website
1.1 DB backup
/usr/local/mysql/bin/mysqldump -u --password= .sql
2.Copy your site to a test site



Sorry to finish like this, I am not able to migrate my application. My learning is that it only works if your application only uses the core modules. 

Google appengine


I have Always been a fan of Google applications, when Google started appengine few years ago I was very excited, the only problem was that it supported python and I was not much familiar with python. Within a year while I was leaning python GAE started supporting java.
The features and services provided were tempting enough for a developer like me to jump in right away. I started using it for one of my website, migrated it from php to java and while I was doing that it was always in my mind that the code is becoming increasingly coupled to gae, but I was stupid and lazy to write the code smart enough that could avoid the trap.

Thursday, December 1, 2011

Could not initialize class com.ibm.rational.team.client.ui.model.common.ImageManager

An error has occurred. See error log for more details.Could not initialize class com.ibm.rational.team.client.ui.model.common.ImageManager, If you also got stuck in this thing then here is the solution.
Start eclipse with -clean option it works fine.

Thursday, September 29, 2011

Save the best

Even though we may be unaware of it but most of us have this tendency - to save the best. I recall my school days when I was very much into western music I used to collect and maintain a decent collection of music tapes.
In those times where Hindi music cassettes used come for 22Rs English cassettes used to cost over a 100Rs, even though this luxury was quite beyond my reach I still used to save for it and buy my fav ones, The bigger problem in those days was that you have so many friends and if they know that you have all this great stuff it goes into a circulation with no return guarantee. On the other hand I used to love my music so much that sometimes with the fear of a tape may go bad, I used to first make a copy of it and then listen the copy.
Eight years ago, one day I left my hometown looking for a job in Delhi, I still remember that day clearly that I could feel my baggage and how I have no option but to shed some of the load of it in order to move ahead, it was a very sad day of my life as all the feelings that were coming while leaving my town I was also feeling down that I will never be able to use my stuff ever again, two box full of rare oldies music - and my bag was too small to carry the boxes along.
Each day life keeps becoming complex and busier, and these old memories and hobbies keep fading.
Bangalore is a place with heavy traffic on roads, my 14Km office commute take over an hour, I usually watch movies and TV serials in bus, This let to another hobby of watching movies and TV series.
Within a short span of less than a year I watched hundreds of good movies and download over 3 TB movies on my machine.
Last week I was thinking of buying a new Disk to accommodate more movies and this is when I again felt the same thing about music tapes - That even though it is going fine for the time being will I have enough time in future to enjoy what I am collecting. I don't have an answer to this and so this leads to that instead of buying a new disk I should delete the movies that I have already seen and free up space.

Tuesday, June 28, 2011

When we bought our first car.

Last month I bought a car, even though I did a lot of research on the internet about the various options that were in my budget limit it was still a difficult task to finally select a model.
Our primary reason to buy a car was that my wife was finding it difficult to commute in the thickly populated BMTC busses. The first thing that went through my head was that since she is not a experienced driver she might find it difficult to drive in Bangalore traffic so it would be a good idea to buy a second hand car as it won't pain that much if it gets few scratches or dents.
We went to a send hand car dealer in JP Nagar and we discovered that second hand cars in Bangalore are very expensive for instance a new Alto costs ~ 3.20 L while a 2007 model Alto costs 2.20 L and the same was seen with other cars like Wagon R, Hyundai etc.
We then decided to buy a new car, the thought that my wife is a beginner when it comes to driving still kept us on the track that we should not be spending too much on our first car. We decided to have a Tata Nano test drive, we went to a Tata showroom and saw Nano, when we sat in this car it was awesome, it feels spacious and the car is really good, the sales guy told us that the test drive car is gone to some place and that we can book a test drive and he can get the car at our place for a test drive, The same day after leaving from there we went for Maruti Showroom and had a look at Alto, Alto was much better the only issue was that it was costing almost as much as Wagon R ( ~4L ), we had a wagon r test drive and liked it we also booked it the same day. With Petrol prices touching 72 we discussed at home that when we are spending something like 4.5L why not try to get a Diesel car instead.
We had a look at Swift and Ritz, no one can "not like" Swift and Ritz was good but the speedometer and dashboard didn't look like a 6 L car to me, and we finalized Swift Diesel.
The only problem this time was that the waiting time was around 4 months. We thought of having a check at other dealers if someone has a lower waiting period, we found one where some one had just canceled his Swift Dzire Diesel version and even though it was slightly out of our reach we borrowed some money from family to get this car.
It has been one month now, I am 100% satisfied with this car.

Sunday, June 26, 2011

Spring 3 BlazeDS Google AppEngine Integration


I am finally able to get this thing working, this is how it can be done.

1. Follow what Martin's blog says about this issue.
2. You can take reference from my code .

Spring 3 Blazeds Integration.

This weekend I wanted to learn how to integrate Spring and Blazeds and test it using SoapUI.
Ok, before you get started the you need to make sure that you have the following softwares properly installed on your machine.
Java SDK 6, Maven 2.2, Eclipse Helios - (Plugins that I have installed are subeclipse, m2, ), SoapUI, Tomcat 6.

1. Create a Web Project
Open command prompt and type.

mvn archetype:create -DgroupId=org.example.webapp -DartifactId=example-webapp -DarchetypeArtifactId=maven-archetype-webapp

maven has created a simple web application, now we need create few eclipse files so that we can easily import this project in eclipse.

mvn -Dwtpversion=2.0 eclipse:eclipse

Next we have to import this project in eclipse.


Wednesday, June 22, 2011

Create Aspects in Spring for Logging DAO response time

Step One: Create a System architecture class which defines which methods to pointcut

@Aspect
public class SystemArchitecture {

/**
* Service Layer Aspect.
*/
@Pointcut("within(com.service..*)")
public void inServiceLayer() {

}

/**
* Service Implementation layer aspect.
*/
@Pointcut("execution(* com.service..*.*(..))")
public void businessService() {

}

/**
* DAO Layer aspect.
*/
@Pointcut("execution(* com.dao..*.*(..))")
public void dataAccessOperation() {

}
}

Step two: Create a Tracing Aspect class which contains the actual code that is executed at the point cuts

@Aspect
public class TracingAspects {

/**
* Around advice to log method entry and exits. Logs at TRACE level
*
* @param pjp ProceedingJoinPoint
* @return Object
* @throws Throwable if aspect throw any exception
*/
@Around("com.util.SystemArchitecture.dataAccessOperation()")
public Object traceMethodEntryExit(ProceedingJoinPoint pjp) throws Throwable {
Log log = LogFactory.getLog(pjp.getTarget().getClass());

MethodSignature mthdSignature = (MethodSignature) pjp.getSignature();
log.debug("Entering method " + mthdSignature.getName());

try {
return pjp.proceed();
} finally {
log.debug("Exiting method " + mthdSignature.getName());
}

}

/**
* round advice to log method execution time. Logs at DEBUG level
*
* @param pjp ProceedingJoinPoint
* @return Object
* @throws Throwable if aspect throw any exception
*/
@Around("com.util.SystemArchitecture.dataAccessOperation()")
public Object perfTrace(ProceedingJoinPoint pjp) throws Throwable {
Log log = LogFactory.getLog(pjp.getTarget().getClass());

MethodSignature mthdSignature = (MethodSignature) pjp.getSignature();
long startTime = System.currentTimeMillis();

try {
return pjp.proceed();
} finally {
long elapsedTime = System.currentTimeMillis() - startTime;
log.debug("Method " + mthdSignature.getName() + " took " + elapsedTime + "ms");
}

}


Step Three: Enable AOP in Spring configuration


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<aop:aspectj-autoproxy proxy-target-class="true"/>
<bean id="tracingAspects" class="com.util.TracingAspects"/>
</beans>

Exception Handling in Spring MVC

Here is one good and easy way to do it
First of all We should create a user defined exception class

public class MyExceptionClass extends RuntimeException {
private String userMessage = "User message not set";

public MyExceptionClass() {
super();
}

public MyExceptionClass(String userMessage, Throwable cause) {
super(cause);
this.userMessage = userMessage;
}

public MyExceptionClass(String userMessage) {
super(userMessage);
this.userMessage = userMessage;
}

public MyExceptionClass(Throwable cause) {
super(cause);
userMessage = cause.getMessage();
}

public String getUserMessage() {
return userMessage;
}

public void setUserMessage(String userMessage) {
this.userMessage = userMessage;
}

@Override
public String toString() {
return "User message = " + userMessage + "\n" + super.toString();
}
}

Next step is to configure exception handling in application context file

<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="MyExceptionClass">error</prop>
<prop key="java.lang.Exception">error</prop>
</props>
</property>
</bean>