Sunday, September 20, 2009

Maven to the rescue

I just finished a Maven Tutorial to be used from my upcoming Spring Web Flow Tutorial and I thought it is good time to talk a little bit about Maven.

I have being involved in several building process for many different languages. Specifically for Java I have used shell scripts, Ant and Maven.

At the beginning when I learned about the existence of a better tool to do my builds I went to forums trying to get opinions about Ant versus Maven. By that time the community was really divided.

Nowadays we know about Ant limitations and while Maven is not the only tool that allows to circumvent them, it is for sure one of those that solve main issues:

1. No need to store jar files on version control systems like SVN. This allows for extremely fast checkouts of projects.

2. Transitive dependency. Projects depend on jars that at the same time depends on others. Once you declare a dependency on a given jar you need not to worry about those dependencies that result from the new inclusion.

3. Version headaches. It is common to include a jar file and then dependencies of that jar file. It is very easy to get wrong on the versions of the dependencies of the included jar. Maven will pick the right dependency versions for you.

4. Maven is actually a project management tool and not just a build tool. There are hundreds of plugins available going from compilation to deployment issues and bringing project reports. It covers pretty much all you need from SDLC perspective.

5. Maven has extensive support and is used nowadays in sample projects embedded in the well known frameworks like Spring. It is also the min building tool in use from Jakarta and other important Open Source Software projects. Pretty much there is no big project out there that is lacking support for Maven.

6. Maven is IDE agnostic. Thanks to the plugin architecture your projects can be run from Eclise, Netbeans or IDEA. How the project is debugged and run in your local IDE is a concern of plugins and that allows to get cleaner version system repositories as there is no need to store specific to IDE files.

Mavenizing an existing project is easy. Well done Maven!

Tuesday, September 01, 2009

Wiki Tutorial

People get scared of Wiki syntax but actually with too little knowledge you can do a lot of editing. Below is what I would say is necessary and enough to edit WIKIs. At least MoinMoin and Google Code Wiki comply with this standards. So there we go:

1. Numbering
1.
1.
1.


2. Code block
{{{
}}}


3. Main header:
= Header Here =


4. Subheaders:
== Sub Header Here ==

5. Images:
attachment:image.jpg

6. Subpages index
[[FullSearch()]]

Thursday, August 27, 2009

JSON Forms

Forms in a WEB applications are always a need and as they get complicated frameworks come to your rescue. Sometimes though, you have not a framework to rely on.

JSON gives a clean solution that actually works with any language out there as it is a standard Object notation supported by APIs in all modern languages used in WEB programming. After all building a JSON parser is not that hard.

Here are simple steps to come up with your own JSON Form API:
1. Create a JSON Form Array per WEB Form listing the necessary form fields. Below is a prepopulated Person JSON Form:

[{"name":"first_name","minlength":"6","maxlength":"50","mandatory":true,"editable":true,"translation":"First Name","value":"","selected":"Foo"},{"name":"last_name","minlength":"6","maxlength":"50","mandatory":true,"editable":true,"translation":"Last Name","value":"","selected":"Bar"},{"name":"email","minlength":"6","maxlength":"50","mandatory":true,"editable":true,"translation":"Email","value":"","selected":"foo.bar@fakeemail.com"},{"name":"phone","minlength":"7","maxlength":"16","mandatory":true,"editable":true,"translation":"Phone","value":"","selected":"+01 305-222-4444"},
{"name":"address1","minlength":"1","maxlength":"100","mandatory":true,"editable":true,"translation":"Address 1","value":"","selected":"1509 Alton Road"},{"name":"address2","minlength":"1","maxlength":"100","mandatory":false,"editable":true,"translation":"Address 2","value":"","selected":"Suite 302"},{"name":"city","minlength":"3","maxlength":"50","mandatory":true,"editable":true,"translation":"City","value":"","selected":"Miami Beach"},{"name":"state","minlength":"1","maxlength":"50","mandatory":true,"editable":true,"translation":"State","value":"","selected":"FL"},{"name":"zip","minlength":"3","maxlength":"20","mandatory":true,"editable":true,"translation":"Zip","value":"","selected":"33139"},{"name":"country","minlength":"3","maxlength":"3","mandatory":true,"editable":false,"translation":"Country","value":["USA", "Canada"],"selected":"USA"},{"name":"age","minlength":"1","maxlength":"3","mandatory":true,"editable":true,"translation":"Product","value":"","type":"int","selected":"33","min":"21","max":"100"},{"name":"graduation_date","minlength":"6","maxlength":"10","mandatory":true,"editable":true,"translation":"Graduation Date","value":"","type":"date","selected":"1999-09-05","format":"yyyy-MM-dd"},{"name":"comments","minlength":"0","maxlength":"255","mandatory":false,"editable":true,"translation":"Comments","value":"","selected":""}]
{"name":"languages","minlength":"0","maxlength":"255","mandatory":false,"editable":true,"translation":"Languages","value":["English","Spanish","Russian"],"selected":"English","mutex":"false"}]


2. First time the form could be rendered with data using the "selected" field, others the form will come empty meaning "selected" will have no value. We can use "value" for a list of possible options, "mutex" to decide if we will accept multiple values, "format" for date types (we could actually change the format with the locale of the user), and so on.

