Use Wicket templating system to generate Html

html-iconApache Wicket is a great web framework, its clear separation between logic and markup allows to focus on what’s need to be done.

As we use Wicket at SRMvision, we needed to send mails with rather rich templates to our users. The first implementation we used was relying on Wicket to generate these templates using Html. We finally don’t use it (our mailing tasks are done by a background job, thus we don’t have access to our webapp), but I though the code used in our fast proof of concept could help someone else.

import org.apache.wicket.markup.MarkupType;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.Response;
import org.apache.wicket.response.StringResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Simple panel allowing to use the templating engine 
 *    provided by Wicket to generate HTML.
 * Typical use would be to generate mail content.
 *
 * User of this class will need to subclass it 
 *    and create a panel as usual. 
 * Then a call to getHtml() will return the generated Html.
 *
 * @author cedric at gatay.fr
 */
public class HtmlTemplaterPanel extends Panel {
    private static final Logger LOGGER = 
        LoggerFactory.getLogger(HtmlTemplaterPanel.class);

    /**
     * Default constructor takes no wicket:id > 
     *   the panel will not be added to any component
     */
    public HtmlTemplaterPanel(){
        super("dummy");
    }

    /**
     * Call this whenever you want to get
     *   the Html for this component
     * @return Html or empty string
     */
    public String getHtml(){
        final Response origResponse = getRequestCycle().getResponse();
        try{
            final StringResponse stringResponse = new StringResponse();
            getRequestCycle().setResponse(stringResponse);
            renderAssociatedMarkup("panel", "");
            return stringResponse.toString();
        }catch(Exception e){
            LOGGER.error("Unable to build HTML for panel : {}",
                         e.getMessage());
        }finally{
            getRequestCycle().setResponse(origResponse);
        }
        return "";
    }

    @Override
    protected boolean getStatelessHint() {
        return true;
    }

    @Override
    public MarkupType getMarkupType() {
        return MarkupType.HTML_MARKUP_TYPE;
    }
}

If you want to generate a template using Apache Wicket, you only need to create a Panel and its associated markup which inherits this simple class. Then, when you want to get the Html for your component, call getHtml().

The only drawback of this is that you need a RequestCycle to generate the markup (you’ll find out why reading the code).

Graph of programming languages people used in 2012

I came across this link representing a visualization of programming languages usage based on a hashtag collect : http://www.ioncannon.net/projects/code2012/

Although this method can be criticized, it provides interesting data : JavaScript is the clear winner with Java just behind. We can see Scala is a growing language too, it has been used more than PHP last year (according to this study).

If you find another study on this topic don’t hesitate to comment this blog post to let me know.

OS X Tools I use in my daily activities

MBP KeyboardDuring a Jabber talk with my friend Thomas Debarochez I mentioned an app I use everyday that he hardly ever knows. Then I think it might be a good idea to describe the tools I use everyday at work or home on my machines. My main computer is a MacBook Pro (late 2011) running latest OS X version (Mountain Lion). I use it to develop the SRMvision platform which is built using Java EE technologies (the whole stack will be detailed in a further post).

The tools I use on my machine in my development process are the following :

  • IntelliJ IDEA Ultimate 12 : the best Java / JVM language IDE so far. It is a great IDE, offers a really good Maven integration and there is a wide range of plugins available. This last version features the really nice Darcula theme (eye candyness) and out of process compiler which makes it really fast.
  • Sublime Text 2 : it is a simple but really powerful text editor. I use it to open every file that is out of my IntelliJ’s projects.
  • Sequel Pro : a nice and powerful mySQL GUI client. It is sometimes more comfortable to query database with a GUI than with the command line.
  • MongoHub : a simple MongoDB GUI client, crashy but it can be useful at times.
  • Apache Maven : there is no need to elaborate on this one, I think every Java developer knows it.
  • Oracle Glassfish : one should chose a JavaEE application server, we chose the reference implementation of the spec.

