Saturday, January 30, 2010

the iPad



I know I am days late with this post, and that there are probably already into the millions of posts and forum discussions about the iPad on the web right now but I thought I would throw in my two-cents worth as well.

There was a lot of hype in the build up to the launch this week, as there always is with Apple, but there were some differences that made some people talk... normally before a launch Apple remain tight lipped, saying nothing and ocasionally unofficially leaking information to the press to try and lower expectations (it was suspected that the "analysts" predicting the price of the iPad was going to be coming in at $1,000 was in fact due to an unofficial leak - so when Steve Jobs announce the entry level price was half that its a big win straight away). However, this time Apple were not so quiet about it, with it being mentioned a few times by some of the top dogs, most notably mr Jobs himself saying it was the best thing he had ever worked on.


So is the iPad going to be any good? in my humble oppinion, that depends, but it is looking like it will be a yes. For the iPad, or any new tablet device for that matter, to be successful it needs to offer something different, it needs to change the way we use things and do things - Recently Microsoft announced their tablet, which was quite hugely panned, because it was just a Windows machine in tablet form, which doesn't really offer much to anyone, as apart from the touchscreen functionality what does it really offer more than a NetBook? There is no real reason to use a tablet at home or in the office over a laptop/desktop so if all it really offers is a different way to surf the web or read things on the move then its just not that good.


Why does Apple have any chance of doing better than the Windows tablet? basically because of the emphasis on user interaction from the iPod/iPhone has paved the way for where tablet computing can really revolutionise computing.
A lot of people have been talking about using tablet devices to read newspapers and books, and it will change the way people read news, and this is true, but it needs to offer more than just the ability to read the content like you would from a website, the content needs to be interactive, for example, imagine a cookery book where you could read the recipe but also pull down videos of various stages, details about the ingredients and suggested alternatives, all without leaving the recipe page; or a history book where you could read about the second world war and pull down biographical information about various generals or see timelines and photos, again all without having to leave the page - without having to trawl through links on wikipedia.

That would be revolutionising the way we read, the way we learn and Apples UI naturally lends itself to an interface that facilitates this sort of interaction. However, unfortunately, all this content needs to be created, and thats not something Apple can do - its up to the content providers to "tablet-ify" their news, and publishers need to do the same for books and encyclopedias, and this is a big ask!


Thankfully for Apple, there are already a few startups appearing with the sole aim of helping publishers and content providers get the information in a iPad friendly format, so maybe in the not so distant future we will be seeing the change in the way we receive information...


so like i said... maybe.

Web App Woes..

So things have been really hectic with work this week which has only really left me weekends for any of my ongoing endevours, and most of last weekend ended up being dedicated to getting the web app project up and running.

It started off with some more playing around with Spring Roo generation framework and decided to go from there. The idea for the application has changed from a simple requirement gathering application to a more robust design capture tool (focusing largely on the design of SOA integration work) so thought i will start from scratch with the Roo generated stuff as the foundation.

On the whole I am quite impressed with the ease of use of Roo, I am still not using it for complete JPA entity creation, but for basic webapp project setup and boilerplate configuration its pretty good - its still pretty immature and occasionally it stutters a bit and an import will be generated incorrectly (for example import java.java.util.list) but the ease of setting up the config and then switching it is pretty handy.

That said, last weekend was not without its cursing as i worked through some teething problems of my app (not largely caused by my stupiditiy though!)...

  1. The first bump in the road was that I had selected to use EclipseLink as my JPA implementation, as I had worked with it before, however, I soon found that Roo still has some issues with EclipseLink, plus I intended to use JPA2.0 and Roo and EclipseLink2.0 definitely didnt play well together, so i have now switched to Hibernate

  2. So on switching to Hibernate, the out of the box web site fired up fine and i was able to configure the basic security to allow login, and the first thing i wanted to do was move away from the basic xml configured users to using my own implementation of the Spring user security stuff. So I created the custom implementations of the Spring User class and the UserDetailService and plugged them in to the security configuration ("applicationContext-security.xml" - below for reference)

    <!-- Define the bean for my custom implementation of Springs UserDetailsService -->
    <beans:bean id="userService" class="com.tmm.design.security.UserDetailServiceImplemntation">
    <beans:property name="accountController" ref="accountController" />
    </beans:bean>


    <!-- define the authentication manager and set it to use our custom bean above -->
    <authentication-manager alias="authenticationManager">
    <authentication-provider userserviceref="userService">
    <password-encoder base64="true" hash="md5"><beans:bean id="userService" class="com.tmm.designdesktop.security.UserDetailsServiceImpl">
    <alt-source property="accountId">
    </salt-source>
    </beans:bean>
    </password-encoder>


    My security service now plugged in to the web login, I fired it up again and nothing - running through the debug my DAO was returning "account not found" - so I put together a quick java class that created an Account object and persisted it using the JPA layer, all seemed fine and a quick query showed the admin user now existed in my MySQL table. Once again I fired it up and tried to login, but still no account found... Baffled, I spent some time going around in circles, failing to understand how it was not finding my newly created user. As it turns out, this was my own fault - in the persistence.xml file i had defined the following Hibernate property.

    <property name="hibernate.hbm2ddl.auto" value="create"/>

    As it happens, this means everytime I restarted the server all the tables were dropped and recreated. Coming from EclipseLink, this would have been equivalent to the property "drop-and-create". I promptly changed to "update" and my acoount was finally being found!


  3. Having now found the account, my app was still refusing logon - this time it was definitely my fault... I had created my Account entity (persisted Java class) and had created a method setAndEncodePassword(String password); that allowed passing of a plain text password to the method and it would then use the Spring MD5 Password encoder encode it, the only problem being that I was using the account ID as the salt for this encoding, and the ID was autogenerated by hibernate, so at the time of creating the new Account object and setting the password the ID had not yet been generated, so it was using null as the password salt, then as soon as the new account was persisted to the database the ID was updated making the password impossible to use!! I have now moved the password encoding to the AccountController class to ensure that the account object is persisted before any password is encoded.

  4. The final strange thing i noticed, was that when in Eclipse, I normally set my Server settings to "Serve Modules without publishing" option for ease of development and refresh, however, I found that selecting this option prevented the site from displaying complaining that it could not find the .tagx files...