3. When the form is submitted, pass the parameters to a Factory Form class that will append a validation error field (Array of errors) to the JSON Object. Things like "incorrect_length", "incorrect_type", "bigger number needed", "mandatory" are typical. On the other hand following conventions if the name of the field contains "email" then use regex to match if the email should be accepted or just use a library (Jakarta Commons Validator for Java offers an extensive amount of special data types). The same applies to zip codes and phones for example but commonly those follow special rules per country.

4. If special values are to be inserted from specific business rules do so in the JSON Object.

5. If there are validation errors render back the JSON Form explaining what the errors are (JQuery is great for this especially when using existing form plugins). Notice that with the same JSON Object you can provide both front end and middle tear validation. Ideally you should have a script that runs everytime the involved Database metadata changes, so the JSON Object is actually regenerated from time to time. That keeps the third tear (Backend) synchronized as well.

5. If there are no errors, proceed to persist the JSON Form Data in the Database. Again the persistence logic could be optionally provided on the fly using ORM techniques or even including a pre-populated by script Class that changes every time the model changes as well.

Wednesday, July 22, 2009

Mac ZIP / UNZIP, Microsoft Word 2007 and OpenOffice

Open Office reads Microsoft Word 2007 documents out of the box. Mac OSX comes with an unzip utility out of the box so it would make sense you receive on your MAC a zipped Word 2007 document and you will read it without any problems.

The reality is that at least in my latest Mac Book Pro (2009) when I double click the zip file it gets extracted in a folder full of XML files which Open Office will not recognize.

Of course from command prompt your old friend "unzip" will do nothing more than extracting your file but Finder will not. Somehow it is so smart that it will decompress the doc file as well (Yes the .doc you get from Microsoft 2007 is no more than a zipped bundle of XML files and more)

Now, if you are on a MAC you love GUI ;-) and so allow me to recommend http://www.edenwaith.com/products/guitar/ for uncompressing. It is a wrapper of command line utilities that do not go any smarter than what you need.

Wednesday, June 24, 2009

Windows Mobile, Outlook/Exchange and Google Contacts/Calendar Synchronization

There is no need to pay for any service or program to keep your Google calendar and contacts synchronized with those in your pocket-pc and your Windows Desktop OS.

1. Visit "Google Help › Mobile Help › Using Your Device › Windows Mobile Devices › Google Sync" and get instructions to set up your mobile device.
2. Visit "Google Help › Google Calendar Help › Access options › Sync › Sync with Microsoft Outlook › Google Calendar Sync: Overview" to download and install in your Windows Desktop OS "Google Calendar Sync"
3. Calendars are synchronized between all parts without problems. Contacts though is a different story. For contacts you will need to synchronize from the mobile device to Google and your Exchange Corporate Server, that way your ActiveSync will necessarily be the master as of the time of this writing not direct sync between Google and Exchange is still available.

From now on you can manage your contacts or calendar from either Microsoft Outlook, your mobile phone or Google Web interface.

Wednesday, March 25, 2009

Submitting Iphone Application to iTunes

Well this proved to be a little bit complicated but it shouldn't be if you carefully follow at least one time all the steps from IPhone developer Program ("Distribution|Prepare App" has all necessary instructions). Anyway here are some important and very basic steps to follow.

1. In XCode navigate to Products/${appname}.app. CTRL + click on top of it and select " Reveal in Finder"
2. In the Finder Window use CTRL + click on top of ${appname}.app and select "compress"
3. Open App Loader and select Menu | File | New and choose your application
4. Follow steps and point to the binary (zip created above)
5. Press Send.



The major problem I got was "application failed codesign verification" after trying to send the binary from App Loader.

Just be sure you follow careful all steps from IPhone developer Program ("Distribution|Prepare App" has them all). The error is very generic and anything you miss will stop your app from being sent to Apple. In my case I was working with the 'Project Info Window' (Menu | Project | Edit Project Settings) all the time, ignoring that many of the steps involve using the 'Target Info Window' (Menu | Project | Edit Active Target)

As a side note the application I was working on had a lot of local resources and being almost 40MB it took 15 minutes to get uploaded. It was not my Internet Connection for sure but just an Apple throughput limitation.

JQuery Tooltip for Html Select Boxes

Sometimes there is limited content width for options showing up in an HTML Select tag. Consider using in those cases JQuery Tooltip plugin:

<!-- Include jquery and tooltip plugin -->
<script src="jquery-1.2.6.js" type="text/javascript"></script>
<script src="jquery.tooltip.js" type="text/javascript"></script>

<!-- Forcing a narrow select box -->
<style type="text/css">
select{
width: 60;
}
option{
width: 60;
}
</style>

<!-- Include custom code to handle the tooltip -->
<script type="text/javascript">
//After loading the page insert the title attribute.
$(function(){
$("select option").attr( "title", "" );
$("select option").each(function(i){
this.title = this.text;
})
});

//Attach a tooltip to select elements
$("select").tooltip({
left: 25
});
</script>

<!-- When moving the mouse over the below options -->
<select>
<option>very long option text 1</option>
<option>very long option text 2</option>
<option>very long option text 3</option>
<option>very long option text 4</option>
<option>very long option text 5</option>
<option>very long option text 6</option>
</select>

Followers