Project

General

Profile

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.

request:

<iq to="pubsub.testserver.com" id="UmHvbP" type="set">
  <pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
    <configure node="GameNode">
      <x xmlns="jabber:x:data" type="submit">
        <field type="hidden" var="FORM_TYPE">
          <value>http://jabber.org/protocol/pubsub#node_config</value>
        </field>
        <field type="text-single" var="pubsub#send_last_published_item">
          <value>never</value>
        </field>
        <field type="text-single" var="pubsub#children">
          <value>LolNode</value>
        </field>
      </x>
    </configure>
  </pubsub>
</iq>

receive two packet from server:

<message xmlns="jabber:client" id="1" from="pubsub.testserver.com" to="kelly@testserver.com">
  <event xmlns="http://jabber.org/protocol/pubsub#event">
    <collection node="GameNode">
      <associate node="LolNode"/>
    </collection>
  </event>
</message>

and

<iq xmlns="jabber:client" to="kelly@testserver.com/TestJaxmppClient" type="result" id="UmHvbP" from="pubsub.testserver.com"></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);
    }
    nc.setCollection(nodeName);
    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)

(1)

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.

(1)

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.

(1)

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:

https://projects.tigase.org/projects/tigase-pubsub/repository/revisions/1ac8b6feb48c3444cec0d233303da85d77945129

  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.

    (1-5/5)