Feeds:
Posts
Comments

I have had an opportunity to play around with annotation and hibernate validation. Basically, hibernate has a few predefined annotations that you can use to annotate your getter methods. Later on, when in comes the user input, it will be validated based on the annotation type you use. For example -

@Length(max = 100)
@Email
public String getEmail() {
  return email;
}

Here we are limiting the length of the String and also annotating it as an Email. The @Email annotation has a Validator class defined with @ValidatorClass annotation. The isValid() method of the respective validator gets called at runtime which then decided whether the input value is valid. You can find out more about it here.

Anyway, my problem in the above email field was, now we wanted to save multiple email addresses separated by comma. Since the default validator treats the whole value as one email address, it discards the input when there is a comma, obviously. Therefore, we needed a custom solution. After a bit of research and code digging, the final solution turned out to be very simple. But more importantly, elegant as well.

To implement custom validation in hibernate, all we need to do is define a new annotation and a corresponding validator. Lets first create the annotation.

 

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ValidatorClass(CustomEmailValidator.class)
public @interface CustomEmail {
  String message() default "Email address not valid";
}

As you can see, our annotation is called CustomEmail (as opposed to Email in the first listing). We have written a new class named CustomEmailValidator and defined it here as our validator class. This class implements  org.hibernate.validator.Validator which has a isValid method that will get called at runtime. All we needed to do was put our validation logic inside this method. Here is a part of the code


public class CustomEmailValidator implements Validator<CustomEmail>, Serializable {

  public boolean isValid(Object value) {

    // return true or false after validating value

  }
}

Note, while implementing the Validator, we have to define the annotation name that this validator is linked with. Thats it! We just created implemented a new validation rule using hibernates validator framework.

Just came across this Garfield post today through google gadget. As always they are funny as hell. But wait, this one is more. It looks awefully familiar !

Garifield Sleeping

Can you guess which one is me?

Business as usual?

For the past couple of days, I have been trying to deploy the web services I have written. It was a lot harder than I ever imagined. I had configured everything and it was running fine in my local setup. I took my time and made the perfect deployment plan. It was supposed to be just a matter of updating the context followed by a restart of the application server. Needless to say, it was nowhere near that!

It is a matter of great discomfort when you are deploying a set of new configurations, which works perfectly in your local box, refuse to work in the live server. To make matter worse, the error doesn’t give any clear indication and the log file behaves like just another day in the office!

Fortunately though, the air has cooled down, all the issues are resolved now at the expense of couple of  days of frustration and head scratching debugging.

My collegue yesterday noticed I was unusually quite (even for my standard) and wondered whether this sort of problematic patch is frequent in programming. Frequent or not, the aftermath is surely worth it and more. :)

Last evening was special for me. I have always wanted to go to those fancy car shows. Watching pictures of others in front of Ferrari or Mercedes seemed very appalling to me. Well, I was never going to miss when this opportunity came to me. There is a motor expo going on at the moment and we happened to be there last evening. We went there after office and stayed almost till 9 PM. For me, it was an amazing experience. I don’t know why, but I was extremely delighted to be there. I even managed to totally forget my headache the whole time I was there!

I saw the cars – as much as I could – literally. The best part of course was watching the red Ferrari. But there were a lot of other cars for the pleasure of my eyes. Well, yes eyes. I wasn’t thinking about buying, duh! And I don’t really day dream either! :)

Ferrari

The main attraction though, was the future car from Mazda -

Mazda Taiki - The Future Car

Mazda Taiki - The Future Car

This beautiful two seater was designed with a single objective to “create a design that visually expresses the flow of air.”

There were also great cars from Lamborghini, Lexus, Toyota, Holden, Maserati, Nissan, Renault, Suzuki, Volvo, Ford and Hyundai. To find out more about the expo and see other car pictures, visit the official site.

Obama in Xbox

Like millions others worldwide, I am also quite keenly following the developments of US presidential election this year.  I was amused to see the following today – Obama’s campaign has put adverts on Xbox live game ‘Burnout Paradise’. Looks like he is trying to encourage young voters to sign up.

Barack Obama in burnout

Barack Obama billboard in Xbox

I have a new toy!

I can’t remember when was the last time I was so happy after buying something. Maybe not since the old and naive childhood days when a toy used to mean everything I could ever hope for! Well, last night we just got ourselves a cute little Car. After getting it from its previous owner we went for a quick spin around the block – it was fun and kind of scary! For the first time I was driving without an instructor. My wife tried her best to chip in with helpful instructions though.
I had given our car space to our neighbour for this week, therefore had to park the car on the street last night. Its quite a normal thing to do, but being the first day, I was very nervous for doing that. Have I locked the car right? Have I blocked any drive way? Why is a light flashing there? I also remember jumping out of the bed twice and looking out of the window to check if the car was there. Not my fault, I heard a car door closing sound followed by start of an engine! :)
Anyway, this is how it looked this morning from our window -
Our first car

