Aug 182014

When coming to use DeepaMehta (DM), sometimes we are not aware of all the potential that is already there. So I’ve decided that when I come through some solutions that at first may be not obvious I’ll tag them as in the blog as DeepaMehta tips ;-)

The first one, it has to do with retyping topics.
I’ve found out, that my first impulse when using DM is only to use the default topic types, almost everything can be a Note, a Person, an Institution or a WebResource. So I’m very happy just to start with those, once my project evolutes, I begin to need my own topic types, but was not sure how to do this in DM, without having to redo everything, so here it is how to reuse the information that you already have. In my case I’ve retyped Notes so I wanted to reuse its title and description.

1. Create Notes
2. Reveal the Note topic type (most simple by navigating along from a Note instance)
3. Create your own topic type, make it **composite**
4. Attach the Note type’s Title and Text child types to your own topic type
5. Create and attach further child types to your topic type
6. Optional: change the child order of your type so that Title remains the 1st child
7. RETYPE your Note instances (by invoking Retype from the context menu) -> Your Notes are now instances of your own type while keeping their existing content and label!

Retyping is on a per-instance basis, so each Note can be retyped to a different Type one by one :-)


 Posted by at 2:59 am
Jul 262014

Este artículo es parte del libro colectivo “#15MP2P. Una mirada transdisciplinar del #15M“, cuyo objetivo es tener una mirada múltiple y abierta sobre el 15M, con la pretensión de entender un poquito más, entre todos, qué pasó como para que cambiaran tanto nuestras vidas.

Como el artículo es un poco largo para la lectura en la web, a continuación los primeros párrafos y el artículo entero os lo podéis descargar.

El objetivo de este artículo es pensar sobre el devenir cyborg, como se diluyen las fronteras entre lo digital y lo real en las #revolution, todo es real, todo pasa, todo nos pasa. Haremos las reflexiones en pequeñas dosis o pildoras, se podrá saltar de una a otra, sin orden ni concierto, sera un impulso lo que lleve a leer cada una, no necesariamente deberá ser una lectura seguida, en tiempos de procastinación, la lectura también cambia. Este texto, no pretende ser un análisis objetivo sino una visión personal y subjetiva,desde la vivencia.

Mi piel está hecha de bits

Cuando la tecnología es parte de la piel, y los bits circulan por la sangre, cuando lees un tweet y te da un brinco el corazón, cuando deslizas el dedo en una pantalla y la distancia se vuelve algo relativo, cuando en un clic muestras al mundo lo que tienes alrededor, entonces empiezas a pensar que quizá algo esta cambiando, algo estamos cambiando, algo nos esta cambiando.

Artículo completo: Mamá, me ha salido un bit

 Posted by at 2:11 am
May 162014

Some days ago, I wrote a post about how to export a Topicmap in Deepamehta. This functionality is part of the final goal of doing an Import/Export plugin.

In this post, I will explain how have I done the import Topicmap method, that I will probably change in the next days, but in any case, I’ll tell what have I done until now :-)

Let’s see what do we need to actually import a Topicmap.

  1. Have a Topicmap file to import, obvious ;-)
  2. Create a new Topicmap where we will place the topics and associations of our exported Topicmap
  3. Add the topics of our exported Topicmap to our new Topicmap
  4. Add the associations of our exported Topicmap to our new Topicmap

So let’s proceed

First, read the file where the exported Topicmap is. For the moment, and to do things step by step, I’ve hard coded the file that I want to import.

As I said in the previous post, I exported the Topicmap into a JSON file placed in runner directory, that is at the root of your DM instance. We are going to read the same file that was exported there.

File file = new File("topicmap-11216.json");
String json = JavaUtils.readTextFile(file);

Now we will define a JSON Object from the read file

JSONObject topicmap = new JSONObject(json);

So the exported file with the Topicmap we have it accessable in JSON format in the variable topicmap.

The next task was to have a new Topicmap, where we will add the topics and the associations from the exported Topicmap.

Topic importedTopicmap = topicmapsService.createTopicmap("Imported Topicmap","dm4.webclient.default_topicmap_renderer", null);

To create a new map we need topicmapService, so you need to import it, that means add it to the rest of the import at the top of the file.

import de.deepamehta.plugins.topicmaps.service.TopicmapsService;

Fine, let’s continue. Which one was our third task? To add the topics of our exported Topicmap to our new Topicmap.

We will first create an array with the topics by extracting the information from the JSON that we already have.

