Sep 042014
 

A DeepaMehta(DM) plugin can publish static resources and dynamic resources.

A DM plugin automatically publishes the Static resources (files) that are in resource/web directory. They will be published in the URI specified in bundle symbolic name in the pom.xml

A DM plugin can also publish dynamic resources created by java code, by providing a DeepaMehta RESTful service. To do so, you should define a method where you call getStaticResource to access a resource from the plugin, this method returns an Inputstream. The resources will be published in the URI obtained from the @path annotation defined in the plugin, and the resource method should be annotated with @Produces(“text/html”).

An example:


package de.example;

import de.deepamehta.core.osgi.PluginActivator;
import java.io.InputStream;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;

@Path("/website")
public class ExamplePlugin extends PluginActivator {

@GET
@Path("/{id}")
@Produces("text/html")
public InputStream invokeExample() {
return getStaticResource("web/index.html");
}
}

 Posted by at 7:27 am
Sep 042014
 

DM does not log you out automatically. There is no session timeout.

Once logged in DM creates a session in its webserver. The session ID is hold in a cookie. The cookie is a “session cookie”, that is it has no expiration date. So your session is only lost when a) restarting the DM server (in particular its web server), or b) when you restart the browser (or delete the cookie manually).

In case you have installed DM integration with SAlly, then you may experience an automatically log out, to change it you must put

org.ops4j.pax.web.session.timeout=120

in Karaf’s etc/system.properties file (gives 120 minutes to time out).

 Posted by at 6:04 am
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 :-)

PastedGraphic-5

 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 jsonparser.org.

abriraqui_jsonparser

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.

abriraqui_jsonparser_assocs

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();
role1.setPlayerId(mapTopicIds.get(role1.getPlayerId()));
                    
RoleModel role2 = assocModel.getRoleModel2();
role2.setPlayerId(mapTopicIds.get(role2.getPlayerId()));

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 :-)

abriraqui_imported_topicmap

 Posted by at 4:41 pm