I also use hosted service (self-hosted on our internal network or in the cloud for some) :

  • GitlabHQ : if you’ve read past blog entries, you should know this wonderful tool to manage git repositories (self hosted).
  • Jenkins : the well known build tool (self-hosted).
  • Sonatype Nexus : as we build our softwares with Apache Maven, we need an internal artifact repository, this one was chosen because it was the simplest to install (when we did it) (self-hosted).
  • Sonar : associated in our build pipeline, we have got a Sonar install to collect metrics on our projects (self-hosted).
  • Trac : old but not dead, Trac is our source ticketing system from day one. It is surely not the hottest kid in town, but it does its job as expected (self-hosted).
  • Trello : our sprint management tool, its card approach with TrelloScrum plugin allows us to easily plan and run our sprints.

In my list of programs I run everyday without being specifically targeted toward development, I use the following :

  • Synergy : it is a simple tool allowing you to share one computer’s mouse and keyboard with many other machines using your network connection. As I have two other machines at my desk, this tool is really useful in order to control each one from a mouse and keyboard.
  • ControlPlane.app : a great app if you use a MacBook, it allows you to define profiles and trigger them based on your location. I have a few profiles allowing me to toggle screensaver password, screen luminosity and my synergy setup.
  • Alfred.app : it is Apple’s Spotlight on steroid, you can do whatever you want to by simply hitting the shortcut you defined in Alfred. My usage is mainly using it as an application launcher.
  • Cloud.app : this little tool is really great. Every screenshot I take is uploaded to their servers and the link is then automatically put in my clipboard. It is really useful to quickly share screenshots over instant messenging.

And to finish with this little blog post, here are the stuff I keep installed on my machine even though I don’t use them daily :

  • HomeBrew : when I got my first Intel Mac, I used MacPorts to install tools from the Unix world from sources. This tool is great, but you end up downloading a lot of dependencies to get a simple soft to build and you are transforming your CPU to a toaster. Then I heard about HomeBrew, which is the simplest and the greatest way of managing third party applications on your Mac. Everything is clean, there is no need to be root, no need to be part of the global warming thing with your CPU.
  • Dropbox : I think this one is known by everyone now. Just upload and share your files easily, the app is so great that I can even forget the magic it is doing in my back.
  • Pocket : (previously Read It Later) is a great software to mark links, blog posts, everything you can come across on the web as to be read later. The Mac application is beautiful, so is the Android one (Hint : don’t stack in it if you can’t manage to free time for unstacking).
  • SourceTree.app and Github.app: at times, I need to get a visual help to manage my git repositories. SourceTree is a complete tool offering a really good looking branch visualization. Github allows to seamlessly use their service, I often use it to reorder my commits before making a pull request.
  • Colloquy : a really good IRC client, I use it when I am telecommuting, otherwise I use the classic XChat (linux version).
  • Spotify : I think I can not work without music, the 10€ / month membership allows me to use it with my phone too, it is very unlikely that I cancel this subscription anytime soon (I even use the Linux version).
  • XSlimmer : I use this tool from time to time to slim down the size of the app I have installed. It works by removing unused language in packages.
  • Clusters : I have this one installed and do its work without worrying of what it is doing. It allows me to save some space in the folders where I store documents (compression is very efficient here).
  • Dashlane : this password and identity manager is really good. It exists for different OSes and allows to setup strong passwords on every account you own : must have.

Mise en place de tests unitaire

A qui est destiné ce document

Ce document est à l’attention des développeurs ayant de bonnes connaissances techniques. En revanche il est intéressant pour un chef de projet de connaître les généralités énoncées dans la première partie du document.

Généralité

Qu’est ce qu’un test unitaire

D’après Wikipédia :

En programmation informatique, le test unitaire est un procédé permettant de s’assurer du fonctionnement correct d’une partie déterminée d’un logiciel ou d’une portion d’un programme (appelée « unité » ou « module »).
On écrit un test pour confronter une réalisation à sa spécification.

Ils consistent en liste de tests à valider afin d’être conforme à la documentation fonctionnelle. Ces tests doivent être exécutés le plus souvent possible au cours de la réalisation, en effet ils permettent en autre de mettre en évidence toutes régression dans le processus de développement. Continue reading