We will first take a look at our JSON file, to parse it and visualize it you can check


So you can see that we have 3 parent objects: assocs, info and topics.

We are focusing in the topics, so we can see that there are 4 topics that need to be imported, we will access to the topics by getting the array associated to the key “topics”.

JSONArray topicsArray = topicmap.getJSONArray("topics");

When importing topics, there is one important thing to have in mind.
The way to retrieve the associations between topics, is because we establish an association between 2 topics through the topicIc, something like, association1 relates topicId=12 with topicId 23. So we have to map the new topicIds with the exported topicIds

We know that we are adding new topics to a recently created Topicmap. The id of the new topic will be automatically generated and set, so we don’t have the option of setting the id of the new topic to be the same as the id of the topic exported. That means that we have to keep track of which new topicId corresponds to the exported topicId by creating a Hash.

We define the Hash to map topic Ids.

Map<Long, Long> mapTopicIds = new HashMap();

In order to get the topics we have to iterate through the topicsArray by doing (for example)

 for (int i = 0, size = topicsArray.length(); i < size; i++)

By iterating we are going to get individual topics. If we take another look at the jsonparser, we can see that a topic is determined by an id, type_uri, uri, value, composite and view_props.

In each iteration we are going to get the content of all of these attributes.

 for (int i = 0, size = topicsArray.length(); i < size; i++)
                    JSONObject topic =  topicsArray.getJSONObject(i);
                    TopicModel model = new TopicModel(topic);
                    CompositeValueModel viewProps =new CompositeValueModel(topic.getJSONObject("view_props"));

                    Topic newTopic =  dms.createTopic(model, null);

                    long topicId = newTopic.getId();
                    long origTopicId = topic.getLong("id");
                    mapTopicIds.put(origTopicId, topicId);
                    topicmapsService.addTopicToTopicmap(topicmapId, topicId, viewProps);


To understand the loop, we’ll go line by line. By invoking getJSONObject(i) we will extract topic i.
On the other side we know that the createTopic method is provided by Deepamehta Servide (dms), where you need to pass a model and clientState. The clientState will be null.
The model we will be created by

TopicModel model = new TopicModel(topic);

so with a model and clientState we create the new Topic

Topic newTopic =  dms.createTopic(model, null);

We said that we have to keep the relation between new Topics id(newTopic.getId()) and exported Topics id(topic.getLong(“id”)), so we do that

long topicId = newTopic.getId();
long origTopicId = topic.getLong("id");
mapTopicIds.put(origTopicId, topicId);

In order to be able to add the new Topic to the new Topicmap, the topicmapService provides us with a couple of methods, the one we will choose is

addTopicToTopicmap(long topicmapId, long topicId, CompositeValueModel viewProps);

so before being able to add a Topic to a Topicmap, we need to get the CompositeValueModel, viewProps from the exported Topic.

 CompositeValueModel viewProps =new CompositeValueModel(topic.getJSONObject("view_props"));

Finally we can add the Topic with the info coming from the exportation to the new Topicmap

topicmapsService.addTopicToTopicmap(topicmapId, topicId, viewProps);

Wowww…now if you go to the webClient and click on import Topicmap, you will see how the topics appear in a new Topicmap :-))

And our last step was a”Add the associations of our exported Topicmap to our new Topicmap”

As with the topics we are going to extract the associations of the JSON file into an Array

JSONArray assocsArray = topicmap.getJSONArray("assocs");

We will iterate through the Array

 for (int i=0, size = assocsArray.length(); i< size; i++)

Take a moment, to check in the jsonparser, that the elements that form an association are id, role1, role2, type_uri, uri, value and composite. Inside role1 and role2 is stored the reference to the topicId to the "two sides" of the association.


As with Topics, DeepaMehta Service provides us with a createAssociation method

Association newAssociation = dms.createAssociation(assocModel, null);

We can create a new Association Model by

AssociationModel assocModel = new AssociationModel(assocsArray.getJSONObject(i));

but the important thing is to actually associate the two topics "coming" from our export file. To track this association we have already built a Hash that maps the topicId from the exported file with the new topicId, now we are going to use that mapping. So we have to change the values created automatically when creating an AssociationModel and set them with the values of the exported Topicmap.

RoleModel role1 = assocModel.getRoleModel1();
RoleModel role2 = assocModel.getRoleModel2();

So first, we get the RoleModel of the new association and we set the topicId(playerId is a general term that can be refered to a topicId or an associationId) to the value that was stored on our hash called mapTopicIds.

