[deepamehta-devel] Setting a simple association programmatically
Malte Reissig
mre at deepamehta.de
Sun Oct 23 23:44:03 CEST 2016
Hi Robert,
that is an very interesting observation. The solution lies in the
"CoreService", it "provides the methods to deal with topics,
associations, types and plugins", among others there is a
`createAssociation` method.
Tocreate a simple "dm4.core.association" you can write, for example:
dm4.createAssociation(mf.newAssociationModel("dm4.core.association",
mf.newTopicRoleModel(username.getId(), "dm4.core.default"),
mf.newTopicRoleModel(website.getId(), "dm4.core.default")));
In your plugin the CoreService is available through the `dm4` object:
http://api.deepamehta.de/deepamehta/4.8.3/de/deepamehta/core/service/CoreService.html
I must leave a better explanation to others here but here is my quick
answer: ChildTopics is a core service utility which takes the respective
type definition into account governing the relation between, e.g. a
"Comment" and a "Blogpost". If your "Comment" type is not (child) part
of a "Blogpost"s type definition you can not use ChildTopics.addRef().
For an "assocDefUri" (=associationDefinitionUri) the only two valid
values are "dm4.core.composition" or "dm4.core.aggregation".
You might want to consider to either (1) introduce a custom association
type to express this relation (esp. if the association carries dedicated
application logic and not rely on ChildTopics but on
dm4.createAssociation() or (2) alter the type definition of the parent
in a way that, e.g. for each "Blogpost" a "Comment" becomes a (by type)
defined (meaning either aggregated, composed) child of it.
I hope this helps.
Nice greetings,
Malte
On 23.10.2016 22:10, Robert Schuster wrote:
> Hi all,
> I want to create a simple association between between two topics
> programmatically.
>
> So the result should be as if I would draw a line between two topics in
> the webclient. I was under the impression that this would be a simple:
>
> ChildTopics childs = comment.getChildTopics();
> childs.addRef("dm4.core.association", topicCommentOn.getId());
>
> However that did not work as intended. Any idea what I am missing here?
>
> What wonders me also is that this code seemingly works without error but
> I cannot 'see' any associations in the webclient later on.
>
> Best regards,
> Robert
>
More information about the devel
mailing list