Our first car

Did you know?

While designing a template for Joomla, I ran into this weird problem the other day. For some reason, the tab images on the navigation bar were having a white space in between them. I checked my code over and over again, even narrowed down the file into a simpler layout. But no luck! I didn’t even know what to type in google. The problem was so silly!

Well, when I finally found out the solution, the problem seemed even sillier! Turns out, if you leave a white space or new line in between to img tags, a white space appears in between them. But if you delete the spaces between the two tags, it renders fine! Check it out.

I wish hadn’t had to know that!

Last night, we were not in the mood of cooking and therefore went to buy some curry in our nearby restaurant. There we met this girl who happened to come from Bangladesh as well. We started talking and she described how tough her life has been here, so far. The descriptions were really touching. We felt for her and all other students, who leave their country for a better life and then pass through the same suffering.

Its of course, all about money. Problem with coming from a poor country is, the apparently huge amount of money sent to you from your family, when converted into rich country’s currency, becomes really insignificant. Unless your family back home is really really rich, you soon realise you have to earn your own expenses. Every student we have seen so far, is doing the same. They are trying to survive the academic years, for once that has been accomplished, they will get the permit to work full time.

Luckily for me, I never had that enough richness to venture the thought of coming here as a student! :) Therefore, we thankfully, are living on the other side of this stream. People in this side, wake up with alarm clocks, catch the same carriage of the exact same train on exact o’clock everyday. Most of them return home long after the sun has set with their shoulders and heads pointing towards earth and the face clearly expressing the tiredness.

Which is, to me, is still fine. I mean life was never supposed to be easy. But when after all this, something from inside keeps you asking what the hell are you doing here, I get really confused! This is something I have wanted for so long and thankfully I have got it. But I never knew the cost that I had to pay, cause I had never lived without my family before.

I just hope and believe, this is for the better for all of us.

While I can imagine the Euro 2008 buzz that might be going on in Dhaka by looking at the local newspapers, I certainly do not see or feel anything here. I try to keep up with the scores by reading the news, but I do miss the live action. Well, any action to be honest! I keep myself updated with the scores and results by visiting the BBC worlds website. Although they have video highlights there, they don’t let me watch it! It keeps on saying “Sorry, this media is not available in your territory”.

This morning when I read the shocking news of Russia beating Netherlands, I had to see how it happened. But as usual, no video in my territory. After a while, I opted to view their version of ‘Virtual Replay’ – animated simulation of the actual play. It lets you switch the camera from lots of different angles, you can also control the speed of the play. All in all, nice interface with lots of customisable option.

But .. after watching it for a while, I wondered what I was doing. What a loser, I thought! I missed the live action, missed the highlights, the game is now two days old and I am sitting here watching bunch of cartoon characters running on a green canvas!! :D

No doubt I will have to find a solution for watching sports. I just didn’t realise until now, how glued I am with them. My parents were right! :)

Alt one-two

When I first started working in Linux, I was given a window manager named Windowmaker. It is a lot cleaner and lightweight compared to the default Gnome. I used to have five virtual desktops inside this window manager. I had customised my desktops in the following order -

  • Desktop1 for IntelliJ IDEA and a command terminal to start/stop the application server
  • Desktop2 for Firefox
  • Desktop3 for email client
  • Desktop4 for miscellaneous stuff and
  • Desktop5 for IM

So for the past two and a half years, I used to move around these desktops using Alt+1, Alt+2, Alt+3 etc. As you can guess (or you may not), I have so much got into the habit of pressing Alt one-two that now I do it in Windows too! Obviously, pressing those cause nothing in Windows. Not sure if It was because I was missing my last workplace or not, but I felt really sorry for not being able to do Alt one-two any more.

Today, finally being fade up with switching between the Windows using Alt+tab, I started searching for a window manger for Windows. After a while, it seemed like Dexpot is a neat one. So I installed it and organised my windows, spreading them over the four Desktops that it has. After that, I was wondering how would I switch between the desktops and whether I can configure it to my favourite Alt one-two! To my absolute delight, I found out that it actually comes with the same short cut keys by default. Therefore, now I have multiple virtual desktop and I can switch between them using Alt one-two – just like the good old days! :)

Older Posts »