The path to Alfresco enlightenment

I started working with Alfresco back in 2005 and the code base was a lot smaller back then! More recently I’ve seen people try to dive into WebScript development without a concrete understanding of the foundational elements of the API. When I was set the task of organising an internal ‘hackathon’ as part of a ‘company day’ I decided that the goal should be to create a hands-on code-based tutorial.

Alfresco Koans

The koans tutorial style had been around for a few years (e.g. Neo4j, the Ruby Koans) when I decided it would make a good opportunity for our seasoned & certified Alfresco architects and senior developers to create additional hands-on learning material for new starters. Self-guided learning of the Alfresco APIs before they went on our of our more rigorous internal bootcamps.

The idea was to introduce Java developers who were new to Alfresco to the core API concepts starting with the foundational store references and stores, before progressing onto nodes/node references and then further down the line actions, behaviours/policies, rules, web scripts etc.

The aim is to make the deliberately broken unit tests pass and learn the API along the way by taking small steps, some of which will require referring to the API documentation (e.g. StoreRef).

For example, the first koan starts with learning about constructing a StoreRef with two String objects:

   StoreRef ref = null;

   // You can construct a StoreRef with two Strings
   String protocol = null;
   String identifier = null;

   // YOUR CODE STARTS HERE

   // YOUR CODE FINISHES HERE

   assertNotNull("Have you set the protocol?", protocol);
   assertNotNull("have you set the identifier?", identifier);
   ref = new StoreRef(protocol,identifier);
   assertEquals("The store ref is wrong", "foo://bar", ref.toString());

Having learnt the format for the String representation of the StoreRef, the next step is to use the single String constructor.

   StoreRef ref = null;

   // You can construct a StoreRef with a string
   String string = null;

   // YOUR CODE STARTS HERE

   // YOUR CODE FINISHES HERE

   assertNotNull("Have you set the store string?", string);
   ref = new StoreRef(string);
   assertEquals("The store ref is wrong", "cafe://babe", ref.toString());

Then it is on to obtaining the static StoreRef for ‘workspace://SpacesStore‘, which will involve either inspecting the class or its javadoc:

   StoreRef ref = null;

   // You can get the well-known Workspace SpacesStore without needing to use a constructor.

   // YOUR CODE STARTS HERE

   // YOUR CODE FINISHES HERE

   assertNotNull("Ref mustn't be null, have you implemented your code snippet yet?", ref);
   assertEquals("The store ref is wrong", "workspace://SpacesStore", ref.toString());

I’m pleased to anounce that the initial set of source code for the exercises has now been released as Open Source and can be found at https://github.com/rbramley/Alfresco-Koans – enjoy the start of the path to enlightenment!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s