Ticket #549 (closed Feature Request: worksforme)

Opened 10 years ago

Last modified 10 years ago

Question: How can I programmatically create a Topic of type Topicmap (which then becomes a proper Geomap)

Reported by: Malte Owned by: jri
Priority: Blocker Milestone:
Component: 3rd Party Plugins Version: 4.1.2
Keywords: Cc:
Complexity: 3 Area: Application Framework / API
Module: dm3-freifunk-geomap


In a migration. Thanks for help.

Change History

comment:1 Changed 10 years ago by Malte

So, regarding the title. Since I know a Geomap is nothing else then a topic of type "Topicmap" the I formulated the question as it is in the title. What I need to know is: What do I need to add programmatically to turn a "Topicmap" into a "Geomap"? Probably it has just something to do with the renderer, but who knows.

Thanks for help.

comment:2 Changed 10 years ago by Malte

Later, on exactly that (programmatically created) Geomap-Topic my plugin will invoke the addTopicToGeomap()method (which happens from another plugin) using the GeomapService?. Probably that helps you to imagine the usage scenario.

comment:3 Changed 10 years ago by jri

The Topicmaps Service provides exactly what you need. It would be most easy to use that:

Topic createTopicmap(String name, String uri, String topicmapRendererUri, ClientState clientState)


tm_service.createTopicmap("My Geomap", "my.topicmap.uri", "dm4.geomaps.geomap_renderer", null)

As you said you just specify the URI of the Geomaps renderer.

Unfortunately in a migration you have no access to any plugin service (#324).

That's why I would't use a migration here but make the createTopicmap() call in your plugin's serviceArrived() hook, just when the Topicmaps service becomes available.
This means, before creating the topicmap you must check if it exists already (to not create it twice). That's why you should set a specific URI for your topicmap instance (see example above).

Topic topicmap = dms.getTopic("uri", new SimpleValue("my.topicmap.uri"), false);
if (topicmap == null) {
    // create topicmap

In general this very pattern proved as best practice when a migration semantic is desired but plugin service's are required.

Last edited 10 years ago by jri (previous) (diff)

comment:4 Changed 10 years ago by jri

UPDATE: of course the check is if topicmap == null.
Corrected in comment.

comment:5 Changed 10 years ago by Malte

OK, I did that now in my plugin code, no big deal.

But can I also use the postInstall-Hook? The issue with the serviceArrived()-Hook is, it seems to be fired before Migration1.java was run and I hesitate to move all Migration-Code into my plugin, (but the Geomap itself needs to be hooked up with topics from my migration).

Keeping the code in the serviceArrived()-Hook creates the Geomap just after a restart of my bundle/plugin and not directly with the initial DM startup.

Anyway, now I can continue to work with an imperatively created Geomap. Thanks for the info and the code.

comment:6 Changed 10 years ago by Malte

  • Status changed from new to closed
  • Resolution set to worksforme

Addendum: If you find this solution, don't forget to add ACLs to the Geomap created this way (too).

Note: See TracTickets for help on using tickets.