We are almost done :-) .. just one step missing, to add an Association to a Topicmap, the need the id of the new association, with that we are able to use the method provided by topicmapsService, AddAssociationToTopicmap to add our associations to our imported Topicmap :-)

long assocId = newAssociation.getId()              topicmapsService.addAssociationToTopicmap(topicmapId, assocId);

So, if you go to the webClient and chose to Import a Topicmap, you'll see it directly on the screen, as an example the one that I have :-)


 Posted by at 4:41 pm
May 032014

In the previous post , we explained how to writer the export part of the server side part of the import-export plugin. But with almost everything done, we missed one thing, the implementation of the export option from one of the menus in DM webclient.

The place to click the export action will be inside the topicmap drop-down menu.

First we need to create the directory structure for our client side, that is, inside /src/main you have to create


and in there the file plugin.js

Once the plugin.js file is created, we have to add our plugin, for that you have to invoke dm client (dm4c)

dm4c.add_plugin("net.abriraqui.import-export", function(){

Then dmc4 provides a listener that will allow you add elements to the topicmap menu. The elements that we will add are: a separator and the new item with “Export Topicmap” label, that will execute a export_topicmap method.

dm4c.add_listener("post_refresh_topicmap_menu", function(topicmap_menu) {
    label: "Export Topicmap",
    handler: export_topicmap

and of course, we need to write the export_topicmap method, which will be quite simple. We define the uri for the export action, “/import-export/export”. Since we want to show an alert box that tells us that the topicmap has been exported, we first get the topicmap and then in the alert we call the get_id() method to know which topic map are we in.

function export_topicmap(){
 dm4c.restc.request("POST", "/import-export/export") 
 var topicmap =   dm4c.get_plugin("de.deepamehta.topicmaps").get_topicmap()
 alert("Export of topicmap " + topicmap.get_id() + " complete")

Once done that, now we can finally check into our runner directory, in the root directory of your plugin, for the topicmap-XXX.json file with the info of the topicmap exported.

Implementing export topicmap option

May 032014

Some months ago, I wrote a post of how to start creating a plugin in DeepaMehta, it was basically to show, the use of migrations to create new topic types in a permanent way, in your DeepaMehta instance.
It was the first step to create a Calendar plugin for DeepaMehta, but since to create both client side and server side for that plugin would be quite difficult task as a first contact with DeepaMehta, I decided to do a couple of things first.

One was to actually write a casual user guide of how DeepaMehta can be used, that has deepen my understanding of how to use it, how it works, what I miss, etc.

On its way, one of the things that I miss is the possibility to import and export topicmaps. So since import-export feature works more at a server side, I thought it would be good to first focus on the server side, with a bit of client side, to get familiar with DM development framework.

The good thing is that this part is already documented in DeepaMehta  plugin developers documentation :) so what I’ll try to do is write down my use case with the import-export plugin.

To start the plugin main file must be located directly in the plugin’s src/main/java/, so the first thing to do is to create this structure, then it will have to be followed by a specific tree structure and the plugin name(as a convention, must end with Plugin). So the first thing is to figure out this directory structure.

One thing that I forgot to say, is that actually the first thing to do when creating a plugin is to define the pom.xml file. Following the guide, the initial pom.xml will look something like

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="" xmlns:xsi=""

  <name>DeepaMehta 4 Import Export </name>
  <groupId>net.abriraqui.dm4 </groupId>
  <packaging>bundle </packaging>



The important thing to see is the groupId, where we are defining the unique namespace for our plugin,net.abriraqui.dm4, and the artifactId, where we are defining the context where is created, that is DeepaMehta version (4.3) SNAPSHOT , the development version, followed by the name of the plugin, import-export.

We will build a correspondent directory structure inside src/main/java  that will me net/abriraqui/dm4/importexport  , importexport is the name of the plugin that in the directory structure, by convention, won’t have a dash in between.

Once you’ve created the directory structure, you create your plugin java file that should be called, .

So as in the dev guide says, the plugin package is net.abriraqui.dm4.importexport and the plugin main class is ImportExportPlugin

A plugin main file is a Java class that is derived from de.deepamehta.core.osgi.PluginActivator. The smallest possible plugin main file looks like this

package net.abriraqui.dm4.importexport;

import de.deepamehta.core.osgi.PluginActivator;
public class ImportExportPlugin extends PluginActivator {

Continue reading »