Examples of RosterManager


Examples of org.jivesoftware.openfire.roster.RosterManager

                // Those who already have presence subscriptions to jidFrom
          // will now automatically be subscribed to this new
          // PEPService.
          try {
            final RosterManager rm = XMPPServer.getInstance()
                .getRosterManager();
            final Roster roster = rm.getRoster(senderJID.getNode());
            for (final RosterItem item : roster.getRosterItems()) {
              if (item.getSubStatus() == RosterItem.SUB_BOTH
                  || item.getSubStatus() == RosterItem.SUB_FROM) {
                createSubscriptionToPEPService(pepService, item
                    .getJid(), senderJID);
View Full Code Here

Examples of org.jivesoftware.openfire.roster.RosterManager

        System.out.println("Accounts created successfully: " + created);
    }

    public void populateRosters(String userPrefix, int from, int total, int usersPerRoster) {
        XMPPServer server = XMPPServer.getInstance();
        RosterManager rosterManager = server.getRosterManager();


        int batchTotal = total / usersPerRoster;
        System.out.println("Total batches of users: " + batchTotal);
        for (int batchNumber = 0; batchNumber < batchTotal; batchNumber++) {

            System.out.println("Current batch: " + batchNumber + ". Users: " + batchNumber*usersPerRoster + " - " + ((batchNumber*usersPerRoster)+usersPerRoster));
            // Add rosters items between connected users
            for (int i = (batchNumber * usersPerRoster) + from;
                 i < (batchNumber * usersPerRoster) + usersPerRoster + from; i++) {
                String username = userPrefix + i;
                Roster roster;
                try {
                    roster = rosterManager.getRoster(username);
                } catch (UserNotFoundException e) {
                    continue;
                }
                if (roster.getRosterItems().size() >= usersPerRoster) {
                    // Roster already populated. Skip it.
                    continue;
                }
                for (int j = (batchNumber * usersPerRoster) + from;
                     j < (batchNumber * usersPerRoster) + usersPerRoster + from; j++) {
                    if (i == j) {
                        continue;
                    }

                    try {
                        Roster recipientRoster = rosterManager.getRoster(userPrefix + j);

                        manageSub(server.createJID(userPrefix + j, null), true, Presence.Type.subscribe, roster);
                        manageSub(server.createJID(username, null), false, Presence.Type.subscribe, recipientRoster);

                        manageSub(server.createJID(userPrefix + j, null), true, Presence.Type.subscribed, roster);
View Full Code Here

Examples of org.jivesoftware.openfire.roster.RosterManager

    }     
   
  }
 
  private List<String> getGroups(String ownerJID, String userJID) {
    RosterManager rosterManager = XMPPServer.getInstance().getRosterManager();
    Roster roster;
    try {
      roster = rosterManager.getRoster(new JID(ownerJID).getNode());
      RosterItem rosterItem = roster.getRosterItem(new JID(userJID));
      if (rosterItem != null) {
        return rosterItem.getGroups();
      }
    } catch (UserNotFoundException e) {
View Full Code Here

Examples of rocks.xmpp.core.roster.RosterManager

                        lock.unlock();
                    }
                }
            }
        });
        rosterManager = new RosterManager(this);
        presenceManager = new PresenceManager(this);

        streamNegotiatedUntilSasl = lock.newCondition();
        streamNegotiatedUntilResourceBinding = lock.newCondition();
View Full Code Here

Examples of rocks.xmpp.core.roster.RosterManager

     * @return The action, which was actually performed. This may vary from the specified action, e.g. if you add a contact that already exists, only its groups are updated. If no action was performed, e.g. if you want to delete a contact, that does not exist, null is returned.
     * @throws rocks.xmpp.core.stanza.model.StanzaException If the entity returned a stanza error.
     * @throws rocks.xmpp.core.session.NoResponseException  If the entity did not respond.
     */
    public ContactExchange.Item.Action approve(ContactExchange.Item item) throws XmppException {
        RosterManager rosterManager = xmppSession.getRosterManager();
        Contact contact = rosterManager.getContact(item.getJid());
        ContactExchange.Item.Action action = null;
        if (item.getAction() == null || item.getAction() == ContactExchange.Item.Action.ADD) {
            // If the contact does not exist yes, add it and request subscription.
            // (After completing the roster set, the receiving application SHOULD also send a <presence/> stanza of type "subscribe" to the JID of the new item.)
            if (contact == null) {
                rosterManager.addContact(new Contact(item.getJid(), item.getName(), item.getGroups()), true, null);
                action = ContactExchange.Item.Action.ADD;
            } else {
                List<String> newGroups = new ArrayList<>(contact.getGroups());
                List<String> additionalGroups = new ArrayList<>(item.getGroups());
                // Remove all existing groups from the list.
                additionalGroups.removeAll(newGroups);
                if (!additionalGroups.isEmpty()) {
                    // Then add all additional groups to the existing groups.
                    newGroups.addAll(additionalGroups);
                    // ... SHOULD edit the existing item so that will also belong to the specified group (in addition to the existing group, if any).
                    rosterManager.updateContact(new Contact(contact.getJid(), contact.getName(), newGroups));
                    action = ContactExchange.Item.Action.MODIFY;
                }
            }
        } else if (item.getAction() == ContactExchange.Item.Action.DELETE) {
            if (contact != null) {
                List<String> existingGroups = new ArrayList<>(contact.getGroups());
                List<String> specifiedGroups = new ArrayList<>(item.getGroups());
                // Remove all specified groups from the existing groups.
                existingGroups.removeAll(specifiedGroups);
                // If there are still some groups left, only update the contact, but do not delete it.
                if (!existingGroups.isEmpty()) {
                    rosterManager.updateContact(new Contact(contact.getJid(), contact.getName(), existingGroups));
                    action = ContactExchange.Item.Action.MODIFY;
                } else {
                    rosterManager.removeContact(item.getJid());
                    action = ContactExchange.Item.Action.DELETE;
                }
            }
        } else if (item.getAction() == ContactExchange.Item.Action.MODIFY) {
            if (contact != null) {
                rosterManager.updateContact(new Contact(item.getJid(), item.getName(), item.getGroups()));
                action = ContactExchange.Item.Action.MODIFY;
            }
        }
        return action;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.