Lose leaf node when add it to a Collection Node

Kelly Kuang
Added almost 3 years ago

I want to associate a Leaf Node to a Collection Node, but have some problems.

The following is my step:

  1. Create and config a collection node(GameNode).

  2. Create a leaf node(LolNode) with default config.(I've been query database. I confirm both collection node and leaf node are exit and their pubsub#node_type are correct.)

  3. config collection node, set pubsub#children to leaf node.


<iq to="" id="UmHvbP" type="set">
  <pubsub xmlns="">
    <configure node="GameNode">
      <x xmlns="jabber:x:data" type="submit">
        <field type="hidden" var="FORM_TYPE">
        <field type="text-single" var="pubsub#send_last_published_item">
        <field type="text-single" var="pubsub#children">

receive two packet from server:

<message xmlns="jabber:client" id="1" from="" to="">
  <event xmlns="">
    <collection node="GameNode">
      <associate node="LolNode"/>


<iq xmlns="jabber:client" to="" type="result" id="UmHvbP" from=""></iq>

I thought I have succeeded but when I query database, I found the leaf node disappeared! The pubsub#children in collection node config have been set to LolNode.

My problem:

  1. How to associate a Leaf Node to a Collection Node? Is there something wrong in my steps? I missed some important things?

  2. If my steps are correct, why the leaf node disappeared?

I have debugged the server code and found:

In tigase.pubsub.modules.NodeConfigModule#process(Packet packet)

If nodeConfig is CollectionNodeConfig, server will find and loop addedChildNodes.

for (String ann : addedChildNodes) {
    AbstractNodeConfig nc = getRepository().getNodeConfig(toJid, ann);

    if (nc == null) {
        throw new PubSubException(Authorization.ITEM_NOT_FOUND, "(#2) Node '" + ann + "' doesn't exists");
    if (nc.getCollection().equals("")) {
        getRepository().removeFromRootCollection(toJid, nc.getNodeName());   //Comment1: This row remove the added child node(LolNode) from database.
    } else {
        AbstractNodeConfig cnc = getRepository().getNodeConfig(toJid, nc.getCollection());

        if (cnc == null) {
            throw new PubSubException(Authorization.ITEM_NOT_FOUND, "(#3) Node '" + nc.getCollection()
                    + "' doesn't exists");
        if (!(cnc instanceof CollectionNodeConfig)) {
            throw new PubSubException(Authorization.NOT_ALLOWED, "(#2) Node '" + nc.getCollection()
                    + "' is not collection node");
        ((CollectionNodeConfig) cnc).removeChildren(nc.getNodeName());
        getRepository().update(toJid, cnc.getNodeName(), cnc);
    getRepository().update(toJid, nc.getNodeName(), nc);  //Comment2: This row will try to update the added child node collection_id, but it is no effect. Because the leaf node has been removed. 

    Element associateNotification = createAssociateNotification(nodeName, ann);

    publishModule.sendNotifications(associateNotification, packet.getStanzaTo(),
            nodeName, nodeConfig, nodeAffiliations, nodeSubscriptions);

In comment1, I think remove from root collection is correct. But why remove from database?

Replies (5)


Added by Andrzej Wójcik IoT 1 CloudTigaseTeam almost 3 years ago

Which version of Tigase XMPP Server and PubSub Component are you using?

In version 7.1.0-SNAPSHOT which should be released soon, this code is changed and PubSub node is no longer being removed from database when @removeFromRootCollection is being executed.


Added by Kelly Kuang almost 3 years ago

I am using tigase-server-7.0.2. I will try with 7.1.0-SNAPSHOT later. Thank you very much.


Added by Kelly Kuang almost 3 years ago

Because of many reasons, I can't upgrade my local Tigase server version. But I need to fix this problem.

I am going to only fix the java code hand by hand, according to the official source code.

Could you please tell me the SHA id which fix this problem?

I found this PubSub upgrade:

  1. Is this upgrade fix the problem?

  2. As the code is shown above, Can I only fix the CachedPubSubRepository#removeFromRootCollection() to solve this problem. (I know this may be difficult to confirm...)

Added by Andrzej Wójcik IoT 1 CloudTigaseTeam almost 3 years ago

I check if this is only place that needs to be changed and I think that if you apply this change - even only the first part - this change should fix this issue.

Added by Kelly Kuang almost 3 years ago

Thank you very much.