So I finally got my user security setup, this weekend I will get on with designing the domain model (I will be trying to model both a "Business Service" and a more general "Data Model" and have already got some interesting decisions to make with regards the solution, so it could be interesting)

Sunday, January 17, 2010

Evolutionary Computation Roadmap

Following the first release of the evolutionary programming framework last week I though I would put together something of an early roadmap for what is going to be being added along the way.

In no particular order:

  • GrayCode Individual/chromosome implementation and all re-combination methods
  • Arithmetic crossover
  • Cauchy Mutation
  • Gaussian Mutation
  • Best individual selection, tournament selection, roulette wheel selection
  • Best copuling
  • Invert coupling
  • Random coupling
  • Linear fitness scaling
  • Exponential fitness scaling

Spring Roo Test Run

Just last week i was introduced to Spring Roo, and despite it having been around for a couple of months this was the suprisingly the first I had heard of it.

Those who were as oblivious as i was, Spring Roo is a generation framework for quickly and easily generate Sprin/JPA projects - and having skimmed through the overview and having read the quick start tutorials I was liking what I was hearing so throught I would have a play (i would like to make clear that this was not another distraction! this falls broadly under some of my web app projects... kind of). On the Spring Roo site () there is a 10minute tutorial as well as some slightly more comprehensive examples, although realistically even the other examples can be completed in under 10 minutes so I played around with both.

The idea is that from just a few commands a lot of the core boilerplate stuff for the project can be quickly and easily created, and in fact, with just a few more a lot of the code code can be generated also.

It can create the project and maven setup, create all the spring and JPA configuration files, create the tests and it can be used to define the JPA entities and the controller classes - and true to its word, you can get a web application created and deployed pretty quickly. I think in reality I would maybe not use it to create the JPA entites, as I prefer to be able to define that in an IDE (it also has a "perform eclipse" command which can create all the files so the project can be imported straight in to Eclipse, which was a nice touch) but it is definitely going to be of use for a lot of the boilerplate stuff.


I did hit a couple of minor glitches whilst playing with the tutorials, which I will share below in case anyone else experiences the same:

  1. EclipseLink with the PizzaShop tutorial - Having most experience of EclipseLink JPA implementation I decided to use that again whilst following the tutorial rather than recommended Hibernate - when it came to then deploying and trying to start my Tomcat server I was getting an "Error creating bean with name "transactionManager", not particularly wanting to spend time trying to debug the tutorial example I reverted to Hibernate (which is easily done with just a few commands) and this problem was resolved
  2. Next, once my Tomcat server was starting without error, when I visited the app I was getting the error "File "/WEB-INF/tags/language.tagx" not found" - thankfully, this time some quick googling discovered that this was linked to the server configuration within Eclipse - unchecking the "Serve modules without publishing" option fixed this and my pizzashop was online!

On the whole I was fairly impressed with the framework, and will surely save some time on future apps with the config and general setup - so is recommended.

Sunday, January 10, 2010

Evolutionary Computation Framework BETA 0.1

The first beta version of my evolutionary computation framework project has been finished... i say first version, its not really practically useable in any real way, but it seemed like a good point to pause for a moment and review the progress.

So here we are, the current release includes:
  • AbstractPopulation class - this contains the method to score the individuals, which must alway be overriden
  • AbstractIndividual & AbstractChromosome - these are abstract to allow different implementations (for example, binary/graycode etc)
  • BinaryIndividual & BinaryChromosome - binary implementations of the abstract classes
The binary implementations only currently contain single-point crossover recombination, and a simple implementation of the binary bit flip mutation method.

TMM Evolutionary Framework BETA 0.1

Tuesday, January 5, 2010

Google Collections 1.0 Final Released

