Ticket #554 (closed Enhancement: fixed)
How to: Programmatically add topic to topicmap (so that it is correct)
Reported by: | Malte | Owned by: | jri |
---|---|---|---|
Priority: | Blocker | Milestone: | |
Component: | DeepaMehta Standard Distribution | Version: | 4.1.2 |
Keywords: | Cc: | ||
Complexity: | 3 | Area: | Application Framework / API |
Module: | deepamehta-topicmaps |
Description
Everything seemed to work fine using
topicmapService.addTopicToTopicmap(topicmap.getId(), topic.getId(), null);
.. the "Topicmap" has a "Topic Mapcontext" relation to an added "Topic"
But:
(A) the added topic does not appear in the Topicmap (visually in webclient) - also not if I call tmService.setVisibility(topcmapId, topicId, true);
(B) and an AmbiguityException? ("there are 2 dm4.topicmaps.topic_mapcontext") is thrown which I could not deal with since
(C) I could not find a way to look for existing "Topics" in a "Topicmap" since "TopicmapService?" doesn't offer me "getTopicmapTopics()" (or something equivalent) and
My current workaround for issue (C)
- load a "Topicmaps"-Topic composite does not contain "Topics" contained in "Topicmap"
- checking the TopicmapViewmodel?.toJSON()-raw-data-set of a "Topicmap" does not contain a "Topic" (despite there is a "Topic Mapcontext" relation)
Issue 1: So it seems to me that just using the TopicmapService? and call "addToTopicmap(topicmapId, topicId, null); is not sufficient / leads to numerous problems. I can't find out by myself how to use it. And a quick search through numerous other plugins (source code) has not yielded any helpful code-passages using this method.
Issue 2: Existence check of "Topic" in "Topicmap". How to? Isn't it that one "Topic" can only occur once in a "Topicmap"? But maybe issue (C) is a follow-up of (A).
Change History
comment:2 Changed 7 years ago by jri
The problem is the null in your call. The topic needs "view properties", coordinates in particular.
addTopicToTopicmap(topicmapId, topicId, new CompositeValueModel() .put("dm4.topicmaps.x", x) .put("dm4.topicmaps.y", y) .put("dm4.topicmaps.visibility", true) )
Standard view properties comprise x, y, and visibility.
(In conjunction with a Viewmodel Customizer you could add custom view properties as well.)
comment:3 in reply to: ↑ description Changed 7 years ago by jri
Replying to Malte:
(C) I could not find a way to look for existing "Topics" in a "Topicmap" since "TopicmapService?" doesn't offer me "getTopicmapTopics()" (or something equivalent)
Yes, the public Topicmaps API is currently not sufficient.
I plan to extend it in 2 regards today:
- A TopicmapViewmodel? gets 2 public methods:
- getTopics() which returns an Iterable<TopicViewmodel?>
- getAssociations() accordingly
- The TopicmapsService? gets a new method:
- boolean isTopicInTopicmap(topicId, topicmapId)
The latter can be emulated already by dms.getAssociation(). Tell me if you need details.
comment:4 Changed 7 years ago by Malte
Ok, thanks. Now the topics are visible in my topicmap via the webclient.
But I still don't have a solution for an existence check (to avoid trying to add a Topic twice to a topicmap). The added topics don't appear (when using workaround b, checking the TopicmapViewmodel?) in the toJSON() representation, in fact the "topics:[]" list of that topicmpa remains empty. In fact it seems to remain empty when I create a simple "Note" topic in that map.
Any ideas on how I can accomplish that? Aha, OK. Don't worry, now I could also implement such existence check by myself, but yeah, the Topicmap needs this definitely. As you like, maybe you had other things on mind for today.
comment:5 Changed 7 years ago by jri
Replying to Malte:
Issue 2: Existence check of "Topic" in "Topicmap". How to? Isn't it that one "Topic" can only occur once in a "Topicmap"?
For the moment you can perform a "topic in topicmap?" existence check this way:
Association assoc = dms.getAssociation("dm4.topicmaps.topic_mapcontext", topicmapId, topicId, "dm4.core.default", "dm4.topicmaps.topicmap_topic", false); if (assoc != null) { // topic exists in topicmap }
This works already.
Of course isTopicInTopicmap() as proposed above would be more comfortable.
And, yes, a topic can occur only once in a topicmap.
To clarify: (B) is of course thrown when I try to add a "Topic" again to a "Topicmap" the way described above.