Have you ever wondered how you could use Alfresco to run a Trivia Game? No? Strange, I believe that should be a very important question to ask yourself when you are looking for an ECM for your company! If you have been working or following Alfresco in the past 10 years, you might have heard about the ContentCraft project, which is an integration between Alfresco and Minecraft, using CMIS. A few months ago, I was preparing a presentation about REST-API in Alfresco and to conclude the talk on a funnier note (a 45min talk about REST-API IS fun!), I thought about which game I could play using Alfresco REST-API.

With half a day to setup my Alfresco environment and implement the game, I obviously didn’t want to do something too complex and therefore, I thought about a Trivia Game. It’s essentially a question-and-answer game so knowing that Alfresco stores metadata and documents and that the REST-API can be used to fetch that, it appeared to be something feasible easily. In addition to that, it would help me and my presentation by running a small quiz to “test” the attendees and make sure they understood (/followed :D) the talk.

In this first blog, I will talk about the Alfresco preparation needed, which mainly consists of the meta-model. In a second blog, I will go through the REST-API calls needed to add questions into Alfresco with their associated good/bad answers of course. And the final blog will be around really “playing” the game. I will be using REST-API because it’s the simplest/fastest way to interact with Alfresco. A more advanced version of the game would most probably be using Web Scripts/Services so that it’s not up to the client to know how many answers are needed or to check whether the answer is good or bad, since on the client I could obviously just disregard the real answer and display that I selected the correct answer (but I don’t cheat! ;)).

First thing first, to have something done quickly for my purpose, I designed a small meta-model using the Share Model Manager. I started with the creation of the model “dbi”:

Create Model

In terms of XML, it should be something like:

<model xmlns="http://www.alfresco.org/model/dictionary/1.0" name="dbi:dbi">
  <description>Model for demo</description>
  <author>Morgan Patou</author>
  ...
  <namespaces>
    <namespace uri="http://www.dbi-services.com/model/content/1.0" prefix="dbi"/>
  </namespaces>
  ...
</model>

Then I added an aspect “dbi_trivia”, so it can be added into existing nodes:

Create Aspect

In terms of XML, it should add something like:

  <aspect name="dbi:dbi_trivia">
    <title>dbi trivia</title>
    <properties>
      ...
    </properties>
    ...
  </aspect>

This game could be done using documents. For example, a document being a question with the different answers and the correct one as content. Or it could be a type of document with the details as metadata. In this blog, I will use an aspect that will be applied to folders. Basically, a question is a folder, and the aspect is assigned to the folder so that it has access to the different metadata for questions and answers. I thought that would be one of the fastest/simplest to apply so I went with that. Therefore, the next step is to create the different properties for the aspect, 1 for the question, then 4 for the different answers (it could be a multi-valued one as well) and finally a last one to specify which is the correct answer:

Aspect Properties

In terms of XML, it should add something like:

    <properties>
      <property name="dbi:dbi_question">
        <title>Question</title>
        <type>d:text</type>
        <mandatory>true</mandatory>
        ...
      </property>
      <property name="dbi:dbi_answer1">
        <title>Answer#1</title>
        <type>d:text</type>
        <mandatory>false</mandatory>
        ...
      </property>
      ...
      <property name="dbi:dbi_correct_answer">
        <title>Correct Answer</title>
        <type>d:text</type>
        <mandatory>false</mandatory>
        ...
      </property>
    </properties>

The “dbi:dbi_correct_answer” here is again a “d:text” metadata, in the sense that it will contain again the textual answer (same value as either answer #1, 2, 3 OR 4). It would of course be possible to have this parameter as an integer instead, to link to the answer. I selected a text so that it is slightly easier to show/see which one is the correct one if you want to randomise the display of possible answers for example.

The next step is to create the layout to display these properties, which is optional, if you want them to be visible through Share. Again, something very simple:

Aspect Layout

As mentioned previously, the questions of a quiz would be different folders. To be able to handle/support multiple quiz, it would be possible to either separate the quiz based on a parent folder (each parent folder containing the different questions) or through another metadata that indicate a Unique ID for a specific quiz, in which case you could find the different questions through searches, and you wouldn’t really mind where the files are stored in Alfresco. The simplest being the parent folder (=quiz) and sub-folder (=questions) approach, I went with that, create one parent folder for now and noted its “uuid” (last part of the “nodeRef“).

That concludes the first part of this blog. It’s basically a 10/15 minutes setup to have the skeleton needed to play the game on the repository side. The second part of this blog can be found here and the third part here.