I noticed over the holidays that Google have released the final 1.0 release of their Goole Collections library. The Google Collections library is a custom extension of the Java Collections API, which at first glance seems to be very useful. The main benefit seems to be the reduction of code that developers would have to write for fairly common patterns using the existing API - the last few months I seem to have coded a lot of fairly ugly nested Maps, for example:

Map> map = new Hashmap>();

public void makeSale(Salesperson salesPerson, Sale sale) {
List sales = map.get(salesPerson);
if (sales == null) {
sales = new ArrayList();
map.put(salesPerson, sales);
}
sales.add(sale);
}




Multimap multimap = new ArrayListMultimap();

public void makeSale(Salesperson salesPerson, Sale sale) {
multimap.put(salesperson, sale);
}



(Taken From http://publicobject.com/2007/09/series-recap-coding-in-small-with.html)

Now it's just going to be a case of getting in to the habit of using the library, and I will see how it works out.

For more information, some guys have been doing a blog on lots of little before and after scenarios highlighting some of the nice features of the API which can be found here: http://publicobject.com/2007/09/series-recap-coding-in-small-with.html (the example above was taken from there, and of course, the library itself can be found here: http://code.google.com/p/google-collections/

more distractions...

I sometimes think if I am being too fadd-ish, with my seemingly ever growing list of projects and technologies that I am working on - am I spreading myself too thin? following my expedition in to the DJango tutorials, I have now found another two things I want to work on, so these are being added to the list! (Django was not added to the list, that was just a bit of a jolly!)

  • Google Apps - having read an email regarding some google apps work, and having a brief look at the Google Apps for Java overview, it seems quite interesting, and not a million miles away from normal webapp with persistence data object development - so I am going to have a look in to that
  • This next one is coming more from a need than a particular interest in the technologies in question; I am going to have a look at building a Checkstyle extension to handle Javascript (Checkstyle is a Java code quality checking tool - with eclipse & maven plugins). I will not be writing the ANTLR Javascript grammar though, and will just try to re-use one of the available grammars on the web


So thats it (for the moment) for the list of things I will be playing with, lets hope it does not continue to expand too much...


So it begins

So, towards the end of the seasonal break, after being distracted by the intrigues of Django, i managed to actually make a start on one the web app project (extjs/jpa).

It took relatively little time to get the server side stuff setup, setting up a basic domain model to allow modelling of my requirement structure (i will add some class diagrams in a later post) and the EclipseLink annotation to persist the objects to the db appeared to work with no problems - all good so far!

I put together a basic UI using EXTJS, with the grouped tabs example available in EXTJS 3.1 as the foundation for the layout of the app. I kept a lot of the example content for now, but created a few tabbed panes to display my new content. I decided to start creating the admin panel first of all - this decision seemed a little strange to me, but was driven by the fact that none of the tabs would have had any data to display in the first instance, so decided to start by providing a global admin control to allow easy addition of projects/users etc.

  • That was the Model and View started, so next began on the Controllers - the Controller structure i am using has three core controllers:
  • The Account Controller - this will be used for all the boilerplate user admin. I decided to keep this controller seperate from the main Model Controller as the users and account objects are not kept together with the domain model, so decided this would be the best approach
  • The Model Controller - this will be used for all Domain model updates/retrieval and will be the central controller for most actions in the app

The JSON Controller - the web app will be using JSON objects to send data between the UI and the controllers and this will be the central pivot point that receives all the http requests from the UI and then passes the data on to the necessary Controller to complete the action



Having a very bare skeleton of my entire MVC I decided to plug it all together with the simple example of a page that allowed new user creation.

I quickly generated the three controller classes, adding methods to the Account Controller to create/retrieve users and a chunk of the normal functionality you would expect around user authentication and created a method in the JSON controller that would be used to create a new user. I also added a form to the EXTJS UI that captured the basic user information required (name/email/password) and added an ajax request from the form to my new method in the JSON controller.

On deploying and firing up the application on tomcat it worked and logged in fine (having created a single user account using a quick Java app i put together), however, it all came unstuck when I tried to create load the table of existing user details.

The error i received was regarding a problem trying to execute a closed entity manager:

"Attempting to execute an operation on a closed EntityManager"



Unfortunately, Googling the issue did not throw any more light on it, with most of the forum posts/blogs with similar issues seemed to be resolved by adding @Transactional annotation to the methods using the EntityManager or not correctly adding the AnnotationDriven configuration option to the app context - but these were both fine in my case.

After spending several hours trying to resolve this, i finally had some joy on realising that the error had been born entirely out of my haste to get something strung together - Instead of parsing the data from the original JSON object within the JSON controller and then passing the data to the Account Controller to handle the DAO action, I had been lazy and was just getting the Account Controller within the JSON Controller and then directly accessing the user DAO from there. As a result, the EntityManager was open and worked fine when to create the Query within the DAO but then was closed following that so attempting to execute the Query triggered the resulting error. On promptly moving the EnittyManager and DAO action to the correct Account Controller it all worked fine, so we have started!


I am still curious as to why the EntityManager was closed after the initial use, as I had tried adding the @Transactional annotation to the JSON Controller method - I suspect I will have to do some further reading in to this, but for the time being, the app is working correctly so I will continue!